<?php
header('Content-Type: text/html; charset=UTF-8');
require('fpdf/fpdf.php');
require('alphapdf.php');
date_default_timezone_set("America/La_Paz");
include "core/autoload.php";
include "core/app/model/AccountData.php";
include "core/app/model/ProductData.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, 'CANIAX S.RL.', 0, 0, 'C');
		$this->Cell(100);
		$this->SetFont('Arial', 'B', 9);
		$this->Cell(21, 5, 'LA PAZ', 0, 1, 'C');
		$this->Cell(20);
		$this->Cell(31, 5, 'SORATA', 0, 0, 'C');
		$this->Cell(25);
		$this->SetFont('Arial', 'B', 12);
		$this->Cell(31, 5, 'REPORTE GENERAL DE DEPOSITO', 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, 'Ingreso a Sorata', 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, 'Telf: 2', 0, 1);
		$this->Cell(31, 4, 'Email: ', 0, 1);
		$this->Cell(31, 4, 'www.fliartecompany.com', 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');
	}
	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");
	}
}
$operations = array();

if (count($_POST) > 0) {
	$fi = date($_POST["sd"]);
	$ff = date($_POST["ed"]);
	$operations = AccountData::getAllByDate($fi, $ff);
}else{
	$operations = AccountData::getAll();
}

// $sell = AccountData::getById($_GET["id"]);
$sdate = date('Y-m-d');
$dia = date('d', strtotime($sdate));
$anio = date('Y', strtotime($sdate));
$mes = date('m', strtotime($sdate));

$pdf  = new PDF();
$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: Administrador', 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(25, 5, 'Nro Deposito', 1, 0);
$pdf->Cell(65, 5, 'Nombre Depositante', 1, 0);
$pdf->Cell(25, 5, 'Monto Total', 1, 0);
$pdf->Cell(50, 5, 'Cuenta a Depositar', 1, 0);
$pdf->Cell(30, 5, 'Fecha Deposito', 1, 1);
//$pdf->Cell(50, 5, 'Fecha Ingreso', 1, 1); //end of line

$pdf->SetFont('Arial', '', 8);
foreach ($operations as $o) {
	$pdf->Cell(25, 5, $o->no, 1, 0);
	$pdf->Cell(65, 5, $o->sol, 1, 0);
	$pdf->Cell(25, 5, $o->amount . ' Bs.', 1, 0);
	$pdf->Cell(50, 5, $o->owner, 1, 0);
	$pdf->Cell(30, 5, $o->date, 1, 1);
	//$pdf->Cell(196, 5, $o->created_at, 1, 1);
}
$pdf->Output();
