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' => 'Successfully created driver details']; } } 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' => 'Successfully updated driver details']; } } 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 = 'Successfully Updated Driver details'; } }else{ $message = "Driver details Not Avalable"; } $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 States"; }else{ $message = "Driver details Not Avalable"; } $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('driverId') ? $this->request->getGet('driverId') : ''; $input_driver_id = $this->request->getPost('driver_id') ? $this->request->getPost('driver_id') : $this->request->getGet('driverId'); // echo($input_driver_id); $input_month_year = $this->request->getPost('monthyear') ? $this->request->getPost('monthyear') : date('M-Y'); 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['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' => 'Successfully created driver Trip details']; } } 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' => 'Successfully updated driver Trip details']; } } return $this->response->setJSON($data); } /** * reactive the driver Attendance details isactive - 0 into 1 */ public function reActivateDriverAttendance(){ $driverAttendanceId = $_GET['driverAttendanceId']; $driverId = $_GET['driverId']; if(!empty($driverAttendanceId)){ $data = ['isactive' => 1,'updated_by' => $this->session->get('userId')]; $this->driver_model->useDriverAttendanceTable()->update($driverAttendanceId, $data); if ($this->driver_model->affectedRows() > 0) { // $data = ['status' => true, 'message' => 'Successfully updated Driver Trip details']; $message = 'Successfully Updated Driver Trip details'; } }else{ $message = "Driver Trip details Not Avalable"; } $this->session->setFlashdata('success', $message); return redirect()->to(current_url()); // return redirect()->route('loadDriverAttendance'); // return redirect()->to(base_url('loadDriverAttendance?driverId=' . $driverId)); } /** * delete the driver Attendance details */ function deleteDriverAttendance() { $driverId = $this->request->getGet('driverId') ? $this->request->getGet('driverId') : ''; $driverAttendanceId = $this->request->getGet('driverAttendanceId') ? $this->request->getGet('driverAttendanceId') : ''; // echo "*****"; // echo $driverAttendanceId."**"; // echo "-------------"; // die; 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 States"; }else{ $message = "Driver Trip details Not Avalable"; } $this->session->setFlashdata('success', $message); // return redirect()->to(current_url()); return redirect()->route('loadDriverAttendance'); // return redirect()->to(base_url('loadDriverAttendance?driverId=' . $driverId)); } function gatheredCustAndQty(){ $data = $this->request->getPost(); $invoice = $data['invoiceNumber']; $results = $this->driver_model->gatheredCustAndQty($invoice); return $this->response->setJSON($results); } }