<?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>
<script src="<?php echo JS_PATH; ?>scripts.js"></script>
<script src="<?php echo THEME_PATH; ?>/plugins/moment/moment.min.js"></script>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"> <?php echo $IsReceipt ? CommonLanguage::getMessage('receipt_due_dates') : CommonLanguage::getMessage('payment_due_dates'); ?> </div>
            <div class="row ">
                <div class="col-md-12 form-group ">

                    <div class="col-md-3" >
                        <label><?php echo CommonLanguage::getMessage('Date') ?></label>
                        <input id="From_To_Date" type="text" class="form-control" name="From_To_Date" >
                    </div> 

                    <div class="col-md-3" >
                        <label><?php echo CommonLanguage::getMessage('type') ?></label>
                        <select class="full-width" id="type_filter" data-init-plugin="select2">
                            <option value="all"><?php echo CommonLanguage::getMessage('All') ?></option>
                            <option value="1"><?php echo CommonLanguage::getMessage('pending') ?></option>
                        </select>
                    </div>
                    <div class="col-md-3" >
                        <label><?php echo CommonLanguage::getMessage('checks') ?></label>
                        <input type="checkbox" id="is_check"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="panel-body">

            <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('Name'); ?></th>
                        <th class="text-center" style="width:15%" > <?php print CommonLanguage::getMessage('cheque'); ?></th>
                        <th class="text-center" style="width:10%"> <?php print CommonLanguage::getMessage('amount'); ?></th>
                        <th class="text-center" style="width:5%" > <?php print CommonLanguage::getMessage('type'); ?></th>
                        <th class="text-center" style="width:10%"> <?php print CommonLanguage::getMessage('due_date'); ?></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('status'); ?></th>
                        <th class="text-center" style="width:10%"> <?php print CommonLanguage::getMessage('Action'); ?></th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
                <tfoot>
                <th>
                    <?php if ($permissions->hasPermission($is_actual ? ($IsReceipt ? "settle_act_rec_to_bank" : "settle_act_pay_from_bank") : ($IsReceipt ? "settle_rec_to_bank" : "settle_pay_from_bank"))) { ?>
                        <button class="btn btn-complete m-b-10 full-width" id="settle_all"><?php echo CommonLanguage::getMessage('settle'); ?></button>
                    <?php } ?>
                </th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>

                </tfoot>
            </table>
        </div>

    </div>
</div>

<script>
    var IsReceipt = <?php echo $IsReceipt ? "true" : "false" ?>;
    var is_actual = <?php echo $is_actual ?>;
    var title = <?php echo json_encode(CommonLanguage::getMessage($IsReceipt ? 'receipt_due_dates' : 'payment_due_dates')); ?>;
    var today = <?php echo json_encode($today) ?>;
    $(function () {
 
        new Switchery($("#is_check").get(0), {color: $.Pages.getColor("complete")});
        ChangeTable()
        $("input[name=From_To_Date]").daterangepicker({
            ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            }
        }, function (start, end, label) {
            window.startDate = start.format("YYYY-MM-DD"),
                    window.endDate = end.format("YYYY-MM-DD")
            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", ".collect_pay", function () {
            CommonViewById('ACCAjax/get_payment_detail', {id: $(this).attr('data-id')},
                    '#paymentLoader', function (response) {
                        $("#pay_detail_id").val(response['payment_detail_id'])
                        $("#pay_acc_id").val(response['payment_account_id'])
                        $("#pay_amount").val(response['payment_amount'])
                        $("#currency_id").val(response['currency_id']).select2()
                        $("#collection_modal").modal("show")

                    });
        })
        $("#type_filter,#is_check").on("change", function () {
            ChangeTable()
        })
        $("#settle_all").on("click", function () {
            var data = {
                payments: []
            }
            $("input.change_status:checked").each(function () {
                data.payments.push($(this).attr("data-id"))
            })
            if (data.payments.length == 0) {
                toastr.error('<?php echo CommonLanguage::getMessage('choose_payments_pending') ?>')
                return false;
            }
            $.ajax({
                url: "ACCAjax/settle_payment_ajax",
                data: data,
                method: 'post',
                complete: function (v1, v2) {
                    if (v2 == 'success') {
                        if (v1.responseText == 'OK') {
                            toastr.success('<?php echo CommonLanguage::getMessage('Submitted_Successfully') ?>')
                            ChangeTable()
                        } else {
                            toastr.error('<?php echo CommonLanguage::getMessage('Failed_Submit') ?>')
                        }
                    }
                }
            })
        })
    })

    function ChangeTable() {
        var Date = {Is_Receipt: IsReceipt ? 1 : 0,
            Is_Actual: is_actual,
            is_pending: $("#type_filter").val(),
            Payment_Date_From: window.startDate ? window.startDate : today,
            Payment_Date_To: window.endDate ? window.endDate : today,
            is_check: $("#is_check").is(":checked") ? 1 : 0
        };
        RebuildDataTable(title, [0, 1, 2, 3, 4, 5, 6], "ACCAjax/PaymentDueDates", Date);
    }


</script>
