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

	public function dashboard()
	{
		check_login();
	$data['materials']=$this->System->count_materials();
		$data['count_vendor']=$this->System->count_vendor();
		$data['count_parties']=$this->System->count_parties();
		$data['products']=$this->System->count_products();
		$data['molds']=$this->System->count_molds();
		$data['machines']=$this->System->count_machines();
		$data['get_po']=$this->Orders->get_all_po();
		$data['all_requisition']=$this->Requisitions->all_requisition();
		$data['get_po1']=$this->Sales_Orders->get_all_po();
		$data['all_requisition_pro'] =$this->Requisitions->all_requisition_pro();
		$today_date = date('Y-m-d');
		$data['compound_production'] =$this->System->today_compound_production($today_date);
		$data['po_today'] =$this->System->po_today($today_date);
		$data['so_today'] =$this->System->so_today($today_date);
		$data['semi_production'] =$this->System->semi_production($today_date);
		$data['finish_production'] =$this->System->finish_production($today_date);
		$data['get_delivery_challan']=$this->Sales_Orders->get_all_po_dashboard($today_date);
		$data['check_timing']=$this->System->check_timing_data($today_date);
		$data['randomly_check_qc']=$this->System->randomly_check_qc($today_date);
		$data['get_all_confirm_so']=$this->Sales_Orders->get_all_confirm_so_active_admin();

				$currentYear = date('Y');
				$year=array(1,2,3,4,5,6,7,8,9,10,11,12);
				$leasecount=array();
				$lcount=array();
				foreach ($year as $month){
					//$this->db->get_where('lease',array('MONTH(cmtdate)'=>$month))->result_array();
					$mcount = count($this->db->get_where('sales_order',array('MONTH(so_date)'=>$month,'status'=>1, 'YEAR(so_date)'=>$currentYear))->result_array());
					array_push($leasecount, $mcount);
				}
				foreach ($leasecount as $count){
					array_push($lcount,$count);
				}


				$data['leasecount']= json_encode($lcount);



				$currentYear1 = date('Y');
				$year1=array(1,2,3,4,5,6,7,8,9,10,11,12);
				$leasecount1=array();
				$lcount1=array();
				foreach ($year1 as $month1){
					//$this->db->get_where('lease',array('MONTH(cmtdate)'=>$month))->result_array();
					$mcount1 = count($this->db->get_where('purchase_order',array('MONTH(po_date)'=>$month1,'status'=>1, 'YEAR(po_date)'=>$currentYear1))->result_array());
					array_push($leasecount1, $mcount1);
				}
				foreach ($leasecount1 as $count1){
					array_push($lcount1,$count1);
				}

				$data['leasecount1']= json_encode($lcount1);

		$this->load->view('dashboard',$data);
	}



	public function dashboard1()
	{
		check_login();
	$data['materials']=$this->System->count_materials();
		$data['count_vendor']=$this->System->count_vendor();
		$data['count_parties']=$this->System->count_parties();
		$data['products']=$this->System->count_products();
		$data['molds']=$this->System->count_molds();
		$data['machines']=$this->System->count_machines();
		$data['get_all_confirm_so']=$this->Sales_Orders->get_all_confirm_so_active();
        $data['packing_fg_line']=$this->Stocks->packing_fg_line();
		
				$currentYear = date('Y');
				$year=array(1,2,3,4,5,6,7,8,9,10,11,12);
				$leasecount=array();
				$lcount=array();
				foreach ($year as $month){
					//$this->db->get_where('lease',array('MONTH(cmtdate)'=>$month))->result_array();
					$mcount = count($this->db->get_where('sales_order',array('MONTH(so_date)'=>$month,'status'=>1, 'YEAR(so_date)'=>$currentYear))->result_array());
					array_push($leasecount, $mcount);
				}
				foreach ($leasecount as $count){
					array_push($lcount,$count);
				}


				$data['leasecount']= json_encode($lcount);



				$currentYear1 = date('Y');
				$year1=array(1,2,3,4,5,6,7,8,9,10,11,12);
				$leasecount1=array();
				$lcount1=array();
				foreach ($year1 as $month1){
					//$this->db->get_where('lease',array('MONTH(cmtdate)'=>$month))->result_array();
					$mcount1 = count($this->db->get_where('purchase_order',array('MONTH(po_date)'=>$month1,'status'=>1, 'YEAR(po_date)'=>$currentYear1))->result_array());
					array_push($leasecount1, $mcount1);
				}
				foreach ($leasecount1 as $count1){
					array_push($lcount1,$count1);
				}

				$data['leasecount1']= json_encode($lcount1);

		$this->load->view('dashboard1',$data);
	}


	public function products()
	{
		check_login();
		
		
		$this->load->view('system/products');
	}
	
	
  public function daily_work_sheet()
	{
		check_login();
			$id = $this->uri->segment('3'); 
			if($this->input->post())
			{

			 $result = $this->System->add_daily_sheet($_POST);
	        if($result){$add_Sheet=array('status'=>'true');}else{$add_Sheet=array('status'=>'false');}
	            echo json_encode($add_Sheet);	

			}else{
		    $data['get_depart']=$this->System->get_depart();
	      	$data['empolyee']=$this->System->get_empolyee();
	      	$data['get_daily_sheet']=$this->System->get_daily_sheet($id);
			$this->load->view('system/daily_work_sheet',$data);
		}
	}




	public function update_daily_sheet_data($idemp){
		check_login();

	   // $ids = $this->uri->segment('3');
		if($this->input->post())
		{

			

			$result=$this->System->update_daily_sheet_emp($idemp);
			
			if($result){$res=array('status'=>'true');}else{$res=array('status'=>'false');}
			echo json_encode($res);
		}else{

					$data['get_emp_dailysheet']=$this->System->get_emp_dailysheet($idemp);
					
	          		$this->load->view('system/update_daily_sheet_data',$data);
	      }


	}

	

	public function reset_pass(){
		check_login();

	   // $ids = $this->uri->segment('3');
		if($this->input->post())
		{

			$password = $this->input->post('password');
			$n_password = $this->input->post('n_password');
			$c_password = $this->input->post('c_password');

			$user = $this->session->userdata('id');

			$result=$this->System->check_password($user,$password);

			if($result ==""){

			$res=array('status'=>'false');
			echo json_encode($res);

			}else if($n_password == $c_password){



				$result=$this->System->update_password($user,$n_password);
				if($result){$res=array('status'=>'true');}else{$res=array('status'=>'false');}
					echo json_encode($res);

			}else{

					$res=array('status'=>'false');
					echo json_encode($res);

			}

			
			
		}

	}


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

			$id = $this->input->post('empolyee_id');
			$date = $this->input->post('date');
			$enddate = $this->input->post('enddate');


			 $data['filter_data'] = $this->System->filter_daily_sheet($id,$date,$enddate);
			 
	    echo json_encode (array('html'=>$this->load->view('system/filter_daily_sheet',$data,true)));

			}else{
		  $data['empolyee']=$this->System->get_empolyee();
			$this->load->view('system/work_sheet_report',$data);
		}
	}
	
	
	
	public function get_form_ad_ot()
	{
		check_login();
			
		

			$id = $this->input->post('id');
			$data['get_emp_ad_ot']=$this->System->get_emp_ad_ot($id);
	  	  echo json_encode (array('html'=>$this->load->view('system/get_form_ad_ot',$data,true)));
	  	  //echo json_encode (array('html'=>$this->load->view('system/get_emp_all_details',$data,true)));

	}

	
	public function view_ot_advance()
	{
		check_login();
			
		

			$id = $this->input->post('id');
			$data['get_emp_ot']=$this->System->view_ot_advance($id);
	  	  echo json_encode (array('html'=>$this->load->view('system/get_form_view_ot',$data,true)));
	  	  //echo json_encode (array('html'=>$this->load->view('system/get_emp_all_details',$data,true)));

	}
	
	
	
	public function delete_daily_sheet($id){

			check_login();
	
			$result=$this->System->delete_daily_sheet($id);
	
			if($result){$empolyee=array('status'=>'true');}else{$empolyee=array('status'=>'false');}
			echo json_encode($empolyee);

	}

	

	public function delete_fg_set($id){

		check_login();

		$result=$this->System->delete_fg_set($id);

		if($result){$empolyee=array('status'=>'true');}else{$empolyee=array('status'=>'false');}
		echo json_encode($empolyee);

}
	
	
	public function get_empolyee_data(){

			$data['get_depart']=$this->System->get_depart();
	      	$data['empolyee']=$this->System->get_empolyee();
	      	$this->load->view('system/get_empolyee_list',$data);
	}


	public function get_empolyees_data(){
		check_login();
		if($this->input->post())
			{
			$id = $this->input->post('empolyee');
			$data = $this->System->get_empolyees_data($id);
			
			echo json_encode ($data);
		}
	}


	public function profile()
	{
		check_login();
		
		
		$this->load->view('system/profile');
	}


	public function machine()
	{
		check_login();
		
		if($this->input->post()){
	     	
	            $result = $this->System->add_machine($_POST);
	        	if($result){$add_machine=array('status'=>'true');}else{$add_machine=array('status'=>'false');}
	            echo json_encode($add_machine);
	      }else{
	      		$data['get_vendors']=$this->System->get_vendors();
	      		$data['get_machine']=$this->System->get_machine();
	      		$code['code'] = $this->System->get_code();
	      		$xx = $code['code'][0]['code'];
	      		for ($machine_code = 0; $machine_code <= $xx; $machine_code++) {
		             
		            }
	      		$data['codes'] = $machine_code;
				$this->load->view('system/machine',$data);
	      }
	}

	

	public function other_machine()
	{
		check_login();
		
		if($this->input->post()){
	     	
	            $result = $this->System->add_other_machine($_POST);
	        	if($result){$add_machine=array('status'=>'true');}else{$add_machine=array('status'=>'false');}
	            echo json_encode($add_machine);
	      }else{
	      		$data['get_vendors']=$this->System->get_vendors();
	      		$data['other_machine']=$this->System->other_machine();
	      		$code['code'] = $this->System->other_get_code();
	      		$xx = $code['code'][0]['code'];
	      		for ($machine_code = 0; $machine_code <= $xx; $machine_code++) {
		             
		            }
	      		$data['codes'] = $machine_code;
				$this->load->view('system/other_machine',$data);
	      }
	}

	

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

		if($this->input->post()){
	     	
	            $result = $this->System->add_other_machine($_POST);
	        	if($result){$add_machine=array('status'=>'true');}else{$add_machine=array('status'=>'false');}
	            echo json_encode($add_machine);
	      }else{
	      		$data['get_vendors']=$this->System->get_vendors();
	      		$data['other_machine']=$this->System->other_machine_get($id);
	      		
				$this->load->view('system/edit_othermachine',$data);
	      }
	}


	public function add_description()
	{
		check_login();
		
		if($this->input->post()){
	     	
	            $result = $this->System->add_description($_POST);
	        	if($result){$add_description=array('status'=>'true');}else{$add_description=array('status'=>'false');}
	            echo json_encode($add_description);
	      }else{
	      		$data['get_data']=$this->System->get_descriptions();

	      		$data['get_fg_pro']=$this->System->get_fg_pro();
	      		
				$this->load->view('system/add_description',$data);
	      }
	}


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

	   
		if($this->input->post())
		{

			$result=$this->System->update_descriptione($id);
	
			if($result){$machine=array('status'=>'true');}else{$machine=array('status'=>'false');}
			echo json_encode($machine);
		}else{
				
				$data['get_data_edit']=$this->System->edit_get_descriptions($id);
				
				$data['get_data']=$this->System->get_descriptions();
	      		$data['get_fg_pro']=$this->System->get_fg_pro();
	           $this->load->view('system/edit_description',$data);
	      }
				
	}

	

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

	   
		if($this->input->post())
		{

			$result=$this->System->update_other_machine($id);
	
			if($result){$machine=array('status'=>'true');}else{$machine=array('status'=>'false');}
			echo json_encode($machine);
		}
				
	}

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

	   
		if($this->input->post())
		{
			
			$result=$this->System->update_machine($id);
	
			if($result){$machine=array('status'=>'true');}else{$machine=array('status'=>'false');}
			echo json_encode($machine);
		}else{
				$data['get_vendors']=$this->System->get_vendors();
	      		$data['get_machine']=$this->System->get_machine_data($id);
	           $this->load->view('system/edit_machine',$data);
	      }
				
	}


	

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

	   
		if($this->input->post())
		{
			
			$result=$this->System->update_assembled_line_area($id);
	
			if($result){$machine=array('status'=>'true');}else{$machine=array('status'=>'false');}
			echo json_encode($machine);
		}else{
				$data['get_line']=$this->System->get_line_data($id);
	           $this->load->view('stock/edit_assembled_line_area',$data);
	      }
				
	}

	
	public function view_machines_details(){

		check_login();
		
		$id = $this->uri->segment('3');

		
		$data['get_machine_data']=$this->System->get_machine_data($id);
		$this->load->view('system/view_machine_details',$data);
		//echo json_encode (array('html'=>$this->load->view('/purchase/view_po_invoice',$data,true)));
	
	}
	
	
	public function edit_get_daily_sheet($id)
	{
		 check_login();
		 $id = $this->uri->segment('3');
	   
		if($this->input->post())
		{
			
			$result=$this->System->edit_get_daily_sheet($id);
	
			if($result){$machine=array('status'=>'true');}else{$machine=array('status'=>'false');}
			echo json_encode($machine);
		}else{
				
	      		$data['edit_get_daily_sheet']=$this->System->get_daily_sheetdata($id);
	      		
	           $this->load->view('system/edit_get_daily_sheet',$data);
	      }
				
	}


