<style type="text/css">
    .table thead tr>th {
        background-color: #4c0870;
        color: #fff;
    }

    .table thead tr th[class*='sorting_'] {
        color: #fff;
    }

    .MonthPicker,
    .YearPicker {
        display: none;
    }

    #tableWithSearch td {
        text-align: center;
    }

    .datepicker thead tr .dow {
        color: #ed9421 !important;
    }

    .bg-master-lighter {
        border: none;
        background-color: #fff;
        border-top: 1px solid #ddd;
    }

    .datepicker table tr td.day:hover {
        background: #ed9421 !important;
        color: #fff;
    }

    .datepicker table tr td.active {
        background-color: #ed9421 !important;
    }

    .datepicker thead tr .datepicker-switch {
        color: #ed9421 !important;
        font-size: 13px;
    }

    .datepicker table tr td span.active {
        background-color: #ed9421 !important;
    }

    .datepicker table tr td span:hover {
        background-color: #ed9421 !important;
        color: #fff;
    }

    datepicker thead tr .next:before,
    .datepicker thead tr .prev:before {
        color: #ed9421 !important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }

    .datepicker thead tr .next:before,
    .datepicker thead tr .prev:before {
        color: #ed9421 !important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }

    .complete,
    .btn-group .active {
        background-color: #ed9421 !important;
        color: #fff;
    }

    .btn-default {
        border: none;
    }

    .btn-default:hover {
        background-color: #ed9421 !important;
        color: #fff;
        border: none;
    }

    #selected_entry {
        height: 90px;
        color: black;
        margin-top: 20px;
        font-size: 16px;
        padding-top: 2%;
    }

    .select_table td {
        padding-left: 70px;
    }
</style>
<script src="<?php echo THEME_PATH; ?>/plugins/moment/moment.min.js"></script>
<script src="<?php echo JS_PATH; ?>scripts.js"></script>

<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <h4 class="bold"><?php echo $IsVendor ? CommonLanguage::getMessage('debit_list') : CommonLanguage::getMessage('credit_list'); ?> </h4>

            <div class="row">
                <div class="col-md-3  <?php echo $permissions->hasPermission('Branches') ? '' : 'hidden'; ?>">
                    <label><?php echo CommonLanguage::getMessage('choose_branch') ?></label>
                    <input id="search_branch_id" type="hidden" class="full-width" name="search_branch_id" >
                </div>

                <div class="   col-md-3">
                    <span class="input-group-addon bg-complete"><i class="fa fa-calendar"></i></span>
                    <input id="From_To_Date" type="text" class="form-control" name="From_To_Date">
                </div>
            </div>


        </div>
        <div class="panel-body">
            <table class="table table-bordered table-hover demo-table-search" id="tableWithSearch">
                <thead>
                    <tr>
                        <th style="text-align:center;">#</th>
                        <th style="text-align:center;"><?php echo $IsVendor ? CommonLanguage::getMessage('Vendor') : CommonLanguage::getMessage('customer'); ?></th>
                        <th style="text-align:center;"><?php print CommonLanguage::getMessage('Date'); ?></th>
                        <th style="text-align:center;"><?php print CommonLanguage::getMessage('amount'); ?></th>
                        <th style="text-align:center;"><?php print CommonLanguage::getMessage('note'); ?></th>
                        <th style="text-align:center;"><?php print CommonLanguage::getMessage('Action'); ?></th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>

    </div>
</div>



<script>
    var ViewLang = <?php echo json_encode(CommonLanguage::getMessage('view')); ?>;
    var IsVendor = <?php echo $IsVendor ? "true" : "false" ?>,
        is_actual = <?php echo $is_actual; ?>;
    var today = <?php echo json_encode($today) ?>;
    var title = <?php echo json_encode(CommonLanguage::getMessage($IsVendor ? 'debit_list' : 'credit_list')); ?>;
    $(function() {
        build_select2($("#search_branch_id"), "xhr/CommonSearch?col_name=branch_name&col_id=branch_id&table=tbl_organization_branches");
        $('#search_branch_id').on('change', function() {
            ChangeTable();
        });

        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_cre", function() {
            var entry_value = $(this).parents('.Action').attr('data-id');
            var data = {
                id: entry_value,
                is_debit: (IsVendor ? 1 : 0)
            };
            IncludeDeleteModal(common_delete_modal, data, function() {
                ChangeTable();
            }, "ACCAjax/delete_debit_credit_note");
        })

    })

    function ChangeTable() {
        var Date = {
            Date_From: window.startDate ? window.startDate : today,
            Date_To: window.endDate ? window.endDate : today,
            Is_Debit_Note: IsVendor ? 1 : 0,
            is_actual: is_actual ? 1 : 0,
            search_branch_id: $("#search_branch_id").val(),
        };
        RebuildDataTable(title, [0, 1, 2, 3], "ACCAjax/DebitListRequest", Date);

    }
</script>