590 lines
20 KiB
PHP
Executable File
590 lines
20 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
use App\Models\Driver_model;
|
|
use Mpdf\Mpdf;
|
|
|
|
|
|
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->getGet('gobal_driver_id');
|
|
// $input_month_year = $this->request->getPost('month_year') ? $this->request->getPost('month_year') : get_date_time_dynamical_format('d-M-Y','d-m-',"01-"+$this->request->getGet('month_year')) ;
|
|
$input_date = $this->request->getGet('date')
|
|
? $this->request->getGet('date')
|
|
: get_date_time_dynamical_format('d-M-Y','d-m-Y',"01-".$this->request->getGet('month_year'));
|
|
|
|
|
|
list($date,$month,$year) = explode('-', $input_date);
|
|
|
|
$get_last_date_of_the_month = cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
|
$from_mysql_date = get_date_time_dynamical_format('d-m-Y','Y-m-d',"01-$month-$year");
|
|
$to_mysql_date = get_date_time_dynamical_format('d-m-Y','Y-m-d',"$get_last_date_of_the_month-$month-$year");
|
|
$indian_date = get_date_time_dynamical_format('d-m-Y','d-m-Y',"$get_last_date_of_the_month-$month-$year");
|
|
|
|
$amount = $this->driver_model->getDriverAttendanceTable($input_driver_id,"$year-$month");
|
|
|
|
$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,0);
|
|
$data['invoice_info'] = $this->driver_model->getInvoiceInfo();
|
|
$data['datefordropdown'] = $input_date;
|
|
$data['gobal_driver_id'] = $input_driver_id;
|
|
$data['gobal_diesel_amount'] = isset($amount->diesel_amount) ? $amount->diesel_amount : 0 ;
|
|
$data['gobal_shed_amount'] = isset($amount->shed_amount) ? $amount->shed_amount : 0 ;
|
|
|
|
$this->global['pageTitle'] = 'Driver Attendance List';
|
|
$this->loadViews("driverAttendance", $this->global, $data, NULL);
|
|
}
|
|
public function updateDieselAndShedValuesBasedonEmpID(){
|
|
$arr = $this->request->getPost();
|
|
$userId = $this->session->get('userId');
|
|
$to_mysql_date = get_date_time_dynamical_format('d-m-Y','Y-m',$arr['date']);
|
|
|
|
$update_arr = ['driver_id' =>$arr['empid'],$arr['column'] =>$arr['value'],'updated_by' => $userId];
|
|
$where_arr = ['DATE_FORMAT(t_driver_attendance.date, "%Y-%m")' =>$to_mysql_date,'t_driver_attendance.driver_id' =>$arr['empid']];
|
|
|
|
$data = $this->driver_model->updateDieselAndShedValuesBasedonEmpID($where_arr,$update_arr);
|
|
return $data;
|
|
// [column] => shed_amount
|
|
// [value] => 400
|
|
// [date] => 21-02-2025
|
|
// [empid] => RIPL136
|
|
|
|
|
|
}
|
|
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);
|
|
}
|
|
|
|
public function driverMonthlyPayInputs()
|
|
{
|
|
$current = $this->request->getGet('month_year') ? $this->request->getGet('month_year') : date("n-Y"); // for get - input header click and dropdown changes
|
|
|
|
list($month, $year) = explode('-', $current);
|
|
|
|
$month_in_number = get_date_time_dynamical_format('n','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");
|
|
|
|
// $data['monthinputs']
|
|
$attendance_data = $this->driver_model->driverAttendanceForMonthlyPayInputs($from_mysql_date,$to_mysql_date);
|
|
$format_month_year = get_date_time_dynamical_format('n-Y','m-Y',"$current");
|
|
|
|
$monthly_pay_data = $this->driver_model->driverMonthlyPayInputs($format_month_year);
|
|
// dd($attendance_data);
|
|
// dd($monthly_pay_data);
|
|
|
|
// both foreach refer with chatgpt array data replacement....
|
|
$monthly_pay_array = [];
|
|
foreach ($monthly_pay_data as $row) {
|
|
$monthly_pay_array[$row->driver_id] = $row;
|
|
}
|
|
|
|
foreach ($attendance_data as &$attendance) {
|
|
if (isset($monthly_pay_array[$attendance->driver_id])) {
|
|
// Replace values where data exists in driverMonthlyPayInputs2
|
|
$attendance->driver_earnings_amount = $monthly_pay_array[$attendance->driver_id]->driver_earnings_amount;
|
|
$attendance->diesel = $monthly_pay_array[$attendance->driver_id]->diesel;
|
|
$attendance->shed_duty_amount = $monthly_pay_array[$attendance->driver_id]->shed_duty_amount;
|
|
$attendance->driver_final_payment = $monthly_pay_array[$attendance->driver_id]->driver_final_payment;
|
|
$attendance->payroll_id = $monthly_pay_array[$attendance->driver_id]->payroll_id;
|
|
}
|
|
}
|
|
|
|
$data['monthinputs'] = $attendance_data;
|
|
$data['dropdownvalue'] = $current;
|
|
|
|
$this->global['pageTitle'] = 'Driver Monthly Inputs';
|
|
$this->loadViews("driverMonthlyPayInputs", $this->global, $data, NULL);
|
|
}
|
|
|
|
function saveMonthlyData()
|
|
{
|
|
|
|
$jsondata = (string)$this->request->getPost('param1');
|
|
|
|
$json = json_decode($jsondata, true);
|
|
|
|
$month = (string)$this->request->getPost('param2');
|
|
|
|
$formattedmonth = get_date_time_dynamical_format('n-Y','m-Y',"$month");
|
|
|
|
$total = 0;
|
|
|
|
foreach ($json as $index => $j) {
|
|
|
|
$ID = isset($j['Driver Id']) ? $j['Driver Id'] : '' ;
|
|
$NAME = isset($j['Driver Name']) ? $j['Driver Name'] : '' ;
|
|
$LOAD = isset($j['Number Of Load']) ? $j['Number Of Load'] : 0 ;
|
|
$SALARY = isset($j['Salary Amount ₹']) ? $j['Salary Amount ₹'] : 0.00 ;
|
|
$FOOD = isset($j['Food Amount ₹']) ? $j['Food Amount ₹'] : 0.00 ;
|
|
$TOTAL = isset($j['Total Amount ₹']) ? $j['Total Amount ₹'] : 0.00 ;
|
|
$DIESEL = isset($j['Diesel']) ? $j['Diesel'] : 0.00 ;
|
|
$SHED = isset($j['Shed Duty']) ? $j['Shed Duty'] : 0.00 ;
|
|
$GRAND = isset($j['Grand Total in ₹']) ? $j['Grand Total in ₹'] : 0.00;
|
|
$CREATED = $this->session->get('userId');
|
|
$UPDATED = $this->session->get('userId');
|
|
|
|
$monthlypaydata = array(
|
|
'month_year' => $formattedmonth,
|
|
'driver_id' =>$ID,
|
|
'driver_name' =>$NAME,
|
|
'no_of_loads' =>$LOAD,
|
|
'driver_monthly_salary_amount' =>$SALARY,
|
|
'driver_monthly_food_amount' =>$FOOD,
|
|
'driver_earnings_amount' =>$TOTAL,
|
|
'diesel' =>$DIESEL,
|
|
'shed_duty_amount' =>$SHED,
|
|
'driver_final_payment' =>$GRAND,
|
|
'created_by'=>$CREATED,
|
|
'updated_by'=>$UPDATED
|
|
|
|
);
|
|
|
|
$result = $this->driver_model->saveMonthlyData($monthlypaydata);
|
|
$total = $total + $result;
|
|
}
|
|
|
|
echo $total . "- Driver Updated Successfully ";
|
|
}
|
|
|
|
// payroll------->
|
|
public function viewGenerator()
|
|
{
|
|
|
|
$data['Payon'] = $this->driver_model->getPayOn();
|
|
|
|
$this->global['pageTitle'] = 'Payroll Generater';
|
|
|
|
$this->loadViews("driverPaySlipGenerate", $this->global, $data, NULL);
|
|
}
|
|
|
|
function getDriver()
|
|
{
|
|
$id = $this->request->getPost('id1');
|
|
|
|
$result = $this->driver_model->getDriverlist2($id);
|
|
|
|
$HTML = "";
|
|
|
|
if (count($result) > 0) {
|
|
|
|
foreach ($result as $list) {
|
|
|
|
$HTML .= "<option value='" . $list->driver_id . "'>" . $list->name . "</option>";
|
|
}
|
|
}
|
|
echo $HTML;
|
|
}
|
|
|
|
function checkDriverExistPay()
|
|
{
|
|
$driver = $this->request->getPost('driver');
|
|
$payon = $this->request->getPost('payon');
|
|
$result = $this->driver_model->checkDriverExistPay($driver, $payon);
|
|
echo json_encode(count($result));
|
|
}
|
|
|
|
public function driverPayslip()
|
|
{
|
|
|
|
$PayOn = $this->request->getPost('payon');
|
|
$Driver = $this->request->getPost('employee');
|
|
|
|
$res = $this->driver_model->getMonthlyPayDetails($Driver, $PayOn);
|
|
|
|
$result = $res[0];
|
|
|
|
$data = [
|
|
'PayOn' => $result->month_year,
|
|
'driver_id' => $result->driver_id,
|
|
'no_of_loads' => $result->no_of_loads,
|
|
'driver_monthly_salary_amount' => $result->driver_monthly_salary_amount,
|
|
'driver_earnings_amount' => $result->driver_earnings_amount,
|
|
'driver_final_payment' => $result->driver_final_payment,
|
|
'created_by' => $this->session->get('userId')
|
|
];
|
|
|
|
$insert = $this->driver_model->insertPayroll($data);
|
|
return $insert;
|
|
|
|
}
|
|
|
|
public function driverPrintPdf()
|
|
{
|
|
|
|
$filename = " ";
|
|
$html = "";
|
|
$All = $this->request->getPost('All');
|
|
$Payon = $this->request->getPost('PayOn');
|
|
$m = date("M", mktime(0, 0, 0, (int)$Payon, 10));
|
|
$y = substr((string)$Payon, 3);
|
|
|
|
|
|
if ($All != '') {
|
|
$filename = 'PayslipFor-' . $m . '-' . $y;
|
|
$result = $this->driver_model->getEmpAll($Payon);
|
|
|
|
if ($result > 0) {
|
|
for ($i = 0; $i < count($result); $i++) {
|
|
|
|
$EmpID = $result[$i]['EmpId'];
|
|
|
|
$Data['PayDetails'] = $this->driver_model->GetPayslipdata($Payon, $EmpID);
|
|
|
|
|
|
$totalsalary = $Data['PayDetails'][0]->TotalSalary;
|
|
$totalsalaryinwords = $this->convertNumberToWords(round($totalsalary));
|
|
$Data['amtinwords'] = $totalsalaryinwords;
|
|
|
|
|
|
$html .= view("driverPayslipGeneratePrint", $Data);
|
|
|
|
|
|
}
|
|
}
|
|
} else {
|
|
$EmpID = $this->request->getPost('Driver');
|
|
|
|
$Data['PayDetails'] = $this->driver_model->GetPayslipdata($Payon, $EmpID);
|
|
|
|
$name = $Data['PayDetails'][0]->name;
|
|
$filename = 'PayslipFor-' . $EmpID . ' ' . $name . ' ' . $m . ' ' . $y;
|
|
|
|
$totalsalary = $Data['PayDetails'][0]->driver_final_payment;
|
|
$totalsalaryinwords = $this->convertNumberToWords(round($totalsalary));
|
|
$Data['amtinwords'] = $totalsalaryinwords;
|
|
// print_r ($Data);exit();
|
|
// echo view("driverPayslipGeneratePrint", $Data);die;
|
|
$html = view("driverPayslipGeneratePrint", $Data);
|
|
}
|
|
|
|
|
|
$mpdf = new Mpdf([
|
|
'mode' => 'utf-8',
|
|
'format' => 'A4-P',
|
|
'margin_left' => 10,
|
|
'margin_right' => 10,
|
|
'margin_top' => 10,
|
|
'margin_bottom' => 10,
|
|
'margin_header' => 10,
|
|
'margin_footer' => 6,
|
|
'setAutoTopMargin' => 'stretch',
|
|
'setAutoBottomMargin' => 'stretch'
|
|
]);
|
|
$mpdf->SetDisplayMode('fullpage');
|
|
// $mpdf->SetHTMLHeader($HtmlHeading);
|
|
$mpdf->setFooter("Page {PAGENO} of {nb}");
|
|
$mpdf->list_indent_first_level = 1;
|
|
$mpdf->WriteHTML($html);
|
|
$mpdf->SetTitle('Resico:DriverPayslip');
|
|
|
|
$mpdf->Output("driverPayslip-" . $filename . ".pdf", 'D');
|
|
|
|
}
|
|
|
|
function convertNumberToWords($number) {
|
|
$numberWords = [
|
|
0 => "Zero",
|
|
1 => "One",
|
|
2 => "Two",
|
|
3 => "Three",
|
|
4 => "Four",
|
|
5 => "Five",
|
|
6 => "Six",
|
|
7 => "Seven",
|
|
8 => "Eight",
|
|
9 => "Nine",
|
|
10 => "Ten",
|
|
11 => "Eleven",
|
|
12 => "Twelve",
|
|
13 => "Thirteen",
|
|
14 => "Fourteen",
|
|
15 => "Fifteen",
|
|
16 => "Sixteen",
|
|
17 => "Seventeen",
|
|
18 => "Eighteen",
|
|
19 => "Nineteen",
|
|
20 => "Twenty",
|
|
30 => "Thirty",
|
|
40 => "Forty",
|
|
50 => "Fifty",
|
|
60 => "Sixty",
|
|
70 => "Seventy",
|
|
80 => "Eighty",
|
|
90 => "Ninety"
|
|
];
|
|
|
|
if ($number == 0) {
|
|
return $numberWords[0];
|
|
}
|
|
|
|
$word = '';
|
|
|
|
if ($number >= 10000000) {
|
|
$crore = floor($number / 10000000);
|
|
if ($crore > 0) {
|
|
$word .= $this->convertNumberToWords($crore) . " Crore ";
|
|
}
|
|
$number %= 10000000;
|
|
}
|
|
|
|
if ($number >= 100000) {
|
|
$lakh = floor($number / 100000);
|
|
if ($lakh > 0) {
|
|
$word .= $this->convertNumberToWords($lakh) . " Lakh ";
|
|
}
|
|
$number %= 100000;
|
|
}
|
|
|
|
if ($number >= 1000) {
|
|
$thousand = floor($number / 1000);
|
|
if ($thousand > 0) {
|
|
$word .= $this->convertNumberToWords($thousand) . " Thousand ";
|
|
}
|
|
$number %= 1000;
|
|
}
|
|
|
|
if ($number >= 100) {
|
|
$hundred = floor($number / 100);
|
|
if ($hundred > 0) {
|
|
$word .= $this->convertNumberToWords($hundred) . " Hundred ";
|
|
}
|
|
$number %= 100;
|
|
}
|
|
|
|
if ($number > 0) {
|
|
if ($word !== '') {
|
|
$word .= "and ";
|
|
}
|
|
if ($number <= 20) {
|
|
$word .= $numberWords[$number];
|
|
} else {
|
|
$word .= $numberWords[floor($number / 10) * 10];
|
|
if ($number % 10 > 0) {
|
|
$word .= " " . $numberWords[$number % 10];
|
|
}
|
|
}
|
|
}
|
|
|
|
return trim($word);
|
|
}
|
|
|
|
|
|
} |