<?php $CI =& get_instance(); ?>
<div class="modal fade" id="item-modal" tabindex='-1'>
  <?= form_open('#', array('class' => '', 'id' => 'item-form','enctype'=>'multipart/form-data', 'method'=>'POST')); ?>
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title"><?= $this->lang->line('new_item'); ?></h4>
      </div>
      <div class="modal-body">
        <!-- Basic Information -->
        <div class="row">
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_item_name"><?= $this->lang->line('item_name'); ?> <span class="text-danger">*</span></label>
              <span id="m_item_name_msg" class="text-danger text-right pull-right"></span>
              <input type="text" class="form-control" id="m_item_name" name="m_item_name" placeholder="Enter item name" required>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_item_name_tamil">Item Name (Tamil)</label>
              <span id="m_item_name_tamil_msg" class="text-danger text-right pull-right"></span>
              <input type="text" class="form-control" id="m_item_name_tamil" name="m_item_name_tamil" placeholder="தயாரிப்பு பெயர்" style="font-family: 'Noto Sans Tamil', Arial, sans-serif;">
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_brand_id"><?= $this->lang->line('brand'); ?></label>
              <span id="m_brand_msg" class="text-danger text-right pull-right"></span>
              <select class="form-control" id="m_brand_id" name="m_brand_id" style="width: 100%;">
                <option value="">-Select Brand-</option>
                <?= get_brands_select_list(); ?>
              </select>
            </div>
          </div>
        </div>
        
        <div class="row">
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_category_id"><?= $this->lang->line('category'); ?> <span class="text-danger">*</span></label>
              <span id="m_category_id_msg" class="text-danger text-right pull-right"></span>
              <select class="form-control" id="m_category_id" name="m_category_id" style="width: 100%;" required>
                <option value="">-Select Category-</option>
                <?= get_categories_select_list(); ?>
              </select>
            </div>
          </div>
          <div class="col-md-3">
            <div class="form-group">
              <label for="m_unit_id"><?= $this->lang->line('unit'); ?> <span class="text-danger">*</span></label>
              <span id="m_unit_id_msg" class="text-danger text-right pull-right"></span>
              <select class="form-control" id="m_unit_id" name="m_unit_id" style="width: 100%;" required>
                <?= get_units_select_list(); ?>
              </select>
            </div>
          </div>
          <div class="col-md-3">
            <div class="form-group">
              <label for="m_hsn"><?= $this->lang->line('hsn'); ?></label>
              <span id="m_hsn_msg" class="text-danger text-right pull-right"></span>
              <input type="text" class="form-control maxlength" id="m_hsn" name="m_hsn" placeholder="HSN Code">
            </div>
          </div>
          <div class="col-md-3">
            <div class="form-group">
              <label for="m_sku"><?= $this->lang->line('sku'); ?></label>
              <span id="m_sku_msg" class="text-danger text-right pull-right"></span>
              <input type="text" class="form-control maxlength" id="m_sku" name="m_sku" placeholder="SKU">
            </div>
          </div>
          <div class="col-md-3">
            <div class="form-group">
              <label for="m_custom_barcode"><?= $this->lang->line('barcode'); ?></label>
              <span id="m_custom_barcode_msg" class="text-danger text-right pull-right"></span>
              <input type="text" class="form-control maxlength" id="m_custom_barcode" name="m_custom_barcode" placeholder="Barcode">
            </div>
          </div>
        </div>

        <div class="row">
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_alert_qty"><?= $this->lang->line('alert_qty'); ?></label>
              <span id="m_alert_qty_msg" class="text-danger text-right pull-right"></span>
              <input type="text" maxlength="10" class="form-control maxlength no_special_char_no_space" id="m_alert_qty" name="m_alert_qty" placeholder="Alert quantity">
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_seller_points"><?= $this->lang->line('seller_points'); ?></label>
              <span id="m_seller_points_msg" class="text-danger text-right pull-right"></span>
              <input type="text" maxlength="10" class="form-control maxlength" id="m_seller_points" name="m_seller_points" placeholder="Seller points">
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_description"><?= $this->lang->line('description'); ?></label>
              <span id="m_description_msg" class="text-danger text-right pull-right"></span>
              <textarea class="form-control" id="m_description" name="m_description" placeholder="Item description" rows="2"></textarea>
            </div>
          </div>
        </div>

        <!-- Pricing Section -->
        <div class="section-header">
          <i class="fa fa-money"></i>
          Pricing Information
        </div>
        
        <div class="row">
          <div class="col-md-3">
            <div class="form-group">
              <label for="m_price"><?= $this->lang->line('price'); ?> <span class="text-danger">*</span></label>
              <span id="m_price_msg" style="display:none" class="text-danger"></span>
              <input type="text" class="form-control only_currency" id="m_price" name="m_price" placeholder="Price without tax" required>
            </div>
          </div>
          <div class="col-md-3">
            <div class="form-group">
              <label for="m_purchase_price"><?= $this->lang->line('purchase_price'); ?> <span class="text-danger">*</span></label>
              <span id="m_purchase_price_msg" style="display:none" class="text-danger"></span>
              <input type="text" readonly class="form-control only_currency" id="m_purchase_price" name="m_purchase_price" placeholder="Purchase price">
            </div>
          </div>
          <div class="col-md-3">
            <div class="form-group">
              <label for="m_sales_price"><?= $this->lang->line('sales_price'); ?> <span class="text-danger">*</span></label>
              <span id="m_sales_price_msg" class="text-danger text-right pull-right"></span>
              <input type="text" maxlength="10" class="form-control maxlength only_currency" id="m_sales_price" name="m_sales_price" placeholder="Sales price" required>
            </div>
          </div>
          <div class="col-md-3">
            <div class="form-group">
              <label for="m_mrp"><?= $this->lang->line('mrp'); ?></label>
              <span id="m_mrp_msg" class="text-danger text-right pull-right"></span>
              <input type="text" maxlength="10" class="form-control maxlength only_currency" id="m_mrp" name="m_mrp" placeholder="Maximum retail price">
            </div>
          </div>
        </div>

        <div class="row">
          <div class="col-md-6">
            <div class="form-group">
              <label for="m_shop_rate">Shop Rate</label>
              <span id="m_shop_rate_msg" class="text-danger text-right pull-right"></span>
              <input type="text" maxlength="10" class="form-control maxlength only_currency" id="m_shop_rate" name="m_shop_rate" placeholder="Shop selling rate">
            </div>
          </div>
          <div class="col-md-6">
            <div class="form-group">
              <label for="m_wholesale_rate">Wholesale Rate</label>
              <span id="m_wholesale_rate_msg" class="text-danger text-right pull-right"></span>
              <input type="text" maxlength="10" class="form-control maxlength only_currency" id="m_wholesale_rate" name="m_wholesale_rate" placeholder="Wholesale rate">
            </div>
          </div>
        </div>

        <div class="row">
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_tax_id"><?= $this->lang->line('tax'); ?> <span class="text-danger">*</span></label>
              <span id="m_tax_id_msg" class="text-danger text-right pull-right"></span>
              <select class="form-control" id="m_tax_id" name="m_tax_id" style="width: 100%;" required>
                <?= get_tax_select_list(); ?>
              </select>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_tax_type"><?= $this->lang->line('tax_type'); ?> <span class="text-danger">*</span></label>
              <span id="m_tax_type_msg" class="text-danger text-right pull-right"></span>
              <select class="form-control" id="m_tax_type" name="m_tax_type" style="width: 100%;" required>
                <option value="Inclusive">Inclusive</option>
                <option value="Exclusive">Exclusive</option>
              </select>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_profit_margin"><?= $this->lang->line('profit_margin'); ?> (%)</label>
              <span id="m_profit_margin_msg" class="text-danger text-right pull-right"></span>
              <input type="text" class="form-control only_currency" id="m_profit_margin" name="m_profit_margin" placeholder="Profit margin">
            </div>
          </div>
        </div>

        <!-- Discount Section -->
        <div class="section-header">
          <i class="fa fa-percent"></i>
          Discount Information
        </div>
        
        <div class="row">
          <div class="col-md-6">
            <div class="form-group">
              <label for="m_discount_type"><?= $this->lang->line('discount_type'); ?></label>
              <span id="m_discount_type_msg" class="text-danger text-right pull-right"></span>
              <select class="form-control" id="m_discount_type" name="m_discount_type" style="width: 100%;">
                <option value='Percentage'>Percentage (%)</option>
                <option value='Fixed'>Fixed (<?= $CI->currency() ?>)</option>
              </select>
            </div>
          </div>
          <div class="col-md-6">
            <div class="form-group">
              <label for="m_discount"><?= $this->lang->line('discount'); ?></label>
              <span id="m_discount_msg" class="text-danger text-right pull-right"></span>
              <input type="text" class="form-control maxlength no_special_char_no_space" id="m_discount" name="m_discount" placeholder="Discount value">
            </div>
          </div>
        </div>

        <!-- Stock & Image Section -->
        <div class="section-header">
          <i class="fa fa-cube"></i>
          Stock & Media
        </div>
        
        <div class="row">
          <div class="col-md-4">
            <div class="form-group">
              <label for="m_warehouse_id"><?= $this->lang->line('warehouse'); ?></label>
              <span id="warehouse_id_msg" class="text-danger text-right pull-right"></span>
              <select class="form-control" id="m_warehouse_id" name="m_warehouse_id" style="width: 100%;">
                <?= get_warehouse_select_list();?>
              </select>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label for="adjustment_qty"><?= $this->lang->line('opening_stock'); ?></label>
              <span id="adjustment_qty_msg" class="text-danger text-right pull-right"></span>
              <input type="text" class="form-control maxlength only_currency" id="adjustment_qty" name="adjustment_qty" placeholder="Opening stock quantity" value='0'>
            </div>
          </div>
          <div class="col-md-4">
            <div class="form-group">
              <label for="item_image"><?= $this->lang->line('select_image'); ?></label>
              <span id="item_image_msg" style="display:block;" class="text-danger">Max (1000px*1000px), 1MB</span>
              <input type="file" name="item_image" id="item_image" class="form-control">
            </div>
          </div>
        </div>

        <!-- Hidden Fields -->
        <div class="hide">
          <div class="form-group">
            <label for="m_item_group"><?= $this->lang->line('item_group'); ?></label>
            <select class="form-control" id="m_item_group" name="m_item_group" style="width: 100%;">
              <option value="Single">Single</option>
              <option value="Variants">Variants</option>
            </select>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <input type="hidden" name="existing_row_count" value="0">
        <button type="button" class="btn btn-warning" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary add_item">Save Item</button>
      </div>
    </div>
  </div>
  <?= form_close();?>
</div>

