<?php
$this->load->view($left);
$this->load->view($header);
?>
<style type="text/css">
    .ibox-content {
        border-style : none;
    }

    .hr-line-dashed {
        margin: 5px 0;
    }

    .disabledbutton {
        pointer-events: none;
        opacity: 0.4;
    }

    .imageupload {
        background: white;
        border-radius: 5px;
        border: 2px dashed rgb(0, 135, 247);
        border-image: none;
        max-width: 500px;
        min-height:200px;
        margin-left: auto;
        margin-right: auto;
    }
    .addform .required:after {
    content: " *";
        color: red;
        font-weight: 100;
    }

</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" />
<div id="overlay" style="
    background: rgba(0,0,0,0.5);
    width: 100%;
    height: 100%;
    position: absolute;
    z-index: 99999;
"></div>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <h2>Update Product</h2>
    </div>
</div>
<img id="loader_image" style="display:none" src="<?=base_url()?>/img/loader.jpg">
<div class="wrapper wrapper-content">
    <div class="row text-center animated fadeInRightBig">
        <div class="col-lg-12">
            <form method="POST" action="" class="form-horizontal addform" id="invoice_data" enctype='multipart/form-data'>
                <div class="ibox float-e-margins">
                    <div class="ibox-content">

                        <div class="form-group">
                            <label class="col-sm-2 control-label required">Name</label>
                            <div class="col-sm-10">
                                <input type="text" name="name" id="name" class="form-control" placeholder="Name" value="<?php echo $product->name; ?>" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label required">Vendor</label>
                            <div class="col-sm-10">
                                <select class="form-control select2" name="vendor" id="vendor" required>
                                    <option value="">Select Vendor</option>
                                    <?php
                                    if (count($vendor_list) > 0) {
                                        foreach ($vendor_list as $key => $value) {
                                            ?>
                                            <option value="<?php echo $value->id; ?>" <?php echo ($product->_vendor == $value->id ? 'selected' : ''); ?> ><?php echo $value->vendor_name; ?></option>
                                            <?php
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"><a id="create_vendor_option" href='javascript:void(0)'>Create Vendor</a></label>
                            <div class="col-sm-10">
                                <input type="text" name="create_vendor" id="create_vendor" class="form-control" placeholder="Create Vendor" value="" >
                            </div>
                            
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Category</label>
                            <div class="col-sm-10">
                                <select class="form-control select2 required" name="category" id="category" required>
                                    <option value="">Select Category</option>
                                    <?php
                                    if (count($category_list) > 0) {
                                        foreach ($category_list as $key => $value) {
                                            ?>
                                            <option value="<?php echo $value->id; ?>" <?php echo ($product->_category == $value->id ? 'selected' : ''); ?> ><?php echo $value->name; ?></option>
                                            <?php
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><a id="create_category_option" href='javascript:void(0)'>Create Category</a></label>
                            <div class="col-sm-10">
                                <input type="text" name="create_category" id="create_category" class="form-control" placeholder="Create Category" value="" >
                            </div>
                            
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label required">SKU</label>
                            <div class="col-sm-10">
                                <label class="col-sm-6 control-label" style="color:red; margin-top:-20px;">Please Change Duplicate Value</label>
                                <input type="text" name="photo_id" id="photo_id" class="form-control" placeholder="SKU" value="<?php echo $product->photo_id; ?>" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label required">Description</label>
                            <div class="col-sm-10">
                                <input type="text" name="description" id="description" class="form-control" placeholder="Description" value="<?php echo $product->description; ?>" required>
                            </div>
                        </div>

                        <!--<div class="form-group">
                            <label class="col-sm-2 control-label">Color</label>
                            <div class="col-sm-10">
                                <input type="text" name="color" id="color" class="form-control" placeholder="Color" value="<?php echo $product->color; ?>" required>
                                <select class="form-control" name="color" id="color" required>
                                    <option value="">Select Color</option>
                                    <?php
                                    if (!empty($color_drop)) {
                                        foreach ($color_drop->result() as $value) {
                                            ?>
                                            <option value="<?php echo $value->id; ?>"<?= $product->color == $value->color ? "selected" : '' ?> ><?php echo $value->color; ?></option>
                                            <?php
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>-->
                        <?php
                         //echo "<pre>";
                         //print_r($product);
                        ?>
                        <div class="form-group">
                            <label class="col-sm-2 control-label required">Colors</label>
                            <div class="col-sm-10">
                                <select class="form-control select2" multiple name="colors[]" id="colors" required>
                                    <option value="">Select Color</option>
                                    <?php
                                    $arr_colors = array();
                                    if (!empty($color_drop)) {
                                        if($product->colors != null && $product->colors != ''){
                                            $arr_colors = json_decode($product->colors);
                                        }
                                        
                                        //print_r($arr_colors);exit;
                                        if(count($arr_colors > 0)){
                                           foreach ($arr_colors as $value) {

                                            ?>
                                            <option value="<?php echo $value; ?>" selected ><?php echo $value; ?></option>
                                            <?php
                                            } 
                                        }
                                        
                                        foreach ($color_drop->result() as $value) {
                                            if(!in_array($value->color, $arr_colors)){
                                            ?>
                                                <option value="<?php echo $value->color; ?>"><?php echo $value->color; ?></option>
                                            <?php
                                            }
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                            
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"><a id="create_color_option" href='javascript:void(0)'>Create Color</a></label>
                            <div class="col-sm-10">
                                <input type="text" name="create_color" id="create_color" class="form-control" placeholder="Create Color" value="" >
                            </div>
                            
                        </div>
                        
                        
                        <!--<div class="form-group">
                            <label class="col-sm-2 control-label">Residential</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="isResidential" id="isResidential" data-tr="0" required>
                                                <option value="">Residential</option>
                                                  <option value="1" <?= ($product->isResidential == 1) ? "Selected" : "";?> >Yes</option>
                                                  <option value="0" <?= ($product->isResidential == 0) ? "Selected" : "";?> >No</option>  
                                </select>
                            </div>
                            
                        </div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Commercial</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="isCommercial" id="isCommercial" data-tr="0" required>
                                                <option value="">Commercial</option>
                                                  <option value="1" <?= ($product->isCommercial == 1) ? "Selected" : "";?> >Yes</option>
                                                  <option value="0" <?= ($product->isCommercial == 0) ? "Selected" : "";?> >No</option>  
                                </select>
                            </div>
                            
                        </div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Furniture</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="isFurniture" id="isFurniture" data-tr="0" required>
                                                <option value="">Furniture</option>
                                                  <option value="1" <?= ($product->isFurniture == 1) ? "Selected" : "";?> >Yes</option>
                                                  <option value="0" <?= ($product->isFurniture == 0) ? "Selected" : "";?> >No</option>  
                                </select>
                            </div>
                            
                        </div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Promo</label>
                            <div class="col-sm-10">
                                 <input type="text" name="promo" id="promo" class="form-control" placeholder="Promo" value="<?=$product->promo?>" >
                            </div>
                            
                        </div> -->
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Sale</label>
                            <div class="col-sm-10">
                                 <input type="text" name="sale" id="sale" class="form-control" placeholder="Sale" value="<?=$product->sale?>" >
                            </div>
                            
                        </div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Custom Price</label>
                            <div class="col-sm-10">
                                 <input type="text" name="custom_price" id="custom_price" class="form-control" placeholder="Custom Price" value="<?=$product->custom_price?>" >
                            </div>
                            
                        </div>
                        
                        
                        <div class="form-group">
                            <div class="col-sm-12">
                                <input type="hidden" name="new_arrival" id="new_arrival" class="form-control" value="0" >
                            </div>
                            
                        </div>

                        
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label required">Material</label>
                            <div class="col-sm-10">
                                <input type="text" name="material" id="material" class="form-control" placeholder="Material" value="<?php echo $product->material; ?>" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Backing</label>
                            <div class="col-sm-10">
                                <input type="text" name="backing" id="backing" class="form-control" placeholder="Backing" value="<?php echo $product->backing; ?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label required">Quality</label>
                            <div class="col-sm-10">
                                <input type="text" name="quality" id="quality" class="form-control" placeholder="Quality" value="<?php echo $product->quality; ?>" required>
                                 <!--<select class="form-control" name="quality" id="quality" required>
                                    <option value="">Select Quality</option>
                                    <?php
                                    if (!empty($qualities_drop)) {
                                        foreach ($qualities_drop->result() as $value) {
                                            ?>
                                            <option value="<?php echo $value->id; ?>"<?= $product->quality == $value->name ? "selected" : '' ?> ><?php echo $value->name; ?></option>
                                            <?php
                                        }
                                    }
                                    ?>
                                </select>-->
                            </div>
                        </div>
        
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><a id="create_quality_option" href='javascript:void(0)'>Create Quality</a></label>
                            <div class="col-sm-10">
                                <input type="text" name="create_quality" id="create_quality" class="form-control" placeholder="Create Quality" value="" >
                            </div>
                            
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label required">Collection</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="collections" id="collections" required>
                                    <option value="">Select Collection</option>
                                    <?php
                                    if (!empty($collection_list)) {
                                        foreach ($collection_list as $value) {
                                            ?>
                                            <option value="<?php echo $value->id; ?>" <?= $product->collection == $value->name ? "selected" : '' ?> ><?php echo $value->name; ?></option>
                                            <?php
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label required">Design</label>
                            <?php if($product->attributes){
                                $attributes=json_decode($product->attributes);
                                foreach($attributes as $value){
                                    if($value->group==='design'){
                                        
                                        ?>
                                        <div class="col-sm-10">
                                            <input type="text" name="design" id="design" class="form-control" placeholder="Design" value="<?= $value->name;?>" required>
                                        </div>
                                <?php        
                                    }
                                }
                            }else{
                            ?>
                            <div class="col-sm-10">
                                            <input type="text" name="design" id="design" class="form-control" placeholder="Design" value="" required>
                            </div>
                            <?php }?>
                        </div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label required">Vendor SKU</label>
                            <div class="col-sm-10">
                                <input type="text" name="vendor_sku" id="vendor_sku" class="form-control" placeholder="Vendor SKU" value="<?= $product->vendor_sku?>" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">Keywords</label>
                            <div class="col-sm-10">
                                <input type="text" name="keyword_additions" id="keyword_additions" class="form-control" placeholder="Keywords" value="<?php echo $product->keyword_additions; ?>">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label required">Image</label>
                            <div class="col-sm-10">
                                <!-- <input type="file" name="productimage" id="productimage" class="form-control"> -->
                                <input type="hidden" multiple="multiple" name="image_name[]" class="form-control image_upload" />
                                <div class="needsclick imageupload" id="demo-upload">
                                    <DIV class="dz-message needsclick">  

                                        Drop files here or click to upload.

                                    </DIV>
                                </div>

                            </div>
                        </div>

                        <?php if ($product->thumb_pic != '' && $product->picture != '' && $product->large_pic != '') { ?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">All Images</label>
                                <div class="col-sm-10">

                                    <input type="hidden" name="smallimg" id="smallimg" class="form-control" value="<?php echo $product->thumb_pic; ?>">
                                    <input type="hidden" name="medimg" id="medimg" class="form-control" value="<?php echo $product->picture; ?>">
                                    <input type="hidden" name="largeimg" id="largeimg" class="form-control" value="<?php echo $product->large_pic; ?>">

                                    <img src="<?php echo site_url($product->thumb_pic); ?>" height="100px" width="100px">
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <img src="<?php echo site_url($product->picture); ?>" height="100px" width="100px">
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <img src="<?php echo site_url($product->large_pic); ?>" height="100px" width="100px">
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                </div>
                            </div>
                        <?php } ?>

                        <!-- <div class="form-group date_calender">
                             <label class="col-sm-2 control-label">Invoice Date</label>
                             <div class="col-sm-4">
                                 <div class="input-group date">
                                     <span class="input-group-addon"><i class="fa fa-calendar"></i></span><input type="text" name="invoice_date" id="invoice_date" class="form-control" value="<?php echo (!empty($invoice_id) && isset($invoice_data) ? date('d/m/Y', strtotime(str_replace('-', '/', $invoice_data['invoice_date']))) : date('d/m/Y')); ?>">
                                 </div>
                             </div>
                             <label class="col-sm-2 control-label">Due Date</label>
                             <div class="col-sm-4">
                                 <div class="input-group date">
                                     <span class="input-group-addon"><i class="fa fa-calendar"></i></span><input type="text" name="due_date" id="due_date" class="form-control" value="<?php echo (!empty($invoice_id) && isset($invoice_data) ? date('d/m/Y', strtotime(str_replace('-', '/', $invoice_data['due_date']))) : date('d/m/Y')); ?>">
                                 </div>
                             </div>
                         </div> -->
                         
                        <!-- Extra Image -->
			
                        <div class="col-md-12" style="border-top:1px solid #939393; padding-top: 5px;">
                                <h3 style="float:left;"><b>Extra Images :</b></h3>
                        </div>
                                        
                                      
                            <div class="col-md-12">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">File</label>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label text-center">Type</label>
                                    </div>
                                </div>
                            </div>
                        <div id="divextraimagerow">
                            <div class="col-md-12">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <div class="col-sm-10">
                                            <input type="file" name="extra_image[]"  class="form-control" value="">
                                            <input type="hidden" name="extra_image_id[]" value="">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <div class="col-sm-10">
                                            <select class="form-select" name="extra_image_type[]" style="float:left;">
                                                <option value="">Select image type</option>
                                                <option value="ang">ang</option>
                                                <option value="back">back</option>
                                                <option value="corner">corner</option>
                                                <option value="head">head</option>
                                                <option value="roomscene">roomscene</option>
                                                <option value="wash">wash</option>
                                                <option value="rect">rect</option>
                                                <option value="zoom">zoom</option>
                                            </select>

                                        </div>
                                    </div>
                            </div>
                        </div>
                    </div>
                        <div class="row">
                            <div class="col-md-10">
                                <div class="form-group">
                                    <div class="col-sm-2"> 
                                        <button type="button" id="btn_extra_image_add" class="btn btn-primary"><i class="fa fa-plus"></i></button>
                                    </div>
                                </div>
                            </div>
                         
                        <div class="col-md-12" style="border-top:1px solid #939393; padding-top: 5px;">
                            <h3 style="float:left;"><b>Variations(s) :</b></h3>
                        </div>
                        <div id="sell_item" class="form-group">
                            <div class="col-sm-12 table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr><th></th>
                                            <th>GS1</th>
                                            <th>MSRP</th>
                                            <!--<th>Length</th>
                                            <th>Width</th>
                                            <th>Height</th>-->
                                            <th>Old Price</th>
                                            <th class="required">Price</th>
                                            <th>Cost</th>
                                            <th class="required">Search Size</th>
                                            <th class="required">Size</th>
                                            <!--<th>Shape</th>
                                            <th>Stock</th>-->
                                            <!--<th>shippingHeight</th>
                                            <th>shippingLength</th>
                                            <th>shippingWidth</th>-->
                                            <th class="required">Active</th>
                                            <th class="required">Size SKU</th>
                                            <!--<th>Alias Size</th>-->
                                        </tr>
                                    </thead>
                                    <tbody id="products">
                                        <?php
                                        if (isset($item_details) && count($item_details)) {
                                            foreach ($item_details as $key => $value) {
                                                ?>
                                                <tr class="tr_<?php echo $key; ?>">
                                                    <td style="width: 40%;">
                                                        <div class="col-sm-1 no-padding">
                                                            <button type="button" class="btn btn-danger btn-circle btn-xxs remove_item" data-tr="<?php echo $key; ?>"><i class="fa fa-times-circle-o fa-lg"></i></button>
                                                        </div>
                                                        <div class="col-sm-11 no-padding">
                                                            <input type="" name="item_name[]" id="item_name_0" class="form-control item_name" data-tr="<?php echo $key; ?>" value="<?php echo!empty($value->item) ? $value->item : ''; ?>">
                                                            <!-- <select class="form-control item_name" name="item_name[]" data-tr="0">
                                                                <option value="">Select Item</option>
                                                            <?php
                                                            //if(count($item_list) > 0){
                                                            //foreach($item_list as $key_item => $value_item){
                                                            ?>
                                                                    <option value="<?php //echo $value_item->item_id;     ?>" <?php //echo (!empty($value->item) && ($value_item->item_id == $value->item)) ? 'selected="selected"' : '';      ?>><?php //echo $value_item->item_name;     ?></option>
                                                            <?php
                                                            //}
                                                            //}
                                                            ?>
                                                            </select> -->
                                                        </div>
                                                    </td>
                                                    <td style="width: 10%;"><input type="text" name="hsn_code" id="hsn_code0" class="form-control hsn_code" data-tr="<?php echo $key; ?>" value="<?php echo!empty($value->hsn_code) ? $value->hsn_code : ''; ?>"></td>
                                                    <td style="width: 10%;"><input type="number" name="gst_rate" id="gst_rate0" class="form-control gst_rate" data-tr="<?php echo $key; ?>" value="<?php echo!empty($value->gst_rate) ? $value->gst_rate : ''; ?>"></td>
                                                    <td style="width: 10%;"><input type="number" name="item_quantity[]" class="form-control quantity" data-tr="<?php echo $key; ?>" value="<?php echo!empty($value->qty) ? $value->qty : ''; ?>"></td>
                                                    <td style="width: 10%;"><select name="uom[]" class="form-control uom" id="uom0" data-tr="0"><option value="Pice" <?php echo (!empty($value->uom) && ($value->uom == 'Pice')) ? 'slected="selected"' : ''; ?>>Pice</option><option value="Pair" <?php echo (!empty($value->uom) && ($value->uom == 'Pair')) ? 'slected="selected"' : ''; ?>>Pair</option><option value="Set" <?php echo (!empty($value->uom) && ($value->uom == 'Set')) ? 'slected="selected"' : ''; ?>>Set</option></select></td>
                                                    <td style="width: 10%;"><input type="number" name="item_rate[]" class="form-control unit_price" id="unit_price0" data-tr="<?php echo $key; ?>" value="<?php echo!empty($value->rate) ? number_format((float) $value->rate, 2, '.', '') : ''; ?>"></td>
                                                    <td style="width: 10%;"><input type="number" name="item_discount[]" class="form-control discount" data-tr="<?php echo $key; ?>" value="<?php echo!empty($value->discount) ? $value->discount : ''; ?>"></td>
                                                    <td style="width: 10%;"><span id="item_price_<?php echo $key; ?>"><?php echo!empty($value->amount) ? number_format((float) $value->amount, 2, '.', '') : ''; ?></span></td>
                                                </tr>
                                                <?php
                                            }
                                        } else {
                                            ?>
                                            <?php
                                            $variations = json_decode($product->variations);
                                            
                                            if ($variations) {
                                                foreach ($variations as $vkey => $value) {
                                                   
                                                    ?>
                                                    <tr class="tr_<?php echo $vkey; ?>">
                                                        <?php if ($vkey != 0) { ?>
                                                            <td style="width: 10%;">
                                                                <button type="button" class="btn btn-danger btn-circle btn-xxs remove_item" data-tr="<?php echo $vkey; ?>"><i class="fa fa-times-circle-o fa-lg"></i></button></td>
                                                        <?php } else { ?>
                                                            <td></td>
                                                        <?php } ?>
                                                        <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="gs1[]" id="hsn_code<?php echo $vkey; ?>" class="form-control hsn_code" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->GS1) ? $value->GS1 : ''); ?>"></td>
                                                        <td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="msrp[]" id="hsn_code<?php echo $vkey; ?>" class="form-control hsn_code" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->MSRP) ? $value->MSRP : ''); ?>"></td>
                                                        <!--<td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="length[]" id="gst_rate<?php echo $vkey; ?>" class="form-control gst_rate" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->length) ? $value->length : ''); ?>"></td>
                                                        <td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="width[]" class="form-control quantity" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->width) ? $value->width : ''); ?>"></td>
                                                        <td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="height[]" class="form-control quantity" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->height) ? $value->height : ''); ?>"></td>-->
                                                        
                                                        <td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="old_cost[]" class="form-control unit_price" id="oldcost<?php echo $vkey; ?>" data-tr="0" value="<?php echo (isset($value->old_price) ? $value->old_price : ''); ?>"></td>
                                                        
                                                        <td style="width: 10%;"><input type="number" style="padding: 0px 0px;width: 80px;" name="price[]" class="form-control unit_price" id="unit_price<?php echo $vkey; ?>" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->price) ? $value->price : ''); ?>" required></td>
                                                        <td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="cost[]" class="form-control unit_price" id="cost<?php echo $vkey; ?>" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->cost) ? $value->cost : ''); ?>"></td>
                                                        <td style="width: 10%;">
                                                            <!--<input type="number" name="size[]" class="form-control discount" data-tr="<?php echo $vkey; ?>" value="<?php echo ($value->size ? $value->size : ''); ?>">-->
                                                            <select class="form-control" style="padding: 0px 0px;width: 80px;" name="searchsize[]" id="searchsize<?php echo $vkey; ?>" data-tr="<?php echo $vkey; ?>" required>
                                                                <option value="">Search Size</option>
                                                                <?php
                                                                if (!empty($size_drop)) {
                                                                    foreach ($size_drop->result() as $val) {
                                                                        $searchSize = '';
                                                                        if (property_exists($value, 'searchSize')){
                                                                            $searchSize = $value->searchSize;
                                                                        }
                                                                        if (property_exists($value, 'searchsize')){
                                                                            $searchSize = $value->searchsize;
                                                                        }
                                                                        
                                                                        ?>
                                                                        <option actSize="<?php echo str_replace("'", "", $searchSize); ?>" value="<?php echo $val->id; ?>"<?=  strtolower($searchSize) == strtolower($val->size) ? "selected" : '' ?> ><?php echo $val->size; ?></option>
                                                                        <?php
                                                                    }
                                                                }
                                                                ?>
                                                            </select>
                                                        </td>
                                                          </td>
                                                        <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="size[]" class="form-control unit_price" id="size<?php echo $vkey; ?>" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->size) ? $value->size : ''); ?>" required></td>
                                                        <!--<td style="width: 10%;">
                                                      <select class="form-control hsn_code" style="padding: 0px 0px;width: 80px;" name="shape[]" id="shape" data-tr="0" required>
                                                        <option value="">Shape</option>
                                                        <?php
                                                        if (!empty($shape_drop)) {
                                                            foreach ($shape_drop->result() as $value2) {
                                                                ?>
                                                                <option value="<?php echo $value2->id; ?>" <?= $value2->id == $value->shape ? "selected" : '' ?> ><?php echo $value2->shape; ?></option>
                                                                <?php
                                                            }
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                                 <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="stock[]" class="form-control unit_price" id="stock<?php echo $vkey; ?>" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->stock) ? $value->stock : ''); ?>"></td>-->
                                                
                                                   <!--<td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="shippingHeight[]" id="hsn_code<?php echo $vkey; ?>" class="form-control hsn_code" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->shippingHeight) ? $value->shippingHeight : ''); ?>"></td>
                                                        <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="shippingLength[]" id="hsn_code<?php echo $vkey; ?>" class="form-control hsn_code" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->shippingLength) ? $value->shippingLength : ''); ?>"></td>
                                                        <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="shippingWidth[]" id="hsn_code<?php echo $vkey; ?>" class="form-control hsn_code" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->shippingWidth) ? $value->shippingWidth : ''); ?>"></td>-->
                                                        
                                                        <td style="width: 10%;">
                                                         <select class="form-control hsn_code" style="padding: 0px 0px;width: 80px;" name="active[]" id="active" data-tr="<?php echo $vkey; ?>" required>
                                                            <?php 
                                                            $active = '';
                                                            if(property_exists($value, 'active'))
                                                            {  
                                                                $active = $value->active;
                                                            }
                                                            ?>
                                                                <option value="">Active</option>
                                                                <option value="1" <?= ($active == 1) ? "Selected" : "";?>>Yes</option>
                                                                <option value="0" <?= ($active == 0) ? "Selected" : "";?>>No</option>  
                                                        </select>
                                                        </td>
                                                        <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="sizesku[]" id="hsn_code<?php echo $vkey; ?>" class="form-control hsn_code" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->sizesku) ? $value->sizesku : ''); ?>" required></td>
                                                        <!--<td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="aliassize[]" id="hsn_code<?php echo $vkey; ?>" class="form-control hsn_code" data-tr="<?php echo $vkey; ?>" value="<?php echo (isset($value->aliasSize) ? $value->aliasSize : ''); ?>"></td>-->
                                                    </tr>
                                                    <?php
                                                }
                                            } else {
                                                ?>
                                                <tr class="tr_0">
                                                    <td></td>
                                                    <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="gs1[]" id="hsn_code0" class="form-control hsn_code" data-tr="0"></td>
                                                    <td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="msrp[]" id="hsn_code0" class="form-control hsn_code" data-tr="0"></td>
                                                    <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="length[]" id="gst_rate0" class="form-control gst_rate" data-tr="0"></td>
                                                    <td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="width[]" class="form-control quantity" data-tr="0"></td>
                                                    <td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="height[]" class="form-control quantity" data-tr="0"></td>
                                                    <td style="width: 10%;"><input type="number" style="padding: 0px 0px;width: 80px;" name="price[]" class="form-control unit_price" id="unit_price0" data-tr="0"></td>
                                                    <td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="cost[]" class="form-control unit_price" id="cost0" data-tr="0"></td>
                                                    <td style="width: 10%;">
                                                        <!--<input type="number" name="size[]" class="form-control discount" data-tr="0">-->
                                                        <select class="form-control" style="padding: 0px 0px;width: 80px;" name="size[]" id="size" data-tr="0" required>
                                                            <option value="">Size</option>
                                                            <?php
                                                            if (!empty($size_drop)) {
                                                                foreach ($size_drop->result() as $val) {
                                                                    ?>
                                                                    <option value="<?php echo $val->id; ?>"><?php echo $val->size; ?></option>
                                                                    <?php
                                                                }
                                                            }
                                                            ?>
                                                        </select>
                                                    </td>
                                                     <select class="form-control hsn_code" style="padding: 0px 0px;width: 80px;" name="shape[]" id="shape" data-tr="0" required>
                                                        <option value="">Shape</option>
                                                        <?php
                                                        if (!empty($shape_drop)) {
                                                            foreach ($shape_drop->result() as $value) {
                                                                ?>
                                                                <option value="<?php echo $value->id; ?>" ><?php echo $value->shape; ?></option>
                                                                <?php
                                                            }
                                                        }
                                                        ?>
                                                    </select>
                                                    <!--<td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="shape[]" id="hsn_code0" class="form-control hsn_code" data-tr="0"></td>
                                                    <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="stock[]" id="hsn_code0" class="form-control hsn_code" data-tr="0"></td>
                                                    <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="shippingHeight[]" id="hsn_code0" class="form-control hsn_code" data-tr="0"></td>
                                                    <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="shippingLength[]" id="hsn_code0" class="form-control hsn_code" data-tr="0"></td>
                                                    <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="shippingWidth[]" id="hsn_code0" class="form-control hsn_code" data-tr="0"></td>-->
                                                </tr>
                                            <?php } ?>
                                        <?php } ?>
                                    </tbody>
                                </table>
                                <div class="form-group" style="float: right;">
                                    <div class="col-lg-6">
                                        <button type="button" style="float: right;" class="btn btn-success additem"><i class="fa fa-plus-square"></i><span class="m-l-xs">Add Item</span></button>
                                    </div>                            
                                </div>
                            </div>
                            <div class="col-md-12" style="border-top:1px solid #939393; padding-top: 5px;">
                                <h3 style="float:left;"><b>Additional Attribute :</b></h3>
                            </div>
                            <div class="col-md-12">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">Name</label>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">value</label>
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">Frontend</label>
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">Backend</label>
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group">

                                    </div>
                                </div>
                            </div>
                            <div id="divrow">
                                <?php
                                if (!empty($product->additional_attributes)) {
                                    $add_attributes = json_decode($product->additional_attributes);
                                    foreach ($add_attributes as $attr) {
                                        //print_r($attr);
                                        ?>
                                        <div class="col-md-12">
                                            <div class="col-md-3">
                                                <div class="form-group">
                                                    <div class="col-sm-10">
                                                        <input type="text" name="add_name[]" class="form-control" value="<?= $attr->title ?>">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-3">
                                                <div class="form-group">
                                                    <div class="col-sm-10">
                                                        <input type="text" name="add_val[]" class="form-control" value="<?= $attr->value ?>">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-2">
                                        <div class="form-group">
                                            <div class="col-sm-10">
                                                <?php if($attr->visibleFront){
                                                        
                                                ?>
                                               <select name="show_front[]">
                                                  <option value="1"<?= ($attr->visibleFront == 1) ? "Selected" : "";?>>True</option>
                                                  <option value="0" <?=($attr->visibleFront != 1) ? "Selected" : ""?> >False</option>
                                                </select>
                                                <?php }else{
                                                     
                                                ?>
                                                    <select name="show_front[]">
                                                      <option value="1"<?= ($attr->visibleFront == 1) ? "Selected" : "";?>>True</option>
                                                        <option value="0" <?=($attr->visibleFront != 1) ? "Selected" : ""?> >False</option>
                                                    </select>
                                                <?php }?>
                                            </div>
                                        </div>
                                    </div>  
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <div class="col-sm-10">
                                                <?php if($attr->visibleAdmin){
                                                 
                                                ?> 
                                                <select name="show_back[]">
                                                  <option value="1" <?= ($attr->visibleAdmin == 1) ? "Selected" : "";?>>True</option>
                                                  <option value="0" <?= ($attr->visibleAdmin != 1) ? "Selected" : "";?>>False</option>
                                                </select>
                                                <?php }else{
                                                  
                                                ?>
                                                    <select name="show_back[]">
                                                        <option value="1" <?= ($attr->visibleAdmin == 1) ? "Selected" : "";?>>True</option>
                                                        <option value="0" <?= ($attr->visibleAdmin != 1) ? "Selected" : "";?>>False</option>
                                                    </select>
                                                <?php }?>
                                            </div>
                                        </div>
                                    </div>
                                            <div class="col-md-2 remove_row">
                                                <div class="form-group">
                                                    <div class="col-sm-2">
                                                        <button type="button" class="btn btn-danger"><i class="fa fa-times"></i></button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <?php
                                    }
                                } else {
                                    ?>
                                    <div class="col-md-12">
                                        <div class="col-md-3">
                                            <div class="form-group">
                                                <div class="col-sm-10">
                                                    <input type="text" name="add_name[]" id="add_name" class="form-control" value="">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-3">
                                            <div class="form-group">
                                                <div class="col-sm-10">
                                                    <input type="text" name="add_val[]" id="add_val" class="form-control" value="">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-2">
                                        <div class="form-group">
                                            <div class="col-sm-10">
                                                <select name="show_front[]">
                                                    <option value="1">True</option>
                                                    <option value="0">False</option>
                                                </select>
                                            </div>
                                        </div>
                                        </div>
                                        <div class="col-md-2">
                                            <div class="form-group">
                                                <div class="col-sm-10">                  
                                                    <select name="show_back[]">
                                                        <option value="1">True</option>
                                                        <option value="0">False</option>
                                                    </select>
                                                    
                                                </div>
                                            </div>
                                        </div>                                
                                    </div>
                                    <?php
                                }
                                ?>
                            </div>
                            <div class="col-md-10">
                                <div class="form-group">
                                    <div class="col-sm-2"> 
                                        <button type="button" id="btn_add" class="btn btn-primary"><i class="fa fa-plus"></i></button>
                                    </div>
                                </div>
                            </div>
                            <!-- Attribute(s) -->
                            
                            <div class="col-md-12" style="border-top:1px solid #939393; padding-top: 5px;">
                                <h3 style="float:left;"><b>Attribute(s) :</b></h3>
                            </div>
                            <div class="col-sm-12 table-responsive">
                                    
                                <table class="table table-bordered">
                                        <thead>
                                            <tr><th></th>
                                                <th>Group</th>
                                                <th>value</th>
                                                <th>Name</th>
                                            </tr>
                                        </thead>
                                        <tbody id="att_products">
                                            <?php 
                                                              $Productattributes=json_decode($product->attributes);
                                                                foreach ($Productattributes as $vkey => $val) {    
                                                        ?>
                                                                    <tr class="tr_<?php echo $vkey; ?>">
                                                                    <?php if ($vkey != 0) { ?>
                                                                            <td style="width: 10%;">
                                                                            <button type="button" class="btn btn-danger btn-circle btn-xxs remove_item" data-tr="<?php echo $vkey; ?>"><i class="fa fa-times-circle-o fa-lg"></i></button></td>
                                                                    <?php } else { ?>
                                                                            <td></td>
                                                                    <?php } ?>
                                                                    <td style="width: 30%;">
                                                                        <input type="text" name="group[]" id="gst_rate0" class="form-control gst_rate" value="<?php echo isset($val->group)?$val->group:'';?>">
                                                                    </td>
                                                                    <td style="width: 30%;"><input type="text" name="value[]" id="gst_rate0" class="form-control gst_rate" value="<?php echo isset($val->value)?$val->value:'';?>"></td>
                                                                    <td style="width: 30%;">
                                                                        <input type="text" name="att_name[]" class="form-control quantity" value="<?php echo isset($val->name)?$val->name:'';?>">
                                                                       
                                                                    </td>
                                                                    
                                                                </tr>
                                                        <?php 
                                                                } 
                                                           
                                                        
                                                        ?>
                                        </tbody>
                                </table>
                                <div class="form-group" style="float: right;">
                                        <div class="col-lg-6">
                                            <button type="button" style="float: right;" class="btn btn-success addAttributeItem"><i class="fa fa-plus-square"></i><span class="m-l-xs">Add Item</span></button>
                                        </div>                            
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
                <!--<div class="ibox">
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-lg-8 pull-right">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label" style="text-align: left;">Customer Note</label>
                                    <div class="col-sm-9">
                                        <textarea class="form-control" name="customer_note"></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div> -->
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-lg-6 pull-right">
                                <div class="form-group">
                                    <div class="col-sm-12 col-sm-offset-2">
                                        <!-- <button class="btn btn-info generate_invoice" type="button" data-status="0"><i class="fa fa-dropbox"></i><span class="m-l-xs">Save Draft</span></button> -->
                                        <button class="btn btn-primary generate_invoice" type="submit" data-status="1"><i class="fa fa-download"></i><span class="m-l-xs">Save</span></button>
                                        <button class="btn btn-danger back_listing" type="button">Cancel</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $this->load->view($footer); ?>
