<style>
    .nav-tabs-fillup>li>a:after {
        background: none repeat scroll 0 0 #4c0870 !important;
        border: 1px solid #4c0870 !important;
    }

    .dropdown-menu>li>a {
        cursor: pointer;
    }

    input.wrong {
        border: 1px solid rgba(255, 0, 0, 0.2);
        background: rgba(255, 0, 0, 0.05);
        /*        width:100%;*/
    }

    .profile-pic {
        text-align: center;
        border-radius: 100%;
        -moz-border-radius: 100%;
        -webkit-border-radius: 100%;
        width: 210px;
        height: 210px;
        border: 5px solid #4c0870;
        overflow: hidden;
        margin-left: 0px;
        margin: 0px auto;
        background: #fafafa;
    }

    .profile-pic img {
        width: 188px;
        height: 188px;
        margin-top: 6px;
        border-radius: 100%;
        -moz-border-radius: 100%;
        -webkit-border-radius: 100%;
        overflow: hidden;
        -webkit-transition: all .3s ease-in-out;
        -moz-transition: all .3s ease-in-out;
        transition: all .3s ease-in-out;
    }

    #NewProductUploadPhoto {
        width: 25%;
        overflow: hidden;
        position: relative;
    }

    #NewProductUploadPhoto {
        /*margin-left:128px;
        margin-top:10px;*/
        margin: 10px auto;
        background-color: #4c0870 !important;
        color: #fff;
        width: auto;
        display: block;
    }

    #NewProductUploadPhoto>input,
    #NewProductUploadPhoto>input {
        position: absolute;
        left: 0px;
        top: 0px;
        width: 100%;
        height: 100%;
        opacity: 0.01;
        cursor: pointer;
    }

    .DropDownForForms>.dropdown-menu {
        height: auto;
        cursor: pointer;
        overflow-y: auto;
        width: 100%;
    }

    .AddRow,
    .AddCriteriaRow {
        background: #e5e5e5;
        padding: 10px;
        border-radius: 6px;
        margin-bottom: 10px;
    }
