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


</style>

<div class="row wrapper border-bottom white-bg page-heading">

    <div class="col-sm-4">

        <h2>Copy Product</h2>

    </div>

</div>

<div class="wrapper wrapper-content">

    <div class="row text-center animated fadeInRightBig">

        <div class="col-lg-12">

            <form method="POST" action="" class="form-horizontal" 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">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">Vendor</label>

                            <div class="col-sm-10">

                                <select class="form-control" 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">Category</label>

                            <div class="col-sm-10">

                                <select class="form-control" 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">SKU</label>

                            <div class="col-sm-10">

                                <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">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">

                                <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->id ? "selected" : '' ?> ><?php echo $value->color; ?></option>

                                            <?php

                                        }

                                    }

                                    ?>

                                </select>

                            </div>

                        </div>

                        <div class="form-group">

                            <label class="col-sm-2 control-label">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; ?>" required>

                            </div>

                        </div>

                        <div class="form-group">

                            <label class="col-sm-2 control-label">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>

                            </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; ?>" required>

                            </div>

                        </div>



                        <div class="form-group">

                            <label class="col-sm-2 control-label">Image</label>

                            <div class="col-sm-10">

                                <!-- <input type="file" name="productimage" id="productimage" class="form-control"> -->

                                <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> -->



                        <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>Price</th>

                                            <th>Cost</th>

                                            <th>Size</th>

                                            <th>Shape</th>

                                            <th>Stock</th>

                                            <th>shippingHeight</th>

                                            <th>shippingLength</th>

                                            <th>shippingWidth</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);

                                            //echo '<pre>';

                                            //print_r($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 ($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 ($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 ($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 ($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 ($value->height ? $value->height : ''); ?>"></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 ($value->price ? $value->price : ''); ?>"></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 (@$value->cost ? $value->cost : ''); ?>"></td>

                                                        <td style="width: 10%;">

                                                            <select class="form-control" style="padding: 0px 0px;width: 80px;" name="size[]" id="size" data-tr="<?php echo $vkey; ?>" required>

                                                                <option value="">Size</option>

                                                                <?php

                                                                if (!empty($size_drop)) {

                                                                    foreach ($size_drop->result() as $val) {

                                                                        ?>

                                                                        <option value="<?php echo $val->id; ?>"<?= $value->size == $val->id ? "selected" : '' ?> ><?php echo $val->size; ?></option>

                                                                        <?php

                                                                    }

                                                                }

                                                                ?>

                                                            </select></td>

                                                        <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="shape[]" id="hsn_code<?php echo $vkey; ?>" class="form-control hsn_code" data-tr="<?php echo $vkey; ?>" value="<?php echo ($value->shape ? $value->shape : ''); ?>"></td>

                                                        <td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="stock[]" id="hsn_code<?php echo $vkey; ?>" class="form-control hsn_code" data-tr="<?php echo $vkey; ?>" value="<?php echo ($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 ($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 ($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 ($value->shippingWidth ? $value->shippingWidth : ''); ?>"></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%;">

                                                        <select class="form-control" style="padding: 0px 0px;width: 80px;" name="size[]" id="size" data-tr="<?php echo $vkey; ?>" 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>

                                                    <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">

                                    <div class="col-lg-6" style="float: right;">

                                        <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">

                                <h3 style="float:left;"><b>Additional Attribute :</b></h3>

                            </div>

                            <div class="col-md-12">

                                <div class="col-md-4">

                                    <div class="form-group">

                                        <label class="col-sm-2 control-label">Name</label>

                                    </div>

                                </div>

                                <div class="col-md-4">

                                    <div class="form-group">

                                        <label class="col-sm-2 control-label">value</label>

                                    </div>

                                </div>

                                <div class="col-md-4">

                                    <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) {

                                        ?>

                                        <div class="col-md-12">

                                            <div class="col-md-4">

                                                <div class="form-group">

                                                    <div class="col-sm-10">

                                                        <input type="text" name="add_name[]" class="form-control" value="<?= $attr->title ?>" required>

                                                    </div>

                                                </div>

                                            </div>

                                            <div class="col-md-4">

                                                <div class="form-group">

                                                    <div class="col-sm-10">

                                                        <input type="text" name="add_val[]" class="form-control" value="<?= $attr->value ?>" required>

                                                    </div>

                                                </div>

                                            </div>

                                            <div class="col-md-4 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-4">

                                            <div class="form-group">

                                                <div class="col-sm-10">

                                                    <input type="text" name="add_name[]" id="add_name" class="form-control" value="" required>

                                                </div>

                                            </div>

                                        </div>

                                        <div class="col-md-4">

                                            <div class="form-group">

                                                <div class="col-sm-10">

                                                    <input type="text" name="add_val[]" id="add_val" class="form-control" value="" required>

                                                </div>

                                            </div>

                                        </div>                               

                                    </div>

                                    <?php

                                }

                                ?>

                            </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 () {


        $(".imageupload").dropzone({url: "/admin/all_products/newimage"});


<?php if ($variations) { ?>

            var trId = '<?php echo $vkey; ?>';

<?php } else { ?>

            var trId = 0;

<?php } ?>



        $('.additem').on('click', function () {

            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>';

            tr += '<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="text" style="padding: 0px 0px;" name="length[]" id="gst_rate' + trId + '" class="form-control gst_rate" data-tr="' + trId + '"></td>';

            tr += '<td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="width[]" class="form-control quantity" data-tr="' + trId + '"></td>';

            tr += '<td style="width: 10%;"><input type="number" style="padding: 0px 0px;" name="height[]" class="form-control quantity" 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 + '"></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%;">\

                 <select class="form-control discount" style="padding: 0px 0px;width: 80px;" name="size[]" id="size" data-tr="' + trId + '"  required><option value="">Size</option><?php

if (!empty($size_drop)) {

    foreach ($size_drop->result() as $value) {

        ?><option value="<?php echo $value->id; ?>" ><?php echo str_replace("'", "\'", $value->size); ?></option><?php

    }

}

?></select></td>';

            tr += '<td style="width: 10%;"><input type="text" style="padding: 0px 0px;" name="shape[]" 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="stock[]" 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="shippingHeight[]" 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="shippingLength[]" 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="shippingWidth[]" 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()

        });









        // $(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-4">\

                                        <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-4">\

                                        <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-4 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++;

        });



        $(document).on('click', '.remove_row', function () {

            $(this).parent().remove();

        });



    });

</script>

