mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-26 16:04:11 +00:00
61 lines
2.1 KiB
PHP
61 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Models\Transaction;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class MappableTransactionWithDetailsResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
|
|
$debtor_code = null;
|
|
$order_reference = null; // if owner is payment
|
|
$bill_no = null; // if not payment
|
|
$marking = null; // if not payment
|
|
|
|
if ($this->type === TransactionType::PAYMENT) {
|
|
$order = $this->owner->owner->owner;
|
|
$order_reference = $order->reference;
|
|
$company_module = $order->companyModule;
|
|
$debtor_code = $company_module->company->debtor;
|
|
|
|
// } else {
|
|
} else if (in_array($this->type, [TransactionType::GROUP_PAYMENT, TransactionType::TOP_UP])) {
|
|
|
|
// TransactionType::GROUP_PAYMENT, TransactionType::TOP_UP
|
|
$wallet = $this->owner;
|
|
$company_module = $this->owner->owner;
|
|
$connection = $company_module->inviters()->withPivot('invitee_reference')->first();
|
|
$marking = $connection ? $connection->pivot->invitee_reference:'';
|
|
$bill_no = $this->bill_no;
|
|
}
|
|
else {
|
|
dd($this);
|
|
}
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
// 'owner_type' => $this->owner_type,
|
|
// 'owner_id' => $this->owner_type,
|
|
'updated_at' => $this->updated_at,
|
|
'debtor_code' => $debtor_code,
|
|
'order_reference' => $order_reference,
|
|
'bill_no' => $bill_no,
|
|
'type' => $this->type,
|
|
'marking' => $marking,
|
|
'amount' => $this->amount,
|
|
];
|
|
}
|
|
}
|