<?php $this->load->view("common/header"); ?>

<!-- end: HEAD -->

<!-- start: CSS REQUIRED FOR THIS PAGE ONLY -->
<link rel="stylesheet" type="text/css" href="<?php echo asset_url(); ?>plugins/select2/select2.css" />
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/DataTables/media/css/DT_bootstrap.css" />

<!-- end: CSS REQUIRED FOR THIS PAGE ONLY -->

<!-- start: CSS REQUIRED FOR THIS PAGE ONLY -->

<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/select2/select2.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/datepicker/css/datepicker.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-timepicker/css/bootstrap-timepicker.min.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-daterangepicker/daterangepicker-bs3.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/jQuery-Tags-Input/jquery.tagsinput.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/bootstrap-fileupload/bootstrap-fileupload.min.css">
<link rel="stylesheet" href="<?php echo asset_url(); ?>plugins/summernote/build/summernote.css">

<!-- end: CSS REQUIRED FOR THIS PAGE ONLY -->

<!-- end: HEAD -->

<!-- start: BODY -->

<body>

<!-- start: HEADER -->

<div class="navbar navbar-inverse navbar-fixed-top"> 
  
  <!-- start: TOP NAVIGATION CONTAINER -->
  
  <div class="container">
    <div class="navbar-header"> 
      
      <!-- start: RESPONSIVE MENU TOGGLER -->
      
      <button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button"> <span class="clip-list-2"></span> </button>
      
      <!-- end: RESPONSIVE MENU TOGGLER --> 
      
      <!-- start: LOGO -->
      
      <?php $this->load->view("common/logo"); ?>
      
      <!-- end: LOGO --> 
      
    </div>
    <div class="navbar-tools"> 
      
      <!-- start: TOP NAVIGATION MENU -->
      
      <?php $this->load->view("common/notifications.php"); ?>
      
      <!-- end: TOP NAVIGATION MENU --> 
      
    </div>
  </div>
  
  <!-- end: TOP NAVIGATION CONTAINER --> 
  
</div>

<!-- end: HEADER --> 

<!-- start: MAIN CONTAINER -->

