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

	<!-- 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'); ?>">
										 DASHBORD 
									</a>
								</li>
                                <li>
									<a href="#">
										 RAW MATERIAL
									</a>
								</li>
                                
								<li class="active">
							NEW - RAW MATERIAL 
								</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">
								<h3>NEW - RAW MATERIAL </h3>
							</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>
							NEW - RAW MATERIAL
								</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);
										?>                                                                   
										<div class="form-group">
											<label class="col-sm-2 control-label" for="form-field-1">
												NAME
											*</label>
											<div class="col-sm-9">
												<input type="text" id="product_name" class="form-control" name="product_name">
											</div>
										</div>

										<div class="form-group">
											<label class="col-sm-2 control-label" for="form-field-2">
											CODE
											*</label>
											<div class="col-sm-9">
                                           
												<input type="text" id="product_code" class="form-control" name="product_code" value="">
                                                <input type="hidden" id="product_id" class="form-control" name="product_id" value="">
											</div>
										</div>
										<div class="form-group">
									<label class="col-sm-2 control-label" for="form-field-1">
										TYPE
									</label>
									<div class="col-sm-9">
										 <select id="product_type" class="form-control" name="product_type">
												<?php 
                                                    foreach ($product_type as $row){ 
                                                    if($row->mpt_id==2){continue;}
                                                    ?>
													<option value="<?php echo $row->mpt_id; ?>"> <?php echo $row->mpt_name; ?> </option>
                                                <?php   } ?>							
										</select>
									</div>
								</div>
                                        <div class= "form-group collapse" >
											<label class="col-sm-2 control-label" for="form-field-2">
												SAP CODE
											</label>
											<div class="col-sm-9">
												<input type="text" id="product_part_no" class="form-control" name="product_part_no">
											</div>
										</div>
                                      
									  <div class="form-group">
											<label class="col-sm-2 control-label" for="form-field-3" >
												CATEGORY*
											</label>
											<div class="col-sm-8">
												<select class="form-control search-select" id="category" name="category">
												<option value="">&nbsp;</option>
													<?php foreach ($main_category as $key => $category) {?>
														<option value="<?php echo $category->cat_id; ?>"><?php echo $category->cat_name; ?></option>										
													<?php } ?>
												</select>
												
											
											</div>
												<div class="col-sm-1">
												    	<div class="d-flex align-items-center">
												    	<button data-toggle="tooltip" title="NEW CATEGORY" type="button" onclick="add_category()" class="btn btn-sm btn-primary "><i class="fa fa-plus"></i></button>
                                        	<button data-toggle="tooltip" title="EDIT CATEGORY" type="button" onclick="edit_category()" class="btn btn-sm btn-primary"><i class="fa fa-edit"></i></button>
                                        </div>
												    </div>
										</div>
 							        	<div class="form-group">
											<label class="col-sm-2 control-label" for="form-field-3" >
												SUB CATEGORY
											</label>
											<div id="subcat_data" class="col-sm-8">
											<select data-placeholder="Select Category to load Subcategories" id="subcategory" class="form-control search-select" name="subcategory">
											<option selected="selected" value=""></option>
											</select>
											</div>
												<div class="col-sm-1">
												    	<button data-toggle="tooltip" title="NEW SUB CATEGORY" type="button" onclick="add_sub_category()" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i></button>
                                        <button data-toggle="tooltip" title="EDIT SUB CATEGORY" type="button" onclick="edit_sub_category()" class="btn btn-sm btn-primary"><i class="fa fa-edit"></i></button>
												    </div>
										</div>
										
                                <div class="form-group">
											<label class="col-sm-2 control-label" for="form-field-2">
											UOM *
											</label>
											<div class="col-sm-9">
												<select  class="form-control search-select" id="unit" name="unit">
						                            <?php foreach ($unit_type as $key => $unit) {
						                            	if ($unit->unit_code == "Item") {
						                            		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="pr_quantity">
												QTY RER ITEM IN UOM  
											*</label>
											<div class="col-sm-9">
												<input type="text" id="pr_quantity" class="form-control" name="pr_quantity" value="1">
											</div>
										</div>
                                       <div class="form-group">
											<label class="col-sm-2 control-label" for="form-field-2">
												CPU  *
											</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="0">
											</div>
								        </div> 
								        
								        <div class="collapse">
                                            <hr>
                                            DISTRIBUTION PRICES</br></br>
                                            <div class="form-group">
    											<label class="col-sm-2 control-label" for="form-field-2">
    												RETAIL 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="0">
    											</div>
    										</div>  
                                            <div class="form-group">
    											<label class="col-sm-2 control-label" for="form-field-2">
    												CREDIT 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="0">
    											</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="2" value="0">
    											</div>
    										</div>   
                                        </div>
                                         <hr>
                                        
                                        <div class="form-group collapse">
											<label class="col-sm-2 control-label" for="sub_product_of">
												MAIN ITEM
											</label>
											<div class="col-sm-9">
											    <input type="hidden" id="sub_product_of" name="sub_product_of" class="js-data-customer_id-ajax form-control" style="padding:0px 0px; border: none; box-shadow: none" placeholder="-Select-" value="" />
												<!--<input type="text"  id="sub_product_of" name="sub_product_of" class="form-control" value="<?php echo $product_details->sub_product_of; ?>">-->
											</div>
										</div>
                                        <div class="form-group">
											<label class="col-sm-2 control-label" for="form-field-2">
												BRAND * 
											</label>
											<div class="col-sm-8">
												<input type="hidden" value="" id="brand_id" name="brand_id" class="js-data-customer_id-ajax form-control" style="padding:0px 0px; border: none; box-shadow: none" placeholder="-Select-" />
                     						</div>
                     						
                     							<div class="col-sm-1">
												    	<button data-toggle="tooltip" title="NEW BRAND" type="button" onclick="add_brand()" class="btn btn-sm btn-primary "><i class="fa fa-plus"></i></button>
                                        <button data-toggle="tooltip" title="EDIT BRAND" type="button" onclick="edit_brand()" class="btn btn-sm btn-primary"><i class="fa fa-edit"></i></button>
												    </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) {
						                            	//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 QUNTITY
											</label>
											<div class="col-sm-9">
												<input type="text"  id="alert_quty" name="alert_quty" class="form-control">
											</div>
										</div>
                                         <div class="form-group">
											<label class="col-sm-2 control-label" for="form-field-2">
												MAXIMUM QUNTITY
											</label>
											<div class="col-sm-9">
												<input type="text"  id="product_max_qty" name="product_max_qty" class="form-control">
											</div>
										</div>
                                        
                                        
                                         <div class="form-group">
											<label class="col-sm-2 control-label" for="form-field-2">
												STORE LOCATION
											</label>
											<div class="col-sm-9">
                                                <input type="text" id="store_position" class="form-control" name="store_position">
											</div>
										</div> 
                                       
                                        <div class="form-group collapse">
											<label class="col-sm-2 control-label" for="form-field-2">
												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">
													DETAILS *
												</label>
												<textarea class="ckeditor form-control" cols="10" rows="10" name="product_details"></textarea>
                                         </div>
										</div>
                                      
										
										<div class="form-group">
                                        	<div class="col-sm-1">
                                              <input type="checkbox" id="do_not_refresh" class="form-control" name="do_not_refresh" style="float:right" value="0">
                                          </div>
                                          <div class="col-sm-9 control-label">
                                                     KEEP CURRANT DATA
                                                </div>
                                            
										</div>
										
										 <div class="form-group">
                                        	<div class="col-sm-1">
                                              <input type="checkbox" id="is_export_scale" class="form-control" name="is_export_scale" style="float:right" value="0">
                                          </div>
                                          <div class="col-sm-9 control-label">
                                                     EXPORT TO SCALE MACHINE
                                                </div>
                                            
										</div>
                                        
                                  <div class="form-group">
                                     <div class="col-sm-12">       
									<button class="btn btn-primary btn-squared" type="submit">
											SAVE
										</button>
                                        </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">
				2014 &copy; clip-one by cliptheme.
			</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.1.js"></script>
		<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY  VALIDATION-->
                        
		<script>
			jQuery(document).ready(function() {
				$(".search-select").select2({
					allowClear: true
				});

				FormValidator.init();
    			$('.auto').autoNumeric('init');
			});
			
			$('#is_hw').change(function(){
				
				if ($('#'+this.id).is(':checked')) {
					$('#'+this.id).val(1);
					displayNotice("Edit Product","Marked as a Final product");
				}else {
					$('#'+this.id).val(0);
					displayNotice("Edit Product","Marked as a Non Final only product");
				}
			});

			$('select#category').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 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) {
		    var refresh=0;
		     if ($('#do_not_refresh').is(':checked')) {
					refresh=1;
				}
               $('body').modalmanager('loading');
                setTimeout(function () {
                    $.ajax({
                    url: "<?php echo base_url('product_material/loadSaveProductMaterial'); ?>", // 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','');
									window.scrollTo( 500, 0 );
                                } 
                                else
                                {
                                    $('body').modalmanager('removeLoading');
                                    $('body').attr('class','');
                                    set_message('categories notice!','Product successfully Added');
									setTimeout(function(){
									if (refresh==1) {
					                    displayNotice("ADD PRODUCT","Do not refresh");
					                    $("#product_code").val("");
					                    $("#product_name").val("");
					                    $("#product_cost").val("");
					                    $("#retail_cash").val("");
					                    
				                    }else {
				                        document.getElementById("add_product_form").reset();
					                    displayNotice("ADD PRODUCT","refresh after add");
					                   window.location.reload(this);
				                    }
									}, 2000);
                                };

                        }
                    });
                }, 1000);
		}
		
		$("#brand_id").select2({
	allowClear: true,
ajax: {
url: "<?php echo base_url('brands/getBrand') ?>",
		dataType: 'json',
		delay: 250,
		data: function (query) {
		if (!query)
				query = '';
		return {
		search_string: query,
				format: 'json'
		};
		},
		results: function (data) {
		return {
		results: $.map(data, function (item) {
		return {
		text: item.brand_name,
				slug: item.brand_name,
				id: item.brand_id
		};
		})
		};
		},
		cache: true
}
});

