[WIP] Update Claim Table

This commit is contained in:
R
2022-12-05 16:20:09 +07:00
parent 3bc8877740
commit 885edec290
6 changed files with 69 additions and 17 deletions

View File

@@ -35,6 +35,9 @@ class CorporateMemberController extends Controller
->with([
'employeds',
'currentPolicy',
'claims' => function ($claim) {
return $claim->used();
}
])
->with('currentPlan')
->paginate()

View File

@@ -28,6 +28,15 @@ class Claim extends Model
'updated_by',
'deleted_by',
];
public static $status = [
'draft' => 'Draft',
'requested' => 'Requested',
'received' => 'Received',
'approved' => 'Approved',
'paid' => 'Paid',
'declined' => 'Declined'
];
protected static function boot()
{
@@ -61,5 +70,12 @@ class Claim extends Model
{
return $this->belongsTo(Benefit::class, 'benefit_id');
}
public function scopeUsed($query, $startDate, $endDate)
{
return $query
->whereIn('status', ['approved', 'paid'])
->whereBetween('requested_at', $startDate, $endDate);
}
}

View File

@@ -60,7 +60,8 @@ class Member extends Model
protected $appends = [
'full_name',
'age',
'gender_code'
'gender_code',
''
];
protected $hidden = [
@@ -125,7 +126,7 @@ class Member extends Model
{
return $this->hasOneThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id')->latest();
}
public function policies()
{
return $this->hasMany(MemberPolicy::class, 'member_id', 'member_id');

View File

@@ -4,6 +4,8 @@ namespace App\Services;
use App\Models\Claim;
use App\Models\Icd;
use App\Models\Member;
use Carbon\Carbon;
use Str;
class ClaimService{
@@ -24,4 +26,19 @@ class ClaimService{
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;
}
}

View File

@@ -13,22 +13,22 @@ return new class extends Migration
*/
public function up()
{
Schema::create('corporate_plans', function (Blueprint $table) {
$table->id();
$table->foreignId('corporate_id')->nullable()->index();
$table->string('code')->index();
$table->string('name')->nullable();
$table->text('description')->nullable();
$table->boolean('active')->default(true);
$table->timestamps();
$table->softDeletes();
// Schema::create('corporate_plans', function (Blueprint $table) {
// $table->id();
// $table->foreignId('corporate_id')->nullable()->index();
// $table->string('code')->index();
// $table->string('name')->nullable();
// $table->text('description')->nullable();
// $table->boolean('active')->default(true);
// $table->timestamps();
// $table->softDeletes();
$table->foreignId('created_by')->nullable()->index();
$table->foreignId('updated_by')->nullable()->index();
$table->foreignId('deleted_by')->nullable()->index();
// $table->foreignId('created_by')->nullable()->index();
// $table->foreignId('updated_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()
{
Schema::dropIfExists('corporate_plans');
// Schema::dropIfExists('corporate_plans');
}
};

View File

@@ -22,6 +22,21 @@ return new class extends Migration
$table->string('currency');
$table->foreignId('plan_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->softDeletes();