<?php
header('Content-Type: text/html; charset=iso-8859-1');
include ('bd.php');
require ('fpdf/fpdf.php');
date_default_timezone_set("America/La_Paz");
include "core/autoload.php";
include "core/app/model/AdmissionData.php";
include "core/app/model/UserAdmissionData.php";
include "core/app/model/BillData.php";
include "core/app/model/UserData.php";
include "core/app/model/MentionData.php";
include "core/app/model/DivisionData.php";
include "core/app/model/CourseData.php";
include "core/app/model/SufficiencyData.php";
include "core/app/model/UserPayData.php";
include "core/app/model/TransactionData.php";

class PDF extends FPDF
{

	function Header()
	{

		//Logo
		$this->SetFillColor(0,0,0); 
		$this->Image('logo coplumu.jpg',5,5,30);
		$this->Cell(189 ,10,'',0,1);//end of line
		//Arial bold 15
		$this->SetFont('Arial','B',8);
		//Movernos a la derecha
		//$this->Cell(189 ,10,'',0,1);//end of line
		$this->Cell(50);

		$this->Cell(31,5,'',0,0,'C');
		$this->Cell(25);
		$this->SetFont('Arial','B',12);
		$this->Cell(31,5,'CONSERVATORIO PLURINACIONAL DE MUSICA',0,1,'C');
		$this->SetFont('Arial','B',10);
		$this->Cell(105);
		$this->Cell(31,5,'FONDO ROTATIVO',0,1,'C');
		$this->SetFont('Arial','B',12);
		
		//$this->Cell(189 ,5,'',0,1);//end of line
		

		//Salto de l�nea
		$this->Ln(5);
		$this->SetAlpha(0.1);
		//$this->Image('fondo9.png', 16, 60, $fpdf->w, $fpdf->h);
		$this->SetAlpha(1);
	}

	function Footer()
	{
		//Posici�n: a 1,5 cm del final
		$this->SetY(-10);
		//Arial italic 8
		$this->SetFont('Arial','B',9);
		//N�mero de p�gina
		//$this->Cell(0,10,'',0,0,'C');
		$this->Cell(80 ,5,'DIRECTOR(A) ADMINISTRATIVO(A)',0,0,'C');
		$this->Cell(120 ,5,'CONTABILIDAD',0,1,'C');
	}

	function addNumTVA($tva)
{
	$this->SetFont( "Arial", "B", 10);
	$r1  = $this->w - 80;
	$r2  = $r1 + 70;
	$y1  = 80;
	$y2  = $y1+10;
	$mid = $y1 + (($y2-$y1) / 2);
	$this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D');
	$this->Line( $r1, $mid, $r2, $mid);
	$this->SetXY( $r1 + 16 , $y1+1 );
	$this->Cell(40, 4, "TVA Intracommunautaire", '', '', "C");
	$this->SetFont( "Arial", "", 10);
	$this->SetXY( $r1 + 16 , $y1+5 );
	$this->Cell(40, 5, $tva, '', '', "C");
}
}

$id = $_GET["id"];
$operations = array();
if($id==""){
	$operations = TransactionData::getAll();
}else{
	$operations = TransactionData::getAllByMonth($id);
} 
$mes = $_GET["id"];
if($mes == 1)
$letra = 'Enero';
if($mes == 2)
$letra = 'Febrero';
if($mes == 3)
$letra = 'Marzo';
if($mes == 4)
$letra = 'Abril';
if($mes == 5)
$letra = 'Mayo';
if($mes == 6)
$letra = 'Junio';
if($mes == 7)
$letra = 'Julio';
if($mes == 8)
$letra = 'Agosto';
if($mes == 9)
$letra = 'Septiembre';
if($mes == 10)
$letra = 'Octubre';
if($mes == 11)
$letra = 'Noviembre';
if($mes == 12)
$letra = 'Diciembre';


	$pdf  = new PDF('L', 'mm', 'letter');
	$pdf->AliasNbPages();
	$pdf->AddPage();

	$pdf->SetFont('Arial','b',10);
	if($id==""){
		$pdf->Cell(105);
		$pdf->Cell(31,5,'MES: TODOS',0,1,'');
	}else{
		$pdf->Cell(105);
		$pdf->Cell(31,5,'MES: '.$letra,0,1,'');	
	} 
	
	$pdf->Cell(189 ,5,'',0,1);//end of line

	//set font to arial, bold, 14pt
	$pdf->SetFont('Arial','B',7);

	$pdf->Cell(7 ,5,'NRO ',1,0);
	$pdf->Cell(25 ,5,'FECHA',1,0);
	$pdf->Cell(25 ,5,'DEPOSITO',1,0);
	$pdf->Cell(127 ,5,'DETALLE',1,0);
	$pdf->Cell(20 ,5,'DEBITO',1,0);
	$pdf->Cell(20 ,5,'CREDITO',1,0);
	$pdf->Cell(20 ,5,'SALDO',1,1);
	$total = 0;
	foreach($operations as $o){
		$pdf->Cell(7 ,5,$o->id,1,0);
		$pdf->Cell(25 ,5,$o->created_at,1,0);
		$pdf->Cell(25 ,5,$o->code,1,0);
		$pdf->Cell(127 ,5,$o->description,1,0);
		if($o->type == 1){
			$pdf->Cell(20 ,5,number_format($o->amount,2,'.',','),1,0,'C');
			$pdf->Cell(20 ,5,'-',1,0,'C');
			$total += $o->amount;
		}else{
			$pdf->Cell(20 ,5,'-',1,0,'C');
			$pdf->Cell(20 ,5,number_format($o->amount,2,'.',','),1,0,'C');
			$total -= $o->amount;
		}
		$pdf->Cell(20 ,5,number_format($total,2,'.',','),1,1,'C');
	}

	//$pdf->Cell(189 ,5,'',0,1);//end of line
	
$pdf->Output();