<?php
header('Content-Type: text/html; charset=UTF-8');
require('fpdf/fpdf.php');
date_default_timezone_set("America/La_Paz");
include "core/autoload.php";
include "core/app/model/SellData.php";
include "core/app/model/BillData.php";
include "core/app/model/UserData.php";
include "core/app/model/SpendBoxData.php";
include "core/app/model/OperationData.php";
include "core/app/model/OperationTypeData.php";

class PDF extends FPDF
{
	function Header()
	{
		$dia = date('d');
		$anio = date('Y');
		$mes = date('m');
		//Logo
		//$this->SetFillColor(0,0,0); 
		//$this->Image('logo.jpg',0,2,45);
		//Arial bold 15
		$this->SetFont('Arial', 'B', 8);
		//Movernos a la derecha
		$this->Cell(30);
		//T�tulo
		$this->Cell(21, 5, 'CRM', 0, 0, 'C');
		$this->Cell(100);
		$this->SetFont('Arial', 'B', 9);
		$this->Cell(21, 5, '', 0, 1, 'C');
		$this->Cell(20);
		$this->Cell(31, 5, '', 0, 0, 'C');
		$this->Cell(25);
		$this->SetFont('Arial', 'B', 12);
		$this->Cell(31, 5, 'NOTA DE GASTO - CAJA CHICA', 0, 0, 'C');
		$this->Cell(35);
		$this->SetFont('Arial', 'B', 9);
		$this->Cell(10, 5, 'DIA', 0, 0, 'C');
		$this->Cell(5);
		$this->Cell(10, 5, 'MES', 0, 0, 'C');
		$this->Cell(5);
		$this->Cell(10, 5, utf8_decode('AÑO'), 0, 1, 'C');
		$this->SetFont('Arial', '', 8);
		$this->Cell(31, 4, '', 0, 0);
		$this->Cell(108);
		$this->Cell(15, 4, $GLOBALS['dia'], 0, 0, 'C');
		$this->Cell(15, 4, $GLOBALS['mes'], 0, 0, 'C');
		$this->Cell(15, 4, $GLOBALS['anio'], 0, 1, 'C');
		$this->Cell(31, 4, '', 0, 1);
		$this->Cell(31, 4, '', 0, 1);
		$this->Cell(31, 4, '', 0, 1);
		$this->Cell(31, 4, '', 0, 1);
		//Salto de l�nea
		$this->Ln(5);
	}
	function Footer()
	{
		//Posici�n: a 1,5 cm del final
		$this->SetY(-15);
		//Arial italic 8
		//$this->SetFont('Arial','I',8);
		//N�mero de p�gina
		//$this->Cell(0,10,'',0,0,'C');
		$this->Cell(70, 5, 'Generado por', 0, 0, 'C');
		$this->Cell(70, 5, '', 0, 0, 'C');
		$this->Cell(70, 5, 'V.B.', 0, 0, 'C');
	}
}

$o = SpendBoxData::getById($_GET["id"]);
$sdate = $o->created_at;
$dia = date('d', strtotime($sdate));
$anio = date('Y', strtotime($sdate));
$mes = date('m', strtotime($sdate));
$user  = $o->getUser();
//$user_id = $o->user_id;

$pdf  = new PDF('P', 'mm', array(216, 178));
$pdf->AliasNbPages();
$pdf->AddPage();
//$pdf->SetAlpha(0.1);
//$pdf->Image('fondo.png', 16, 60, $fpdf->w, $fpdf->h);
//$pdf->SetAlpha(1);
$pdf->SetFont('Arial', '', 10);
//set font to arial, bold, 14pt
$pdf->SetFont('Arial', 'B', 10);
//$pdf->Cell(100 ,5,'Lugar y Fecha : La Paz, '.$fecha_l,0,1);//end of line
//$pdf->Cell(100 ,5,'Hora : '.date('H:i'),0,1);//end of line
$pdf->Cell(0, 5, 'USUARIO: ' . $user->name . ' ' . $user->lastname, 1, 1);
//$pdf->Cell(0 ,5,'AL: '.$ff,1,1);
//make a dummy empty cell as a vertical spacer
$pdf->Cell(189, 10, '', 0, 1); //end of line
//invoice contents
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(15, 5, 'Nro', 1, 0);
$pdf->Cell(30, 5, 'Concepto', 1, 0, 'C');
$pdf->Cell(105, 5, 'Descripcion', 1, 0);
$pdf->Cell(25, 5, 'Total', 1, 0);
//$pdf->Cell(25 ,5,'Usuario',1,0);
$pdf->Cell(20, 5, 'Fecha', 1, 1); //end of line
$pdf->SetFont('Arial', '', 10);
//Numbers are right-aligned so we give 'R' after new line parameter
//display the items

$pdf->Cell(15, 5, $o->code, 1, 0);
$pdf->Cell(30, 5, $o->name, 1, 0);
$pdf->Cell(105, 5, $o->description, 1, 0);
$pdf->Cell(25, 5, "Bs." . number_format($o->spend, 2, '.', ','), 1, 0);
//$pdf->Cell(25,5,$user->name	,1,0);
$dt1 = date_create($o->created_at);
$df1 = date_format($dt1, 'd/m/Y');
$pdf->Cell(20, 5, $df1, 1, 1, 'R');
$supertotal += ($o->spend);
$pdf->Cell(189, 10, '', 0, 1); //end of line
//summary
$pdf->SetFont('Arial', '', 20);
$pdf->Cell(25, 5, '', 0, 1);
$pdf->Cell(25, 5, 'TOTAL BS.' . number_format($supertotal, 2, '.', ','), 0, 0);
$pdf->SetFont('Arial', '', 10);

$pdf->Output();
