[WIP] Update Claim Table
This commit is contained in:
@@ -35,6 +35,9 @@ class CorporateMemberController extends Controller
|
|||||||
->with([
|
->with([
|
||||||
'employeds',
|
'employeds',
|
||||||
'currentPolicy',
|
'currentPolicy',
|
||||||
|
'claims' => function ($claim) {
|
||||||
|
return $claim->used();
|
||||||
|
}
|
||||||
])
|
])
|
||||||
->with('currentPlan')
|
->with('currentPlan')
|
||||||
->paginate()
|
->paginate()
|
||||||
|
|||||||
@@ -28,6 +28,15 @@ class Claim extends Model
|
|||||||
'updated_by',
|
'updated_by',
|
||||||
'deleted_by',
|
'deleted_by',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static $status = [
|
||||||
|
'draft' => 'Draft',
|
||||||
|
'requested' => 'Requested',
|
||||||
|
'received' => 'Received',
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'paid' => 'Paid',
|
||||||
|
'declined' => 'Declined'
|
||||||
|
];
|
||||||
|
|
||||||
protected static function boot()
|
protected static function boot()
|
||||||
{
|
{
|
||||||
@@ -61,5 +70,12 @@ class Claim extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Benefit::class, 'benefit_id');
|
return $this->belongsTo(Benefit::class, 'benefit_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeUsed($query, $startDate, $endDate)
|
||||||
|
{
|
||||||
|
return $query
|
||||||
|
->whereIn('status', ['approved', 'paid'])
|
||||||
|
->whereBetween('requested_at', $startDate, $endDate);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ class Member extends Model
|
|||||||
protected $appends = [
|
protected $appends = [
|
||||||
'full_name',
|
'full_name',
|
||||||
'age',
|
'age',
|
||||||
'gender_code'
|
'gender_code',
|
||||||
|
''
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
@@ -125,7 +126,7 @@ class Member extends Model
|
|||||||
{
|
{
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function policies()
|
public function policies()
|
||||||
{
|
{
|
||||||
return $this->hasMany(MemberPolicy::class, 'member_id', 'member_id');
|
return $this->hasMany(MemberPolicy::class, 'member_id', 'member_id');
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ namespace App\Services;
|
|||||||
|
|
||||||
use App\Models\Claim;
|
use App\Models\Claim;
|
||||||
use App\Models\Icd;
|
use App\Models\Icd;
|
||||||
|
use App\Models\Member;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Str;
|
use Str;
|
||||||
|
|
||||||
class ClaimService{
|
class ClaimService{
|
||||||
@@ -24,4 +26,19 @@ class ClaimService{
|
|||||||
|
|
||||||
return $claim;
|
return $claim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getMemberTotalUsage(Member $member, $startDate = null, $endDate = null)
|
||||||
|
{
|
||||||
|
$startDate = empty($startDate) ? Carbon::now()->startOfMonth() : $startDate;
|
||||||
|
$endDate = empty($endDate) ? Carbon::now()->startOfMonth() : $endDate;
|
||||||
|
|
||||||
|
$claims = $member->claims()
|
||||||
|
->used($startDate, $endDate)
|
||||||
|
->get();
|
||||||
|
$total = $claims->sum(function($claim){
|
||||||
|
return $claim->total_claim;
|
||||||
|
});
|
||||||
|
|
||||||
|
return $total;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -13,22 +13,22 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
Schema::create('corporate_plans', function (Blueprint $table) {
|
// Schema::create('corporate_plans', function (Blueprint $table) {
|
||||||
$table->id();
|
// $table->id();
|
||||||
$table->foreignId('corporate_id')->nullable()->index();
|
// $table->foreignId('corporate_id')->nullable()->index();
|
||||||
$table->string('code')->index();
|
// $table->string('code')->index();
|
||||||
$table->string('name')->nullable();
|
// $table->string('name')->nullable();
|
||||||
$table->text('description')->nullable();
|
// $table->text('description')->nullable();
|
||||||
$table->boolean('active')->default(true);
|
// $table->boolean('active')->default(true);
|
||||||
$table->timestamps();
|
// $table->timestamps();
|
||||||
$table->softDeletes();
|
// $table->softDeletes();
|
||||||
|
|
||||||
$table->foreignId('created_by')->nullable()->index();
|
// $table->foreignId('created_by')->nullable()->index();
|
||||||
$table->foreignId('updated_by')->nullable()->index();
|
// $table->foreignId('updated_by')->nullable()->index();
|
||||||
$table->foreignId('deleted_by')->nullable()->index();
|
// $table->foreignId('deleted_by')->nullable()->index();
|
||||||
|
|
||||||
$table->unique(["corporate_id", "code"], 'corporate_plans_unique');
|
// $table->unique(["corporate_id", "code"], 'corporate_plans_unique');
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,6 +38,6 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::dropIfExists('corporate_plans');
|
// Schema::dropIfExists('corporate_plans');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,21 @@ return new class extends Migration
|
|||||||
$table->string('currency');
|
$table->string('currency');
|
||||||
$table->foreignId('plan_id')->index();
|
$table->foreignId('plan_id')->index();
|
||||||
$table->foreignId('benefit_id')->index();
|
$table->foreignId('benefit_id')->index();
|
||||||
|
|
||||||
|
$table->dateTime('requested_at')->nullable();
|
||||||
|
$table->unsignedBigInteger('requested_by')->nullable()->index();
|
||||||
|
|
||||||
|
$table->dateTime('received_at')->nullable();
|
||||||
|
$table->unsignedBigInteger('received_by')->nullable()->index();
|
||||||
|
|
||||||
|
$table->dateTime('approved_at')->nullable();
|
||||||
|
$table->unsignedBigInteger('approved_by')->nullable()->index();
|
||||||
|
|
||||||
|
$table->dateTime('approved_at')->nullable();
|
||||||
|
$table->unsignedBigInteger('approved_by')->nullable()->index();
|
||||||
|
|
||||||
|
$table->dateTime('paid_at')->nullable();
|
||||||
|
$table->unsignedBigInteger('paid_by')->nullable()->index();
|
||||||
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->softDeletes();
|
$table->softDeletes();
|
||||||
|
|||||||
Reference in New Issue
Block a user