<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">
                <h4 class="bold"><?php echo CommonLanguage::getMessage($is_return ? 'sales_purchase_return_list' : 'sales_purchase_list'); ?> </h4>
            </div>
            <div class="row">
                <div class="input-group  col-md-3" >
                    <span class="input-group-addon bg-primary"><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">
            <div class="row">
                <div class="col-md-12 table-responsive" id="MyTable" >
                    <table class="table table-bordered inventory" id="tableWithSearch" >
                        <thead>
                            <tr>
                                <th class="text-center" style="width:5%" >#</th>
                                <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('customer_name'); ?></th>
                                <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('Date'); ?></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('vat'); ?></th>
                                <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('subtotal'); ?></th>
                                <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('total'); ?></th>
                                <th class="text-center " style="width:10%" ><?php print CommonLanguage::getMessage('Action'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var ViewLang = <?php echo json_encode(CommonLanguage::getMessage('view')); ?>;
    var title = <?php echo json_encode(CommonLanguage::getMessage('invoice_list')); ?>;
    var today = <?php echo json_encode($today) ?>,
            is_return = <?php echo $is_return ? "true" : "false"; ?>;
    $(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('div.Action').attr('data-id');
//            console.log(entry_value)
//            return;
            IncludeDeleteModal(common_delete_modal, {id: entry_value, is_return: (is_return ? 1 : 0)}, function () {
                ChangeTable();
            }, "InventoryAjax/delete_sales_purchase");
        });
    })
    function ChangeTable() {
        var Date = {
            Date_From: window.startDate ? window.startDate : today,
            Date_To: window.endDate ? window.endDate : today,
            is_return: is_return ? 1 : 0};
        RebuildDataTable(title, [0, 1, 2, 3, 4, 5, 6], "InventoryAjax/SalesPurchaseListRequests", Date)
    }
</script>