MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/allyindian_com/sbltt/application/models/Vehicle_model.php
<?php
class Vehicle_model extends CI_Model
{
	public function search($search,$rows = 0,$limit_from= 0,$sort='vehicle_id',$order='asc'){
		$this->db->from('vehicle');
		$this->db->join('veh_type', 'veh_type.veh_type_id = vehicle.vehicle_type','left');
		$this->db->join('vendor', 'vendor.vendor_id = vehicle.owned_by','left');
		$this->db->join('permit_type', 'permit_type.permit_type_id = vehicle.permit_type','left');
		$this->db->join('employees', 'employees.id = vehicle.driver_name','left');
		$this->db->join('people', 'people.person_id = employees.person_id');
		$this->db->where('vehicle.status',1);
		$this->db->group_start();
			$this->db->like('vehicle_id',$search);
			$this->db->or_like('vehicle_no',$search);
			$this->db->or_like('veh_type.veh_type',$search);
			$this->db->or_like('vendor.vendor_name',$search);
			$this->db->or_like('permit_type.permit_type_name',$search);
			$this->db->or_like('people.first_name',$search);
			$this->db->or_like('insur_company',$search);
		$this->db->group_end();
		$this->db->order_by('vehicle_id',$order);
		if($rows>0)
		{
			$this->db->limit($rows, $limit_from);
		}
		return $this->db->get();
	}
	
	public function get_found_rows($search){
		$this->db->from('vehicle');
		$this->db->where('status',1);
		return $this->db->get()->num_rows();
	}

	public function get_info($vehicle_id)	
	{
		$this->db->from('vehicle');
		$this->db->where('vehicle_id',$vehicle_id);
		$a=$this->db->get();
		if($a->num_rows() === 1){
			return $a->row();
		
		}else{
			foreach ($this->db->list_fields('vehicle') as $field)
			{
				$PersonObj->field= '';
			}
			return $PersonObj;
		}
	}

	

	public function exists($vehicle_id){
		$this->db->from('vehicle');
		$this->db->where('vehicle_id', $vehicle_id);
		return ($this->db->get()->num_rows() == 1);
	}
	/*Gets all of state*/
	public function get_state() {
	   $this->db->from('state');
	   $this->db->order_by('state_name', 'asc');
	   return $this->db->get();
	}
	public function get_vehicle_type() {
	   $this->db->from('veh_type');
	   $this->db->where('status', 1);
	   $this->db->order_by('veh_type', 'asc');
	   return $this->db->get();
	}
	
	public function get_permit_type() {
	   $this->db->from('permit_type');
	   $this->db->where('status', 1);
	   $this->db->order_by('permit_type_name', 'asc');
	   return $this->db->get();
	}
	
	public function get_supplier() {
	   $this->db->from('supplier');
	   $this->db->where('status', 1);
	   $this->db->order_by('supplier_name', 'asc');
	   return $this->db->get();
	}
	
	public function get_expence_type() {
	   $this->db->from('expence_type');
	   $this->db->where('status', 1);
	   $this->db->order_by('expence_type_name', 'asc');
	   return $this->db->get();
	}
	
