<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace CmBundle\Controller;

use FPDF;
use CmBundle\Controller\NumberToLetterConverter;
use PHPQRCode\QRcode;

date_default_timezone_set('America/Mexico_City');

/**
 * Description of PDFReciboCeepam
 *
 * @author OMAR
 */
class PDFReciboPagoRapido extends FPDF {

    //put your code here
    public function reciboPagoRapido($d) {
        $this->SetLeftMargin(10);
        $this->SetRightMargin(10);

        $this->Image("images/fondos/mg.png", 0, 0, 216, 279);

        $this->SetTextColor(96, 96, 96); //GRIS OBSCURO
        $this->SetDrawColor(96, 96, 96); //GRIS OBSCURO

        $meses = ["ENERO", "FEBRERO", "MARZO", "ABRIL", "MAYO", "JUNIO", "JULIO", "AGOSTO", "SEPTIEMBRE", "OCTUBRE", "NOVIEMBRE", "DICIEMBRE"];

        $this->Ln(15);
        $this->SetFont('', 'B', '12');
        $this->Cell(0, 8, utf8_decode("TOLUCA, EDO. DE MÉXICO A " . (date('d') * 1) . " DE " . $meses[(date('m') * 1) - 1] . " DE " . date('Y')), 0, 0, 'R', FALSE);
        $this->Ln();
        $this->SetFont('', 'B', '14');
        $this->Cell(60, 8, utf8_decode("RECIBO DE PAGO"), "B", 0, 'L', false);
        $this->Ln();
        $this->SetFont('', 'B', '12');
        $this->Cell(135, 8, "", 0, 0, 'C', false);
        $this->Cell(20, 8, utf8_decode("FOLIO:"), 0, 0, 'R', false);
        $this->SetFillColor(30, 94, 111); //RELLENO CADETEBLUE
        $this->SetTextColor(255, 255, 255); //BLANCO
        $this->Cell(0, 8, utf8_decode($d->getNumRecibo()), 0, 0, 'C', true);
        $this->Ln(12);
        $this->SetTextColor(96, 96, 96); //GRIS OBSCURO
        $this->Cell(23, 6, utf8_decode("PLANTEL:"), 0, 0, 'L', false);
        $this->SetFont('', '', '');
        $this->SetTextColor(30, 94, 111); //CADETEBLUE
        $this->Cell(0, 6, utf8_decode($d->getCvePla()->getNomPla()), 0, 0, 'L', false);
        $this->Ln();
        $this->SetFont('', 'B', '12');
        $this->SetTextColor(96, 96, 96); //GRIS OBSCURO
        $this->Cell(27, 6, utf8_decode("RECIBO DE: "), 0, 0, 'L', false);
        $this->SetFont('', '', '');
        $this->SetTextColor(30, 94, 111); //CADETEBLUE
        $this->Cell(0, 6, utf8_decode($d->getEntrega()), 0, 0, 'L', false);
        $this->Ln();
        $this->SetFont('', 'B', '');
        $this->SetTextColor(96, 96, 96); //GRIS OBSCURO
        $this->Cell(39, 6, utf8_decode("LA CANTIDAD DE: "), 0, 0, 'L', false);
        $this->SetFont('', 'B', '10');
        $this->SetTextColor(30, 94, 111); //CADETEBLUE

        $convertidor = new NumberToLetterConverter();
        $cantidadLetra = $convertidor->to_word($d->getMonTot());

        $this->Cell(0, 6, utf8_decode("$" . number_format($d->getMonTot(), 2, ".", ",") . " ( " . $cantidadLetra . "PESOS 00/100 MXN )"), 0, 0, 'L', false);

        // DATOS DEL PAGO #1
        $this->Ln();
        //$this->Rect(10, 75, 196, 12, 'D'); //RECTANGULO PAGO #1
        $this->SetFont('', 'B', '10');
        $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
        $this->SetFillColor(96, 96, 96); //GRIS OBSCURO
        $this->Cell(40, 6, utf8_decode("FORMA DE PAGO:"), 1, 0, 'L', true);
        $this->SetFont('', '', '');
        $this->SetTextColor(30, 94, 111); //CADETEBLUE
        if ($d->getTipPag() == 0) {
            $this->Cell(40, 6, utf8_decode("BOUCHER"), 1, 0, 'C', false);
        } elseif ($d->getTipPag() == 1) {
            $this->Cell(40, 6, utf8_decode("EFECTIVO"), 1, 0, 'C', false);
        } elseif ($d->getTipPag() == 2) {
            $this->Cell(40, 6, utf8_decode("TRANSFERENCIA"), 1, 0, 'C', false);
        } elseif ($d->getTipPag() == 3) {
            $this->Cell(40, 6, utf8_decode("TERMINAL"), 1, 0, 'C', false);
        }
        $this->SetFont('', 'B', '');
        $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
        $this->Cell(26, 6, utf8_decode("REFERENCIA:"), 1, 0, 'L', true);
        $this->SetFont('', '', '');
        $this->SetTextColor(30, 94, 111); //CADETEBLUE
        $this->Cell(0, 6, utf8_decode($d->getRefPag()), 1, 0, 'C', false);
        $this->Ln();
        $this->SetFont('', 'B', '');
        $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
        $this->Cell(22, 6, utf8_decode("CANTIDAD:"), 1, 0, 'L', true);
        $this->SetFont('', '', '');
        $this->SetTextColor(30, 94, 111); //CADETEBLUE
        $this->Cell(25, 6, utf8_decode("$ " . number_format($d->getPagUno(), 2, ".", ",")), 1, 0, 'C', false);
        $this->SetFont('', 'B', '');
        $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
        $this->Cell(15, 6, utf8_decode("FECHA:"), 1, 0, 'L', true);
        $this->SetFont('', '', '');
        $this->SetTextColor(30, 94, 111); //CADETEBLUE
        $this->Cell(25, 6, utf8_decode($d->getFecPag()->format('d-m-Y')), 1, 0, 'C', false);
        $this->SetFont('', 'B', '');
        $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
        $this->Cell(16, 6, utf8_decode("BANCO:"), 1, 0, 'L', true);
        $this->SetFont('', '', '');
        $this->SetTextColor(30, 94, 111); //CADETEBLUE
        if ($d->getCveBan() == null) {
            $this->Cell(0, 6, utf8_decode("N/A"), 1, 0, 'C', false);
        } else {
            $this->Cell(0, 6, utf8_decode($d->getCveBan()->getBanco() . " : " . $d->getCveBan()->getNombre()), 1, 0, 'C', false);
        }


        //verificar si hay más comprobantes de pago.

        if ($d->getRefPagDos() != null) {

            $this->Ln(8);
            //$this->Rect(10, 87, 196, 12, 'D'); //RECTANGULO PAGO #2
            $this->SetFont('', 'B', '');
            $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
            $this->Cell(40, 6, utf8_decode("FORMA DE PAGO 2:"), 1, 0, 'L', true);
            $this->SetFont('', '', '');
            $this->SetTextColor(30, 94, 111); //CADETEBLUE
            if ($d->getTipPagDos() == 0) {
                $this->Cell(40, 6, utf8_decode("BOUCHER"), 1, 0, 'C', false);
            } elseif ($d->getTipPagDos() == 1) {
                $this->Cell(40, 6, utf8_decode("EFECTIVO"), 1, 0, 'C', false);
            } elseif ($d->getTipPagDos() == 2) {
                $this->Cell(40, 6, utf8_decode("TRANSFERENCIA"), 1, 0, 'C', false);
            } elseif ($d->getTipPagDos() == 3) {
                $this->Cell(40, 6, utf8_decode("TERMINAL"), 1, 0, 'C', false);
            }
            $this->SetFont('', 'B', '');
            $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
            $this->Cell(26, 6, utf8_decode("REFERENCIA:"), 1, 0, 'L', true);
            $this->SetFont('', '', '');
            $this->SetTextColor(30, 94, 111); //CADETEBLUE
            $this->Cell(0, 6, utf8_decode($d->getRefPagDos()), 1, 0, 'C', false);
            $this->Ln();
            $this->SetFont('', 'B', '');
            $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
            $this->Cell(22, 6, utf8_decode("CANTIDAD:"), 1, 0, 'L', true);
            $this->SetFont('', '', '');
            $this->SetTextColor(30, 94, 111); //CADETEBLUE
            $this->Cell(25, 6, utf8_decode("$ " . number_format($d->getPagDos(), 2, ".", ",")), 1, 0, 'C', false);
            $this->SetFont('', 'B', '');
            $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
            $this->Cell(15, 6, utf8_decode("FECHA:"), 1, 0, 'L', true);
            $this->SetFont('', '', '');
            $this->SetTextColor(30, 94, 111); //CADETEBLUE
            $this->Cell(25, 6, utf8_decode($d->getFecPagDos()->format('d-m-Y')), 1, 0, 'C', false);
            $this->SetFont('', 'B', '');
            $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
            $this->Cell(16, 6, utf8_decode("BANCO:"), 1, 0, 'L', true);
            $this->SetFont('', '', '');
            $this->SetTextColor(30, 94, 111); //CADETEBLUE
            if ($d->getCveBanDos() == null) {
                $this->Cell(0, 6, utf8_decode("N/A"), 1, 0, 'C', false);
            } else {
                $this->Cell(0, 6, utf8_decode($d->getCveBanDos()->getBanco() . " : " . $d->getCveBanDos()->getNombre()), 1, 0, 'C', false);
            }
        }

        if ($d->getRefPagTres() != null) {

            $this->Ln(8);
            //$this->Rect(10, 99, 196, 12, 'D'); //RECTANGULO PAGO #3
            $this->SetFont('', 'B', '');
            $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
            $this->Cell(40, 6, utf8_decode("FORMA DE PAGO 3:"), 1, 0, 'L', true);
            $this->SetFont('', '', '');
            $this->SetTextColor(30, 94, 111); //CADETEBLUE
            if ($d->getTipPagTres() == 0) {
                $this->Cell(40, 6, utf8_decode("BOUCHER"), 1, 0, 'C', false);
            } elseif ($d->getTipPagTres() == 1) {
                $this->Cell(40, 6, utf8_decode("EFECTIVO"), 1, 0, 'C', false);
            } elseif ($d->getTipPagTres() == 2) {
                $this->Cell(40, 6, utf8_decode("TRANSFERENCIA"), 1, 0, 'C', false);
            } elseif ($d->getTipPagTres() == 3) {
                $this->Cell(40, 6, utf8_decode("TERMINAL"), 1, 0, 'C', false);
            }
            $this->SetFont('', 'B', '');
            $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
            $this->Cell(26, 6, utf8_decode("REFERENCIA:"), 1, 0, 'L', true);
            $this->SetFont('', '', '');
            $this->SetTextColor(30, 94, 111); //CADETEBLUE
            $this->Cell(0, 6, utf8_decode($d->getRefPagTres()), 1, 0, 'C', false);
            $this->Ln();
            $this->SetFont('', 'B', '');
            $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
            $this->Cell(22, 6, utf8_decode("CANTIDAD:"), 1, 0, 'L', true);
            $this->SetFont('', '', '');
            $this->SetTextColor(30, 94, 111); //CADETEBLUE
            $this->Cell(25, 6, utf8_decode("$ " . number_format($d->getPagTres(), 2, ".", ",")), 1, 0, 'C', false);
            $this->SetFont('', 'B', '');
            $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
            $this->Cell(15, 6, utf8_decode("FECHA:"), 1, 0, 'L', true);
            $this->SetFont('', '', '');
            $this->SetTextColor(30, 94, 111); //CADETEBLUE
            $this->Cell(25, 6, utf8_decode($d->getFecPagTres()->format('d-m-Y')), 1, 0, 'C', false);
            $this->SetFont('', 'B', '');
            $this->SetTextColor(255, 255, 255); //TEXTO BLANCO
            $this->Cell(16, 6, utf8_decode("BANCO:"), 1, 0, 'L', true);
            $this->SetFont('', '', '');
            $this->SetTextColor(30, 94, 111); //CADETEBLUE
            if ($d->getCveBanTres() == null) {
                $this->Cell(0, 6, utf8_decode("N/A"), 1, 0, 'C', false);
            } else {
                $this->Cell(0, 6, utf8_decode($d->getCveBanTres()->getBanco() . " : " . $d->getCveBanTres()->getNombre()), 1, 0, 'C', false);
            }
        }


        //termina la verficación de comprobantes de pago.

        $this->Ln(10);
        $this->SetFont('', 'B', '12');
        $this->SetTextColor(255, 255, 255); //BLANCO
        $this->SetFillColor(96, 96, 96); //RELLENO GRIS OBSCURO
        $this->Cell(56, 6, utf8_decode("DESCRIPCIÓN DEL PAGO:"), 1, 0, 'L', true);
        $this->Ln();
        $this->SetFont('', '', '10');
        $this->SetTextColor(30, 94, 111); //CADETEBLUE
        $this->MultiCell(0, 6, utf8_decode($d->getDesPag()), 1, "J", false);

        $this->SetXY(10, 210);
        $this->SetFont('', 'B', '12');
        $this->SetTextColor(96, 96, 96); //GRIS OBSCURO
        $this->Cell(70, 6, utf8_decode("ENTREGA"), 0, 0, 'C', false);
        $this->Cell(50, 6, utf8_decode(""), 0, 0, 'C', false);
        $this->Cell(70, 6, utf8_decode("RECIBE"), 0, 0, 'C', false);
        $this->Ln(20);
        $this->SetFont('', 'B', '10');
        $this->SetTextColor(30, 94, 111); //CADETEBLUE
        $this->Cell(70, 6, utf8_decode($d->getEntrega()), "B", 0, 'C', false);
        $this->Cell(50, 6, utf8_decode(""), 0, 0, 'C', false);
        $this->Cell(70, 6, utf8_decode($d->getRecibe()), "B", 0, 'C', false);
        $this->Ln(7);
        $this->SetTextColor(96, 96, 96); //GRIS OBSCURO
        $this->MultiCell(70, 4, utf8_decode($d->getCvePla()->getNomPla()), 0, "C", false);
        $this->SetXY(80, 237);
        $this->Cell(50, 6, utf8_decode(""), 0, 0, 'C', false);
        $this->MultiCell(70, 4, utf8_decode("CORPORATIVO EMPRESARIAL DE ESCUELAS PARTICULARES DE MÉXICO"), 0, "C", false);
    }

}