<div class="main-container">
  <div class="navbar-content"> 
    
    <!-- start: SIDEBAR -->
    
    <?php $this->load->view("common/navigation"); ?>
    
    <!-- end: SIDEBAR --> 
    
  </div>
  
  <!-- start: PAGE -->
  
  <div class="main-content"> 
    
    <!-- start: PANEL CONFIGURATION MODAL FORM -->
    
    <div class="modal fade" id="panel-config" tabindex="-1" role="dialog" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times; </button>
            <h4 class="modal-title">Panel Configuration</h4>
          </div>
          <div class="modal-body"> Here will be a configuration form </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal"> Close </button>
            <button type="button" class="btn btn-primary"> Save changes </button>
          </div>
        </div>
        
        <!-- /.modal-content --> 
        
      </div>
      
      <!-- /.modal-dialog --> 
      
    </div>
    
    <!-- /.modal --> 
    
    <!-- end: SPANEL CONFIGURATION MODAL FORM -->
    
    <div class="container"> 
      
      <!-- start: PAGE HEADER -->
      
      <div class="row">
        <div class="col-sm-12"> 
          
          <!-- start: PAGE TITLE & BREADCRUMB -->
          
          <ol class="breadcrumb">
            <li> <a href="<?php echo base_url('dashboard'); ?>"> Dashboard </a> </li>
            <li> <a href="#"> Product </a> </li>
            <li class="active"> Edit Product </li>
            <li class="search-box">
              <form class="sidebar-search">
                <div class="form-group">
                  <input type="text" placeholder="Start Searching...">
                  <button class="submit"> <i class="clip-search-3"></i> </button>
                </div>
              </form>
            </li>
          </ol>
          <div class="page-header">
            <h1>Edit Product</h1>
            
            <?php
                //if($product_details->last_update_user)
                {
                echo " &nbsp;&nbsp;Last Updated: ".$product_details->last_update_date;
                
                	  $ref_id = new User_Model();
	  $data['user_details']=$ref_id->get_user_info($product_details->last_update_user);
	 echo '<br/>&nbsp;&nbsp;Updated by: '; 
	 echo $data['user_details']['user_first_name'].' '.$data['user_details']['user_last_name']; 
	 
	 
               // echo "Updated By: ";
                
                }
                
                ?>
          </div>
          
          <!-- end: PAGE TITLE & BREADCRUMB --> 
          
        </div>
      </div>
      
      <!-- start grid -->
      
      <div class="row">
        <div class="col-md-12"> 
          
          <!-- start: DYNAMIC TABLE PANEL -->
          
          <div class="panel panel-default">
            <div class="panel-heading"> <i class="fa fa-external-link-square"></i> Edit Product </div>
            <div class="panel-body">
              <div id="error"></div>
              <?php 

										$config = array('role' =>'form', 'class'=>'form-horizontal','id'=>'add_product_form', 'name'=>'add_product_form');

										echo form_open_multipart("#",$config);

										?>
              <input type="hidden" name="product_id" value="<?php echo $product_details->product_id; ?>">
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-3" > Brand * </label>
                <div class="col-sm-9">
                  <?php
											    
											   // echo "dep id:".$product_details->dep_id;
											    ?>
											    
											    <a onClick="click_add_new_cateegory_button_b()" id="" name="customer" style="cursor: pointer;    margin-top: 6px;    position: absolute;    left: -16px;"><i id="addIcon" class="fa fa-2x fa-plus-circle addIcon"></i></a>
											    
											    
                  <select id="dep_id" class="form-control search-select" name="dep_id">
                    <?php
											         
											         $sel_s='';
											         $sel_ser='';
											         if($product_details->dep_id==1){
											             $sel_s='selected';
											         }
											         
											         if($product_details->dep_id==2){
											             $sel_ser='selected';
											         }
											         
											         if($product_details->dep_id==3){
											             $sel_com='selected';
											         }
											         
											         ?>
                    <option value=""<?php //echo $sel_0; ?>>-Select-</option>
                    <?php 
											     //department_list
											
											foreach ($department_list as $key => $item)
											{
											$sel_com='';
											 if($product_details->dep_id==$item->department_id){
											             $sel_com='selected';
											         }
											?>
                    <option value="<?php echo $item->department_id;?>" <?php echo $sel_com;?>><?php echo $item->department_name;?> (<?php echo $item->department_id;?>)</option>
                    <?php } ?>
                    <!-- 
											         <option value="1"<?php echo $sel_s; ?>>Mobile Phone</option>
                        
                        <option value="2"<?php echo $sel_ser; ?>>Service Repair</option>
                        
                        <option value="3"<?php echo $sel_com; ?>>Computer</option> -->
                    
                  </select>
                  
                  <div id="cat_wap_b" style="margin-top:10px; display:none">
                    <input id="new_cat_name_b" class="form-control" name="new_cat_name_b" type="text">
                    <div class="btn btn-primary btn-squared" type="" onClick="save_new_category_b()"> Add New Brand  </div>
                  </div>
                  
                </div>
              </div>
              
              <!-- start type -->
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-3" > Type (<?php echo $product_details->ptype_id;?>) * 
                
                </label>
                <div class="col-sm-9">
                  <?php
                  
											    
											   // echo "dep id:".$product_details->dep_id;
											    ?>
											    
											    <a onClick="click_add_new_cateegory_button_t()" id="" name="customer" style="cursor: pointer;    margin-top: 6px;    position: absolute;    left: -16px;"><i id="addIcon" class="fa fa-2x fa-plus-circle addIcon"></i></a>
                  <select id="ptype_id" class="form-control search-select" name="ptype_id">
                    <?php
											       
											         
											         ?>
                    <option value="">-Select-</option>
                    <?php 
											     //department_list
											
											foreach ($type_list as $key => $item)
											{
											$sel_com='';
											 if($product_details->ptype_id==$item->ptype_id){
											             $sel_com=' selected';
											         }
											?>
                    <option value="<?php echo $item->ptype_id;?>" <?php echo $sel_com;?>><?php echo $item->ptype_name;?> (<?php echo $item->ptype_id;?>)</option>
                    <?php } ?>
                    
                    
                  </select>
                  
                  <div id="cat_wap_t" style="margin-top:10px; display:none">
                    <input id="new_cat_name_t" class="form-control" name="new_cat_name_t" type="text">
                    <div class="btn btn-primary btn-squared" type="" onClick="save_new_category_t()"> Add New Type  </div>
                  </div>
                  
                </div>
              </div>
              <!-- end typee -->
              
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-3" > Department * </label>
                <div class="col-sm-9"> <a onClick="click_add_new_cateegory_button()" id="" name="customer" style="cursor: pointer;    margin-top: 6px;    position: absolute;    left: -16px;"><i id="addIcon" class="fa fa-2x fa-plus-circle addIcon"></i></a>
                  <select class="form-control search-select" id="category" name="category">
                    <option value="">&nbsp;</option>
                    <?php foreach ($main_category as $key => $category) {

														if ($product_details->cat_id == $category->cat_id) {

														echo "<option selected value='$category->cat_id'>$category->cat_name ($category->cat_id)</option>";										

														} else {

														echo "<option value='$category->cat_id'>$category->cat_name</option>";										

														}

													} ?>
                  </select>
                  <div id="cat_wap" style="margin-top:10px; display:none">
                    <input id="new_cat_name" class="form-control" name="new_cat_name" type="text">
                    <div class="btn btn-primary btn-squared" type="" onClick="save_new_category()"> Add New Department  </div>
                  </div>
                </div>
              </div>
              
              <!-- Start Model -->
               <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-3" > Model * </label>
                <div class="col-sm-9"> 
                 <a onClick="click_add_new_cateegory_button_2()" id="" name="customer" style="cursor: pointer;    margin-top: 6px;    position: absolute;    left: -16px;"><i id="addIcon" class="fa fa-2x fa-plus-circle addIcon"></i></a>
                 
                 <select class="form-control search-select" id="pro_model_id" name="pro_model_id">
                    <option value="">-Select-</option>
                    <?php
                    //print_r($pro_model_list);
                    
                    foreach ($pro_model_list as $key => $category) {

														if ($product_details->pro_model_id == $category->pro_model_id) {

														echo "<option selected value='$category->pro_model_id'>$category->pro_model_name ($category->pro_model_id)</option>";										

														} else {

														echo "<option value='$category->pro_model_id'>$category->pro_model_name</option>";										

														}

													} ?>
                  </select>
                  
                  
                  <div id="cat_wap_2" style="margin-top:10px; display:none">
                    <input id="new_cat_name_2" class="form-control" name="new_cat_name_2" type="text">
                    <div class="btn btn-primary btn-squared" type="" onClick="save_new_category_2()"> Add New Model  </div>
                  </div>
                </div>
                    
                </div>
                 <!-- End Model -->
                
                <!-- Start Color -->
                <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-3" > Color * </label>
                <div class="col-sm-9"> 
                 <a onClick="click_add_new_cateegory_button_3()" id="" name="customer" style="cursor: pointer;    margin-top: 6px;    position: absolute;    left: -16px;"><i id="addIcon" class="fa fa-2x fa-plus-circle addIcon"></i></a>
                 
                 <select class="form-control search-select" id="pro_color_id" name="pro_color_id">
                    <option value="">-Select-</option>
                    <?php
                    //print_r($pro_model_list);
                    
                    foreach ($pro_color_list as $key => $category) {

														if ($product_details->pro_color_id == $category->pro_color_id) {

														echo "<option selected value='$category->pro_color_id'>$category->pro_color_name ($category->pro_color_id)</option>";										

														} else {

														echo "<option value='$category->pro_color_id'>$category->pro_color_name</option>";										

														}

													} ?>
                  </select>
                  
                  
                  <div id="cat_wap_3" style="margin-top:10px; display:none">
                    <input id="new_cat_name_3" class="form-control" name="new_cat_name_3" type="text">
                    <div class="btn btn-primary btn-squared" type="" onClick="save_new_category_3()"> Add New Color  </div>
                  </div>
                </div>
                    
                </div>
                
                <!-- End Color -->
                
                
                
                <!-- Start capacity -->
                <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-3" > Capacity * </label>
                <div class="col-sm-9"> 
                 <a onClick="click_add_new_cateegory_button_4()" id="" name="customer" style="cursor: pointer;    margin-top: 6px;    position: absolute;    left: -16px;"><i id="addIcon" class="fa fa-2x fa-plus-circle addIcon"></i></a>
                 
                 <select class="form-control search-select" id="pro_capacity_id" name="pro_capacity_id">
                    <option value="">-Select-</option>
                    <?php
                    //print_r($pro_model_list);
                    
                    foreach ($pro_capacity_list as $key => $category) {

														if ($product_details->pro_capacity_id == $category->pro_capacity_id) {

														echo "<option selected value='$category->pro_capacity_id'>$category->pro_capacity_name ($category->pro_capacity_id)</option>";										

														} else {

														echo "<option value='$category->pro_capacity_id'>$category->pro_capacity_name</option>";										

														}

													} ?>
                  </select>
                  
                  
                  <div id="cat_wap_4" style="margin-top:10px; display:none">
                    <input id="new_cat_name_4" class="form-control" name="new_cat_name_4" type="text">
                    <div class="btn btn-primary btn-squared" type="" onClick="save_new_category_4()"> Add New Capacity  </div>
                  </div>
                </div>
                    
                </div>
                
                <!-- End capacity -->
                
              <div class="form-group">
                <label class="col-sm-2 control-label " for="form-field-3" > Category  <?php //echo $product_details->sub_cat_id;?></label>
                <div id="" class="col-sm-9">
                    <?php
                   // print_r($sub_category);
                    ?>
                     <a onClick="click_add_new_sub_cateegory_button()" id="" name="customer" style="cursor: pointer;    margin-top: 6px;    position: absolute;    left: -16px;"><i id="addIcon" class="fa fa-2x fa-plus-circle addIcon"></i></a>
                  <div id="subcat_data">
                      
                    <!-- <select data-placeholder="Select Category to load Subcategories" id="subcategory" class=" form-control search-select" name="subcategory"> -->
                        
                        <select class="form-control search-select" id="subcategory" name="subcategory">
                        <option value="">-select-</option>
                      <?php foreach ($sub_category as $key => $sub_category) {

														if ($product_details->sub_cat_id == $sub_category->sub_cat_id) {

														echo "<option selected value='$sub_category->sub_cat_id'>$sub_category->sub_cat_name ".($sub_category->sub_cat_id)."</option>";										

														} else {

														echo "<option value='$sub_category->sub_cat_id'>$sub_category->sub_cat_name ".($sub_category->sub_cat_id)."</option>";										

														}

													} ?>
                    </select>
                  </div>
                  <div id="sub_cat_wap" style="margin-top:10px; display:none">
                    <input id="new_sub_category" class="form-control" name="new_sub_category" type="text">
                    <div class="btn btn-primary btn-squared" type="" onClick="save_new_sub_category()"> Add New Category </div>
                  </div>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-1"> Product Name
                  
                  *</label>
                <div class="col-sm-9">
                  <input type="text" id="product_name" class="form-control" name="product_name" value="<?php echo $product_details->product_name; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Product Code
                  
                  *</label>
                <div class="col-sm-9">
                  <input type="text" id="product_code" class="form-control" value="<?php echo $product_details->product_code; ?>" name="product_code">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Item Code </label>
                <div class="col-sm-9">
                  <input type="text" id="product_part_no" class="form-control" name="product_part_no" value="<?php echo $product_details->product_part_no; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Product Unit * </label>
                <div class="col-sm-9">
                  <select class="form-control search-select" id="unit" name="unit">
                    <option value="">&nbsp;</option>
                    <?php foreach ($unit_type as $key => $unit) {

						                            	if ($product_details->product_unit == $unit->unit_id) {

						                            	echo "<option selected value='$unit->unit_id'>$unit->unit_code</option>";

						                            	} else {

						                            	echo "<option value='$unit->unit_id'>$unit->unit_code</option>";

						                            	}

						                            	

						                            } ?>
                  </select>
                </div>
              </div>
              
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Product Cost </label>
                <div class="col-sm-9">
                  <input type="text" name="product_cost" id="product_cost" class="form-control auto" data-a-sign="Rs. " data-d-group="2" value="<?php echo $product_details->product_cost; ?>">
                </div>
              </div>
              
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Cash Price * </label>
                <div class="col-sm-9">
                  <input type="text" id="product_price" class="form-control auto" name="product_price" data-a-sign="Rs. " data-d-group="2" value="<?php echo $product_details->product_price; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Wholesale Price * </label>
                <div class="col-sm-9">
                  <input type="text" id="wholesale_price" class="form-control auto" name="wholesale_price" data-a-sign="Rs. " data-d-group="" value="<?php echo $product_details->wholesale_price; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Credit Selling Price </label>
                <div class="col-sm-9">
                  <input type="text" id="credit_salling_price" class="form-control auto" name="credit_salling_price" data-a-sign="Rs. " data-d-group="2" value="<?php echo $product_details->credit_salling_price; ?>">
                </div>
              </div>
              
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Tax Method </label>
                <div class="col-sm-9">
                  <select class="form-control" id="tax" name="tax">
                    <?php foreach ($tax as $key => $tax) {

						                            	if ($product_details->tax == $tax->id) {

						                            			echo "<option selected value='$tax->id'>$tax->name</option>";

						                            	} else {

						                            			echo "<option value='$tax->id'>$tax->name</option>";

						                            	}

						                            	

						                            } ?>
                  </select>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Minimum Quantity </label>
                <div class="col-sm-9">
                  <input type="text" id="alert_quty" name="alert_quty" class="form-control" value="<?php echo $product_details->product_alert_qty; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Maximum Quantity </label>
                <div class="col-sm-9">
                  <input type="text" id="product_max_qty" name="product_max_qty" class="form-control" value="<?php echo $product_details->product_max_qty; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Store Position </label>
                <div class="col-sm-9">
                  <input type="text" id="store_position" class="form-control" name="store_position" value="<?php echo $product_details->store_position; ?>">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Serial Number Exists </label>
                <div class="col-sm-9">
                  <input type="checkbox" name="product_sn_exissts" value="1" <?php if($product_details->product_sn_exissts) echo 'checked' ?>>
                </div>
              </div>
              <div class="form-group">
											<label class="col-sm-2 control-label" for="is_saleable">
												A saleable product
											</label>
											<div class="col-sm-9">
                                            <input type="checkbox" name="is_saleable" value="yes" id="is_saleable" checked>
											</div>
										</div>
              <div class="form-group">
                <label class="col-sm-2 control-label" for="form-field-2"> Product Image </label>
                <div class="col-sm-9">
                  <div class="form-group">
                    <div class="col-sm-4">
                      <label> </label>
                      <div class="fileupload fileupload-new" data-provides="fileupload">
                        <div class="input-group">
                          <div class="form-control uneditable-input"> <i class="fa fa-file fileupload-exists"></i> <span class="fileupload-preview"></span> </div>
                          <div class="input-group-btn">
                            <div class="btn btn-light-grey btn-file"> <span class="fileupload-new"><i class="fa fa-folder-open-o"></i> Select file</span> <span class="fileupload-exists"><i class="fa fa-folder-open-o"></i> Change</span>
                              <input type="file" class="file-input" name="userfile">
                            </div>
                            <a href="#" class="btn btn-light-grey fileupload-exists" data-dismiss="fileupload"> <i class="fa fa-times"></i> Remove </a> </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="form-group">
                <div class="col-sm-12">
                  <label class="control-label"> Product Details </label>
                  <textarea id="product_details" class="ckeditor form-control" cols="10" rows="5" name="product_details" ><?php echo $product_details->product_details; ?></textarea>
                </div>
              </div>
              <div class="form-group">
                <div class="col-sm-12">
                  <button class="btn btn-primary btn-squared" type="submit"> Update Product </button>
                </div>
                
                
              </div>
              <input name="product_cat_ref_id" type="hidden" id="product_cat_ref_id" value="0">
              <div class="form-group" style="display:none">
                <label class="col-sm-2 control-label" for="form-field-2"> Product Cost 2 </label>
                <div class="col-sm-9">
                  <input type="text" name="product_cost_2" id="product_cost_2" class="form-control auto" data-a-sign="Rs. " data-d-group="2" value="<?php echo $product_details->product_cost_2; ?>">
                </div>
              </div>
              </form>
            </div>
          </div>
        </div>
        
        <!-- end: DYNAMIC TABLE PANEL --> 
        
      </div>
    </div>
    
    <!-- end grid --> 
    
  </div>
  
  <!-- end: PAGE --> 
  
