02ba2fe6b6
API CI/CD / Validate (composer + pint) (push) Successful in 3m8s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Test (PHPUnit) (push) Failing after 6m5s
API CI/CD / Security audit (push) Failing after 52s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
46 lines
2.2 KiB
PHP
46 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Invoices;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class InvoiceResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => (int) ($this->resource['id'] ?? 0),
|
|
'parent_id' => (int) ($this->resource['parent_id'] ?? 0),
|
|
'invoice_number' => $this->resource['invoice_number'] ?? null,
|
|
'total_amount' => (float) ($this->resource['total_amount'] ?? 0),
|
|
'paid_amount' => (float) ($this->resource['paid_amount'] ?? 0),
|
|
'discount' => (float) ($this->resource['discount'] ?? 0),
|
|
'balance' => (float) ($this->resource['balance'] ?? 0),
|
|
'status' => $this->resource['status'] ?? null,
|
|
'school_year' => $this->resource['school_year'] ?? null,
|
|
'semester' => $this->resource['semester'] ?? null,
|
|
'issue_date' => $this->resource['issue_date'] ?? null,
|
|
'due_date' => $this->resource['due_date'] ?? null,
|
|
'created_at' => $this->resource['created_at'] ?? null,
|
|
'updated_at' => $this->resource['updated_at'] ?? null,
|
|
'refund_amount' => (float) ($this->resource['refund_amount'] ?? 0),
|
|
'last_paid_amount' => (float) ($this->resource['last_paid_amount'] ?? 0),
|
|
'last_payment_date' => $this->resource['last_payment_date'] ?? null,
|
|
'payments' => collect($this->resource['payments'] ?? [])
|
|
->map(static fn ($payment) => [
|
|
'id' => (int) ($payment['id'] ?? 0),
|
|
'invoice_id' => (int) ($payment['invoice_id'] ?? 0),
|
|
'paid_amount' => (float) ($payment['paid_amount'] ?? 0),
|
|
'balance' => (float) ($payment['balance'] ?? 0),
|
|
'payment_method' => $payment['payment_method'] ?? null,
|
|
'payment_date' => $payment['payment_date'] ?? null,
|
|
'transaction_id' => $payment['transaction_id'] ?? null,
|
|
'status' => $payment['status'] ?? null,
|
|
])
|
|
->values()
|
|
->all(),
|
|
];
|
|
}
|
|
}
|