Update Validasi

This commit is contained in:
2023-05-15 11:10:16 +07:00
parent 70b0d880fc
commit 342725ebcc
8 changed files with 231 additions and 26 deletions

View File

@@ -7,6 +7,7 @@ use App\Helpers\Helper;
use App\Models\Corporate;
use App\Models\CorporateEmployee;
use App\Models\CorporateDivision;
use App\Models\CorporatePolicy;
use App\Models\CorporatePlan;
use App\Models\Member;
use App\Models\MemberPolicy;
@@ -50,7 +51,7 @@ class MemberEnrollmentService
"Agent Code / intermediary code" => "agent_code",
"Member Name" => "name",
"Address1" => "address1",
"Address 1" => "address1",
// "Address 1" => "address1",
"Address2" => "address2",
"Address3" => "address3",
"Address4" => "address4",
@@ -90,12 +91,13 @@ class MemberEnrollmentService
"Member Suspended" => "member_suspended",
"Activation Date" => "activation_date",
"Internal Use" => "internal_use_6",
"Date Terminated" => "date_terminated",
"StartNoClaim" => "start_no_claim",
"EndNoClaim" => "end_no_claim",
"Option Mode" => "option_mode",
"Policy Inforce" => "policy_in_force",
"Renewal activation date" => "renewal_activation_date",
"Renewal Activation Date" => "renewal_activation_date",
// "Renewal Activation Date" => "renewal_activation_date",
"Ingestion Code" => "ingestion_code", // TODO I think this should not be here because if user uploading result then ingestion code and status will be filled
"Ingestion Status" => "ingestion_status",
];
@@ -129,7 +131,7 @@ class MemberEnrollmentService
"agent_code" => "Agent Code / intermediary code",
"name" => "Member Name",
"address1" => "Address1",
"address1" => "Address 1",
// "address1" => "Address 1",
"address2" => "Address2",
"address3" => "Address3",
"address4" => "Address4",
@@ -168,7 +170,7 @@ class MemberEnrollmentService
"start_no_claim" => "StartNoClaim",
"end_no_claim" => "EndNoClaim",
"option_mode" => "Option Mode",
"renewal_activation_date" => "Renewal Activation Date",
// "renewal_activation_date" => "Renewal Activation Date",
"ingestion_code" => "Ingestion Code",
"ingestion_status" => "Ingestion Status",
];
@@ -201,7 +203,7 @@ class MemberEnrollmentService
"Internal Use",
"Member Name",
"Address1",
"Address 1",
// "Address 1",
"Address2",
"Address3",
"Address4",
@@ -239,7 +241,7 @@ class MemberEnrollmentService
"StartNoClaim",
"EndNoClaim",
"Option Mode",
"Renewal Activation Date",
// "Renewal Activation Date",
"Ingestion Code",
"Ingestion Status",
];
@@ -253,8 +255,26 @@ class MemberEnrollmentService
return is_string($date_from_row) ? Carbon::parse(strtotime($date_from_row)) : Carbon::parse($date_from_row);
}
public function validateDate($dateString, $dateFormat = 'Ymd'){
$date = DateTime::createFromFormat($dateFormat, $dateString);
if ($date && $date->format($dateFormat) == $dateString) {
return true;
} else {
return false;
}
}
protected function validateRow($row)
{
$title =[
'member_effective_date' => 'Member Effective Date',
'member_expiry_date' => 'Member Expired Date',
'activation_date' => 'Activation Date',
'date_of_birth' => 'Date of Birth',
'date_terminated' => 'Date Terminated',
];
if (empty($row['record_type'])) {
throw new ImportRowException(__('enrollment.RECORD_TYPE_REQUIRED'), 0, null, $row);
}
@@ -312,17 +332,35 @@ class MemberEnrollmentService
if (!empty($row['marital_status']) && !in_array($row['marital_status'], ['S', 'M', 'D'])) {
throw new ImportRowException(__('enrollment.INVALID_MARITAL_STATUS'), 0, null, $row);
}
// TODO EFFECTIVE DATE VALIDATION
if (empty($row['member_effective_date'])) {
throw new ImportRowException(__('enrollment.MEMBER_EFFECTIVE_REQUIRED'), 0, null, $row);
}
// TODO EFFECTIVE DATE VALIDATION
if(!$this->validateDate($row['member_effective_date'])){
throw new ImportRowException(__('enrollment.INVALID_DATE', [
'title' => $title['member_effective_date']
]), 0, null, $row);
}
if (empty($row['member_expiry_date'])) {
throw new ImportRowException(__('enrollment.MEMBER_EXPIRY_REQUIRED'), 0, null, $row);
}
if(!$this->validateDate($row['member_expiry_date'])){
throw new ImportRowException(__('enrollment.INVALID_DATE', [
'title' => $title['member_expiry_date']
]), 0, null, $row);
}
// TODO EFFECTIVE DATE VALIDATION
if (empty($row['activation_date'])) {
throw new ImportRowException(__('enrollment.ACTIVATION_DATE_REQUIRED'), 0, null, $row);
}
if(!$this->validateDate($row['activation_date'])){
throw new ImportRowException(__('enrollment.INVALID_DATE', [
'title' => $title['activation_date']
]), 0, null, $row);
}
// TODO FKTP VALIDATION
// TODO FKRTL VALIDATION
@@ -334,6 +372,10 @@ class MemberEnrollmentService
throw new ImportRowException(__('enrollment.NAME_REQUIRED'), 0, null, $row);
}
if (!Helper::validatePhoneNumber($row['telephone_mobile'])){
throw new ImportRowException(__('enrollment.PHONE_INVALID'), 0, null, $row);
}
if (
!empty($row['telephone_mobile'])
&& !(substr($row['telephone_mobile'], 0, 4) == '+628' || substr($row['telephone_mobile'], 0, 3) == '628')
@@ -351,13 +393,32 @@ class MemberEnrollmentService
if (empty($row['date_of_birth'])) {
throw new ImportRowException(__('enrollment.DATE_OF_BIRTH_REQUIRED'), 0, null, $row);
}
if(!$this->validateDate($row['date_of_birth'])){
throw new ImportRowException(__('enrollment.INVALID_DATE', [
'title' => $title['date_of_birth']
]), 0, null, $row);
}
if (empty($row['date_terminated'])) {
throw new ImportRowException(__('enrollment.DATE_OF_TERMINATED'), 0, null, $row);
}
if(!$this->validateDate($row['date_terminated'])){
throw new ImportRowException(__('enrollment.INVALID_DATE', [
'title' => $title['date_terminated']
]), 0, null, $row);
}
// TODO DOB FORMAT VALIDATION
if (empty($row['sex'])) {
throw new ImportRowException(__('enrollment.SEX_REQUIRED'), 0, null, $row);
}
if (!in_array($row['sex'], ['F', 'M'])){
throw new ImportRowException(__('enrollment.SEX_CODE_NOT_VALID'), 0, null, $row);
}
}
public function handleImportRow(Corporate $corporate, $row)
{
try {
@@ -366,10 +427,10 @@ class MemberEnrollmentService
"member_id" => $row['member_id'] ?? null,
"payor_id" => $row['payor_id'] ?? null,
"nik" => $row['nik'] ?? null,
"birth_date" => $this->dateParser($row['date_of_birth']),
"birth_date" => $row['date_of_birth'],
"gender" => Helper::genderNormalization($row['sex']),
// "language" => $row['language'] ?? null,
// "race" => $row['race'] ?? null,
"language" => $row['language'] ?? null,
"race" => $row['race'] ?? null,
"marital_status" => $row['marital_status'] ?? null,
"record_type" => $row['record_type'] ?? null,
"principal_id" => $row['principal_id'] ?? null,
@@ -396,6 +457,11 @@ class MemberEnrollmentService
"policy_in_force" => $row['policy_in_force'] ?? null,
"start_no_claim" => $row['start_no_claim'] ?? null,
"end_no_claim" => $row['end_no_claim'] ?? null,
"members_effective_date" => $row['member_effective_date'] ?? null,
"members_expire_date" => $row['member_expiry_date'] ?? null,
"activation_date" => $row['activation_date'] ?? null,
"terminated_date" => $row['date_terminated'] ?? null,
];
if (!isset($corporate->currentPolicy) || $corporate->currentPolicy->code != $row['policy_number']) {
@@ -404,6 +470,86 @@ class MemberEnrollmentService
]), 0, null, $row);
}
// validasi member efektif date range date in periode date coroporate
$member_effective_date = date("Y-m-d", strtotime($row['member_effective_date']));
$date_terminated = date("Y-m-d", strtotime($row['date_terminated']));
$activation_date = date("Y-m-d", strtotime($row['activation_date']));
// validasi member expried date range date in periode date coroporate
$members_expire_date = date("Y-m-d", strtotime($row['member_expiry_date']));
// validasi member expried date must less date member effective
$members_expire_date = date("Y-m-d", strtotime($row['member_expiry_date']));
$members_expire_date = date("Y-m-d", strtotime($row['member_expiry_date']));
if ($member_effective_date <= $corporate->currentPolicy->start && ($member_effective_date != $corporate->currentPolicy->start)) {
throw new ImportRowException(__('enrollment.MORE_THAN', [
'date_param' => 'Member Effective Date',
'date' => $member_effective_date,
'date_param2' => 'Start Period Date',
'start' => $corporate->currentPolicy->start
]), 0, null, $row);
}
if ($member_effective_date >= $corporate->currentPolicy->end && ($member_effective_date != $corporate->currentPolicy->end)) {
throw new ImportRowException(__('enrollment.LESS_THAN', [
'date_param' => 'Member Effective Date',
'date' => $member_effective_date,
'date_param2' => 'End Period Date',
'end' => $corporate->currentPolicy->end
]), 0, null, $row);
}
if ($member_effective_date >= $corporate->currentPolicy->end && ($member_effective_date != $corporate->currentPolicy->end)) {
throw new ImportRowException(__('enrollment.LESS_THAN', [
'date_param' => 'Member Effective Date',
'date' => $member_effective_date,
'date_param2' => 'End Period Date',
'end' => $corporate->currentPolicy->end
]), 0, null, $row);
}
if ($members_expire_date <= $corporate->currentPolicy->start && ($members_expire_date != $corporate->currentPolicy->start) ) {
throw new ImportRowException(__('enrollment.MORE_THAN', [
'date_param' => 'Member Expired Date',
'date' => $members_expire_date,
'date_param2' => 'Start Period Date',
'start' => $corporate->currentPolicy->start
]), 0, null, $row);
}
if ($members_expire_date >= $corporate->currentPolicy->end && ($members_expire_date != $corporate->currentPolicy->end)) {
throw new ImportRowException(__('enrollment.LESS_THAN', [
'date_param' => 'Member Expired Date',
'date' => $members_expire_date,
'date_param2' => 'END Period Date',
'end' => $corporate->currentPolicy->end
]), 0, null, $row);
}
if ($members_expire_date <= $member_effective_date && ($members_expire_date != $member_effective_date)) {
throw new ImportRowException(__('enrollment.MORE_THAN', [
'date_param' => 'Member Expired Date',
'date' => $members_expire_date,
'date_param2' => 'Member Effective Date',
'start' => $member_effective_date
]), 0, null, $row);
}
if ($date_terminated <= $member_effective_date && ($date_terminated != $member_effective_date)) {
throw new ImportRowException(__('enrollment.MORE_THAN', [
'date_param' => 'Date Terminated Date',
'date' => $date_terminated,
'date_param2' => 'Member Effective Date',
'start' => $member_effective_date
]), 0, null, $row);
}
if (($activation_date == $date_terminated) && ($activation_date == $member_effective_date)) {
throw new ImportRowException(__('enrollment.MORE_THAN', [
'date_param' => 'Activation Date',
'date' => $activation_date,
'date_param2' => 'Member Effective Date',
'start' => $activation_date
]), 0, null, $row);
}
if($corporate->code != $row['corporate_id']){
throw new ImportRowException(__('enrollment.CORPORATE_CODE_NOT_MATCH', [
'corporate_id' => $row['corporate_id']
]), 0, null, $row);
}
switch ($row['record_mode']) {
case "1": // New Member
$member = Member::query()
@@ -421,7 +567,8 @@ class MemberEnrollmentService
],
[
'name' => $row['name'] ?? null,
'birth_date' => $this->dateParser($row['date_of_birth']),
// 'birth_date' => $this->dateParser($row['date_of_birth']),
'birth_date' => $row['date_of_birth'],
'gender' => Helper::genderPerson($row['sex']),
'language' => $row['language'] ?? null,
'race' => $row['race'] ?? null,
@@ -458,9 +605,11 @@ class MemberEnrollmentService
throw new ImportRowException(__('enrollment.PLAN_NOT_FOUND'), 0, null, $row);
}
$this->validateRow($row);
try {
DB::beginTransaction();
$member->fill($member_data);
@@ -534,6 +683,8 @@ class MemberEnrollmentService
]), 0, null, $row);
}
$this->validateRow($row);
try {
$memberPolicy = MemberPolicy::query()
->where('policy_id', $row['policy_number'])
@@ -559,8 +710,16 @@ class MemberEnrollmentService
if (!$memberPolicy->member->isDirty()) {
throw new ImportRowException(__('enrollment.MEMBER_NO_CHANGE'), 0, null, $row);
}
$memberPolicy->member->save();
// update informasi person
$person = Person::query()
->where('id', $member->person_id)
->first();
$person->fill($member_data);
$person->save();
DB::commit();
} catch (\Exception $e) {
DB::rollback();
@@ -580,6 +739,7 @@ class MemberEnrollmentService
'policy_id' => $row['policy_number']
]), 0, null, $row);
}
$this->validateRow($row);
$memberPolicy = MemberPolicy::query()
->where('policy_id', $row['policy_number'])
@@ -1036,6 +1196,17 @@ class MemberEnrollmentService
return $cells;
}
// This validation for range date in period corporate // validasi untuk range tanggal dalam period corporate yang ditentukan
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);
}
}
// This returning row with format or order as it is
public function makeResultRow($row_data)
{