<!DOCTYPE html>
<html>
   <head>
  <!-- TABLES CSS CODE -->
  <?php include"comman/code_css_form.php"; ?>
  
  <link rel="stylesheet" href="<?php echo $theme_link; ?>sweetalert/sweetalert.css">
  <!-- </copy> -->  
  </head>
   <body class="hold-transition skin-blue  sidebar-mini">

    <!-- **********************MODALS***************** -->
    <?php include"modals/modal_brand.php"; ?>
    <?php include"modals/modal_category.php"; ?>
    <?php include"modals/modal_unit.php"; ?>
    <?php include"modals/modal_tax.php"; ?>
    <!-- **********************MODALS END***************** -->
      
      </div>
      <div class="wrapper">
      <?php include"sidebar.php"; ?>
      <?php
         if(!isset($item_name)){
         $custom_barcode ='';
         $item_name=$sku=$hsn=$opening_stock=$item_code=$brand_id=$category_id=$color_id=$size_id=$gst_percentage=$tax_type=
         $sales_price=$purchase_price=$profit_margin=$unit_id=$price=$alert_qty=$lot_number="";
         $stock = 0;
         $expire_date ='';
         $description ='';
         $final_price ='';
          $tax_id='';
         }
         $new_opening_stock ='';
         $adjustment_note ='';
         ?>
      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
         <!-- Content Header (Page header) -->
         <section class="content-header">
            <h1>
               <?= $page_title;?>
               <small>Add/Update Items</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">
               <!-- ********** ALERT MESSAGE START******* -->
               <?php include"comman/code_flashdata.php"; ?>
               <!-- ********** ALERT MESSAGE END******* -->
               <!-- right column -->
               <div class="col-md-12">
                  <!-- Horizontal Form -->
                  <div class="box box-info ">
                     
                      <?= form_open('#', array('class' => 'form', 'id' => 'items-form', 'enctype'=>'multipart/form-data', 'method'=>'POST'));?>
                        <input type="hidden" id="base_url" value="<?php echo $base_url; ?>">
                        <div class="box-body">
                           <div class="row">
                              <div class="form-group col-md-4">
                                 <label for="sku">SKU</label>
                                 <input type="text" class="form-control" id="sku" name="sku" placeholder="" value="<?php print $sku; ?>" onBlur="checkAvailabilitySKU()">
                                 <span id="sku_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4">
                                 <label for="item_name"><?= $this->lang->line('item_name'); ?><span class="text-danger">*</span></label>
                                 <input type="text" class="form-control" id="item_name" name="item_name" placeholder="" value="<?php print $item_name; ?>" >
                                 <span id="item_name_msg" style="display:none" class="text-danger"></span>
                              </div>

                              
                              <div class="form-group col-md-4">
                                 <label for="category_id">Category <span class="text-danger">*</span></label>
                                 <div class="input-group">
                                 <select class="form-control select2" id="category_id" name="category_id"  style="width: 100%;"  value="<?php print $category_id; ?>">
                                    <?php
                                       $query1="select * from db_category where status=1";
                                       $q1=$this->db->query($query1);
                                       if($q1->num_rows($q1)>0)
                                        {  echo '<option value="0">-Select-</option>'; 
                                            foreach($q1->result() as $res1)
                                          { 
                                            $selected = ($category_id==$res1->id)? 'selected' : '';
                                            echo "<option $selected value='".$res1->id."'>".$res1->category_name."</option>";
                                          }
                                        }
                                        else
                                        {
                                           ?>
                                    <option value="">No Records Found</option>
                                    <?php
                                       }
                                       ?>
                                 </select>
                                 <span class="input-group-addon pointer" id="ad_category" onclick="addNewCategory(this)" title="Add Category"><i class="fa fa-plus-square-o text-primary fa-lg"></i></span>
                                    </div>
                                 <span id="category_id_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4" hidden>
                                 <label for="color_id">Color</label>
                                 <div class="input-group">
                                    <select class="form-control select2" id="color_id" name="color_id"  style="width: 100%;" >
                                       <?php
                                       $query1="select * from db_color where status=1 limit 1";
                                       $q1=$this->db->query($query1);
                                       if($q1->num_rows($q1)>0)
                                       {
                                       // echo '<option value="0">-Select-</option>'; 
                                          foreach($q1->result() as $res1)
                                          {
                                             $selected = ($color_id==$res1->id)? 'selected' : '';
                                          echo "<option $selected value='".$res1->id."'>".$res1->color."</option>";
                                          }
                                       }
                                       else
                                       {
                                          ?>
                                       <option value="">No Records Found</option>
                                       <?php } ?>
                                    </select>
                                    <span class="input-group-addon pointer" id="ad_color" onclick="addNewColor(this)" title="Add Color"><i class="fa fa-plus-square-o text-primary fa-lg"></i></span>
                                 </div>
                              </div>

                              <div class="form-group col-md-4" hidden>
                                 <label for="size_id">Size</label>
                                 <div class="input-group">
                                       <select class="form-control select2" id="size_id" name="size_id"  style="width: 100%;" >
                                          <?php
                                          $query1="select * from db_size where status=1 limit 1";
                                          $q1=$this->db->query($query1);
                                          if($q1->num_rows($q1)>0)
                                          {
                                          // echo '<option value="0">-Select-</option>'; 
                                             foreach($q1->result() as $res1)
                                             {
                                                $selected = ($size_id==$res1->id)? 'selected' : '';
                                             echo "<option $selected value='".$res1->id."'>".$res1->size."</option>";
                                             }
                                          }
                                          else
                                          {
                                             ?>
                                          <option value="">No Records Found</option>
                                          <?php } ?>
                                       </select>
                                       <span class="input-group-addon pointer" id="ad_size" onclick="newSizeAdd(this)" title="Add Size"><i class="fa fa-plus-square-o text-primary fa-lg"></i></span>
                                    </div>
                              </div>
                              <div class="form-group col-md-4">
                                 <label for="brand_id">Brand</label>
                                 <div class="input-group">
                                 <select class="form-control select2" id="brand_id" name="brand_id"  style="width: 100%;"  >
                                    <?php
                                       $query1="select * from db_brands where status=1";
                                       $q1=$this->db->query($query1);
                                       if($q1->num_rows($q1)>0)
                                        {
                                           echo '<option value="0">-Select-</option>'; 
                                            foreach($q1->result() as $res1)
                                          { 
                                            $selected = ($brand_id==$res1->id)? 'selected' : '';
                                            echo "<option $selected value='".$res1->id."'>".$res1->brand_name."</option>";
                                          }
                                        }
                                        else
                                        {
                                           ?>
                                    <option value="">No Records Found</option>
                                    <?php
                                       }
                                       ?>
                                 </select>
                                 <span class="input-group-addon pointer" id="ad_size" onclick="newSizeAdd(this)" title="Add Size"><i class="fa fa-plus-square-o text-primary fa-lg"></i></span>
                              </div>
                                 <span id="brand_id_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4">
                                 <label for="unit_id" class="control-label"><?= $this->lang->line('unit'); ?><span class="text-danger">*</span></label>
                                 <!-- <div class="input-group"> -->
                                 <select class="form-control select2" id="unit_id" name="unit_id"  style="width: 100%;" >
                                    <?php
                                       $query1="select * from db_units where status=1";
                                       $q1=$this->db->query($query1);
                                       if($q1->num_rows($q1)>0)
                                        {
                                            foreach($q1->result() as $res1)
                                          {
                                            $selected = ($res1->id==$unit_id)? 'selected' : '';
                                            echo "<option $selected value='".$res1->id."'>".$res1->unit_name."</option>";
                                          }
                                        }
                                        else
                                        {
                                           ?>
                                    <option value="">No Records Found</option>
                                    <?php
                                       }
                                       ?>
                                 </select>
                                 <!-- <span class="input-group-addon pointer" data-toggle="modal" data-target="#unit_modal" title="Add Unit"><i class="fa fa-plus-square-o text-primary fa-lg"></i></span>
                                    </div> -->
                                 <span id="unit_id_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4">
                                 <label for="item_image"><?= $this->lang->line('select_image'); ?></label>
                                 <input type="file" name="item_image" id="item_image">
                                 <span id="item_image_msg" style="display:block;" class="text-danger">Max Width/Height: 1000px * 1500px & Size: 1MB </span>
                              </div>
                           </div>
                           <div class="row">
                              
                              
                              <div class="form-group col-md-4" hidden>
                                 <label for="hsn" ><?= $this->lang->line('hsn'); ?></label>
                                 <input type="text" class="form-control" id="hsn" name="hsn" placeholder="" value="<?php if($hsn==""){ print '0';}else{ print $hsn;} ?>" >
                                 <span id="hsn_msg" style="display:none" class="text-danger"></span>
                              </div>
                              
                              
                              <div class="form-group col-md-4" hidden>
                                 <label for="alert_qty" ><?= $this->lang->line('minimum_qty'); ?></label>
                                 <input type="number" class="form-control no_special_char" id="alert_qty" name="alert_qty" placeholder="" min="0"  value="<?php if($alert_qty==""){ print '1';}else{ print $alert_qty;} ?>" >
                                 <span id="alert_qty_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4" hidden>
                                 <label for="lot_number" ><?= $this->lang->line('lot_number'); ?></label>
                                 <input type="text" class="form-control no_special_char" id="lot_number" name="lot_number" placeholder=""  value="<?php print $lot_number; ?>" >
                                 <span id="lot_number_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4" hidden>
                                 <label for="expire_date" ><?= $this->lang->line('expire_date'); ?></label>
                                 <div class="input-group date">
                                  <div class="input-group-addon">
                                  <i class="fa fa-calendar"></i>
                                  </div>
                                  <input type="text" class="form-control pull-right datepicker" id="expire_date" name="expire_date" value="<?php if($expire_date==""){ $today = date("Y-m-d"); $NewDate=date('Y-m-d', strtotime($today. ' + 100 days')); print $NewDate; }else{ print $expire_date;}?>">
                                </div>
                                 <span id="expire_date_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4" hidden>
                                 <label for="custom_barcode" ><?= $this->lang->line('barcode'); ?></label>
                                 <input type="text" class="form-control" id="custom_barcode" name="custom_barcode" placeholder=""  value="<?php print $custom_barcode; ?>" >
                                 <span id="custom_barcode_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4" hidden>
                                 <label for="custom_barcode" ><?= $this->lang->line('description'); ?></label>
                                 <textarea type="text" class="form-control" id="description" name="description" placeholder=""><?php if($description==""){print "-";}else{ print $description;} ?></textarea>
                                 <span id="description_msg" style="display:none" class="text-danger"></span>
                              </div>
                              
                           </div>
                           
                           <div class="row" hidden>
                              <div class="form-group col-md-4">
                                 <label for="price"><?= $this->lang->line('price'); ?><span class="text-danger">*</span></label>
                                 <input type="text" class="form-control only_currency" id="price" name="price" placeholder="Price of Item without Tax"  value="<?php if($price==""){print "1.00";}else{ print $price;} ?>" >
                                 <span id="price_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4">
                                 <label for="tax_id" ><?= $this->lang->line('tax'); ?><span class="text-danger">*</span></label>
                                 <div class="input-group">
                                 <select class="form-control select2" id="tax_id" name="tax_id"  style="width: 100%;" >
                                       <option value="1" selected >0..00</option>
                                 </select>
                                 <span class="input-group-addon pointer" data-toggle="modal" data-target="#tax_modal" title="Add Tax"><i class="fa fa-plus-square-o text-primary fa-lg"></i></span>
                                    </div>
                                 <span id="tax_id_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4">
                                 <label for="purchase_price"><?= $this->lang->line('purchase_price'); ?><span class="text-danger">*</span></label>
                                 <input type="text" class="form-control only_currency" id="purchase_price" name="purchase_price" placeholder="Total Price with Tax Amount"  value="<?php if($purchase_price==""){print "1.00";}else{ print $purchase_price;} ?>" readonly='' >
                                 <span id="purchase_price_msg" style="display:none" class="text-danger"></span>
                              </div>
                           </div>
                           <!-- /row -->
                           <div class="row" hidden>
                              <div class="form-group col-md-4">
                                 <label for="tax_type"><?= $this->lang->line('tax_type'); ?><span class="text-danger">*</span></label>
                                 <select class="form-control select2" id="tax_type" name="tax_type"  style="width: 100%;" >
                                  <?php 
                                    // $inclusive_selected=$exclusive_selected='';
                                    // if($tax_type =='Inclusive') { $inclusive_selected='selected'; }
                                    // if($tax_type =='Exclusive') { $exclusive_selected='selected'; }

                                  ?>
                                    <option value="Exclusive" selected>Exclusive</option>
                                    <option value="Inclusive">Inclusive</option>
                                 </select>
                                 <span id="tax_type_msg" style="display:none" class="text-danger"></span>
                                 
                              </div>
                              <div class="form-group col-md-4">
                                 <label for="profit_margin"><?= $this->lang->line('profit_margin'); ?>(%) <i class="hover-q " data-container="body" data-toggle="popover" data-placement="top" data-content="<?= $this->lang->line('based_on_purchase_price'); ?>" data-html="true" data-trigger="hover" data-original-title="">
                                  <i class="fa fa-info-circle text-maroon text-black hover-q"></i>
                                </i></label>
                                 <input type="text" class="form-control only_currency" id="profit_margin" name="profit_margin" placeholder="Profit in %"  value="<?php if($profit_margin==""){print "100";}else{ print $profit_margin;} ?>" >
                                 <span id="profit_margin_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4">
                                 <label for="sales_price" class="control-label"><?= $this->lang->line('sales_price'); ?><span class="text-danger">*</span></label>
                                 <input type="text" class="form-control only_currency " id="sales_price" name="sales_price" placeholder="Sales Price"  value="<?php if($sales_price==""){print "2.00";}else{ print $sales_price;} ?>" >
                                 <span id="sales_price_msg" style="display:none" class="text-danger"></span>
                              </div>
                           </div>
                           <div class="row" hidden>
                              <div class="form-group col-md-4">
                                 <label for="final_price" class="control-label"><?= $this->lang->line('final_price'); ?><span class="text-danger">*</span></label>
                                 <input type="text" class="form-control only_currency " id="final_price" name="final_price" placeholder="Final Price"  value="<?php if($final_price==""){print "2.00";}else{ print $final_price;} ?>" readonly >
                                 <span id="final_price_msg" style="display:none" class="text-danger"></span>
                              </div>
                           </div>
                           <!-- /row -->
                           <div class="row" hidden>
                              <div class="form-group col-md-4">
                                 <label for="current_opening_stock"><?= $this->lang->line('current_opening_stock'); ?></label>
                                 <input type="text" class="form-control only_currency" id="current_opening_stock" name="current_opening_stock" placeholder="" readonly=""  value="<?php if($stock==""){print "0";}else{ print $stock;} ?>" >
                                 <span id="current_opening_stock_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4">
                                 <label for="new_opening_stock"><?= $this->lang->line('adjust_stock'); ?> <i class="hover-q " data-container="body" data-toggle="popover" data-placement="top" data-content="<?= $this->lang->line('stock_adjustment_msg'); ?>" data-html="true" data-trigger="hover" data-original-title="">
                                  <i class="fa fa-info-circle text-maroon text-black hover-q"></i>
                                </i></label>
                                 <input type="text" class="form-control" id="new_opening_stock" name="new_opening_stock" placeholder="-/+"  value="<?php if($new_opening_stock==""){print "0";}else{ print $new_opening_stock;} ?>" >
                                 <span id="new_opening_stock_msg" style="display:none" class="text-danger"></span>
                              </div>
                              <div class="form-group col-md-4">
                                 <label for="adjustment_note" ><?= $this->lang->line('adjustment_note'); ?></label>
                                 <textarea type="text" class="form-control" id="adjustment_note" name="adjustment_note" placeholder=""><?php if($adjustment_note==""){print "-";}else{ print $adjustment_note;} ?></textarea>
                                 <span id="adjustment_note_msg" style="display:none" class="text-danger"></span>
                              </div>
                           </div>
                           <!-- /row -->
                           <!-- /.box-body -->
                           <div class="box-footer">
                              <div class="col-sm-8 col-sm-offset-2 text-center">
                                 <!-- <div class="col-sm-4"></div> -->
                                 <?php
                                    if($item_name!=""){
                                         $btn_name="Update";
                                         $btn_id="update";
                                         ?>
                                 <input type="hidden" name="q_id" id="q_id" value="<?php echo $q_id;?>"/>
                                 <?php
                                    }
                                              else{
                                                  $btn_name="Save";
                                                  $btn_id="save";
                                              }
                                    
                                              ?>
                                 <div class="col-md-3 col-md-offset-3">
                                    <button type="button" id="<?php echo $btn_id;?>" class=" btn btn-block btn-success" title="Save Data"><?php echo $btn_name;?></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_close(); ?>
                     </div>
                     <!-- /.box -->
                  </div>
                  <!--/.col (right) -->
               </div>
               <div class="col-md-12" hidden>
         
                    <div class="box">
                      <div class="box-header">
                        <h3 class="box-title text-blue"><?= $this->lang->line('opening_stock_adjustment_records'); ?></h3>
                      </div>
                      <!-- /.box-header -->
                      <div class="box-body table-responsive no-padding">
                        
                        <table class="table table-bordered table-hover " id="report-data" >
                          <thead>
                          <tr class="bg-gray">
                            <th style="text-align:center;">#</th>
                            <th style=""><?= $this->lang->line('entry_date'); ?></th>
                            <th style=""><?= $this->lang->line('stock'); ?></th>
                            <th style=""><?= $this->lang->line('note'); ?></th>
                            <th style=""><?= $this->lang->line('action'); ?></th>
                          </tr>
                          </thead>
                          <tbody>
                              <?php 
                                if(isset($q_id)){
                                  $q3 = $this->db->query("select * from db_stockentry where item_id=$q_id");
                                  if($q3->num_rows()>0){
                                    $i=1;
                                    $total_paid = 0;
                                    foreach ($q3->result() as $res3) {
                                      echo "<td>".$i."</td>";
                                      echo "<td>".show_date($res3->entry_date)."</td>";
                                      echo "<td>".$res3->qty."</td>";
                                      echo "<td>".$res3->note."</td>";
                                      echo '<td><i class="fa fa-trash text-red pointer" onclick="delete_stock_entry('.$res3->id.')"> Delete</i></td>';
                                      echo "</tr>";
                                      $i++;
                                    }
                                  }
                                  else{
                                    echo "<tr><td colspan='5' class='text-center text-bold'>No Previous Stock Entry Found!!</td></tr>";
                                  }
                                }
                                else{
                                  echo "<tr><td colspan='5' class='text-center text-bold'>No Previous Stock Entry Found!!</td></tr>";
                                }
                              ?>
                           </tbody>
                        </table>
                        
                        
                      </div>
                      <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                  </div>
               <!-- /.row -->
         </section>

         <section class="content">
      <div class="row">
        <!-- ********** ALERT MESSAGE START******* -->
        <?php include"comman/code_flashdata.php"; ?>
        <!-- ********** ALERT MESSAGE END******* -->
        <div class="col-xs-12">
          <div class="box">
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example2" class="table table-bordered table-striped" width="100%">
                <thead class="bg-primary ">
                <tr>
                  <th class="text-center">#</th>
                  <th><?= $this->lang->line('item_code'); ?></th>
                  <th><?= $this->lang->line('sku'); ?></th>
                  <th><?= $this->lang->line('item_name'); ?></th>                  
                  <th><?= $this->lang->line('category'); ?></th>
                </tr>
                </thead>
                <tbody>
				
                </tbody>
               
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
         <!-- /.content -->
         </div>
         <!-- /.content-wrapper -->
         <?php include"footer.php"; ?>
         <!-- 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 include"comman/code_js_datatable.php"; ?>
      <?php include"comman/code_js_sound.php"; ?>
      <!-- TABLES CODE -->
      <?php include"comman/code_js_form.php"; ?>
      <script src="<?php echo $theme_link; ?>js/items.js?v=164"></script>
      <script src="<?php echo $theme_link; ?>js/modals.js"></script>
      <script src="<?php echo $theme_link; ?>sweetalert/sweetalert.min.js"></script>
      <!-- Make sidebar menu hughlighter/selector -->
      <script>$(".<?php echo basename(__FILE__,'.php');?>-active-li").addClass("active");</script>
      <script>
         $('#item_name').on('change',function(){
            $("#category_id").select2('open');
         });
      </script>

      <script>
         $('#sku').on('change',function(){
            var sku = $('#sku').val();
            $('#lot_number').val(sku);
         });
      </script>
