<?php
require_once('config/lang/eng.php');
require_once('tcpdf.php');

// extend TCPF with custom functions
class PDF extends TCPDF {
  public $comision;
  
    public function setComision($id_comision,$vigencia) {
      $this->comision = ComisionesPeer::retrieveByPK($id_comision,$vigencia); 
    }
    
    public function Header() {
        // Logo
        sfLoader::loadHelpers('Date');
        sfLoader::loadHelpers('Asset');
        $this->Ln(10);
        $this->SetRightMargin(15);
        $this->SetTopMargin(8);
        $this->SetFont('helvetica', '', 9);
        $html  = '<table border="1" cellpadding="2"><tr><td rowspan="2" width="215"><img src="images/header.png" /></td><td>';
        $html .= "<b>Área:</b><br/> ".$this->comision->getAreas()->getDesare();
        $html .= "</td><td>&nbsp;<b>Fecha: </b><br/>".ucfirst(format_date($this->comision->getFecha(),'MMMM yyyy','es'))."</td>";
        $html .= "<td><b>Tipo comisión:</b> <br/>".$this->comision->getTiposComision()->getDescomi()."". (($this->comision->getTiposComision()->getDescomi()=='Adicion') ? ' al plan comision '.$this->comision->getIdOriginal() : '')."".(($this->comision->getInterrupcion()==1)? ' CON INTERRUPCION ' :'')."</td>";
        $html .= "<td width=\"90\"><b>Consecutivo: </b><br/>".$this->comision->getId()."</td>";
        $html .= "</tr><tr>";
        $html .= '<td colspan="3"><b>Proyecto: </b><br/>'.$this->comision->getCodpro().' - '.$this->comision->getProyectos()->getDespro().'</td>';
        $html .= "<td width=\"90\">".'Página '.$this->getAliasNumPage()." de ".$this->getAliasNbPages()."</td></tr></table>";
        $this->writeHTML($html);
        $this->Ln(20);
        $this->SetMargins(20,50,20);
    }
    
    public function Footer() {
        $this->SetRightMargin(2);
        $this->SetLeftMargin(2);
        $this->SetY(-19);
        $this->SetFont('helvetica', '', 10);
        $html  = '<table border="0" cellpadding="7"><tr bgcolor="#b2b7ba">';
        $html .= '<td></td></tr></table>';
        $this->writeHTML($html);
        $this->SetY(-17);
        $html  = '<table border="0"><tr>';
        $html .= '<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.ucfirst(format_date(date('Y-m-d'),'dddd, dd MMMM yyyy','es')).'</td><td align="right"><b>ORDENADOR DEL GASTO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td></tr></table>';
        $this->writeHTML($html);
        $this->SetFont('helvetica', '', 7);
        $this->SetY(-9);
        $html = '<div align="center" style="font-style:italic;color:gray">Websafi - comisiones</div>';
        $this->writeHTML($html);
    }  
}