</div>

<!-- end: MAIN CONTAINER --> 

<!-- start: FOOTER -->

<div class="footer clearfix">
  <div class="footer-inner">
    <?php date("Y");?>
    Developed by: Sallelanka Solutions (pvt) Ltd. </div>
  <div class="footer-items"> <span class="go-top"><i class="clip-chevron-up"></i></span> </div>
</div>

<!-- end: FOOTER --> 

<!-- start: RIGHT SIDEBAR -->

<div id="page-sidebar"> <a class="sidebar-toggler sb-toggle" href="#"><i class="fa fa-indent"></i></a>
  <div class="sidebar-wrapper">
    <ul class="nav nav-tabs nav-justified" id="sidebar-tab">
      <li class="active"> <a href="#users" role="tab" data-toggle="tab"><i class="fa fa-users"></i></a> </li>
      <li> <a href="#favorites" role="tab" data-toggle="tab"><i class="fa fa-heart"></i></a> </li>
      <li> <a href="#settings" role="tab" data-toggle="tab"><i class="fa fa-gear"></i></a> </li>
    </ul>
  </div>
</div>

<!-- end: RIGHT SIDEBAR -->

<div id="event-management" class="modal fade" tabindex="-1" data-width="760" style="display: none;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times; </button>
        <h4 class="modal-title">Event Management</h4>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-light-grey"> Close </button>
        <button type="button" class="btn btn-danger remove-event no-display"> <i class='fa fa-trash-o'></i> Delete Event </button>
        <button type='submit' class='btn btn-success save-event'> <i class='fa fa-check'></i> Save </button>
      </div>
    </div>
  </div>
