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,7 +336,8 @@ class MemberEnrollmentService
$this->member = $member; $this->member = $member;
} }
public function dateParser($date_from_row) { public function dateParser($date_from_row)
{
if ($date_from_row instanceof DateTime) { if ($date_from_row instanceof DateTime) {
return $date_from_row->format('Y-m-d'); return $date_from_row->format('Y-m-d');
@@ -353,7 +354,8 @@ class MemberEnrollmentService
} }
} }
public function validateDate($dateString, $dateFormat = 'Ymd'){ public function validateDate($dateString, $dateFormat = 'Ymd')
{
$date = DateTime::createFromFormat($dateFormat, $dateString); $date = DateTime::createFromFormat($dateFormat, $dateString);
if ($date && ($date->format($dateFormat) == $dateString)) { if ($date && ($date->format($dateFormat) == $dateString)) {
return true; return true;
@@ -744,6 +746,7 @@ class MemberEnrollmentService
); );
$member->person_id = $person->id; $member->person_id = $person->id;
$member->save(); $member->save();
throw new ImportRowException(__('enrollment.MEMBER_UNIQUE', [ throw new ImportRowException(__('enrollment.MEMBER_UNIQUE', [
'member_id' => $row['member_id'], 'member_id' => $row['member_id'],
'policy_id' => $row['policy_number'] 'policy_id' => $row['policy_number']
@@ -752,6 +755,75 @@ class MemberEnrollmentService
$member = new Member(); $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() $memberPolicy = $member->policies()
->where('policy_id', $row['policy_number']) ->where('policy_id', $row['policy_number'])
->first(); ->first();
@@ -868,7 +940,6 @@ class MemberEnrollmentService
'end' => $this->dateParser($row['member_expiry_date']), 'end' => $this->dateParser($row['member_expiry_date']),
]); ]);
} }
} }
DB::commit(); DB::commit();
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -989,7 +1060,8 @@ class MemberEnrollmentService
if (!$plan) { if (!$plan) {
throw new ImportRowException(__('enrollment.PLAN_NOT_FOUND'), 0, null, $row); throw new ImportRowException(__('enrollment.PLAN_NOT_FOUND'), 0, null, $row);
} }
$member->memberPlans()->updateOrCreate([ $member->memberPlans()->updateOrCreate(
[
'member_id' => $member->id, 'member_id' => $member->id,
'plan_id' => $plan->id, 'plan_id' => $plan->id,
], ],
@@ -998,7 +1070,8 @@ class MemberEnrollmentService
'status' => 'active', 'status' => 'active',
'start' => $this->dateParser($row['member_effective_date']), 'start' => $this->dateParser($row['member_effective_date']),
'end' => $this->dateParser($row['member_expiry_date']), 'end' => $this->dateParser($row['member_expiry_date']),
]); ]
);
} }
} else { } else {
$plan = Plan::query() $plan = Plan::query()
@@ -1008,7 +1081,8 @@ class MemberEnrollmentService
if (!$plan) { if (!$plan) {
throw new ImportRowException(__('enrollment.PLAN_NOT_FOUND'), 0, null, $row); throw new ImportRowException(__('enrollment.PLAN_NOT_FOUND'), 0, null, $row);
} }
$member->memberPlans()->updateOrCreate([ $member->memberPlans()->updateOrCreate(
[
'member_id' => $member->id, 'member_id' => $member->id,
'plan_id' => $plan->id, 'plan_id' => $plan->id,
], ],
@@ -1017,7 +1091,8 @@ class MemberEnrollmentService
'status' => 'active', 'status' => 'active',
'start' => $this->dateParser($row['member_effective_date']), 'start' => $this->dateParser($row['member_effective_date']),
'end' => $this->dateParser($row['member_expiry_date']), 'end' => $this->dateParser($row['member_expiry_date']),
]); ]
);
} }
// end update plan // end update plan
@@ -1038,7 +1113,7 @@ class MemberEnrollmentService
'dStartDate' => $row['member_effective_date'], 'dStartDate' => $row['member_effective_date'],
'dExpireDate' => $row['member_expiry_date'], 'dExpireDate' => $row['member_expiry_date'],
'dTanggalLahir' => $row['date_of_birth'] ? $this->dateParser($row['date_of_birth']) : null, '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 */ /* Lihat ID Marital status di table tm_status_pernikahan Linksehat */
@@ -1105,7 +1180,6 @@ class MemberEnrollmentService
'sKTP' => $row['nric'] ?? null, 'sKTP' => $row['nric'] ?? null,
] ]
); );
} }
if (!$memberPolicy) { if (!$memberPolicy) {
@@ -1600,11 +1674,9 @@ class MemberEnrollmentService
$value = $row_data[$this->doc_headers_to_field_map[$header]] ?? null; $value = $row_data[$this->doc_headers_to_field_map[$header]] ?? null;
if (is_string($value)) { if (is_string($value)) {
$cells[] = WriterEntityFactory::createCell($value); $cells[] = WriterEntityFactory::createCell($value);
} } else if ($value instanceof DateTime) {
else if ($value instanceof DateTime) {
$cells[] = WriterEntityFactory::createCell(Carbon::parse($value)->format('Ymd')); $cells[] = WriterEntityFactory::createCell(Carbon::parse($value)->format('Ymd'));
} } else {
else {
$cells[] = WriterEntityFactory::createCell($value); $cells[] = WriterEntityFactory::createCell($value);
} }
} }
@@ -1613,10 +1685,10 @@ class MemberEnrollmentService
} }
// This validation for range date in period corporate // validasi untuk range tanggal dalam period corporate yang ditentukan // 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)); $date = date("Y-m-d", strtotime($dates));
if (!isset($corporate->currentPolicy) || $corporate->currentPolicy->start <= $date) { if (!isset($corporate->currentPolicy) || $corporate->currentPolicy->start <= $date) {
} }
if (!isset($corporate->currentPolicy) || $corporate->currentPolicy->end >= $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 <?php
namespace App\Models\OLDLMS; namespace App\Models\OLDLMS;
use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -77,4 +78,17 @@ class User extends Authenticatable
{ {
return $this->notificationTokens()->pluck('token')->toArray(); 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();
});
}
} }