</style>
<?php
$product_required_fields = smc_session()['default_setting']['product_required_fields'] != '' ? explode(",", smc_session()['default_setting']['product_required_fields']) : [];
?>
<link href="<?php echo LIBS_URL; ?>summernote/summernote.css" rel="stylesheet">
<script src="<?php echo LIBS_URL; ?>summernote/summernote.min.js"></script>
<div class="modal fade" id="addProduct" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog ">
        <?php echo Forms::ModalLoader('ProductIsBusy') ?>
        <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('new_product'); ?></h5>
                <div id="ProductValidationAlert"></div>
            </div>
            <input id="enable_category_barcode" value="<?php echo smc_session()['default_setting']['enable_category_barcode']; ?>" hidden>
            <div class="modal-body">
                <form id="AddProductPostForm" method="POST" onsubmit="return false">
                    <div class="panel panel-transparent ">
                        <ul class="nav nav-tabs nav-tabs-fillup">
                            <li class="active">
                                <a data-toggle="tab" href="#slide1"><span><?php print CommonLanguage::getMessage('product_info'); ?></span></a>
                            </li>
                            <li>
                                <a data-toggle="tab" href="#slide2"><span><?php print CommonLanguage::getMessage('uom_conversion'); ?></span></a>
                            </li>
                            <li>
                                <a data-toggle="tab" href="#slide3"><span><?php print CommonLanguage::getMessage('product_links'); ?></span></a>
                            </li>
                            <li>
                                <a data-toggle="tab" href="#slide4"><span><?php print CommonLanguage::getMessage('product_shelfs'); ?></span></a>
                            </li>
                            <li class="<?php echo smc_session()['default_setting']['is_tag_active'] == 1 ? '' : 'hidden'; ?>">
                                <a data-toggle="tab" href="#slide5"><span><?php print CommonLanguage::getMessage('product_criteria'); ?></span></a>
                            </li>
                            <li class="<?php echo smc_session()['default_setting']['is_add_ons_active'] == 1 ? '' : 'hidden'; ?>">
                                <a data-toggle="tab" href="#slide6"><span><?php print CommonLanguage::getMessage('add_ons'); ?></span></a>
                            </li>
                            <li>
                                <a data-toggle="tab" href="#slide7"><span><?php print CommonLanguage::getMessage('maintenance'); ?></span></a>
                            </li>
                        </ul>
                        <div class="tab-content">
                            <div class="tab-pane slide-left active" id="slide1">
                                <div class="row">
                                    <div class="col-md-3">
                                        <div class="profile-pic">
                                            <div class="profile-border">
                                                <img id="NewProductUploadImagePreview" src="<?php echo SITE_LINK; ?>img/profiles/product.png" alt="">
                                            </div>
                                        </div>
                                        <label class="btn btn-default" id="NewProductUploadPhoto"><?php print CommonLanguage::getMessage('Upload'); ?><input type="file" data-target="#NewProductUploadImagePreview" onchange="window.NewProductCurrentFileUploadaddProduct = event.target.files;ValidateForNewProductPhoto(this, 'Picture')" name="image_file" value="Upload"></label>
                                    </div>
                                    <div class="col-md-9">
                                        <div class="row form-group">
                                            <div class="col-md-4">
                                                <label><?php print CommonLanguage::getMessage('Code'); ?></label><span class="red-star">*</span>
                                                <input type="text" placeholder="<?php print CommonLanguage::getMessage('Code'); ?>" id="Product_Code" name="Product_Code" class="form-control textinput" value="<?php echo smc_session()['auto_generate_code'] == 1 ? $max_code : '' ?>" required>
                                            </div>
                                            <div class="col-md-4">
                                                <label><?php print CommonLanguage::getMessage('Name'); ?></label><span class="red-star">*</span>
                                                <input type="text" placeholder="<?php print CommonLanguage::getMessage('Name'); ?>" id="Product_Name" name="Product_Name" class="form-control textinput" required>
                                            </div>
                                            <div class="col-md-4">
                                                <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 required id="Category_ID" name="Category_ID" class="full-width Category_ID" type="hidden" />
                                            </div>
                                        </div>
                                        <div class="row form-group">
                                            <div class="col-md-4">
                                                <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 required 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="<?= json_encode(!empty($check_uom) ? $check_uom['UOM_Name'] : '') ?>" />
                                            </div>
                                            <div class="col-md-4">
                                                <label><?php print CommonLanguage::getMessage('barcode'); ?></label>
                                                <span class="red-star  <?php echo !in_array(8, $product_required_fields) ? 'hidden' : '' ?>">*</span>
                                                <span style="color:red">(<?php echo CommonLanguage::getMessage('barcode_5char') ?>)</span>
                                                <span class="fa fa-retweet generate_barcode" style="cursor: pointer;"></span>
                                                <input type="text" placeholder="<?php print CommonLanguage::getMessage('barcode'); ?>" id="Bar_Code" name="Bar_Code" class="form-control textinput" <?php echo !in_array(8, $product_required_fields) ? '' : 'required' ?>>
                                            </div>
                                            <div class="col-md-4">
                                                <label><?php print CommonLanguage::getMessage('arabic_name'); ?></label>
                                                <input type="text" placeholder="<?php print CommonLanguage::getMessage('arabic_name'); ?>" id="Product_Arabic_Name" name="Product_Arabic_Name" class="form-control textinput">
                                            </div>
                                        </div>
                                        <div class="row form-group">
                                            <div class="col-md-4">
                                                <label><?php print CommonLanguage::getMessage('pur_cat'); ?><span class="red-star <?php echo !in_array(0, $product_required_fields) ? 'hidden' : '' ?>">*</span></label><span class="fa fa-plus-circle m-l-5 openFrame" data-src="Inventory/purchase_cat_list?is_pop=1" style="color:#8a7dbe;cursor:pointer"></span>
                                                <input id="pur_cat_id" name="pur_cat_id" class="full-width pur_cat_id" type="hidden" <?php echo !in_array(0, $product_required_fields) ? '' : 'required' ?> />
                                            </div>

                                            <div class="col-md-4 <?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-4  <?php echo smc_session()['default_setting']['points_for_products'] == 1 ? '' : 'hidden'; ?> ">
                                                <label><?php print CommonLanguage::getMessage('positive_points'); ?></label>
                                                <input type="text" placeholder="<?php print CommonLanguage::getMessage('positive_points'); ?>" id="positive_points" name="positive_points" class="form-control textinput">
                                            </div>

                                            <div class="col-md-4 <?php echo smc_session()['default_setting']['points_for_products'] == 1 ? '' : 'hidden'; ?> ">
                                                <label><?php print CommonLanguage::getMessage('negative_points'); ?></label>
                                                <input type="text" placeholder="<?php print CommonLanguage::getMessage('negative_points'); ?>" id="negative_points" name="negative_points" class="form-control textinput">
                                            </div>
                                            
                                        </div> 
                                        <div class="row form-group  <?php echo smc_session()['default_setting']['enable_kabalan_height_width'] ? '' : 'hidden' ?> ">

                                            <div class="col-md-4">
                                                <label><?php print CommonLanguage::getMessage('n_width'); ?></label>
                                                <input type="text" placeholder="<?php print CommonLanguage::getMessage('n_width'); ?>" id="n_width" name="n_width" class="form-control textinput" >
                                            </div>
                                            <div class="col-md-4">
                                                <label><?php print CommonLanguage::getMessage('n_height'); ?></label>
                                                <input type="text" placeholder="<?php print CommonLanguage::getMessage('n_height'); ?>" id="n_height" name="n_height" class="form-control textinput" >
                                            </div>

                                        </div>

                                        <hr class="b-dashed">
                                        <div class="row form-group">
                                            <div class="col-md-4">
                                                <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">
                                            </div>
                                            <div class="col-md-4">
                                                <label><?php print CommonLanguage::getMessage('Printers'); ?><span class="red-star  <?php echo !in_array(1, $product_required_fields) ? 'hidden' : '' ?>">*</span></label>
                                                <select <?php echo !in_array(1, $product_required_fields) ? '' : 'required' ?> id="printer_id" name="printer_id" multiple class="full-width " data-init-plugin="select2">
                                                    <?php foreach ($printers as $printer) : ?>
                                                        <option value="<?php echo $printer['printer_id']; ?>"><?php echo $printer['printer_title']; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </div>
                                            <div class="col-md-4">
                                                <label><?php print CommonLanguage::getMessage('family'); ?><span class="red-star  <?php echo !in_array(2, $product_required_fields) ? 'hidden' : '' ?>">*</span></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 id="family_id" name="family_id" class="full-width family_id" type="hidden" <?php echo !in_array(2, $product_required_fields) ? '' : 'required' ?> />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <div class="col-md-3 ">
                                        <label><?php print CommonLanguage::getMessage('product_second_code'); ?><span class="red-star  <?php echo !in_array(3, $product_required_fields) ? 'hidden' : '' ?>">*</span></label>
                                        <input type="text" id="product_second_code" name="product_second_code" class="form-control" <?php echo !in_array(3, $product_required_fields) ? '' : 'required' ?> />
                                    </div>
                                    <div class="col-md-3">
                                        <label><?php print CommonLanguage::getMessage('section'); ?></label>
                                        <span class="fa fa-plus-circle m-l-5 openFrame" data-src="Inventory/product_sections?is_pop=1" style="color:#8a7dbe;cursor:pointer"></span>
                                        <input type="hidden" id="section_id" name="section_id" class="full-width" />
                                    </div>
                                    <div class="col-md-3">
                                        <label><?php echo CommonLanguage::getMessage('main_supplier') ?><span class="red-star  <?php echo !in_array(4, $product_required_fields) ? 'hidden' : '' ?>">*</span></label>
                                        <input type="hidden" id="main_supplier_id" name="main_supplier_id" class="full-width" <?php echo !in_array(4, $product_required_fields) ? '' : 'required' ?> />
                                    </div>
                                    <div class="col-md-3">
                                        <label><?php print CommonLanguage::getMessage('brand_name'); ?><span class="red-star  <?php echo !in_array(5, $product_required_fields) ? 'hidden' : '' ?>">*</span></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" <?php echo !in_array(5, $product_required_fields) ? '' : 'required' ?> />
                                    </div>

                                </div>
                                <div class="row form-group">
                                    <div class="col-md-3">
                                        <label><?php print CommonLanguage::getMessage('group_account'); ?><span class="red-star  <?php echo !in_array(6, $product_required_fields) ? 'hidden' : '' ?>">*</span></label>
                                        <input type="hidden" id="group_account_id" name="group_account_id" class="full-width" <?php echo !in_array(6, $product_required_fields) ? '' : 'required' ?> />
                                    </div>
                                    <div class="col-md-3">
                                        <label><?php print CommonLanguage::getMessage('Type'); ?></label>
                                        <select id="product_type" name="product_type" class="full-width" data-init-plugin="select2">
                                            <option value="0"><?php echo CommonLanguage::getMessage('sales_purchase') ?></option>
                                            <option value="1"><?php echo CommonLanguage::getMessage('sales') ?></option>
                                            <option value="2"><?php echo CommonLanguage::getMessage('purchase') ?></option>
                                        </select>
                                    </div>
                                    <div class="col-md-3">
                                        <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" />
                                    </div>
                                    <div class="col-md-3">
                                        <label><?php echo CommonLanguage::getMessage('color'); ?></label>
                                        <input type="text" name="product_color" id="product_color" value="#4c0870" class="form-control" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <div class="col-md-3">
                                        <label><?php echo CommonLanguage::getMessage('sort_order'); ?></label>
                                        <input type="number" name="product_order" id="product_order" class="form-control" />
                                    </div>
                                    <div class="col-md-2">
                                        <div> <label><?php print CommonLanguage::getMessage('weightable') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="plu_type" name="plu_type" />
                                    </div>
                                    <div class="col-md-2">
                                        <div><label><?php print CommonLanguage::getMessage('move_scale'); ?></label></div>
                                        <input type="checkbox" id="move_scale" name="move_scale" />
                                    </div>
                                    <div class="col-md-2 ">
                                        <div><label><?php print CommonLanguage::getMessage('force_change_price') . '?'; ?></label></div>
                                        <input type="checkbox" id="force_change_price" name="force_change_price" />
                                    </div>
                                    <div class="col-md-2  <?php echo smc_session()['default_setting']['activate_product_duration_reservation'] ? '' : 'hidden' ?>">
                                        <div><label><?php print CommonLanguage::getMessage('duration_reservation') . '?'; ?></label></div>
                                        <input type="checkbox" id="duration_reservation" name="duration_reservation" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <div class="col-md-1 <?php echo smc_session()['default_setting']['activate_card_tax'] == 0 ? 'hidden' : ''; ?>">
                                        <div><label><?php print CommonLanguage::getMessage('is_card'); ?></label></div>
                                        <input type="checkbox" id="is_card" name="is_card" />
                                    </div>
                                    <div class="col-md-1 <?php echo smc_session()['default_setting']['activate_product_lot_nb'] == 1 ? '' : 'hidden' ?>">
                                        <div><label><?php print CommonLanguage::getMessage('lot') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="is_lot" name="is_lot" />
                                    </div>
                                    <div class="col-md-1 <?php echo smc_session()['default_setting']['activate_product_serial_nb'] == 1 ? '' : 'hidden' ?>">
                                        <div><label><?php print CommonLanguage::getMessage('serial') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="is_serial" name="is_serial" />
                                    </div>
                                    <div class="col-md-1 <?php echo smc_session()['default_setting']['activate_product_ticket'] == 1 ? '' : 'hidden' ?>">
                                        <div><label><?php print CommonLanguage::getMessage('ticket') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="is_ticket" name="is_ticket" />
                                    </div>
                                    <div class="col-md-1 ">
                                        <div><label><?php print CommonLanguage::getMessage('service') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="is_service" name="is_service" />
                                    </div>
                                    <div class="col-md-2 <?php echo smc_session()['default_setting']['activate_expiry_date'] == 0 ? 'hidden' : ''; ?>">
                                        <div><label><?php print CommonLanguage::getMessage('Expiry') . '?'; ?></label></div>
                                        <input type="checkbox" id="is_expiry" name="is_expiry" />
                                    </div>
                                    <div class="col-md-1">
                                        <div><label><?php print CommonLanguage::getMessage('Taxable'); ?></label></div>
                                        <input type="checkbox" id="VAT" name="VAT" />
                                    </div>
                                    <div class="col-md-2 ">
                                        <div><label><?php print CommonLanguage::getMessage('product_rate') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="is_rate" name="is_rate" />
                                    </div>

                                    <div class="col-md-2 <?php echo $permissions->hasPermission('is_rate_type_one') ? '':'hidden'; ?>">
                                        <div><label><?php print CommonLanguage::getMessage('is_rate_type_one') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="is_rate_type_one" name="is_rate_type_one" />
                                    </div>
                                    <div class="col-md-2 <?php echo $permissions->hasPermission('is_rate_type_two') ? '':'hidden'; ?>">
                                        <div><label><?php print CommonLanguage::getMessage('is_rate_type_two') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="is_rate_type_two" name="is_rate_type_two" />
                                    </div>
                                    <div class="col-md-2 <?php echo $permissions->hasPermission('effect_qty_link_product') ? '':'hidden'; ?>">
                                        <div><label><?php print CommonLanguage::getMessage('effect_qty_link_product') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="effect_qty_link_product" name="effect_qty_link_product" />
                                    </div>

                                    <div class="col-md-2 <?php echo $permissions->hasPermission('hide_pos') ? '' : 'hidden'; ?>">
                                        <div><label><?php print CommonLanguage::getMessage('hide_pos') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="hide_pos" name="hide_pos" />
                                    </div>

                                    <div class="col-md-1 vatPercentDiv hidden ">
                                        <label><?php print CommonLanguage::getMessage('vat_percent'); ?></label>
                                        <input type="text " id="vat_percent" class="form-control" name="vat_percent" />
                                    </div>
                                    <div class="col-md-1 vat2PercentDiv hidden ">
                                        <label><?php print CommonLanguage::getMessage('vat2_percent'); ?></label>
                                        <input type="text " id="vat2_percent" class="form-control" name="vat2_percent" />
                                    </div>


                                </div>


                                <?php
                                $i = 1;
                                foreach ($pricing_classes as $class) {
                                ?>
                                    <?php if ($i % 4 == 1) { ?><div class="row form-group "><?php } ?>
                                        <div class="col-md-3 classes_price">
                                            <label><?php print $class['Class_Name'] . ' ' . CommonLanguage::getMessage('Price') . ' - ' . $class['Currency_Symbol']; ?></label>
                                            <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 if ($i % 4 == 0 || $i == count($pricing_classes)) { ?>
                                        </div><?php } ?>
                                <?php
                                    $i++;
                                }
                                ?>
                                <div class="row form-group">
                                    <div class="col-md-<?php echo smc_session()['default_setting']['activate_summernote_in_product'] == 1 ? '12' : '6' ?>">
                                        <label><?php print CommonLanguage::getMessage('Description'); ?></label>
                                        <?php if (smc_session()['default_setting']['activate_summernote_in_product'] == 1) { ?>
                                            <div class="col-md-12  summernote-wrapper m-b-10">
                                                <div id="product_description" name="product_description"></div>
                                            </div>
                                        <?php } else { ?>
                                            <textarea class="form-control " id="product_description" name="product_description" style="overflow: hidden; word-wrap: break-word; resize:vertical "></textarea>
                                        <?php } ?>
                                    </div>
                                    <div class="col-md-6">
                                        <label><?php print CommonLanguage::getMessage('additional_barcodes'); ?></label>
                                        <span class="red-star">(<?php echo CommonLanguage::getMessage('barcode_delimeter') ?>)</span>
                                        <textarea class="form-control " id="additional_barcodes" name="additional_barcodes" style="overflow: hidden; word-wrap: break-word; resize:vertical "></textarea>
                                    </div>
                                </div>
                                <hr>
                                <div class="row form-group">
                                    <?php if (!empty(smc_session()['default_setting']['product_param1_desc'])) { ?>
                                        <div class="col-md-3">
                                            <label><?php echo smc_session()['default_setting']['product_param1_desc']; ?></label>
                                            <input type="text" class="form-control" id="product_param1" name="product_param1" />
                                        </div>
                                    <?php }
                                    if (!empty(smc_session()['default_setting']['product_param2_desc'])) { ?>
                                        <div class="col-md-3">
                                            <label><?php echo smc_session()['default_setting']['product_param2_desc']; ?></label>
                                            <input type="text" class="form-control" id="product_param2" name="product_param2" />
                                        </div>
                                    <?php }
                                    if (!empty(smc_session()['default_setting']['product_param3_desc'])) { ?>
                                        <div class="col-md-3">
                                            <label><?php echo smc_session()['default_setting']['product_param3_desc']; ?></label>
                                            <input type="text" class="form-control" id="product_param3" name="product_param3" />
                                        </div>
                                    <?php }
                                    if (!empty(smc_session()['default_setting']['product_param4_desc'])) { ?>
                                        <div class="col-md-3">
                                            <label><?php echo smc_session()['default_setting']['product_param4_desc']; ?></label>
                                            <input type="text" class="form-control" id="product_param4" name="product_param4" />
                                        </div>
                                    <?php } ?>
                                </div>
                            </div>
                            <div class="tab-pane slide-left " id="slide2">
                                <h3><?php echo CommonLanguage::getMessage('default_uom') ?>:&nbsp<span id="default_uom_span"></span></h3>
                                <div class="col-md-12" id="UOMConForm">
                                    <div class="col-md-12 AddRow m-b-10 form-group">
                                        <div class="col-md-7">
                                            <div class="row">
                                                <div class="col-xs-4 ">
                                                    <label><?php echo CommonLanguage::getMessage('From') ?><span class="red-star">*</span></label>
                                                    <select name="UOM_From" class="full-width UOM_From" data-init-plugin="select2">
                                                        <option selected value=""><?php echo CommonLanguage::getMessage('Select_UOM') ?></option>
                                                        <?php foreach ($all_uom as $uom) : ?>
                                                            <option value="<?php echo $uom['UOM_ID']; ?>"><?php echo $uom['UOM_Name']; ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </div>
                                                <div class="col-xs-4">
                                                    <label><?php echo CommonLanguage::getMessage('value') ?><span class="red-star">*</span></label>
                                                    <input type="text" class="form-control conval digits ">
                                                </div>
                                                <div class="col-xs-4">
                                                    <label><?php echo CommonLanguage::getMessage('barcode') ?></label>
                                                    <input type="text" class="form-control code  ">
                                                </div>
                                            </div>
                                            <div class="row">
                                                <?php
                                                $i = 1;
                                                foreach ($pricing_classes as $class) {
                                                ?>
                                                    <?php if ($i % 4 == 1) { ?><div class="col-md-12 "><?php } ?>
                                                        <div class="col-md-3 uom_price">
                                                            <label><?php print $class['Class_Name'] . ' ' . CommonLanguage::getMessage('Price') . ' - ' . $class['Currency_Symbol']; ?></label>
                                                            <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 if ($i % 4 == 0 || $i == count($pricing_classes)) { ?>
                                                        </div><?php } ?>
                                                <?php
                                                    $i++;
                                                }
                                                ?>
                                            </div>
                                            <div class="row m-t-10">
                                                <div class="col-md-3">
                                                    <input type="checkbox" name="is_default_view_uom" class="is_default_view_uom">
                                                    <label><?php echo CommonLanguage::getMessage('is_default_view'); ?></label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="checkbox" name="is_default_sales_uom" class="is_default_sales_uom">
                                                    <label><?php echo CommonLanguage::getMessage('is_default_sales'); ?></label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="checkbox" name="is_default_purchase_uom" class="is_default_purchase_uom">
                                                    <label><?php echo CommonLanguage::getMessage('is_default_purchase'); ?></label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="checkbox" name="is_print_uom" class="is_print_uom">
                                                    <label><?php echo CommonLanguage::getMessage('is_print_uom'); ?></label>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <label><?php echo CommonLanguage::getMessage('additional_barcodes') ?><span style="color:red">(<?php echo CommonLanguage::getMessage('barcode_delimeter') ?>)</span></label>
                                            <textarea class="form-control additional_barcodes" rows="5" style="overflow: hidden; word-wrap: break-word; resize:vertical "></textarea>
                                        </div>
                                        <div class="col-md-1 AddButtons">
                                            <span class="fa fa-plus-circle" style="color:#4c0870;margin-top:15px;margin-right:25px"></span>
                                            <span class="fa fa-minus-circle" style="color:#ed9421;margin-top:15px;"></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="tab-pane slide-left " id="slide3">
                                <div class="row form-group">
                                    <div class="col-md-4">
                                        <label><?php echo CommonLanguage::getMessage('link_note'); ?></label>
                                        <textarea class="form-control" name="link_note" id="link_note"></textarea>
                                    </div>
                                </div>
                                <div class="row m-t-10 form-group" style="display:flex;">
                                    <div class="col-md-6 b-r b-dashed b-grey">
                                        <div class="col-md-12 text-center b-b b-dashed b-grey">
                                            <h3> <?php echo CommonLanguage::getMessage('in'); ?></h3>
                                        </div>
                                        <div class="col-md-12 form-group">
                                            <div class="col-md-4 text-center"><label><?php echo CommonLanguage::getMessage('Item'); ?></label></div>
                                            <div class="col-md-4 text-center"><label><?php echo CommonLanguage::getMessage('UOM'); ?></label></div>
                                            <div class="col-md-2 text-center"><label><?php echo CommonLanguage::getMessage('qty'); ?></label></div>
                                            <div class="col-md-2"></div>
                                        </div>
                                        <div class="InContainer ">
                                            <div class="col-md-12 InItem m-b-10">
                                                <div class="col-md-4"><input type="hidden" class=" full-width" name="in_product" /></div>
                                                <div class="col-md-4"><input class="full-width" name="in_uom" type="hidden" /></div>
                                                <div class="col-md-2"><input type="text" class="in_qty form-control" /></div>
                                                <div class="col-md-2">
                                                    <span class="fa fa-plus-circle m-l-5 " style="color:#8a7dbe;cursor:pointer"></span>
                                                    <span class="fa fa-minus-circle  " style="color:#ed9421;cursor:pointer"></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6 ">
                                        <div class="col-md-12 text-center b-b b-dashed b-grey">
                                            <h3 style="display: flex;">
                                                <input type="number" min="1" value="1" id="recipe_qty" name="recipe_qty" class="form-control" style="    margin-top: 2%;margin-right:2%;max-width:20%" />

                                                <?php echo CommonLanguage::getMessage('out'); ?>
                                            </h3>
                                        </div>
                                        <div class="col-md-12 form-group">
                                            <div class="col-md-4 text-center"><label><?php echo CommonLanguage::getMessage('Item'); ?></label></div>
                                            <div class="col-md-4 text-center"><label><?php echo CommonLanguage::getMessage('UOM'); ?></label></div>
                                            <div class="col-md-2 text-center"><label><?php echo CommonLanguage::getMessage('qty'); ?></label></div>
                                            <div class="col-md-2"></div>
                                        </div>
                                        <div class="OutContainer ">
                                            <div class="col-md-12 OutItem m-b-10">
                                                <div class="col-md-4"><input type="hidden" class=" full-width" name="out_product" /></div>
                                                <div class="col-md-4"><input class="full-width " name="out_uom" type="hidden" /></div>
                                                <div class="col-md-2"><input type="text" class="out_qty form-control" /></div>
                                                <div class="col-md-2" id="OutItem_add_delete">
                                                    <span class="fa fa-plus-circle m-l-5 " style="color:#8a7dbe;cursor:pointer"></span>
                                                    <span class="fa fa-minus-circle  " style="color:#ed9421;cursor:pointer"></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6 col-md-push-6">
                                        <div class="col-md-12 text-center b-b b-dashed b-grey">
                                            <h3 style="display: flex;">
                                                <?php echo CommonLanguage::getMessage('optional_out'); ?></h3>
                                        </div>
                                        <div id="optional_out" class="form-group">
                                            <div class="row op_out_row ">
                                                <div class="col-md-10 m-t-10">
                                                    <div class="col-md-6" style="display:inline-flex;">
                                                        <label><?php echo CommonLanguage::getMessage('Quantity') ?></label>
                                                        <input type="number" class="optional_quantity form-control m-l-10" />
                                                    </div>
                                                    <div class="col-md-6" style="display:inline-flex;">
                                                        <label class=" m-r-10"><?php echo CommonLanguage::getMessage('is_required') ?></label>
                                                        <input type="checkbox" class="op_required" />
                                                    </div>

                                                    <div class=" col-md-12 m-t-10">
                                                        <div class="col-md-12 ">
                                                            <div class="col-md-4 text-center"><label><?php echo CommonLanguage::getMessage('Item'); ?></label></div>
                                                            <div class="col-md-4 text-center"><label><?php echo CommonLanguage::getMessage('UOM'); ?></label></div>
                                                            <div class="col-md-2"></div>
                                                        </div>
                                                    </div>
                                                    <div class="op_detail_div ">
                                                        <div class="col-md-12 op_detail_row m-b-10">
                                                            <div class="col-md-4"><input type="hidden" class=" full-width" name="op_product" /></div>
                                                            <div class="col-md-4"><input class="full-width " name="op_uom" type="hidden" /></div>
                                                            <div class="col-md-2">
                                                                <span class="fa fa-plus-circle m-l-5 op_det_add" style="color:#8a7dbe;cursor:pointer"></span>
                                                                <span class="fa fa-minus-circle  op_det_del" style="color:#ed9421;cursor:pointer"></span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-2" style="margin-top:5%">
                                                    <span class="fa fa-plus-circle m-l-5 op_add" style="color:#8a7dbe;cursor:pointer"></span>
                                                    <span class="fa fa-minus-circle  op_del" style="color:#ed9421;cursor:pointer"></span>
                                                </div>
                                                <br>
                                                <hr>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="tab-pane slide-left " id="slide4">
                                <div class="row " style="display:flex;">
                                    <div class="col-md-12">
                                        <h3><?php echo CommonLanguage::getMessage('product_shelfs') ?></h3>
                                        <div class="col-md-12 form-group">
                                            <div class="col-md-4 text-center"><label><?php echo CommonLanguage::getMessage('Depot'); ?></label></div>
                                            <div class="col-md-4 text-center"><label><?php echo CommonLanguage::getMessage('shelfs_name'); ?></label></div>
                                            <div class="col-md-2"></div>
                                        </div>
                                        <div class="product_shelfs ">
                                            <div class="col-md-12 shelfItem m-b-10">
                                                <div class="col-md-4"><input type="hidden" class=" full-width depot_id" name="depot_id" /></div>
                                                <div class="col-md-6"><input class="full-width shelf_id" name="shelf_id" type="hidden" /></div>
                                                <div class="col-md-2">
                                                    <span class="fa fa-plus-circle m-l-5 " style="color:#8a7dbe;cursor:pointer"></span>
                                                    <span class="fa fa-minus-circle  " style="color:#ed9421;cursor:pointer"></span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="tab-pane slide-left" id="slide5">
                                <div class="col-md-12 AddCriteriaRow m-b-10 form-group">
                                    <div class="col-md-12">
                                        <!--<div class="row">-->
                                        <div class="col-xs-4 p-l-0">
                                            <label><?php print CommonLanguage::getMessage('criteria_name'); ?></label>
                                            <input type="text" placeholder="<?php print CommonLanguage::getMessage('criteria_name'); ?>" name="criteria_name" class="form-control ">
                                        </div>
                                        <div class="col-xs-4 p-l-0">
                                            <label><?php print CommonLanguage::getMessage('criteria_type'); ?></label>
                                            <select name="criteria_type" class="full-width  criteria_type" data-init-plugin="select2" required>
                                                <option value="1"><?php print CommonLanguage::getMessage('checkbox'); ?></option>
                                                <option value="2"><?php print CommonLanguage::getMessage('radio'); ?></option>
                                            </select>
                                        </div>
                                        <div class="col-xs-2 p-l-0 criteria_count">
                                            <label><?php print CommonLanguage::getMessage('criteria_max_count'); ?></label>
                                            <input type="text" name="criteria_max_count" class="form-control " placeholder="<?php print CommonLanguage::getMessage('criteria_max_count'); ?>">
                                        </div>
                                        <div class="col-xs-2 AddButtons">
                                            <span class="fa fa-plus-circle" style="color:#4c0870;margin-top:15px;margin-right:25px"></span>
                                            <span class="fa fa-minus-circle" style="color:#ed9421;margin-top:15px;display:none;"></span>
                                        </div>
                                        <!--</div>-->
                                        <!--<div class="row">-->
                                        <!--</div>-->
                                    </div>
                                    <div class="col-md-12">
                                        <!--                                        <label><?php // print CommonLanguage::getMessage('criteria_details');                                                    
                                                                                            ?>
