<?php

namespace Modules\Inventory\Transformers\Purchase;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class PurchaseInvoiceListResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'invoice_no' => $this->invoice_no,
            'invoice_date' => $this->invoice_date,
            'supplier' => $this->whenLoaded('supplier', function () {
                return $this->supplier;
            }),
            'subtotal' => $this->subtotal,
            'total_discount' => $this->total_discount,
            'taxable_amount' => $this->taxable_amount,
            'total_vat' => $this->total_vat,
            'grand_total' => $this->grand_total,
            'paid_amount' => $this->paid_amount,
            'due_amount' => $this->due_amount,
            'status' => $this->status,
            'can_be_posted' => $this->isEligibleForPosting(),
            'payment_status' => $this->payment_status
        ];
    }
}