<script>
    $(document).ready(function(){
      fill_tbData();
    });
</script>

<script>
   function checkAvailabilitySKU() {
      var itm_sku    = $('#sku').val();
      $.ajax({
         url:"<?php echo site_url('items/check_sku')?>",
         type: 'POST',
         data:{itm_sku:itm_sku},
         dataType: 'json',
         success: function (data) {
            $.each(data.itm_sku_info, function(){
               var sku_count = parseInt(this['sku_count']);
               if(sku_count>0){
                  toastr["error"]("Sorry! This sku already exists.Try again!");
                  // $("#sku_msg").html('Sorry, This sku already exists !');
                  $('#sku').val("");
               }
               
            });          
        },
        error:function (){}
    });
  }
</script>

<script>
         function addNewColor(ctl) {
            swal("Add New Color", {
               buttons: {
                  cancel: true,
                  confirm: true,
               },
               showConfirmButton: false,
               allowOutsideClick: false,
               allowEscapeKey: false,
               content: "input",
               })
               .then((value) => {
                  var color = value;
                  if(color==null){
                     //toastr["error"]("Sorry! Please Enter Color !");
                  }else{
                     $.ajax({
                        url: '<?php echo $base_url; ?>colors/itm_new_color',
                        type: 'POST',
                        data: {color:color},
                        dataType: 'JSON',
                        success: function(data) {
                           //console.log(data);
                           if (data=="success") {
                              color_fill();
                              //swal("Successfully!", "Color Added !", "success");
                              toastr["success"]("New Color Added!!");
                           }else if (data=="exist"){
                              //swal("Sorry","This Color Already Exist !!","error");
                              toastr["error"]("Sorry! This Color Already Exist.Try again!");
                           }else if (data=="failed"){
                              //swal("Sorry","Error occured !!","error");
                              toastr["error"]("Sorry! Something Wrong.Try again!");
                           }
                        }
                     });
                  }
               });
            }
      </script>