<span style="color:red">(<?php // echo CommonLanguage::getMessage('criteria_details_delimeter')                                                          
                            ?>)</span>
</label>-->
                                        <div class="criteria_detail_divs ">
                                            <div class="row">
                                                <div class="col-xs-4 p-l-0">
                                                    <label><?php print CommonLanguage::getMessage('criteria_detail'); ?></label>
                                                </div>
                                                <div class="col-xs-4 p-l-0">
                                                    <label><?php print CommonLanguage::getMessage('criteria_detail_price'); ?></label>
                                                </div>
                                            </div>
                                            <div class="criteria-items">
                                                <div class="row cr-row">
                                                    <div class="col-xs-4 p-l-0">
                                                        <input type="text" name="criteria_detail_name" class="form-control criteria_detail_name">
                                                    </div>
                                                    <div class="col-xs-4 p-l-0">
                                                        <input type="text" name="criteria_detail_price" class="form-control criteria_detail_price">
                                                    </div>
                                                    <div class="col-xs-4 p-l-0">
                                                        <span class="fa fa-plus-circle" style="color:#4c0870;margin-top:15px;margin-right:25px"></span>
                                                        <span class="fa fa-minus-circle" style="color:#ed9421;margin-top:15px;display:none;"></span>
                                                    </div>
                                                </div>
                                            </div>
                                            <!--                                            <div class="col-md-12 criteria-details-item  p-l-0">
