Add data user to db old lms

This commit is contained in:
pajri
2024-06-18 17:44:24 +07:00
parent cff897aee2
commit 0ddf3ee1d8
2 changed files with 162 additions and 76 deletions

View File

@@ -336,35 +336,37 @@ class MemberEnrollmentService
$this->member = $member;
}
public function dateParser($date_from_row) {
public function dateParser($date_from_row)
{
if ($date_from_row instanceof DateTime) {
return $date_from_row->format('Y-m-d');
} else if ($date_from_row != null) {
if (strtotime($date_from_row)){
if (strtotime($date_from_row)) {
return date('Y-m-d', strtotime($date_from_row));
} else {
// throw new ImportRowException(__('Format Date Invalid'), 0, null, $date_from_row);
// throw new ImportRowException(__('Format Date Invalid'), 0, null, $date_from_row);
return null;
}
} else {
// throw new ImportRowException(__('Format Date Invalid'), 0, null, $date_from_row);
return null;
return null;
}
}
public function validateDate($dateString, $dateFormat = 'Ymd'){
public function validateDate($dateString, $dateFormat = 'Ymd')
{
$date = DateTime::createFromFormat($dateFormat, $dateString);
if ($date && ($date->format($dateFormat) == $dateString)) {
return true;
return true;
} else {
return false;
return false;
}
}
protected function validateRow($row)
{
$title =[
$title = [
'member_effective_date' => 'Member Effective Date',
'member_expiry_date' => 'Member Expired Date',
'activation_date' => 'Activation Date',
@@ -401,13 +403,13 @@ class MemberEnrollmentService
if ($row['record_type'] == 'D') {
$member = Member::query()
->where('member_id', $row['principal_id'])
// ->whereHas('employeds', function ($query) use ($corporate) {
// $query->where('corporate_id', $corporate->id);
// })
->first();
->where('member_id', $row['principal_id'])
// ->whereHas('employeds', function ($query) use ($corporate) {
// $query->where('corporate_id', $corporate->id);
// })
->first();
if(empty($member)){
if (empty($member)) {
// throw new ImportRowException(__('enrollment.PRINCIPAL_NOT_IN_MEMBER_ID'), 0, null, $row);
} else {
// if ($member['record_type'] != 'P'){
@@ -551,11 +553,11 @@ class MemberEnrollmentService
{
try {
$activation_date = NULL;
if (!empty($row['activation_date'])){
if (!empty($row['activation_date'])) {
$activation_date = $row['activation_date'];
}
$date_terminated = NULL;
if(!empty($row['date_terminated'])){
if (!empty($row['date_terminated'])) {
$date_terminated = $row['date_terminated'];
}
@@ -627,7 +629,7 @@ class MemberEnrollmentService
$date_terminated = $this->dateParser($row['date_terminated']);
if(!empty($row['activation_date'])){
if (!empty($row['activation_date'])) {
// $activation_date = date("Y-m-d", strtotime($row['activation_date']));
// if (($activation_date == $date_terminated) && ($activation_date == $member_effective_date)) {
// throw new ImportRowException(__('enrollment.MORE_THAN', [
@@ -638,7 +640,7 @@ class MemberEnrollmentService
// ]), 0, null, $row);
// }
}
if (!empty($row['date_terminated'])){
if (!empty($row['date_terminated'])) {
// $date_terminated = date("Y-m-d", strtotime($row['date_terminated']));
// if($date_terminated){
// if ($date_terminated <= $member_effective_date && ($date_terminated != $member_effective_date)) {
@@ -712,7 +714,7 @@ class MemberEnrollmentService
// }
if($corporate->code != $row['corporate_id']){
if ($corporate->code != $row['corporate_id']) {
throw new ImportRowException(__('enrollment.CORPORATE_CODE_NOT_MATCH', [
'corporate_id' => $row['corporate_id']
]), 0, null, $row);
@@ -744,6 +746,7 @@ class MemberEnrollmentService
);
$member->person_id = $person->id;
$member->save();
throw new ImportRowException(__('enrollment.MEMBER_UNIQUE', [
'member_id' => $row['member_id'],
'policy_id' => $row['policy_number']
@@ -752,6 +755,75 @@ class MemberEnrollmentService
$member = new Member();
}
if ($row['relationship_with_principal'] == 'H') {
$sMartialStatus = 6;
$nIDHubunganKeluarga = 3;
} else if ($row['relationship_with_principal'] == 'W') {
$sMartialStatus = 7;
$nIDHubunganKeluarga = 4;
} else if ($row['relationship_with_principal'] == 'S') {
$sMartialStatus = 4;
$nIDHubunganKeluarga = 5;
} else if ($row['relationship_with_principal'] == 'D') {
$sMartialStatus = 5;
$nIDHubunganKeluarga = 5;
} else {
$sMartialStatus = 0;
$nIDHubunganKeluarga = 0;
}
if ($row['sex'] == 'M') {
$nIDJenisKelamin = 1;
} else {
$nIDJenisKelamin = 2;
};
$name = explode(" ", $row['name']);
// First name
$first_name = isset($name[0]) ? $name[0] : '';
// Middle name
$middle_name = isset($name[1]) ? $name[1] : '';
// Last name
$last_name = '';
if (count($name) > 2) {
$last_name = implode(" ", array_slice($name, 2));
}
$userLms = User::create(
[
'sFirstName' => $first_name,
'sLastName' => $middle_name . ' ' . $last_name, // Ubah ini dengan variabel yang sesuai dengan nama belakang (last name)
'sPhone' => $row['telephone_mobile'],
'sEmail' => str_replace(' ', '', $row['email']),
'nIDHubunganKeluarga' => $nIDHubunganKeluarga !== 0 ? $nIDHubunganKeluarga : null,
'dUpdateOn' => date('Y-m-d H:i:s'),
]
);
$nIDUser = $userLms->nID;
$userLmsDetail = UserDetail::create(
[
'nIDUser' => $nIDUser,
// 'dTanggalLahir' => $row['date_of_birth'],
'dTanggalLahir' => $this->dateParser($row['date_of_birth']),
'dCreateOn' => date('Y-m-d H:i:s'),
'sMartialStatus' => $sMartialStatus != 0 ? $sMartialStatus : null,
'nIDJenisKelamin' => $nIDJenisKelamin,
'sCreateBy' => $nIDUser,
'sKTP' => $row['nric'] ?? null,
]
);
UserInsurance::updateOrCreate(
['nIDUser' => $nIDUser],
[
'sNamaPeserta' => $row['name'],
'dStartDate' => $row['member_effective_date'],
'dExpireDate' => $row['member_expiry_date'],
'dTanggalLahir' => $row['date_of_birth'] ? $this->dateParser($row['date_of_birth']) : null,
'sNoPolis' => $row['member_id']
]
);
$memberPolicy = $member->policies()
->where('policy_id', $row['policy_number'])
->first();
@@ -765,13 +837,13 @@ class MemberEnrollmentService
// Validate If Plan Exist
// TODO validate corporate plan
$plans = explode(",",$row['plan_id']);
$plans = explode(",", $row['plan_id']);
if (count($plans) > 0) {
foreach($plans as $d){
foreach ($plans as $d) {
$plan = Plan::query()
->where('code', $d)
->where('corporate_id', $corporate->id)
->first();
->where('code', $d)
->where('corporate_id', $corporate->id)
->first();
if (!$plan) {
throw new ImportRowException(__('enrollment.PLAN_NOT_FOUND'), 0, null, $row);
}
@@ -836,13 +908,13 @@ class MemberEnrollmentService
]);
// Bisa disini penyebab data dobel
$plans = explode(",",$row['plan_id']);
$plans = explode(",", $row['plan_id']);
if (count($plans) > 0) {
foreach($plans as $d){
foreach ($plans as $d) {
$plan = Plan::query()
->where('code', $d)
->where('corporate_id', $corporate->id)
->first();
->where('code', $d)
->where('corporate_id', $corporate->id)
->first();
if (!$plan) {
throw new ImportRowException(__('enrollment.PLAN_NOT_FOUND'), 0, null, $row);
}
@@ -868,7 +940,6 @@ class MemberEnrollmentService
'end' => $this->dateParser($row['member_expiry_date']),
]);
}
}
DB::commit();
} catch (\Exception $e) {
@@ -877,7 +948,7 @@ class MemberEnrollmentService
}
break;
case "2": // Member Information Update (Without Replacement Card)
$this->validateRow($row);
$member = Member::query()
->where('member_id', $row['member_id'])
@@ -964,11 +1035,11 @@ class MemberEnrollmentService
$division_id = $division->id;
}
// Bisa disini penyebab data dobel
$member->employeds()->updateOrCreate([
'division_id' => $division_id
],[
], [
'corporate_id' => $corporate->id,
'branch_code' => $row['branch_code'],
'division_id' => $division_id ?? null,
@@ -979,26 +1050,28 @@ class MemberEnrollmentService
}
$plans = explode(",",$row['plan_id']);
$plans = explode(",", $row['plan_id']);
if (count($plans) > 0) {
foreach($plans as $d){
foreach ($plans as $d) {
$plan = Plan::query()
->where('code', $d)
->where('corporate_id', $corporate->id)
->first();
->where('code', $d)
->where('corporate_id', $corporate->id)
->first();
if (!$plan) {
throw new ImportRowException(__('enrollment.PLAN_NOT_FOUND'), 0, null, $row);
}
$member->memberPlans()->updateOrCreate([
'member_id' => $member->id,
'plan_id' => $plan->id,
],
[
'plan_id' => $plan->id,
'status' => 'active',
'start' => $this->dateParser($row['member_effective_date']),
'end' => $this->dateParser($row['member_expiry_date']),
]);
$member->memberPlans()->updateOrCreate(
[
'member_id' => $member->id,
'plan_id' => $plan->id,
],
[
'plan_id' => $plan->id,
'status' => 'active',
'start' => $this->dateParser($row['member_effective_date']),
'end' => $this->dateParser($row['member_expiry_date']),
]
);
}
} else {
$plan = Plan::query()
@@ -1008,16 +1081,18 @@ class MemberEnrollmentService
if (!$plan) {
throw new ImportRowException(__('enrollment.PLAN_NOT_FOUND'), 0, null, $row);
}
$member->memberPlans()->updateOrCreate([
'member_id' => $member->id,
'plan_id' => $plan->id,
],
[
'plan_id' => $plan->id,
'status' => 'active',
'start' => $this->dateParser($row['member_effective_date']),
'end' => $this->dateParser($row['member_expiry_date']),
]);
$member->memberPlans()->updateOrCreate(
[
'member_id' => $member->id,
'plan_id' => $plan->id,
],
[
'plan_id' => $plan->id,
'status' => 'active',
'start' => $this->dateParser($row['member_effective_date']),
'end' => $this->dateParser($row['member_expiry_date']),
]
);
}
// end update plan
@@ -1025,7 +1100,7 @@ class MemberEnrollmentService
$userInsuranceLms = UserInsurance::query()
->where('sNoPolis', $row['member_id'])
->first();
if ($userInsuranceLms){
if ($userInsuranceLms) {
$userInsuranceLms->sNamaPeserta = $row['name'];
$userInsuranceLms->dStartDate = $row['member_effective_date'];
$userInsuranceLms->dExpireDate = $row['member_expiry_date'];
@@ -1038,20 +1113,20 @@ class MemberEnrollmentService
'dStartDate' => $row['member_effective_date'],
'dExpireDate' => $row['member_expiry_date'],
'dTanggalLahir' => $row['date_of_birth'] ? $this->dateParser($row['date_of_birth']) : null,
// 'nNoKTP' => $row['nric'] ?? ,
'sNoPolis' => $row['member_id']
]
);
/* Lihat ID Marital status di table tm_status_pernikahan Linksehat */
if ($row['relationship_with_principal'] == 'H'){
$sMartialStatus= 6;
if ($row['relationship_with_principal'] == 'H') {
$sMartialStatus = 6;
$nIDHubunganKeluarga = 3;
} else if ($row['relationship_with_principal'] == 'W'){
} else if ($row['relationship_with_principal'] == 'W') {
$sMartialStatus = 7;
$nIDHubunganKeluarga = 4;
} else if ($row['relationship_with_principal'] == 'S'){
} else if ($row['relationship_with_principal'] == 'S') {
$sMartialStatus = 4;
$nIDHubunganKeluarga = 5;
} else if ($row['relationship_with_principal'] == 'D'){
} else if ($row['relationship_with_principal'] == 'D') {
$sMartialStatus = 5;
$nIDHubunganKeluarga = 5;
} else {
@@ -1060,7 +1135,7 @@ class MemberEnrollmentService
}
if($row['sex'] == 'M'){
if ($row['sex'] == 'M') {
$nIDJenisKelamin = 1;
} else {
$nIDJenisKelamin = 2;
@@ -1082,7 +1157,7 @@ class MemberEnrollmentService
],
[
'sFirstName' => $first_name,
'sLastName' => $middle_name . ' ' .$last_name, // Ubah ini dengan variabel yang sesuai dengan nama belakang (last name)
'sLastName' => $middle_name . ' ' . $last_name, // Ubah ini dengan variabel yang sesuai dengan nama belakang (last name)
'sPhone' => $row['telephone_mobile'],
'sEmail' => str_replace(' ', '', $row['email']),
'nIDHubunganKeluarga' => $nIDHubunganKeluarga !== 0 ? $nIDHubunganKeluarga : null,
@@ -1105,9 +1180,8 @@ class MemberEnrollmentService
'sKTP' => $row['nric'] ?? null,
]
);
}
if (!$memberPolicy) {
throw new ImportRowException(__('enrollment.MEMBER_NOT_EXISTS', [
'member_id' => $row['member_id'],
@@ -1600,11 +1674,9 @@ class MemberEnrollmentService
$value = $row_data[$this->doc_headers_to_field_map[$header]] ?? null;
if (is_string($value)) {
$cells[] = WriterEntityFactory::createCell($value);
}
else if ($value instanceof DateTime) {
} else if ($value instanceof DateTime) {
$cells[] = WriterEntityFactory::createCell(Carbon::parse($value)->format('Ymd'));
}
else {
} else {
$cells[] = WriterEntityFactory::createCell($value);
}
}
@@ -1613,13 +1685,13 @@ class MemberEnrollmentService
}
// This validation for range date in period corporate // validasi untuk range tanggal dalam period corporate yang ditentukan
public function validateRangePeriode($dates){
public function validateRangePeriode($dates)
{
$date = date("Y-m-d", strtotime($dates));
if (!isset($corporate->currentPolicy) || $corporate->currentPolicy->start <= $date) {
}
if (!isset($corporate->currentPolicy) || $corporate->currentPolicy->end >= $date) {
dd($corporate->currentPolicy->end, $dates);
dd($corporate->currentPolicy->end, $dates);
}
}

View File

@@ -1,6 +1,7 @@
<?php
namespace App\Models\OLDLMS;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -77,4 +78,17 @@ class User extends Authenticatable
{
return $this->notificationTokens()->pluck('token')->toArray();
}
protected static function boot()
{
parent::boot();
static::creating(function ($user) {
$user->sIPAddress = request()->ip();
});
static::updating(function ($user) {
$user->sIPAddress = request()->ip();
});
}
}