This commit is contained in:
R
2023-03-01 12:07:03 +07:00
parent ce0fde18dc
commit 89cd2a9d37
36 changed files with 1366 additions and 206 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Events;
use App\Models\ClaimRequest;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
@@ -14,14 +15,16 @@ class ClaimRequested
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $claim_request;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
public function __construct(ClaimRequest $claimRequest)
{
//
$this->claim_request = $claimRequest;
}
/**

View File

@@ -0,0 +1,92 @@
<?php
namespace App\Http\Controllers;
use App;
use App\Models\GeneratedDocument;
use Illuminate\Http\Request;
use PDF;
use Response;
class GeneratedDocumentController extends Controller
{
// Display Content from generated_documents to used by pdf generator (wkhtmltopdf)
public function show($id)
{
$document = GeneratedDocument::findOrFail($id);
return $document->html_content.$document->html_content.$document->html_content.$document->html_content.$document->html_content;
}
public function header(Request $request)
{
return '<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<pre>'.json_encode($request->toArray()).'
<table>
<tbody>
<tr>
<td style="width: 200px; background-color: #00be67;"> asdkjasnd </td>
<td style="width: 500px; background-color: #0a94e3;" align="center"> asjdkadsn </td>
<td style="width: 200px; background-color: #7b3f25" align="right"> qkjwenkqwjenkqwjen </td>
</tr>
</tbody>
</table>
</body>
</html>';
}
public function footer()
{
return "<h2>Footer Fatherfucker</h2>";
}
public function pdf($id)
{
// return 'fuck';
// $document = GeneratedDocument::findOrFail($id);
// $pdf = PDF::loadFile('http://localhost:8000/');
// $pdf = PDF::loadFile('http://aso-linksehat.local/');
// return $pdf->inline();
// dd(route('generated-document.show', $id));
// $pdf = PDF::loadFile(route('generated-document.show', $id));
// return $pdf->inline();
// $snappy = App::make('snappy.pdf');
// $html = '<h1>Bill</h1><p>You owe me money, dude.</p>';
// // $snappy->generateFromHtml($html, '/tmp/bill-123.pdf');
// // $snappy->generate('http://www.github.com', '/tmp/github.pdf');
// //Or output:
// return new Response(
// $snappy->getOutputFromHtml($html),
// 200,
// array(
// 'Content-Type' => 'application/pdf',
// 'Content-Disposition' => 'attachment; filename="file.pdf"'
// )
// );
$pdf = PDF::loadFile(route('generated-document.show', $id));
// $pdf->loadFile(route('generated-document.show', $id));
// $pdf->loadFile(route('generated-document.show', $id));
// $pdf->loadFile(route('generated-document.show', $id));
// $pdf->loadFile(route('generated-document.show', $id));
// $pdf->setPaper('a4')->setOrientation('landscape')->setOption('margin-bottom', 0);
// $pdf->setOption('header-html', route('pdf.header'));
// $pdf->setOption('footer-html', route('pdf.header'));
// $pdf->setOption('footer-center', 'asdasdasd');
// $pdf->setOption('footer-html', route('pdf.footer'));
// $pdf->loadHtml('asdasdasd');
return $pdf->inline();
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Listeners;
use App\Events\ClaimRequested;
use App\Models\User;
use App\Notifications\ClaimRequestedNotification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class NotifyClaimRequested
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \App\Events\ClaimRequested $event
* @return void
*/
public function handle(ClaimRequested $event)
{
// TODO List Of User that should be notified about Claim that Requested
$user = User::first();
$user->notify(new ClaimRequestedNotification());
}
}

View File

