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); } 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; } } $data['monthinputs'] = $attendance_data; $data['dropdownvalue'] = $current; // dd($data['monthinputs']); $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 "; } }