CHANGE_DELETION_ADD_ONE_DAY

This commit is contained in:
velz 2024-08-07 16:15:27 +05:30
parent 896916c889
commit 7deea48a68

View File

@ -18,6 +18,7 @@ use App\Models\EmpEndorsementModel;
use App\Models\MessageModel;
use App\Models\ClientBranchModel;
use App\Models\NotificationModel;
use App\Models\InsurerModel;
use App\Helpers\sendMailNotification;
@ -41,6 +42,7 @@ class EmployeeServiceController extends AdminController
protected $messageModel;
protected $clientBranchModel;
protected $notificationModel;
protected $insurerModel;
protected $general_relationships = [
'self' => [
@ -649,6 +651,7 @@ class EmployeeServiceController extends AdminController
$this->messageModel = new MessageModel();
$this->clientBranchModel = new ClientBranchModel();
$this->notificationModel = new NotificationModel();
$this->insurerModel = new InsurerModel();
}
public function excelFileFormatValidation($params)
@ -1295,21 +1298,31 @@ class EmployeeServiceController extends AdminController
// $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
unset($excel_data[0]);
// dd($excel_data);
// kint::dump($excel_data);
$endorsement_data = [];
$policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']);
$insurer = new InsurerModel();
$insurer = ($insurer->find($policy_terms[0]->insurer_id));
// kint::dump($insurer);
//make closure funciton which is going to use only by this method
$endorsement = function($data,$file,$row){
$endorsement = function($data,$file,$row) use ($insurer){
$group_key = rand(100000, 999999);
$row[4] = change_date_format($row[4],'d-M-Y','Y-m-d');// date of exit from excel
// Kint::dump($row[4]);
// check if insurer configured with add one day for deletion
if($insurer['deletion_add_day'] == true)
{
$row[4] = (new \DateTime($row[4]))->modify('+1 day')->format('Y-m-d');
}
// dd($row[4]);
//for emp table
$this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
// dd( $this->empEndorsementModel->getLastQuery());
// $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'change_event','old_value' => $data['change_event'],'new_value' => 'deletion','created_by' => $file['created_by'],'remarks' => 'general deletion']);
// for employee policy table
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'date_of_exit','old_value' => $data['date_of_exit'],'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'date_of_exit','old_value' => $data['date_of_exit'],'new_value' => $row[4],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'reason_for_exit','old_value' => $data['reason_for_exit'],'new_value' => $row[5],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'status','old_value' => $data['status'],'new_value' => 'inactive','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
};
@ -1326,6 +1339,7 @@ class EmployeeServiceController extends AdminController
// dd($employee);
if(is_array($employee) && count($employee))
{
// dd($employee);
$existing_endorsements = $this->empEndorsementModel->where('actions','d')
->where('table_name','employees')
->where('endorsement_id is null')
@ -1334,9 +1348,10 @@ class EmployeeServiceController extends AdminController
->where('field_name','emp_status')
->findAll();
// dd($existing_endorsements);
if(!count($existing_endorsements))
{
// dd($employee);
if(strtolower($employee['relationship']) != 'self')
{