<style>
    .actionButton{
        background-color:#4c0870;
    }
</style>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading form-group">
            <div class="panel-title">
                <h4 class="bold"><?php echo $title; ?> </h4>

            </div>
            <div class="row">
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('Date') ?></label>
                    <div class="input-group">
                        <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" autocomplete="off" />
                    </div>
                </div> 
                <div class="col-md-2">
                    <label><?php echo $IsVendor ? CommonLanguage::getMessage('choose_supplier') : CommonLanguage::getMessage('choose_customer') ?></label>
                    <input id="customer_supplier_id" type="hidden" class="full-width" name="customer_supplier_id" >
                </div> 
                <div class="col-md-2 <?php echo $permissions->hasPermission('Branches') ? '':'hidden'; ?>">
                    <label><?php echo CommonLanguage::getMessage('choose_branch') ?></label>
                    <input id="current_branch_id" type="hidden" class="full-width" name="current_branch_id"   >
                </div> 
                <div class="col-md-2">
                    <label><?php echo CommonLanguage::getMessage('print') ?></label>
                    <select class="full-width" data-init-plugin="select2" id="print_filter">
                        <option value=""><?php echo CommonLanguage::getMessage('All') ?></option> 
                        <option value="1"><?php echo CommonLanguage::getMessage('invoice_with_print') ?></option> 
                        <option value="0"><?php echo CommonLanguage::getMessage('invoice_no_print') ?></option> 
                    </select>
                </div> 

                <?php if ($permissions->hasPermission('export_invoices')) { ?>
                    <div class="col-md-1 m-t-20">
                        <button class=" btn btn-primary  btn-cons full-width " id="export_invoices"  type="button" ><i class="pg-form"></i> <span class="bold"><?php print CommonLanguage::getMessage('export'); ?></span></button>
                    </div>
                    <?php
                }
                if ((!$IsVendor && $permissions->hasPermission($is_actual ? 'ActualInvoice' : 'newSalesInvoice')) || ($IsVendor && $permissions->hasPermission($is_actual ? ($is_noqty ? 'add_act_purchase_no_qty' : 'ActualPurchase') : ($is_noqty ? 'add_purchase_no_qty' : 'addpurchase')))) {
                    ?>
                    <div class="col-md-2 pull-right">    
                        <div class="floatingContainer ">
                            <a href="Inventory/addpurchase<?php echo ($IsVendor ? '' : '/sales') . ($is_actual ? '/act' : '') . ($is_noqty ? '/noqty' : '') ?>" >
                                <div class="actionButton" >
                                    <p class="floatingText"><span class="floatingTextBG"><?php echo CommonLanguage::getMessage('add') ?></span></p>
                                </div>
                            </a>
                        </div>
                    </div>
                <?php } ?>

            </div>
            <div class="row">
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('product') ?></label>
                    <input id="product_filter" type="hidden" class="full-width" name="product_filter" >
                </div> 

                <div class="col-md-2">
                    <label ><?php print CommonLanguage::getMessage($IsVendor ? 'supplier_group' : 'customer_group'); ?></label>
                    <input type="hidden"  id="group_id" name="group_id" class="full-width " >
                </div> 
                <div class="col-md-2">
                    <label ><?php print CommonLanguage::getMessage($IsVendor ? 'supplier_class' : 'customer_class'); ?></label>
                    <input type="hidden"  id="class_id" name="class_id" class="full-width " >
                </div> 
                <div class=" col-md-2 <?php echo!$IsVendor ? '' : 'hidden'; ?>">
                    <label><?php print CommonLanguage::getMessage('customer_branch'); ?></label>
                    <input type="hidden" name="customer_branch_id" id="customer_branch_id" class="full-width"/>
                </div>
                <div class=" col-md-2 <?php echo !$IsVendor ? '' : 'hidden'; ?>  <?php echo smc_session()['user_details']['limit_customer_invoice'] == 1 ? 'hidden' : ''; ?>">
                    <?php  $Employee_ID  =  smc_session()['user_details']['Employee_ID']; ?>

                    <label value="<?php echo smc_session()['user_details']['limit_customer_invoice'] == 1 ? $Employee_ID:'';?>" data-select-name="<?php echo smc_session()['user_details']['limit_customer_invoice'] == 1 ? smc_session()['user_logged_full_name']:'';?>"><?php print CommonLanguage::getMessage('salesman'); ?></label>
                    <input type="hidden" name="salesman_id" id="salesman_id" value="<?php echo smc_session()['user_details']['limit_customer_invoice'] == 1 ? $Employee_ID:'';?>" data-select-name="<?php echo smc_session()['user_details']['limit_customer_invoice'] == 1 ? smc_session()['user_logged_full_name']:'';?>" class="full-width"/>
                </div>
            </div>
            <div class="row">
                <div class="col-md-3 <?php echo $permissions->hasPermission('Depots') ? '':'hidden'; ?>">
                    <label><?php echo CommonLanguage::getMessage('Depot') ?></label>
                    <input id="depot_filter_id" type="hidden" class="full-width" name="depot_filter_id"     comment="value='<?php echo smc_session()['user_accounts']['depot_id'] ?>' data-select-name='<?php echo smc_session()['user_accounts']['Depot_Name']; ?>'" >
                </div> 
                <div class="col-md-3 <?php echo $IsVendor ? 'hidden' : ''; ?>">
                    <label><?php echo CommonLanguage::getMessage('invoice_types') ?></label>
                    <input id="invoice_type_filter" type="hidden" class="full-width" name="invoice_type_filter" >
                </div> 
                <?php if ($is_noqty && $IsVendor) { ?>
                    <div class="col-md-3 ">
                        <label><?php echo CommonLanguage::getMessage('converted_to_delivery') ?></label>
                        <select id="is_converted" class=" full-width is_converted" data-init-plugin="select2">
                            <option value="0"><?php echo CommonLanguage::getMessage('All') ?></option>
                            <option value="1"><?php echo CommonLanguage::getMessage('no') ?></option>
                            <option value="2"><?php echo CommonLanguage::getMessage('yes') ?></option>
                        </select>
                    </div> 
                <?php } ?>
                <div class="col-md-3">
                    <label><?php echo CommonLanguage::getMessage('search_note') ?></label>
                    <input id="search_note" type="text" class="form-control" name="search_note" >
                </div> 
                <div class="col-md-2">
                    <div><label><?php print CommonLanguage::getMessage('pending'); ?></label></div>
                    <div><input type="checkbox" id="is_pending" /></div>
                </div>

            </div>
        </div>
        <div class="panel-body">
            <div class="row ">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered inventory" id="tableWithSearch" >
                        <thead>
                            <tr>
                                <th class="text-center" style="width:5%" ><input type="checkbox" class="inv_check_all_td pull-left multi_delete"/>#</th>
                                <!--<th class="text-center" style="width:5%" >#</th>-->
                                <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage($IsVendor ? 'vendor_name' : '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('user_ref'); ?></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('shipping_fees'); ?></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 no-print" style="width:10%" ><?php print CommonLanguage::getMessage('Action'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                        <tfoot>
                        <th>
                            <?php if ($permissions->hasPermission($is_actual ? ($IsVendor ? ($is_noqty ? "act_purch_multi_delete_noqty" : "act_purch_multi_delete") : "act_inv_multi_delete") : ($IsVendor ? ($is_noqty ? "purch_multi_delete_noqty" : "purch_multi_delete") : "inv_multi_delete"))) { ?>
                                <button class="btn btn-primary m-b-10 full-width" id="delete_all"><?php echo CommonLanguage::getMessage('Delete'); ?></button>
                            <?php } if ($permissions->hasPermission($is_actual ? ($IsVendor ? ($is_noqty ? 'act_purch_multi_to_official_noqty' : 'act_purch_multi_to_official') : 'act_inv_multi_to_official') : ($IsVendor ? ($is_noqty ? 'purch_multi_to_actual_noqty' : "purch_multi_to_actual") : "inv_multi_to_actual"))) { ?>
                                <button class="btn btn-primary full-width" id="change_actual"><?php echo CommonLanguage::getMessage($is_actual ? 'to_official' : 'to_actual'); ?></button>
                            <?php } ?>
                        </th>
                        <!--<th></th>-->
                        <th><strong><span><?php echo CommonLanguage::getMessage('net_selected') . ': '; ?></span><br><span id="selected_total">0</span><span>&nbsp;<?php echo smc_session()['local_currency_symbol'] ?></span></strong></th>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th><div class="text-center"><strong><span id="total_sub"></span></strong></div></th>
                        <th><div class="text-center"><strong><span id="total"></span></strong></div></th>
                        <th></th>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="ConfirmDeleteInv" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header text-left">
                <h4 class="modal-title bold"><?php print CommonLanguage::getMessage('Confirm_Delete') ?></h4>
                <div id="delete_alert"></div>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12 m-t-10">
                        <p><?php print CommonLanguage::getMessage('about_delete_inv') ?>&nbsp;<span id="inv_nb" class="bold red-star"></span></p>
                        <p><?php print CommonLanguage::getMessage('Proceed_Delete') ?></p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close') ?></button>
                <button type="button" class="btn btn-danger width-auto" id="inv_delete"><?php print CommonLanguage::getMessage('delete') ?></button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="change_actual_modal" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <div id="change_act_alert"></div>
                <h4 class="modal-title"><?php print CommonLanguage::getMessage($is_actual ? 'to_official_alert' : 'to_actual_alert') ?></h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12 m-t-10">
                        <span id="act_nb" class="bold red-star"></span>
                        <p><?php print CommonLanguage::getMessage('proceed') . ' ?' ?></p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close') ?></button>
                <button type="button" class="btn btn-danger width-auto" id="change_act_btn"><?php print CommonLanguage::getMessage('proceed') ?></button>
            </div>
        </div>
    </div>
</div>
<button id="price_list_btn" class="openFrame hidden" data-src=""></button>
<script>
    var ViewLang = <?php echo json_encode(CommonLanguage::getMessage('view')); ?>,
            Deleted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Deleted_Successfully')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            data_linked_to_app = <?php echo json_encode(CommonLanguage::getMessage('data_linked_to_app')); ?>,
            invoice_linked_to_subscription = <?php echo json_encode(CommonLanguage::getMessage('invoice_linked_to_subscription')); ?>,
            invoice_linked_to_ticketing = <?php echo json_encode(CommonLanguage::getMessage('invoice_linked_to_ticketing')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>;
    var IsVendor = <?php echo $IsVendor ? "true" : "false"; ?>,
            IsSales = <?php echo $IsVendor ? "false" : "true"; ?>,
            is_noqty = <?php echo $is_noqty ? "true" : "false"; ?>,
            is_actual = <?php echo $is_actual ? "true" : "false"; ?>;
    title = <?php echo json_encode(CommonLanguage::getMessage($title)); ?>;
    var today = <?php echo json_encode($today) ?>, inv_to_delete = [], inv_nb_del = [], inv_to_change = [], inv_nb_act = [];
    $(function () {
        ChangeTable();

        build_select2($("#group_id"), "xhr/general_group_Search?group_type=" + (IsVendor ? 'supp' : 'cust'));
        build_select2($("#class_id"), "xhr/general_class_Search?class_type=" + (IsVendor ? 'supp' : 'cust'));
        build_select2($("#salesman_id"), "xhr/employeeSearch")
        build_select2($("#depot_filter_id"), "xhr/depotSearch")

        new Switchery($("#is_pending").get(0), {
            color: $.Pages.getColor("primary")
        });


        //        if (localStorage.getItem("filters") != null)
        //        console.log(JSON.parse(localStorage.getItem("filters")))
        //        console.log(get_storage_element(page_link))
        var data_session = get_storage_element(page_link);
        if (data_session.branch_name != '') {
            $("#current_branch_id").val(data_session.branch_id).attr("data-select-name", data_session.branch_name)
        }
        if (data_session.person_name != '') {
            $("#customer_supplier_id").val(data_session.customer_supplier_id).attr("data-select-name", data_session.person_name)
        }
        if (data_session.Date != '') {
            window.startDate = data_session.from_date;
            window.endDate = data_session.to_date;
            $("input[name=From_To_Date]").val(data_session.Date)
        }
        build_select2($("#product_filter"), 'xhr/ProductSearch');

        build_select2($("#current_branch_id"), "xhr/CommonSearch?col_name=branch_name&col_id=branch_id&table=tbl_organization_branches");
        build_select2($("#invoice_type_filter"), "xhr/CommonSearch?col_name=invoice_type_name&col_id=invoice_type_id&table=tbl_invoice_types");

        if (IsVendor)
            build_select2($('#customer_supplier_id'), 'xhr/supplierSearch');
        else {
            build_select2($('#customer_supplier_id'), 'xhr/customerSearch');
            build_select2($('#customer_branch_id'), 'xhr/searchCustomerBranch?customer_id=' + $("#customer_supplier_id").val());
        }
        ChangeTable();
        $("#tableWithSearch").on("click", ".go_delivery", function () {
            var type = IsSales ? 'dlc' : 'dls';
//            console.log(type)
            $("#invoice_type_id").val('').attr('data-select-name', '')
            build_select2($("#invoice_type_id"), "xhr/invoice_type_search?type=" + type + "&is_actual=" + (is_actual ? 1 : 0));

        })
        $("#tableWithSearch").on("click", "input.inv_check_all_td", function (e) {
            var is_checked = $(this).is(":checked");
            var row = $("#tableWithSearch").dataTable().fnGetNodes();
            for (var i = 0; i < row.length; i++) {
                $(row[i]).find("input.inv_del_td").prop("checked", is_checked);
            }
        });
        $("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')]
            }, locale: {
                cancelLabel: 'Clear'
            }, allowEmpty: false,
            autoUpdateInput: false
        });

        $("input[name=From_To_Date]").on('apply.daterangepicker', function (ev, picker) {
            window.startDate = picker.startDate.format('YYYY-MM-DD'),
                    window.endDate = picker.endDate.format('YYYY-MM-DD');
            $(this).val(picker.startDate.format('YYYY-MM-DD') + ' - ' + picker.endDate.format('YYYY-MM-DD'));
            ChangeTable();
        });
        $("input[name=From_To_Date]").on('cancel.daterangepicker', function (ev, picker) {
            window.startDate = ''
            window.endDate = ''
            $(this).val('');
            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();
        //        });
        $('#current_branch_id,#print_filter,#product_filter,#group_id,#class_id,#customer_branch_id,#salesman_id,#depot_filter_id,#invoice_type_filter,#is_converted').on('change', function () {
            ChangeTable();
        });

        $(document).on('keydown', function (e) {
            if (e.which == 13)
                ChangeTable();
        });
        
        $('#is_pending').on('change', function () {
            ChangeTable();
        });

        $('#customer_supplier_id').on('change', function () {
            if (!IsVendor) {
                $('#customer_branch_id').val('');
                build_select2($('#customer_branch_id'), 'xhr/searchCustomerBranch?customer_id=' + $("#customer_supplier_id").val());
            }
            ChangeTable();
        });
        $("#export_invoices").on("click", function () {
            var is_actual = is_actual ? 1 : 0,
                    from = window.startDate ? window.startDate : today,
                    to = window.endDate ? window.endDate : today
            //            };
            $('#export_excel_iframe').remove();
            $("<iframe id='export_excel_iframe' style='display:none;' src='InventoryAjax/export_invoices?from=" + from + "&to=" + to + "&is_actual=" + is_actual + "'></iframe>").appendTo('body');
        })
        //        $("#tableWithSearch").on("click", ".adjust_prices", function () {
        //            $.ajax({
        //                url: "InventoryAjax/get_purchase_item_ids",
        //                data: {id: $(this).parents(".Action").attr("data-id")},
        //                complete: function (v1, v2) {
        //                    if (v2 == 'success') {
        //                        var url = 'Inventory/PricingList?is_pop=1&id=' + v1.responseText;
        //                        $("#price_list_btn").attr("data-src",url).trigger("click")
        //                    }
        //                }
        //            })
        //        })
        $("#tableWithSearch").on("click", ".change_actual", function () {
            inv_to_change = [$(this).parents(".Action").attr("data-id")];
            $("#act_nb").html($(this).parents("tr").find("td:eq(0)").text())
            $("#change_actual_modal").modal("show")
        })
        $("#change_actual").on("click", function () {
            inv_to_change = []
            inv_nb_act = []
            $("#tableWithSearch .inv_del_td:checked").each(function () {
                inv_to_change.push($(this).attr("data-id"));
                inv_nb_act.push($(this).attr("data-nb"));
            })
            if ($("#tableWithSearch .inv_del_td:checked").length > 0) {
                $("#act_nb").html(inv_nb_act.join())
                $("#change_actual_modal").modal("show")
            }
        })
        $("#change_act_btn").on("click", function () {
            $.ajax({
                url: IsVendor ? "InventoryAjax/change_purchase_actual" : "InventoryAjax/change_invoice_actual",
                method: "POST",
                data: {id: inv_to_change, is_actual: is_actual ? 0 : 1},
                complete: function (v1, v2) {
                    if (v2 == 'success') {
                        if (v1.responseText == 'OK') {
                            $("#change_act_alert").attr("class", "alert alert-success").html(Submitted_Successfully)
                            inv_to_change = []
                            ChangeTable()
                            setTimeout(function () {
                                $("#change_actual_modal").modal("hide")
                                $("#change_act_alert").addClass("hidden")
                            }, 1500)
                        } else {
                            $("#change_act_alert").attr("class", "alert alert-danger").html(v1.responseText)
                        }
                    }
                }
            })
        })
        $("#tableWithSearch").on("input", '.inv_del_td ', function () {
            get_total_selected()
        })
        $("#delete_all").on("click", function () {
            get_total_selected()
            inv_to_delete = []
            inv_nb_del = []
            $("#tableWithSearch .inv_del_td:checked").each(function () {
                inv_to_delete.push($(this).attr("data-id"));
                inv_nb_del.push($(this).attr("data-nb"));
            })
            if ($("#tableWithSearch .inv_del_td:checked").length > 0) {
                $("#inv_nb").html(inv_nb_del.join())
                $("#ConfirmDeleteInv").modal("show")
            }
        })
        $("#tableWithSearch").on("click", ".delete_inv", function () {
            $('#inv_delete').attr('disabled', false);
            inv_to_delete = [$(this).parents(".Action").attr("data-id")];
            $("#inv_nb").html($(this).parents("tr").find("td:eq(0)").text())
            if ($(this).attr('data-invoice-app-id') != 0)
                $("#delete_alert").attr("class", "alert alert-danger").html(data_linked_to_app)
            if ($(this).attr('data-subscription-fees-id')) {
                $("#delete_alert").attr("class", "alert alert-danger").html(invoice_linked_to_subscription);
                $('#inv_delete').attr('disabled', true);
            }
            if ($(this).attr('data-ticketing-id')) {
                $("#delete_alert").attr("class", "alert alert-danger").html(invoice_linked_to_ticketing);
                $('#inv_delete').attr('disabled', true);
            }
            $("#ConfirmDeleteInv").modal("show");
        })
        $("#inv_delete").on("click", function () {
            var data = inv_to_delete
            $.ajax({
                url: "InventoryAjax/delete_sales_invoice",
                method: "GET",
                data: {ids: data, is_purchase: IsVendor ? 1 : 0},
                complete: function (v1, v2) {
                    if (v2 == 'success') {
                        if (v1.responseText == 'ok') {
                            $("#delete_alert").attr("class", "alert alert-success").html(Deleted_Successfully)
                            inv_to_delete = []
                            ChangeTable()
                            setTimeout(function () {
                                $("#ConfirmDeleteInv").modal("hide")
                                $("#delete_alert").addClass("hidden")
                            }, 1500)
                        } else {
                            $("#delete_alert").attr("class", "alert alert-danger").html(v1.responseText)
                        }
                    }
                }
            });
        });
        $('#ConfirmDeleteInv').on('hidden.bs.modal', function () {
            $("#delete_alert").attr("class", "").html('')
        });
    })
    function ChangeTable() {

        var Data = {
            IsVendor: IsVendor,
            is_actual: is_actual ? 1 : 0,
            is_pending: $("#is_pending").is(":checked") ? 1 : 0,
            customer_supplier_id: $('#customer_supplier_id').val(),
            person_name: ($("#customer_supplier_id").select2('data') == null ? '' : $("#customer_supplier_id").select2('data').text),
            branch_id: $('#current_branch_id').val(),
            branch_name: ($("#current_branch_id").select2('data') == null ? '' : $("#current_branch_id").select2('data').text),
            Date: $("input[name=From_To_Date]").val(),
            from_date: window.startDate,
            to_date: window.endDate,
            print_filter: $('#print_filter').val(),
            product_id: $('#product_filter').val(),
            class_id: $('#class_id').val(),
            group_id: $('#group_id').val(),
            salesman_id: $('#salesman_id').val(),
            depot_id: $('#depot_filter_id').val(),
            customer_branch_id: $('#customer_branch_id').val(),
            is_noqty: is_noqty ? 1 : 0,
            invoice_type_id: $('#invoice_type_filter').val(),
            is_converted: $('#is_converted').val(),
            search_note:$("#search_note").val()
        }

        set_storage_element(page_link, Data)

        //        localStorage.setItem("filters", JSON.stringify(Data));
        $.ajax({
            url: "InventoryAjax/get_total_sales_purchase_invoices",
            data: Data,
            dataType: 'JSON',
            complete: function (v1, v2) {
                if (v2 == "success") {
                    var optns = {
                        cb_ft: function (dt_optns) {
                            // stop sorting for column since on click on header checkbox the sorting is triggered
                            dt_optns.columnDefs.push({targets: [0], "orderable": false});
                        },
                    };
                    RebuildDataTable(title, [0, 1, 2, 3, 4, 5, 6], "InventoryAjax/InvoiceListRequests", Data, '', '', optns);
                    $("#total").html(v1.responseJSON['total']);
                    $("#total_sub").html(v1.responseJSON['sub_total']);
                }
            }
        })
    }
    function get_total_selected() {
        var selected_total = 0;
        $("#selected_total").text('0');
        $("#tableWithSearch .inv_del_td:checked").each(function () {
            selected_total += parseFloat($(this).attr("data-total"));
            $("#selected_total").text(AddCommas(selected_total.toFixed(3)));
        })
    }
</script>
<?php
include 'Views/Inventory/general_invoice_type_modal.php';
