<?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>Edit Attributes</h2>
    </div>
</div>

<div class="wrapper wrapper-content">
    <div class="row text-center animated fadeInRightBig">
        <div class="col-lg-12">
             <div class="ibox float-e-margins">
                    <div class="ibox-content">
                         <div class="form-group">
                             <div id="sell_item" class="form-group">
                                          <form method="POST" action="" class="form-horizontal" id="invoice_data" enctype='multipart/form-data'>
                                            <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="products">
                                                        <?php 
                                                           foreach($attributes as $value){
                                                              $Productattributes=json_decode($value->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="<?=$val->group?>">
                                                                    </td>
                                                                    <td style="width: 30%;"><input type="text" name="value[]" id="gst_rate0" class="form-control gst_rate" value="<?=$val->value?>"></td>
                                                                    <td style="width: 30%;">
                                                                        <input type="text" name="name[]" class="form-control quantity" value="<?=$val->name?>">
                                                                        <input type="hidden" name="product_id" class="form-control quantity" value="<?=$productId?>">
                                                                    
                                                                    </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 additem"><i class="fa fa-plus-square"></i><span class="m-l-xs">Add Item</span></button>
                                                    </div>                            
                                                </div>
                                        </div>
                                        <div class="col-sm-12 col-sm-offset-2">
                                            <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>
                                        </form>
                                    </div>
                            </div>
                        </div>
                </div>
            </div>
            </div>
            </div>
            
<script>
    
    var trId = 0;

        $('.additem').on('click', function () {
            trId++;
            // alert();
            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: 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="name[]" id="hsn_code"' + trId + '" class="form-control hsn_code" data-tr="' + trId + '"></td>\
                  </tr>';
            $('#products').append(tr);

        });

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