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/nt/application/models/admin/Mcar.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Mcar extends CI_Model {

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

    }

    public function getCarData() {
        // Select active industrial parks from the database
        $this->db->select('car_master.*');
        $this->db->where('status', 1);
        $query = $this->db->get('car_master');

        // Return the result as an array
        return $query->result_array();
    }
    public function getCardetailsByCarId($carId) {
        // Select active industrial parks from the database
        $this->db->select('car_master.*');
        $this->db->where('car_id', $carId);
        $query = $this->db->get('car_master');

        // Return the result as an array
        return $query->row();
    }

    public function saveCarData($data) {
        $this->db->insert('car_master', $data);
        // echo $this->db->last_query(); die;
        return $this->db->insert_id();
    }

    public function checkExistingCar($data) {
        $this->db->select('car_master.*');
        $this->db->where('taxi_number', $data["taxi_number"]);
        if($data["terminal"] != ''){
            $this->db->where('terminal', $data["terminal"]);
        }
        $query = $this->db->get('car_master');
        return $query->num_rows();
    }

    public function savePlotDetail($data) {
        $this->db->insert('plot_detail', $data);
    }

    public function saveBoundaryDetail($data) {
        $this->db->insert('boundary_detail', $data);
    }

    public function getAllCarData() {
        $this->db->select('car_master.*');
        $this->db->from('car_master');
        $query = $this->db->get();
    
        // Return results as array
        return $query->result_array();
    }

    public function updateCarData($carData, $carId) {
        $this->db->where('car_id', $carId);
        $this->db->update('car_master', $carData);
        return 1;
    }

    public function getPlotDetails($plotHeaderId) {
        // Join plot_header with industrial_park_master to get park_name
        $this->db->select('plot_header.*, industrial_park_master.park_name,uom_master.name as uom_name');
        $this->db->from('plot_header');
        $this->db->join('industrial_park_master', 'plot_header.industrial_park_id = industrial_park_master.industrial_park_id');
        $this->db->join('uom_master', 'plot_header.uom_id = uom_master.uom_id');

        $this->db->where('plot_header.plot_header_id', $plotHeaderId);
        $plotDetails = $this->db->get()->row_array();
 
        // Fetch plot_details for the given plot_header_id
        $this->db->select('*');
        $this->db->from('plot_detail');
        $this->db->where('plot_header_id', $plotHeaderId);
        $plotDetails['plot_details'] = $this->db->get()->result_array();
    
        // Fetch boundary_details if exists
        $this->db->select('*');
        $this->db->from('boundary_detail');
        $this->db->where('plot_header_id', $plotHeaderId);
        $boundaryDetails = $this->db->get()->result_array();
    
        if (!empty($boundaryDetails)) {
            $plotDetails['boundary_details'] = $boundaryDetails;
        }
        return $plotDetails;
    }
    
    public function updatePlotHeader($plotHeaderId, $plotHeaderData) {
        // Update plot header details with the specified plot header ID
        $this->db->where('plot_header_id', $plotHeaderId);
        $this->db->update('plot_header', $plotHeaderData);
    }

    public function deletePlotDetails($plotHeaderId) {
        // Delete existing plot details associated with the specified plot header ID
        $this->db->where('plot_header_id', $plotHeaderId);
        $this->db->delete('plot_detail');
    }

    public function deleteBoundaryDetails($plotHeaderId) {
        // Delete existing boundary details associated with the specified plot header ID
        $this->db->where('plot_header_id', $plotHeaderId);
        $this->db->delete('boundary_detail');
    }
    
    
}