<style>
    .AddRow,.productDetailsMain{
        background: #e5e5e5;
        padding: 10px;
        border-radius: 6px;
        margin-bottom: 10px;
    }
</style>
<div class="modal fade DontReset" id="add_multi_product_modal" data-backdrop="static" >
    <div class="modal-dialog ">
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label bold"><?php echo CommonLanguage::getMessage('add_multi_product'); ?></h5>
            </div>
            <div class="modal-body">
                <!--
<div class="row">
< ?php echo Forms::AlertDiv('multi_product_alert'); ?>
</div>
-->
                <form id="add_multi_product_form" method="POST" onsubmit="return false">
                    <div class="row form-group">
                        <div class="col-md-2">
                            <label><?php echo CommonLanguage::getMessage('family'); ?></label>
                            <span class="fa fa-plus-circle m-l-5 openFrame" data-src="Inventory/family?is_pop=1" style="color:#8a7dbe;cursor:pointer"></span>
                            <input type="hidden" id="family_id" name="family_id" class="full-width empty_m">
                        </div>
                        <div class="col-md-4 m-t-20 family_product_div hidden">
                            <input type="checkbox" name="delete_old_prod" class="delete_old_prod" id="delete_old_prod">
                            <label><?php echo CommonLanguage::getMessage('delete_old_prod_family'); ?></label>
                            <br>
                            <input type="checkbox" name="auto_generate_bar_code" class="auto_generate_bar_code" id="auto_generate_bar_code">
                            <label><?php echo CommonLanguage::getMessage('auto_generate_bar_code'); ?></label>
                        </div> 
                    </div>
                    <div class="row form-group">
                        <div class="col-md-2">
                            <label><?php print CommonLanguage::getMessage('Name'); ?></label>
                            <span class="red-star">*</span>
                            <input type="text" placeholder="" id="Product_Name" name="Product_Name" class="form-control textinput empty_m" required>
                        </div>
                        <div class="col-md-2 auto_generate_code_class">
                            <label><?php print CommonLanguage::getMessage('Code'); ?></label>
                            <span class="red-star">*</span>
                            <input type="text" placeholder="" id="Product_Code" name="Product_Code" class="form-control textinput empty_m" value="" required>
                        </div>
                        <div class="col-md-2 auto_generate_code_class">
                            <label><?php print CommonLanguage::getMessage('name_separator'); ?></label>
                            <input type="text" placeholder="" id="Product_Name_Separator" name="Product_Name_Separator" class="form-control textinput empty_m" >
                        </div>
                        <div class="col-md-2 auto_generate_code_class">
                            <label><?php print CommonLanguage::getMessage('code_separator'); ?></label>
                            <input type="text" placeholder="" id="Product_Code_Separator" name="Product_Code_Separator" class="form-control textinput empty_m" value="" >
                        </div>
                        <div class="col-md-2">
                            <label><?php print CommonLanguage::getMessage('Category'); ?></label>
                            <span class="red-star">*</span>
                            <span class="fa fa-plus-circle m-l-5 openFrame" data-src="Inventory/POSCat?is_pop=1" style="color:#8a7dbe;cursor:pointer"></span>
                            <input  id="Category_ID" name="Category_ID" class="full-width Category_ID" type="hidden" required/>
                        </div>
                        <div class="col-md-2">
                            <label><?php print CommonLanguage::getMessage('UOM'); ?></label>
                            <span class="red-star">*</span>
                            <span class="fa fa-plus-circle m-l-5 openFrame" data-src="Inventory/GeneralSetting?is_pop=1&ID=2" style="color:#8a7dbe;cursor:pointer"></span>
                            <input  id="UOM_ID" name="UOM_ID" class="full-width UOM_ID" type="hidden" value="<?php echo!empty($check_uom) ? $check_uom['UOM_ID'] : '' ?>" data-select-name='<?php echo json_encode(!empty($check_uom) ? $check_uom['UOM_Name'] : ''); ?>' required/>
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-2">
                            <label><?php print CommonLanguage::getMessage('Reorder_Level'); ?></label>
                            <input type="text" placeholder="<?php print CommonLanguage::getMessage('Reorder_Level'); ?>" id="Product_Reorder_Point" name="Product_Reorder_Point" class="form-control textinput empty_m" >
                        </div>
                        <div class="col-md-2">
                            <label><?php print CommonLanguage::getMessage('max_discount'); ?></label>
                            <input type="number" step="any" id="Product_Limit_Discount" name="Product_Limit_Discount" class="full-width form-control empty_m"/>
                        </div>
                        <div class="col-md-2">
                            <label><?php print CommonLanguage::getMessage('brand_name'); ?></label><span class="fa fa-plus-circle m-l-5 openFrame" data-src="Inventory/viewBrand?is_pop=1" style="color:#8a7dbe;cursor:pointer"></span>
                            <input type="hidden" id="brand_id" name="brand_id" class="full-width"/>
                        </div>
                        <?php  if(smc_session()['default_setting']['activate_summernote_in_product'] == 0){?>
                        <div class="col-md-4">
                            <label><?php print CommonLanguage::getMessage('Description'); ?></label>
                            <textarea  id="product_description" name="product_description" class="form-control empty_m"></textarea>
                        </div>
                        <?php }?>
                    </div>
                    <?php  if(smc_session()['default_setting']['activate_summernote_in_product'] == 1){?>
                    <div class="row form-group">
                        <div class="col-md-12  ">
                            <label><?php print CommonLanguage::getMessage('Description'); ?></label>
                            <div class="summernote-wrapper m-b-10">
                                <div id="product_description"></div>
                            </div>
                        </div>
                    </div>
                    <?php }?>
                    <div class="row form-group">
                        <?php foreach ($pricing_classes as $class) { ?>
                        <div class="col-md-2 classes_price">
                            <div><label><?php print $class['Class_Name'] . ' ' . CommonLanguage::getMessage('Price') . ' - ' . $class['Currency_Symbol']; ?></label></div>
                            <input type="hidden"  value="<?php echo $class['Currency_ID'] ?>" class="form-control ignore cur_input" onkeyup="return false" onkeydown="return false"/>
                            <input type="text" placeholder="<?php print $class['Class_Name'] . ' ' . CommonLanguage::getMessage('Price'); ?>" data-class="<?php echo $class['Class_ID'] ?>"  class="form-control textinput digits price_value" >
                        </div>
                        <?php } ?>
                    </div>


                    <hr>
                    <div id="product_details">
                        <div class="col-md-12 productDetailsMain m-b-10 form-group add-row"  >
                            <?php
                            $param_arr = [];
                            if (!empty(smc_session()['default_setting']['product_param1_desc']))
                                $param_arr[1] = smc_session()['default_setting']['product_param1_desc'];
                            if (!empty(smc_session()['default_setting']['product_param2_desc']))
                                $param_arr[2] = smc_session()['default_setting']['product_param2_desc'];
                            if (!empty(smc_session()['default_setting']['product_param3_desc']))
                                $param_arr[3] = smc_session()['default_setting']['product_param3_desc'];
                            if (!empty(smc_session()['default_setting']['product_param4_desc']))
                                $param_arr[4] = smc_session()['default_setting']['product_param4_desc'];
                            ?>

                            <div class="col-md-2 pull-right form-group">
                                <label ><?php print CommonLanguage::getMessage('specification'); ?></label>
                                <input type="hidden" class="product_specification_id full-width"/>

                                <div class="<?php echo empty($param_arr) ? 'hidden' : '' ?>">
                                    <!--<br>-->
                                    <label ><?php print CommonLanguage::getMessage('save_in'); ?></label>
                                    <select class="save_in full-width" data-init-plugin="select2" >
                                        <option value="0"><?php echo CommonLanguage::getMessage('select') ?></option>
                                        <?php foreach ($param_arr as $prod_param_id => $prod_param) { ?>
                                        <option value="<?php echo $prod_param_id ?>"><?php echo $prod_param ?></option>
                                        <?php } ?>

                                    </select>
                                </div>
                            </div>
                            <div class="col-md-2 pull-right form-group">
                                <label ><?php print CommonLanguage::getMessage('show_image_upload'); ?></label>
                                <input type="checkbox" class="is_default_image_shown" name="is_default_image_shown"/> 
                                <label ><?php print CommonLanguage::getMessage('show_second_code'); ?></label>
                                <input type="checkbox" class="is_second_code_shown" name="is_second_code_shown"/>
                                <label><?php  echo CommonLanguage::getMessage('empty_specification');?></label>
                                <input type="checkbox" class="empty_specification" name="empty_specification"/>

                            </div>
                            <div class="col-md-1 pull-right AddButtons">
                                <span class="fa fa-plus" style="color:#4c0870;margin-top:15px;margin-right:25px"></span>
                                <span class="fa fa-minus" style="color:#ed9421;margin-top:15px;display:none;"></span>
                            </div>
                            <div class="col-md-7">
                                <div class="product_detail_div ">
                                    <div class="row">
                                        <div class="col-xs-3 p-l-0">
                                            <label ><?php print CommonLanguage::getMessage('Name'); ?></label>
                                        </div>
                                        <div class="col-xs-2 p-l-0 auto_generate_code_class">
                                            <label ><?php print CommonLanguage::getMessage('Code'); ?></label>
                                        </div>  
                                    </div>
                                    <div class="product-details-items">
                                        <div class="row  mp-row">
                                            <div class="col-xs-3 p-l-0">
                                                <input type="text"   name="current_product_name" class="form-control current_product_name">
                                            </div>
                                            <div class="col-xs-2 p-l-0 auto_generate_code_class">
                                                <input type="text"   name="current_product_code" class="form-control current_product_code">
                                            </div>
                                            <div class="col-xs-3 p-l-0 image_main_input hidden" >
                                            </div>
                                            <div class="col-xs-3 p-l-0 second_code_input hidden" >
                                            </div>
                                            <div class="col-xs-1 p-l-0">
                                                <span class="fa fa-plus" style="color:#4c0870;margin-top:15px;margin-right:25px"></span>
                                                <span class="fa fa-minus" style="color:#ed9421;margin-top:15px;display:none;"></span>               
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" id="CloseProduct" data-dismiss="modal"  >  <?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn btn-primary submit_multi_product" data-type="1" loader="mutli_product_loader">   <?php print CommonLanguage::getMessage('Save'); ?> </button>
                <button class="btn btn-primary submit_multi_product pull-left" data-type="2" loader="mutli_product_loader">   <?php print CommonLanguage::getMessage('view'); ?> </button>
            </div>
            <?php echo Forms::ModalLoader('mutli_product_loader'); ?>
        </div>
    </div>
