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

@@ -49,7 +49,6 @@ class CorporateMemberController extends Controller
])
->paginate()
->appends($request->all());
return Helper::paginateResources(MemberDataTableResource::collection($members));
}
@@ -179,11 +178,9 @@ class CorporateMemberController extends Controller
$new_member_data[$headers_map_to_table_fields[$doc_headers_indexes[$header_index]]] = $cell->getValue();
}
}
try {
$rowResponse = $this->memberEnrollmentService->handleImportRow($corporate, $new_member_data);
// Write Success Result to File
$singleRow = WriterEntityFactory::createRow($this->memberEnrollmentService->makeResultRowWithResultFormat($rowResponse));
$writer->addRow($singleRow);
@@ -219,7 +216,7 @@ class CorporateMemberController extends Controller
$writer->close();
Storage::delete('temp/' . $file_name);
// throw(404);
dd($corporate);
return [
'total_success_row' => $imported_member_data,
'total_failed_row' => count($failed_member_data),

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)
{

View File

@@ -184,4 +184,20 @@ class Helper
'data' => $data,
], $statusCode);
}
public static function validatePhoneNumber($phoneNumber) {
// Menghapus semua karakter selain angka dan +
$cleanedNumber = preg_replace('/[^0-9+]/', '', $phoneNumber);
// Memeriksa apakah nomor telepon hanya terdiri dari angka dan +
if ($cleanedNumber == $phoneNumber) {
// Nomor telepon valid
return true;
} else {
// Nomor telepon tidak valid
return false;
}
}
}

View File

@@ -54,6 +54,10 @@ class Member extends Model
"pre_existing",
"bpjs_id",
"endorsement_date",
"members_effective_date",
"members_expire_date",
"activation_date",
"terminated_date",
"remarks",
"policy_in_force",
"start_no_claim",
@@ -216,8 +220,8 @@ class Member extends Model
protected function birthDate(): Attribute
{
// $date = $this->person->birth_date ?? ($this->birth_date ?? null);
$date = $this->person->birth_date ?? ($this->birth_date ?? null);
return Attribute::make(
get: fn () => !empty($date) ? Carbon::parse($date)->format('Y-m-d') : null
);

View File

@@ -60,7 +60,8 @@ export default function RHFDatepicker({ name, ...other }: IProps & TextFieldProp
<DesktopDatePicker
value={field.value}
inputFormat="dd/MM/yyyy"
// inputFormat="dd/MM/yyyy"
inputFormat="yyyy-MM-dd"
onChange={(value) => {
field.onChange(value);
}}

View File

@@ -380,11 +380,11 @@ export default function CorporatePlanList() {
</TableCell>
<TableCell align="left">{row.member_id}</TableCell>
<TableCell align="left">{row.current_policy?.start}</TableCell>
<TableCell align="left">{row.members_effective_date}</TableCell>
<TableCell align="left">{row.name}</TableCell>
<TableCell align="left">{row.current_plan?.code}</TableCell>
<TableCell align="left">{row.current_policy?.start}</TableCell>
<TableCell align="left">{row.current_policy?.end}</TableCell>
<TableCell align="left">{row.activation_date}</TableCell>
<TableCell align="left">{row.terminated_date}</TableCell>
<TableCell align="center">
{row.active == 1 && (
<Button
@@ -471,7 +471,7 @@ export default function CorporatePlanList() {
: {row.gender ?? '-'}
</Grid>
<Grid item xs={6}>
Martial Status
Marital Status
</Grid>
<Grid item xs={6}>
: {row.marital_status ?? '-'}
@@ -488,6 +488,12 @@ export default function CorporatePlanList() {
<Grid item xs={6}>
: {row.race ?? '-'}
</Grid>
<Grid item xs={6}>
Relationship
</Grid>
<Grid item xs={6}>
: {row.relation_with_principal ?? '-'}
</Grid>
</Grid>
</Grid>
</Grid>

View File

@@ -11,6 +11,7 @@ return [
|
*/
"POLICY_NUMBER_NOT_MATCH" => "Wrong Policy Number (:policy_id)",
"CORPORATE_CODE_NOT_MATCH" => "Wrong Corporate Code (:corporate_id)",
"RECORD_MODE_REQUIRED" => "Record mode must be filled",
"MODE_UNAVAILABLE" => "Record mode for member is not available",
"RECORD_TYPE_REQUIRED" => "Record Type must be filled for member (Member ID)",
@@ -43,16 +44,25 @@ return [
"PRINCIPAL_ID_REQUIRED" => "Mapping ID must be filled",
"BRANCH_CODE_NOT_REQUIRED" => "Dependents don't need to fill in Branch Code ",
"INVALID_LANGUAGE" => "Language (field 12) is invalid",
"INVALID_DATE" => "Format Date (:title) is invalid",
"INVALID_TYPE_OF_WORK" => "Type of work (field 13) is invalid",
"INVALID_RACE" => "Race (field 14) is invalid",
"POLICY_NUMBER_REQUIRED" => "Policy Number must be filled for member (Member ID)",
"MORE_THAN" => ":date_param (:date) must be greater than :date_param2 date (:start)",
"LESS_THAN" => ":date_param (:date) must be less than :date_param2 date (:end)",
"MEMBER_EFFECTIVE_REQUIRED" => "Member's Effective Date must be filled for member (Member ID)",
"MEMBER_EXPIRY_REQUIRED" => "Member's Expiry Date must be filled for member (Member ID)",
"MEMBER_EXPIRY_REQUIRED" => "Member's Expiry Date must be filled for member (Member ID)",
"ACTIVATION_DATE_REQUIRED" => "Activation's Date must be filled for member (Member ID)",
"INVALID_MARITAL_STATUS" => "Marital Status (field 16) is invalid",
"NAME_REQUIRED" => "Member Name must be filled",
"PHONE_INVALID" => "Telephone - Mobile must follow +628 format",
"EMAIL_INVALID" => "Email must folllow email format e.g. xx@gmail.com",
"DATE_OF_BIRTH_REQUIRED" => "Date of Birth must be filled",
"DATE_OF_TERMINATED" => "Date of Terminated must be filled",
"SEX_REQUIRED" => "Sex must be filled",
"SEX_CODE_NOT_VALID" => "Sex must be filled F or M",
];