<?php
class System extends CI_Model {


	public function check_password($user,$password){

		$this->db->select('id');  
		  
		$this->db->from('users');
		$this->db->where('id',$user);
		$this->db->where('password',$password);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	
	public function get_empolyee_production()
	{
		$sql = $this->db->get_where('empolyees', array('depart'=>'7'));
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	
	public function check_timing_data($today_date){

		$this->db->select('*');  
		  
		$this->db->from('add_timing_qc');
		$this->db->where('insert_date',$today_date);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	

	public function randomly_check_qc($today_date){

		$this->db->select('*');  
		  
		$this->db->from('randomly_check_qc');
		$this->db->where('insert_date',$today_date);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	
	public function update_password($user,$n_password) {
		$result = $this->db->where('id',$user);
		$result = $this->db->update('users',array('password' =>$n_password));
		if($result){return true;}else{return false;}
		}

		

		


	public function count_vendor()
	{
		$this->db->select('count(*) as vendor_count');
		$sql = $this->db->get('vendors');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	
	public function count_machines()
	{
		$this->db->select('count(*) as count_machines');
		$sql = $this->db->get('machines');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	

	public function get_descriptions()
	{
		// $this->db->select('*');
		// $sql = $this->db->get('company_description');

		$this->db->select('fg_rates.status,company_description.fg_ref_id,company_description.id,company_description.description,company_description.created');
		$this->db->from('company_description');
		$this->db->join('fg_rates', 'company_description.fg_ref_id = fg_rates.ref_code', 'left');
		$this->db->where('fg_rates.status',1);
		
		$sql = $this->db->get();
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function count_materials()
	{
		$this->db->select('count(*) as materials');
		$sql = $this->db->get('materials');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function count_products()
	{
		$this->db->select('count(*) as products');
		$sql = $this->db->get('products');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function count_molds()
	{
		$this->db->select('count(*) as count_molds');
		$sql = $this->db->get('molds');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	

	public function count_parties()
	{
		$this->db->select('count(*) as party_count');
		$sql = $this->db->get('parties');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	

	public function get_code(){

		$this->db->select('machines.code');  
		  
		$this->db->from('machines');
		//$this->db->where('type',1);
		$this->db->order_by('machines.id','DESC');
		
		$this->db->limit(1);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	public function other_get_code(){

		$this->db->select('other_machine.code');  
		  
		$this->db->from('other_machine');
		//$this->db->where('type',1);
		$this->db->order_by('other_machine.id','DESC');
		
		$this->db->limit(1);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

		
	public function get_machine_data($id)
	{
		$sql = $this->db->get_where('machines', array('id'=>$id));
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	
	public function get_empolyee_data($id)
	{
		$sql = $this->db->get_where('empolyees', array('id'=>$id));
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	
	public function add_description($post) {
      $result = $this->db->insert('company_description',$post);
      if($result){return true;}else{return false;} 
  
    }
	
	public function add_bank($post) {
		$result = $this->db->insert('banks',$post);
		if($result){return true;}else{return false;} 
	
	  }
	

	public function update_machine($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('machines',$_POST);
		if($result){return true;}else{return false;}
	}
	
	public function edit_get_empolyee($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('empolyees',$_POST);
		if($result){return true;}else{return false;}
	}

	public function add_machine($post) {
          $result = $this->db->insert('machines',$post);
          if($result){return true;}else{return false;} 
		  
    }

	
	public function add_other_machine($post) {
		$result = $this->db->insert('other_machine',$post);
		if($result){return true;}else{return false;} 
		
  }
    
     public function add_daily_sheet($post) {
          $result = $this->db->insert('daily_work_sheet',$post);
          if($result){return true;}else{return false;} 
		  
    }
    
     public function add_daily_work_add_ad_ot($post) {
          $result = $this->db->insert('ot_advance_emp',$post);
          if($result){return true;}else{return false;} 
		  
    }
    

    public function add_po_rates($post) {
          $result = $this->db->insert('po_rates',$post);
          if($result){return true;}else{return false;} 
		  
    }
    
    		 public function get_daily_sheetdata($id)
		{
		$sql = $this->db->get_where('ot_advance_emp', array('in_out_id'=>$id));

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
		}
        
        
        
        public function edit_get_daily_sheet($id) {
		$result = $this->db->where('in_out_id',$id);
		$result = $this->db->update('ot_advance_emp',$_POST);
		if($result){return true;}else{return false;}
		}
    
    public function get_emp_ad_ot($id)
	{
		$sql = $this->db->get_where('tap_in_out', array('id'=>$id));
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	public function add_party($post) {
          $result = $this->db->insert('parties',$post);
          if($result){return true;}else{return false;} 
		  
    }


    public function add_vendor($post) {
          $result = $this->db->insert('vendors',$post);
          if($result){return true;}else{return false;} 
		  
    }

    public function add_depart($post) {
          $result = $this->db->insert('department',$post);
          if($result){return true;}else{return false;} 
		  
    }

    
    public function add_machine_report($dataarray) {
          $result = $this->db->insert('machine_daily_report',$dataarray);
          if($result){return true;}else{return false;} 
		  
    }

	
	public function add_fg_set($post) {
		$result = $this->db->insert('fg_sets',$post);
		if($result){return true;}else{return false;} 
		
  }

    public function delete_vendor($id)
	{
		$sql = $this->db->delete('vendors', array('id'=>$id));
		
		return true;
	}

    public function get_mold_data($id)
		{
		$sql = $this->db->get_where('molds', array('id'=>$id));

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
		}

		

		public function get_fg_sets($id)
		{
		$sql = $this->db->get_where('fg_sets', array('fg_id'=>$id));

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
		}


		
		public function update_machine_qc_id($qc_machine_id) {
		$result = $this->db->where('id',$qc_machine_id);
		$result = $this->db->update('qc_machine',array('status' =>'1'));
		if($result){return true;}else{return false;}
		}

		public function update_fg_set_status($id) {
			$result = $this->db->where('id',$id);
			$result = $this->db->update('products',array('set_status' =>'1'));
			if($result){return true;}else{return false;}
			}

		public function update_molds($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('molds',$_POST);
		if($result){return true;}else{return false;}
		}

    public function get_vendors()
	{
		$sql = $this->db->get('vendors');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
public function get_daily_sheet($id)
	{
		 
		$this->db->select('tap_in_out.id,tap_in_out.tap_in,tap_in_out.emp_id,tap_in_out.date,tap_in_out.tap_out,tap_in_out.date_out,ot_advance_emp.in_out_id');  
		  
		$this->db->from('tap_in_out');
		$this->db->join('ot_advance_emp', 'tap_in_out.id = ot_advance_emp.in_out_id', 'left');
		
		$this->db->where("tap_in_out.emp_id",$id);
		$this->db->order_by("tap_in_out.date",'DESC');
		$this->db->where("tap_in_out.date !=",'0000-00-00');
		 $this->db->where('MONTH(tap_in_out.date)', date('10')); //For current month
     	 $this->db->where('YEAR(tap_in_out.date)', date('2021')); // For current year
		
		//$this->db->group_by("tap_in_out.date");
		/*SELECT * FROM `tap_in_out` WHERE emp_id ='17' ORDER BY id DESC*/

		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	
	public function get_daily_sheet_today_attendance($dates)
        {
        
        $this->db->select('tap_in_out.id,tap_in_out.tap_in,tap_in_out.emp_id,tap_in_out.date,tap_in_out.tap_out,tap_in_out.date_out,ot_advance_emp.in_out_id');  
         
        $this->db->from('tap_in_out');
        $this->db->join('ot_advance_emp', 'tap_in_out.id = ot_advance_emp.in_out_id', 'left');
        
        $this->db->where("tap_in_out.date",$dates);
        $this->db->order_by("tap_in_out.id",'DESC');
        //$this->db->where("staff_tap_out.emp_id",$id);
        
        //$this->db->group_by("staff_tap_out.id");
        /*SELECT * FROM `tap_in_out` WHERE emp_id ='17' ORDER BY id DESC*/
        
        $sql = $this->db->get();
        
        if($sql->num_rows() >0)
        {return $sql->result_array();
        }else
        {return false;}
        }
        
        
        
        public function view_ot_advance($id)
	{
		 $this->db->where('in_out_id',$id);
		$sql = $this->db->get('ot_advance_emp');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	public function update_daily_sheet_emp($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('daily_work_sheet',$_POST);
		if($result){return true;}else{return false;}
	}

	

	

	public function get_emp_dailysheet($id)
	{
		 $this->db->where('id',$id);
		$sql = $this->db->get('daily_work_sheet');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function get_depart()
	{
		$sql = $this->db->get('department');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function get_machine()
	{
		$sql = $this->db->get('machines');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	

	public function other_machine()
	{
		$sql = $this->db->get('other_machine');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	
	public function other_machine_get($id)
	{
		$this->db->where('id',$id);
		$sql = $this->db->get('other_machine');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	
	public function get_machine_qc_data()
	{
		//$this->db->where('report_date',$date);
		//$this->db->where('report_date','2022-10-01');
		$this->db->where('status',0);
		$this->db->where('qc_machine.report_date >=','2023-04-01');
		$sql = $this->db->get('qc_machine');

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function delete_depart($id)
	{
		$sql = $this->db->delete('department', array('id'=>$id));
		
		return true;
	}

	
	public function delete_fg_set($id)
	{
		$sql = $this->db->delete('fg_sets', array('id'=>$id));
		
		return true;
	}

	
	public function update_get_depart($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('department',$_POST);
		if($result){return true;}else{return false;}
	}
	
	public function update_other_machine($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('other_machine',$_POST);
		if($result){return true;}else{return false;}
	}

	public function get_depart_data($id)
	{
		$sql = $this->db->get_where('department', array('id'=>$id));
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	
	public function get_line_data($id)
	{
		$sql = $this->db->get_where('assembled_line', array('id'=>$id));
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function get_vendor_data($id)
	{
		$sql = $this->db->get_where('vendors', array('id'=>$id));
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function update_vendor($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('vendors',$_POST);
		if($result){return true;}else{return false;}
	}

	
	public function update_assembled_line_area($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('assembled_line',$_POST);
		if($result){return true;}else{return false;}
	}

    
    public function get_party()
	{
		$sql = $this->db->get('parties');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	
	public function get_parties_assembling()
	{
		$this->db->where('nature',8);
		$sql = $this->db->get('parties');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function get_bus_nature()
	{
		$sql = $this->db->get('business_nature');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function get_party_data($p_id)
	{
		$sql = $this->db->get_where('parties', array('p_id'=>$p_id));
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	

	
public function check_ref($id)
	{
		//$sql = $this->db->get_where('qc_parameter_ref_no', array('mold_id'=>$id));
		 $this->db->select('qc_parameter_ref_no.mold_id');
		  $this->db->from('qc_parameter_ref_no');
		  $this->db->where('mold_id',$id);
		  
		  $sql = $this->db->get();
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function delete_party($id)
	{
		$sql = $this->db->delete('parties', array('p_id'=>$id));
		
		return true;
	}

	
	public function delete_other_machine($id)
	{
		$sql = $this->db->delete('other_machine', array('id'=>$id));
		
		return true;
	}
	
	
	public function delete_line($id)
	{
		$sql = $this->db->delete('assembled_line', array('id'=>$id));
		
		return true;
	}
	
	public function delete_daily_sheet($id)
	{
		$sql = $this->db->delete('daily_work_sheet', array('id'=>$id));
		
		return true;
	}

	public function filter_daily_sheet($id,$date,$end_date)
	{

		//$sql = $this->db->get_where('qc_parameter_ref_no', array('mold_id'=>$id));
		 $this->db->select('tap_in_out.emp_id,tap_in_out.date,tap_in_out.date_out,tap_in_out.tap_in,tap_in_out.tap_out,ot_advance_emp.in_out_id,ot_advance_emp.over_time,ot_advance_emp.advance');
		  $this->db->from('tap_in_out');
		  $this->db->join('ot_advance_emp', 'tap_in_out.id = ot_advance_emp.in_out_id', 'left');
		 $this->db->where('tap_in_out.emp_id',$id);
		  $this->db->where('tap_in_out.date >=',$date);
		   $this->db->where('tap_in_out.date <=',$end_date);
 //$this->db->where('tap_in_out.date_out !=','');
		   $sql = $this->db->get();
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	
	public function filter_attendance_report($month,$year)
	{

		//$sql = $this->db->get_where('qc_parameter_ref_no', array('mold_id'=>$id));
		 $this->db->select('tap_in_out.id,tap_in_out.tap_in,tap_in_out.date,tap_in_out.emp_id,count(tap_in_out.emp_id)as count_data');
		  $this->db->from('tap_in_out');
		  //$this->db->join('ot_advance_emp', 'tap_in_out.id = ot_advance_emp.in_out_id', 'left');
		
		  $this->db->where('MONTH(date)',$month);
		   $this->db->where('YEAR(date)',$year);
 			$this->db->group_by('tap_in_out.emp_id');
 			/*$$this->db->where('tap_in_out.tap_out !=','');*/
		   $sql = $this->db->get();

		   
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	

	public function filter_attendance_report1($month,$year,$emp_id)
	{

		//$sql = $this->db->get_where('qc_parameter_ref_no', array('mold_id'=>$id));
		 $this->db->select('tap_in_out.id,tap_in_out.tap_in,tap_in_out.date,tap_in_out.emp_id,count(tap_in_out.emp_id) as count_data');
		  $this->db->from('tap_in_out');
		  //$this->db->join('ot_advance_emp', 'tap_in_out.id = ot_advance_emp.in_out_id', 'left');
		
		  $this->db->where('MONTH(date)',$month);
		   $this->db->where('YEAR(date)',$year);
		   $this->db->where('emp_id',$emp_id);
 			$this->db->group_by('tap_in_out.emp_id');
 			/*$$this->db->where('tap_in_out.tap_out !=','');*/
		   $sql = $this->db->get();

		   /*print_r($this->db->last_query($sql));   die;*/
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	
	public function get_summary_reort($array_val)
	{
		
		$this->db->select('qc_machine.day_night,machine_daily_report.machine_id,machine_daily_report.product_id,machine_daily_report.material_id,machine_daily_report.emp_id,machine_daily_report.job,machine_daily_report.m_weight,machine_daily_report.w_weight,machine_daily_report.tp_weight,machine_daily_report.hrs,machine_daily_report.cost,machine_daily_report.qc_machine_id,machine_daily_report.created');
		$this->db->from('machine_daily_report');
		$this->db->join('qc_machine', 'machine_daily_report.qc_machine_id = qc_machine.id', 'left');
		$this->db->where($array_val);
		$sql = $this->db->get();
		  /*print_r($this->db->last_query($sql));   die;*/
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	

	public function update_parties($p_id) {
		$result = $this->db->where('p_id',$p_id);
		$result = $this->db->update('parties',$_POST);
		if($result){return true;}else{return false;}
	}


	
	public function update_descriptione($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('company_description',$_POST);
		if($result){return true;}else{return false;}
	}


	public function 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) {


		$data = array(
			        'code' => $code,
			        'product_id' => $product_id,
			        'manufacture' => $manufacture,
			        'mfg_date' => $mfg_date,
			        'cavity' => $cavity,
			        'cycle_time' => $cycle_time,
			        'cost' => $cost,
			        'self_life' => $self_life,
			        'self_life_start' => $self_life_start,
			        
			        'self_life_remain' => $self_life_remain,
			        'machine_type' => $machine_type,

			         'image' => $image,
			        'created' => $created,
			        'modified' => $modified
			        );  
		 
          $result = $this->db->insert('molds',$data);
          if($result){return true;}else{return false;} 
		  
    }

    
    public function add_empolyee($fullname,$phone,$nic,$depart,$designation,$salary,$new_tapin,$new_tapout,$over_time,$email,$address,$comments,$image,$user_id,$created,$modified) {


		$data = array(
			        'fullname' => $fullname,
			        'phone' => $phone,
			        'nic' => $nic,
			        'depart' => $depart,
			        'designation' => $designation,
			        'salary' => $salary,
			        'tap_in' => $new_tapin,
			        'tap_out' => $new_tapout,
			        'over_time'=> $over_time,
			        'email'=> $email,
			        'address' => $address,
			        'comments' => $comments,
			        'image' => $image,
			        'user_id'=> $user_id,
      	            'created' => $created,
			        'modified' => $modified
			        
			        );  
		 
          $result = $this->db->insert('empolyees',$data);
          if($result){return true;}else{return false;} 
		  
    }

    
    public function get_empolyee()
	{
		$sql = $this->db->get('empolyees');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	


		public function delete_empolyee($id)
	{
		$sql = $this->db->delete('empolyees', array('id'=>$id));
		
		return true;
	}


	

		public function delete_decription($id)
	{
		$sql = $this->db->delete('company_description', array('id'=>$id));
		
		return true;
	}


	public function get_molds()
	{
    	$this->db->select('*');
		$this->db->from('molds');
		
		$this->db->order_by("id", "asc"); 
		$sql = $this->db->get();
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

public function get_counter_number_molds(){

		$this->db->select('molds.code');  
		  
		$this->db->from('molds');
		//$this->db->where('product_type',5);
		$this->db->order_by('code','DESC');
		
		$this->db->limit(1);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	
	public function get_code_party(){

		$this->db->select('parties.party_code');  
		  
		$this->db->from('parties');
		//$this->db->where('product_type',5);
		$this->db->order_by('party_code','DESC');
		
		$this->db->limit(1);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function delete_mold($id)
	{
		$sql = $this->db->delete('molds', array('id'=>$id));
		
		return true;
	}
	
	
	public function vendor_type()
	{
		$sql = $this->db->get('vendors_type');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	

	public function get_fg_pro(){

		$this->db->select('fg_rates.id,fg_rates.ref_code,fg_rates.product');  
		  
		$this->db->from('fg_rates');
		$this->db->where('status',1);
		//$this->db->where('fg_rates.product_type',5);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	
		public function get_fg_for_fg_rates(){

		$this->db->select('products.id,products.name,products.pro_code,products.set_status');  
		  
		$this->db->from('products');
		$this->db->where('product_type',5);
		//$this->db->where('fg_rates.product_type',5);
		
		
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	

	public function get_pro(){

		$this->db->select('products.id,products.name');  
		  
		$this->db->from('products');
		$this->db->where('product_type',5);
		//$this->db->where('products.product_type',5);
		
		
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function get_pro_fg_edit(){

		$this->db->select('products.id,products.name');  
		  
		$this->db->from('products');
		$this->db->where('product_type',5);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	public function check_fg_condition(){

		$this->db->select('*');  
		  
		$this->db->from('fg_rates');
		$this->db->where('product_type',5);
		$this->db->where('product_type',5);
		$this->db->where('product_type',5);
		
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	
	
	public function get_pro_porates(){

		$this->db->select('products.id,products.name');  
		  
		$this->db->from('products');
		$this->db->where('product_type !=',5);
		$this->db->where('product_type !=',3);
		$this->db->where('product_type !=',4);
		
		
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function add_fg_rates($post) {
          $result = $this->db->insert('fg_rates',$post);
          if($result){return true;}else{return false;} 
		  
    }

    public function all_fg_rates()
	{
		$this->db->select('*');  
		  
		$this->db->from('fg_rates');
		$this->db->group_by('ref_code');
		
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function allbanks()
	{
		$this->db->select('*');  
		  
		$this->db->from('banks');
		$sql = $this->db->get();
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	

	
	public function all_fg_rates_logs($id)
	{
		$this->db->select('*');  
		  
		$this->db->from('fg_rates');
		$this->db->where('ref_code',$id);
		//$sql = $this->db->get_where('fg_rates', array('ref_code'=>$id));
		$sql = $this->db->order_by('created','DESC');
		$sql = $this->db->get();
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	public function all_rates()
	{
		$sql = $this->db->get('po_rates');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	
	public function delete_fgrates($id)
	{
		$sql = $this->db->delete('fg_rates', array('id'=>$id));
		
		return true;
	}

	public function delete_rates($id)
	{
		$sql = $this->db->delete('po_rates', array('id'=>$id));
		
		return true;
	}

	public function get_edit_fg_rates($id)
	{
		$sql = $this->db->get_where('fg_rates', array('id'=>$id));
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}



	public function get_edit_rates($id)
	{
		$sql = $this->db->get_where('po_rates', array('id'=>$id));
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	

		public function edit_get_descriptions($id)
	{
		// $sql = $this->db->get_where('company_description', array('id'=>$id));
		$this->db->select('*');
		$this->db->from('company_description');
		$this->db->join('fg_rates', 'company_description.fg_ref_id = fg_rates.id', 'left');
		$this->db->where('fg_rates.status',1);
		$this->db->where('fg_ref_id',$id);
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	
	public function update_edit_all_fg_ratess($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('fg_rates',$_POST);
		if($result){return true;}else{return false;}
	}


	public function update_edit_all_ratess($id) {
		$result = $this->db->where('id',$id);
		$result = $this->db->update('po_rates',$_POST);
		if($result){return true;}else{return false;}
	}

	public function add_parameter($mold_id,$type,$sno_num,$descrip,$parameters,$max,$min,$units,$user_id,$created,$modified) {

		$data = array(
					'mold_id' => $mold_id,
					'type' => $type,
			        'sno_num' => $sno_num,
			        'descrip' => $descrip,
			        'parameters' => $parameters,
					'max_range' => $max,
					'min_range' => $min,
					'units' => $units,
			        'user_id' => $user_id,
			        'created' => $created,
			        'modified' => $modified
			       
			        ); 

          $result = $this->db->insert('qc_parameter',$data);
          if($result){return true;}else{return false;} 
		  
    }

    public function get_mold_parameter($id)
		{
		$sql = $this->db->where('mold_id',$id);
		$sql = $this->db->get('qc_parameter');
		
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

		}

		
		public function add_ref($mold_id,$ref_no,$user_id,$created,$modified) {

			$data = array(
			        'mold_id' => $mold_id,
			        'ref_no' => $ref_no,
			        'user_id' => $user_id,
			        'created' => $created,
			        'modified' => $modified
			       
			        );  

          $result = $this->db->insert('qc_parameter_ref_no',$data);
          if($result){return true;}else{return false;} 
		  
    }

		public function mold_delete_parameter($id)
	{
		$sql = $this->db->delete('qc_parameter', array('id'=>$id));
		
		return true;
	}

	public function get_molds_data_all($id)
		{
		$sql = $this->db->where('id',$id);
		$sql = $this->db->get('molds');
		
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

		}


		public function get_parameter($id)
		{
		$sql = $this->db->where('mold_id',$id);
		$sql = $this->db->get('qc_parameter');
		
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

		}
		
		
		public function last_tapin($emp_id,$date)
		{
		
		
		$sql =$this->db->where('date',$date);
		$sql =$this->db->where('emp_id',$emp_id);
		$sql =$this->db->where('status',1);
		$sql = $this->db->get('tap_in_out');
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

		}


		public function code_verification($code)
	{
		
		  $this->db->select('empolyees.fullname,empolyees.designation,empolyees.rf_id,empolyees.image,empolyees.id');
		  $this->db->from('empolyees');
		  $this->db->where('rf_id',$code);

		  
		  $sql = $this->db->get();
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	
	 public function add_param($data_save) {
          $result = $this->db->insert('staff_tap_in',$data_save);
          if($result){return  true;}else{return false;} 
		  
    }

    
    public function add_tap_in($data_save) {
          $result = $this->db->insert('tap_in_out',$data_save);
          if($result){return  true;}else{return false;} 
		  
    }

    
     public function add_param_out($data_save) {
          $result = $this->db->insert('staff_tap_out',$data_save);
          if($result){return true;}else{return false;} 
		  
    }


		public function get_daily_machine_qc_data($id){

			$sql = $this->db->where('machine_id',$id);
			 //$sql = $this->db->group_by('material_id');
			 $sql = $this->db->get('qc_machine');

			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}

		}


		
		public function get_oprators(){

			//$sql = $this->db->where('machine_id',$id);
			 //$sql = $this->db->group_by('material_id');
			 $sql = $this->db->get('empolyees');

			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}

		}
		
		
		 public function tap_in_check($emp_id,$date){

    	  $this->db->select('staff_tap_in.tap_in');
		  $this->db->from('staff_tap_in');
		  $this->db->where('emp_id',$emp_id);
		  $this->db->where('date',$date);
		  $this->db->order_by('staff_tap_in.tap_in','DESC');
		  $this->db->limit('1');
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }
    
     public function tap_in_date($emp_id,$date){

    	  $this->db->select('tap_in_out.date');
		  $this->db->from('tap_in_out');
		  $this->db->where('emp_id',$emp_id);
		  $this->db->where('date',$date);
		 $this->db->where('date_out','0000-00-00');
		  $this->db->group_by('date');
		 $this->db->order_by("date", "DESC");

		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }

    

public function tap_out_date($emp_id,$date){

    	  $this->db->select('tap_in_out.date_out');
		  $this->db->from('tap_in_out');
		  $this->db->where('emp_id',$emp_id);
		  $this->db->where('date_out',$date);
		  //$this->db->where('date_out','');
		  $this->db->group_by('date_out');
		 $this->db->order_by("date_out", "DESC");
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }


    

    public function tap_out_check($emp_id,$date){

    	 $this->db->select('staff_tap_out.tap_out');
		  $this->db->from('staff_tap_out');
		  $this->db->where('emp_id',$emp_id);
		  $this->db->where('date',$date);
		  $this->db->order_by('staff_tap_out.tap_out','DESC');
		  $this->db->limit('1');
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }


    public function add_tap($data1_save) {
          $result = $this->db->insert('staff_tap_out',$data1_save);
          if($result){return true;}else{return false;} 
		  
    }
    
    public function add_attendance($data_save) {
          $result = $this->db->insert('tap_in_out',$data_save);
          if($result){return true;}else{return false;} 
		  
    }
    
    
     public function atten_check($emp_id,$date){

    	 $this->db->select('tap_in_out.emp_id');
		  $this->db->from('tap_in_out');
		  $this->db->where('emp_id',$emp_id);
		  $this->db->where('date',$date);
		  //$this->db->order_by('tap_in_out.tap_out','DESC');
		  //$this->db->limit('1');
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }
    
    
    
    public function param_update($data1_save1,$emp_id,$datein) {
		$result = $this->db->where('emp_id',$emp_id);
		$result = $this->db->where('status',1);
	    $result = $this->db->where('date',$datein);
		$result = $this->db->update('tap_in_out',$data1_save1);
		if($result){return true;}else{return false;}
	}
	
	
	 public function get_tap_data($id){

    	  $this->db->select('staff_tap_in.tap_in,staff_tap_in.date,staff_tap_in.emp_id');
		  $this->db->from('staff_tap_in');
		  $this->db->where('emp_id',$id);
		  $this->db->where('tap_in !=','');
		   $this->db->where('date !=','');
		 // $this->db->order_by('staff_tap_in.tap_in','DESC');
		  //$this->db->limit('1');
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }

    
     public function update_tapout_attendance($id,$date_in,$data1_save1) {
		$result = $this->db->where('emp_id',$id);
		$result = $this->db->where('status',1);
	    $result = $this->db->where('date',$date_in);
		$result = $this->db->update('tap_in_out',$data1_save1);

		
		if($result){return true;}else{return false;}
	}
	
	 public function get_filter_daily_machine_report($insert_date,$insert_last,$job_no){

    	   $this->db->select('machine_daily_report.qc_machine_id,machine_daily_report.emp_id,machine_daily_report.job,machine_daily_report.m_weight,machine_daily_report.w_weight,machine_daily_report.tp_weight,machine_daily_report.hrs,machine_daily_report.cost,qc_machine.product_id,qc_machine.material_id,qc_machine.mr_mould,qc_machine.pcs_cavity,qc_machine.weight,qc_machine.finishing,qc_machine.fitting,qc_machine.color');
		  $this->db->from('machine_daily_report');
		  $this->db->join('qc_machine', 'machine_daily_report.qc_machine_id = qc_machine.id', 'left');
		 $this->db->where('machine_daily_report.insert_date >=',$insert_date);
		   $this->db->where('machine_daily_report.insert_date <=',$insert_last);
		   $this->db->where('machine_daily_report.job',$job_no);
		$sql = $this->db->get();
		   
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }
    
    public function get_filter_daily_machine_report_job($job_no){

    	  $this->db->select('machine_daily_report.qc_machine_id,machine_daily_report.emp_id,machine_daily_report.job,machine_daily_report.m_weight,machine_daily_report.w_weight,machine_daily_report.tp_weight,machine_daily_report.hrs,machine_daily_report.cost,qc_machine.product_id,qc_machine.material_id,qc_machine.mr_mould,qc_machine.pcs_cavity,qc_machine.weight,qc_machine.finishing,qc_machine.fitting,qc_machine.color');
		  $this->db->from('machine_daily_report');
		  $this->db->join('qc_machine', 'machine_daily_report.qc_machine_id = qc_machine.id', 'left');
		 $this->db->where('machine_daily_report.job',$job_no);
		  
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }


    
    public function get_filter_daily_machine_report_dates($insert_date,$insert_last){

    	 $this->db->select('machine_daily_report.qc_machine_id,machine_daily_report.emp_id,machine_daily_report.job,machine_daily_report.m_weight,machine_daily_report.w_weight,machine_daily_report.tp_weight,machine_daily_report.hrs,machine_daily_report.cost,qc_machine.product_id,qc_machine.material_id,qc_machine.mr_mould,qc_machine.pcs_cavity,qc_machine.weight,qc_machine.finishing,qc_machine.fitting,qc_machine.color');
		  $this->db->from('machine_daily_report');
		  $this->db->join('qc_machine', 'machine_daily_report.qc_machine_id = qc_machine.id', 'left');
		 $this->db->where('machine_daily_report.insert_date >=',$insert_date);
		   $this->db->where('machine_daily_report.insert_date <=',$insert_last);
		  
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }
    
    
    
    public function get_machine_data_today($date,$id){

	    $this->db->select('machine_daily_report.day_night,machine_daily_report.job,machine_daily_report.m_weight,machine_daily_report.emp_id,machine_daily_report.w_weight,machine_daily_report.tp_weight,machine_daily_report.hrs,machine_daily_report.cost,machine_daily_report.created,machine_daily_report.id');
		 $this->db->from('machine_daily_report');
		 
		 $this->db->where('insert_date',$date);
		  //$this->db->where('machine_id',$machine_id);
		  $this->db->where('machine_daily_report.qc_machine_id',$id);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }
    


     public function get_machine_qc($date){

     $this->db->select('qc_machine.machine_id');
	 $this->db->from('qc_machine');
	 
	  $this->db->where('insert_date',$date);
	 
	$sql = $this->db->get();

	if($sql->num_rows() >0)
	{return $sql->result_array();
	}else
	{return false;}

    }

   


     public function get_condition_machine_qc($id){

     $this->db->select('machine_daily_report.qc_machine_id');
	 $this->db->from('machine_daily_report');
	 
	  $this->db->where('qc_machine_id',$id);
	 
	$sql = $this->db->get();

	if($sql->num_rows() >0)
	{return $sql->result_array();
	}else
	{return false;}

    }


    public function get_products_qc($date){

    $this->db->select('qc_machine.product_id');
	 $this->db->from('qc_machine');
	 
	 $this->db->where('insert_date',$date);
	 
	$sql = $this->db->get();

	if($sql->num_rows() >0)
	{return $sql->result_array();
	}else
	{return false;}

	    }


     public function get_materials_qc($date){

    $this->db->select('qc_machine.material_id');
	 $this->db->from('qc_machine');
	 
	 $this->db->where('insert_date',$date);
	 
	$sql = $this->db->get();

	if($sql->num_rows() >0)
	{return $sql->result_array();
	}else
	{return false;}

	    }



     public function get_machine_daily($date){

    $this->db->select('machine_daily_report.machine_id');
	 $this->db->from('machine_daily_report');
	 
	 $this->db->where('insert_date',$date);
	 
	$sql = $this->db->get();

	if($sql->num_rows() >0)
	{return $sql->result_array();
	}else
	{return false;}

    }

   


    public function get_products_daily($date){

    $this->db->select('machine_daily_report.product_id');
	 $this->db->from('machine_daily_report');
	 
	$this->db->where('insert_date',$date);
	 
	$sql = $this->db->get();

	if($sql->num_rows() >0)
	{return $sql->result_array();
	}else
	{return false;}

	    }


	     public function get_materials_daily($date){

	    $this->db->select('machine_daily_report.material_id');
		 $this->db->from('machine_daily_report');
		 
		 $this->db->where('insert_date',$date);
		 
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

	    }



	public function edit_machine_data_todays_edit($id,$dataarray) {
	$result = $this->db->where('id',$id);
	$result = $this->db->update('machine_daily_report',$dataarray);
	if($result){return true;}else{return false;}

	}


	public function get_machinereport_data_edit($id){

		$sql = $this->db->where('id',$id);
		$sql = $this->db->get('machine_daily_report');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
        public function add_expense($post) {
          $result = $this->db->insert('expenses',$post);
          if($result){return true;}else{return false;} 
		  
    }
    

    public function get_expenses(){

		//$sql = $this->db->where('id',$id);
		$sql = $this->db->get('expenses');
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	public function get_expenses_total()
		{
		
		$this->db->select('SUM(expenses.amount) AS total_expense');
		$this->db->from('expenses');
		
		$sql = $this->db->get();
			if($sql->num_rows() >0)
			{return $sql->result_array();
			}else
			{return false;}
		}



		 public function count_active_machine($date){

	     $this->db->select('count(qc_machine.machine_id) as count_active_machine');
		 $this->db->from('qc_machine');
		 
		 //$this->db->where('status',0);
		 $this->db->where('insert_date',$date);
		 
		$sql = $this->db->get();
         //print_r($this->db->last_query($sql));   die;
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

	    }
	    
	    
	     public function count_active_machine1($dates){

	    $this->db->select('count(qc_machine.machine_id) as count_active_machines');
		 $this->db->from('qc_machine');
		 
		 //$this->db->where('status',0);
		 $this->db->where('report_date',$dates);
		 
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

	    }
	    
	    

	    

	     public function get_total_expense(){

	    $this->db->select('SUM(amount) as get_total_expense');
		 $this->db->from('expenses');
		
		 
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

	    }



	    public function get_day_night($dates){

    	 $this->db->select('machine_daily_report.machine_id,machine_daily_report.emp_id,machine_daily_report.job,machine_daily_report.m_weight,machine_daily_report.w_weight,machine_daily_report.tp_weight,machine_daily_report.hrs,machine_daily_report.cost,machine_daily_report.genrator_hrs,machine_daily_report.c_h,machine_daily_report.hr,qc_machine.product_id,qc_machine.material_id,qc_machine.mr_mould,qc_machine.pcs_cavity,qc_machine.weight,qc_machine.finishing,qc_machine.fitting,qc_machine.color,qc_machine.report_date');
		  $this->db->from('qc_machine');
		  $this->db->join('machine_daily_report', 'machine_daily_report.qc_machine_id = qc_machine.id', 'left');
		 //$this->db->where('machine_daily_report.report_date',$dates);
		 $this->db->where('qc_machine.report_date',$dates);
		  $this->db->where('qc_machine.day_night',1);

		  
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }


    
     public function get_day_night_night($dates){

    	 $this->db->select('machine_daily_report.machine_id,machine_daily_report.emp_id,machine_daily_report.job,machine_daily_report.m_weight,machine_daily_report.w_weight,machine_daily_report.tp_weight,machine_daily_report.hrs,machine_daily_report.cost,machine_daily_report.genrator_hrs,machine_daily_report.c_h,qc_machine.product_id,machine_daily_report.hr,qc_machine.material_id,qc_machine.mr_mould,qc_machine.pcs_cavity,qc_machine.weight,qc_machine.finishing,qc_machine.fitting,qc_machine.color');
		  $this->db->from('qc_machine');
		  $this->db->join('machine_daily_report', 'machine_daily_report.qc_machine_id = qc_machine.id', 'left');
		 //$this->db->where('machine_daily_report.report_date',$dates);
		 $this->db->where('qc_machine.report_date',$dates);
		  $this->db->where('qc_machine.day_night',2);
		  
		$sql = $this->db->get();
		
		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}

    }
    
    
    

     public function get_last_job_no(){

		$this->db->select('machine_daily_report.job');  
		  
		$this->db->from('machine_daily_report');
		//$this->db->where('type',1);
		$this->db->order_by('machine_daily_report.id','DESC');
		
		$this->db->limit(1);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}
	
	   public function today_compound_production($today_date){

		$this->db->select('stock_out_production.so_id,stock_out_production.product_id,stock_out_production.material_id,stock_out_production.machine_id,stock_out_production.qcr,stock_out_production.qty');  
		  
		$this->db->from('stock_out_production');
		$this->db->where('stock_out_production.insert_date',$today_date);
	
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


public function po_today($today_date){

		$this->db->select('purchase_order.id,purchase_order.po_no,purchase_order.po_date,purchase_order.vendor_id');  
		  
		$this->db->from('purchase_order');
		$this->db->where('purchase_order.po_date',$today_date);
	
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	
	public function so_today($today_date){

		$this->db->select('sales_order.id,sales_order.so_no,sales_order.so_date,sales_order.party_id');  
		  
		$this->db->from('sales_order');
		$this->db->where('sales_order.so_date',$today_date);
	
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	

	public function semi_production($today_date){

		$this->db->select('in_stock_log.so_id,in_stock_log.product_id,in_stock_log.insert_date,in_stock_log.qty');  
		  
		$this->db->from('in_stock_log');
		$this->db->where('in_stock_log.insert_date',$today_date);
		$this->db->where('in_stock_log.type',1);
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}


	public function finish_production($today_date){

		$this->db->select('in_stock_log.so_id,in_stock_log.product_id,in_stock_log.insert_date,in_stock_log.qty,in_stock_log.batch,in_stock_log.created');  
		  
		$this->db->from('in_stock_log');
		$this->db->where('in_stock_log.insert_date',$today_date);
		$this->db->where('in_stock_log.type',5);
	
		$sql = $this->db->get();

		if($sql->num_rows() >0)
		{return $sql->result_array();
		}else
		{return false;}
	}

	




	
}