</div>
<div class="modal fade " id="view_multi_product_modal" data-backdrop="static" >
    <div class="modal-dialog ">
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label bold"><?php echo CommonLanguage::getMessage('view_multi_product'); ?></h5>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12 table-responsive">
                        <table  class="table table-bordered table-hover inventory full-width" id="view_multi_product_table" >
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th><?php print CommonLanguage::getMessage('Code'); ?></th>
                                    <th><?php print CommonLanguage::getMessage('product_second_code'); ?></th>
                                    <th><?php print CommonLanguage::getMessage('Name'); ?></th>
                                </tr>
                            </thead>
                            <tfoot>
                                <tr>
                                    <th><button class="btn btn-primary full-width m-t-10" id="delete_products"><?php echo CommonLanguage::getMessage('delete'); ?></button></th>
                                    <th colspan="3"></th>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"  >  <?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn btn-primary submit_multi_product" data-type="3" loader="view_mutli_product_loader">   <?php print CommonLanguage::getMessage('Save'); ?> </button>
            </div>
            <?php echo Forms::ModalLoader('view_mutli_product_loader'); ?>
        </div>
    </div>
</div>
<script type="text/javascript">
    var deleted_products_array = [],
        check_uom = <?php echo json_encode($check_uom); ?>,
        current_separator_code = <?php echo json_encode(smc_session()['default_setting']['multi_product_separator_code']); ?>,
            current_separator_name = <?php echo json_encode(smc_session()['default_setting']['multi_product_separator_name']); ?>,
                is_sumernote = <?php echo json_encode(smc_session()['default_setting']['activate_summernote_in_product']); ?>;
                $(function () {

                    //        $('#view_multi_product_table').on('click',function(){
                    //            var current_table = $("#view_multi_product_table").DataTable();
                    //            deleted_products_array.push($(this).attr('data-current-index'));
                    //            current_table.row($(this).parents('tr')).remove();
                    //            //            $(this).parents('tr').remove()
                    //        });
                    $('#delete_products').on('click',function(){
                        var row = $("#view_multi_product_table").dataTable().fnGetNodes(),
                            current_table = $("#view_multi_product_table").DataTable();
                        for (var i = 0; i < row.length; i++) {
                            if($(row[i]).find("input.check_current_row").is(":checked")){
                                deleted_products_array.push($(row[i]).find("input.check_current_row").attr('data-current-index'));
                                current_table.row($(row[i])).remove();
                            }
                        }
                        current_table.draw();
                    });

                    $('#family_id').on('change', function () {
                        if ($(this).val()) {
                            $('#Product_Name').val($('#family_id').select2('data').text)
                            $('.family_product_div').removeClass('hidden');
                        } else{
                            $('.family_product_div').addClass('hidden');
                            $('.auto_generate_code_class').removeClass('hidden');
                            $('#auto_generate_bar_code').prop('checked',false);
                        }
                    });
                    $('#auto_generate_bar_code').on('click',function(){
                        if($(this).is(":checked")){
                            $('.auto_generate_code_class').addClass('hidden');
                            $('#Product_Code').attr('required',false);
                        }else{
                            $('.auto_generate_code_class').removeClass('hidden');
                            $('#Product_Code').attr('required',true);
                        }
                    });
                    build_select2($("#UOM_ID"), "xhr/uomSearch");
                    build_select2($("#Category_ID"), "xhr/catSearch");
                    build_select2($("input.product_specification_id"), "xhr/commonSearch?col_id=product_specification_id&col_name=product_specification_name&table=tbl_product_specification");
                    build_select2($("#family_id"), "xhr/commonSearch?col_id=family_id&col_name=family_name&table=tbl_inventory_family");
                    build_select2($("#brand_id"), "xhr/CommonSearch?col_name=brand_name&col_id=brand_id&table=tbl_brand_products");
                    $("#product_details").on("click", ".AddButtons .fa-plus", function (e) {
                        $("#product_details .AddButtons .fa-minus").css("display", "inline-block")
                        var Parent = $(this).parents(".productDetailsMain"), NewItem = Parent.clone().insertAfter(Parent);
                        $('.product-details-items .mp-row:eq(0) .fa-minus', NewItem).css("display", "none")
                        $('.product-details-items .mp-row:gt(0)', NewItem).remove()
                        NewItem.find("input").val('');
                        NewItem.find("input[name=is_default_image_shown],input[name=is_second_code_shown],input[name=empty_specification]").prop('checked', false);
                        $('.product-details-items .image_main_input,.product-details-items .second_code_input', NewItem).empty().addClass('hidden');
                        NewItem.find(".select2-container").remove()
                        build_select2(NewItem.find("input.product_specification_id"), "xhr/commonSearch?col_id=product_specification_id&col_name=product_specification_name&table=tbl_product_specification")
                        $("select.save_in",NewItem).val('0').select2()
                        $(".select2-container", NewItem).show()
                    });
                    $("#product_details").on('click', 'input[name=is_default_image_shown]', function () {
                        var index = $('input[name=is_default_image_shown]').index(this);
                        $('input[name=is_default_image_shown]').not(":eq(" + index + ")").prop('checked', false)
                        var current_checked_parent = $("input[name=is_default_image_shown]:checked").closest('.productDetailsMain');
                        $('input[name=is_default_image_shown]', current_checked_parent).prop('checked', $('input[name=is_default_image_shown]', current_checked_parent).is(":checked") ? true : false)
                        $('.product-details-items .image_main_input').empty().addClass('hidden');
                        $('.image_main_input', current_checked_parent).each(function () {
                            $('.image_main_input', current_checked_parent).empty().append('<input type="file" name="image_file"  class="image_file form-control"/>').removeClass('hidden')
                        });

                    });
                    $("#product_details").on('click', 'input[name=is_second_code_shown]', function () {
                        var index = $('input[name=is_second_code_shown]').index(this);
                        $('input[name=is_second_code_shown]').not(":eq(" + index + ")").prop('checked', false)
                        var current_checked_parent = $("input[name=is_second_code_shown]:checked").closest('.productDetailsMain');
                        $('input[name=is_second_code_shown]', current_checked_parent).prop('checked', $('input[name=is_second_code_shown]', current_checked_parent).is(":checked") ? true : false)
                        $('.product-details-items .second_code_input').empty().addClass('hidden');
                        $('.second_code_input', current_checked_parent).each(function () {
                            $('.second_code_input', current_checked_parent).empty().append('<input type="text" name="product_second_code"  class="product_second_code form-control" placeholder="Second Code"/>').removeClass('hidden')
                        });

                    }); 
                    $("#product_details").on('click', 'input[name=empty_specification]', function () {
                        if($(this).is(":checked")){
                            var current_checked_parent = $(this).closest('.productDetailsMain');
                            $('.product_detail_div .product-details-items .mp-row:gt(0)',current_checked_parent).remove();
                            $('.product-details-items .current_product_name,.product-details-items .current_product_code',current_checked_parent).val('');
                            $('.product-details-items .fa-minus',current_checked_parent).css("display", "none");
                        }
                    });
                    $("#product_details").on("change", ".product_specification_id", function () {
                        var current_parent = $(this).closest('.productDetailsMain');
                        if ($(this).val()) {
                            CommonViewById('InventoryAjax/viewProductSpecificationOptions', {product_specification_id: $(this).val()},
                                           '#product_specification_option_loader', function (response) {
                                var options = response['options'],
                                    current_row = $(".product-details-items .mp-row:eq(0)", current_parent).clone();
                                if (options.length > 0) {
                                    $(".product-details-items .mp-row", current_parent).remove()
                                    $.each(options, function (index, value) {
                                        current_row = current_row == null ? $(".product-details-items .mp-row:eq(0)", current_parent).clone() : current_row;
                                        $('input.current_product_name', current_row).val(options[index].option_name);
                                        $('input.current_product_code', current_row).val(options[index].option_code);
                                        $(".product-details-items", current_parent).append(current_row);
                                        current_row = null
                                        $(".mp-row", current_parent).each(function () {
                                            $(" .fa-minus", $(this).parents('.product-details-items')).css({"display": $(".mp-row", $(this).parents('.product-details-items')).length <= 1 ? "none" : "inline-block"})
                                        });
                                    });
                                }
                            });
                        } else {
                            $(".product-details-items .mp-row:gt(0)", current_parent).remove();
                            $(".product-details-items .fa-minus", current_parent).css({"display": 'none'});
                            $(".product-details-items input", current_parent).val('');
                        }
                        $('input[name=empty_specification]',current_parent).prop('checked',false);
                    });
                    $("#product_details").on("click", " .AddButtons .fa-minus", function (e) {
                        $(this).closest(".productDetailsMain").empty().remove();
                        $(".productDetailsMain").each(function () {
                            $(".AddButtons .fa-minus", $(this)).css({"display": $(".productDetailsMain").length <= 1 ? "none" : "inline-block"})
                        });
                    });

                    $("#product_details").on("click", ".product-details-items .fa-plus", function (e) {
                        $(".fa-minus", $(this).parents('.product-details-items')).css("display", "inline-block")
                        var Parent = $(this).parents(".mp-row"), NewItem = Parent.clone().insertAfter(Parent);
                        NewItem.find("input").val('');
                    });
                    $("#product_details").on("click", ".product-details-items .fa-minus", function (e) {
                        var parent = $(this).parents('.productDetailsMain');
                        $(this).closest(".mp-row").empty().remove();
                        $(".mp-row", parent).each(function () {
                            $(".fa-minus", $(this)).css({"display": $(".mp-row", parent).length <= 1 ? "none" : "inline-block"})
                        });
                    });


                    $(".submit_multi_product").on("click", function () {
                        var current_type = $(this).attr('data-type'),
                            loader = $(this).attr('loader');
                        var code_is_empty = false;
                        if (!$("#add_multi_product_form").valid()) {
                            return;
                        }
                        var image_index = $('.image_main_input').not('.hidden').parents('.productDetailsMain').index();
                        $('.image_main_input .image_file').each(function (index) {
                            $(this).attr('name', 'image_file_' + image_index + '_' + index);
                        });
                        var second_code_index = $('.second_code_input').not('.hidden').parents('.productDetailsMain').index();
                        $('.second_code_input .product_second_code').each(function (index) {
                            $(this).attr('name', 'product_second_code_' + second_code_index + '_' + index);
                        });
                        var Data = new FormData(document.getElementById("add_multi_product_form"));
                        var product = [], price_arr = [];
                        $('.productDetailsMain').each(function (main_index) {
                            var product_detail_arr = {
                                save_in:$("select.save_in",$(this)).val(),
                                products:[]
                            };
                            $(".mp-row", $(this)).each(function (index) {
                                if ($(".current_product_name", $(this)).val()) {
                                    product_detail_arr.products.push({name: $(".current_product_name", $(this)).val(),
                                                                      code: $(".current_product_code", $(this)).val(),
                                                                      index: index});
                                }
                                if(!$(".current_product_code", $(this)).val() && !$('#auto_generate_bar_code').is(":checked"))
                                    code_is_empty = true;
                            });
                            if (product_detail_arr.products.length > 0)
                                product.push(product_detail_arr);
                        });
                        $(".classes_price").each(function () {
                            var price = $(this).find(".price_value").val(),
                                class_id = $(this).find(".price_value").attr("data-class"),
                                currency_id = $(this).find(".cur_input").val();
                            price_arr.push({
                                price: price,
                                class_id: class_id,
                                currency_id: currency_id
                            })
                        })
                        if (product.length == 0 || code_is_empty) {
                            toastr.error("<?php echo CommonLanguage::getMessage('input_option'); ?>");
                            return;
                        }

                        Data.append('current_index', image_index < 0 ? '' : image_index);
                        Data.append('current_code_index', second_code_index < 0 ? '' : second_code_index);
                        Data.append('data', JSON.stringify(product));
                        Data.append("price_arr", JSON.stringify(price_arr));
                        Data.append('auto_generate_code',$('#family_id').val() ? ($('#auto_generate_bar_code').is(":checked") ? 1 : 0) : 0);
                        Data.append("delete_old_prod", !$('#family_id').val() ? 0 : ($('#delete_old_prod').is(":checked") ? 1 : 0));
                        Data.append("current_type",current_type);
                        Data.append("deleted_products_array", JSON.stringify(deleted_products_array));
                        if (is_sumernote == 1) {
                            Data.append("product_description", $('#product_description').code())
                        }
                        //            console.log(deleted_products_array);
                        if(current_type == 3 && $("#view_multi_product_table").dataTable().fnGetNodes().length == 0){
                            toastr.error('<?php  echo CommonLanguage::getMessage('empty_table_product');?>');
                            return;
                        }
                        //            return;
                        $("#"+loader).removeClass('hidden');
                        $.ajax({
                            url: "InventoryAjax/submitMultiProduct",
                            method: "POST",
                            data: Data,
                            dataType: "json",
                            processData: false,
                            contentType: false,
                            complete: function (jqXHR, v2) {
                                if (v2 == 'success') {
                                    if(current_type == 1 || current_type ==3){
                                        if (jqXHR.responseJSON[1] == "success") {
                                            if(current_type ==3)
                                                hideModalAlert('view_multi_product_modal');
                                            hideModalAlert('add_multi_product_modal');

                                            $('.family_product_div').addClass('hidden');
                                            $('.product-details-items .mp-row:gt(0)').remove();
                                        }
                                        toastr.success( jqXHR.responseJSON[0] == 'unable_delete_product' ? '<?php echo CommonLanguage::getMessage('unable_delete_product'); ?>' : jqXHR.responseJSON[0]);
                                    }else{
                                        deleted_products_array = [];
                                        $('#view_multi_product_modal').modal('show');
                                        $("#view_multi_product_table").DataTable().destroy();
                                        $("#view_multi_product_table tbody").empty().html(jqXHR.responseJSON[0]);
                                        RebuildDataTable($('#panel-heading .panel-title').html(), [], "", {}, '#view_multi_product_table');
                                        $("#view_multi_product_table").css({width:"100%"})
                                    }
                                }
                                $("#"+loader).addClass('hidden');
                            }
                        });
                    });
                    $("#add_multi_product_modal").on("shown.bs.modal", function () {
                        if ($('.modal.note-link-dialog:visible').length == 0) {
                            if (typeof (check_uom) == 'object') {
                                $('#UOM_ID').val(check_uom['UOM_ID']).attr('data-select-name', check_uom['UOM_Name']).trigger('change')
                            }
                            $('#Product_Code_Separator').val(current_separator_code);
                            $('#Product_Name_Separator').val(current_separator_name);
                            CommonViewById("InventoryAjax/get_max_product_code",{},'#mutli_product_loader',function(response){
                                $('#Product_Code').val(response);
                            });
                        }
                    })
                    $("#add_multi_product_modal").on("hidden.bs.modal", function () {
                        if ($('#add_multi_product_modal:visible').length == 0) {
                            $('input[name=is_default_image_shown],input[name=is_second_code_shown]').prop('checked', false);
                            $('.image_main_input,.second_code_input').empty().addClass('hidden');
                            $('.auto_generate_code_class').removeClass('hidden');
                            $('#Product_Code').attr('required',true);
                            $('.family_product_div').addClass('hidden');
                            $('select.save_in').val(0).select2();
                            $('input.price_value,#add_multi_product_modal .empty_m').val('');
                            $('#brand_id,#Category_ID,#UOM_ID,#family_id').val('').attr('data-select-name','').trigger('change');
                            $('input.product_specification_id').val('').attr('data-select-name','').trigger('change');
                            $('#auto_generate_bar_code').prop('checked',false);
                            if (is_sumernote == 1) {
                                $('#product_description').code('')
                            }
                            deleted_products_array = [];
                        }
                    });
                    if (is_sumernote == 1) {
                        $('#product_description').summernote({
                            height: 150,
                            toolbar: [
                                ['style', ['style']],
                                ['font', ['bold', 'italic', 'underline', 'clear']],
                                ['fontname', ['fontname']],
                                ['color', ['color']],
                                ['para', ['ul', 'ol', 'paragraph']],
                                ['height', ['height']],
                                ['table', ['table']],
                                ['insert', ['link', 'hr']]
                            ],
                            focus: true
                        });
                        document.onselectstart = function () {
                            return true
                        };
                    }
                });
</script>