<script>
         function addNewCategory(ctl) {
            swal("Add New Category", {
               buttons: {
                  cancel: true,
                  confirm: true,
               },
               showConfirmButton: false,
               allowOutsideClick: false,
               allowEscapeKey: false,
               content: "input",
               })
               .then((value) => {
                  var category = value;
                  if(category==null){
                     //toastr["error"]("Sorry! Please Enter Color !");
                  }else{
                     $.ajax({
                        url: '<?php echo $base_url; ?>category/itm_new_category',
                        type: 'POST',
                        data: {category:category},
                        dataType: 'JSON',
                        success: function(data) {
                           //console.log(data);
                           if (data=="success") {
                              category_fill();
                              //swal("Successfully!", "Color Added !", "success");
                              toastr["success"]("New Category Added!!");
                           }else if (data=="exist"){
                              //swal("Sorry","This Color Already Exist !!","error");
                              toastr["error"]("Sorry! This Category Already Exist.Try again!");
                           }else if (data=="failed"){
                              //swal("Sorry","Error occured !!","error");
                              toastr["error"]("Sorry! Something Wrong.Try again!");
                           }
                        }
                     });
                  }
               });
            }
      </script>


      <script>
         function newSizeAdd(ctl) {
            swal("Add New Brand", {
               buttons: {
                  cancel: true,
                  confirm: true,
               },
               showConfirmButton: false,
               allowOutsideClick: false,
               allowEscapeKey: false,
               content: "input",
               })
               .then((value) => {
                  var brand = value;
                  if(brand==null){
                     toastr["error"]("Sorry! Please Enter Brand !");
                  }else{
                     $.ajax({
                        url: '<?php echo $base_url; ?>brands/itm_new_brand',
                        type: 'POST',
                        data: {brand:brand},
                        dataType: 'JSON',
                        success: function(data) {
                           //console.log(data);
                           if (data=="success") {
                              size_fill();
                              //swal("Successfully!", "Size Added !", "success");
                              toastr["success"]("New Brand Added!!");
                           }else if (data=="exist"){
                              //swal("Sorry","This Brand Already Exist !!","error");
                              toastr["error"]("Sorry! This Brand Already Exist.Try again!");
                           }else if (data=="failed"){
                              //swal("Sorry","Error occured !!","error");
                              toastr["error"]("Sorry! Something Wrong.Try again!");
                           }
                        }
                     });
                  }
               });
            }
      </script>
      <script>
         function color_fill(){
            $.ajax({
               url: '<?php echo $base_url; ?>colors/s_all_color',
                  type: 'GET',
                  dataType: 'json',
                  success: function(data) {
                     //console.log(data);
                     $('#color_id').empty();
                     $('#color_id').append('<option value="">-Select-</option>');
                     $.each(data.colorInfo, function(){
                        //console.log(this['id']);
                        $('#color_id').append($("<option></option>").val(this['id']).html(this['color']));
                     });
                  }
            });
         }
      </script>
      <script>
         function size_fill(){
            $.ajax({
               url: '<?php echo $base_url; ?>brands/s_all_brand',
                  type: 'GET',
                  dataType: 'json',
                  success: function(data) {
                     //console.log(data);
                     $('#brand_id').empty();
                     $('#brand_id').append('<option value="">-Select-</option>');
                     $.each(data.sizeInfo, function(){
                        //console.log(this['id']);
                        $('#brand_id').append($("<option></option>").val(this['id']).html(this['brand_name']));
                     });
                  }
            });
         }
      </script>

      <script>
         function category_fill(){
            $.ajax({
               url: '<?php echo $base_url; ?>category/s_all_category',
                  type: 'GET',
                  dataType: 'json',
                  success: function(data) {
                     //console.log(data);
                     $('#category_id').empty();
                     $('#category_id').append('<option value="">-Select-</option>');
                     $.each(data.categoryInfo, function(){
                        //console.log(this['id']);
                        $('#category_id').append($("<option></option>").val(this['id']).html(this['category_name']));
                     });
                  }
            });
         }
      </script>

<script>
  function fill_tbData(){

      $.ajax({
        url:"<?php echo site_url('items/itm_details_get')?>",
        type: 'get',
        //data: {payment_type:payment_type,agent_id:agent_id,to_date:to_date,from_date:from_date,platform_id:platform_id},
        dataType: 'json',
        success: function (data) {

          var table;
          table = $('#example2').DataTable();
          table.clear(); 

              var indexNo = 1; 
              $.each(data.itm_info, function(){
                table.row.add([indexNo,this['item_code'], this['sku'],this['item_name'], this['category_name']]);
                indexNo++;
              });
              table.draw();
            // }else {
            //    $('#example2').DataTable();
            //    //swal("Something Wrong","Data Not Found !!","warning");
            //    toastr["warning"]("Something Wrong! , Data Not Found. ");
            // }
        //  });
          
        },
        error: function (xhr, ajaxOptions, thrownError) {
          console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
      });
  }
</script>

   </body>
</html>
