update validasi
This commit is contained in:
@@ -12,10 +12,7 @@ use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
|
||||
|
||||
class CorporateService
|
||||
{
|
||||
protected function validatePlanRow($row)
|
||||
{
|
||||
// $corporate_policy = CorporatePolicy::where('corporate_id', $corporateId)->get();
|
||||
/*
|
||||
/*
|
||||
Refer to Coverage code :
|
||||
MEDIVAC = Medical evacuation
|
||||
MSO = Medical second opinion
|
||||
@@ -34,8 +31,25 @@ class CorporateService
|
||||
LAB = Test Diagnostic
|
||||
PHAR = Pharmacy
|
||||
**/
|
||||
protected $service_code = ['MEDIVAC', 'MSO', 'PAC', 'OPDE', 'IP', 'OP', 'MA', 'ANC', 'DE', 'GL', 'SP', 'PF', 'MCU', 'KB-VACC', 'LAB', 'PHAR'];
|
||||
|
||||
protected function corporatePlansId($corporate_id){
|
||||
$plans = Plan::where('corporate_id', $corporate_id)->get()->toArray();
|
||||
$current_corporate_plans_id = [];
|
||||
if($plans){
|
||||
foreach($plans as $plan){
|
||||
array_push($current_corporate_plans_id,$plan['corporate_plan_id']);
|
||||
}
|
||||
}
|
||||
return $current_corporate_plans_id;
|
||||
}
|
||||
|
||||
protected function validatePlanRow($row, $corporate_id)
|
||||
{
|
||||
// $corporate_policy = CorporatePolicy::where('corporate_id', $corporateId)->get();
|
||||
$plans = Plan::where('corporate_id', $corporate_id)->get()->toArray();
|
||||
$current_corporate_plans = $this->corporatePlansId($corporate_id);
|
||||
|
||||
$service_code = ['MEDIVAC', 'MSO', 'PAC', 'OPDE', 'IP', 'OP', 'MA', 'ANC', 'DE', 'GL', 'SP', 'PF', 'MCU', 'KB-VACC', 'LAB', 'PHAR'];
|
||||
$plan_code = [1, 2, 3, 4];
|
||||
$prorate_type = [0, 1, 2];
|
||||
$family_plan = ['F', 'S', 'N'];
|
||||
@@ -44,7 +58,7 @@ class CorporateService
|
||||
throw new ImportRowException(__('plan.REQUIRED', [
|
||||
'attribute' => 'Service Code'
|
||||
] ), 0, null, $row);
|
||||
} else if (!in_array($row['service_code'], $service_code)){
|
||||
} else if (!in_array($row['service_code'], $this->service_code)){
|
||||
throw new ImportRowException(__('plan.NOT_MATCH', [
|
||||
'attribute' => 'Service Code',
|
||||
'code' => $row['service_code']
|
||||
@@ -55,6 +69,11 @@ class CorporateService
|
||||
throw new ImportRowException(__('plan.REQUIRED', [
|
||||
'attribute' => 'Plan'
|
||||
]), 0, null, $row);
|
||||
} else if(!in_array($row['corporate_plan_id'], $current_corporate_plans)){
|
||||
throw new ImportRowException(__('plan.NOT_MATCH', [
|
||||
'attribute' => 'Plans',
|
||||
'code' => $row['corporate_plan_id']
|
||||
]), 0, null, $row);
|
||||
}
|
||||
|
||||
if (empty($row['code'])) {
|
||||
@@ -87,28 +106,21 @@ class CorporateService
|
||||
// ]), 0, null, $row);
|
||||
// }
|
||||
|
||||
if (!empty($row['family_plan']) && !in_array($family_plan)) {
|
||||
if (!empty($row['family_plan']) && !in_array($row['family_plan'],$family_plan)) {
|
||||
throw new ImportRowException(__('plan.NOT_MATCH', [
|
||||
'attribute' => 'Family Plan',
|
||||
'code' => $row['family_plan']
|
||||
]), 0, null, $row);
|
||||
}
|
||||
|
||||
if (!empty($row['family_plan']) && !in_array($family_plan)) {
|
||||
throw new ImportRowException(__('plan.NOT_MATCH', [
|
||||
'attribute' => 'Family Plan',
|
||||
'code' => $row['family_plan']
|
||||
]), 0, null, $row);
|
||||
}
|
||||
|
||||
if (!empty($row['prorate_type']) && !in_array($prorate_type)) {
|
||||
if (!empty($row['prorate_type']) && !in_array($row['prorate_type'], $prorate_type)) {
|
||||
throw new ImportRowException(__('plan.NOT_MATCH', [
|
||||
'attribute' => 'Prorate Type',
|
||||
'code' => $row['prorate_type']
|
||||
]), 0, null, $row);
|
||||
}
|
||||
|
||||
if (!empty($row['prorate_lookup']) && !in_array($prorate_type)) {
|
||||
if (!empty($row['prorate_lookup']) && !in_array($row['prorate_lookup'], $prorate_type)) {
|
||||
throw new ImportRowException(__('plan.NOT_MATCH', [
|
||||
'attribute' => 'Prorate Lookup',
|
||||
'code' => $row['prorate_lookup']
|
||||
@@ -117,6 +129,8 @@ class CorporateService
|
||||
|
||||
if (empty($row['limit_rules'])) {
|
||||
throw new ImportRowException(__('plan.PLAN_LIMIT_REQUIRED'), 0, null, $row);
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
if (empty($row['msc'])) {
|
||||
@@ -124,11 +138,12 @@ class CorporateService
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function handlePlanRow(Corporate $corporate, $row)
|
||||
{
|
||||
try {
|
||||
$plan_data = $row;
|
||||
$this->validatePlanRow($plan_data);
|
||||
$this->validatePlanRow($plan_data, $corporate->id);
|
||||
$plan_data["corporate_id"] = $corporate->id;
|
||||
$plan = $corporate->plans()->updateOrCreate([
|
||||
'corporate_plan_id' => $plan_data['corporate_plan_id'],
|
||||
@@ -141,52 +156,76 @@ class CorporateService
|
||||
}
|
||||
}
|
||||
|
||||
protected function validateBenefitRow($row)
|
||||
protected function validateBenefitRow($row, $corporate_id)
|
||||
{
|
||||
$max_frequence = 7;
|
||||
$budget_aso = [1,2];
|
||||
$current_corporate_plans = $this->corporatePlansId($corporate_id);
|
||||
if (empty($row['service_code'])) {
|
||||
throw new ImportRowException(__('benefit.SERVICE_CODE_REQUIRED'), 0, null, $row);
|
||||
throw new ImportRowException(__('plan.REQUIRED', [
|
||||
'attribute' => 'Service Code'
|
||||
]), 0, null, $row);
|
||||
} else if (!in_array($row['service_code'], $this->service_code)){
|
||||
throw new ImportRowException(__('plan.NOT_MATCH', [
|
||||
'attribute' => 'Service Code',
|
||||
'code' => $row['service_code']
|
||||
]), 0, null, $row);
|
||||
}
|
||||
|
||||
if (empty($row['plan_code'])) {
|
||||
throw new ImportRowException(__('benefit.PLAN_CODE_REQUIRED'), 0, null, $row);
|
||||
} else if (!in_array($row['plan_code'], $current_corporate_plans)){
|
||||
throw new ImportRowException(__('plan.NOT_MATCH', [
|
||||
'attribute' => 'Plan',
|
||||
'code' => $row['plan_code']
|
||||
]), 0, null, $row);
|
||||
}
|
||||
|
||||
if (empty($row['code'])) {
|
||||
throw new ImportRowException(__('benefit.BENEFIT_CODE_REQUIRED'), 0, null, $row);
|
||||
throw new ImportRowException(__('plan.REQUIRED', [
|
||||
'attribute' => 'Benefit Code'
|
||||
]), 0, null, $row);
|
||||
}
|
||||
if (empty($row['corporate_benefit_code'])) {
|
||||
throw new ImportRowException(__('benefit.CUSTOMER_BENEFIT_CODE_REQUIRED'), 0, null, $row);
|
||||
throw new ImportRowException(__('plan.REQUIRED', [
|
||||
'attribute' => 'Customer Benefit Code'
|
||||
]), 0, null, $row);
|
||||
}
|
||||
if (empty($row['description'])) {
|
||||
throw new ImportRowException(__('benefit.DESCRIPTION_REQUIRED'), 0, null, $row);
|
||||
throw new ImportRowException(__('plan.REQUIRED', [
|
||||
'attribute' => 'Description'
|
||||
]), 0, null, $row);
|
||||
}
|
||||
if (empty($row['limit_amount'])) {
|
||||
throw new ImportRowException(__('benefit.LIMIT_AMOUNT_REQUIRED'), 0, null, $row);
|
||||
throw new ImportRowException(__('plan.REQUIRED', [
|
||||
'attribute' => 'Limit Amount'
|
||||
]), 0, null, $row);
|
||||
}
|
||||
if (empty($row['msc'])) {
|
||||
throw new ImportRowException(__('benefit.MSC_REQUIRED'), 0, null, $row);
|
||||
throw new ImportRowException(__('plan.REQUIRED', [
|
||||
'attribute' => 'MSC'
|
||||
]), 0, null, $row);
|
||||
}
|
||||
if (empty($row['genders'])) {
|
||||
throw new ImportRowException(__('benefit.GENDER_REQUIRED'), 0, null, $row);
|
||||
throw new ImportRowException(__('plan.REQUIRED', [
|
||||
'attribute' => 'Gender'
|
||||
]), 0, null, $row);
|
||||
}
|
||||
if (!empty($row['max_frequency_period']) && $row['max_frequency_period'] >= $max_frequence){ // jenis frequence
|
||||
throw new ImportRowException(__('benefit.MAX_FREQUENCY'), 0, null, $row);
|
||||
throw new ImportRowException(__('plan.MAX_FREQUENCY'), 0, null, $row);
|
||||
}
|
||||
|
||||
if (!empty($row['budget']) && !in_array($budget_aso)) {
|
||||
|
||||
if (!empty($row['budget']) && !in_array($budget_aso)) {
|
||||
throw new ImportRowException(__('plan.MAX_FREQUENCY'), 0, null, $row);
|
||||
}
|
||||
}
|
||||
|
||||
public function handleBenefitRow(Corporate $corporate, $row)
|
||||
{
|
||||
|
||||
try {
|
||||
$benefit_data = $row;
|
||||
$this->validateBenefitRow($benefit_data, $corporate->id);
|
||||
$benefit_data["corporate_id"] = $corporate->id;
|
||||
$this->validateBenefitRow($benefit_data);
|
||||
|
||||
|
||||
$plan = $corporate->plans()
|
||||
->where('corporate_plan_id', $benefit_data['plan_code'])
|
||||
->first();
|
||||
@@ -200,7 +239,6 @@ class CorporateService
|
||||
], [
|
||||
'code' => $benefit_data['code'],
|
||||
'service_code' => $plan->service_code,
|
||||
'active' => 1,
|
||||
'description' => $benefit_data['description'],
|
||||
]);
|
||||
|
||||
@@ -211,7 +249,6 @@ class CorporateService
|
||||
|
||||
return $corporateBenefit;
|
||||
} catch (\Exception $e) {
|
||||
// dd($e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,9 @@ return [
|
||||
"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",
|
||||
|
||||
|
||||
"MAX_FREQUENCY" => "Max Frequency must be less 6",
|
||||
|
||||
"RELATIONSHIP_WITH_PRICIPAL_REQUIRED" => "Relationship must be filled",
|
||||
"RELATIONSHIP_WITH_PRICIPAL_NOT_VALID" => "Relationship must be filled W, S, D or H",
|
||||
|
||||
Reference in New Issue
Block a user