CHANGES-INDATE-CONVERTION:GWM
This commit is contained in:
parent
bcb83b85bf
commit
32ba40df89
@ -105,14 +105,20 @@ class EmployeeRestController extends AdminController
|
|||||||
try {
|
try {
|
||||||
$emp_code = $this->request->getGet('emp_code');
|
$emp_code = $this->request->getGet('emp_code');
|
||||||
if ($emp_code) {
|
if ($emp_code) {
|
||||||
$employee = $this->employeeModel->where('emp_code', $emp_code)
|
$employee = $this->employeeModel->where('emp_code', $emp_code)->findAll();
|
||||||
->findAll();
|
$dateConverter = function($item) {
|
||||||
|
if ($item['dob'] !== '0000-00-00') {
|
||||||
$result = $employee;
|
$dateTime = \DateTime::createFromFormat('Y-m-d', $item['dob']);
|
||||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
$item['dob'] = $dateTime->format('d-m-Y');
|
||||||
|
}
|
||||||
|
return $item;
|
||||||
|
};
|
||||||
|
$employee = array_map($dateConverter, $employee);
|
||||||
|
return $this->respond(['status' => 'success','code' => 200,'data' => $employee],200);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$result = "No Match's";
|
|
||||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
|
return $this->respond(['status' => 'failed','code' => 404,'data' => []],404);
|
||||||
}
|
}
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||||
@ -129,6 +135,7 @@ class EmployeeRestController extends AdminController
|
|||||||
$updatedCount = 0;
|
$updatedCount = 0;
|
||||||
foreach ($data as $item) {
|
foreach ($data as $item) {
|
||||||
$id = $item->id;
|
$id = $item->id;
|
||||||
|
$item->dob = $this->convertDateFormat($item->dob);
|
||||||
$employee = $this->employeeModel->update($id, (array)$item);
|
$employee = $this->employeeModel->update($id, (array)$item);
|
||||||
if ($employee) {
|
if ($employee) {
|
||||||
$updatedCount++;
|
$updatedCount++;
|
||||||
@ -162,6 +169,7 @@ class EmployeeRestController extends AdminController
|
|||||||
//update old data
|
//update old data
|
||||||
$id = $item->id;
|
$id = $item->id;
|
||||||
$item->family_floater_key = $this->RelationshipMap($item->relationship);
|
$item->family_floater_key = $this->RelationshipMap($item->relationship);
|
||||||
|
$item->dob = $this->convertDateFormat($item->dob);
|
||||||
$employee = $this->employeeModel->update($id, (array)$item);
|
$employee = $this->employeeModel->update($id, (array)$item);
|
||||||
if ($employee) {
|
if ($employee) {
|
||||||
$Count++;
|
$Count++;
|
||||||
@ -169,6 +177,7 @@ class EmployeeRestController extends AdminController
|
|||||||
}else{
|
}else{
|
||||||
//create new data
|
//create new data
|
||||||
$item->family_floater_key = $this->RelationshipMap($item->relationship);
|
$item->family_floater_key = $this->RelationshipMap($item->relationship);
|
||||||
|
$item->dob = $this->convertDateFormat($item->dob);
|
||||||
$employee = $this->employeeModel->insert($item);
|
$employee = $this->employeeModel->insert($item);
|
||||||
if ($employee) {
|
if ($employee) {
|
||||||
$Count++;
|
$Count++;
|
||||||
@ -204,6 +213,21 @@ class EmployeeRestController extends AdminController
|
|||||||
return 'spouse';
|
return 'spouse';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function convertDateFormat($dateString)
|
||||||
|
{
|
||||||
|
// Attempt to create a DateTime object from the provided date string
|
||||||
|
$dateTime = \DateTime::createFromFormat('d-m-Y', $dateString);
|
||||||
|
|
||||||
|
// Check if the conversion was successful and the date string is in the format dd-mm-yyyy
|
||||||
|
if ($dateTime instanceof \DateTime) {
|
||||||
|
// Format the date to yyyy-mm-dd
|
||||||
|
return $dateTime->format('Y-m-d');
|
||||||
|
} else {
|
||||||
|
// If the date string is not in the format dd-mm-yyyy, return null
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
public function deleteDependence()
|
public function deleteDependence()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -283,7 +307,6 @@ class EmployeeRestController extends AdminController
|
|||||||
|
|
||||||
$empPolicy = $this->employeeModel->getEmployeePolicy($id);
|
$empPolicy = $this->employeeModel->getEmployeePolicy($id);
|
||||||
$empData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
|
$empData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
|
||||||
// dd($empPolicy);
|
|
||||||
if ($empPolicy) {
|
if ($empPolicy) {
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
@ -338,9 +361,14 @@ class EmployeeRestController extends AdminController
|
|||||||
if(count($empData)){
|
if(count($empData)){
|
||||||
foreach ($empData as $key => $value) {
|
foreach ($empData as $key => $value) {
|
||||||
if ($value['family_floater_key'] === $dependent) {
|
if ($value['family_floater_key'] === $dependent) {
|
||||||
|
$employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array->ClientPolicyId)->get()->getRow();
|
||||||
$temp['family_floater_key'] = $familyFloatesValue;
|
$temp['family_floater_key'] = $familyFloatesValue;
|
||||||
$temp['label'] = $value['relationship'];
|
$temp['label'] = $value['relationship'];
|
||||||
$temp['name'] = $value['name'];
|
$temp['name'] = $value['name'];
|
||||||
|
$temp['employee_id'] = $value['id'];
|
||||||
|
$temp['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
|
||||||
|
$temp['client_policy_id'] = $array->ClientPolicyId;
|
||||||
|
|
||||||
array_push($data,$temp);
|
array_push($data,$temp);
|
||||||
unset($empData[$key]);
|
unset($empData[$key]);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user