</div>

<!-- start: MAIN JAVASCRIPTS -->

<?php $this->load->view("common/footer"); ?>

<!-- end: MAIN JAVASCRIPTS --> 

<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY VALIDATION--> 

<script src="<?php echo asset_url(); ?>plugins/jquery-validation/dist/jquery.validate.min.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/autoNumeric.js"></script> 
<script src="<?php echo asset_url(); ?>js/form-validation-add-product.js"></script> 

<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY  VALIDATION--> 

<script>

	function save_new_category()
	{		
		var category = $('#category').val();
		var new_cat_name=$('#new_cat_name').val();
		if(!new_cat_name){
			alert("Please add category name");
		}else{
			
			 jQuery.ajax({
       		type: "POST",
       		url: "<?php echo base_url().'products/save_new_category?cat_id='?>"+category+'&new_cat_name='+new_cat_name,

       		cache: false,
      		 success: function(response)
       		{
			displayNotice('page','New category successfully added');
			var obj = jQuery.parseJSON(response);
			var cat_id=obj.cat_id;
									var cat_name=obj.cat_name;
									var app = $("<option/>",{value:cat_id , text: cat_name});
            						$('#category').append(app);
									$('#category').select2("val", cat_id).trigger('change');
									click_add_new_cateegory_button();


    	}
     });
		}
		
	
}	


	function save_new_category_2()
	{		
		var pro_model_id = $('#pro_model_id').val();
		var new_cat_name_2=$('#new_cat_name_2').val();
		if(!new_cat_name){
			alert("Please add model name");
		}else{
			
			 jQuery.ajax({
       		type: "POST",
       		url: "<?php echo base_url().'products/save_new_category_2?pro_model_id='?>"+pro_model_id+'&new_cat_name_2='+new_cat_name_2,

       		cache: false,
      		 success: function(response)
       		{
			displayNotice('page','New model successfully added');
			var obj = jQuery.parseJSON(response);
			var pro_model_id=obj.pro_model_id;
									var pro_model_name=obj.pro_model_name;
									var app = $("<option/>",{value:pro_model_id , text: pro_model_name});
            						$('#pro_model_id').append(app);
									$('#pro_model_id').select2("val", pro_model_id).trigger('change');
									click_add_new_cateegory_button_2();


    	}
     });
		}
		
	
}

	function save_new_category_4()
	{		
		var pro_capacity_id = $('#pro_capacity_id').val();
		var new_cat_name_4=$('#new_cat_name_4').val();
		if(!new_cat_name_4){
			alert("Please add capacity name");
		}else{
			
			 jQuery.ajax({
       		type: "POST",
       		url: "<?php echo base_url().'products/save_new_category_4?pro_capacity_id='?>"+pro_capacity_id+'&new_cat_name_4='+new_cat_name_4,

       		cache: false,
      		 success: function(response)
       		{
			displayNotice('page','New capacity successfully added');
			var obj = jQuery.parseJSON(response);
			var pro_capacity_id=obj.pro_capacity_id;
									var pro_capacity_name=obj.pro_capacity_name;
									var app = $("<option/>",{value:pro_capacity_id , text: pro_capacity_name});
            						$('#pro_capacity_id').append(app);
									$('#pro_capacity_id').select2("val", pro_capacity_id).trigger('change');
									click_add_new_cateegory_button_4();


    	}
     });
		}
		
	
}


	function save_new_category_3()
	{		
		var pro_color_id = $('#pro_color_id').val();
		var new_cat_name_3=$('#new_cat_name_3').val();
		if(!new_cat_name_3){
			alert("Please add color name");
		}else{
			
			 jQuery.ajax({
       		type: "POST",
       		url: "<?php echo base_url().'products/save_new_category_3?pro_color_id='?>"+pro_color_id+'&new_cat_name_3='+new_cat_name_3,

       		cache: false,
      		 success: function(response)
       		{
			displayNotice('page','New color successfully added');
			var obj = jQuery.parseJSON(response);
			var pro_color_id=obj.pro_color_id;
									var pro_color_name=obj.pro_color_name;
									var app = $("<option/>",{value:pro_color_id , text: pro_color_name});
            						$('#pro_color_id').append(app);
									$('#pro_color_id').select2("val", pro_color_id).trigger('change');
									click_add_new_cateegory_button_3();


    	}
     });
		}
		
	
}


