mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-08-28 02:57:29 -04:00
48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\StaffPayroll\Transformers;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Modules\StaffPayroll\Services\InvoiceAmountResponseService;
|
|
use Modules\StaffPayroll\Services\InvoiceService;
|
|
|
|
class InvoiceResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
|
|
$amount = $this->status == 'PAID' && $this->total_amount > 0 ? $this->total_amount : InvoiceAmountResponseService::amountString((new InvoiceService)->getInvoiceAmount($this->resource));
|
|
|
|
$resource = [
|
|
'id' => $this->id,
|
|
'invoice_number' => $this->invoice_number,
|
|
'issue_date' => $this->issue_date,
|
|
'created_date' => $this->created_at,
|
|
'user_id' => $this->user_id,
|
|
'note' => $this->note,
|
|
'terms' => $this->terms,
|
|
'amount' => $amount,
|
|
'status' => $this->status,
|
|
'due_date' => $this->due_date,
|
|
'discount_type' => $this->discount_type,
|
|
'discount' => $this->discount,
|
|
'user' => $this->whenLoaded('user'),
|
|
'items' => InvoiceItemResource::collection($this->whenLoaded('items')),
|
|
'payout' => $this->whenLoaded('payout'),
|
|
'stamp' => $this->stamp,
|
|
'month_stamp' => $this->month_stamp,
|
|
'is_approved' => $this->is_approved,
|
|
'reprocessed_items' => InvoiceItemResource::collection($this->whenLoaded('reprocessedItems'))
|
|
];
|
|
|
|
return $resource;
|
|
}
|
|
}
|