@@ -18,8 +18,11 @@ use Illuminate\Support\Str;
class Claim extends Model
{
use HasFactory, Blameable, SoftDeletes;
protected static $code_prefix = 'CLM';
protected $fillable = [
'claim_request_id',
'code',
'member_id',
'total_claim',
@@ -54,7 +57,8 @@ class Claim extends Model
static::creating(function ($model) {
try {
$model->code = (string) Str::orderedUuid(); // generate uuid
$model->uuid = (string) Str::orderedUuid(); // generate uuid
$model->code = self::getNextCode();
} catch (\Exception $e) {
abort(500, $e->getMessage());
}
@@ -78,9 +82,9 @@ class Claim extends Model
'status' => $model->status
]);
if ($model->status == 'requested') {
ClaimRequested::dispatch($model);
}
// if ($model->status == 'requested') {
// ClaimRequested::dispatch($model);
// }
if ($model->status == 'received') {
ClaimReceived::dispatch($model);
@@ -104,6 +108,20 @@ class Claim extends Model
}
});
}
public static function getNextCode()
{
$last_number = self::withTrashed()->max('code');
$next_number = empty($last_number) ? 1 : ((int) explode('-', $last_number)[1] + 1);
return self::makeCode($next_number);
}
public static function makeCode($next_number)
{
return (string) self::$code_prefix .'-'. str_pad($next_number, 5, 0, STR_PAD_LEFT);
}
public function files()
{

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Models;
use App\Traits\Blameable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ClaimHistory extends Model
{
use HasFactory, Blameable;
public $fillable = [
'claim_id',
'title',
'description',
'type',
'parent_id',
'data',
'system_origin'
];
public static $types = [
'info',
'document-request',
'document-submit'
];
public function parent()
{
return $this->belongsTo(ClaimHistory::class, 'parent_id');
}
public function childs()
{
return $this->hasMany(Claimhistory::class, 'parent_id');
}
public function claim()
{
return $this->belongsTo(Claim::class, 'claim_id');
}
public function historiable()
{
return $this->morphTo();
}
}

View File

@@ -2,10 +2,13 @@
namespace App\Models;
use App\Events\ClaimReceived;
use App\Events\ClaimRequested;
use App\Traits\Blameable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Str;
class ClaimRequest extends Model
{
@@ -13,17 +16,91 @@ class ClaimRequest extends Model
protected static $code_prefix = 'CRQ';
public $fillable = [
'submission_date',
'member_id',
'status',
'claim_id'
];
protected $hidden = [
// 'created_at',
'updated_at',
'deleted_at',
'created_by',
'updated_by',
'deleted_by',
];
public static $status = [
'draft' => 'Draft',
'requested' => 'Requested',
'received' => 'Received',
'approved' => 'Approved',
'postpone' => 'Postpone',
'paid' => 'Paid',
'declined' => 'Declined'
];
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
try {
$model->uuid = (string) Str::orderedUuid(); // generate uuid
$model->code = self::getNextCode();
} catch (\Exception $e) {
abort(500, $e->getMessage());
}
});
static::created(function ($model) {
// try {
// if (!empty($model->status) && $model->status == 'requested') {
// $model->histories()->create([
// 'title' => 'New Claim Requested',
// 'description' => "Claim Requested for Member : {$model->member->member_id} - ({$model->member->full_name})",
// 'type' => 'info'
// ]);
// }
// } catch (\Exception $e) {
// abort(500, $e->getMessage());
// }
});
static::updated(function ($model) {
if ($model->hasChanges(['status'])) {
// if ($model->status == 'requested') {
// $model->histories()->create([
// 'title' => 'New Claim Requested',
// 'description' => "Claim Requested for Member : {$model->member->member_id} - ({$model->member->full_name})",
// 'type' => 'info'
// ]);
// }
// if ($model->status == 'received') {
// ClaimReceived::dispatch($model);
// }
// if ($model->status == 'approved') {
// ClaimApproved::dispatch($model);
// }
// if ($model->status == 'postpone') {
// ClaimPostpone::dispatch($model);
// }
// if ($model->status == 'paid') {
// ClaimPaid::dispatch($model);
// }
// if ($model->status == 'declined') {
// ClaimDeclined::dispatch($model);
// }
}
});
}
public static function getNextCode()
@@ -39,17 +116,26 @@ class ClaimRequest extends Model
return (string) self::$code_prefix .'-'. str_pad($next_number, 5, 0, STR_PAD_LEFT);
}
public $fillable = [
'submission_date',
'member_id',
'status'
];
public function claims()
{
return $this->hasMany(Claim::class, 'claim_request_id');
}
public function files()
{
return $this->morphMany(File::class, 'fileable');
}
public function generatedDocuments()
{
return $this->morphMany(GeneratedDocument::class, 'generated_documentable');
}
public function histories()
{
return $this->morphMany(ClaimHistory::class, 'historiable');
}
public function member()
{
return $this->belongsTo(Member::class, 'member_id', 'id');

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use PDF;
class GeneratedDocument extends Model
{
use HasFactory;
public $fillable = [
'type',
'title',
'document_type',
'html_content',
'system_origin',
'parent_id'
];
public function parent()
{
return $this->belongsTo(GeneratedDocument::class, 'parent_id');
}
public function childs()
{
return $this->hasMany(GeneratedDocument::class, 'parent_id');
}
public function generated_documentable()
{
return $this->morphTo();
}
public function makePdf()
{
return PDF::loadFile(route('generated-document.show', $this->id));
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models\OLDLMS;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Kota extends Model
{
use HasFactory, SoftDeletes;
const CREATED_AT = 'dCreateOn';
const UPDATED_AT = 'dUpdateOn';
const DELETED_AT = 'dDeleteOn';
protected $connection = 'oldlms';
protected $table = 'tm_kota';
protected $primaryKey = 'nID';
public function provinsi()
{
return $this->belongsTo(Provinsi::class, 'nIDProvinsi', 'nID');
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models\OLDLMS;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Provinsi extends Model
{
use HasFactory, SoftDeletes;
const CREATED_AT = 'dCreateOn';
const UPDATED_AT = 'dUpdateOn';
const DELETED_AT = 'dDeleteOn';
protected $connection = 'oldlms';
protected $table = 'tm_provinsi';
protected $primaryKey = 'nID';
}

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class ClaimRequestedNotification extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'asdasd' => 'asdasdsd'
];
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Providers;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class ClaimRequested
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}

View File

@@ -4,6 +4,7 @@ namespace App\Providers;
use App\Events\ClaimApproved;
use App\Listeners\LogClaimJournal;
use App\Listeners\NotifyClaimRequested;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
@@ -21,9 +22,14 @@ class EventServiceProvider extends ServiceProvider
SendEmailVerificationNotification::class,
],
ClaimRequested::class => [
NotifyClaimRequested::class,
],
ClaimApproved::class => [
LogClaimJournal::class,
]
],
];
/**
@@ -43,6 +49,6 @@ class EventServiceProvider extends ServiceProvider
*/
public function shouldDiscoverEvents()
{
return false;
return true;
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Services;
use App\Events\ClaimApproved;
use App\Events\ClaimRequested;
use App\Models\Claim;
use App\Models\ClaimRequest;
use App\Models\Icd;
use App\Models\Member;
use Carbon\Carbon;
use DB;
use Str;
class ClaimRequestService{
public static function storeClaimRequest($member, $submissionDate = null, $status = 'requested')
{
try {
DB::beginTransaction();
$claimRequestData = [
'member_id' => $member->id,
'submission_date' => $submissionDate ?? now(),
'status' => $status
];
$claimRequest = ClaimRequest::create($claimRequestData);
DB::commit();
return $claimRequest;
} catch (\Exception $error) {
DB::rollBack();
throw new \Exception($error);
}
}
}

View File

@@ -119,8 +119,6 @@ class ClaimService{
->active()
->first();
// dd($benefit->toArray());
// dd(compact(['plan', 'policy', 'corporate', 'benefit']));
$limits = [
'total_limit' => $corporateBenefit ? $corporateBenefit->limit_amount : 0,
'frequency_limit_name' => $corporateBenefit ? $corporateBenefit->max_frequency_period_name : null,
@@ -163,22 +161,21 @@ class ClaimService{
return $limits;
}
public static function storeClaim($member, $diagnosis, $totalClaim, $benefit, $status)
public static function storeClaim($member, $diagnosis = null, $totalClaim = null, $benefit = null, $status = 'requested', $claimRequest = null)
{
try {
DB::beginTransaction();
$claimData = [
'member_id' => $member->id,
'claim_request_id' => $claimRequest->id ?? null,
'diagnosis_id' => $diagnosis->id ?? null,
'total_claim' => $totalClaim,
'total_claim' => $totalClaim ?? null,
'currency' => 'IDR',
'plan_id' => $member->currentPlan->id,
'benefit_id' => $benefit->id,
'plan_id' => $member->currentPlan->id ?? null,
'benefit_id' => $benefit->id ?? null,
'status' => $status
];
// $claimData[$status.'_at'] = now();
// $claimData[$status.'_by'] = auth()->user()->id ?? null;
$claim = Claim::create($claimData);