
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php echo CommonLanguage::getMessage($IsVendor ? 'vendor_invoice_list' : 'customer_invoice_list'); ?> </div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered inventory" id="tableWithSearch">
                            <thead>
                                <tr>
                                    <th class="text-center" style="width:5%" >#</th>
                                    <th class="text-center" style="width:5%" ><?php print CommonLanguage::getMessage('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:5%" ><?php print CommonLanguage::getMessage('vat'); ?></th>
                                    <th class="text-center" style="width:5%" ><?php print CommonLanguage::getMessage('subtotal'); ?></th>
                                    <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('total'); ?></th>
                                    <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('Action'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </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">
                <div id="delete_alert"></div>
                <h4 class="modal-title"><?php print CommonLanguage::getMessage('Confirm_Delete') ?></h4>
            </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>
<script>
    var id = <?php echo json_encode($ID) ?>,
        title = <?php echo json_encode(CommonLanguage::getMessage($IsVendor ? 'vendor_invoice_list' : 'customer_invoice_list')); ?>,
	
            Deleted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Deleted_Successfully')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
		
            IsVendor = <?php echo $IsVendor ? "true" : "false"; ?>;
			
			 var data = {Is_Vendor: IsVendor,id: id};
            $(function () {
             
                RebuildDataTable(title, [0, 1, 2, 3, 4, 5, 6], 'InventoryAjax/InvoicesPerCustomerVendor', data);
            });
			  $("#tableWithSearch").on("click", ".delete_inv", function () {
            inv_to_delete = $(this).parents(".Action").attr("data-id");
            $("#inv_nb").html($(this).parents("tr").find("td:eq(0)").text())
            $("#ConfirmDeleteInv").modal("show")
        })
    $("#inv_delete").on("click", function () {
            var new_data = [inv_to_delete]
            $.ajax({
                url: "InventoryAjax/delete_sales_invoice",
                method: "GET",
                data: {ids: new_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 = 0
                         RebuildDataTable(title, [0, 1, 2, 3, 4, 5, 6], 'InventoryAjax/InvoicesPerCustomerVendor', data);
                            setTimeout(function () {
                                $("#ConfirmDeleteInv").modal("hide")
                                $("#delete_alert").addClass("hidden")
                            }, 1500)
                        } else {
                            $("#delete_alert").attr("class", "alert alert-danger").html(v1.responseText)
                        }
                    }
                }
            })
        })
</script>