function save_new_category_b()
	{		
		var pro_color_id = $('#pro_color_id').val();
		var new_cat_name_b=$('#new_cat_name_b').val();
		if(!new_cat_name_b){
			alert("Please add color name");
		}else{
			
			 jQuery.ajax({
       		type: "POST",
       		url: "<?php echo base_url().'products/save_new_category_b?pro_color_id='?>"+pro_color_id+'&new_cat_name_b='+new_cat_name_b,

       		cache: false,
      		 success: function(response)
       		{
			displayNotice('page','New brand successfully added');
			var obj = jQuery.parseJSON(response);
			var dep_id=obj.dep_id;
									var dep_name=obj.dep_name;
									var app = $("<option/>",{value:dep_id , text: dep_name});
            						$('#dep_id').append(app);
									$('#dep_id').select2("val", dep_id).trigger('change');
									click_add_new_cateegory_button_b();


    	}
     });
		}
		
	
}


function save_new_category_t()
	{		
		var pro_color_id = $('#pro_color_id').val();
		var new_cat_name_t=$('#new_cat_name_t').val();
		if(!new_cat_name_t){
			alert("Please add name");
		}else{
			
			 jQuery.ajax({
       		type: "POST",
       		url: "<?php echo base_url().'products/save_new_category_t?pro_color_id='?>"+pro_color_id+'&new_cat_name_t='+new_cat_name_t,

       		cache: false,
      		 success: function(response)
       		{
			displayNotice('page','New type successfully added');
			var obj = jQuery.parseJSON(response);
			var dep_id=obj.dep_id;
									var dep_name=obj.dep_name;
									var app = $("<option/>",{value:dep_id , text: dep_name});
            						$('#ptype_id').append(app);
									$('#ptype_id').select2("val", dep_id).trigger('change');
									click_add_new_cateegory_button_t();


    	}
     });
		}
		
	
}
		

	function save_new_sub_category()
	{		
		var category = $('#category').val();
		//alert(cat_id);
		var subcategory = $('#subcategory').val();
		var new_sub_category=$('#new_sub_category').val();
		
		if(!category){
			alert("Please select category");
		}
		if(!new_cat_name){
			alert("Please add sub category name");
		}else{
			
			 jQuery.ajax({
       		type: "POST",
       		url: "<?php echo base_url().'products/save_new_sub_category?cat_id='?>"+category+'&new_sub_category='+new_sub_category,

       		cache: false,
      		 success: function(response)
       		{
			displayNotice('page','New sub category successfully added');
			var obj = jQuery.parseJSON(response);
			var cat_id=obj.cat_id;
									var cat_name=obj.cat_name;
									var app = $("<option/>",{value:cat_id , text: cat_name});
            						$('#subcategory').append(app);
									$('#subcategory').select2("val", cat_id).trigger('change');
									click_add_new_sub_cateegory_button();


    	}
     });
		}
		
	
}	

