<?php

namespace App\Http\Resources\Accounting;

use Illuminate\Http\Resources\Json\JsonResource;

class DepreciationResource extends JsonResource
{
    
    public function toArray($request)
    {
        return [
            'id'                => $this->id,
            'asset_id'          => $this->asset_id,
            'currency_id'       => $this->currency_id,
            'branch_id'         => $this->branch_id,
            'chart_asset'       => $this->chart_asset,
            'chart_expense'     => $this->chart_expense,
            'depreciation_date' => $this->depreciation_date,
            'status_asset'      => $this->status_asset,
            'brand'             => $this->brand,
            'location_using'    => $this->location_using,
            'user_name'         => $this->user_name,
            'another'           => $this->another,
            'asset_name'        => $this->asset_name,
            'invoice_number'    => $this->invoice_number,
            'period'            => $this->period,
            'total_amount'      => $this->total_amount,
            'total_paid'        => $this->total_paid,
            'balance'           => $this->balance,
            'desc'              => $this->desc,
            'type_asset_name'   => $this->assets->name??'',
            'acc_asset_name'    => $this->chartAsset->chart_name??'',
            'asset_code'        => $this->chartAsset->chart_code??'',
            'expense_name'      => $this->chartExpense->chart_name??'',
            'expense_code'      => $this->chartExpense->chart_code??'',
            'created_by'        => $this->createdBy->name??'',
            'payment_date'      => $this->depreciation_date??'',
            'amount'            => $this->total_amount??0,
            'created_at'        => $this->created_at,
            'updated_at'        => $this->updated_at,
            'period_paid'       => $this->depreciationDetail->where('status',2)->count()??0,
            'period_unpaid'     => $this->period-$this->depreciationDetail->where('status',2)->count()??0,
            // 'first_payment'     => $this->depreciationDetail->first()->amount??0,
            'first_payment'     => $this->first_payment??0,
            'details'           => DepreciationDetailResource::collection($this->depreciationDetail),
            'branch_name'      => $this->branchs->name_km??'',
        ];
    }
}
