Update Linking With ASO
This commit is contained in:
@@ -4,7 +4,10 @@ namespace App\Http\Controllers\Api\OLDLMS;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\OLDLMS\MemberResource;
|
||||
use App\Models\Corporate;
|
||||
use App\Models\Member;
|
||||
use App\Rules\NikRule;
|
||||
use App\Services\ClaimService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -169,4 +172,83 @@ class MembershipController extends Controller
|
||||
|
||||
return Helper::responseJson(data: $limits);
|
||||
}
|
||||
|
||||
public function linkingRules(Request $request)
|
||||
{
|
||||
$corporates = Corporate::query()
|
||||
->when($request->search, function ($q, $search) {
|
||||
$q->where('name', 'LIKE', '%'.$search.'%');
|
||||
})
|
||||
->get();
|
||||
|
||||
return Helper::responseJson(data: $corporates);
|
||||
}
|
||||
|
||||
public function linkingValidate(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'corporate_id' => 'required'
|
||||
]);
|
||||
|
||||
$corporate = Corporate::findOrFail($request->corporate_id);
|
||||
|
||||
// Make Validation from Linking Rules
|
||||
$linkingRulesArr = $corporate->linking_rules->toArray();
|
||||
$validationRules = [];
|
||||
foreach ($linkingRulesArr as $field) {
|
||||
$rules = ['required']; // Default is required if in the linking_rules
|
||||
if ($field == 'email') {
|
||||
$rules[] = 'email';
|
||||
}
|
||||
|
||||
if ($field == 'nric') {
|
||||
$rules[] = new NikRule;
|
||||
}
|
||||
|
||||
$validationRules[$field] = $rules;
|
||||
}
|
||||
$request->validate($validationRules);
|
||||
|
||||
$member = Member::query()
|
||||
->when(in_array('nric', $linkingRulesArr), function($q) use ($request) {
|
||||
$q->where('nric', $request->nric);
|
||||
})
|
||||
->when(in_array('member_id', $linkingRulesArr), function($q) use ($request) {
|
||||
$q->where('member_id', $request->member_id);
|
||||
})
|
||||
->when(in_array('name', $linkingRulesArr), function($q) use ($request) {
|
||||
$q->where('name', $request->name);
|
||||
})
|
||||
->when(in_array('dob', $linkingRulesArr), function($q) use ($request) {
|
||||
$q->where('birth_date', $request->dob);
|
||||
})
|
||||
->when(in_array('phone', $linkingRulesArr), function($q) use ($request) {
|
||||
$q->whereHas('person', function ($person) use ($request) {
|
||||
$person->where('phone', $request->phone);
|
||||
});
|
||||
})
|
||||
->when(in_array('email', $linkingRulesArr), function($q) use ($request) {
|
||||
$q->where('email', $request->email);
|
||||
})
|
||||
->when(in_array('nik', $linkingRulesArr), function($q) use ($request) {
|
||||
$q->whereHas('employeds', function ($employed) use ($request) {
|
||||
$employed->where('corporate_id', $request->corporate_id)
|
||||
->where('nik', $request->nik);
|
||||
});
|
||||
})
|
||||
|
||||
->with([
|
||||
'memberPlans' => function ($memberPlan) {
|
||||
$memberPlan->latest();
|
||||
},
|
||||
])
|
||||
|
||||
->first();
|
||||
|
||||
if ($member) {
|
||||
return Helper::responseJson(data: MemberResource::make($member), message: 'Data Member ditemukan!');
|
||||
}
|
||||
|
||||
return Helper::responseJson(data: [], message: 'Member Tidak ditemukan', statusCode: 404, status: 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,23 @@ class MemberResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
// $data = parent::toArray($request);
|
||||
$currentMemberPlan = $this->memberPlans?->first();
|
||||
$currentPlan = $currentMemberPlan ? [
|
||||
'code' => $currentMemberPlan->plan->code ?? null,
|
||||
'start' => $currentMemberPlan->start,
|
||||
'end' => $currentMemberPlan->end
|
||||
] : null;
|
||||
|
||||
$data = [
|
||||
'member_id' => $this->member_id,
|
||||
'birth_date' => $this->birth_date,
|
||||
'email' => $this->email,
|
||||
'phone' => $this->person->phone ?? null,
|
||||
'full_name' => $this->full_name,
|
||||
'nric' => $this->nric,
|
||||
'plan' => $currentPlan
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
@@ -23,7 +24,7 @@ class Corporate extends Model
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'linking_rules' => 'array',
|
||||
'linking_rules' => AsArrayObject::class,
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
|
||||
@@ -141,7 +141,8 @@ class Member extends Model
|
||||
|
||||
public function currentPlan()
|
||||
{
|
||||
return $this->hasOneThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id')->latest();
|
||||
return $this->hasOneThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id')
|
||||
->latest(); // TODO Fix This
|
||||
}
|
||||
|
||||
public function policies()
|
||||
|
||||
@@ -31,4 +31,17 @@ class MemberPlan extends Model
|
||||
{
|
||||
return $this->belongsTo(CorporatePlan::class, 'plan_id', 'code');
|
||||
}
|
||||
|
||||
public function plan()
|
||||
{
|
||||
return $this->belongsTo(Plan::class, 'plan_id');
|
||||
}
|
||||
|
||||
public function scopeActive($q)
|
||||
{
|
||||
return $q
|
||||
->where('start', '<', now())
|
||||
->where('end', '>', now())
|
||||
->latest();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Rules\NikRule;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Str;
|
||||
|
||||
|
||||
66
app/Rules/NikRule.php
Normal file
66
app/Rules/NikRule.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class NikRule implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
// The NIK is a 16-digit number
|
||||
if (!preg_match('/^[0-9]{16}$/', $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// // The first 6 digits represent the person's birth date in the format of YYMMDD
|
||||
// $year = substr($value, 6, 2);
|
||||
// $month = substr($value, 8, 2);
|
||||
// $day = substr($value, 10, 2);
|
||||
|
||||
// // dd($year, $month, $day);
|
||||
// // dd(checkdate($month, $day, "19{$year}"));
|
||||
|
||||
// if (!checkdate($month, $day, "19{$year}")) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// // The next 2 digits represent the place of birth (province/city code)
|
||||
// $provinceCode = substr($value, 6, 2);
|
||||
|
||||
// // The next 2 digits represent the person's gender (odd for male, even for female)
|
||||
// $genderCode = substr($value, 14, 1);
|
||||
|
||||
// // The last 4 digits represent the sequence number of the person's birth in that day
|
||||
// $sequenceNumber = substr($value, 12, 4);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return ':attribute bukan valid NIK Indonesia.';
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ export default function CorporateForm({ isEdit, currentCorporate }: Props) {
|
||||
policy_stop_service_net: currentCorporate?.current_policy?.minimal_stop_service_net || 0,
|
||||
policy_start: currentCorporate?.current_policy?.start || '',
|
||||
policy_end: currentCorporate?.current_policy?.end || '',
|
||||
linking_rules: currentCorporate?.linking_rules || ['nrik', 'nik', 'member_id'],
|
||||
linking_rules: currentCorporate?.linking_rules || ['nric', 'nik', 'member_id'],
|
||||
type: currentCorporate?.type || 'corporate',
|
||||
logo: currentCorporate?.logo || '',
|
||||
}),
|
||||
@@ -174,6 +174,8 @@ export default function CorporateForm({ isEdit, currentCorporate }: Props) {
|
||||
formData.append('policy_end', data.policy_end);
|
||||
formData.append('linking_rules', data.linking_rules);
|
||||
|
||||
console.log('MOTHERFUCKER', data.linking_rules)
|
||||
|
||||
if (!isEdit) {
|
||||
const response = await axios.post('/corporates', formData);
|
||||
} else {
|
||||
@@ -269,7 +271,7 @@ export default function CorporateForm({ isEdit, currentCorporate }: Props) {
|
||||
const linking_rules_checkbox_name = 'linking_rules';
|
||||
const linking_tools = [
|
||||
{
|
||||
value: 'nrik',
|
||||
value: 'nric',
|
||||
label: 'No. KTP',
|
||||
},
|
||||
{
|
||||
@@ -425,6 +427,7 @@ export default function CorporateForm({ isEdit, currentCorporate }: Props) {
|
||||
Linking Rules
|
||||
</Typography>
|
||||
<Stack>
|
||||
{JSON.stringify(getValues('linking_rules'))}
|
||||
<RHFCustomMultiCheckbox name="linking_rules" options={linking_tools} />
|
||||
</Stack>
|
||||
</Stack>
|
||||
|
||||
@@ -154,7 +154,7 @@ export default function FormulariumForm({ isEdit, currentFormularium }: Props) {
|
||||
const linking_rules_checkbox_name = "linking_rules"
|
||||
const linking_tools = [
|
||||
{
|
||||
"value" : "nrik",
|
||||
"value" : "nric",
|
||||
"label" : "No. KTP"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -22,7 +22,10 @@ Route::middleware('linksehat.old.auth')->group(function() {
|
||||
Route::post('check-membership', [MembershipController::class, 'check']);
|
||||
Route::post('check-limit', [MembershipController::class, 'checkLimit']);
|
||||
Route::post('check-coverage-limit', [MembershipController::class, 'checkLimit']);
|
||||
Route::get('linking-rules', [MembershipController::class, 'linkingRules']);
|
||||
Route::post('linking-validate', [MembershipController::class, 'linkingValidate']);
|
||||
|
||||
Route::post('claim-create', [ClaimController::class, 'store']);
|
||||
Route::post('claim-update-diagnosis', [ClaimController::class, 'updateClaimDiagnosis']);
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user