function click_add_new_cateegory_button(){
		//$("#cat_wap").show();
		var x = document.getElementById("cat_wap");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
		
	}
	
	
	function click_add_new_cateegory_button_2(){
		//$("#cat_wap").show();
		var x = document.getElementById("cat_wap_2");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
		
	}
	
	
	function click_add_new_cateegory_button_3(){
		//$("#cat_wap").show();
		var x = document.getElementById("cat_wap_3");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
		
	}
	
	
	function click_add_new_cateegory_button_b(){
		//$("#cat_wap").show();
		var x = document.getElementById("cat_wap_b");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
		
	}
	
		function click_add_new_cateegory_button_t(){
		//$("#cat_wap").show();
		var x = document.getElementById("cat_wap_t");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
		
	}
	
		function click_add_new_cateegory_button_4(){
		//$("#cat_wap").show();
		var x = document.getElementById("cat_wap_4");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
		
	}
	
	
	function click_add_new_sub_cateegory_button(){
		//$("#cat_wap").show();
		var x = document.getElementById("sub_cat_wap");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
		
	}





function create_product_name(){

	$('#product_name').val($('#category').find('option:selected').text()+' '+$('#subcategory').find('option:selected').text());

	

	$('#product_details').text($('#category').find('option:selected').text()+' '+$('#subcategory').find('option:selected').text());

}