<textarea class="form-control criteria_details" rows="5" style="overflow: hidden; word-wrap: break-word; resize:vertical "></textarea>
</div>-->
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="tab-pane slide-left" id="slide6">
                                <div class="col-md-12 m-t-10 add_ons_divs">
                                    <h4 class="semi-bold"><?php print CommonLanguage::getMessage('add_ons'); ?></h4>
                                    <div class="row add-row">
                                        <div class="col-md-12 m-t-10">
                                            <div class="col-md-4">
                                                <select name="add_ons_id" class="full-width " data-init-plugin="select2">
                                                    <option value=""><?php print CommonLanguage::getMessage('choose_add_ons_details'); ?></option>
                                                    <?php foreach ($add_ons as $add) : ?>
                                                        <option value="<?php echo $add['add_ons_id']; ?>"><?php echo $add['add_ons_title']; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </div>
                                            <div class="col-md-2">
                                                <input type="number" name="product_add_ons_quantity" min="1" value="" class="form-control valid" aria-invalid="false">
                                            </div>
                                            <div class="col-md-1 buttons">
                                                <span class="fa fa-plus cursor"></span>
                                                <span class="fa fa-minus red-star cursor" style="display: none;"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="tab-pane slide-left form-group" id="slide7">
                                <div class="col-md-12 m-t-10" style="padding-left:0px;">
                                    <div class="col-md-4">
                                        <label><?php echo CommonLanguage::getMessage('type') ?></label>
                                        <select id="machine_type_id" name="machine_type_id" class="full-width " data-init-plugin="select2">
                                            <option value="0"><?php print CommonLanguage::getMessage('select'); ?></option>
                                            <option value="1"><?php echo CommonLanguage::getMessage('machine'); ?></option>
                                            <option value="2"><?php echo CommonLanguage::getMessage('parts'); ?></option>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-12 m-t-10 parts_divs hidden">
                                    <h3 class="semi-bold"><?php print CommonLanguage::getMessage('parts'); ?></h3>
                                    <div class="col-md-12 m-t-10 " style="padding:0;">
                                        <div class="col-md-4" style="padding:0;"><label><?php echo CommonLanguage::getMessage('product') ?></label></div>
                                        <div class="col-md-4" style="padding:0;"><label><?php echo CommonLanguage::getMessage('Description') ?></label></div>
                                    </div>
                                    <div class="row add-part-row">
                                        <div class="col-md-12 m-t-10 ">
                                            <div class="col-md-4">
                                                <input type="hidden" name="parts_product" class="full-width parts_product">
                                            </div>
                                            <div class="col-md-4">
                                                <textarea class="form-control parts_note" rows="1" style="overflow: hidden; word-wrap: break-word; resize:vertical "></textarea>
                                            </div>
                                            <div class="col-md-1 buttons">
                                                <span class="fa fa-plus-circle" style="color:#4c0870;margin-top:15px;margin-right:25px"></span>
                                                <span class="fa fa-minus-circle" style="color:#ed9421;margin-top:15px;"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-12 m-t-10 properties_divs hidden">
                                    <h3 class="semi-bold"><?php print CommonLanguage::getMessage('properties'); ?></h3>
                                    <div class="col-md-12 m-t-10 " style="padding:0;">
                                        <div class="col-md-4" style="padding:0;"><label><?php echo CommonLanguage::getMessage('name') ?></label></div>
                                    </div>
                                    <div class="row add-prop-row">
                                        <div class="col-md-12 m-t-10 ">
                                            <div class="col-md-4">
                                                <input type="text" name="property_name" class="full-width property_name form-control">
                                            </div>
                                            <div class="col-md-1 buttons">
                                                <span class="fa fa-plus-circle" style="color:#4c0870;margin-top:15px;margin-right:25px"></span>
                                                <span class="fa fa-minus-circle" style="color:#ed9421;margin-top:15px;"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" id="CloseProduct"> <?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn btn-primary" id="SubmitProduct"> <?php print CommonLanguage::getMessage('Save'); ?> </button>
            </div>
            <?php echo Forms::ModalLoader('addProductLoader'); ?>
        </div>
    </div>
