HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //var/www/html/qcr24/app/application/models/admin/Mfinetoll_fees.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Mfinetoll_fees extends CI_Model {

    public function __construct() {
        parent::__construct();

    }

    public function getFinetoll_fees($where=''){
        $this->db->select('ff.*,md.first_name,md.middle_name,md.last_name,mdep.department_name');
        $this->db->from('finetoll_fees ff');
        $this->db->join('master_driver md','md.driver_id=ff.driver_id','inner');
        $this->db->join('master_department mdep','mdep.department_id=ff.department_id','inner');
        if(!empty($where)){
            $this->db->where('ff.finetoll_fees_id',$where);
            $query=$this->db->get();
            return $query->row_array();
        }else{ 
            $this->db->order_by('ff.finetoll_fees_id','desc');
            $query=$this->db->get();
            return $query->result_array();
        }
    }

    public function get_driver(){
        $this->db->select('md.*');
        $this->db->from('master_driver md');
        $this->db->where('md.status','1');
        $query=$this->db->get();
        return $query->result_array();
    }

    public function get_car(){
        $this->db->select('a.*');
        $this->db->from('master_car a');
        $this->db->where('a.status <>','2');
        $this->db->order_by('a.car_id','desc');
		/*$this->db->group_by('car_name');*/
        $query=$this->db->get();
        return $query->result_array();
    }

    public function get_department(){
        $this->db->select('a.*,1 department_count');
        $this->db->from('master_department a');
        $this->db->where('status <>','2');
		/*$this->db->group_by('department_name');*/
        $query=$this->db->get();
        return $query->result_array();
    }

    public function getDriverDetails($driver_id){
        $this->db->select('md.driver_id,concat(md.first_name," ",md.middle_name," ",md.last_name) AS driver_name,concat(md.flat_no," ",md.street_no," ",md.street_name," ",md.suburb) AS address,md.email,md.mobile,md.licence_no,DATE_FORMAT(md.dob, "%d/%m/%Y") AS dob,md.pin');
        $this->db->from('master_driver md');
        $this->db->where('md.driver_id',$driver_id);
        $query=$this->db->get();
        return $query->row_array();
    }

    public function getRentOutDriver($referance_date,$car_id){
        $this->db->select('rov.driver_id,concat(md.first_name," ",md.middle_name," ",md.last_name) AS driver_name,concat(md.flat_no," ",md.street_no," ",md.street_name," ",md.suburb) AS address,md.email,md.mobile,md.licence_no,DATE_FORMAT(md.dob, "%d/%m/%Y") AS dob,md.pin,DATEDIFF("'.$referance_date.'",rov.created_ts) as rent_out_days');
        $this->db->from('rent_out_vehcile rov');
        $this->db->join('master_driver md','md.driver_id=rov.driver_id','inner');
        $this->db->join('rent_in_vehcile riv','riv.rent_out_id=rov.rent_out_id','left');
        $this->db->where('rov.car_id',$car_id);
        $this->db->where("CASE WHEN riv.rent_in_id > 0 THEN '".$referance_date."' BETWEEN `rov`.`created_ts` AND riv.created_ts ELSE `rov`.`created_ts` <= '".$referance_date."' END",null,false);
        $this->db->order_by('rent_out_days', 'ASC');
        $this->db->limit(1);
        $query=$this->db->get();
        //echo $this->db->last_query();die;
        return $query->row_array();
    }

    public function getRentinDetails($where=''){
        $this->db->select('riv.*,md.first_name,md.middle_name,md.last_name,DATE_FORMAT(rov.created_ts, "%d/%m/%Y") AS rent_out_date,rov.rent_out_no,rov.odometer_reading AS rent_out_odometer_reading,mc.car_no');
        $this->db->from('rent_in_vehcile riv');
        $this->db->join('rent_out_vehcile rov','rov.rent_out_id=riv.rent_out_id');
        $this->db->join('master_driver md','md.driver_id=riv.driver_id');
        $this->db->join('master_car mc','mc.car_id=rov.car_id');
        if(!empty($where)){
            $this->db->where('riv.rent_in_id',$where);
            $query=$this->db->get();
            return $query->row_array();
        }else{ 
            $query=$this->db->get();
            return $query->result_array();
        }
    }

    public function getRentoutDetails($driver_id,$rent_out_id){
        $this->db->select('rov.*,DATE_FORMAT(rov.created_ts, "%d/%m/%Y") AS rent_out_date,mc.car_no');
        $this->db->from('rent_out_vehcile rov');       
        $this->db->join('master_car mc','mc.car_id=rov.car_id','inner');
        $this->db->where('rov.driver_id',$driver_id);
        $this->db->where('rov.rent_out_id',$rent_out_id);
        $query=$this->db->get();
        return $query->row_array();
        
    }

    public function submitfinetoll_fees($data){
        $this->db->insert('finetoll_fees', $data);
        return $this->db->insert_id();
    }

    public function update_finetoll_fees($condition,$data){
        $result=$this->db->update('finetoll_fees', $data, $condition);
        return $result;
    }

    public function update_rentin($condition,$data){
        $result=$this->db->update('rent_in_vehcile', $data, $condition);
        return $result;
    }

}