//create product code

function create_product_code(){

	var cat_id=$('#category').val();

	{

	var url="<?php echo base_url();?>products/create_product_code/"+cat_id;

		$.post(url)

	  .done(function( data ) {

		  var obj = jQuery.parseJSON(data);

		  if(obj.status){

		  	$('#product_part_no').val(obj.product_code);

			$('#product_cat_ref_id').val(obj.product_cat_ref_id);

		  }

	  });

	}

	

}		

		

			jQuery(document).ready(function() {

				$(".search-select").select2({

					allowClear: true

				});



				FormValidator.init();

    			$('.auto').autoNumeric('init');

			});





			$('select#category_del').on('change', function(){



			   		var v = $(this).val();



					$.ajax({

					  type: "get",

					  async: false,

					  url: "<?php echo base_url('products/get_sub_category_by_id'); ?>",

					  data: { category_id: v },

					  dataType: "html",

					  success: function(data) {

						if(data != "") {

							$('#subcat_data').empty();

							$('#subcat_data').html(data);

							$("#subcategory").select2({allowClear: true});

						} else {

							$('#subcat_data').empty();

							var default_data = '<select onChange="create_product_name()" name="subcategory" id="subcategory" class="form-control search-select" data-placeholder="Select Category to load Subcategories"></select>';

							$('#subcat_data').html(default_data);

							$("#subcategory").select2({allowClear: true});

							set_message("Product Info","No Subcategory found for the select category.");

						}},

					  error: function(){

       					alert('Error occured while getting data from server.');

    				  }

					  

					});

			});





		function add_product(form) {



               $('body').modalmanager('loading');

                setTimeout(function () {

                    $.ajax({

                    url: "<?php echo base_url('products/edit_product'); ?>", // Url to which the request is send

                    type: "POST",             // Type of request to be send, called as method

                    data: new FormData(form), // Data sent to server, a set of key/value pairs (i.e. form fields and values)

                    contentType: false,       // The content type used when sending data to the server.

                    cache: false,             // To unable request pages to be cached

                    processData:false,        // To send DOMDocument or non processed data file it is set to false

                        success: function(data)   // A function to be called if request succeeds

                        {

                            var obj = jQuery.parseJSON(data);

                            if (obj.status==0) 

                                {

                                    $('div#error').html('<div class="alert alert-block alert-danger fade in"><button type="button" class="close" data-dismiss="alert">×</button><h4 class="alert-heading"><i class="fa fa-times-circle"></i> Error!</h4>'+obj.validation+'</div>');

                                    $('body').modalmanager('removeLoading');

                                    $('body').attr('class','');

                                } 

                                else

                                {

                                    $('body').modalmanager('removeLoading');

                                    $('body').attr('class','');

                                    set_message('categories notice!','Product successfully Updated');

									//document.getElementById("add_product_form").reset();

                                };



                        }

                    });

                }, 1000);

		}

$('#is_saleable').change(function(){
				
				if ($('#'+this.id).is(':checked')) {
					$('#'+this.id).val("yes");
					displayNotice("Edit Product","Marked as a saleabe product");
				}else {
					$('#'+this.id).val("no");
					displayNotice("Edit Product","Marked as a non sealable product");
				}
			});

		</script>
</body>

<!-- end: BODY -->

</html>