diff --git a/app/Config/Routes.php b/app/Config/Routes.php index bb47a222..93f75b0c 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -83,13 +83,15 @@ $routes->post('fetchDriverDetails', 'Driver::fetchDriverDetails');// for Ajax bo $routes->get('reActivateDriver', 'Driver::reActivateDriver'); $routes->get('deleteDriver', 'Driver::deleteDriver'); $routes->post('checkDriver', 'Driver::checkDriver'); - +// Driver Trip Routes $routes->match(['GET', 'POST'], 'loadDriverAttendance', 'Driver::loadDriverAttendance'); $routes->post('fetchDriverAttendanceDetails', 'Driver::fetchDriverAttendanceDetails'); $routes->get('reActivateDriverAttendance', 'Driver::reActivateDriverAttendance'); $routes->get('deleteDriverAttendance', 'Driver::deleteDriverAttendance'); $routes->post('gatheredCustAndQty', 'Driver::gatheredCustAndQty'); - +// Driver Monthly Pay Inputs Routes +$routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'driverMonthlyPayInputs', 'Driver::driverMonthlyPayInputs'); +$routes->post('saveMonthlyData', 'Driver::saveMonthlyData'); // Asset Detail Routes $routes->get('assetListing', 'Assetdetails::assetListing'); $routes->get('addasset', 'Assetdetails::addasset'); diff --git a/app/Controllers/Driver.php b/app/Controllers/Driver.php index 4d4e484a..23ddaca3 100755 --- a/app/Controllers/Driver.php +++ b/app/Controllers/Driver.php @@ -242,4 +242,100 @@ class Driver extends BaseController $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 "; + } + } \ No newline at end of file diff --git a/app/Models/Driver_model.php b/app/Models/Driver_model.php index bdede21d..3664b621 100755 --- a/app/Models/Driver_model.php +++ b/app/Models/Driver_model.php @@ -91,7 +91,68 @@ class Driver_model extends Model return $query->getRowArray() ?: []; } + + function driverAttendanceForMonthlyPayInputs($from,$to){ + $builder = $this->db->table('t_driver_attendance') + ->select('t_driver_attendance.driver_id,SUM(t_driver_attendance.salary_amount) as driver_monthly_salary_amount,SUM(t_driver_attendance.food_amount) as driver_monthly_food_amount,t_driver.driver_name, + DATE_FORMAT(date, "%M-%Y") AS month_year,SUM(salary_amount + food_amount) AS driver_earnings_amount,COUNT(t_driver_attendance.load_type) AS no_of_loads') + ->join('t_driver', 't_driver.driver_id = t_driver_attendance.driver_id and t_driver.isactive = 1', 'left') + ->where('t_driver_attendance.date BETWEEN "'.$from.'" AND "'.$to.'"') + ->groupBy('t_driver.driver_id, DATE_FORMAT(t_driver_attendance.date, "%M-%Y")'); + + $query = $builder->get(); + return $query->getResult(); + } + + function driverMonthlyPayInputs($monthYear){ + + $builder = $this->db->table('t_driver_monthly_pay_inputs'); + $query = $builder->where('t_driver_monthly_pay_inputs.month_year', $monthYear) + ->groupBy('t_driver_monthly_pay_inputs.driver_id, t_driver_monthly_pay_inputs.month_year') + ->get(); + + $result = $query->getResult(); + return $result; + } + + function saveMonthlyData($data) + { + + $month = $data['month_year']; + $drid = $data['driver_id']; + $count = 0; + + $builder = $this->db->table('t_driver_monthly_pay_inputs')->select('count(*) as count') + ->where('month_year', $month) + ->where('driver_id', $drid); + $isExits = $builder->get(); + $res = $isExits->getResultArray(); + + if (!empty($res)) { + + $count = $res[0]['count']; + } + + + if ($count == 0) { + unset($data['updated_by']); + $builder = $this->db->table('t_driver_monthly_pay_inputs'); + $builder->insert($data); + $i = $this->db->affectedRows(); + return $i; + } elseif ($count == 1) { + unset($data['created_by']); + $this->db->table('t_driver_monthly_pay_inputs') + ->where('driver_id', $data['driver_id']) + ->where('month_year', $data['month_year']) + ->update($data); + + $i = $this->db->affectedRows(); + return $i; + } + } + } ?> diff --git a/app/Views/driverMonthlyPayInputs.php b/app/Views/driverMonthlyPayInputs.php new file mode 100644 index 00000000..88f4a420 --- /dev/null +++ b/app/Views/driverMonthlyPayInputs.php @@ -0,0 +1,559 @@ + + + + + + + + + +
| S.No | +Driver Name | +Number Of Load | +Salary Amount ₹ | +Food Amount ₹ | +Total Amount ₹ | +Diesel | +Shed Duty | +Grand Total in ₹ | +
|---|---|---|---|---|---|---|---|---|
| + | driver_name; ?> | +no_of_loads; ?> | ++ driver_monthly_salary_amount)) { + $totalforfooter[] = $record->driver_monthly_salary_amount; + echo number_format($record->driver_monthly_salary_amount, 2, '.', ''); + } else { + echo number_format(0.00, 2, '.', ''); + } ?> + | + driver_monthly_food_amount)) { + $totalforfooter2[] = $record->driver_monthly_food_amount; + echo number_format($record->driver_monthly_food_amount, 2, '.', ''); + } else { + echo number_format(0.00, 2, '.', ''); + } ?> + | ++ driver_earnings_amount) ? $record->driver_earnings_amount : ($record->driver_monthly_salary_amount + $record->driver_monthly_food_amount); + if (!empty($driver_earnings_amount)) { + $totalforfooter3[] = $driver_earnings_amount; + echo number_format($driver_earnings_amount, 2, '.', ''); + } else { + echo number_format(0.00, 2, '.', ''); + } ?> + | +Key)) { + echo "contenteditable='true';"; + } ?> + Key)) { ?> title="Payslip Calculated" style="text-align:right;color:blue;" + style="text-align:right;" > + + diesel)) { + echo number_format($record->diesel, 2, '.', ''); + $totalforfooter4[] = $record->diesel; + } else { + echo number_format(0.00, 2, '.', ''); + } ?> + | +Key)) { + echo "contenteditable='true';"; + } ?> + Key)) { ?> title="Payslip Calculated" + style="text-align:right;color:blue;" + style="text-align:right;" > + + shed_duty_amount)) { + echo number_format($record->shed_duty_amount, 2, '.', ''); + $totalforfooter5[] = $record->shed_duty_amount; + } else { + echo number_format(0.00, 2, '.', ''); + } ?> + | +Key)) { + echo "contenteditable='false';"; + } ?> + Key)) { ?> title="Payslip Calculated" + style="text-align:right;color:blue;" style="text-align:right;" > + driver_final_payment)) { + echo number_format($record->driver_final_payment, 2, '.', ''); + $totalforfooter6[] = $record->driver_final_payment; + } else { + echo number_format(0.00, 2, '.', ''); + } + ?> + | + + +
| + | Total | ++ | + + | ++ + | ++ + | ++ + | ++ + | ++ + | +