public function empolyee()
	{
		
		check_login();
	    if(isset($_FILES["file"]["name"]))  
  		  {  


		 $config['upload_path'] = './assets/images/profile';  
		 $config['allowed_types'] = 'jpg|jpeg|png|gif';  
		 $this->load->library('upload', $config);  
		 if(!$this->upload->do_upload('file'))  
		 {  
		 	//die;
		 	 $data = array('upload_data' => $this->upload->data());
		 
		            $fullname = $this->input->post('fullname');
			        $phone = $this->input->post('phone');
			        $nic = $this->input->post('nic');
			        $depart = $this->input->post('depart');
			        $designation = $this->input->post('designation');
			        $salary = $this->input->post('salary');
			         $over_time = $this->input->post('over_time');
			          $allowance = $this->input->post('allowance');
			        $tap_in = $this->input->post('tap_in');
			        $tap_out = $this->input->post('tap_out');
			        $email = $this->input->post('email');
			        $address = $this->input->post('address');
			        $comments = $this->input->post('comments');
			        $image= $data['upload_data']['file_name']; 
			        $user_id = $this->input->post('user_id');
			        $created = $this->input->post('created');
			        $modified = $this->input->post('modified');
			        //$new_tapin = date('h:i:s A', strtotime($tap_in));
			        //$new_tapout = date('h:i:s A', strtotime($tap_out));
			       	
			       	$dateTime = new DateTime('now', new DateTimeZone('Asia/Karachi')); 
					 //$data['time'] = $dateTime->format("h:i:s A"); 
				     //$data['desig'] = $result[0]['designation'];
				  	//return json_encode ($data);
					$new_tapin = $dateTime->format("h:i:s A"); 
					$new_tapout = $dateTime->format("h:i:s A"); 

			       
					 $result = $this->System->add_empolyee($fullname,$phone,$nic,$depart,$designation,$salary,$new_tapin,$new_tapout,$over_time,$allowance,$email,$address,$comments,$image,$user_id,$created,$modified);
		
				 if($result){$add_empolyee=array('status'=>'true');}else{$add_empolyee=array('status'=>'false');}
	            echo json_encode($add_empolyee);
		 //echo $this->upload->display_errors();  
		 }  
		 else  
		 {  
		 $data = array('upload_data' => $this->upload->data());
		 
		            $fullname = $this->input->post('fullname');
			        $phone = $this->input->post('phone');
			        $nic = $this->input->post('nic');
			        $depart = $this->input->post('depart');
			        $designation = $this->input->post('designation');
			        $salary = $this->input->post('salary');
			        $over_time = $this->input->post('over_time');
			        $email = $this->input->post('email');
			        $tap_in = $this->input->post('tap_in');
			        $tap_out = $this->input->post('tap_out');
			        $address = $this->input->post('address');
			        $comments = $this->input->post('comments');
			        $image= $data['upload_data']['file_name']; 
			        $user_id = $this->input->post('user_id');
			        $created = $this->input->post('created');
			        $modified = $this->input->post('modified');



			         //$new_tapin = date('h:i:s A', strtotime($tap_in));
			        //$new_tapout = date('h:i:s A', strtotime($tap_out));
			        $dateTime = new DateTime('now', new DateTimeZone('Asia/Karachi')); 
					 //$data['time'] = $dateTime->format("h:i:s A"); 
				     //$data['desig'] = $result[0]['designation'];
				  	//return json_encode ($data);
					$new_tapin = $dateTime->format("h:i:s A"); 
					$new_tapout = $dateTime->format("h:i:s A"); 


			        $result = $this->System->add_empolyee($fullname,$phone,$nic,$depart,$designation,$salary,$new_tapin,$new_tapout,$over_time,$email,$address,$comments,$image,$user_id,$created,$modified);
		
				 if($result){$add_empolyee=array('status'=>'true');}else{$add_empolyee=array('status'=>'false');}
	            echo json_encode($add_empolyee);
		 
		 }  
	       
	      }else{
	      	$data['get_depart']=$this->System->get_depart();
	      	$data['empolyee']=$this->System->get_empolyee();
	         $this->load->view('system/empolyees',$data);
	      }
		
		
		
	}	

	

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

	   
		if($this->input->post())
		{

					$fullname = $this->input->post('fullname');
			        $phone = $this->input->post('phone');
			        $nic = $this->input->post('nic');
			        $fnic = $this->input->post('fnic');
			        $depart = $this->input->post('depart');
			        $designation = $this->input->post('designation');
			        $email = $this->input->post('email');
			        $salary = $this->input->post('salary');
			        $over_time = $this->input->post('over_time');
			        $allowance = $this->input->post('allowance');
			        $tap_in = $this->input->post('tap_in');
			        $tap_out = $this->input->post('tap_out');
			        $address = $this->input->post('address');
			        $comments = $this->input->post('comments');
			        $user_id = $this->input->post('user_id');
			        //$image= $data['upload_data']['file_name']; 
			        $status  = $this->input->post('status');
			        $created = $this->input->post('created');
			        $modified = $this->input->post('modified');

			         //$new_tapin = date('h:i:s A', strtotime($tap_in));
			        //$new_tapout = date('h:i:s A', strtotime($tap_out));
			        //$dateTime = new DateTime('now', new DateTimeZone('Asia/Karachi')); 
					 //$data['time'] = $dateTime->format("h:i:s A"); 
				     //$data['desig'] = $result[0]['designation'];
				  	//return json_encode ($data);
					//$new_tapin = $tap_in->format("h:i:s A");
					$new_tapin = date('h:i:s A', strtotime($tap_in));
					$new_tapout = date('h:i:s A', strtotime($tap_out));
					//$new_tapout = $tap_out->format("h:i:s A"); 

					$arrayName = array('fullname' =>$fullname ,
										'phone' =>$phone ,
										'nic' =>$nic ,
										'fnic' =>$fnic,
										'depart' =>$depart ,
										'designation' =>$designation ,
										'salary' =>$salary,
										'tap_in' =>$new_tapin,
										'tap_out' =>$new_tapout,
										'over_time'=>$over_time,
										'allowance'=>$allowance,
										'email'=>$email,
										'address'=>$address,
										'comments'=>$comments,
										'created'=>$created,
										'modified'=>$modified,
										'status' =>$status
										
									 );
			
			$result=$this->System->edit_get_empolyee($id,$arrayName);
	
			if($result){$empolyee=array('status'=>'true');}else{$empolyee=array('status'=>'false');}
			echo json_encode($empolyee);
		}else{
				//$data['nature']=$this->System->get_bus_nature();
	      		$data['get_emp']=$this->System->get_empolyee_data($id);
	      		$data['get_depart']=$this->System->get_depart();
	           $this->load->view('system/edit_get_empolyee',$data);
	      }
				
	}

	

	public function view_emp_details(){

		check_login();
		
		$id=$this->input->post('id');
		$data['get_emp_all']=$this->System->get_empolyee_data($id);
		
		echo json_encode (array('html'=>$this->load->view('system/get_emp_all_details',$data,true)));
	
	}
	
	
	public function view_tap_out_details(){

		check_login();
		
		$id=$this->input->post('id');
		$data['get_emp_all']=$this->System->get_tap_data($id);
		
		echo json_encode (array('html'=>$this->load->view('system/tap_out_form',$data,true)));
		//print_r($aa);
		//}
	//
	//$this->load->view('sales/view_boms_details',$data);
		     
	

		
	}
	
	
	public function tap_out_attendance($id)
	{
		 check_login();

		

		 //$emp_id = $this->input->post('emp_id');
		 $tap_out = $this->input->post('tap_out');
		 $date_out = $this->input->post('date_out');
		 $date_in = $this->input->post('date_out');
		 $dateTime = new DateTime('now', new DateTimeZone('Asia/Karachi'));
			
				$newTime_out = date('h:i:s A', strtotime($tap_out));


		 $data1_save1 = array(
			    'date_out'=>$date_out,
			    'tap_out'=>$newTime_out,
			    'status'=>2
			    );

				$result = $this->System->update_tapout_attendance($id,$date_in,$data1_save1);
	        	if($result){$add_fg_rates=array('status'=>'true');}else{$add_fg_rates=array('status'=>'false');}
	            echo json_encode($add_fg_rates);

		}

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

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

	     	 
	     	
	           $result = $this->System->add_party($_POST);
	        if($result){$add_party=array('status'=>'true');}else{$add_party=array('status'=>'false');}
	            echo json_encode($add_party);
	      }else{
	      		$data['nature']=$this->System->get_bus_nature();
	      		$data['parties']=$this->System->get_party();
	      		$code['code'] = $this->System->get_code_party();
	      		$xx = $code['code'][0]['party_code'];
	      		for ($code = 0; $code <= $xx; $code++) {
		             
		            }
	      	   $data['code'] = $code;
	           $this->load->view('system/company',$data);
	      }	
	}

	public function banks()
	{
		 check_login();
	     if($this->input->post()){
	           $result = $this->System->add_bank($_POST);
	        if($result){$add_party=array('status'=>'true');}else{$add_party=array('status'=>'false');}
	            echo json_encode($add_party);
	      }else{
	      		
			$data['banks']=$this->System->allbanks();
	           $this->load->view('system/banks',$data);
	      }
	}

	public function edit_parties($p_id)
	{
		 check_login();

	   
		if($this->input->post())
		{
			
			$result=$this->System->update_parties($p_id);
	
			if($result){$party=array('status'=>'true');}else{$party=array('status'=>'false');}
			echo json_encode($party);
		}else{
				$data['nature']=$this->System->get_bus_nature();
	      		$data['get_parties']=$this->System->get_party_data($p_id);
	           $this->load->view('system/edit_parties',$data);
	      }
				
	}


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

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

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

	public function department()
	{
		
		check_login();
	     if($this->input->post()){
	     	
	           $result = $this->System->add_depart($_POST);
	        if($result){$add_depart=array('status'=>'true');}else{$add_depart=array('status'=>'false');}
	            echo json_encode($add_depart);
	      }else{
	      		$data['depart']=$this->System->get_depart();
	      		//$data['parties']=$this->System->get_party();
	           $this->load->view('system/department',$data);
	      }
		
		
	}
	
	
	public function daily_work_add_ad_ot()
	{
		
		check_login();
	     if($this->input->post()){
	     	
	           $result = $this->System->add_daily_work_add_ad_ot($_POST);
	        if($result){$add_ot_ad=array('status'=>'true');}else{$add_ot_ad=array('status'=>'false');}
	            echo json_encode($add_ot_ad);
	      }
		
		
	}
	
	