</div>
<script type="text/javascript">
    var enable_category_barcode = $("#enable_category_barcode").val();
    var retype_code = <?php echo json_encode(CommonLanguage::getMessage('retype_code')); ?>,
        Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
        check_uom = <?php echo json_encode($check_uom); ?>,
        Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
        link_required = <?php echo json_encode(CommonLanguage::getMessage('link_required')); ?>,
        Data_Exists = <?php echo json_encode(CommonLanguage::getMessage('Data_Exists')); ?>,
        barcode_check = <?php echo json_encode(CommonLanguage::getMessage('barcode_check')); ?>,
        Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
        activate_second_vat = <?php echo json_encode(smc_session()['default_setting']['activate_second_vat']); ?>,
        vat_percent = <?php echo json_encode(smc_session()['default_setting']['vat_percent']); ?>,
        vat2_percent = <?php echo json_encode(smc_session()['default_setting']['second_vat_percent']); ?>,
        is_smart_diner = <?php echo json_encode(smc_session()['default_setting']['activate_smart_diner']); ?>,
        is_tag_active = <?php echo json_encode(smc_session()['default_setting']['is_tag_active']); ?>,
        is_add_ons_active = <?php echo json_encode(smc_session()['default_setting']['is_add_ons_active']); ?>,
        is_sumernote = <?php echo json_encode(smc_session()['default_setting']['activate_summernote_in_product']); ?>,
        auto_generate_code = <?php echo json_encode(smc_session()['auto_generate_code']); ?>,
        max_code = <?php echo json_encode($max_code); ?>,
        product_required_fields = <?php echo json_encode($product_required_fields); ?>;
    //    var validate = $("#AddProductPostForm").validate();
    $(function() {
        $('#product_color').colorpicker({
            format: 'hex',
            autoInputFallback: false
        });
        build_select2($("input[name=in_product],input[name=out_product],input[name=op_product]"), ("xhr/ProductSearch"));
        build_select2($("input[name=parts_product]"), ("xhr/MachinePartSearch?type=2&Status_ID=1"));
        build_select2($(".UOM_ID"), "xhr/uomSearch");
        build_select2($("input[name=in_uom]"), "xhr/productuomSearch?pid=" + $("input[name=in_product]").val());
        build_select2($("input[name=out_uom]"), "xhr/productuomSearch?pid=" + $("input[name=out_product]").val());
        build_select2($("input[name=op_uom]"), "xhr/productuomSearch?pid=" + $("input[name=op_product]").val());
        build_select2($(".Category_ID"), "xhr/catSearch");
        build_select2($("#family_id"), "xhr/CommonSearch?col_name=family_name&col_id=family_id&table=tbl_inventory_family");
        build_select2($("#brand_id"), "xhr/CommonSearch?col_name=brand_name&col_id=brand_id&table=tbl_brand_products");
        build_select2($("#section_id"), "xhr/CommonSearch?col_name=section_name&col_id=section_id&table=tbl_product_sections");
        build_select2($("#pur_cat_id"), "xhr/CommonSearch?col_name=pur_cat_name&col_id=pur_cat_id&table=tbl_purchase_cat");
        build_select2($("#group_account_id"), "xhr/GroupAccountSearch");
        build_select2($("#main_supplier_id"), "xhr/supplierSearch");
        build_select2($("#current_branch_id"), "xhr/CommonSearch?col_name=branch_name&col_id=branch_id&table=tbl_organization_branches",1);

        new Switchery($("#VAT").get(0), {
            color: $.Pages.getColor("primary")
        });
        new Switchery($("#plu_type").get(0), {
            color: $.Pages.getColor("primary")
        });
        new Switchery($("#move_scale").get(0), {
            color: $.Pages.getColor("primary")
        });
        new Switchery($("#is_card").get(0), {
            color: $.Pages.getColor("primary")
        })
        new Switchery($("#is_expiry").get(0), {
            color: $.Pages.getColor("primary")
        })
        new Switchery($("#force_change_price").get(0), {
            color: $.Pages.getColor("primary")
        })
        new Switchery($("#duration_reservation").get(0), {
            color: $.Pages.getColor("primary")
        });
        new Switchery($("#is_lot").get(0), {
            color: $.Pages.getColor("primary")
        });
        new Switchery($("#is_serial").get(0), {
            color: $.Pages.getColor("primary")
        });
        new Switchery($("#is_ticket").get(0), {
            color: $.Pages.getColor("primary")
        });
        new Switchery($("#is_service").get(0), {
            color: $.Pages.getColor("primary")
        });
        new Switchery($("#is_rate").get(0), {
            color: $.Pages.getColor("primary")
        })
        new Switchery($("#is_rate_type_one").get(0), {
            color: $.Pages.getColor("primary")
        })
        new Switchery($("#is_rate_type_two").get(0), {
            color: $.Pages.getColor("primary")
        })
        new Switchery($("#effect_qty_link_product").get(0), {
            color: $.Pages.getColor("primary")
        })
        new Switchery($("#hide_pos").get(0), {
            color: $.Pages.getColor("primary")
        })


        $('#slide2').on('click', 'input.is_default_view_uom', function() {
            var index = $('#slide2 input.is_default_view_uom').index(this);
            $('input.is_default_view_uom').not(":eq(" + index + ")").prop('checked', false)
            var parent = $(this).closest('.AddRow');
            $('input.is_default_view_uom', parent).prop('checked', $('input.is_default_view_uom', parent).is(":checked") ? true : false)
        });
        $('#slide2').on('click', 'input.is_default_sales_uom', function() {
            var index = $('#slide2 input.is_default_sales_uom').index(this);
            $('input.is_default_sales_uom').not(":eq(" + index + ")").prop('checked', false)
            var parent = $(this).closest('.AddRow');
            $('input.is_default_sales_uom', parent).prop('checked', $('input.is_default_sales_uom', parent).is(":checked") ? true : false)
        });
        $('#slide2').on('click', 'input.is_default_purchase_uom', function() {
            var index = $('#slide2 input.is_default_purchase_uom').index(this);
            $('input.is_default_purchase_uom').not(":eq(" + index + ")").prop('checked', false)
            var parent = $(this).closest('.AddRow');
            $('input.is_default_purchase_uom', parent).prop('checked', $('input.is_default_purchase_uom', parent).is(":checked") ? true : false)
        });
        $('#slide2').on('click', 'input.is_print_uom', function() {
            var index = $('#slide2 input.is_print_uom').index(this);
            $('input.is_print_uom').not(":eq(" + index + ")").prop('checked', false)
            var parent = $(this).closest('.AddRow');
            $('input.is_print_uom', parent).prop('checked', $('input.is_print_uom', parent).is(":checked") ? true : false)
        });
        $("#UOM_ID").on("change", function() {
            $("#default_uom_span").html($("#s2id_UOM_ID a span:eq(0)").text());
        });
        build_select2($("input[name=depot_id]"), "xhr/depotSearch");
        build_select2($("input[name=shelf_id]"), "xhr/shelfdepotSearch?pid=" + $("input[name=depot_id]").val(), 1);
        $("#machine_type_id").on("change", function() {
            if ($(this).val() != 1) {
                $(".add-part-row:gt(0)").empty().remove()
                $(".add-part-row:eq(0) .parts_note").val("")
                $(".add-part-row:eq(0) input[name=parts_product]").val('').attr("data-select-name", "");
                build_select2($(".add-part-row:eq(0) input[name=parts_product]"), ("xhr/MachinePartSearch?type=2&Status_ID=1"))
                $(".add-prop-row:gt(0)").empty().remove()
                $(".add-prop-row:eq(0) .property_name").val("")
                $(".parts_divs,.properties_divs").addClass("hidden")
            } else {
                $(".parts_divs,.properties_divs").removeClass("hidden")
            }
        })
        $("#effect_qty_link_product").on("change", function() {
            if ($(this).is(":checked")) {
                $("#OutItem_add_delete").addClass("hidden")

            } else {
                $("#OutItem_add_delete").removeClass("hidden")
            }

        })

        $(".generate_barcode").on("click", function() {
            $.ajax({
                url: "InventoryAjax/generate_prod_barcode",
                data: {
                    code: $("#Bar_Code").val()
                },
                complete: function(v1, v2) {
                    if (v2 == 'success') {
                        $("#Bar_Code").val(v1.responseText)
                    }
                }
            })
        })
        $(".product_shelfs").on("change", "input[name=depot_id]", function(e) {
            var shelf_depot = $(this).parents(".shelfItem").find("input[name=shelf_id]");
            shelf_depot.val('');
            shelf_depot.attr("data-select-name", "");
            build_select2(shelf_depot, "xhr/shelfdepotSearch?pid=" + $(this).val(), 1);
        });

        $("#n_width,#n_height").on("keyup", function (e) {
            var width  =  $("#n_width").val();
            var height =  $("#n_height").val();
            $("#UOMConForm .conval").val(width*height);
        });

        $(".product_shelfs").on("click", " .fa-plus-circle", function(e) {
            $(".product_shelfs  .fa-minus-circle").css("display", "inline-block")
            var Parent = $(this).parents(".shelfItem"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find(".select2-container").remove();
            NewItem.find("input[name=depot_id],input[name=shelf_id]").val(0);
            NewItem.find("input[name=depot_id],input[name=shelf_id]").attr("data-select-name", "");
            build_select2(NewItem.find("input[name=depot_id]"), ("xhr/depotSearch"))
            build_select2(NewItem.find("input[name=shelf_id]"), "xhr/shelfdepotSearch?pid=" + NewItem.find("input[name=depot_id]").val());
            $(".select2-container", NewItem).show();
        });
        $(".product_shelfs").on("click", ".fa-minus-circle", function(e) {
            $(this).closest(".shelfItem").empty().remove();
            $(".shelfItem").each(function() {
                $(" .fa-minus-circle", $(this).parents('.product_shelfs')).css({
                    "display": $(".shelfItem", $(this).parents('.product_shelfs')).length <= 1 ? "none" : "inline-block"
                })
            });
        });
        $("#UOMConForm").on("click", ".AddButtons > .fa-plus-circle", function(e) {
            $(".AddButtons > .fa-minus-circle").css("display", "")
            var Parent = $(this).parents(".AddRow"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find("input").val('');
            NewItem.find(".additional_barcodes").val('');
            NewItem.find("input[name=is_default_view_uom],input[name=is_default_sales_uom],input[name=is_default_purchase_uom],input[name=is_print_uom]").prop('checked', false);
            $(".select2-container", NewItem).empty().remove()
            NewItem.find(".UOM_From").show().select2()
        });
        $("#UOMConForm").on("click", ".AddButtons > .fa-minus-circle", function(e) {
            if ($(".AddRow").length == 1) {
                $(".AddRow input").val("")
                $(".AddRow select.UOM_From").val(0).select2();
                $(".AddRow .additional_barcodes").val("");
            } else {
                $(this).closest(".AddRow").empty().remove();
            }
        });
        $("#optional_out").on("change", "input[name=op_product]", function(e) {
            var op_uom = $(this).parents(".op_detail_row").find("input[name=op_uom]");
            if ($(this).val() == '') {
                op_uom.val('').attr("data-select-name", "").trigger("change")
            } else {
                get_default_uom($(this).val(), op_uom)
            }
        });
        $(".InContainer").on("change", "input[name=in_product]", function(e) {
            var in_uom = $(this).parents(".InItem").find("input[name=in_uom]");
            get_default_uom($(this).val(), in_uom)
        });
        $(".OutContainer").on("change", "input[name=out_product]", function(e) {
            var out_uom = $(this).parents(".OutItem").find("input[name=out_uom]");
            get_default_uom($(this).val(), out_uom)
        });
        $(".InContainer").on("click", " .fa-plus-circle", function(e) {
            $(".InContainer  .fa-minus-circle").css("display", "inline-block")
            var Parent = $(this).parents(".InItem"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find(".in_qty").val('');
            NewItem.find(".select2-container").remove()
            NewItem.find("input[name=in_uom],input[name=in_product]").val(0);
            NewItem.find("input[name=in_uom],input[name=in_product]").attr("data-select-name", "");
            build_select2(NewItem.find("input[name=in_product]"), ("xhr/ProductSearch"))
            build_select2(NewItem.find("input[name=in_uom]"), "xhr/productuomSearch?pid=" + NewItem.find("input[name=in_product]").val())
            $(".select2-container", NewItem).show()
        });
        $(".InContainer").on("click", ".fa-minus-circle", function(e) {
            $(this).closest(".InItem").empty().remove();
            $(".InItem").each(function() {
                $(" .fa-minus-circle", $(this).parents('.InContainer')).css({
                    "display": $(".InItem", $(this).parents('.InContainer')).length <= 1 ? "none" : "inline-block"
                })
            });
        });
        $(".OutContainer").on("click", " .fa-plus-circle", function(e) {
            $(".OutContainer  .fa-minus-circle").css("display", "inline-block")
            var Parent = $(this).parents(".OutItem"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find(".out_qty").val('');
            NewItem.find(".select2-container").remove()
            NewItem.find("input[name=out_uom],input[name=out_product]").val('');
            NewItem.find("input[name=out_uom],input[name=out_product]").attr("data-select-name", "");
            build_select2(NewItem.find("input[name=out_product]"), ("xhr/ProductSearch"))
            build_select2(NewItem.find("input[name=out_uom]"), "xhr/productuomSearch?pid=" + NewItem.find("input[name=out_product]").val())
            $(".select2-container", NewItem).show()
        })
        $(".OutContainer").on("click", ".fa-minus-circle", function(e) {
            $(this).closest(".OutItem").empty().remove();
            $(".OutItem").each(function() {
                $(" .fa-minus-circle", $(this).parents('.OutContainer')).css({
                    "display": $(".OutItem", $(this).parents('.OutContainer')).length <= 1 ? "none" : "inline-block"
                })
            })
        });
        $("#slide5").on("click", ".criteria-items .fa-plus-circle", function(e) {
            $(".fa-minus-circle", $(this).parents('.criteria-items')).css("display", "inline-block")
            var Parent = $(this).parents(".cr-row"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find("input").val('');
            NewItem.attr('data-criteria-detail-id', 0);
        });
        $("#slide5").on("click", ".criteria-items .fa-minus-circle", function(e) {
            var parent = $(this).parents('.AddCriteriaRow');
            $(this).closest(".cr-row").empty().remove();
            $(".cr-row", parent).each(function() {
                $(".fa-minus-circle", $(this)).css({
                    "display": $(".cr-row", parent).length <= 1 ? "none" : "inline-block"
                })
            });
        });
        $(".parts_divs").on("click", " .fa-plus-circle", function(e) {
            $(".add-part-row  .fa-minus-circle").css("display", "inline-block")
            var Parent = $(this).parents(".add-part-row"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find(".parts_note").val('');
            NewItem.find(".select2-container").remove()
            NewItem.find("input[name=parts_product]").val('').attr("data-select-name", "");
            build_select2(NewItem.find("input[name=parts_product]"), ("xhr/MachinePartSearch?type=2&Status_ID=1"))
            $(".select2-container", NewItem).show()
        });
        $(".parts_divs").on("click", ".fa-minus-circle", function(e) {
            if ($(".add-part-row").length == 1) {
                $(".parts_note").val("")
                $(".add-part-row input[name=parts_product]").val('').attr("data-select-name", "");
                build_select2($(".add-part-row input[name=parts_product]"), ("xhr/MachinePartSearch?type=2&Status_ID=1"))
            } else {
                $(this).closest(".add-part-row").empty().remove();
            }
        });
        $(".properties_divs").on("click", " .fa-plus-circle", function(e) {
            $(".add-prop-row  .fa-minus-circle").css("display", "inline-block")
            var Parent = $(this).parents(".add-prop-row"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find(".property_name").val('');
        });
        $(".properties_divs").on("click", ".fa-minus-circle", function(e) {
            if ($(".add-prop-row").length == 1) {
                $(".property_name").val("")
            } else {
                $(this).closest(".add-prop-row").empty().remove();
            }
        });

        $("#optional_out").on("click", " .op_add", function(e) {
            $("#optional_out  .op_del").css("display", "inline-block")
            var Parent = $(this).parents(".op_out_row"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find(".optional_quantity").val('');
            NewItem.attr("data-id", "0");
            NewItem.find("input.op_required").prop("checked", false)
            $(".op_detail_row:gt(0)", NewItem).empty().remove()
            NewItem.find(".select2-container").remove()
            NewItem.find("input[name=op_uom],input[name=op_product]").val('').attr("data-select-name", "");
            build_select2(NewItem.find("input[name=op_product]"), ("xhr/ProductSearch"))
            build_select2(NewItem.find("input[name=op_uom]"), "xhr/productuomSearch?pid=" + NewItem.find("input[name=op_product]").val())
            $(".select2-container", NewItem).show()
        });
        $("#optional_out").on("click", ".op_del", function(e) {
            var parent = $(this).parents('.op_out_row');
            if ($(".op_out_row").length == 1) {
                $(".input").val("")
                $(".op_detail_row:gt(0)", parent).remove()
                $("input[name=op_product],input[name=op_uom]", parent).val('').attr("data-select-name", "");
                build_select2(parent.find("input[name=op_product]"), ("xhr/ProductSearch"))
                build_select2(parent.find("input[name=op_uom]"), "xhr/productuomSearch?pid=" + parent.find("input[name=op_product]").val())
            } else {
                $(this).closest(".op_out_row").empty().remove();
            }
        });
        $("#optional_out").on("click", " .op_det_add", function(e) {
            $(".op_det_del", $(this).parents('.op_detail_div')).css("display", "inline-block")
            var Parent = $(this).parents(".op_detail_row"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find(".select2-container").remove()
            NewItem.find("input[name=op_uom],input[name=op_product]").val('').attr("data-select-name", "");
            build_select2(NewItem.find("input[name=op_product]"), ("xhr/ProductSearch"))
            build_select2(NewItem.find("input[name=op_uom]"), "xhr/productuomSearch?pid=" + NewItem.find("input[name=op_product]").val())
            $(".select2-container", NewItem).show()
        });
        $("#optional_out").on("click", ".op_det_del", function(e) {

            var parent = $(this).parents('.op_detail_row');
            if ($(".op_detail_row").length == 1) {
                $(".input").val("")
                $("input[name=op_product],input[name=op_uom]", parent).val('').attr("data-select-name", "");
                build_select2(parent.find("input[name=op_product]"), ("xhr/ProductSearch"))
                build_select2(parent.find("input[name=op_uom]"), "xhr/productuomSearch?pid=" + parent.find("input[name=op_product]").val())
            } else {
                $(this).closest(".op_detail_row").empty().remove();
            }
        });


        $("#SubmitProduct").on("click", function() {
            if (!$("#AddProductPostForm").valid())
                return;
            var is_criteria_details_empty = false,
                is_criteria_max_count_empty = false,
                criteria = [],
                is_add_ons_quantity = false,
                in_out_validate = true;
            if ($("#Bar_Code").val().length > 5 && $("#move_scale").is(":checked")) {
                $("#ProductValidationAlert").attr("class", "alert alert-danger").show().html(barcode_check)
                $("#addProduct").scrollTop(0)
                return false;
            }
            if ($("#Product_Code").val() == '' || $("#Product_Name").val() == '' || $("#Category_ID").val() == '' || $("#UOM_ID").val() == '') {
                $("#ProductValidationAlert").attr("class", "alert alert-danger").show().html(Required_Fields)
                $("#addProduct").scrollTop(0)
                return false;
            }

            var Data = new FormData(document.getElementById("AddProductPostForm"));
            if ($("#NewProductUploadPhoto > input").prop("files").length > 0) {
                $.each(window.NewProductCurrentFileUploadaddProduct, function(key, value) {
                    Data.append(key, value);
                });
            }
            var price_arr = [],
                Con = [],
                in_item = [],
                out_item = [],
                product_shelf = [],
                add_ons = [],
                prop_arr = [],
                parts_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
                })
            })
            $(".add-part-row").each(function() {
                if ($(this).find("input[name=parts_product]").val() != '') {
                    parts_arr.push({
                        part_prod: $(this).find("input[name=parts_product]").val(),
                        part_note: $(this).find(".parts_note").val()
                    })
                }
            })
            $(".add-prop-row").each(function() {
                if ($(this).find(".property_name").val() != '') {
                    prop_arr.push({
                        property_name: $(this).find(".property_name").val()
                    })
                }
            });
            var conval_is_empty = false;
            //                                                                    console.log(prop_arr)
            $(".AddRow").each(function() {
                var me = $(this);
                var uom_prices = [];
                $(".uom_price", me).each(function() {
                    uom_prices.push({
                        price: $(this).find(".price_value").val(),
                        class_id: $(this).find(".price_value").attr("data-class"),
                        currency_id: $(this).find(".cur_input").val()
                    })
                });
                if (me.find("select[name=UOM_From]").val()) {
                    if (!me.find(".conval").val() || parseFloat(me.find(".conval").val()) == 0)
                        conval_is_empty = true;
                    Con.push({
                        uom_from: me.find("select[name=UOM_From]").val(),
                        uom_to: $("#UOM_ID").val(),
                        conversion_amount: me.find(".conval").val(),
                        code: me.find(".code").val(),
                        additional_barcodes: me.find(".additional_barcodes").val(),
                        uom_prices: uom_prices,
                        is_default_sales: me.find("input[name=is_default_sales_uom]").is(":checked") ? 1 : 0,
                        is_default_purchase: me.find("input[name=is_default_purchase_uom]").is(":checked") ? 1 : 0,
                        is_print_uom: me.find("input[name=is_print_uom]").is(":checked") ? 1 : 0,
                    });
                    if (me.find("input[name=is_default_sales_uom]").is(":checked")) {
                        Data.append('default_sales_uom', me.find("select[name=UOM_From]").val())
                    }
                    if (me.find("input[name=is_default_purchase_uom]").is(":checked")) {
                        Data.append('default_purchase_uom', me.find("select[name=UOM_From]").val())
                    }
                    if (me.find("input[name=is_print_uom]").is(":checked")) {
                        Data.append('print_uom_id', me.find("select[name=UOM_From]").val())
                    }
                }
            });
            if (conval_is_empty) {
                $('#ProductValidationAlert').attr("class", "alert alert-danger").show().html('<?php echo CommonLanguage::getMessage('fill_value_uom_conversion'); ?>');
                $("#addProduct").scrollTop(0)
                return;
            }
            //            console.log(Con.length)
            //            console.log(product_required_fields)

            if (product_required_fields.includes('7') && Con.length == 0) {
                $('#ProductValidationAlert').attr("class", "alert alert-danger").show().html('<?php echo CommonLanguage::getMessage('min_uom_conv_req'); ?>');
                $("#addProduct").scrollTop(0)
                return;
            }
            //            if('7' in product_required_fields){
            //                console.log('gereeyrgjchd')
            //            }
            //            return;
            $(".InItem").each(function() {
                $(this).find("input[name=in_uom]").removeClass("wrong")
                $(this).find(".in_qty").removeClass("wrong")
                //                console.log($(this).find(".in_product"))
                if ($(this).find("input[name=in_product]").val() != '') {
                    if ($(this).find("input[name=in_uom]").val() != '' && $(this).find(".in_qty").val() != '') {
                        in_item.push({
                            sub_item: $(this).find("input[name=in_product]").val(),
                            sub_uom: $(this).find("input[name=in_uom]").val(),
                            sub_qty: $(this).find(".in_qty").val()
                        })
                    } else {
                        if ($(this).find("input[name=in_uom]").val() == '')
                            $(this).find("input[name=in_uom]").addClass("wrong")
                        if ($(this).find(".in_qty").val() == '')
                            $(this).find(".in_qty").addClass("wrong")
                        in_out_validate = false;
                    }
                }
            })
            $(".OutItem").each(function() {
                $(this).find("input[name=out_uom]").removeClass("wrong")
                $(this).find(".out_qty").removeClass("wrong")
                if ($(this).find("input[name=out_product]").val() != '') {
                    if ($(this).find("input[name=out_uom]").val() != '' && $(this).find(".out_qty").val() != '') {
                        //                if ($(this).find(".out_qty").val() != '') {
                        out_item.push({
                            sub_item: $(this).find("input[name=out_product]").val(),
                            sub_uom: $(this).find("input[name=out_uom]").val(),
                            sub_qty: $(this).find(".out_qty").val()
                        })
                    } else {
                        if ($(this).find("input[name=out_uom]").val() == '')
                            $(this).find("input[name=out_uom]").addClass("wrong")
                        if ($(this).find(".out_qty").val() == '')
                            $(this).find(".out_qty").addClass("wrong")
                        in_out_validate = false;
                    }
                }
            });
            if (!in_out_validate) {
                $("#ProductValidationAlert").attr("class", "alert alert-danger").empty().html(link_required);
                return false;
            }
            $(".shelfItem").each(function() {
                if ($(this).find("input[name=depot_id]").val() != '' || $(this).find("input[name=shelf_id]").val() != '') {
                    product_shelf.push({
                        depot_id: $(this).find("input[name=depot_id]").val(),
                        shelf_depot_id: $(this).find("input[name=shelf_id]").val()
                    })
                }
            });
            if (is_tag_active == 1) {
                $('.AddCriteriaRow').each(function() {
                    if ($("input[name=criteria_name]", $(this)).val() != '') {
                        if ($('select[name=criteria_type]', $(this)).val() == 1 && $('input[name=criteria_max_count]', $(this)).val() == '') {
                            is_criteria_max_count_empty = true
                        }
                        var criteria_detail_arr = [];
                        $(".cr-row", $(this)).each(function() {
                            if ($(".criteria_detail_name", $(this)).val()) {
                                criteria_detail_arr.push({
                                    criteria_detail_name: $(".criteria_detail_name", $(this)).val(),
                                    criteria_detail_price: $(".criteria_detail_price", $(this)).val()
                                })
                            }
                        });
                        criteria.push({
                            criteria_name: $("input[name=criteria_name]", $(this)).val(),
                            criteria_type: $("select[name=criteria_type]", $(this)).val(),
                            criteria_max_count: $("input[name=criteria_max_count]", $(this)).val(),
                            criteria_details: criteria_detail_arr
                        })
                        if (criteria_detail_arr.length == 0) {
                            is_criteria_details_empty = true;
                        }
                    }
                });
            }
            if (is_criteria_max_count_empty) {
                AddAlert('#ProductValidationAlert', '<?php echo CommonLanguage::getMessage('fill_criteria_max_count'); ?>', 'danger')
                return;
            }
            if (is_criteria_details_empty) {
                AddAlert('#ProductValidationAlert', '<?php echo CommonLanguage::getMessage('fill_criteria_details'); ?>', 'danger')
                return;
            }
            if (is_add_ons_active == 1) {
                $(".add_ons_divs .add-row").each(function() {
                    var parent = $(this),
                        add_ons_id = $("select[name=add_ons_id]", parent).val(),
                        product_add_ons_quantity = $("input[name=product_add_ons_quantity]", parent).val();
                    if (add_ons_id) {
                        if (product_add_ons_quantity == '') {
                            is_add_ons_quantity = true;
                        }
                        add_ons.push({
                            add_ons_id: add_ons_id,
                            product_add_ons_quantity: product_add_ons_quantity
                        });
                    }
                });
            }
            if (is_add_ons_quantity) {
                AddAlert('#ProductValidationAlert', '<?php echo CommonLanguage::getMessage('fill_add_ons_quantity'); ?>', 'danger')
                return;
            }
            var optionals = [],
                is_optional_details_empty = false;
            $('.op_out_row ').each(function() {
                if ($("input.optional_quantity", $(this)).val() != '') {

                    var optional_detail = [];
                    $(".op_detail_row", $(this)).each(function() {
                        if ($("input[name=op_uom]", $(this)).val() && $("input[name=op_product]", $(this)).val()) {
                            optional_detail.push({
                                uom_id: $("input[name=op_uom]", $(this)).val(),
                                product_id: $("input[name=op_product]", $(this)).val()
                            })
                        }
                    });
                    optionals.push({
                        quantity: $(".optional_quantity", $(this)).val(),
                        is_required: $("input.op_required", $(this)).is(":checked"),
                        details: optional_detail
                    })
                    if (optional_detail.length == 0) {
                        is_optional_details_empty = true;
                    }
                }
            });
            if (is_optional_details_empty) {
                AddAlert('#ProductValidationAlert', '<?php echo CommonLanguage::getMessage('fill_optional_details'); ?>', 'danger')
                return;
            }

            if (Con.length > 0 && $('input.is_default_view_uom:checked').length > 0) {
                var parent = $('input.is_default_view_uom:checked').closest('.AddRow');
                if ($('select[name=UOM_From]', parent).val()) {
                    Data.append('default_view_uom_id', $('select[name=UOM_From]', parent).val())
                    Data.append('default_view_rate', $('input.conval', parent).val())
                } else {
                    Data.append('default_view_uom_id', $('#UOM_ID').val())
                    Data.append('default_view_rate', 1)
                }
            } else {
                Data.append('default_view_uom_id', $('#UOM_ID').val())
                Data.append('default_view_rate', 1)
            }
            //                                                        return ;
            Data.append('criteria', JSON.stringify(criteria))
            Data.append("in_item", JSON.stringify(in_item))
            Data.append("out_item", JSON.stringify(out_item))
            Data.append("price_arr", JSON.stringify(price_arr))
            Data.append("con", JSON.stringify(Con))
            Data.append("product_shelf", JSON.stringify(product_shelf))
            Data.append("price", $("input[data-class=1]").val())
            Data.append("add_ons", JSON.stringify(add_ons))
            Data.append("prop_arr", JSON.stringify(prop_arr))
            Data.append("parts_arr", JSON.stringify(parts_arr))
            Data.append("optionals", JSON.stringify(optionals))
            Data.append("printer_arr", ($("#printer_id").val() == null ? '' : $("#printer_id").val().join()))
            if (is_sumernote == 1) {
                Data.append("product_description", $('#product_description').code())
            }
            Data.append('hide_pos', $("#hide_pos").is(":checked") ? 1 : 0);
            $("#ProductIsBusy").removeClass('hidden');
            $.ajax({
                url: "InventoryAjax/addProductAjax",
                method: "POST",
                data: Data,
                dataType: "json",
                processData: false,
                contentType: false,
                complete: function(v1, v2) {
                    if (v2 == 'success' && v1.responseJSON[0] == 'OK') {
                        //                        $("#ProductIsBusy").remove();
                        $("#ProductValidationAlert").attr("class", "alert alert-success").empty().html(Submitted_Successfully);
                        max_code = v1.responseJSON[1];
                        setTimeout(function() {
                            $("#addProduct").modal('hide')
                            $("#ProductValidationAlert").addClass("hidden")
                            $(".InItem:gt(0),.OutItem:gt(0)").remove()
                            $(".InItem:eq(0) input.in_qty,.OutItem:eq(0) input.out_qty").val('')
                            $(".InItem:eq(0) input.in_qty,.OutItem:eq(0) input.out_qty").val(0);
                            $("input[name=in_product],input[name=out_product],input[name=in_uom],input[name=out_uom]").val('').attr("data-select-name", "");
                            //                            $(".InItem:eq(0) input[name=in_product],.OutItem:eq(0) input[name=out_product]").attr("data-select-name", "");
                            build_select2($("input[name=in_product],input[name=out_product]"), ("xhr/ProductSearch"))
                            build_select2($("input[name=in_uom]"), "xhr/productuomSearch?pid=" + $("input[name=in_product]").val())
                            build_select2($("input[name=out_uom]"), "xhr/productuomSearch?pid=" + $("input[name=out_product]").val())
                            build_select2($("input[name=depot_id]"), "xhr/depotSearch");
                            build_select2($("input[name=shelf_id]"), "xhr/shelfdepotSearch?pid=" + $("input[name=depot_id]").val(), 1);
                            $("#slide2,#slide3,#slide4").removeClass("active")
                            $("#slide1").addClass("active");
                        }, 1500);
                        RebuildDataTable(title, [0, 1, 2, 3], "InventoryAjax/listProductRequest", {
                            Status_ID: $('#product_status').val(),
                            category_id: $('#current_category_id').val(),
                            show_zero_qty: $("#show_zero_qty").is(":checked") ? 1 : 0
                        });
                    } else {
                        $("#ProductValidationAlert").attr("class", "alert alert-danger").empty().html(v1.responseJSON.join(' <br> '));
                    }
                    $("#addProduct").scrollTop(0);
                    $("#ProductIsBusy").addClass('hidden');
                }
            })
            //  }
            //                                              });
            //            $("#AddProductPostForm").validate().resetForm();
            $("#NewProductUploadImagePreview").attr("src", "img/profiles/product.png");
        })
        $("#CloseProduct").on("click", function() {
            $("#addProduct").modal("hide");
            $("#ProductValidationAlert").addClass('hidden');
            $("#NewProductUploadImagePreview").attr("src", "img/profiles/product.png");
        })
        $("#addProduct").on("hidden.bs.modal", function() {
            //            $("#Product_Code").val(max_code)
            if ($("#move_scale").is(":checked")) {
                $("#move_scale").trigger("click")
            }
            if ($("#plu_type").is(":checked")) {
                $("#plu_type").trigger("click")
            }
            if ($("#VAT").is(":checked")) {
                $("#VAT").trigger("click")
            }
            if ($("#is_lot").is(":checked")) {
                $("#is_lot").trigger("click")
            }
            if ($("#is_serial").is(":checked")) {
                $("#is_serial").trigger("click")
            }
            if ($("#is_service").is(":checked")) {
                $("#is_service").trigger("click")
            }
            if ($("#is_rate").is(":checked")) {
                $("#is_rate").trigger("click")
            }
            if ($("#is_rate_type_one").is(":checked")) {
                $("#is_rate_type_one").trigger("click")
            }
            if ($("#is_rate_type_two").is(":checked")) {
                $("#is_rate_type_two").trigger("click")
            }
            if ($("#effect_qty_link_product").is(":checked")) {
                $("#effect_qty_link_product").trigger("click")
            }
            if ($("#hide_pos").is(":checked")) {
                $("#hide_pos").trigger("click")
            }

            if ($("#is_ticket").is(":checked")) {
                $("#is_ticket").trigger("click")
            }
            $('#addProduct ul.nav.nav-tabs li').removeClass('active');
            $('#addProduct ul.nav.nav-tabs li:eq(0)').addClass('active');
            $('#addProduct div.tab-pane').removeClass('active');
            $('#addProduct div.tab-pane:eq(0)').addClass('active');
            $('select[name=UOM_From],select[name=add_ons_id]').val('').trigger('change');
            $('input[name=in_product],input[name=out_product],input[name=in_uom],input[name=out_uom]').val('').trigger('change')
            $('.InContainer .InItem:gt(0),.OutContainer .OutItem:gt(0),.product_shelfs .shelfItem:gt(0),#UOMConForm .AddRow:gt(0),#slide5 .AddCriteriaRow:gt(0),#slide5 .AddCriteriaRow .criteria-items .cr-row:gt(0)').remove()
            $('#slide4 input[name=depot_id]').val('').trigger('change')
        })
        $("#addProduct").on("shown.bs.modal", function() {
            $("#printer_id").val('').select2();
            if (auto_generate_code == 1) {
                $("#Product_Code").val(max_code);
            } else {
                $("#Product_Code").val('');
            }
            $("#recipe_qty").val(1);
        });
        $('.floatingContainer a').on('click', function() {
            if (typeof(check_uom) == 'object') {
                $('.UOM_ID').val(check_uom['UOM_ID']).attr('data-select-name', check_uom['UOM_Name'])
                build_select2($(".UOM_ID"), "xhr/uomSearch");
            }
        })
        $("#VAT").on("change", function() {
            if ($(this).is(":checked")) {
                $(".vatPercentDiv").removeClass("hidden")
                $("#vat_percent").val(vat_percent)
                if (activate_second_vat == 1) {
                    $(".vat2PercentDiv").removeClass("hidden")
                    $("#vat2_percent").val(vat2_percent)
                }
            } else {
                $(".vatPercentDiv,.vat2PercentDiv").addClass("hidden")
                $("#vat_percent,#vat2_percent").val("")
            }
        });
        $("#slide5").on("click", ".AddButtons .fa-plus-circle", function(e) {
            $("#slide5 .AddButtons .fa-minus-circle").css("display", "inline-block")
            var Parent = $(this).parents(".AddCriteriaRow"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find("input,textarea").val('');
            $(".select2-container", NewItem).empty().remove()
            NewItem.find(".criteria_type").show().select2()
            $('.criteria-items .cr-row:eq(0) .fa-minus-circle', NewItem).css("display", "none")
            $('.criteria-items .cr-row:gt(0)', NewItem).remove()
            $('.criteria_count', NewItem).removeClass('hidden')
        });
        $("#slide5").on("click", " .AddButtons .fa-minus-circle", function(e) {
            $(this).closest(".AddCriteriaRow").empty().remove();
            $(".AddCriteriaRow").each(function() {
                $(".AddButtons .fa-minus-circle", $(this)).css({
                    "display": $(".AddCriteriaRow").length <= 1 ? "none" : "inline-block"
                })
            });
        });
        $("#slide5").on("change", 'select[name=criteria_type]', function() {
            var Parent = $(this).parents('.AddCriteriaRow');
            $(this).val() == 1 ? $(".criteria_count", Parent).removeClass('hidden') : ($(".criteria_count", Parent).addClass('hidden') && $(".criteria_count > input", Parent).val(1))
        });
        $(".add_ons_divs").on("click", ".buttons > .fa-plus", function(e) {
            $(".buttons > .fa-minus").css("display", "")
            var Parent = $(this).parents(".add-row"),
                NewItem = Parent.clone().insertAfter(Parent);
            $(".select2-container", NewItem).remove()
            $("input[name=product_add_ons_quantity]", NewItem).val('')
            $("select[name=add_ons_id]", NewItem).select2()
            $(".select2-container", NewItem).css({
                display: 'block'
            });
        });
        $(".add_ons_divs").on("click", ".buttons > .fa-minus", function(e) {
            $(this).parents('.add-row').remove()
            $(".add_ons_divs").each(function() {
                $(".buttons > .fa-minus", $(this).parent()).css({
                    "display": $(".buttons", $(this).parent()).length <= 1 ? "none" : "inline-block"
                })
            })
        });
        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', 'picture', 'hr']]
                ],
                focus: true
            });
            document.onselectstart = function() {
                return true
            };
        }
        $("#Category_ID").on("change", function() {
            if (enable_category_barcode == 1) {
                var cat_id = $(this).val();
                if (cat_id) {
                    $.ajax({
                        url: "InventoryAjax/get_category_prefix_barcode",
                        data: {
                            cat_id: cat_id
                        },
                        dataType: "json",
                        complete: function(v1, v2) {
                            console.log(v1)
                            console.log(v2)
                            if (v2 == 'success') {
                                var new_barcode = v1.responseJSON['new_barcode'];
                                $("#Bar_Code").val(new_barcode);
                                // uom_elem.val(v1.responseJSON['UOM_ID']);
                            }
                        }
                    })
                }
            }
        });
    });

    function ValidateForNewProductPhoto(input) {
        var FileUploadError = '';
        if (input.files && input.files[0]) {
            var FileName = $.trim(input.files[0].name)
            var FileType = FileName.substring(FileName.lastIndexOf("."));
            var FileSizeKB = input.files[0].size / 1024;
            if (FileType) {
                FileType = FileType.toLowerCase();
                var allowedExtensions = ['.jpg', '.png'];
                var maxAllowedSizeKB = 50;
                FileType = FileType.toLowerCase();
                if (allowedExtensions.indexOf(FileType) == -1)
                    FileUploadError = 'File Extension (' + FileType + ') not Supported<br/>Supported Extensions: ' + allowedExtensions.join();
                else if (FileSizeKB > maxAllowedSizeKB)
                    FileUploadError = 'File Size Exceed (' + maxAllowedSizeKB + ' KB)';
            }
            $("#NewProductNoPreviewFileUploadIcon").hide();
            $("#NewProductFilewarning2").remove();
            if (FileUploadError != '') {
                $("#NewProductNoPreviewFileUploadIcon").show();
                $("<span id='NewProductFilewarning2' style='color:#f00;display: block;text-align: center;white-space: normal;'>" + FileUploadError + "</span>").insertAfter($(input))
                return false;
            } else {
                $("#NewProductUploadImagePreview").hide()
                var reader = new FileReader();
                reader.onload = function(e) {
                    $("#NewProductUploadImagePreview").attr('src', e.target.result).show();
                };
                reader.readAsDataURL(input.files[0]);
                return true;
            }
        }
        return false;
    }

    function get_default_uom(pid, uom_elem) {
        if (pid) {
            $.ajax({
                url: "InventoryAjax/get_product_default_uom",
                data: {
                    pid: pid
                },
                dataType: "json",
                complete: function(v1, v2) {
                    if (v2 == 'success') {
                        //                        console.log(v1.responseJSON)
                        uom_elem.val(v1.responseJSON['UOM_ID']);
                        uom_elem.attr("data-select-name", v1.responseJSON['UOM_Name']);
                        build_select2(uom_elem, "xhr/productuomSearch?pid=" + pid);
                    }
                }
            })
        }
    }
    //    $(window).ready(function (e) {
    //
    //
    //
    //        $(window).scannerDetection();
    //        $(window).bind('scannerDetectionComplete', function (e, data) {
    //
    //            console.log('complete ' + data.string);
    //            $("#Product_Code").val(data.string);
    //        })
    //                .bind('scannerDetectionError', function (e, data) {
    //                    console.log('detection error ' + data.string);
    //                })
    //                .bind('scannerDetectionReceive', function (e, data) {
    //                    console.log('Recieve');
    //                    console.log(data.evt.which);
    //                })
    //    })
</script>
