<div class="modal fade" id="general_invoice_type_modal" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="text-left bold"> <?php echo CommonLanguage::getMessage('Type'); ?></h5>
            </div>
            <div class="modal-body">
                <div class="row">
                    <?php echo Forms::AlertDiv('general_invoice_type_alert'); ?>
                </div>
                <form id="general_invoice_type_form" method="POST" onsubmit="return false">
                    <input type='hidden' name='current_url' id='current_url'/>
                    <div class="row form-group m-t-10">
                        <div class="col-md-12">
                            <label><?php print CommonLanguage::getMessage('Type'); ?></label>
                            <span class="red-star">*</span>
                            <input type="hidden"  id="invoice_type_id" name="invoice_type_id" class="full-width "  required>
                        </div>
                    </div> 
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn btn-primary" id="submit_general_invoice_type"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('general_invoice_type_loader'); ?>
        </div>
    </div>
</div>
<script>
    var inv_pur_types = <?php echo json_encode($inv_pur_types); ?>,
            del_types = <?php echo json_encode($del_types); ?>,
            noqty_types = <?php echo json_encode($noqty_types); ?>,
            order_types = <?php echo json_encode($order_types); ?>;
    $(function () {
        build_select2($("#invoice_type_id"), "xhr/invoice_type_search");
        $('#tableWithSearch').on('click', '.copy_to_invoice_purchase,.go_to_invoice,.go_delivery,.go_noqty,.go_order', function () {
            var temp_arr;
            if ($(this).hasClass('go_to_invoice') || $(this).hasClass('copy_to_invoice_purchase')) {
                temp_arr = inv_pur_types;
            }
            if ($(this).hasClass('go_delivery')) {
                temp_arr = del_types;
            }
            if ($(this).hasClass('go_order')) {
                temp_arr = order_types;
            }
            if ($(this).hasClass('go_noqty')) {
                temp_arr = noqty_types;
            }
//        console.log(temp_arr)


//            if (temp_arr.length > 0 && $(this).attr('data-type') == 1) {
            if (temp_arr.length > 0) {
                $('#current_url').val($(this).attr('link'));
                $('#general_invoice_type_modal').modal('show');
            } else {
                window.location = site_link + $(this).attr('link');
            }
        });
        $("#submit_general_invoice_type").on("click", function () {
            if (!$("#general_invoice_type_form").valid())
                return;
            $("#general_invoice_type_loader").removeClass('hidden');
            var Data = new FormData(document.getElementById("general_invoice_type_form"));
            window.location = site_link + $('#current_url').val() + '?invoice_type=' + $('#invoice_type_id').val();
            //            $.ajax({
            //                url: "InventoryAjax/submitGeneralInvoiceType",
            //                method: "POST",
            //                data: Data,
            //                processData: false,
            //                contentType: false,
            //                dataType: "JSON",
            //                complete: function (jqXHR, status) {
            //                    if (status == 'success') {
            //                        if (jqXHR.responseJSON[1] == "success") {
            //                            hideModalAlert('general_invoice_type_modal', 'general_invoice_type_alert');
            //                        }
            //                        AddAlert("#general_invoice_type_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
            //                    }
            //                    $("#general_invoice_type_loader").addClass('hidden');
            //                }
            //            });
        });
    });
</script>