public function add_attendance()
	{
		check_login();
		
		if($this->input->post()){
				
				$emp_id = $this->input->post('emp_id');
				$date = $this->input->post('date');
				$date_out = $this->input->post('date_out');
				$tap_in = $this->input->post('tap_in');
				$tap_out = $this->input->post('tap_out');
				$status = $this->input->post('status');
				$remarks = $this->input->post('remarks');

				$atten_check = $this->System->atten_check($emp_id,$date);

				
				if($atten_check ==""){
				$dateTime = new DateTime('now', new DateTimeZone('Asia/Karachi'));
				//$time = $dateTime->format("h:i:s A");
				$newTime = date('h:i:s A', strtotime($tap_in));

				$newTime_out = date('h:i:s A', strtotime($tap_out));


				$data_save = array(
				'emp_id' => $emp_id,
			    'date'=>$date,
			     'date_out'=>$date_out,
			    'tap_in'=>$newTime,
			     'tap_out'=>$newTime_out,
			      'status'=>2,
			    	'remarks'=>$remarks
			    );
				
	            $result = $this->System->add_attendance($data_save);
	        	if($result){$add_fg_rates=array('status'=>'true');}else{$add_fg_rates=array('status'=>'false');}
	            echo json_encode($add_fg_rates);

				}else{

						
						$add_fg_rates=array('status'=>'false');
	            			echo json_encode($add_fg_rates);
				}

				
	      }else{
	      		/*$data['get_fg_pro']=$this->System->get_fg_pro();
	      		$data['parties']=$this->System->get_party();
	      		$data['all_fg_rates']=$this->System->all_fg_rates();*/
	    		
				$this->load->view('system/add_attendance');
	      }
	}


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


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

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

					$data['get_depart_data']=$this->System->get_depart_data($id);
	      			//$data['get_pro_type']=$this->Master_list->get_pro_type();
	          		$this->load->view('System/edit_get_department',$data);
	      }
				
	}


	


	public function vendors()
	{
		 check_login();
	     if($this->input->post()){
	     	
	           $result = $this->System->add_vendor($_POST);
	        if($result){$add_vendor=array('status'=>'true');}else{$add_vendor=array('status'=>'false');}
	            echo json_encode($add_vendor);
	      }else{
	      	$data['get_vendors']=$this->System->get_vendors();
	      	 $data['vendor_type']=$this->System->vendor_type();
	         $this->load->view('system/vendors',$data);
	      }
		
	}

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


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

	    // $id = $this->uri->segment('3');
		if($this->input->post())
		{
			
			$result=$this->System->update_vendor($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_vendor_data']=$this->System->get_vendor_data($id);
	     		 	//$data['get_units']=$this->Master_list->get_units();
	     		 	$data['vendor_type']=$this->System->vendor_type($id);
	          		$this->load->view('system/vendors_edit',$data);
	      }
				
	}
	


	public function mold()
	{

			check_login();
		if(isset($_FILES["file"]["name"]))  
    {  
		 $config['upload_path'] = './assets/images/molds';  
		 $config['allowed_types'] = 'jpg|jpeg|png|gif';  
		 $this->load->library('upload', $config);  
		 if(!$this->upload->do_upload('file'))  
		 {  

		 	 $data = array('upload_data' => $this->upload->data());
		 
		 	        $code = $this->input->post('code');
			        $product_id = $this->input->post('product_id');
			        $manufacture = $this->input->post('manufacture');
			        $mfg_date = $this->input->post('mfg_date');
			        $cavity = $this->input->post('cavity');
			        $cycle_time = $this->input->post('cycle_time');
			        $cost = $this->input->post('cost');
			        $self_life = $this->input->post('self_life');
			        $self_life_start = $this->input->post('self_life_start');
			        
			        $self_life_remain = $this->input->post('self_life_remain');
			         $machine_type = $this->input->post('machine_type');
			        //$qc_specs = $this->input->post('qc_specs');
			        $image= $data['upload_data']['file_name']; 
			        $created = $this->input->post('created');
			        $modified = $this->input->post('modified');
			          
					 $result = $this->System->add_mold($code,$product_id,$manufacture,$mfg_date,$cavity,$cycle_time,$cost,$self_life,$self_life_start,$self_life_remain,$machine_type,$image,$created,$modified);
		
				 if($result){$add_mold=array('status'=>'true');}else{$add_mold=array('status'=>'false');}
	            echo json_encode($add_mold);
		 //echo $this->upload->display_errors();  
		 }  
		 else  
		 {  
		 $data = array('upload_data' => $this->upload->data());
		 
		 
		 

			        $code = $this->input->post('code');
			        $product_id = $this->input->post('product_id');
			        $manufacture = $this->input->post('manufacture');
			        $mfg_date = $this->input->post('mfg_date');
			        $cavity = $this->input->post('cavity');
			        $cycle_time = $this->input->post('cycle_time');
			        $cost = $this->input->post('cost');
			        $self_life = $this->input->post('self_life');
			        $self_life_start = $this->input->post('self_life_start');
			        
			        $self_life_remain = $this->input->post('self_life_remain');
			        $machine_id = $this->input->post('machine_id');
			        $image= $data['upload_data']['file_name']; 
			        $created = $this->input->post('created');
			        $modified = $this->input->post('modified');
			          
					 $result = $this->System->add_mold($code,$product_id,$manufacture,$mfg_date,$cavity,$cycle_time,$cost,$self_life,$self_life_start,$self_life_remain,$machine_id,$image,$created,$modified);
		
				 if($result){$add_mold=array('status'=>'true');}else{$add_mold=array('status'=>'false');}
	            echo json_encode($add_mold); 
		 }  
	       
	      }else{
	      	
	      	$data['code']=$this->System->get_counter_number_molds();
					$xx = $data['code'][0]['code'];
		             
		            for ($code = 0; $code <= $xx; $code++) {
		             
		            }
		            $data['code_mold'] = $code;
	      	  		$data['molds']=$this->System->get_molds();
	      	  		$data['get_machine']=$this->System->get_machine();
	      	  		$data['get_products']=$this->Master_list->get_products_mold();
	          		$this->load->view('system/mold',$data);
	      }
		
		
	}


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

		   // $id = $this->uri->segment('3');
		if($this->input->post())
		{

		$result=$this->System->update_molds($id);

		if($result){$molds=array('status'=>'true');}else{$molds=array('status'=>'false');}
		echo json_encode($molds);
		}else{
		//$data['get_pro_type']=$this->Master_list->get_pro_type();
		      		$data['get_mold_data']=$this->System->get_mold_data($id);
		    //$data['get_units']=$this->Master_list->get_units();
		    		$data['get_products']=$this->Master_list->get_products_mold();
		    		$data['get_machine']=$this->System->get_machine();
		          $this->load->view('system/edit_get_mold',$data);
		     }

		}



	public function qc_machine()
	{
	check_login();


	$this->load->view('qc_machine');
	}

	public function qc_machine_SH06()
	{
	check_login();

	$data = $this->input->post('data');

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


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


	public function fg_rates()
	{
		check_login();
		
		if($this->input->post()){
	     	$product = $this->input->post('product');
			$code = $this->input->post('ref_code');
			$party = $this->input->post('party'); 
			$condition  = $this->System->check_fg_condition($product,$code,$party);
			if($condition == 1){
				print_r($condition);
				die;
				echo json_encode($condition);				
			}else{
				die;
	            $result = $this->System->add_fg_rates($_POST);
	        	if($result){$add_fg_rates=array('status'=>'true');}else{$add_fg_rates=array('status'=>'false');}
	            echo json_encode($add_fg_rates);
			}
	      }else{
	      		$data['get_fg_pro']=$this->System->get_fg_for_fg_rates();
	      		$data['parties']=$this->System->get_party();
	      		$data['all_fg_rates']=$this->System->all_fg_rates();
	    		
				$this->load->view('system/fg_rates',$data);
	      }
	}

	

	public function fg_rates_log($id)
	{
		check_login();
		
		
	    $data['all_fg_rates']=$this->System->all_fg_rates_logs($id);
	    $this->load->view('system/fg_rates_log',$data);
	      
	}
	


	public function po_rates()
	{
		check_login();
		
		if($this->input->post()){
	     	
	            $result = $this->System->add_po_rates($_POST);
	        	if($result){$add_fg_rates=array('status'=>'true');}else{$add_fg_rates=array('status'=>'false');}
	            echo json_encode($add_fg_rates);
	      }else{
	      		$data['get_pro']=$this->System->get_pro_porates();
	      		//$data['parties']=$this->System->get_party();
	      		$data['all_rates']=$this->System->all_rates();
	    		
				$this->load->view('system/po_rates',$data);
	      }
	}


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



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

	

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

		   // $id = $this->uri->segment('3');
		if($this->input->post())
		{

		$result=$this->System->update_edit_all_fg_ratess($id);

		if($result){$fgrates=array('status'=>'true');}else{$fgrates=array('status'=>'false');}
		echo json_encode($fgrates);
		}else{
		
		       // $data['get_fg_pro']=$this->System->get_fg_pro();
	      		$data['parties']=$this->System->get_party();
	      		$data['get_edit_fg_rates']=$this->System->get_edit_fg_rates($id);
		   	       $data['get_fg_pro']=$this->System->get_pro_fg_edit();
		          $this->load->view('system/edit_all_fg_ratess',$data);
		     }

		}


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

		   // $id = $this->uri->segment('3');
		if($this->input->post())
		{

		$result=$this->System->update_edit_all_ratess($id);

		if($result){$fgrates=array('status'=>'true');}else{$fgrates=array('status'=>'false');}
		echo json_encode($fgrates);
		}else{
		
		        $data['get_pro']=$this->System->get_pro();
	      		
	      		$data['get_edit_rates']=$this->System->get_edit_rates($id);
		   
		          $this->load->view('system/edit_all_ratess',$data);
		     }

		}



		public function qc_parameter()
	{
		check_login();
		$id = $this->uri->segment('3');
		
		$ref=$this->System->check_ref($id);
			//print_r($ref[0]['mold_id']);
			//die;
		if($this->input->post()){
			
				  $ref_no = $this->input->post('ref_no');
			      $mold_id = $this->input->post('mold_id');
				  $user_id = $this->input->post('user_id');
			      $created = $this->input->post('created');
				  $modified = $this->input->post('modified');
				  $sno_num = $this->input->post('sno_num');
				  $descrip = $this->input->post('descrip');
				  $max = $this->input->post('max_range');
				  $min = $this->input->post('min_range');
				  $parameters = $this->input->post('parameters');
				  $type = $this->input->post('type');
				  $units = $this->input->post('units');
				 	if(@$ref[0]['mold_id'] == '' && $ref_no != NULL)
	     			{ 
	     				$result = $this->System->add_parameter($mold_id,$type,$sno_num,$descrip,$parameters,$max,$min,$units,$user_id,$created,$modified);
	           			$result = $this->System->add_ref($mold_id,$ref_no,$user_id,$created,$modified);
	     			}else if($ref_no == NULL){
	     				
	     				$result = $this->System->add_parameter($mold_id,$type,$sno_num,$descrip,$parameters,$max,$min,$units,$user_id,$created,$modified);
	     						
	     			}
	        /*if($result){$add_parameter=array('status'=>'true');}else{$add_parameter=array('status'=>'false');}
	            echo json_encode($add_parameter);
	        }else if($id != $mold && $mold == ""){
	        		print_r('2');
	        		die;
	        	  $ref_no = $this->input->post('ref_no');
			      $mold_id = $this->input->post('mold_id');
				  $user_id = $this->input->post('user_id');
			      $created = $this->input->post('created');
				  $modified = $this->input->post('modified');

				 $sno_num = $this->input->post('sno_num');
				 $descrip = $this->input->post('descrip');
				 $parameters = $this->input->post('parameters');



	        	$result = $this->System->add_parameter($mold_id,$sno_num,$descrip,$parameters,$user_id,$created,$modified);*/
	     		
	        if($result){$add_parameter=array('status'=>'true');}else{$add_parameter=array('status'=>'false');}
	            echo json_encode($add_parameter);

	       
	      }else{
	      	    
	      	    $data['get_mold_parameter']=$this->System->get_mold_parameter($id);
	         	$data['units']=$this->Master_list->get_units();
	      		$data['ref']=$this->System->check_ref($id);
	      		//print_r($data['get_mold_parameter']);
		//die;
	         $this->load->view('system/qc_parameter',$data);
	      }
		
	}

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

	
	public function delete_decription($id)
	{
		 check_login();
		// var_dump($id);
		// exit;
			$result=$this->System->delete_decription($id);
	
			if($result){$mold=array('status'=>'true');}else{$mold=array('status'=>'false');}
			echo json_encode($mold);
		
	}


	public function view_molds_details(){

		check_login();

		$id=$this->input->post('id');
		$data['get_molds_all']=$this->System->get_molds_data_all($id);
		$data['get_molds_parameter']=$this->System->get_parameter($id);

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


	

    	public function today_attendance()
		{
		check_login();

		$dates =  date('Y-m-d');

		   $data['get_depart']=$this->System->get_depart();
		      $data['empolyee']=$this->System->get_empolyee();
		      $data['get_daily_sheet']=$this->System->get_daily_sheet_today_attendance($dates);
		$this->load->view('system/today_attendance',$data);
		}

	
	/*public function add_machine_report(){

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

					    $qc_machine_id = $this->input->post('qc_machine_id');
					    $emp_id = $this->input->post('emp_id');
						$job = $this->input->post('job');
						$m_weight = $this->input->post('m_weight');
						$w_weight = $this->input->post('w_weight');
						$tp_weight = $this->input->post('tp_weight');
						$hrs = $this->input->post('hrs');
						$cost = $this->input->post('cost');
						$insert_date = $this->input->post('insert_date');
						$created = $this->input->post('created');
						$modified = $this->input->post('modified');
						$user_id = $this->input->post('user_id');
						

						$dataarray =  array(
										'qc_machine_id' => $qc_machine_id,
										'emp_id' => $emp_id,
										'job' => $job,
										'm_weight' => $m_weight,
										'w_weight' => $w_weight,
										'tp_weight'=> $tp_weight,
										'hrs'=> $hrs,
										'cost'=> $cost,
										'insert_date'=>$insert_date,
										'created'=> $created,
										'modified'=> $modified,
										'user_id'=> $user_id
										 );

			 	$result = $this->System->add_machine_report($dataarray);

			 	$result = $this->System->update_machine_qc_id($qc_machine_id);
	        	if($result){$add_fg_rates=array('status'=>'true');}else{$add_fg_rates=array('status'=>'false');}
	            echo json_encode($add_fg_rates);
				
				
			}else{

				
			  	$data['get_oprators'] = $this->System->get_oprators();
				$this->load->view('system/daily_machine_report',$data);

			}
	}*/


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

				

				}else{
					//$date = date('2022-09-22');
					//$date = date("Y-m-d");
				  	$data['get_machine_data']=$this->System->get_machine_qc_data();
				  	//$data['get_oprators'] = $this->System->get_oprators();
					$this->load->view('system/daily_machine_report_data',$data);
			}
	}

    public function attendance_view(){


		$this->load->view('attendance_view');
	}

