<?php // echo '<pre>';print_r($Product_Info);                                                     
?>
<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>
<style>
    .AddRow,
    .AddCriteriaRow {
        background: #e5e5e5;
        padding: 10px;
        border-radius: 6px;
        margin-bottom: 10px;
    }

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

    .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;
    }

    .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;
        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;
    }

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

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

    #UpdateProductUploadPhoto>input,
    #UpdateProductUploadPhoto>input {
        position: absolute;
        left: 0px;
        top: 0px;
        width: 100%;
        height: 100%;
        opacity: 0.01;
        cursor: pointer;
    }
</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 stick-up DontReset " id="EditProduct" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog ">
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label bold"><?php echo CommonLanguage::getMessage('edit_product'); ?></h5>
                <div id="UpdateProductValidationAlert"></div>
            </div>
            <div class="modal-body">
                <form id="EditProductPostForm" 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 class="hidden">
                                <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 b-r b-dashed b-grey">
                                        <div class="profile-pic">
                                            <div class="profile-border">
                                                <img id="UpdateProductUploadImagePreview" src="<?php echo $filename1 ?>" alt="">
                                            </div>
                                        </div>
                                        <?php if (file_exists(dirBase . 'uploads/products_photos/' . $Product_ID . '.jpg')) { ?>
                                            <span class="fa fa-trash red-star delete_product_image" data-view="2" data-content="<?php echo $Product_ID; ?>" style="cursor:pointer;"></span>
                                        <?php } ?>
                                        <label class="btn btn-default" id="UpdateProductUploadPhoto"><?php print CommonLanguage::getMessage('Upload'); ?><input type="file" data-target="#UpdateProductUploadImagePreview" onchange="window.UpdateProductCurrentFileUploadaddProduct = event.target.files;ValidateForUpdateProductPhoto(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="hidden" placeholder="Product ID" id="Product_ID" name="Product_ID" class="form-control textinput " value="<?php echo $Product_ID; ?>">
                                                <input type="text" placeholder="<?php print CommonLanguage::getMessage('Code'); ?>" id="Product_Code" name="Product_Code" class="form-control textinput" value="<?php echo $Product_Info[0]["Product_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" value="<?php echo htmlentities($Product_Info[0]["Product_Name"], ENT_QUOTES); ?>" 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 value="<?php echo $Product_Info[0]['Cat_ID']; ?>" data-select-name="<?php echo $Product_Info[0]["Cat_Name"]; ?>" required id="Category_ID" name="Category_ID" class="full-width" type="hidden" required />
                                            </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>
                                                <?php if ($Product_Info[0]['is_used']) { ?>
                                                    <span style="color:red">(<?php echo CommonLanguage::getMessage('change_used_uom') ?>)</span>
                                                <?php } ?>
                                                <input required id="UOM_ID" name="UOM_ID" class="full-width UOM_ID" <?php echo $Product_Info[0]['is_used'] ? 'disabled' : '' ?> type="hidden" data-old="<?php echo $Product_Info[0]['UOM_ID']; ?>" value="<?= $Product_Info[0]['UOM_ID'] ?>" data-select-name='<?= json_encode($Product_Info[0]['UOM_Name']) ?>' data-isused="<?php echo $Product_Info[0]['is_used'] ?>" />
                                            </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" value="<?php echo $Product_Info[0]["Bar_Code"]; ?>" <?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" value="<?php echo $Product_Info[0]["Product_Arabic_Name"]; ?>">
                                            </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" value="<?= $Product_Info[0]['pur_cat_id'] ?>" data-select-name='<?= json_encode($Product_Info[0]['pur_cat_name']) ?>' <?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>
                                                <select id="current_branch_id" name="current_branch_id" class="full-width " multiple data-init-plugin="select2"  >
                                                    <?php foreach ($branches as $branch) : ?>
                                                        <option value="<?php echo $branch['branch_id']; ?>" <?php echo  in_array($branch['branch_id'],explode(",",$Product_Info[0]['multi_branch_id'])) ? 'selected' : '' ?>><?php echo $branch['branch_name']; ?></option>
                                                    <?php endforeach; ?>
                                                </select>
                                            </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" value="<?php echo $Product_Info[0]["n_width"]; ?>">
                                            </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" value="<?php echo $Product_Info[0]["n_height"]; ?>">
                                            </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="Product Reorder Point" id="Product_Reorder_Point" name="Product_Reorder_Point" class="form-control textinput" value="<?php echo $Product_Info[0]["Product_Reorder_Point"]; ?>">
                                            </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 id="printer_id" name="printer_id" class="full-width " multiple data-init-plugin="select2" <?php echo !in_array(1, $product_required_fields) ? '' : 'required' ?>>
                                                    <?php foreach ($printers as $printer) : ?>
                                                        <option value="<?php echo $printer['printer_id']; ?>" <?php echo $printer['printer_id'] == $Product_Info[0]['printers'][0] ? 'selected' : '' ?>><?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" value="<?= $Product_Info[0]['family_id'] ?>" data-select-name='<?= json_encode($Product_Info[0]['family_name']) ?>' <?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" value="<?php echo ($Product_Info[0]['product_second_code']); ?>" <?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" value="<?php echo !empty($Product_Info[0]['section_id']) ? $Product_Info[0]['section_id'] : '' ?>" data-select-name='<?= json_encode(!empty($Product_Info[0]['section_name']) ? $Product_Info[0]['section_name'] : '') ?>' />
                                    </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" value="<?php echo $Product_Info[0]['main_supplier_id'] ?>" data-select-name='<?= json_encode($Product_Info[0]['main_supplier_name']) ?>' <?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 value="<?php echo $Product_Info[0]['brand_id']; ?>" data-select-name="<?php echo $Product_Info[0]["brand_name"]; ?>" 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" value="<?= empty($Product_Info[0]['group_account_id']) ? '' : $Product_Info[0]['group_account_id'] ?>" data-select-name='<?= json_encode(empty($Product_Info[0]['group_account_id']) ? '' : $Product_Info[0]['group_name']) ?>' <?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 $Product_Info[0]['product_type'] == 0 ? 'selected' : '' ?>><?php echo CommonLanguage::getMessage('sales_purchase') ?></option>
                                            <option value="1" <?php echo $Product_Info[0]['product_type'] == 1 ? 'selected' : '' ?>><?php echo CommonLanguage::getMessage('sales') ?></option>
                                            <option value="2" <?php echo $Product_Info[0]['product_type'] == 2 ? 'selected' : '' ?>><?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" value="<?php echo $Product_Info[0]['Product_Limit_Discount'] ?>" />
                                    </div>
                                    <div class="col-md-3">
                                        <label><?php echo CommonLanguage::getMessage('color'); ?></label>
                                        <input type="text" name="product_color" id="product_color" value="<?php echo $Product_Info[0]['product_color'] ?>" 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" value="<?php echo $Product_Info[0]['product_order'] ?>" class="form-control" />
                                    </div>
                                    <div class="col-md-2">
                                        <div><label><?php print CommonLanguage::getMessage('weightable') . ' ?'; ?></label></div>
                                        <input type="hidden" id="Product_PLU" name="Product_PLU" value="<?php echo $Product_Info[0]['Product_PLU']; ?>" />
                                        <input type="checkbox" id="plu_type" name="plu_type" <?php echo $Product_Info[0]['PLU_Type'] == 'P' ? "checked" : ""; ?> />
                                    </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" <?php echo $Product_Info[0]['on_scale'] == 1 ? "checked" : ""; ?> />
                                    </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" <?php echo $Product_Info[0]['force_change_price'] == 1 ? "checked" : ""; ?> />
                                    </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" <?php echo $Product_Info[0]['duration_reservation'] == 1 ? "checked" : ""; ?> />
                                    </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" <?php echo $Product_Info[0]['is_tax'] == 1 ? "checked" : ""; ?> />
                                    </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" <?php echo $Product_Info[0]['is_lot'] == 1 ? "checked" : ""; ?> />
                                    </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" <?php echo $Product_Info[0]['is_serial'] == 1 ? "checked" : ""; ?> />
                                    </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" <?php echo $Product_Info[0]['is_ticket'] == 1 ? "checked" : ""; ?> />
                                    </div>
                                    <div class="col-md-1 ">
                                        <div><label><?php print CommonLanguage::getMessage('service') . ' ?'; ?></label></div>
                                        <input type="checkbox" id="is_service" name="is_service" <?php echo $Product_Info[0]['is_service'] == 1 ? "checked" : ""; ?> <?php echo $Product_Info[0]['service_used'] == 1 ? 'disabled' : '' ?> />
                                    </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" <?php echo $Product_Info[0]['is_expiry'] == 1 ? "checked" : ""; ?> />
                                    </div>
                                    <div class="col-md-1">
                                        <div><label><?php print CommonLanguage::getMessage('Taxable'); ?></label></div>
                                        <input type="checkbox" id="VAT" name="VAT" <?php echo $Product_Info[0]['Product_VAT'] == 1 ? "checked" : ""; ?> />
                                    </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" <?php echo $Product_Info[0]['is_rate'] == 1 ? "checked" : ""; ?> />
                                    </div>
                                    <div class="col-md-2 ">
                                        <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" <?php echo $Product_Info[0]['is_rate_type_one'] == 1 ? "checked" : ""; ?> />
                                    </div>
                                    <div class="col-md-2 ">
                                        <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" <?php echo $Product_Info[0]['is_rate_type_two'] == 1 ? "checked" : ""; ?> />
                                    </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" <?php echo $Product_Info[0]['effect_qty_link_product'] == 1 ? "checked" : ""; ?> />
                                    </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_to_edit" class="hide_pos_to_edit" name="hide_pos_to_edit" <?php echo $Product_Info[0]['hide_pos1'] == 1 ? "checked" : ""; ?> />
                                    </div>

                                    <div class="col-md-1  vatPercentDiv <?php echo $Product_Info[0]['Product_VAT'] == 1 ? '' : 'hidden' ?>">
                                        <label><?php print CommonLanguage::getMessage('vat_percent'); ?></label>
                                        <input type="text " id="vat_percent" class="form-control" name="vat_percent" value="<?php echo $Product_Info[0]['vat_percent'] ?>" />
                                    </div>
                                    <div class="col-md-1 vat2PercentDiv  <?php echo ($Product_Info[0]['Product_VAT'] == 1 && smc_session()['default_setting']['activate_second_vat']) ? '' : 'hidden' ?>">
                                        <label><?php print CommonLanguage::getMessage('vat2_percent'); ?></label>
                                        <input type="text " id="vat2_percent" class="form-control" name="vat2_percent" value="<?php echo $Product_Info[0]['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" value="<?php echo array_key_exists($class['Class_ID'], $class_price) ? $class_price[$class['Class_ID']]['Product_Price'] : 0 ?>" placeholder="<?php print $class['Class_Name'] . ' ' . CommonLanguage::getMessage('Price'); ?>" data-class="<?php echo $class['Class_ID'] ?>" class="form-control textinput digits price_value" required>
                                        </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"><?php echo $Product_Info[0]['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 "><?php echo $Product_Info[0]['product_description'] ?></textarea>
                                        <?php } ?>
                                        <!--<textarea class="form-control " id="product_description"  name="product_description" style="overflow: hidden; word-wrap: break-word; resize:vertical "></textarea>-->
                                    </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 "><?php echo nl2br($Product_Info[0]['additional_barcodes']) ?></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" value="<?php echo $Product_Info[0]['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" value="<?php echo $Product_Info[0]['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" value="<?php echo $Product_Info[0]['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" value="<?php echo $Product_Info[0]['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"><?php echo $Product_Info[0]['UOM_Name'] ?></span></h3>
                                <div class="col-md-12" id="UOMConForm">
                                    <?php
                                    if (!empty($uom_conversion)) {
                                        $is_uom_con_disabled = (!empty($products_links['in_items']) || !empty($products_links['out_items'])) ? true : false;
                                        foreach ($uom_conversion as $uom_conv) {
                                    ?>
                                            <div class="col-md-12 AddRow m-b-10 form-group" data-isused="<?php echo $uom_conv['is_used'] ?>">
                                                <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 id="UOM_From" name="UOM_From" class="full-width UOM_From" data-init-plugin="select2" <?php echo ($uom_conv['is_used'] || $is_uom_con_disabled) ? 'disabled' : '' ?>>
                                                                <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_ID'] == $uom_conv['uom_from'] ? 'selected' : '' ?>><?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><span class="fa fa-info-circle <?php echo $uom_conv['is_used'] || $is_uom_con_disabled ? '' : 'hidden'; ?>" title="<?php echo CommonLanguage::getMessage('change_used_uom_hint') ?>"></span></label>
                                                            <input type="text" <?php echo $uom_conv['is_used'] || $is_uom_con_disabled ? 'readonly' : ''; ?> class="form-control conval digits " value="<?php echo $uom_conv['conversion_amount'] ?>">
                                                        </div>
                                                        <div class="col-xs-4">
                                                            <label><?php echo CommonLanguage::getMessage('barcode') ?></label>
                                                            <input type="text" class="form-control code  " value="<?php echo $uom_conv['Bar_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 $uom_conv['price'][$class['Class_ID']]['Currency_ID'] ?>" class="form-control ignore cur_input" onkeyup="return false" onkeydown="return false" />
                                                                    <input type="text" value="<?php echo array_key_exists($class['Class_ID'], $uom_conv['price']) ? $uom_conv['price'][$class['Class_ID']]['Product_Price'] : 0 ?>" 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" <?php echo $uom_conv['uom_from'] == $Product_Info[0]['default_view_uom_id'] ? 'checked' : ''; ?> />
                                                            <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" <?php echo $uom_conv['uom_from'] == $Product_Info[0]['default_sales_uom'] ? 'checked' : ''; ?>>
                                                            <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" <?php echo $uom_conv['uom_from'] == $Product_Info[0]['default_purchase_uom'] ? 'checked' : ''; ?>>
                                                            <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" <?php echo $uom_conv['uom_from'] == $Product_Info[0]['print_uom_id'] ? 'checked' : ''; ?>>
                                                            <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 "><?php echo nl2br($uom_conv['additional_barcodes']) ?></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>
                                        <?php
                                        }
                                    } else {
                                        ?>
                                        <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 id="UOM_From" 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>
                                    <?php } ?>
                                </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"><?php echo $Product_Info[0]['link_note']; ?></textarea>
                                    </div>
                                </div>
                                <div class="row " 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 ">
                                            <?php
                                            if (!empty($products_links['in_items'])) {
                                                foreach ($products_links['in_items'] as $in) {
                                            ?>
                                                    <div class="col-md-12 InItem m-b-10">
                                                        <div class="col-md-4"><input type="hidden" class=" full-width" name="in_product" value="<?php echo $in['sub_product_id'] ?>" data-select-name="<?php echo $in['Product_Name'] ?>" /></div>
                                                        <div class="col-md-4"><input class="full-width" name="in_uom" type="hidden" value="<?php echo $in['UOM_ID'] ?>" data-select-name="<?php echo $in['UOM_Name'] ?>" /></div>
                                                        <div class="col-md-2"><input type="text" class="in_qty form-control" value="<?php echo $in['current_quantity'] ?>" /></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>
                                                <?php
                                                }
                                            } else {
                                                ?>
                                                <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>
                                            <?php } ?>
                                        </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="<?php echo $Product_Info[0]["recipe_qty"]; ?>" 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-4 text-center"><label><?php echo CommonLanguage::getMessage('qty'); ?></label></div>
                                            <div class="col-md-2"></div>
                                        </div>
                                        <div class="OutContainer ">
                                            <?php
                                            if (!empty($products_links['out_items'])) {
                                                foreach ($products_links['out_items'] as $out) {
                                            ?>
                                                    <div class="col-md-12 OutItem m-b-10">
                                                        <div class="col-md-4"><input type="hidden" class=" full-width" name="out_product" value="<?php echo $out['sub_product_id'] ?>" data-select-name="<?php echo $out['Product_Name'] ?>" /></div>
                                                        <div class="col-md-4"><input class="full-width " name="out_uom" type="hidden" value="<?php echo $out['UOM_ID'] ?>" data-select-name="<?php echo $out['UOM_Name'] ?>" /></div>
                                                        <div class="col-md-2"><input type="text" class="out_qty form-control" value="<?php echo $out['current_quantity'] ?>" /></div>
                                                        <div class="col-md-2 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>
                                                <?php
                                                }
                                            } else {
                                                ?>
                                                <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 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>
                                            <?php } ?>
                                        </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">
                                            <?php
                                            if (!empty($prod_options)) {
                                                foreach ($prod_options as $prod) {
                                            ?>

                                                    <div class="row op_out_row " data-id="<?php echo $prod['option_id'] ?>">
                                                        <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" value="<?php echo $prod['quantity'] ?>" />
                                                            </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" <?php echo $prod['is_required'] == 1 ? 'checked' : '' ?> />
                                                            </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 ">
                                                                <?php
                                                                if (!empty($prod['details'])) {
                                                                    foreach ($prod['details'] as $det) {
                                                                ?>
                                                                        <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" value="<?php echo $det['sub_product_id'] ?>" data-select-name='<?= json_encode($det['product_name']) ?>' /></div>
                                                                            <div class="col-md-4"><input class="full-width " name="op_uom" type="hidden" value="<?php echo $det['UOM_ID'] ?>" data-select-name='<?= json_encode($det['UOM_Name']) ?>' /></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>
                                                                <?php
                                                                    }
                                                                }
                                                                ?>
                                                            </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>
                                                <?php
                                                }
                                            } else {
                                                ?>
                                                <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>
                                            <?php }
                                            ?>
                                        </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>
                                        <?php
                                        if (empty($Product_Info['shelfs']))
                                            $Product_Info['shelfs']['']['shelfs'] = array();
                                        foreach ($Product_Info['shelfs'] as $depot_id => $depot_dtld) {
                                            $shelfs_ids = empty($depot_dtld['shelfs']) ? '' : implode(',', array_keys($depot_dtld['shelfs']));
                                            $shelfs_names = empty($depot_dtld['shelfs']) ? array() : array_values($depot_dtld['shelfs']);
                                        ?>
                                            <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" value="<?= $depot_id ?>" data-select-name='<?= json_encode($depot_dtld['depot_name']) ?>' name="depot_id" /></div>
                                                    <div class="col-md-6"><input class="full-width shelf_id" name="shelf_id" value="<?= $shelfs_ids; ?>" data-select-name='<?= json_encode($shelfs_names); ?>' 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; <?php echo count($Product_Info['shelfs']) <= 1 ? "display:none" : "" ?>"></span>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                            <div class="tab-pane slide-left" id="slide5">
                                <?php
                                if (!empty($product_criteria)) {
                                    foreach ($product_criteria as $criteria) {
                                        $count_details = count($criteria['detail']);
                                        $result = array_filter($criteria['detail'], function ($item) {
                                            if (!is_null($item['details_id'])) {
                                                return true;
                                            }
                                            return false;
                                        });
                                ?>
                                        <div class="col-md-12 AddCriteriaRow m-b-10 form-group" data-criteria-id="<?php echo $criteria['criteria_id']; ?>">
                                            <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'); ?>" value="<?php echo $criteria['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 echo $criteria['criteria_type'] == 1 ? 'selected' : ''; ?>><?php print CommonLanguage::getMessage('checkbox'); ?></option>
                                                        <option value="2" <?php echo $criteria['criteria_type'] == 2 ? 'selected' : ''; ?>><?php print CommonLanguage::getMessage('radio'); ?></option>
                                                    </select>
                                                </div>
                                                <div class="col-xs-2 p-l-0 criteria_count <?php echo $criteria['criteria_type'] == 2 ? 'hidden' : ''; ?>">
                                                    <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'); ?>" value="<?php echo $criteria['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 <?php echo count($result) > 0 ? 'prevent-delete-main' : ''; ?>" style="color:#ed9421;margin-top:15px;">
                                                    </span>
                                                </div>
                                            </div> <div class="col-md-12">
                                            <div class="criteria_detail_divs ">
                                                <div class="col-md-12">
                                                    <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">
                                                    <?php foreach ($criteria['detail'] as $det) { ?>
                                                        <div class="col-md-12 cr-row" data-criteria-detail-id="<?php echo $det['criteria_detail_id'] ?>">
                                                            <div class="col-xs-4 p-l-0">
                                                                <input type="text" name="criteria_detail_name" value="<?php echo $det['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" value="<?php echo $det['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 <?php echo !is_null($det['details_id']) ? 'prevent-delete-details' : ''; ?>" style="color:#ed9421;margin-top:15px;"></span>
                                                            </div>
                                                        </div>
                                                    <?php } ?>
                                                </div>
                                            </div>
                                        </div>
                                    <?php
                                    }
                                } else {
                                    ?>
                                    <div class="col-md-12 AddCriteriaRow m-b-10 form-group" data-criteria-id="0">
                                        <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;"></span>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <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" data-criteria-detail-id="0">
                                                        <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;"></span>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                <?php } ?>
                            </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>
                                    <?php if (empty($product_add_ons)) { ?>
                                        <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="1" 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>
                                        <?php
                                    } else {
                                        foreach ($product_add_ons as $add_ons_data) {
                                        ?>
                                            <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_ons_data['add_ons_id'] == $add['add_ons_id'] ? 'selected' : ''; ?>><?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="<?php echo $add_ons_data['product_add_ons_quantity']; ?>" 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="<?php echo count($product_add_ons) <= 1 ? "display:none" : "" ?>"></span>
                                                    </div>
                                                </div>
                                            </div>
                                    <?php
                                        }
                                    }
                                    ?>
                                </div>
                            </div>
                            <div class="tab-pane slide-left form-group hidden" 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 echo $Product_Info[0]['machine_type_id'] == 0 ? 'selected' : '' ?>><?php print CommonLanguage::getMessage('select'); ?></option>
                                            <option value="1" <?php echo $Product_Info[0]['machine_type_id'] == 1 ? 'selected' : '' ?>><?php echo CommonLanguage::getMessage('machine'); ?></option>
                                            <option value="2" <?php echo $Product_Info[0]['machine_type_id'] == 2 ? 'selected' : '' ?>><?php echo CommonLanguage::getMessage('parts'); ?></option>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-12 m-t-10 parts_divs <?php echo $Product_Info[0]['machine_type_id'] != 1 ? '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>
                                    <?php
                                    if (!empty($maintenance_arr['parts'])) {
                                        foreach ($maintenance_arr['parts'] as $part) {
                                    ?>
                                            <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" value="<?php echo $part['part_product_id'] ?>" data-select-name='<?= json_encode($part['Product_Name']) ?>' <?php echo $part['is_used'] ? 'readonly' : '' ?>>
                                                    </div>
                                                    <div class="col-md-4">
                                                        <textarea class="form-control parts_note" rows="1" style="overflow: hidden; word-wrap: break-word; resize:vertical "><?php echo $part['part_note'] ?></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 <?php echo $part['is_used'] ? 'hidden' : '' ?>" style="color:#ed9421;margin-top:15px;"></span>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php
                                        }
                                    } else {
                                        ?>
                                        <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>
                                    <?php } ?>
                                </div>
                                <div class="col-md-12 m-t-10 properties_divs <?php echo $Product_Info[0]['machine_type_id'] != 1 ? '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>
                                    <?php
                                    if (!empty($maintenance_arr['prop'])) {
                                        foreach ($maintenance_arr['prop'] as $prop) {
                                    ?>
                                            <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" value="<?php echo $prop['property_name'] ?>" data-id="<?php echo $prop['property_id'] ?>" class="full-width property_name form-control" <?php echo $prop['is_used'] ? 'readonly' : '' ?>>
                                                    </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 <?php echo $prop['is_used'] ? 'hidden' : '' ?>" style="color:#ed9421;margin-top:15px;"></span>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php
                                        }
                                    } else {
                                        ?>
                                        <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" data-id="0" 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>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" id="CloseUpdateProduct"> <?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn btn-primary" id="SubmitUpdateProduct"> <?php print CommonLanguage::getMessage('Save'); ?> </button>
            </div>
            <?php echo Forms::ModalLoader('UpdateProductIsBusy') ?>
        </div>
    </div>
</div>
<script type="text/javascript">
    var Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
        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')); ?>,
        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']); ?>,
        Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
        uom_used = <?php echo json_encode(CommonLanguage::getMessage('uom_used')); ?>,
        vat_percent = <?php echo json_encode(smc_session()['vat_percent']); ?>,
        is_sumernote = <?php echo json_encode(smc_session()['default_setting']['activate_summernote_in_product']); ?>,
        vat2_percent = <?php echo json_encode(smc_session()['default_setting']['second_vat_percent']); ?>,
        activate_second_vat = <?php echo json_encode(smc_session()['default_setting']['activate_second_vat']); ?>;
    var UpdateProductCurrentFileUploadaddProduct = "";
    var printers = <?php echo json_encode($Product_Info[0]['printers']); ?>,
        product_required_fields = <?php echo json_encode($product_required_fields); ?>;
    $(function() {
        $('#product_color').colorpicker({
            format: 'hex',
            autoInputFallback: false
        });
        //        fillAddOnsDetails(product_add_ons_details);
        build_select2($("#current_branch_id"), "xhr/CommonSearch?col_name=branch_name&col_id=branch_id&table=tbl_organization_branches");

        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")
        })
        build_select2($("#pur_cat_id"), "xhr/CommonSearch?col_name=pur_cat_name&col_id=pur_cat_id&table=tbl_purchase_cat");
        build_select2($("#Category_ID"), "xhr/catSearch");
        build_select2($("#section_id"), "xhr/CommonSearch?col_name=section_name&col_id=section_id&table=tbl_product_sections");
        //        $("#UOMConForm").each(function () {
        ////            if($(this).)
        //            $(".AddButtons > .fa-minus-circle", $(this).parent()).css({"display": $(".AddButtons", $(this).parent()).length <= 1 ? "none" : "inline-block"})
        //        })
        //        $("#printer_id option[value=1]").prop("selected",true)
        //        $("#printer_id").select2()
        $('#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)
        });
        $("#printer_id").val(printers).select2()
        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"));
        $('.OutItem').each(function() {
            build_select2($("input[name=out_uom]", $(this)), "xhr/productuomSearch?pid=" + $("input[name=out_product]", $(this)).val())
        });
        $('.InItem').each(function() {
            build_select2($("input[name=in_uom]", $(this)), "xhr/productuomSearch?pid=" + $("input[name=in_product]", $(this)).val())
        });
        $('.op_detail_row').each(function() {
            build_select2($("input[name=op_uom]", $(this)), "xhr/productuomSearch?pid=" + $("input[name=op_product]", $(this)).val())
        });
        build_select2($(".UOM_ID"), "xhr/uomSearch");
        build_select2($("#brand_id"), "xhr/CommonSearch?col_name=brand_name&col_id=brand_id&table=tbl_brand_products");
        build_select2($("#family_id"), "xhr/CommonSearch?col_name=family_name&col_id=family_id&table=tbl_inventory_family");
        build_select2($("#group_account_id"), "xhr/GroupAccountSearch")
        build_select2($("#main_supplier_id"), "xhr/supplierSearch");
        new Switchery($("#is_lot").get(0), {
            color: $.Pages.getColor("primary")
        });
        new Switchery($("#is_serial").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_to_edit").get(0), {
            color: $.Pages.getColor("primary")
        });
        new Switchery($("#is_ticket").get(0), {
            color: $.Pages.getColor("primary")
        });
        $("#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("").attr("data-id", 0)
                $(".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")
            }

        })

        $("#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);
        $(".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);
        });
        $(".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.removeAttr("data-isused");
            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").removeAttr("disabled").val(0).show().select2()
        });
        $(".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('').attr("data-id", 0);
        });
        $(".properties_divs").on("click", ".fa-minus-circle", function(e) {
            if ($(".add-prop-row").length == 1) {
                $(".property_name").val("").attr("data-id", 0)
            } else {
                $(this).closest(".add-prop-row").empty().remove();
            }
        });
        $(".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)
                    }
                }
            })
        });
        $("#UOMConForm").on("click", ".AddButtons > .fa-minus-circle", function(e) {
            if ($(this).parents(".AddRow").attr("data-isused") == 1) {
                $("#UpdateProductValidationAlert").attr("class", "alert alert-danger").show().html(uom_used)
                $("#EditProduct").scrollTop(0)
                return
            }
            if ($(".AddRow").length == 1) {
                $(".AddRow input").val("")
                $(".AddRow select.UOM_From").val(0).select2()
                $(".AddRow .additional_barcodes").val("")
            } else {
                $(this).closest(".AddRow").empty().remove();
            }
            //            $("#UOMConForm").each(function () {
            //                $(".AddButtons > .fa-minus-circle", $(this).parent()).css({"display": $(".AddButtons", $(this).parent()).length <= 1 ? "none" : "inline-block"})
            //            })
        })
        $(".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)
        })
        $("#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("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('');
            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"
                })
            })
        })

        $("#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();
            }
        });
        $("#SubmitUpdateProduct").on("click", function() {
            if (!$("#EditProductPostForm").valid())
                return;
            var is_criteria_details_empty = false,
                is_criteria_max_count_empty = false,
                criteria = [],
                is_add_ons_quantity = false,
                in_out_validate = true;
            $("#EditProductPostForm").validate();
            if ($("#Bar_Code").val().length > 5 && $("#move_scale").is(":checked")) {
                $("#UpdateProductValidationAlert").attr("class", "alert alert-danger").show().html(barcode_check)
                $("#EditProduct").scrollTop(0)
                return false;
            }
            //            if (!$("#EditProductPostForm").find("input.textinput").blur().end().valid()) {
            //                $("#UpdateProductValidationAlert").attr("class", "alert alert-danger").show().html(Required_Fields)
            //                $("#EditProduct").scrollTop(0)
            //                return
            //            }
            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 DataForm = new FormData();
            var Data = {
                Product_ID: $("#Product_ID").val(),
                Product_Code: $("#Product_Code").val(),
                Product_Name: $("#Product_Name").val(),
                product_description: is_sumernote == 1 ? $('#product_description').code() : $("#product_description").val(),
                product_color: $("#product_color").val(),
                product_order: $("#product_order").val(),
                Product_Reorder_Point: $("#Product_Reorder_Point").val(),
                Product_VAT: $("#VAT").is(":checked") ? 1 : 0,
                vat_percent: $("#vat_percent").val(),
                vat2_percent: $("#vat2_percent").val(),
                Category_ID: $("#Category_ID").val(),
                current_branch_id: $("#current_branch_id").val(),
                Bar_Code: $("#Bar_Code").val(),
                plu_type: $("#plu_type").is(":checked") ? 'P' : 'N',
                move_scale: $("#move_scale").is(":checked") ? 1 : 0,
                is_card: $("#is_card").is(":checked") ? 1 : 0,
                is_expiry: $("#is_expiry").is(":checked") ? 1 : 0,
                force_change_price: $("#force_change_price").is(":checked") ? 1 : 0,
                duration_reservation: $("#duration_reservation").is(":checked") ? 1 : 0,
                is_lot: $("#is_lot").is(":checked") ? 1 : 0,
                is_serial: $("#is_serial").is(":checked") ? 1 : 0,
                is_service: $("#is_service").is(":checked") ? 1 : 0,
                is_rate: $("#is_rate").is(":checked") ? 1 : 0,
                is_rate_type_one: $("#is_rate_type_one").is(":checked") ? 1 : 0,
                is_rate_type_two: $("#is_rate_type_two").is(":checked") ? 1 : 0,
                effect_qty_link_product : $("#effect_qty_link_product").is(":checked") ? 1 : 0,
                is_ticket: $("#is_ticket").is(":checked") ? 1 : 0,
                main_supplier_id: $("#main_supplier_id").val(),
                product_second_code: $("#product_second_code").val(),
                UOM_ID: $("#UOM_ID").val(),
                printer_id: $("#printer_id").val(),
                Product_Arabic_Name: $("#Product_Arabic_Name").val(),
                additional_barcodes: $("#additional_barcodes").val(),
                Product_PLU: $("#Product_PLU").val(),
                group_account_id: $("#group_account_id").val(),
                Product_Limit_Discount: $("#Product_Limit_Discount").val(),
                product_type: $("#product_type").val(),
                brand_id: $("#brand_id").val(),
                machine_type_id: $("#machine_type_id").val(),
                family_id: $("#family_id").val(),
                section_id: $("#section_id").val(),
                link_note: $('#link_note').val(),
                recipe_qty: $('#recipe_qty').val(),
                pur_cat_id: $('#pur_cat_id').val(),
                product_param1: ($('#product_param1').length > 0 ? $('#product_param1').val() : ''),
                product_param2: ($('#product_param2').length > 0 ? $('#product_param2').val() : ''),
                product_param3: ($('#product_param3').length > 0 ? $('#product_param3').val() : ''),
                product_param4: ($('#product_param4').length > 0 ? $('#product_param4').val() : ''),
                printer_arr: ($("#printer_id").val() == null ? '' : $("#printer_id").val().join()),
                n_width : $('#n_width').val(),
                n_height: $('#n_height').val(),
                hide_pos_to_edit: $("#hide_pos_to_edit").is(":checked") ? 1 : 0,
            };
            $.each(Data, function(key, value) {
                DataForm.append(key, value);
            })

            if (UpdateProductCurrentFileUploadaddProduct != "") {
                DataForm.append("image_file", UpdateProductCurrentFileUploadaddProduct[0]);
            }
            var price_arr = [],
                Con = [],
                in_item = [],
                out_item = [],
                product_shelf = [],
                add_ons = [],
                prop_arr = [],
                parts_arr = [],
                prop_ids = [];
            $(".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(),
                        property_id: $(this).find(".property_name").attr('data-id')
                    })
                    if ($(this).find(".property_name").attr('data-id') != 0) {
                        prop_ids.push($(this).find(".property_name").attr('data-id'))
                    }
                }
            });
            var conval_is_empty = false;
            //            console.log(prop_arr)
            //            return;
            $(".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
                    })
                    if (me.find("input[name=is_default_sales_uom]").is(":checked")) {
                        DataForm.append('default_sales_uom', me.find("select[name=UOM_From]").val())
                    }
                    if (me.find("input[name=is_default_purchase_uom]").is(":checked")) {
                        DataForm.append('default_purchase_uom', me.find("select[name=UOM_From]").val())
                    }
                    if (me.find("input[name=is_print_uom]").is(":checked")) {
                        DataForm.append('print_uom_id', me.find("select[name=UOM_From]").val())
                    }
                }
            });
            if (product_required_fields.includes('7') && Con.length == 0) {
                $('#UpdateProductValidationAlert').attr("class", "alert alert-danger").show().html('<?php echo CommonLanguage::getMessage('min_uom_conv_req'); ?>');
                $("#EditProduct").scrollTop(0)
                return;
            }
            if (conval_is_empty) {
                $('#UpdateProductValidationAlert').attr("class", "alert alert-danger").show().html('<?php echo CommonLanguage::getMessage('fill_value_uom_conversion'); ?>');
                $("#EditProduct").scrollTop(0);
                return;
            }
            $(".InItem").each(function() {
                $(this).find("input[name=in_uom]").removeClass("wrong")
                $(this).find(".in_qty").removeClass("wrong")
                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() != '') {
                        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;
                    }
                }
            })
            //            console.log(in_out_validate)
            //            return
            if (!in_out_validate) {
                $("#UpdateProductValidationAlert").attr("class", "alert alert-danger").empty().html(link_required);
                $("#UpdateProductIsBusy").addClass('hidden');
                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()
                    })
                }
            });
            var criteria_ids = [];
            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
                        }
                        $(this).attr('data-criteria-id') != 0 ? criteria_ids.push($(this).attr('data-criteria-id')) : '';
                        var criteria_detail_arr = [],
                            criteria_detail_ids = [];
                        $(".cr-row", $(this)).each(function() {
                            if (!$(".criteria_detail_name", $(this)).val())
                                is_criteria_details_empty = true;
                            criteria_detail_arr.push({
                                criteria_detail_id: $(this).attr('data-criteria-detail-id'),
                                criteria_detail_name: $(".criteria_detail_name", $(this)).val(),
                                criteria_detail_price: $(".criteria_detail_price", $(this)).val()
                            });
                            criteria_detail_ids.push($(this).attr('data-criteria-detail-id'));
                        })
                        criteria.push({
                            criteria_id: $(this).attr('data-criteria-id'),
                            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,
                            criteria_detail_ids: criteria_detail_ids
                        })
                    }
                });
            }
            if (is_criteria_max_count_empty) {
                AddAlert('#UpdateProductValidationAlert', '<?php echo CommonLanguage::getMessage('fill_criteria_max_count'); ?>', 'danger')
                return;
            }
            if (is_criteria_details_empty) {
                AddAlert('#UpdateProductValidationAlert', '<?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
                        });
                    }
                });
            }

            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({
                        option_id: $(this).attr("data-id") != undefined ? $(this).attr("data-id") : 0,
                        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()) {
                    DataForm.append('default_view_uom_id', $('select[name=UOM_From]', parent).val())
                    DataForm.append('default_view_rate', $('input.conval', parent).val())
                } else {
                    DataForm.append('default_view_uom_id', $('#UOM_ID').val())
                    DataForm.append('default_view_rate', 1)
                }
            } else {
                DataForm.append('default_view_uom_id', $('#UOM_ID').val())
                DataForm.append('default_view_rate', 1)
            }
            if (is_add_ons_quantity) {
                AddAlert('#ProductValidationAlert', '<?php echo CommonLanguage::getMessage('fill_add_ons_quantity'); ?>', 'danger')
                return;
            }
            DataForm.append('criteria_ids', JSON.stringify(criteria_ids))
            DataForm.append('criteria', JSON.stringify(criteria))
            DataForm.append("in_item", JSON.stringify(in_item))
            DataForm.append("out_item", JSON.stringify(out_item))
            DataForm.append("price_arr", JSON.stringify(price_arr))
            DataForm.append("con", JSON.stringify(Con))
            DataForm.append("price", $("input[data-class=1]").val())
            DataForm.append("product_shelf", JSON.stringify(product_shelf))
            DataForm.append("add_ons", JSON.stringify(add_ons))
            DataForm.append("prop_arr", JSON.stringify(prop_arr))
            DataForm.append("parts_arr", JSON.stringify(parts_arr))
            DataForm.append("prop_ids", JSON.stringify(prop_ids))
            DataForm.append("optionals", JSON.stringify(optionals))

            $("#UpdateProductIsBusy").removeClass('hidden');
            $.ajax({
                url: "InventoryAjax/EditProductRequest",
                method: "POST",
                dataType: 'json',
                data: DataForm,
                processData: false,
                contentType: false,
                complete: function(v1, v2) {
                    if (v2 == 'success') {
                        if (v1.responseJSON == 'OK') {
                            $(".Product_Code").empty().html(Data['Product_Code'])
                            $(".Product_Name").empty().html(Data['Product_Name'])
                            $(".Product_Quantity").empty().html(Data['Product_Quantity']);
                            $(".Product_Limit_Discount").empty().html(Data['Product_Limit_Discount'] + ' %');
                            $(".brand_name").empty().html($("#s2id_brand_id span").text());
                            $(".Product_Reorder_Point").empty().html(Data['Product_Reorder_Point']);
                            $(".Product_VAT").empty().html(Data['VAT'] ? 'Taxtable' : 'Not Taxtable')
                            $(".on_scale").empty().html(Data['move_scale'] ? 'Yes' : 'No')
                            $(".is_card").empty().html(Data['is_card'] ? 'Yes' : 'No')
                            $(".is_expiry").empty().html(Data['is_expiry'] ? 'Yes' : 'No')
                            $(".force_change_price").empty().html(Data['force_change_price'] ? 'Yes' : 'No')
                            $(".duration_reservation").empty().html(Data['duration_reservation'] ? 'Yes' : 'No')
                            $(".Category_ID").empty().html($("#s2id_Category_ID span").text());
                            $(".product_type").empty().html($("#product_type option:selected").text());
                            for (var i = 0; i < price_arr.length; i++) {
                                $(".price[data-class=" + price_arr[i]['class_id'] + "] span.PriceSpan").html(price_arr[i]['price'])
                            }
                            //                            $("#UpdateProductIsBusy").remove();
                            $("#UpdateProductValidationAlert").attr("class", "alert alert-success").empty().html(Submitted_Successfully);
                            if ($('#is_modal_shown').val() == 1) {
                                RebuildDataTable('', [0, 1, 2, 3], "InventoryAjax/listProductRequest");
                            }
                            setTimeout(function() {
                                //                                window.location.href = "Inventory/ViewProduct/"+Data['Product_ID']+"?is_pop=1&modal=0";
                                $("#EditProduct").modal('hide')
                                $("#UpdateProductValidationAlert").hide()
                                UpdateProductCurrentFileUploadaddProduct = "";
                                $("#ProductloadImagePreview").attr("src", $("#ProductloadImagePreview").attr("data-src") + "?" + ((new Date()).getSeconds() + (new Date()).getMilliseconds()))
                            }, 1500)
                        } else {
                            $("#UpdateProductValidationAlert").attr("class", "alert alert-danger").empty().html(v1.responseJSON[0]);
                        }
                    } else {
                        $("#UpdateProductValidationAlert").attr("class", "alert alert-danger").empty().html(Failed_Submit);
                    }
                    $("#EditProduct").scrollTop(0)
                    $("#UpdateProductIsBusy").addClass('hidden');
                }
            })
            // clearInput()
        });
        $("#CloseUpdateProduct").on("click", function() {
            //clearInput()
            // $("#EditProductPostForm").validate().resetForm();
            $("#EditProduct").modal("hide");
            if ($('.shelfItem').length > 1) {
                $('.shelfItem').not(':first').remove();
                $(".shelfItem >.fa-minus-circle").css('display', 'none');
            }
        })
        $("#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("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))
        });
        $("#slide5").on("click", " .AddButtons .fa-plus-circle", function(e) {
            var Parent = $(this).parents(".AddCriteriaRow"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find("input,textarea").val('');
            NewItem.attr('data-criteria-id', 0);
            $('.criteria-items .cr-row', NewItem).attr('data-criteria-detail-id', 0);
            $(".select2-container", NewItem).empty().remove()
            $(".fa-minus-circle", NewItem).removeClass('prevent-delete-main')
            $('.criteria-items .cr-row:gt(0)', NewItem).remove()
            NewItem.find(".criteria_type").show().select2()
        });
        $("#slide5").on("click", " .AddButtons .fa-minus-circle", function(e) {
            if ($('.AddCriteriaRow').length == 1)
                return;
            if ($(this).hasClass('prevent-delete-main')) {
                AddAlert('#UpdateProductValidationAlert', '<?php echo CommonLanguage::getMessage('unable_delete_criteria'); ?>', 'danger')
                return;
            }
            $(this).closest(".AddCriteriaRow").empty().remove();
        });
        $("#slide5").on("click", ".criteria-items .fa-plus-circle", function(e) {
            var Parent = $(this).parents(".cr-row"),
                NewItem = Parent.clone().insertAfter(Parent);
            NewItem.find("input").val('');
            NewItem.attr('data-criteria-detail-id', 0);
            $(".fa-minus-circle", NewItem).removeClass("prevent-delete-details")
        });
        $("#slide5").on("click", ".criteria-items .fa-minus-circle", function(e) {
            var parent = $(this).parents('.AddCriteriaRow');
            if ($(".cr-row", parent).length == 1)
                return;
            if ($(this).hasClass('prevent-delete-details')) {
                AddAlert('#UpdateProductValidationAlert', '<?php echo CommonLanguage::getMessage('unable_delete_criteria_details'); ?>', 'danger')
                return;
            }
            $(this).closest(".cr-row").empty().remove();
        });
        $('#EditProduct').on('hidden.bs.modal', function() {
            $('#EditProduct ul.nav.nav-tabs li').removeClass('active');
            $('#EditProduct ul.nav.nav-tabs li:eq(0)').addClass('active');
            $('#EditProduct div.tab-pane').removeClass('active');
            $('#EditProduct div.tab-pane:eq(0)').addClass('active');
        });
        $(".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
            });
            //        $(".summernote-wrapper").on('click', "[data-event = showImageDialog],[data-event=showLinkDialog]", function () {
            //            $(".modal-backdrop.in").remove()
            document.onselectstart = function() {
                return true
            };
        }
    });

    function clearValue() {
        $("#EditProduct input").val('');
        $("#UpdateProductUploadImagePreview").hide().attr("src", "");
    }

    function ValidateForUpdateProductPhoto(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) {
                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)';
            }
            $("#UpdateProductNoPreviewFileUploadIcon").hide();
            $("#UpdateProductFilewarning2").remove();
            if (FileUploadError != '') {
                $("#UpdateProductNoPreviewFileUploadIcon").show();
                $("<span id='UpdateProductFilewarning2' style='color:#f00;display: block;text-align: center;'>" + FileUploadError + "</span>").insertAfter($(input));
                return false;
            } else {
                $("#UpdateProductUploadImagePreview").hide();
                var reader = new FileReader();
                reader.onload = function(e) {
                    $("#UpdateProductUploadImagePreview").attr('src', e.target.result).show();
                };
                reader.readAsDataURL(input.files[0]);
                return true;
            }
        }
        return false;
    }
    //    function fillAddOnsDetails(details){
    //        if(details.length > 0 ){
    //            var current_row = $(".add_ons_divs .add-row:eq(0)").clone()
    //            $(".add_ons_divs .add-row").empty()
    //            $.each(details,function(index,value){
    //                current_row = current_row == null ? $(".add_ons_divs .add-row:eq(0)").clone() : current_row;
    //                $(".select2-container",current_row).remove()
    //                $("input[name=product_add_ons_quantity]",current_row).val(details[index]['product_add_ons_quantity'])
    //                $("select[name=add_ons_id]",current_row).val(details[index]['add_ons_id'])
    //                $("select[name=add_ons_id]",current_row).select2()
    //                $(".select2-container",current_row).css({display:'block'});
    //                $(".add_ons_divs").append(current_row)
    //                current_row = null
    //            }); 
    //            $(".add_ons_divs .add-row").each(function () {
    //                $(".buttons > .fa-minus", $(this).parent()).css({"display": $(".buttons", $(this).parent()).length <= 1 ? "none" : "inline-block"})
    //            })
    //        }
    //    }
    function get_default_uom(pid, uom_elem) {
        $.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);
                }
            }
        })
    }
</script>
