diff --git a/Modules/Internal/Http/Controllers/Api/Linksehat/PaymentController.php b/Modules/Internal/Http/Controllers/Api/Linksehat/PaymentController.php index 8d6e035f..9fdc6b35 100644 --- a/Modules/Internal/Http/Controllers/Api/Linksehat/PaymentController.php +++ b/Modules/Internal/Http/Controllers/Api/Linksehat/PaymentController.php @@ -21,7 +21,7 @@ class PaymentController extends Controller // return $request->toArray(); $appointments = Appointment::query() ->where('sPaymentStatus', 'settlement') - ->with(['healthCare', 'detail', 'user', 'doctor', 'doctor.user']); + ->with(['healthCare', 'healthCare.commission', 'detail', 'user', 'doctor', 'doctor.user']); if ($request->has('search')) { $appointments->where(function ($query) use ($request) { diff --git a/Modules/Internal/Transformers/LinksehatPaymentResource.php b/Modules/Internal/Transformers/LinksehatPaymentResource.php index fe5fcc2f..472f037c 100644 --- a/Modules/Internal/Transformers/LinksehatPaymentResource.php +++ b/Modules/Internal/Transformers/LinksehatPaymentResource.php @@ -14,7 +14,12 @@ class LinksehatPaymentResource extends JsonResource */ public function toArray($request) { - return parent::toArray($request); + $data = parent::toArray($request); + + $data['share_komisi'] = $this->share_komisi; + $data['share_konsultasi'] = $this->share_konsultasi; + + return $data; // return [ // // 'healthcare_name' => $this->healthCare->name ?? '', diff --git a/app/Models/OLDLMS/Appointment.php b/app/Models/OLDLMS/Appointment.php index b403902e..70011769 100644 --- a/app/Models/OLDLMS/Appointment.php +++ b/app/Models/OLDLMS/Appointment.php @@ -115,6 +115,32 @@ class Appointment extends Model ); } + protected function shareKonsultasi(): Attribute + { + return Attribute::make( + get: function() { + return ((float) $this->detail->sPaymentDetails['gross_amount'] ?? 0) - $this->nAdminFee; + } + ); + } + + protected function shareKomisi(): Attribute + { + return Attribute::make( + get: function() { + // return $this->healthCare->commission; + if ( $this->nIDJenisBooking == 3 ) { // Telekonsultasi Sekarang + return $this->shareKonsultasi * ($this->healthCare->commission->nCommissionATC) / 100; + } + else if ( $this->nIDJenisBooking == 2 ) { // Telekonsultasi + return $this->shareKonsultasi * ($this->healthCare->commission->nCommissionTC) / 100; + } + else { // Walk In + return $this->shareKonsultasi * ($this->nCommission) / 100; + } + } + ); + } public function appointmentDetail() { diff --git a/app/Models/OLDLMS/Healthcare.php b/app/Models/OLDLMS/Healthcare.php index 9987b57d..6a25aa35 100644 --- a/app/Models/OLDLMS/Healthcare.php +++ b/app/Models/OLDLMS/Healthcare.php @@ -20,6 +20,11 @@ class Healthcare extends Model protected $primaryKey = 'nID'; + public function commission() + { + return $this->hasOne(HealthcareCommission::class, 'nIDHealthcare', 'nID')->where('sStatus', 1); + } + public function jadwalDokter() { return $this->hasMany(JadwalDokter::class, 'nIDHealthCare', 'nID'); diff --git a/app/Models/OLDLMS/HealthcareCommission.php b/app/Models/OLDLMS/HealthcareCommission.php new file mode 100644 index 00000000..371966e3 --- /dev/null +++ b/app/Models/OLDLMS/HealthcareCommission.php @@ -0,0 +1,27 @@ +belongsTo(Healthcare::class, 'nIDHealthcare', 'nID'); + } +}