public function staff_atten(){


   $code = $this->input->post('rfid_dec');

   $result=$this->System->code_verification($code);
   $condition = $result[0]['rf_id'];
   //print_r($condition);
   //die;
   $emp_id = $result[0]['id'];

   if($condition !=="")
   {
     $data['get_name'] = $result[0]['fullname'];
   
     $data['desig'] = $result[0]['designation'];

     $data['image'] = $result[0]['image'];

    $dateTime = new DateTime('now', new DateTimeZone('Asia/Karachi'));
			$data['time'] = $dateTime->format("h:i:s A");
			 
			$tap_in = $dateTime->format("h:i:s A");
			$date = date('Y-m-d');


			

			$condi_tap_in = $this->System->tap_in_check($emp_id,$date);
			$condi_tap_out = $this->System->tap_out_check($emp_id,$date);

			$con_date = $this->System->tap_in_date($emp_id,$date);
			$con_date_out =  $this->System->tap_out_date($emp_id,$date);


			//$new = $new_datein->date("H:i",);
			$new_tapin = date('H:i:s', strtotime(@$condi_tap_in[0]['tap_in']));
			$new_tapout = date('H:i:s', strtotime(@$condi_tap_out[0]['tap_out']));
			$now_new_tapin = date('H:i:s', strtotime($tap_in));
			
			

			  if($con_date=="" && $con_date_out=="")
			{

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

			$data_save = array('emp_id' => $emp_id,
			    'date'=>$date,
			    'tap_in'=>$tap_in,
			    'status'=>1
			    );
			 $lastid = $this->System->add_param($data_save);

			 $this->System->add_tap_in($data_save);

			}else if($con_date!="" && $con_date_out==""){



			$intap=$this->System->last_tapin($emp_id,$date);

			  $login   = $intap[0]['tap_in'];
			  $logout   = $tap_in;
			  $login1    = new DateTime($login);
			  $logout1   = new DateTime($logout);

			$interval = $logout1->diff($login1);

			$condi = $interval->format(' %i');

			if($condi >= 1){

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

			$data1_save = array('emp_id' => $emp_id,
			    'date'=>$date,
			    'tap_out'=>$tap_in,
			    'status'=>1
			    );


			$data1_save1 = array(
			    'date_out'=>$date,
			    'tap_out'=>$tap_in,
			    'status'=>2
			    );

			$datein = date('Y-m-d');
			$this->System->add_param_out($data1_save);

			$this->System->param_update($data1_save1,$emp_id,$datein);
			}else{

				$data = "<h1>Wait 1 Minutes...</h1>";
				echo json_encode (array('html'=>$data,true));
			}

			}else{

			$data1 = "<h1>Today Attendance Completed...</h1>";
			echo json_encode (array('html'=>$data1,true));
			}


			}else{

			echo "No Card";
			exit;
			}
 
			}


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

				$select_report = $this->input->post('id');
				
				if($select_report==1){
				
				$data['get_machine']=$this->System->get_machine();

				$data['get_materials']=$this->Master_list->get_materials();

				$data['get_products1']=$this->Master_list->get_products_mold();


				$data['operators']=$this->System->get_empolyee();

				echo json_encode (array('html'=>$this->load->view('system/get_summary_report_filters',$data,true)));
				}else if($select_report == 2){

					
					echo json_encode (array('html'=>$this->load->view('system/get_day_night_report_filters',$select_report,true)));

				}

		 }else{
				
			 
				$this->load->view('system/machine_filter_report');
			}
	}


	

	public function filter_summary_report() {
		
		check_login();

		if($this->input->post()) {
			/*print_r($this->input->post('array_val'));
			die;*/
			$array_val = $this->input->post('array_val');
			$array_val = str_replace("$", "'", $array_val);
			// var_dump($array_val);
			// exit;
			/*$end_date = $this->input->post('end_date');
			$material_id = $this->input->post('material_id');
			$machine_id = $this->input->post('machine_id');
			$product_id = $this->input->post('product_id');
			$empolyee_id = $this->input->post('empolyee_id');
			$job_no = $this->input->post('job_no');
			$shift = $this->input->post('shift');*/
			//$where ="";
			/*$count_array = count($this->input->post());
			print_r($this->input->post('array_val'));
			die;
			
			if($strat_date !="" ){
				$where .="insert_date >='".$strat_date."'";
			}

			if($end_date !="" ){
				if($count_array > 1){
					$where .=" AND ";	
				}
				$where .="insert_date <='".$end_date."'";
			}

			if($material_id !="" ){
				if($count_array > 1 ){
					$where .=" AND ";	
				}
				$where .="material_id ='".$material_id."'";
			}*/

			$data['get_summary_reort']=$this->System->get_summary_reort($array_val);
			/*var_dump($data['get_summary_reort']);
			exit;*/

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

	}



	

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

				$dates = $this->input->post('insert_date');
				
				$data['get_day_night']=$this->System->get_day_night($dates);
				$data['get_day_night_night']=$this->System->get_day_night_night($dates);
				$data['count_active_machine'] = $this->System->count_active_machine1($dates);
				
				
				echo json_encode (array('html'=>$this->load->view('system/day_night_report',$data,true)));
		}		
	}


	
	public function add_machine_report(){

		check_login();

		$id = $this->uri->segment('3');

		if($this->input->post())
		{

		   $qc_machine_id = $this->input->post('qc_machine_id');
		   $emp_id = $this->input->post('emp_id');
		   $machine_id = $this->input->post('machine_id');
		   $product_id = $this->input->post('product_id');
		   $material_id = $this->input->post('material_id');
			$job = $this->input->post('job');
		/*	$report_date = $this->input->post('report_date');*/
			$m_weight = $this->input->post('m_weight');
			$w_weight = $this->input->post('w_weight');
			$tp_weight = $this->input->post('tp_weight');
			$hrs = $this->input->post('hrs');
			$hr = $this->input->post('hr');
			$genrator_hrs = $this->input->post('genrator_hrs');
			$c_h = $this->input->post('c_h');
			$cost = $this->input->post('cost');
			//$day_night = $this->input->post('day_night');
			$insert_date = $this->input->post('insert_date');
			$created = $this->input->post('created');
			$modified = $this->input->post('modified');
			$user_id = $this->input->post('user_id');


			$dataarray =  array(
			'qc_machine_id' => $qc_machine_id,
			'emp_id' => $emp_id,
			'machine_id' => $machine_id,
			'product_id' => $product_id,
			'material_id' => $material_id,
			'job' => $job,
			/*'report_date' => $report_date,*/
			'm_weight' => $m_weight,
			'w_weight' => $w_weight,
			'genrator_hrs'=>$genrator_hrs,
			'c_h' => $c_h,
			'tp_weight'=> $tp_weight,
			'hrs'=> $hrs,
			'hr' => $hr,
			'cost'=> $cost,
			//'day_night'=> $day_night,
			'insert_date'=>$insert_date,
			'created'=> $created,
			'modified'=> $modified,
			'user_id'=> $user_id
			);

			    


			    $result = $this->System->add_machine_report($dataarray);
			    
			    $result = $this->System->update_machine_qc_id($qc_machine_id);

		        if($result){$add_fg_rates=array('status'=>'true');}else{$add_fg_rates=array('status'=>'false');}
		           echo json_encode($add_fg_rates);


				}else{

				$date = date('Y-m-d');
			   //$date = ('2023-04-15');
			   $new_date = $this->uri->segment('4');
			   
			   
				$data['get_machine']=$this->System->get_machine_qc($date);
				$data['get_products']=$this->System->get_products_qc($date);
				$data['get_materials']=$this->System->get_materials_qc($date);
				//$machine_id = qc_machine_get_machine_id($id);
				$data['get_machine_data_today'] = $this->System->get_machine_data_today($date,$id);
				$data['total_expense'] = $this->System->get_expenses_total();
				
				$data['count_active_machine'] = $this->System->count_active_machine($new_date);
				$data['get_oprators'] = $this->System->get_oprators();
				$data['total_expense'] = $this->System->get_total_expense();
				$data['get_last_job_no'] = $this->System->get_last_job_no();
				$xx = $data['get_last_job_no'][0]['job'];
	      		for ($code = 0; $code <= $xx; $code++) {
		             
		            }
	      	   $data['job_no'] = $code;

	      	   $data['condition']=$this->System->get_condition_machine_qc($id);


				$this->load->view('system/daily_machine_report',$data);

				}
				}

	



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

		  // $id = $this->uri->segment('3');
		if($this->input->post())
		{


		 $qc_machine_id = $this->input->post('qc_machine_id');
		   $emp_id = $this->input->post('emp_id');
		   $machine_id = $this->input->post('machine_id');
		   $product_id = $this->input->post('product_id');
		   $material_id = $this->input->post('material_id');
			$job = $this->input->post('job');
			/*$report_date = $this->input->post('report_date');*/
			
			$m_weight = $this->input->post('m_weight');
			$w_weight = $this->input->post('w_weight');
			$tp_weight = $this->input->post('tp_weight');
			$hrs = $this->input->post('hrs');
			$hr = $this->input->post('hr');
			$genrator_hrs = $this->input->post('genrator_hrs');
			$cost = $this->input->post('cost');
			$day_night = $this->input->post('day_night');
			$insert_date = $this->input->post('insert_date');
			$created = $this->input->post('created');
			$modified = $this->input->post('modified');
			$user_id = $this->input->post('user_id');


			$dataarray =  array(
			'qc_machine_id' => $qc_machine_id,
			'emp_id' => $emp_id,
			'machine_id' => $machine_id,
			'product_id' => $product_id,
			'material_id' => $material_id,
			'job' => $job,
			/*'report_date' => $report_date,*/
			'm_weight' => $m_weight,
			'w_weight' => $w_weight,
			'genrator_hrs'=>$genrator_hrs,
			'tp_weight'=> $tp_weight,
			'hrs'=> $hrs,
			'hr' => $hr,
			'cost'=> $cost,
			'day_night'=> $day_night,
			'insert_date'=>$insert_date,
			'created'=> $created,
			'modified'=> $modified,
			'user_id'=> $user_id
			);


		$result=$this->System->edit_machine_data_todays_edit($id,$dataarray);

		if($result){$fgrates=array('status'=>'true');}else{$fgrates=array('status'=>'false');}
		echo json_encode($fgrates);
		}else{

        $data['get_data'] = $this->System->get_machinereport_data_edit($id);
        $date = date('Y-m-d');
       // $date = '2022-10-01';
		$data['get_machine']=$this->System->get_machine_qc($date);
		$data['get_products']=$this->System->get_products_qc($date);
		$data['get_materials']=$this->System->get_materials_qc($date);
		$data['get_oprators'] = $this->System->get_oprators();
 		$data['total_expense'] = $this->System->get_expenses_total();

 		$data['count_active_machine'] = $this->System->count_active_machine($date);
         $this->load->view('system/edit_machine_data_todays',$data);
    }

}
	
	
	
