245 lines
9.4 KiB
PHP
Executable File
245 lines
9.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
use App\Models\Driver_model;
|
|
|
|
|
|
class Driver extends BaseController
|
|
{
|
|
protected $driver_model;
|
|
protected $session;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->driver_model = new Driver_model();
|
|
$this->session = session();
|
|
helper('form');
|
|
$this->isLoggedIn();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$data['driver_list'] = $this->driver_model->useDriverTable()->getDriverList();
|
|
$this->global['pageTitle'] = 'Driver List';
|
|
$this->loadViews("driverListing", $this->global, $data, NULL);
|
|
}
|
|
|
|
/**
|
|
* This function is used to add/edit driver details
|
|
*/
|
|
public function fetchDriverDetails() {
|
|
|
|
$id = $this->request->getPost('driver_id');
|
|
log_message('error', 'driver_id: ' . $id);
|
|
$Name = $this->request->getPost('driver_name');
|
|
$Mobile = $this->request->getPost('driver_mobile');
|
|
$userId = $this->session->get('userId');
|
|
|
|
|
|
$data = ['status' => false, 'message' => 'An error occurred while creating driver details'];
|
|
|
|
if ((int)$id == 0) {
|
|
log_message('error', 'LAST DriverID : ' . $id);
|
|
$driver_details = [
|
|
'driver_name' => $Name,
|
|
'driver_mobile' => $Mobile,
|
|
'created_by' => $userId,
|
|
];
|
|
$this->driver_model->useDriverTable()->insert($driver_details);
|
|
$insertedId = $this->driver_model->insertID();
|
|
if ($insertedId > 0) {
|
|
$data = ['status' => true, 'message' => 'Driver details created successfully.'];
|
|
}
|
|
} else {
|
|
$driver_details = [
|
|
'driver_id' => $id,
|
|
'driver_name' => $Name,
|
|
'driver_mobile' => $Mobile,
|
|
'updated_by' => $userId,
|
|
];
|
|
$this->driver_model->useDriverTable()->update($id, $driver_details);
|
|
|
|
if ($this->driver_model->affectedRows() > 0) {
|
|
$data = ['status' => true, 'message' => "Driver details updated successfully."];
|
|
}
|
|
|
|
}
|
|
|
|
return $this->response->setJSON($data);
|
|
}
|
|
|
|
/**
|
|
* reactive the driver details isactive - 0 into 1
|
|
*/
|
|
public function reActivateDriver(){
|
|
|
|
$driverId = $_GET['driverId'];
|
|
if(!empty($driverId)){
|
|
$data = ['isactive' => 1,'updated_by' => $this->session->get('userId')];
|
|
$this->driver_model->useDriverTable()->update($driverId, $data);
|
|
if ($this->driver_model->affectedRows() > 0) {
|
|
// $data = ['status' => true, 'message' => 'Successfully updated driver details'];
|
|
$message = "Driver details deleted successfully.";
|
|
}
|
|
}else{
|
|
$message = "Driver details not available.";
|
|
}
|
|
$this->session->setFlashdata('success', $message);
|
|
return redirect()->route('DriverListing');
|
|
|
|
}
|
|
|
|
/**
|
|
* delete the driver details
|
|
*/
|
|
function deleteDriver($driverId = NULL)
|
|
{
|
|
|
|
$driverId = $driverId ?? $_GET['driverId'];
|
|
if(!empty($driverId)){
|
|
$data = ['isactive' => 0,'updated_by' => $this->session->get('userId')];
|
|
$this->driver_model->useDriverTable()->update($driverId, $data);
|
|
$message = ($this->driver_model->affectedRows() > 0) ? "Driver deleted successfully." : "Driver already deleted.";
|
|
}else{
|
|
$message = "Driver details not available.";
|
|
}
|
|
$this->session->setFlashdata('success', $message);
|
|
return redirect()->route('DriverListing');
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* check Driver mobile number Exsiting or not
|
|
*/
|
|
function checkDriver(){
|
|
|
|
$data = $this->request->getPost();
|
|
|
|
$Id = $data['DriverId'];
|
|
$Mobile = $data['DriverMobile'];
|
|
$mobile = str_replace(' ', '', $Mobile);
|
|
$results = $this->driver_model->useDriverTable()
|
|
->select('driver_mobile, driver_name, isactive')
|
|
->where('driver_id !=', $Id)
|
|
->where('REPLACE(driver_mobile, " ", "")', $mobile)
|
|
->get()
|
|
->getResult();
|
|
|
|
return $this->response->setJSON($results);
|
|
}
|
|
|
|
public function loadDriverAttendance()
|
|
{
|
|
|
|
$input_driver_id = $this->request->getPost('gobal_driver_id') ? $this->request->getPost('gobal_driver_id') : $this->request->getGet('gobal_driver_id');
|
|
$input_month_year = $this->request->getPost('month_year') ? $this->request->getPost('month_year') : $this->request->getGet('month_year');
|
|
list($month, $year) = explode('-', $input_month_year);
|
|
|
|
$month_in_number = get_date_time_dynamical_format('M','m',"$month");// refer helper
|
|
$get_last_date_of_the_month = cal_days_in_month(CAL_GREGORIAN, $month_in_number, $year);
|
|
$from_mysql_date = get_date_time_dynamical_format('d-m-Y','Y-m-d',"01-$month_in_number-$year");
|
|
$to_mysql_date = get_date_time_dynamical_format('d-m-Y','Y-m-d',"$get_last_date_of_the_month-$month_in_number-$year");
|
|
$indian_date = get_date_time_dynamical_format('d-m-Y','d-m-Y',"$get_last_date_of_the_month-$month_in_number-$year");
|
|
$data['driver_attendance_list'] = $this->driver_model->useDriverAttendanceTable()->getDriverAttendanceList($input_driver_id,$from_mysql_date,$to_mysql_date);
|
|
$data['page_driver_name'] = $this->driver_model->getDriverName($input_driver_id);
|
|
$data['invoice_info'] = $this->driver_model->getInvoiceInfo();
|
|
$data['datefordropdown'] = $input_month_year;
|
|
$data['gobal_driver_id'] = $input_driver_id;
|
|
|
|
$this->global['pageTitle'] = 'Driver Attendance List';
|
|
$this->loadViews("driverAttendance", $this->global, $data, NULL);
|
|
}
|
|
|
|
public function fetchDriverAttendanceDetails(){
|
|
$userId = $this->session->get('userId');
|
|
|
|
$id = $this->request->getPost('driver_attendance_id');
|
|
$date = $this->request->getPost('date');
|
|
$driver_id = $this->request->getPost('driver_id');
|
|
$inv = $this->request->getPost('invoice_number');
|
|
$veh = $this->request->getPost('vehicle_number');
|
|
$load = $this->request->getPost('load_type');
|
|
$sal = $this->request->getPost('salary_amount');
|
|
$food = $this->request->getPost('food_amount');
|
|
|
|
|
|
|
|
$data = ['status' => false, 'message' => 'An error occurred while creating driver Trip details'];
|
|
|
|
if ((int)$id == 0) {
|
|
log_message('error', 'LAST DriverID : ' . $id);
|
|
$driver_details = [
|
|
'date' => $date,
|
|
'driver_id' =>$driver_id,
|
|
'invoice_number' =>$inv,
|
|
'vehicle_number' =>$veh,
|
|
'load_type' =>$load,
|
|
'salary_amount' => $sal,
|
|
'food_amount' =>$food,
|
|
'created_by' => $userId,
|
|
];
|
|
$this->driver_model->useDriverAttendanceTable()->insert($driver_details);
|
|
$insertedId = $this->driver_model->insertID();
|
|
if ($insertedId > 0) {
|
|
$data = ['status' => true, 'message' => 'Driver trip details created successfully.'];
|
|
}
|
|
} else {
|
|
$driver_details = [
|
|
|
|
'driver_attendance_id' => $id,
|
|
'date' => $date,
|
|
'driver_id' =>$driver_id,
|
|
'invoice_number' =>$inv,
|
|
'vehicle_number' =>$veh,
|
|
'load_type' =>$load,
|
|
'salary_amount' => $sal,
|
|
'food_amount' =>$food,
|
|
'updated_by' => $userId,
|
|
];
|
|
$this->driver_model->useDriverAttendanceTable()->update($id, $driver_details);
|
|
|
|
if ($this->driver_model->affectedRows() > 0) {
|
|
$data = ['status' => true, 'message' => 'Driver trip details updated successfully.'];
|
|
}
|
|
|
|
}
|
|
|
|
return $this->response->setJSON($data);
|
|
}
|
|
|
|
|
|
/**
|
|
* delete the driver Attendance details
|
|
*/
|
|
function deleteDriverAttendance()
|
|
{
|
|
$driverId = $this->request->getGet('gobal_driver_id') ? $this->request->getGet('gobal_driver_id') : '';
|
|
$driverAttendanceId = $this->request->getGet('driverAttendanceId') ? $this->request->getGet('driverAttendanceId') : '';
|
|
$monthyear = $this->request->getGet('month_year') ?? date('M-Y');
|
|
|
|
if(!empty($driverAttendanceId)){
|
|
$data = ['isactive' => 0,'updated_by' => $this->session->get('userId')];
|
|
$this->driver_model->useDriverAttendanceTable()->update($driverAttendanceId, $data);
|
|
$message = ($this->driver_model->affectedRows() > 0) ? "Driver trip deleted successfully." : "Driver trip already deleted.";
|
|
}else{
|
|
$message = "Driver trip details not available.";
|
|
}
|
|
$this->session->setFlashdata('success', $message);
|
|
// return redirect()->to(current_url());
|
|
// return redirect()->route('loadDriverAttendance');
|
|
return redirect()->to(base_url('loadDriverAttendance?gobal_driver_id=' . $driverId . '&month_year=' . $monthyear));
|
|
|
|
|
|
}
|
|
|
|
function gatheredCustAndQty(){
|
|
$data = $this->request->getPost();
|
|
$invoice = $data['invoiceNumber'];
|
|
$results = $this->driver_model->gatheredCustAndQty($invoice);
|
|
return $this->response->setJSON($results);
|
|
}
|
|
} |