$('input:text').on('focus',function(){
	this.select();
	});

$("#sub_product_of").select2({
	allowClear: true,
    ajax: {
    url: "<?php echo base_url('products/getProducts') ?>",
    		dataType: 'json',
    		delay: 250,
    		data: function (query) {
    		if (!query)
    				query = '';
    		return {
    		search_string: query,
    				format: 'json'
    		};
    		},
    		results: function (data) {
    		return {
    		results: $.map(data, function (item) {
    		return {
    		text: item.product_code+ ' / '+ item.product_name,
    				slug: item.product_name,
    				id: item.product_id
    		};
    		})
    		};
    		},
    		cache: true
    }
});


$('#is_export_scale').change(function(){
				
				if ($('#'+this.id).is(':checked')) {
					$('#'+this.id).val(1);
					displayNotice("Edit Product","Marked as a scale product");
				}else {
					$('#'+this.id).val(0);
					displayNotice("Edit Product","Marked as a non scale product");
				}
	});
	
	
function add_category(){
	var locale = {
    OK: 'SAVE',
    CONFIRM: 'SAVE',
    CANCEL: 'CANCEL'
};
bootbox.addLocale('custom', locale);
bootbox.prompt({ 
    title: "NEW CATEGORY", 
    locale: 'custom',
    callback: function (result) {
        console.log('This was logged in the callback: ' + result);
        //---------------------------
        //ajex
        $.ajax({
        url: '<?php echo base_url('product_category/save_product_category'); ?>',
        type: 'POST',
        data: {cat_name:result},
        datatype: 'json',
        success: function (data) {  
            obj = JSON.parse(data);
            if(obj.status==1)
            {
              $("#category").append(new Option(result, obj.result));
              $("#category").val(obj.result).change();
                //bootbox.alert(obj.validation);
                displayNotice("ADD CATEGORY","CATEGORY CREATED");
               // $("#category").val(obj.result).change();
            }else{
                bootbox.alert(obj.validation);
            }
        },
        error: function (jqXHR, textStatus, errorThrown) { 
            
            alert("CONTACT SYSTEM ADMINISTRATOR!");
        }
    });
        //-----------------------------------------
    }
});
	}
	
	
	
	
		function add_sub_category(){
		    var cat_id=$("#category option:selected").val();
        if(cat_id>0){
            
        }else
        {
          bootbox.alert("Please Select Category First");  
          return false;
        }
	var locale = {
    OK: 'SAVE',
    CONFIRM: 'SAVE',
    CANCEL: 'CANCEL'
};
bootbox.addLocale('custom', locale);
bootbox.prompt({ 
    title: "NEW SUB CATEGORY", 
    locale: 'custom',
    callback: function (result) {
        console.log('This was logged in the callback: ' + result);
        //---------------------------
        //ajex
        
        $.ajax({
        url: '<?php echo base_url('product_category/save_product_sub_category'); ?>',
        type: 'POST',
        data: {cat_name:result,cat_id:cat_id},
        datatype: 'json',
        success: function (data) {  
            obj = JSON.parse(data);
            if(obj.status==1)
            {
              $("#subcategory").append(new Option(result, obj.result));
              $("#subcategory").val(obj.result).change();
               // bootbox.alert(obj.validation);
               displayNotice("ADD SUB CATEGORY","SUB CATEGORY CREATED");
                $("#subcategory").val(obj.result).change();
            }else{
                bootbox.alert(obj.validation);
            }
        },
        error: function (jqXHR, textStatus, errorThrown) { 
            alert("CONTACT SYSTEM ADMINISTRATOR!");
        }
    });
        //-----------------------------------------
    }
});
	}
	
	
	
	function add_brand(){
	var locale = {
    OK: 'SAVE',
    CONFIRM: 'SAVE',
    CANCEL: 'CANCEL'
};
bootbox.addLocale('custom', locale);
bootbox.prompt({ 
    title: "NEW BRAND", 
    locale: 'custom',
    callback: function (result) {
        console.log('This was logged in the callback: ' + result);
        //---------------------------
        //ajex
        $.ajax({
        url: '<?php echo base_url('product_category/save_product_brand'); ?>',
        type: 'POST',
        data: {cat_name:result},
        datatype: 'json',
        success: function (data) {  
            obj = JSON.parse(data);
            if(obj.status==1)
            {
              $("#brand_id").append(new Option(result, obj.result));
              $("#brand_id").val(obj.result).change();
                //bootbox.alert(obj.validation);
                displayNotice("ADD BRAND","BRAND CREATED");
                $("#brand_id").val(obj.result).change();
            
                $("#brand_id").select2('data', { id:obj.result, text: result});
        
            }else{
                bootbox.alert(obj.validation);
            }
        },
        error: function (jqXHR, textStatus, errorThrown) { 
            
            alert("CONTACT SYSTEM ADMINISTRATOR!");
        }
    });
        //-----------------------------------------
    }
});
	}
	
	


	function edit_category(){
	    var cat_id=$("#category option:selected").val();
	      var cat_text=$("#category option:selected").text();
	      
	    if(cat_id>0){}else{
	     bootbox.alert("Select Category Before Edit !"); 
	     return false;
	    }
	    
	      
	var locale = {
    OK: 'SAVE',
    CONFIRM: 'SAVE',
    CANCEL: 'CANCEL'
};
bootbox.addLocale('custom', locale);
bootbox.prompt({ 
    title: "EDIT CATEGORY <br> <small>Selected Category Name : "+cat_text+"</small> <br> <small>Enter new name bellow </small>", 
    locale: 'custom',
    callback: function (result) {
        console.log('This was logged in the callback: ' + result);
        //---------------------------
        //ajex
        $.ajax({
        url: '<?php echo base_url('product_category/update_product_category'); ?>',
        type: 'POST',
        data: {cat_name:result,cat_id:cat_id},
        datatype: 'json',
        success: function (data) {  
            obj = JSON.parse(data);
            if(obj.status==1)
            {
                $("#category option[value='"+cat_id+"']").remove();
              $("#category").append(new Option(result, cat_id));
              $("#category").val(cat_id).change();
                //bootbox.alert(obj.validation);
                displayNotice("Edit CATEGORY","CATEGORY UPDATED");
                //$("#brand_id").val(obj.result).change();
            
                //$("#brand_id").select2('data', { id:obj.result, text: result});
        
            }else{
                bootbox.alert(obj.validation);
            }
        },
        error: function (jqXHR, textStatus, errorThrown) { 
            
            alert("CONTACT SYSTEM ADMINISTRATOR!");
        }
    });
        //-----------------------------------------
    }
});
	}	
	
	
	
		function edit_sub_category(){
	    var cat_id=$("#subcategory option:selected").val();
	      var cat_text=$("#subcategory option:selected").text();
	      
	    if(cat_id>0){}else{
	     bootbox.alert("Select Brand Before Edit !"); 
	     return false;
	    }
	    
	      
	var locale = {
    OK: 'SAVE',
    CONFIRM: 'SAVE',
    CANCEL: 'CANCEL'
};
bootbox.addLocale('custom', locale);
bootbox.prompt({ 
    title: "EDIT SUB CATEGORY <br> <small>Selected Sub-Category Name : "+cat_text+"</small> <br> <small>Enter new name bellow </small>", 
    locale: 'custom',
    callback: function (result) {
        console.log('This was logged in the callback: ' + result);
        //---------------------------
        //ajex
        $.ajax({
        url: '<?php echo base_url('product_category/update_product_sub_category'); ?>',
        type: 'POST',
        data: {cat_name:result,cat_id:cat_id},
        datatype: 'json',
        success: function (data) {  
            obj = JSON.parse(data);
            if(obj.status==1)
            {
              $("#subcategory option[value='"+cat_id+"']").remove();
              $("#subcategory").append(new Option(result, cat_id));
              $("#subcategory").val(cat_id).change();
              displayNotice("Edit SUB-CATEGORY","SUB-CATEGORY UPDATED");
              
            }else{
                bootbox.alert(obj.validation);
            }
        },
        error: function (jqXHR, textStatus, errorThrown) { 
            
            alert("CONTACT SYSTEM ADMINISTRATOR!");
        }
    });
        //-----------------------------------------
    }
});
	}
	
	
	
	
	
	
	
	
		function edit_brand(){
	     var cat= $('#brand_id').select2('data');
	    if(cat==null){bootbox.alert("Select Sub-Category Before Edit !"); 
	     return false;}
	var locale = {
    OK: 'SAVE',
    CONFIRM: 'SAVE',
    CANCEL: 'CANCEL'
};
bootbox.addLocale('custom', locale);
bootbox.prompt({ 
    title: "EDIT BRAND <br> <small>Selected Brand Name : "+cat.text+"</small> <br> <small>Enter new name bellow </small>", 
    locale: 'custom',
    callback: function (result) {
        console.log('This was logged in the callback: ' + result);
        //---------------------------
        //ajex
        $.ajax({
        url: '<?php echo base_url('product_category/update_product_brand'); ?>',
        type: 'POST',
        data: {cat_name:result,cat_id:cat.id},
        datatype: 'json',
        success: function (data) {  
            obj = JSON.parse(data);
            if(obj.status==1)
            {
              $('#brand_id').val(null).trigger('change');
              $("#brand_id").append(new Option(result, cat.id));
              $("#brand_id").val(cat.id).change();
                //bootbox.alert(obj.validation);
                displayNotice("EDIT BRAND","BRAND UPDATED");
                $("#brand_id").val(cat.id).change();
                $("#brand_id").select2('data', { id:cat.id, text: result});
            }else{
                bootbox.alert(obj.validation);
            }
        },
        error: function (jqXHR, textStatus, errorThrown) { 
            
            alert("CONTACT SYSTEM ADMINISTRATOR!");
        }
    });
        //-----------------------------------------
    }
});
	}
	
	
	
	
		</script>
	</body>
	<!-- end: BODY -->
</html>