<!DOCTYPE html>
<html>
   <head>
      <!-- TABLES CSS CODE -->
      <?php $this->load->view('comman/code_css');?>
      <!-- </copy> -->  
   </head>
   <body class="hold-transition skin-blue sidebar-mini">
      <div class="wrapper">
         <?php $this->load->view('sidebar');?>
         <?php
            if(!isset($brand_name)){
                 $brand_code=$brand_name=$description="";
            }
            ?>
         <!-- Content Wrapper. Contains page content -->
         <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
               <h1>
                  <?=$page_title;?>
                  <small>Add/Update Brand</small>
               </h1>
               <ol class="breadcrumb">
                  <li><a href="<?php echo $base_url; ?>dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
                  <li><a href="<?php echo $base_url; ?>items"><?= $this->lang->line('items_list'); ?></a></li>
                  <li class="active"><?=$page_title;?></li>
               </ol>
            </section>
            <!-- Main content -->
            <section class="content">
               <div class="row">
                  <!-- right column -->
                  <div class="col-md-12">
                     <!-- Horizontal Form -->
                     <div class="box box-primary ">
                        <div class="box-header with-border">
                           <h3 class="box-title">Please Enter Valid Data</h3>
                        </div>
                        <!-- /.box-header -->
                        <!-- form start -->
                        <form class="form-horizontal" id="import-form" enctype="multipart/form-data" method="POST">
                           <input type="hidden" name="<?php echo $this->security->get_csrf_token_name();?>" value="<?php echo $this->security->get_csrf_hash();?>">
                           <input type="hidden" id="base_url" value="<?php echo $base_url;; ?>">
                           <div class="box-body">
                               <!-- Store Code -->
                                    <?php 
                                       echo "<input type='hidden' name='store_id' id='store_id' value='".get_current_store_id()."'>";
                                     ?>
                                <!-- Store Code end -->

                              <!-- Warehouse Code -->
                              <?php 
                               if(warehouse_module() && warehouse_count()>1) {$this->load->view('warehouse/warehouse_code',array('show_warehouse_select_box'=>true,'div_length'=>'col-sm-3','show_select_option'=>false)); }else{
                                echo "<input type='hidden' name='warehouse_id' id='warehouse_id' value='".get_store_warehouse_id()."'>";
                               }
                              ?>
                              <!-- Warehouse Code end -->
                              <div class="form-group">
                                 <label for="brand" class="col-sm-2 control-label"><?= $this->lang->line('import_items'); ?><label class="text-danger">*</label></label>
                                 <div class="col-sm-4">
                                    <input type="file" id="import_file" name="import_file">
                                    <span id="import_file_msg" style="display:block;" class="text-danger">
                                      Note: File must be in CSV format.
                                    </span>
                                 </div>
                              </div>
                           </div>
                           <!-- /.box-footer -->
                           <div class="box-footer">
                              <div class="col-sm-8 text-center">
                                 <div class="col-md-3 ">
                                    <button type="button" id="import" class=" btn btn-block btn-success" title="Save Data"><i class="fa fa-arrow-circle-o-left "></i> Import</button>
                                 </div>
                                 <div class="col-sm-3">
                                    <a href="<?=base_url('dashboard');?>">
                                    <button type="button" class="col-sm-3 btn btn-block btn-warning close_btn" title="Go Dashboard">Close</button>
                                    </a>
                                 </div>
                              </div>
                           </div>
                           <!-- /.box-footer -->
                        </form>
                     </div>
                     <!-- /.box -->
                  </div>
                  <!--/.col (right) -->
               </div>
               <!-- /.row -->
            </section>
            <!-- /.content -->
             <section class="content">
      <div class="row">
        <!-- right column -->
        <div class="col-md-12">
         
          <div class="box">
            <div class="box-header">
              <h3 class="box-title"><?= $this->lang->line('import_instructions'); ?></h3>
              <a href="<?= base_url('import/download/items');?>"><button type="button" class="btn btn-info pull-right btnExport" title="Download Data in Excel Format"><?= $this->lang->line('download_example_format'); ?></button>
              </a>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">

              <table class="table table-bordered table-hover " id="report-data" >
                <thead>
                <tr>
                  <th style="">#</th>
                  <th style=""><?= $this->lang->line('column_name'); ?></th>
                  <th style=""><?= $this->lang->line('value'); ?></th>
                  <th style=""><?= $this->lang->line('description'); ?></th>
                </tr>
                </thead>
                <tbody id="tbodyid">
                  <?php $i=1; ?>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('item_name'); ?> <span class="text-danger">*</span></td>
                    <td style="color:green;"><span class="label label-success"><?= $this->lang->line('required'); ?></span></td>
                    <td>Item name is mandatory</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('category_name'); ?> <span class="text-danger">*</span></td>
                    <td style="color:green;"><span class="label label-success"><?= $this->lang->line('required'); ?></span></td>
                    <td>Category name is mandatory</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('sku'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Stock Keeping Unit</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('hsn'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Harmonized System of Nomenclature</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('unit_name'); ?> <span class="text-danger">*</span></td>
                    <td style="color:green;"><span class="label label-success"><?= $this->lang->line('required'); ?></span></td>
                    <td>Unit of measurement is mandatory</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('alert_quantity'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Low stock alert quantity</td>
                  </tr>
                
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('brand_name'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Brand name</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('lot_number'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Lot/Batch number</td>
                  </tr>
                
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('price_before_tax'); ?> <span class="text-danger">*</span></td>
                    <td style="color:green;"><span class="label label-success"><?= $this->lang->line('required'); ?></span></td>
                    <td>Base price before tax is mandatory</td>
                  </tr>
                  
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('tax_name'); ?> <span class="text-danger">*</span></td>
                    <td style="color:green;"><span class="label label-success"><?= $this->lang->line('required'); ?></span></td>
                    <td>Tax name is mandatory</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('tax_value'); ?> <span class="text-danger">*</span></td>
                    <td style="color:green;"><span class="label label-success"><?= $this->lang->line('required'); ?></span></td>
                    <td>Tax percentage is mandatory</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('tax_type'); ?> <span class="text-danger">*</span></td>
                    <td style="color:green;"><span class="label label-success"><?= $this->lang->line('required'); ?></span></td>
                    <td>"Inclusive" or "Exclusive"</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('sales_price'); ?> <span class="text-danger">*</span></td>
                    <td style="color:green;"><span class="label label-success"><?= $this->lang->line('required'); ?></span></td>
                    <td>Sales price is mandatory</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('opening_stock'); ?> <span class="text-danger">*</span></td>
                    <td style="color:green;"><span class="label label-success"><?= $this->lang->line('required'); ?></span></td>
                    <td>Initial stock quantity is mandatory</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('barcode'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Barcode/QR code</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('seller_points'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Loyalty points for seller</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('description'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Item description</td>
                  </tr>

                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('discount_type'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>"Percentage" or "Fixed"</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('discount'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Discount amount</td>
                  </tr>

                  <tr>
                    <td><?=$i++;?></td>
                    <td><?= $this->lang->line('mrp'); ?> <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Maximum Retail Price</td>
                  </tr>
                  
                  <!-- NEW FIELDS FOR WHOLESALE/RETAIL PRICING -->
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Wholesale Price <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Numeric value (default: sales_price)</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Retail Price <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Numeric value (default: sales_price)</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Wholesale Margin Type <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>"percentage" or "fixed" (default: percentage)</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Wholesale Margin Value <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Numeric value (default: 0.00)</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Retail Margin Type <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>"percentage" or "fixed" (default: percentage)</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Retail Margin Value <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Numeric value (default: 0.00)</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Auto Calculate Prices <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>1 for Yes, 0 for No (default: 1)</td>
                  </tr>
                  
                  <!-- TRACKING FIELDS -->
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Tracking Type <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>"none", "expiry_only", "mfg_only", or "both" (default: none). Leave empty to auto-detect from flags below.</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Batch Tracking Enabled <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>1 for Yes, 0 for No (default: 0)</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Expiry Enabled <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>1 for Yes, 0 for No (default: 0)</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Expiry Notification Days <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Days before expiry to notify (default: 30)</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Minimum Stock Level <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Minimum stock level for alerts (default: 0)</td>
                  </tr>
                  <tr>
                    <td><?=$i++;?></td>
                    <td>Reorder Level <span class="text-info">(optional)</span></td>
                    <td style="font-style: italic;"><span class="label label-default"><?= $this->lang->line('optional'); ?></span></td>
                    <td>Reorder level for alerts (default: 0)</td>
                  </tr>
                  
                </tbody>
              </table>
              
              
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
      </div>
    </section>
         </div>
         <!-- /.content-wrapper -->
         <?php $this->load->view('footer');?>
         <!-- Add the sidebar's background. This div must be placed
            immediately after the control sidebar -->
         <div class="control-sidebar-bg"></div>
      </div>
      <!-- ./wrapper -->
      <!-- SOUND CODE -->
      <?php $this->load->view('comman/code_js_sound');?>
      <!-- TABLES CODE -->
      <?php $this->load->view('comman/code_js');?>
      <script type="text/javascript">
        //Post the file
        $("#import").on("click",function(e) {
          var base_url = $("#base_url").val();
          if($("#import_file").val()==''){
            toastr["warning"]("Please select file to Import!");
            failed.currentTime = 0; 
            failed.play();
            return;
          }

          if(confirm("Are you sure ?")){
            e.preventDefault();
            data = new FormData($('#import-form')[0]);//form name
            /*Check XSS Code*/
            if(!xss_validation(data)){ return false; }
            
            $(".box").append('<div class="overlay"><i class="fa fa-refresh fa-spin"></i></div>');
            $("#import").attr('disabled',true);  //Enable Save or Update button
            $.ajax({
            type: 'POST',
            url: base_url+'import/import_items_csv',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(result){
              if(result=="success")
              {
                window.location=base_url+"items";
              }
              else if(result=="failed")
              {
                toastr["error"]("Sorry! Failed to save Record.Try again!");
              }
              else
              {
                toastr["error"](result);
              }
              $("#import").attr('disabled',false);  //Enable Save or Update button
              $(".overlay").remove();
             }
             });
        }
        });
        
        
      </script>
      <!-- Make sidebar menu hughlighter/selector -->
      <script>$(".<?php echo basename(__FILE__,'.php');?>-active-li").addClass("active");</script>
   </body>
</html>

