<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\CuotaView as CuotaViewResources;
use App\Http\Resources\EntidadLite as EntidadLiteResources;
use App\Danoral\U;

class CuotaCond extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $a_cc = [
            'idCond'            => strval($this->idCond),
            'idE'               => strval($this->idE),
            'ano'               => $this->ano,
            'mes'               => U::getMesTxt($this->mes),
            'sumMontoCuota'     => number_format($this->sumMontoCuota, 2, ',', '.'),
            'sumBS_cobro'       => number_format($this->sumBS_cobro, 2, ',', '.'),
            'sumBS'             => $this->sumBS!=0?number_format($this->sumBS, 2, ',', '.'):'',
            'sumUSD'            => $this->sumUSD!=0?number_format($this->sumUSD, 2, ',', '.'):'',
            'idMonedaCobro'     => $this->idMoneda_cobro,
            'symbCobro'         => "Bs",
            'descripcion'       => $this->descripcion,
            'cuotas'            => CuotaViewResources::collection($this->cuotas),
        ];

        if(isset($this->entidad)){
            $datose = json_decode($this->entidad->datose);
            $a_cc = array_merge($a_cc, ['codApto' => isset($datose->cod->value)?$datose->cod->value:'']);
        }

        return $a_cc;
    }
}