<script type="text/javascript" src="<?php echo js_url('jquery.scannerdetection'); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/dropzone.css'); ?>"></script>
<script type="text/javascript" src="<?php echo js_url('dropzone'); ?>"></script>
<script type="text/javascript">
    $(document).ready(function () {
        
        $('#create_vendor').hide();
        $('#create_category').hide();
        $('#create_color').hide();
        $('#create_quality').hide();
        $('#overlay').hide();
        
        $('#photo_id').css('border-color', 'red');
        $('#photo_id').prev().css('display', 'block');
        $('.generate_invoice').prop('disabled', true);
        
        $("#photo_id").focusout(function(e) {
            e.preventDefault();
            var photo_id=$('#photo_id').val();
             //alert(photo_id);
                $.ajax({
                        url: '<?=base_url();?>All_products/check_sku',
                        type: "POST",
                        data: {'sku_value' : photo_id},
                        beforeSend: function(){
                            $('#loader_image').show();
                            $('#overlay').show();
                        },
                        complete: function(){
                            $('#loader_image').hide();
                            $('#overlay').hide();
                        },
                        success: function(msg){
                                console.log(msg);
                                if(msg==1){
                                    $('#photo_id').css('border-color', '');
                                    $('#photo_id').prev().css('display', 'none');
                                    $('.generate_invoice').prop('disabled', false); 
                                }else{
                                    $('#photo_id').css('border-color', 'red');
                                    $('#photo_id').prev().css('display', 'block');
                                    $('.generate_invoice').prop('disabled', true);
                                }
                            }
                });
        });
        

        
        
        $('#create_vendor_option').click(function(e){
            e.preventDefault();
            var vendor_value=$(this).closest('.form-group').prev('.form-group').children().eq(1).val();
            if(vendor_value.length===0){
                 $('#vendor').prop('disabled', true);
                 $('#create_vendor').show();
            }
        });
        
        $('#create_category_option').click(function(e){
            e.preventDefault();
            var vendor_value=$(this).closest('.form-group').prev('.form-group').children().eq(1).val();
            if(vendor_value.length===0){
                 $('#category').prop('disabled', true);
                 $('#create_category').show();
            }
        });
        
        $('#create_color_option').click(function(e){
            e.preventDefault();
            var vendor_value=$(this).closest('.form-group').prev('.form-group').children().eq(1).val();
            if(vendor_value.length===0){
                 $('#color').prop('disabled', true);
                 $('#create_color').show();
            }
        });
        
        $('#create_quality_option').click(function(e){
            e.preventDefault();
            var vendor_value=$(this).closest('.form-group').prev('.form-group').children().eq(1).val();
            if(vendor_value.length===0){
                 $('#quality').prop('disabled', true);
                 $('#create_quality').show();
            }
        });


        //$(".imageupload").dropzone({url: "/admin/all_products/newimage"});
        Dropzone.autoDiscover = false;
    $(".imageupload").dropzone({
        url: "/admin/all_products/newimage",
        addRemoveLinks: true,
        success: function (file, response) {
             if(response==0){
                 $('.dz-message').text('Sorry! Image not uploaded properly....');
                 $('.dz-message').css({ 'color': 'red', 'font-size': '15px' });
                 $('#demo-upload').css('border-color', 'red');
                 //$('.generate_invoice').prop('disabled', true);
             }else{
                 $('.image_upload').val(response);
                 $('.dz-message').text('Congrats! Image uploaded properly....');
                 $('#demo-upload').css('border-color', 'blue');
                 $('.generate_invoice').prop('disabled', false);
             }
        },
        error: function (file, response) {
            file.previewElement.classList.add("dz-error");
        }
    });




<?php if ($variations) { ?>
            var trId = '<?php echo $vkey; ?>';
<?php } else { ?>
            var trId = 0;
<?php } ?>

        $('.additem').on('click', function () {
            trId++;
            //alert(trId);
            var tr = '<tr class="tr_' + trId + '">';
            tr += '<td style="width: 10%;">';
             tr += '<button type="button" class="btn btn-danger btn-circle btn-xxs remove_item" data-tr="' + trId + '"><i class="fa fa-times-circle-o fa-lg"></i></button></td>';
            tr+='<td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="gs1[]" id="hsn_code"' + trId + '" class="form-control hsn_code" data-tr="' + trId + '"></td>\
                 <td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="msrp[]" id="hsn_code"' + trId + '" class="form-control hsn_code" data-tr="' + trId + '"></td>';
            tr += '<td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="old_cost[]" class="form-control unit_price" id="oldcost"'+ trId + '" data-tr="'+ trId + '"></td>';
                                                        
            tr += '<td style="width: 10%;"><input type="number" style="padding: 0px 0px;width: 80px;" name="price[]" class="form-control unit_price" id="unit_price"' + trId + '"  data-tr="' + trId + '" required></td>';
            tr += '<td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="cost[]" class="form-control unit_price" id="cost"' + trId + '" data-tr="' + trId + '"></td>';
            tr += '<td style="width: 10%;">';
             tr += '<select class="form-control" style="padding: 0px 0px;width: 80px;" name="searchsize[]" id="searchSize"' + trId + '" data-tr="' + trId + '" required>';
             tr += '<option value="">Search Size</option>';
                        <?php
                        if (!empty($size_drop)) {
                            foreach ($size_drop->result() as $val) {
                                ?>
                               tr += ' <option value="<?php echo $val->id; ?>"><?php echo str_replace("'", "\'", $val->size); ?></option>';
                                <?php
                            }
                        }
                        ?>
                tr +='</select>\
                </td>\
                  </td>';
            tr += '<td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="size[]" class="form-control unit_price" id="size"' + trId + '" data-tr="' + trId + '" required></td>';
            /*tr += '<td style="width: 10%;">\
                    <select class="form-control hsn_code" style="padding: 0px 0px;width: 80px;" name="shape[]" id="shape" data-tr="0" required>\
                <option value="">Shape</option>';
                <?php
                if (!empty($shape_drop)) {
                    foreach ($shape_drop->result() as $value2) {
                        ?>
                        tr += '<option value="<?php echo $value2->id; ?>"><?php echo str_replace("'", "\'", $value2->shape); ?></option>';
                        <?php
                    }
                }
                ?>
            tr+='</select>\
        </td>';*/
        
          /*tr += '<td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="stock[]" class="form-control unit_price" id="stock"' + trId + '" data-tr="' + trId + '"></td>\*/
          tr +=      '<td style="width: 10%;">\
                 <select class="form-control hsn_code" style="padding: 0px 0px;width: 80px;" name="active[]" id="active" data-tr="' + trId + '" required>';
                tr += '<option value="1" >Yes</option>';
                tr += '<option value="0">No</option>';  
                tr += '</select>\
                </td>';
           tr += '<td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="sizesku[]" id="hsn_code"' + trId + '" class="form-control hsn_code" data-tr="' + trId + '"></td>';
           /*tr +=     '<td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="aliassize[]" id="hsn_code"' + trId + '" class="form-control hsn_code" data-tr="' + trId + '"></td>';*/
            tr +=     '</tr>'; 
          $('#products').append(tr);

        });

        $(document).on('click', '.remove_item', function () {
            var trId = $(this).data('tr');
            $('.tr_' + trId).remove();
            delete items[trId];
            invoice_calculation()
        });


         /* Attributes add options */
        <?php if ($variations) { ?>
            var trId = '<?php echo $vkey; ?>';
        <?php } else { ?>
                    var trId = 0;
        <?php } ?>

        $('.addAttributeItem').on('click', function () {
            trId++;
            
            var tr = '<tr class="att_tr_' + trId + '">';
            tr += '<td style="width: 10%;">';
             tr += '<button type="button" class="btn btn-danger btn-circle btn-xxs remove_att_item" data-tr="' + trId + '"><i class="fa fa-times-circle-o fa-lg"></i></button></td>';
            tr+='<td style="width: 30%;"><input type="text" style="padding: 0px 0px;" name="group[]" id="hsn_code"' + trId + '" class="form-control hsn_code" data-tr="' + trId + '"></td>\
                 <td style="width: 30%;"><input type="text" style="padding: 0px 0px;" name="value[]" id="hsn_code"' + trId + '" class="form-control hsn_code" data-tr="' + trId + '"></td>';
            tr += '<td style="width: 30%;"><input type="text" style="padding: 0px 0px;" name="att_name[]" id="hsn_code"' + trId + '" class="form-control hsn_code" data-tr="' + trId + '"></td>\
                  </tr>';
            $('#att_products').append(tr);

        });

        $(document).on('click', '.remove_att_item', function () {
            var trId = $(this).data('tr');
            $('.att_tr_' + trId).remove();
            delete items[trId];
            invoice_calculation()
        });




        // $(document).on('keyup change','#shipping_charge',function(){
        //      items['shipping_charge'] = $(this).val();
        //      invoice_calculation();
        // });

        // $(document).on('keyup change','#final_adjustment',function(){
        //      items['final_adjustment'] = $(this).val();
        //      invoice_calculation();
        // });




        function format(val, type) {
            if (type == 'cost' || type == 'per') {
                var va = parseFloat(val).toFixed(2);
            } else {
                var va = parseFloat(val);
            }
            var test = va.toString().replace('.', '.');
            String.prototype.reverse = function () {
                var s = "";
                var i = this.length;
                while (i > 0) {
                    s += this.substring(i - 1, i);
                    i--;
                }
                return s;
            };

            var n = test.reverse().replace(/(\d{3})/g, "$1 ").reverse();

            if (type == 'cost') {
                n = n;
            } else if (type == 'per') {
                n = n + ' %';
            }
            return n;
        }

    });

    $(document).ready(function () {
        $('#btn_add').on("click", function () {
            var m = 1;
            var app = '<div class="col-md-12">\
                                    <div class="col-md-3">\
                                        <div class="form-group">\
                                            <div class="col-sm-10">\
                                                <input type="text" name="add_name[]" class="form-control" value="" required>\
                                            </div>\
                                        </div>\
                                    </div>\
                                    <div class="col-md-3">\
                                        <div class="form-group">\
                                            <div class="col-sm-10">\
                                                <input type="text" name="add_val[]" class="form-control" value="" required>\
                                            </div>\
                                        </div>\
                                    </div>\
                                    <div class="col-md-2">\
                                        <div class="form-group">\
                                            <div class="col-sm-10">\
                                                <select name="show_front[]">\
                                                  <option value="1">True</option>\
                                                  <option value="0">False</option>\
                                                </select>\
                                            </div>\
                                        </div>\
                                    </div>\
                                    <div class="col-md-2">\
                                        <div class="form-group">\
                                            <div class="col-sm-10">\
                                                <select name="show_back[]">\
                                                  <option value="1">True</option>\
                                                  <option value="0">False</option>\
                                                </select>\
                                            </div>\
                                        </div>\
                                    </div>\
                                     <div class="col-md-2 remove_row">\
                                <div class="form-group">\
                                    <div class="col-sm-2">\
                                        <button type="button" class="btn btn-danger"><i class="fa fa-times"></i></button>\
                                    </div>\
                                </div>\
                            </div>\
                            </div>';

            $('#divrow').append(app);

            m++;
        });
        
        $('#btn_extra_image_add').on("click", function () {
            var m = 1;
            var app = '<div class="col-md-12">\
                                    <div class="col-md-3">\
                                        <div class="form-group">\
                                            <div class="col-sm-10">\
                                                <input type="file" name="extra_image[]" id="extra_image" class="form-control" value="">\
                                            <input type="hidden" name="extra_image_id[]" value="">\
                                            </div>\
                                        </div>\
                                    </div>\
                                    <div class="col-md-3">\
                                        <div class="form-group">\
                                            <div class="col-sm-10">\
                                                <select name="extra_image_type[]" style="float:left;">\
                                                <option value="">Select image type</option>\
                                                <option value="ang">ang</option>\
                                                <option value="back">back</option>\
                                                <option value="corner">corner</option>\
                                                <option value="head">head</option>\
                                                <option value="roomscene">roomscene</option>\
                                                <option value="wash">wash</option>\
                                                <option value="rect">rect</option>\
                                                <option value="zoom">zoom</option>\
                                            </select>\
                                            </div>\
                                        </div>\
                                    </div>\
                                     <div class="col-md-2 remove_row">\
                                <div class="form-group">\
                                    <div class="col-sm-2">\
                                        <button type="button" class="btn btn-danger"><i class="fa fa-times"></i></button>\
                                    </div>\
                                </div>\
                            </div>\
                            </div>';

            $('#divextraimagerow').append(app);

            m++;
        });

        $(document).on('click', '.remove_row', function () {
            $(this).parent().remove();
        });
        
        $(document).on('click', '.remove_extra_image', function () {
        	let image_id = $(this).val();
        	$.ajax({
		 type: "POST",
		 url: "/admin/all_products/removeExtraImage", 
		 data: {extra_image_id: $(this).val()},
		 dataType: "text",  
		 cache:false,
		 success: 
		      function(data){
		        //alert(data);  //as a debugging message.
		        $(this).parent().remove();
		      }
          	});// you have missed this bracket
     		return false;
        });

    });
</script>
<script>
    $(document).ready(function () {
        //Select2
        $(".customer").select2({
           
        });

        $(".select2").select2({
           
        });

        $("select").on("select2:select", function (evt) {
          var element = evt.params.data.element;
          var $element = $(element);
          
          $element.detach();
          $(this).append($element);
          $(this).trigger("change");
        });
       
    });
</script>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js">
       </script>