public function add_expense()
{
		check_login();

		  // $id = $this->uri->segment('3');
		if($this->input->post())
		{

		$result=$this->System->add_expense($_POST);

		if($result){$fgrates=array('status'=>'true');}else{$fgrates=array('status'=>'false');}
		echo json_encode($fgrates);
		}else{

        $data['get_data'] = $this->System->get_expenses();
        
         $this->load->view('system/add_view_expense',$data);
    }

}

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

			
			    $date = $this->input->post('date');
				$ddd = explode('-', $date);
				$month = $ddd[0];
				$year = $ddd[1];
			    $emp_id = $this->input->post('emp_id');


					if($date !="" && $emp_id =="0"){

						
						
			    	 $data['filter_data'] = $this->System->filter_attendance_report($month,$year);


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

	    			}else if($date !=""  && $emp_id !="0"){

	    				
	    			
	    				 $data['filter_data'] = $this->System->filter_attendance_report1($month,$year,$emp_id);

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


			}else{
		  $data['empolyee']=$this->System->get_empolyee();
			$this->load->view('system/attendance_report',$data);
		}
	}

	public function fg_set()
	{
		check_login();
			
			
		  $data['products']=$this->System->get_fg_for_fg_rates();
			$this->load->view('system/fg_set',$data);
		
	}
	

	public function add_product_set($id){
		$seg_id  = $id;
		$id = $this->uri->segment('3');
		$data['products']=$this->System->get_fg_for_fg_rates();
		$data['get_fg']=$this->System->get_fg_sets($id);
		$this->load->view('system/add_product_set',$data);

	}

	

	public function add_fg_set()
{
		check_login();
	    

		if($this->input->post())
		{
		$id = $this->input->post('fg_id');
		$result=$this->System->add_fg_set($_POST);
		$result=$this->System->update_fg_set_status($id);

		if($result){$fgrates=array('status'=>'true');}else{$fgrates=array('status'=>'false');}
		echo json_encode($fgrates);
		}

}


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

	
}
