update import

This commit is contained in:
Linksehat Staging Server
2023-11-16 10:26:22 +07:00
parent 8be552c141
commit e3aacbb5d5
3 changed files with 82 additions and 27 deletions

View File

@@ -876,24 +876,69 @@ class MemberEnrollmentService
$member->person_id = $person->id;
$member->save();
try {
$memberPolicy = MemberPolicy::query()
->where('policy_id', $row['policy_number'])
->where('member_id', $row['member_id'])
->with('member')
->first();
// Pengecekan jika ada perubahan di plan
$plan = Plan::query()
->where('code', $row['plan_id'])
->first();
if ($plan){
$memberPlan = MemberPlan::query()
->where('member_id', $member->id)
// // Pengecekan jika ada perubahan di plan
// $plan = Plan::query()
// ->where('code', $row['plan_id'])
// ->first();
// if ($plan){
// $memberPlan = MemberPlan::query()
// ->where('member_id', $member->id)
// ->first();
// $memberPlan->plan_id = $plan->id;
// $memberPlan->save();
// }
// Update plan
$plans = explode(",",$row['plan_id']);
if (count($plans) > 0) {
foreach($plans as $d){
$plan = Plan::query()
->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']),
]);
}
} else {
$plan = Plan::query()
->where('code', $row['plan_id'])
->where('corporate_id', $corporate->id)
->first();
$memberPlan->plan_id = $plan->id;
$memberPlan->save();
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']),
]);
}
// end update plan
// Update jika ada perubahaan di ASO maka akan teriflek ke LMS juga\
$userInsuranceLms = UserInsurance::query()
->where('sNoPolis', $row['member_id'])