File: /var/www/html/pmw24/app/application/models/Mapi.php
<?php
class Mapi extends CI_Model {
function __construct(){
parent::__construct();
}
public function insert($table,$data){
$this->db->insert($table,$data);
return $this->db->insert_id();
}
public function batch_insert($table,$data){
$this->db->insert_batch($table,$data);
return 1;
}
public function getDetails($table,$condition){
$this->db->where($condition);
$query=$this->db->get($table);
return $query->result_array();
}
public function getRow($table,$condition){
$this->db->where($condition);
$query=$this->db->get($table);
return $query->row_array();
}
public function checkUser($condition){
$this->db->where($condition);
$query=$this->db->get('admins');
return $query->row_array();
}
public function update($table,$condition,$data){
//print_r($condition);exit;
$this->db->where($condition);
$this->db->update($table,$data);
return 1;
}
public function getRows($table,$condition,$orderby_col=NULL){
$this->db->where($condition);
$this->db->order_by($orderby_col, "desc");
if(isset($limit)){
$this->db->limit($limit);
}
$query=$this->db->get($table);
return $query->result_array();
}
public function getJobList($table,$condition){
$this->db->where('is_applied',0);
$this->db->where($condition);
if(isset($limit)){
$this->db->limit($limit);
}
$query=$this->db->get($table);
return $query->result_array();
}
public function delete($table,$condition){
$this->db->where($condition);
$this->db->delete($table);
return true;
}
public function onGoiningJobList($condition)
{
$results=array();
$this->db->select('job.*');
$this->db->from('assign_job');
$this->db->join('job','job.job_id=assign_job.job_id','INNER');
$this->db->join('job_service_date','job_service_date.job_id=assign_job.job_id','left');
$this->db->where($condition);
$this->db->group_by('job.job_id');
$this->db->order_by('job_service_date.service_date', 'DESC');
$query=$this->db->get();
$results=$query->result_array();
//echo $this->db->last_query();exit;
return $results;
}
public function onGoiningJobDetails($condition)
{
$results=array();
$this->db->select('job.*');
$this->db->from('assign_job');
$this->db->join('job','job.job_id=assign_job.job_id','INNER');
$this->db->join('job_service_date','job_service_date.job_id=assign_job.job_id','left');
$this->db->where($condition);
$query=$this->db->get();
$results=$query->row_array();
//echo $this->db->last_query();exit;
return $results;
}
public function myJobList($condition)
{
$results=array();
$this->db->select('*');
$this->db->from('job');
$this->db->join('users_job','users_job.job_id=job.job_id','left');
$this->db->where($condition);
$this->db->order_by('job.job_date', 'DESC');
$query=$this->db->get();
$results=$query->result_array();
return $results;
}
public function getUserjobList($condition)
{
$results=array();
$this->db->select('*');
$this->db->from('job');
$this->db->join('users_job','users_job.job_id=job.job_id','left');
$this->db->join('users','users.user_id=users_job.user_id','left');
$this->db->join('devices','devices.user_id=users_job.user_id','left');
$this->db->where($condition);
$query=$this->db->get();
$results=$query->result_array();
return $results;
}
public function getUserTimeSlot($user_id,$start_date,$end_date)
{
$results=array();
$this->db->select('*');
$this->db->from('user_time_slot');
$this->db->where('user_id', $user_id);
$this->db->where('date >=', $start_date);
$this->db->where('date <=', $end_date);
$query=$this->db->get();
//echo $this->db->last_query();exit;
$results=$query->result_array();
return $results;
}
public function getServices($job_id){
$this->db->from("job_services");
$this->db->join('service','service.service_id=job_services.service_id','left');
$this->db->where('job_id',$job_id);
$this->db->where('service.status',1);
$query=$this->db->get();
return $query->result_array();
}
public function getRequestedServices($booking_request_id){
$this->db->from("booking_request_services");
$this->db->join('service','service.service_id=booking_request_services.service_id','left');
$this->db->where('booking_request_id',$booking_request_id);
$this->db->where('service.status',1);
$query=$this->db->get();
return $query->result_array();
}
public function jobHostoryDetails($job_id)
{
$this->db->select('mechanic_job_task.*,service.service_name,task.task_name');
$this->db->from("mechanic_job_task");
$this->db->join('service','service.service_id=mechanic_job_task.service_id','left');
$this->db->join('task','task.task_id=mechanic_job_task.task_id','left');
$this->db->where('mechanic_job_task.job_id',$job_id);
//$this->db->where('mechanic_job_task.service_id',$service_id);
$query=$this->db->get();
return $query->result_array();
}
public function searchJobHistory($mechanic_id,$car_id,$start_date,$end_date)
{
$this->db->select('*');
$this->db->from("assign_job");
$this->db->join('job','job.job_id=assign_job.job_id','left');
$this->db->join('job_service_date','job_service_date.job_id=job.job_id','left');
//$this->db->where("mechanic_id",$mechanic_id);
$this->db->where("job.car_id",$car_id);
$this->db->where("job_service_date.service_end_date>=",$start_date);
$this->db->where("job_service_date.service_end_date<=",$end_date);
$query=$this->db->get();
return $query->result_array();
}
public function jobHostoryDetailswithServiceId($job_id,$service_id)
{
$this->db->select('*');
$this->db->from("mechanic_job_task");
$this->db->where('mechanic_job_task.job_id',$job_id);
$this->db->where('mechanic_job_task.service_id',$service_id);
$query=$this->db->get();
return $query->result_array();
}
public function assignedJob($condition)
{
$this->db->select('*');
$this->db->from("assign_job");
$this->db->join('job','job.job_id=assign_job.job_id','LEFT');
$this->db->where($condition);
$query=$this->db->get();
return $query->result_array();
}
public function getRowLast($table,$condition){
$this->db->from($table);
$this->db->where($condition);
$this->db->order_by("job_service_date_id", "desc");
$this->db->limit(1, 0);
$query = $this->db->get();
return $query->row_array();
}
public function getRowLastInv($table,$condition,$orderby_col=NULL){
$this->db->from($table);
$this->db->where($condition);
$this->db->order_by($orderby_col, "desc");
$this->db->limit(1, 0);
$query = $this->db->get();
return $query->row_array();
}
public function carList(){
$this->db->select('car.*,customer.*,CASE WHEN customer.customer_type ="B" THEN customer.business_name ELSE ifnull(CONCAT(customer.first_name," ",CASE WHEN customer.middle_name IS NULL THEN "" ELSE CONCAT(customer.middle_name," ") END,ifnull(customer.last_name,"")),"") END as name,ifnull(customer.mobile,"") as contact_no');
$this->db->from('car');
$this->db->join('customer','customer.customer_id = car.customer_id','left');
$this->db->order_by('car.car_no','asc');
$query=$this->db->get();
//echo $this->db->last_query();exit;
return $query->result_array();
}
}