<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class TransDTView extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $info = '';
        if($this->typeDT == 11) { $this->descripcionDT = 'CUOTA'; }
        if($this->typeDT == 31) { $this->descripcionDT_base = "CUOTA ($this->montoDT_base$)"; }

        if(!is_null($this->idDT_base)){
            $this->descripcionDT_base .= "[$this->valorTC_base@".date("d.m.y",strtotime($this->dateValorTC_base))."]";
        }
        
        return [
            "idE"           => strval($this->idE),
            "idDT"          => strval($this->idDT),
            "ctaT"          => $this->ctaT,
            "dateT"         => date("d/m/Y",strtotime($this->dateT)),
            "nameTypeT"     => $this->nameTypeT,
            "refT"          => $this->refT,
            "descT"         => $this->descT,
            "ctaDT"         => $this->ctaDT,
            "link"          => is_null($this->idDT_base)?0:$this->idDT_base,
            "descripcionDT" => is_null($this->idDT_base)?$this->descripcionDT:"$this->descripcionDT_base",
            "typeDT"        => $this->typeDT,
            "idMoneda"      => $this->idMoneda,
 
            "codESuper"     => is_null($this->codESuper)?'':$this->codESuper,
            "codE"          => $this->codE,
            "montoDT_debe"  => ($this->dhDT==0)?number_format($this->montoDT, 2, ',', '.'):'',
            "montoDT_haber" => ($this->dhDT==1)?number_format($this->montoDT, 2, ',', '.'):'',

            "countTcBase"   => $this->countTcBase,

            "info"          => $info,
            "periodo"       => $this->getPeriodo(),
        ];

    }
}
