155 lines
8.6 KiB
PHP
155 lines
8.6 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use App\Traits\Blameable;
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
use Illuminate\Database\Eloquent\Model;
|
||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||
|
||
class Member extends Model
|
||
{
|
||
use HasFactory, SoftDeletes, Blameable;
|
||
|
||
protected $fillable = [
|
||
"id",
|
||
"member_id",
|
||
"record_type",
|
||
"payor_id",
|
||
"user_id",
|
||
"name_prefix",
|
||
"name",
|
||
"name_suffix",
|
||
"birth_date",
|
||
"gender",
|
||
"language",
|
||
"race",
|
||
"marital_status",
|
||
"principal_id",
|
||
"relation_with_principal",
|
||
"bpjs_class",
|
||
"active",
|
||
"created_by",
|
||
"updated_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 = [
|
||
"Record Mode" => "record_mode",
|
||
"Record Type" => "record_type",
|
||
"Payor ID" => "payor_id",
|
||
"Member ID" => "member_id",
|
||
"Mapping ID" => "principal_id",
|
||
"Halodoc Member ID" => "halodoc_member_id",
|
||
"Corporate ID" => "corporate_id",
|
||
"NIK" => "nik",
|
||
"Division" => "division_code",
|
||
"Branch Code" => "branch_code",
|
||
"Bank Info" => "banks_info",
|
||
"Language" => "language",
|
||
"Type of work" => "type_of_work",
|
||
"Race" => "race",
|
||
"Policy Number" => "policy_number",
|
||
"Marital Status" => "marital_status",
|
||
"Relationship" => "relationship_with_principal",
|
||
"Member's Effective Date" => "member_effective_date",
|
||
"Member's Expiry Date" => "member_expiry_date",
|
||
"Faskes FKTP (First Level Provider) or Individual preferred provider" => "faskes_fktp",
|
||
"Faskes FKRTL (Next Level Provider) or Individual group preferred provider" => "faskes_fkrtl",
|
||
"The Right Classes Room of BPJS Participants" => "bpjs_class",
|
||
"Name of Faskes" => "faskes_name",
|
||
"Rule_BPJSK ('Y' or 'N')" => "bpjsk",
|
||
"Agent Code / intermediary code" => "agent_code",
|
||
"Member Name" => "name",
|
||
"Address1" => "address1",
|
||
"Address2" => "address2",
|
||
"Address3" => "address3",
|
||
"Address4" => "address4",
|
||
"City" => "city",
|
||
"State" => "state",
|
||
"Post Code" => "post_code",
|
||
"Telephone – Mobile" => "telephone_mobile",
|
||
"Telephone – Res" => "telephone_res",
|
||
"Telephone – Office" => "telephone_office",
|
||
"NRIC" => "nric",
|
||
"Passport No" => "passport_number",
|
||
"Passport Country" => "passport_country",
|
||
"Email" => "email",
|
||
"Identification Code" => "identification_code",
|
||
"Date of Birth" => "date_of_birth",
|
||
"Sex" => "sex",
|
||
"Internal Use" => "internal_use",
|
||
"Plan-ID" => "plan_id",
|
||
"Employment-Status" => "employment_status",
|
||
"Internal Use" => "internal_use_1",
|
||
"Internal Use" => "internal_use_2",
|
||
"Internal Use" => "internal_use_3",
|
||
"Date Terminated" => "date_terminated",
|
||
"Pre Existing" => "pre_existing",
|
||
"BPJS ID" => "bpjs_id",
|
||
"Endorsement Date" => "endorsement_date",
|
||
"Remarks" => "remarks",
|
||
"Internal Use" => "internal_use_4",
|
||
"Member Since" => "member_since",
|
||
"Internal Use" => "internal_use_5",
|
||
"Policy In Force" => "policy_in_force",
|
||
"Member Suspended" => "member_suspended",
|
||
"Activation Date" => "activation_date",
|
||
"Internal Use" => "internal_use_6",
|
||
"StartNoClaim" => "start_no_claim",
|
||
"EndNoClaim" => "end_no_claim",
|
||
"Option Mode" => "option_mode",
|
||
];
|
||
|
||
public function employeds()
|
||
{
|
||
return $this->hasMany(CorporateEmployee::class, 'member_id');
|
||
}
|
||
|
||
public function policies()
|
||
{
|
||
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) {
|
||
return $query
|
||
->where('member_id', 'like', "%" . $search . "%")
|
||
->orWhere('payor_id', 'like', "%" . $search . "%")
|
||
->orWhere('name', 'like', "%" . $search . "%")
|
||
;
|
||
// ->orWhereHas('corporatePlan', function ($query) use ($search) {
|
||
// $query->where('code', 'like', "%" . $search . "%");
|
||
// });
|
||
});
|
||
}
|
||
}
|