<?php 
include("Views/Accounting/collection_modal.php");
?>
<style>
    #tableWithSearch thead tr >th{
        background-color:#4c0870;
        color:#fff;
    }
    #tableWithSearch thead tr th[class*='sorting_'] {
        color: #fff;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd;  
    }
    .datepicker thead tr .dow {
        color:#4c0870  !important;
    }
    .datepicker table tr td.day:hover {
        background: #4c0870  !important;
        color:#fff;
    }
    .datepicker table tr td.active {
        background-color: #4c0870  !important;
    }
    .datepicker thead tr .datepicker-switch {
        color: #4c0870   !important;
        font-size: 13px;
    }
    .datepicker table tr td span.active {
        background-color: #4c0870  !important;
    }
    .datepicker table tr td span:hover {
        background-color: #4c0870  !important;
        color:#fff;
    }
    datepicker thead tr .next:before, .datepicker thead tr .prev:before {
        color: #4c0870  !important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }
    .datepicker thead tr .next:before, .datepicker thead tr .prev:before {
        color: #4c0870  !important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }
    /*
    .btn-default:hover{
    background-color:#ed9421 !important;
    color:#fff;
    border: none;
    }
    */
    .complete ,.btn-group  .active{
        background-color:#ed9421 !important;
        color:#fff;
    }
    /*    .MonthPicker,.YearPicker,.FromToPicker{
    display:none;
    }*/
    #selected_entry{
        height:90px;
        color: black;
        margin-top:20px;
        font-size: 16px;
        padding-top: 2%;
    }
    .select_table td{
        padding-left: 70px;
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover,.dataTables_wrapper .dataTables_paginate .paginate_button:hover{
        color:#fff !important;
        border-radius: 50%;
        background: #ed9421 !important;
        border-color: #4c0870
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover{
        color:#fff !important;
    }
    .actionButton{
        background-color:#4c0870;
    }
</style>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title">
                <h4 class="bold"><?php echo $title; ?> </h4>
            </div>
            <div class="row form-group">
                <div class="col-md-3" >
                    <label><?php print CommonLanguage::getMessage('Date'); ?></label>
                    <input id="From_To_Date" type="text" class="form-control" name="From_To_Date" >
                </div> 

            </div>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered table-hover demo-table-search" id="tableWithSearch">
                        <thead>
                            <tr>
                                <th class="text-center" style="width:10%" >#</th>
                                <th class="text-center" style="width:10%" > <?php print CommonLanguage::getMessage('Code'); ?></th>
                                <th class="text-center" style="width:15%" > <?php print CommonLanguage::getMessage('Name'); ?></th>
                                <th class="text-center" style="width:10%"> <?php print CommonLanguage::getMessage('amount'); ?></th>
                                <th class="text-center" style="width:10%"> <?php print CommonLanguage::getMessage('currency'); ?></th>

                                <th class="text-center" style="width:10%"> <?php print CommonLanguage::getMessage('note'); ?></th>
                                <th class="text-center" style="width:10%"> <?php print CommonLanguage::getMessage('Date'); ?></th>
                                <th class="text-center no-print" style="width:5%"><?php print CommonLanguage::getMessage('Action'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var is_actual = <?php echo $is_actual ? "true" : "false" ?>;
    var title = <?php echo json_encode(CommonLanguage::getMessage($title)); ?>;
    var today = <?php echo json_encode($today) ?>;
    $(function () {

        ChangeTable()
        $("input[name=From_To_Date]").daterangepicker({
        }, function (start, end, label) {
            window.startDate = start.format("YYYY-MM-DD"),
                    window.endDate = end.format("YYYY-MM-DD")
            ChangeTable();

        });


        $("#tableWithSearch").on("click", ".delete", function () {
            var entry_value = $(this).parents('.Action').attr('data-id');
            var data = {
                id: entry_value,
                
            };
            
            IncludeDeleteModal(common_delete_modal, data, function () {
                ChangeTable();
            }, "ACCAjax/delete_collection");
        })
        
         $("#tableWithSearch").on("click", ".Edit", function () {
            CommonViewById('ACCAjax/get_collection_by_id', {id: $(this).parents('.Action').attr('data-id')},
                    '#paymentLoader', function (response) {
                        $("#pay_detail_id").val(response['pay_detail_id'])
                        $("#pay_acc_id").val(response['payment_account_id'])
                        $("#collection_id").val(response['collection_id'])
                        $("#currency_id").val(response['currency_id']).select2()
                        $("#collection_date").val(response['collection_date'])
                        $("#commission_amount").val(response['commission_amount'])
                        $("#pay_amount").val(response['pay_amount'])
                        $("#note").val(response['note'])
                        $("#current_rate").val(response['current_rate'])
                        $("#second_currency_rate").val(response['second_currency_rate'])
                        $("#account_id").val(response['account_id']).attr("data-select-name",response['acc_name']).trigger("change")
                        $("#commission_acc_id").val(response['commission_acc_id']).attr("data-select-name",response['com_name']).trigger("change")
                        $("#project_id").val(response['project_id']).attr("data-select-name",response['project_name']).trigger("change")
                        $("#branch_id").val(response['branch_id']).attr("data-select-name",response['branch_name']).trigger("change")
                        $("#job_id").val(response['job_id']).attr("data-select-name",response['job_name']).trigger("change")
                        $("#collection_modal").modal("show")

                    });
        })
    })

    function ChangeTable() {
        var Date = {
            is_actual: is_actual,
            Payment_Date_From: (window.startDate ? window.startDate : today),
            Payment_Date_To: (window.endDate ? window.endDate : today)
        };

        RebuildDataTable(title, [0, 1, 2, 3, 4, 5, 6, 7], 'ACCAjax/collection_list_ajax', Date);


    }


</script>
