<?php

namespace App\View\Components;

use Illuminate\View\Component;
use Illuminate\Support\Facades\DB;
use App\Danoral\Condominios\Recibo as ReciboCondominio;

class ReciboDemanda extends Component
{
    public $codEE;
    public $nameEE;
    public $direccionEE;
    public $rifEE;

    public $codClienteEP;
    public $codEP;
    public $nameEP;
    public $alicuotaEP;
    public $alicuotaEP_str;

    public $tc_valor;
    public $tc_date;
    public $cond_venceTC;

    public $periodoR;
    public $montoR_USD;
    public $montoR_VES;

    public $iComunVES = [];
    public $iComunUSD = [];
    public $iAptoVES = [];
    public $iAptoUSD = [];

    public $sumComunVES;
    public $sumComunUSD;
    public $sumAptoVES;
    public $sumAptoUSD;
    public $sumComunVES_alicuota;
    public $sumComunUSD_alicuota;

    public $iCuotaPD_comun_VES;
    public $iCuotaPD_comun_USD;
    public $iCuotaPD_apto_VES;
    public $iCuotaPD_apto_USD;

    public $sumaCuota_VES;
    public $totalCuota_VES;
    public $totalCuota_USD;
    public $montoTotalVES;

    public $recibo;

    public $isMensaje_dolarizacion;

    public $mensaje;

    public $colorYellow = '#F5DF4D';

    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct(ReciboCondominio $recibo)
    {
        $this->recibo = $recibo;
        $this->loadRecibo();
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\View\View|string
     */
    public function render()
    {
        return view('components.recibo_demanda');
    }


    private function loadRecibo()
    {

        $this->codEE =          $this->recibo->edifE->codE;;
        $this->nameEE =         $this->recibo->edifE->nameE;
        $this->direccionEE =    $this->recibo->edifE->direccionE;
        $this->rifEE =          $this->recibo->edifE->RIF_nro;

        $this->codClienteEP =   $this->recibo->aptoE->codCliente;
        $this->codEP =          trim($this->recibo->aptoE->codE);
        $this->nameEP =         $this->recibo->aptoE->nameE;
        $this->alicuotaEP =     $this->recibo->aptoE->alicuota;
        $this->alicuotaEP_str = number_format($this->alicuotaEP, 8, ',', '.');

        $this->periodoR =       $this->recibo->getPeriodo();

        $this->iComunVES =      $this->recibo->rg['iComunVES'];
        $this->iComunUSD =      $this->recibo->rg['iComunUSD'];
        $this->iAptoVES =       $this->recibo->rg['iAptoVES'];
        $this->iAptoUSD =       $this->recibo->rg['iAptoUSD'];

        $this->sumComunVES =            number_format($this->recibo->rg['sumComunVES'], 2, ',', '.');
        //$this->sumComunUSD =            number_format($this->recibo->rg['sumComunUSD'], 2, ',', '.').'$';
        $this->sumAptoVES =             number_format($this->recibo->rg['sumAptoVES'], 2, ',', '.');
        //$this->sumAptoUSD =             number_format($this->recibo->rg['sumAptoUSD'], 2, ',', '.').'$';
        $this->sumComunVES_alicuota =   number_format($this->recibo->rg['sumComunVES_alicuota'], 2, ',', '.');
        //$this->sumComunUSD_alicuota =   number_format($this->recibo->rg['sumComunUSD_alicuota'], 2, ',', '.').'$';

        $this->tc_valor =               number_format($this->recibo->rg['tc_valor'], 4, ',', '.');
        $this->tc_date =                date('d/m/Y', strtotime($this->recibo->rg['tc_date']));
        $this->cond_venceTC =           date('d/m/Y', strtotime($this->recibo->rg['cond_venceTC']));

        /*
        $this->iCuotaPD_comun_VES =     $this->recibo->rg['iCuotaPD_comun_VES'];
        $this->iCuotaPD_comun_USD =     $this->recibo->rg['iCuotaPD_comun_USD'];
        $this->iCuotaPD_apto_VES =      $this->recibo->rg['iCuotaPD_apto_VES'];
        $this->iCuotaPD_apto_USD =      $this->recibo->rg['iCuotaPD_apto_USD'];
        */

        $this->sumaCuota_VES =          number_format($this->recibo->rg['sumaCuota_VES'], 2, ',', '.').'';
        $this->totalCuota_VES =         'Bs ' . number_format($this->recibo->rg['sumaCuota_VES'], 2, ',', '.').'';
        //$this->totalCuota_USD =         number_format($this->recibo->rg['totalCuota_USD'], 2, ',', '.').'$';
        $this->montoTotalVES =          number_format($this->recibo->rg['sumaCuota_VES'], 2, ',', '.').'';

        //$this->montoR_USD = number_format($this->recibo->rg['montoCuotaUSD'], 2, ',', '.');

        /*
        if($this->recibo->rg['montoCuotaVES']<=0.01 && $this->recibo->rg['montoCuotaVES']>=(-0.01)){
            $this->montoR_VES = '';
        }else{
            $this->montoR_VES = 'Bs ' . number_format($this->recibo->rg['montoCuotaVES'], 2, ',', '.').'';
        }
        */
        $this->montoR_VES = 'Bs ' . number_format($this->recibo->rg['sumaCuota_VES'], 2, ',', '.').'';

        $this->isMensaje_dolarizacion = $this->recibo->rg['isMensaje_dolarizacion'];

    }

}
