mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-27 08:24:06 +00:00
Admin Workflow - Fix new unclear workflow requirement
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingFloatingAmount;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingPayableAmount;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\BookingAttributeNames;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class BookingAdminWorkflowResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company' => new CompanyResource($this->company),
|
||||
'bank' => new BankResource($this->bank),
|
||||
'service' => new ServiceTypeResource($this->service),
|
||||
'marking' => $this->marking,
|
||||
'amount' => $this->fix_amount,
|
||||
// 'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)),
|
||||
'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)),
|
||||
// 'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)),
|
||||
'fixed_currency' => new CurrencyResource($this->fixedCurrency),
|
||||
'order_reference_no' => $this->modelAttributes()->where('name', BookingAttributeNames::ORDER_REFERENCE_NO)->get()->map(function ($attr) {
|
||||
return [
|
||||
'id' => $attr->id,
|
||||
'value' => $attr->value
|
||||
];
|
||||
}),
|
||||
'status' => $this->status,
|
||||
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'),
|
||||
$this->mergeWhen($this->relationLoaded('transactions'), [
|
||||
'payment_history' => TransactionResource::collection($this->transactions()->where(function($query){
|
||||
$query->where(function($query){
|
||||
$query->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED, ApprovalStatus::REFUNDED]);
|
||||
})->orWhere(function($query){
|
||||
$query->where(function($query){
|
||||
$query->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::REJECTED, ApprovalStatus::COMPLETED]);
|
||||
})->orWhere(function($query){
|
||||
$query->where('type', TransactionType::CREDIT_NOTE)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
});
|
||||
});
|
||||
})->latest()->get())
|
||||
])
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user