<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Masterlist extends CI_Controller {

	


	public function material()
	{
		
		check_login();
	     if($this->input->post()){
	     	
	           $result = $this->Master_list->add_material($_POST);
	        if($result){$add_material=array('status'=>'true');}else{$add_material=array('status'=>'false');}
	            echo json_encode($add_material);
	      }else{
	      	$data['get_materials']=$this->Master_list->get_materials();
	      	$data['get_units']=$this->Master_list->get_units();
	      	$data['material_type']=$this->Master_list->material_type();

	         $this->load->view('masterlist/materials',$data);
	      }
		
	}

	public function view_material_details(){

		check_login();

		$id=$this->input->post('id');
		$data['get_materials_all']=$this->Master_list->get_materials_all($id);

		echo json_encode (array('html'=>$this->load->view('masterlist/materials_details',$data,true)));
		}

	public function delete_material($id)
	{
		 check_login();
	
			$result=$this->Master_list->delete_material($id);
	
			if($result){$material=array('status'=>'true');}else{$material=array('status'=>'false');}
			echo json_encode($material);
		
				
	}

	


	public function edit_get_materials($id)
	{
		 check_login();

	    // $id = $this->uri->segment('3');
		if($this->input->post())
		{
		
			$result=$this->Master_list->update_material($id);
			
			if($result){$material=array('status'=>'true');}else{$party=array('status'=>'false');}
			echo json_encode($material);
		}else{
					$data['get_pro_type']=$this->Master_list->get_pro_type();
	      		 	$data['get_materials_data']=$this->Master_list->get_materials_data($id);
	     		 	$data['get_units']=$this->Master_list->get_units();
	     		 	$data['material_type']=$this->Master_list->material_type();
	          		$this->load->view('masterlist/edit_material',$data);
	      }
				
	}


	

	
	public function products()
	{
		check_login();
		
		if($this->input->post()){
	     	
	           $result = $this->Master_list->add_products($_POST);
	        if($result){$add_material=array('status'=>'true');}else{$add_material=array('status'=>'false');}
	            echo json_encode($add_material);
	      }else{
	      	$data['get_products']=$this->Master_list->get_products();
	      	$data['get_pro_type']=$this->Master_list->get_pro_type();
	      	
	      	
	         $this->load->view('masterlist/products',$data);
	      }
		
	}


	public function qc_parameter()
	{
		check_login();
		$id = $this->uri->segment('3');

		/*$result=$this->Master_list->update_products_status($id);*/

		if($this->input->post()){
	     	
	           $result = $this->Master_list->add_product_parameter($_POST);
	        if($result){$add_product_parameter=array('status'=>'true');}else{$add_product_parameter=array('status'=>'false');}
	            echo json_encode($add_product_parameter);
	      }else{
	      	    $data['get_products_parameter']=$this->Master_list->get_products_parameter($id);
	      //	$data['get_pro_type']=$this->Master_list->get_pro_type();
	      	
	      	
	        	 $this->load->view('masterlist/product_qc_parameter',$data);
	      }
		
	}


	public function view_products_details(){

		check_login();

		$id=$this->input->post('id');
		$data['get_product_all']=$this->Master_list->get_product_data_all($id);
		//$data['get_product_parameter']=$this->Master_list->get_parameter($id);
		$data['get_pro_molds']=$this->Master_list->get_pro_molds($id);
		echo json_encode (array('html'=>$this->load->view('masterlist/view_details_products',$data,true)));
		}

	public function product_code(){


		if($this->input->post())
			{
				$id = $this->input->post('id');
					if($id == 5){
					$data['pro_code']=$this->Master_list->get_counter_number_fg();
					$xx = $data['pro_code'][0]['pro_code'];
		             
		            for ($pro_code = 0; $pro_code <= $xx; $pro_code++) {
		             
		            }
					echo json_encode($pro_code);

				}else if($id == 1){

					$data['pro_code']=$this->Master_list->get_counter_number();
					$xx = $data['pro_code'][0]['pro_code'];
		             
		            for ($pro_code = 0; $pro_code <= $xx; $pro_code++) {
		             
		            }
					echo json_encode($pro_code);
					}else if ($id== 2) {
						
						$data['pro_code']=$this->Master_list->get_counter_number_printed();
						$xx = $data['pro_code'][0]['pro_code'];
		             
		           		 for ($pro_code = 0; $pro_code <= $xx; $pro_code++) {
		             
		          		  }
					echo json_encode($pro_code);
					}else if ($id== 3) {
						
						$data['pro_code']=$this->Master_list->get_counter_number_assembled();
						$xx = $data['pro_code'][0]['pro_code'];
		             
		           		 for ($pro_code = 0; $pro_code <= $xx; $pro_code++) {
		             
		          		  }
					echo json_encode($pro_code);
					}else if ($id== 4) {
						
						$data['pro_code']=$this->Master_list->get_counter_number_sealed();
						$xx = $data['pro_code'][0]['pro_code'];
		             
		           		 for ($pro_code = 0; $pro_code <= $xx; $pro_code++) {
		             
		          		  }
					echo json_encode($pro_code);
					}

		
		
		}

	}


	
	public function add_products_mold(){
		 check_login();
		$id = $this->uri->segment('3');
		if($this->input->post())
			{
				$result=$this->Master_list->add_product_mold($_POST);
			
				if($result){$products=array('status'=>'true');}else{$products=array('status'=>'false');}
				echo json_encode($products);

			}else{
					$data['molds']=$this->System->get_molds();
					$data['get_pro_molds']=$this->Master_list->get_pro_molds($id);
	          		$this->load->view('masterlist/product_mould',$data);
			}

		}

		
		public function product_delete_mold($id)
			{
		 check_login();
	
			$result=$this->Master_list->product_delete_mold($id);
	
			if($result){$product=array('status'=>'true');}else{$product=array('status'=>'false');}
			echo json_encode($product);
		
			}

	public function material_code(){
		  check_login();
		if($this->input->post())
			{
				$id = $this->input->post('id');
					if($id == 1){
					$data['material_code']=$this->Master_list->get_counter_number_raw();
					$xx = $data['material_code'][0]['material_code'];
		             
		            for ($material_code = 0; $material_code <= $xx; $material_code++) {
		             
		            }
					echo json_encode($material_code);

				}else if($id == 2){

					$data['material_code']=$this->Master_list->get_counter_packing();
					$xx = $data['material_code'][0]['material_code'];
		             
		            for ($material_code = 0; $material_code <= $xx; $material_code++) {
		             
		             }
					 echo json_encode($material_code);
					 }
					}
				}

	public function delete_product($id)
	{
		 check_login();
	
			$result=$this->Master_list->delete_product($id);
	
			if($result){$product=array('status'=>'true');}else{$product=array('status'=>'false');}
			echo json_encode($product);
		
	}

	
	public function product_delete_parameter($id)
	{
		 check_login();
	
			$result=$this->Master_list->product_delete_parameter($id);
	
			if($result){$product=array('status'=>'true');}else{$product=array('status'=>'false');}
			echo json_encode($product);
		
	}

	public function edit_get_products($id)
	{
		 check_login();

	    
		if($this->input->post())
		{
			 
			$result=$this->Master_list->update_products($id);
			
			if($result){$products=array('status'=>'true');}else{$products=array('status'=>'false');}
			echo json_encode($products);
		}else{
					$data['get_products']=$this->Master_list->get_products();

					$data['get_products_data']=$this->Master_list->get_product_data($id);
	      			$data['get_pro_type']=$this->Master_list->get_pro_type();
	          		$this->load->view('masterlist/edit_product',$data);
	      }
				
	}


	public function boms()
	{
		check_login();
		
		$data['get_products']=$this->Master_list->get_products();
		$data['get_bom_count_products']=$this->Master_list->get_bom_count_products();
		
		$this->load->view('masterlist/boms',$data);
	}


	

	public function delete_dom_data($id)
	{
		 check_login();
	
			$result=$this->Master_list->delete_dom_data($id);
	
			if($result){$product=array('status'=>'true');}else{$product=array('status'=>'false');}
			echo json_encode($product);
		
				
	}

	public function boms_details()
	{
		check_login();
		$id = $this->uri->segment('3');
		if($this->input->post())
		{
			 $param = $this->input->post('id');
 			$data = $this->Master_list->get_products_data($param);
			
			//print_r($data);
			echo json_encode($data);
		}else{
			
			$data['get_units']=$this->Master_list->get_units();
			$data['get_bom_data']=$this->Master_list->get_bom_data($id);
			$data['get_bom_data_paking_material']=$this->Master_list->get_bom_data_packing_material($id);
			
			$data['get_products']=$this->Master_list->get_products();
			//echo  $data['get_bom_data']; exit;
			$this->load->view('masterlist/boms_details',$data);
		}
		
	}


	public function boms_details_child()
	{
		check_login();
		$id = $this->uri->segment('3');
		if($this->input->post())
		{
			 $param = $this->input->post('id');
 			$data = $this->Master_list->get_products_data_child($param);
			
			//print_r($data);
			echo json_encode($data);
		}else{
			
			$data['get_units']=$this->Master_list->get_units();
			$data['get_bom_data_child']=$this->Master_list->get_bom_data_child($id);
			
			$data['get_materials']=$this->Master_list->get_materials();
			$data['get_products']=$this->Master_list->get_products();
			//echo  $data['get_bom_data']; exit;
			$this->load->view('masterlist/bom_details_child',$data);
		}
		
	}


	public function boms_details_add()
	{
		check_login();
		
		if($this->input->post()){

	           $result = $this->Master_list->boms_details_add($_POST);
	        if($result){$add_boms_details_add=array('status'=>'true');}else{$add_boms_details_add=array('status'=>'false');}
	            echo json_encode($add_boms_details_add);
	      }
		
	}

		public function boms_details_add_child()
	{
		check_login();
		
		if($this->input->post()){

			$main_product = $this->input->post('main_product');
			$product_id = $this->input->post('product_id');
			$child_product = $this->input->post('child_product');
			$weight = $this->input->post('weight');
			$unit = $this->input->post('unit');
			$created = $this->input->post('created');
			$modified = $this->input->post('modified');
			$arrayName = array('main_product' => $main_product,'product_id' => $product_id,'child_product' => $child_product,'weight' => $weight,'unit' => $unit,'created' => $created,'modified' => $modified);

	           $result = $this->Master_list->boms_details_add_child($arrayName);
	        if($result){$add_boms_details_add_child=array('status'=>'true');}else{$add_boms_details_add_child=array('status'=>'false');}
	            echo json_encode($add_boms_details_add_child);
	      }
		
	}

	public function boms_details_add_materials()
	{
		check_login();
		
		if($this->input->post()){

	           $result = $this->Master_list->boms_details_add_materials($_POST);
	        if($result){$add_boms_details_add=array('status'=>'true');}else{$add_boms_details_add=array('status'=>'false');}
	            echo json_encode($add_boms_details_add);
	      }
		
	}
	
	



	public function bom_delete($id)
	{
		 check_login();

		// if($this->input->post()){
		
			$result=$this->Master_list->bom_delete($id);
	
			echo $result;
			exit;
	//	}
				
	}


	public function bom_delete_material($id)
	{
		 check_login();

		
			$result=$this->Master_list->bom_delete_material($id);
	
			if($result){$material=array('status'=>'true');}else{$material=array('status'=>'false');}
			echo json_encode($material);
		
				
	}


	
	
	public function boms_details_materials()
	{
		check_login();
		$main = $this->uri->segment('4');
		$pro = $this->uri->segment('3');
		if($this->input->post())
		{
			 $param = $this->input->post('id');
 			$data = $this->Master_list->get_materials_data($param);
			
			//print_r($data);
			echo json_encode($data);
		}else{
			
			$data['get_units']=$this->Master_list->get_units();
			$data['get_bom_data']=$this->Master_list->get_bom_data_materials($pro);
			$data['get_bom_data_materials_pro']=$this->Master_list->get_bom_data_materials_pro($pro,$main);
			$data['get_bom_data_child']=$this->Master_list->get_bom_data_child($pro,$main);

			$data['get_materials']=$this->Master_list->get_materials();
			$data['get_products']=$this->Master_list->get_products();
			//echo  $data['get_bom_data']; exit;
			$this->load->view('masterlist/boms_details_materials',$data);
		}
		
	}

	public function view_design_pro_mat(){

			check_login();
			if($this->input->post())
			{
					$data['segment']=$this->input->post('segment');
					$data['main_product']=$this->input->post('main_product');
					$data['id'] = $this->input->post('id');
					$data['get_units']=$this->Master_list->get_units();
					$data['get_materials']=$this->Master_list->get_materials();
					$data['get_products']=$this->Master_list->get_products();

					echo json_encode (array('html'=>$this->load->view('masterlist/get_material_design',$data,true)));

				
				}	
			}


			public function view_design_pro_mat_packing(){

			check_login();
			if($this->input->post())
			{
					
					$data['main_product']=$this->input->post('main_product');
					
					$data['id'] = $this->input->post('id');
					$data['get_units']=$this->Master_list->get_units();
					$data['get_materials']=$this->Master_list->get_materials();
					$data['get_products']=$this->Master_list->get_products();

					echo json_encode (array('html'=>$this->load->view('masterlist/get_material_design_packing',$data,true)));

				
				}	
			}






	public function logout()
	{
		check_login();
		$this->session->sess_destroy();
		redirect(base_url(),'refresh'); 
	}

	
}
