diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4e380f05..0ee8bd22 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -243,6 +243,10 @@ $routes->post('payslip/checkExistPay', 'Payslip::checkExistPay'); $routes->post('payslip/callsp', 'Payslip::callsp'); $routes->get('payslip/editPayslip/(:any)', 'Payslip::editPayslip/$1'); $routes->post('payslip/updatePayslip', 'Payslip::updatePayslip'); +$routes->post('payslip/isPaySlipGenerated', 'Payslip::isPaySlipGenerated'); +$routes->post('payslip/allowEdit', 'Payslip::allowEdit'); + + // Application Requisition Flow Routes $routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'Requisition', 'Requisitionform::requisitionlisting'); $routes->match(['GET', 'POST', 'PUT', 'DELETE'], 'RequisitionForm', 'Requisitionform::requisition'); diff --git a/app/Controllers/Payslip.php b/app/Controllers/Payslip.php index 0e8ed2db..bbf1d5e8 100755 --- a/app/Controllers/Payslip.php +++ b/app/Controllers/Payslip.php @@ -1074,7 +1074,7 @@ class Payslip extends BaseController $result = array_merge($employee, $driver); - $HTML = ""; + $HTML = ""; if (count($result) > 0) { @@ -1529,6 +1529,46 @@ class Payslip extends BaseController } + public function isPaySlipGenerated(){ + + $empid = $this->request->getPost('employee'); + $payon = $this->request->getPost('payon'); + + $is_driver = $this->driver_model->getDriverName($empid,1); + + if($is_driver){ + $result = $this->driver_model->checkDriverExistPay($empid, $payon); + return $this->response->setJSON(['count' => count($result)]); + + }else{ + $result = $this->payroll_model->checkExistPayData($empid, $payon); + return $this->response->setJSON(['count' => count($result)]); + + } + } + + + public function allowEdit(){ + + $empid = $this->request->getPost('employee'); + $payon = $this->request->getPost('payon'); + + $is_driver = $this->driver_model->getDriverName($empid,1); + + if($is_driver){ + + $result = $this->driver_model->allowEdit($empid, $payon); + return $this->response->setJSON(['result' => $result]); + + }else{ + + $result = $this->payroll_model->allowEdit($empid, $payon); + return $this->response->setJSON(['result' => $result]); + + } + + } + diff --git a/app/Models/Driver_model.php b/app/Models/Driver_model.php index 3a446d87..e7bc21b9 100755 --- a/app/Models/Driver_model.php +++ b/app/Models/Driver_model.php @@ -264,6 +264,40 @@ class Driver_model extends Model return $query->getResult(); } +public function allowEdit($empid, $payon) +{ + // Start a transaction + $this->db->transBegin(); + + // Delete record from t_payroll + $builder1 = $this->db->table('t_driver_payroll') + ->where('PayOn', $payon) + ->where('driver_id', $empid); + + $deleteSuccess = $builder1->delete(); + + + // Check if either failed + if ($deleteSuccess === false ) { + // Rollback all changes if any query failed + $this->db->transRollback(); + return [ + 'status' => 'error', + 'message' => 'Transaction failed: Delete or update unsuccessful.' , + 'result' => false + ]; + } + + // If both succeeded, commit the transaction + $this->db->transCommit(); + return [ + 'status' => 'success', + 'message' => 'Both t_driver_payroll row deleted successfully...!!', + 'result' => true + + ]; +} + function getMonthlyPayDetails($driver_id, $PayOn) { $builder = $this->db->table('t_driver_monthly_pay_inputs MonthlyPay ') diff --git a/app/Models/Payroll_model.php b/app/Models/Payroll_model.php index 0315e182..89a3a864 100755 --- a/app/Models/Payroll_model.php +++ b/app/Models/Payroll_model.php @@ -74,6 +74,47 @@ class Payroll_model extends Model return $query->getResult(); } +public function allowEdit($empid, $payon) +{ + // Start a transaction + $this->db->transBegin(); + + // Delete record from t_payroll + $deleteSuccess = $this->db->table('t_payroll') + ->where('PayOn', $payon) + ->where('EmpID', $empid) + ->delete(); + + // Update record in t_monthly_pay_inputs + $updateSuccess = $this->db->table('t_monthly_pay_inputs') + ->where('Month_Year', $payon) + ->where('EmpID', $empid) + ->set('is_payslip_generated', 0) + ->update(); + + // Check if either failed + if ($deleteSuccess === false || $updateSuccess === false) { + // Rollback all changes if any query failed + $this->db->transRollback(); + return [ + 'status' => 'error', + 'message' => 'Transaction failed: Delete or update unsuccessful.' , + 'result' => false + ]; + } + + // If both succeeded, commit the transaction + $this->db->transCommit(); + return [ + 'status' => 'success', + 'message' => 'Both t_payroll row deleted and t_monthly_pay_inputs updated successfully...!!', + 'result' => true + + ]; +} + + + function checkFileDetailsExists2($PayOn, $EmpId) { //echo $EmpId; diff --git a/app/Views/payslipgenerate.php b/app/Views/payslipgenerate.php index 9e8a618c..641488fc 100755 --- a/app/Views/payslipgenerate.php +++ b/app/Views/payslipgenerate.php @@ -37,6 +37,84 @@ $monthsoptions = array("01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr } }); + $("#Employee").change(function() { + + let payon = $('#PayOn').val(); + let employee = $('#Employee').val(); + + if (payon != '-1' && employee != '-1') { + $('#loader').show(); + $.ajax({ + data: { + payon, + employee + }, + type: "POST", + url: "payslip/isPaySlipGenerated", + success: function(data) { + + console.log(data); + + + if(data.count > 0){ + + $('#allowEdit').show(); + + }else{ + $('#allowEdit').hide(); + } + }, + error: function(xhr, status, error) { + console.error("Error occurred: " + error); + }, + complete: function() { + $('#loader').hide(); + console.log("Request completed"); + } + }); + } else { + alert('Please select the Employee'); + return false; + } + + }); + + $("#allowEdit").click(function() { + let payon = $('#PayOn').val(); + let employee = $('#Employee').val(); + + if (payon != '-1' && employee != '-1') { + $('#loader').show(); + $.ajax({ + data: { + payon, + employee + }, + type: "POST", + url: "payslip/allowEdit", + success: function(data) { + if (data && typeof data === 'object' && data.result?.status === "success") { + $('#allowEdit').hide(); + alert("Edit allowed successfully for Employee -Id: " + employee + " for : " + payon + " Kindly visit the Monthly Pay Information ..!!"); + } else { + alert("Error in Allow Edit"); + } + }, + error: function(xhr, status, error) { + console.error("Error occurred: " + error); + }, + complete: function() { + $('#loader').hide(); + console.log("Request completed"); + } + }); + } else { + alert('Please select the Employee'); + return false; + } + + }); + $("#Calculate").click(function() { var payon = $('#PayOn').val(); var employee = $('#Employee').val(); @@ -102,6 +180,7 @@ $monthsoptions = array("01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr $('form#PayslipGenerator').submit(); $('#loader').hide(); alert("Payslip Downloaded Successfully..!"); + $('#allowEdit').show(); } else { $.ajax({ @@ -116,6 +195,7 @@ $monthsoptions = array("01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr $('form#PayslipGenerator').submit(); $('#loader').hide(); alert("Salary Calculated Successfully..!"); + $('#allowEdit').show(); } }); @@ -158,7 +238,6 @@ $monthsoptions = array("01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr