diff --git a/Modules/Internal/Http/Controllers/Api/MemberController.php b/Modules/Internal/Http/Controllers/Api/MemberController.php index dd4dc89f..a6cebe46 100644 --- a/Modules/Internal/Http/Controllers/Api/MemberController.php +++ b/Modules/Internal/Http/Controllers/Api/MemberController.php @@ -29,9 +29,17 @@ class MemberController extends Controller $benefits = Member::query() ->filter($request->all()) // ->where('corporate_id', $corporate_id) - ->whereHas('employeds', function ($query) use ($corporate_id) { - $query->where('corporate_id', $corporate_id); + ->whereHas('employeds', function ($employeds) use ($corporate_id) { + $employeds->where('corporate_id', $corporate_id); }) + ->with([ + 'employeds', + 'currentPolicy' => function ($policy) use ($corporate_id) { + $policy->whereHas('corporatePolicy', function($corporatePolicy) use ($corporate_id) { + $corporatePolicy->where('corporate_id', $corporate_id); + }); + } + ]) ->paginate(20) ->appends($request->all()); diff --git a/Modules/Internal/Services/MemberEnrollmentService.php b/Modules/Internal/Services/MemberEnrollmentService.php index 475ea7d8..e2964008 100644 --- a/Modules/Internal/Services/MemberEnrollmentService.php +++ b/Modules/Internal/Services/MemberEnrollmentService.php @@ -135,7 +135,7 @@ class MemberEnrollmentService "member_id" => $row['member_id'], "payor_id" => $row['payor_id'], "nik" => $row['nik'], - "birth_date" => Carbon::parse($row['date_of_birth']), + "birth_date" => Carbon::parse(strtotime($row['date_of_birth'])), "gender" => Helper::genderNormalization($row['sex']), "language" => $row['language'], "race" => $row['race'], @@ -144,9 +144,29 @@ class MemberEnrollmentService "principal_id" => $row['principal_id'], "relation_with_principal" => $row['relationship_with_principal'], "bpjs_class" => $row['bpjs_class'], + "nric" => $row['nric'], + "email" => $row['email'], + "bank_info" => $row['banks_info'], + "agent_code" => $row['agent_code'], + "address1" => $row['address1'], + "address2" => $row['address2'], + "address3" => $row['address3'], + "address4" => $row['address4'], + "city" => $row['city'], + "state" => $row['state'], + "postal_code" => $row['post_code'], + "passport_no" => $row['passport_number'], + "passport_country" => $row['passport_country'], + "identification_code" => $row['identification_code'], + "pre_existing" => $row['pre_existing'], + "bpjs_id" => $row['bpjs_id'], + "endorsement_date" => $row['endorsement_date'], + "remarks" => $row['remarks'], + "policy_in_force" => $row['policy_in_force'], + "start_no_claim" => $row['start_no_claim'], + "end_no_claim" => $row['end_no_claim'], ]; - if ($corporate->currentPolicy->code != $row['policy_number']) { throw new ImportRowException(__('enrollment.POLICY_NUMBER_NOT_MATCH', [ 'policy_id' => $row['policy_number'] @@ -206,7 +226,8 @@ class MemberEnrollmentService 'corporate_id' => $corporate->id, 'branch_code' => $row['branch_code'], 'division_id' => $division_id ?? null, - 'nik' => $row['nik'] + 'nik' => $row['nik'], + 'status' => $row['employment_status'] ]); } DB::commit(); @@ -295,7 +316,7 @@ class MemberEnrollmentService throw new ImportRowException(__('enrollment.MEMBER_EXPIRY_DATE_NO_CHANGE'), 0, null, $row); } - if (Carbon::parse(strtotime($row['member_effective_date'])) > Carbon::parse($row['end_date'])) { + if (Carbon::parse(strtotime($row['member_effective_date'])) > Carbon::parse(strtotime($row['member_expiry_date']))) { throw new ImportRowException(__('enrollment.MEMBER_EXPIRY_DATE_INVALID'), 0, null, $row); } diff --git a/app/Models/Member.php b/app/Models/Member.php index fe4c7199..789d0b1f 100644 --- a/app/Models/Member.php +++ b/app/Models/Member.php @@ -29,7 +29,29 @@ class Member extends Model "active", "created_by", "updated_by", - "deleted_by" + "deleted_by", + + "nric", + "email", + "bank_info", + "agent_code", + "address1", + "address2", + "address3", + "address4", + "city", + "state", + "postal_code", + "passport_no", + "passport_country", + "identification_code", + "pre_existing", + "bpjs_id", + "endorsement_date", + "remarks", + "policy_in_force", + "start_no_claim", + "end_no_claim", ]; public static $doc_headers_to_field_map = [ @@ -109,6 +131,11 @@ class Member extends Model return $this->hasMany(MemberPolicy::class, 'member_id', 'member_id'); } + public function currentPolicy() + { + return $this->hasOne(MemberPolicy::class, 'member_id', 'member_id')->where('status', 'active')->latestOfMany(); + } + public function scopeFilter($query, array $filters) { $query->when($filters['search'] ?? false, function ($query, $search) { diff --git a/app/Models/MemberPolicy.php b/app/Models/MemberPolicy.php index 4aa28ad8..42b87eae 100644 --- a/app/Models/MemberPolicy.php +++ b/app/Models/MemberPolicy.php @@ -19,9 +19,9 @@ class MemberPolicy extends Model 'end' ]; - public function policy() + public function corporatePolicy() { - return $this->belongsTo(Policy::class, 'policy_id', 'policy_id'); + return $this->belongsTo(CorporatePolicy::class, 'policy_id', 'code'); } public function member() diff --git a/database/migrations/2022_05_23_073350_create_members_table.php b/database/migrations/2022_05_23_073350_create_members_table.php index 0fbaa089..2f2c9165 100644 --- a/database/migrations/2022_05_23_073350_create_members_table.php +++ b/database/migrations/2022_05_23_073350_create_members_table.php @@ -31,6 +31,29 @@ return new class extends Migration $table->string('principal_id')->nullable()->index(); $table->string('relation_with_principal')->nullable(); $table->string('bpjs_class')->nullable(); + + $table->string('nric')->nullable(); + $table->string('email')->nullable(); + $table->string('bank_info')->nullable(); + $table->string('agent_code')->nullable(); + $table->text('address1')->nullable(); + $table->text('address2')->nullable(); + $table->text('address3')->nullable(); + $table->text('address4')->nullable(); + $table->string('city')->nullable(); + $table->string('state')->nullable(); + $table->string('postal_code')->nullable(); + $table->string('passport_no')->nullable(); + $table->string('passport_country')->nullable(); + $table->string('identification_code')->nullable(); + $table->string('pre_existing')->nullable(); + $table->string('bpjs_id')->nullable(); + $table->string('endorsement_date')->nullable(); + $table->string('remarks')->nullable(); + $table->string('policy_in_force')->nullable(); + $table->string('start_no_claim')->nullable(); + $table->string('end_no_claim')->nullable(); + $table->boolean('active')->default(true); $table->timestamps(); diff --git a/database/migrations/2022_06_17_024432_create_corporate_employees_table.php b/database/migrations/2022_06_17_024432_create_corporate_employees_table.php index aa6b43a8..47672082 100644 --- a/database/migrations/2022_06_17_024432_create_corporate_employees_table.php +++ b/database/migrations/2022_06_17_024432_create_corporate_employees_table.php @@ -21,6 +21,9 @@ return new class extends Migration $table->foreignId('division_id')->nullable()->index(); $table->string('nik')->nullable()->index(); $table->string('status')->nullable(); + + $table->date('start')->nullable(); + $table->date('end')->nullable(); $table->timestamps(); $table->softDeletes(); diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index a1df7280..50983d57 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -18,7 +18,7 @@ class DatabaseSeeder extends Seeder $this->call([ DummyMemberSeeder::class, - DummyCorprateSeeder::class + DummyCorporateSeeder::class ]); } } diff --git a/frontend/dashboard/src/pages/Corporates/Member/List.tsx b/frontend/dashboard/src/pages/Corporates/Member/List.tsx index 1e35957b..d01e4fa0 100644 --- a/frontend/dashboard/src/pages/Corporates/Member/List.tsx +++ b/frontend/dashboard/src/pages/Corporates/Member/List.tsx @@ -208,14 +208,14 @@ export default function CorporatePlanList() { { id: 'member_id', label: 'MemberID', minWidth: 100, align: "left" }, { id: 'principal_id', label: 'Mapping ID', minWidth: 100, align: "left" }, { id: 'nik', label: 'NIK', minWidth: 100, align: "left" }, - { id: 'policy_number', label: 'Policy Number', minWidth: 100, align: "left" }, + { id: 'current_policy.policy_number', label: 'Policy Number', minWidth: 100, align: "left" }, { id: 'effective_date', label: 'Effective Date', minWidth: 100, align: "left" }, { id: 'name', label: 'Name', minWidth: 100, align: "left" }, { id: 'nric', label: 'NRIC', minWidth: 100, align: "left" }, { id: 'email', label: 'E-mail', minWidth: 100, align: "left" }, { id: 'plan_id', label: 'PlanID', minWidth: 100, align: "left" }, - { id: 'termination_date', label: 'Termination Date', minWidth: 100, align: 'right' }, { id: 'activation_date', label: 'Activation Date', minWidth: 100, align: "right" }, + { id: 'termination_date', label: 'Termination Date', minWidth: 100, align: 'right' }, ]); // Generate the every row of the table @@ -235,9 +235,34 @@ export default function CorporatePlanList() { {open ? : } - { columns.map((column, index) => + {/* { columns.map((column, index) => { row[column.id] ?? '-' } - ) } + ) } */} + {/* TODO FIX DISPLAY DATA FROM RELATION */} + + {/* { id: 'member_id', label: 'MemberID', minWidth: 100, align: "left" }, + { id: 'principal_id', label: 'Mapping ID', minWidth: 100, align: "left" }, + { id: 'nik', label: 'NIK', minWidth: 100, align: "left" }, + { id: 'current_policy.policy_number', label: 'Policy Number', minWidth: 100, align: "left" }, + { id: 'effective_date', label: 'Effective Date', minWidth: 100, align: "left" }, + { id: 'name', label: 'Name', minWidth: 100, align: "left" }, + { id: 'nric', label: 'NRIC', minWidth: 100, align: "left" }, + { id: 'email', label: 'E-mail', minWidth: 100, align: "left" }, + { id: 'plan_id', label: 'PlanID', minWidth: 100, align: "left" }, + { id: 'termination_date', label: 'Termination Date', minWidth: 100, align: 'right' }, + { id: 'activation_date', label: 'Activation Date', minWidth: 100, align: "right" }, + */} + {row.member_id} + {row.principal_id} + {row.employeds[0]?.nik} + {row.current_policy.policy_id} + {row.current_policy.start} + {row.name} + {row.nric} + {row.email} + {row.plan_id} + {row.current_policy.start} + {row.current_policy.end} {/* */}