	public function get_vendor() {
	   $this->db->from('vendor');
	   $this->db->where('vendor_type', "Vehicle");
	   $this->db->where('status', 1);
	   $this->db->order_by('vendor_name', 'asc');
	   return $this->db->get();
	}	
	public function get_driver_name() {
	   $this->db->from('employees');
	   $this->db->join('people', 'employees.person_id = people.person_id');
	   $this->db->where('employees.role',7);
	   $this->db->where('employees.deleted',0);
	   $this->db->order_by('first_name', 'asc');
	   return $this->db->get();
	}
	public function expence_exists($vehicle_data){
		$vehicle_id   = $vehicle_data['vehicle_id'];
		$expence_date = $vehicle_data['expence_date'];
		$expence_type = $vehicle_data['expence_type'];
		
		$this->db->from('expence');
		$this->db->where('vehicle_id', $vehicle_id);
		$this->db->where('expence_date', $expence_date);
		$this->db->where('expence_type', $expence_type);
		return $this->db->get()->num_rows();
	}
	public function expence_save(&$vehicle_data, $vehicle_id = FALSE){
		$count = $this->expence_exists($vehicle_data);
		if((int)$count === 0){
			return $this->db->insert('expence', $vehicle_data);
		}
		return false;
		
	}	
	public function expence_upd(&$vehicle_data, $expence_id = FALSE){
		$this->db->where('expence_id', $expence_id);
		return $this->db->update('expence', $vehicle_data);
	}
	public function get_expence_info($vehicle_id){
		$this->db->from('expence');		
		$this->db->join('expence_type', 'expence_type.expence_type_id = expence.expence_type','left');
		$this->db->join('supplier', 'supplier.supplier_id = expence.expence_supplier','left');
		$this->db->where('vehicle_id',$vehicle_id);
		$this->db->order_by('expence_id', 'desc');
		return $this->db->get()->result();
	}
	public function get_emi_info($vehicle_id){
		$this->db->from('emi');
		$this->db->where('vehicle_id',$vehicle_id);
		$this->db->order_by('emi_id', 'desc');
		return $this->db->get()->result();
	}
	public function emi_exists($vehicle_data){
		$vehicle_id   = $vehicle_data['vehicle_id'];
		$emi_from = $vehicle_data['emi_from'];
		$emi_to   = $vehicle_data['emi_to'];
		
		$this->db->from('emi');
		$this->db->where('vehicle_id', $vehicle_id);
		$this->db->where('emi_from', $emi_from);
		$this->db->where('emi_to', $emi_to);
		return $this->db->get()->num_rows();
	}
	public function emi_save(&$vehicle_data, $vehicle_id = FALSE){
		$count = $this->emi_exists($vehicle_data);
		if((int)$count === 0){
			return $this->db->insert('emi', $vehicle_data);
		}
		return false;
	}	
	public function emi_upd(&$vehicle_data, $emi_id = FALSE){
		$this->db->where('emi_id', $emi_id);
		return $this->db->update('emi', $vehicle_data);
	}
	public function doc_exists($vehicle_data){
		$doc_type   = $vehicle_data['doc_type'];
		$vehicle_id = $vehicle_data['vehicle_id'];
		$doc_from   = $vehicle_data['doc_from'];
		$doc_to     = $vehicle_data['doc_to'];
		
		$this->db->from('doc');
		$this->db->where('doc_type', $doc_type);
		$this->db->where('vehicle_id', $vehicle_id);
		$this->db->where('doc_from', $doc_from);
		$this->db->where('doc_to', $doc_to);
		return $this->db->get()->num_rows();
	}
	public function get_doc_info($vehicle_id){
		$this->db->from('doc');
		$this->db->where('vehicle_id',$vehicle_id);
		$this->db->order_by('doc_id', 'desc');
		return $this->db->get()->result();
	}
	public function doc_save(&$vehicle_data, $vehicle_id = FALSE){
		$count = $this->doc_exists($vehicle_data);
		if((int)$count === 0){
			$this->upd_vehicle_head($vehicle_data);
			return $this->db->insert('doc', $vehicle_data);
		}
		return false;		
	}	
	public function doc_upd(&$vehicle_data, $doc_id = FALSE){
		$this->upd_vehicle_head($vehicle_data);
		
		$this->db->where('doc_id', $doc_id);		
		return $this->db->update('doc', $vehicle_data);
	}
	public function upd_vehicle_head($vehicle_data){
		$vehicle_id = $vehicle_data['vehicle_id'];
		$doc_type   = $vehicle_data['doc_type'];
		$doc_from   = $vehicle_data['doc_from'];
		$doc_to     = $vehicle_data['doc_to'];
		
		
		$this->db->where('vehicle_id', $vehicle_id);
		if($doc_type === "FC"){
			return $this->db->update('vehicle', array('fc_date' => $doc_to));
		}else
		if($doc_type === "Permite"){
			return $this->db->update('vehicle', array('permit_date' => $doc_to));
		}else
		if($doc_type === "Insurance"){
			return $this->db->update('vehicle', array('insur_date' => $doc_to));
		}else
		if($doc_type === "Pollution"){
			return $this->db->update('vehicle', array('pollution_date' => $doc_to));
		}
	}
	
	public function get_mileage_info($vehicle_id){
		$this->db->from('mileage');
		$this->db->where('vehicle_id',$vehicle_id);
		$this->db->order_by('mileage_id', 'desc');
		return $this->db->get()->result();
	}
	public function mileage_save(&$vehicle_data, $vehicle_id = FALSE){
		$count = $this->doc_exists($vehicle_data);
		if((int)$count === 0){
			$this->upd_vehicle_head($vehicle_data);
			return $this->db->insert('mileage', $vehicle_data);
		}
		return false;		
	}	
	public function mileage_upd(&$vehicle_data, $doc_id = FALSE){		
		$this->db->where('mileage_id', $doc_id);		
		return $this->db->update('mileage', $vehicle_data);
	}
	public function mileage_exists($vehicle_data){
		$vehicle_id    = $vehicle_data['vehicle_id'];
		$mileage_from  = $vehicle_data['mileage_from'];
		$mileage_to    = $vehicle_data['mileage_to'];
		$mileage       = $vehicle_data['mileage'];
		
		$this->db->from('mileage');
		$this->db->where('vehicle_id', $vehicle_id);
		$this->db->where('mileage_from', $mileage_from);
		$this->db->where('mileage_to', $mileage_to);
		$this->db->where('mileage', $mileage);
		return $this->db->get()->num_rows();
	}
	
	
	/* Inserts or updates a vehicle */
	public function save_vehicle(&$vehicle_data, $vehicle_id = FALSE){
		if(!$vehicle_id || !$this->exists($vehicle_id, TRUE)){
			if($this->db->insert('vehicle', $vehicle_data)){
				$vehicle_data['vehicle_id'] = $this->db->insert_id();
				return TRUE;
			}
			return FALSE;
		}
		$this->db->where('vehicle_id', $vehicle_id);
		return $this->db->update('vehicle', $vehicle_data);

	}

	public function delete_list($vehicle_id){
		$this->db->where_in('vehicle_id',$vehicle_id);
		return $this->db->update('vehicle',array('status'=>0,'deleted_by'=>$this->session->userdata('emp_id'),'deleted_date'=>date('Y-m-d h:i:s')));
	}

	public function get_multiple_info($cat_ids){
		$this->db->from('vehicle');
		$this->db->where_in('vehicle_id', $cat_ids);
		return $this->db->get()->result_array();
	}
}
?>