<?php
header('Content-Type: text/html; charset=UTF-8');
//include('bd.php');
require('fpdf/fpdf.php');
require('alphapdf.php');
date_default_timezone_set("America/La_Paz");
include "core/autoload.php";
include "core/app/model/AssistanceData.php";
include "core/app/model/PersonData.php";
include "core/app/model/SellData.php";
include "core/app/model/UserData.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, 'ISSUCADELA SRL', 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, '', 0, 0, 'C');
		$this->Cell(25);
		$this->SetFont('Arial', 'B', 12);
		$this->Cell(31, 5, 'REPORTE ASISTENCIA', 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, 'Direccion', 0, 0);
		$this->Cell(108);
		$this->Cell(15, 4, $dia, 0, 0, 'C');
		$this->Cell(15, 4, $mes, 0, 0, 'C');
		$this->Cell(15, 4, $anio, 0, 1, 'C');
		$this->Cell(31, 4, 'Zona 16 de Julio - El Alto', 0, 1);
		$this->Cell(31, 4, 'Telf: 23456789 - 76418600 - 76490462', 0, 1);
		$this->Cell(31, 4, 'Email: ventas@issucadela.com', 0, 1);
		$this->Cell(31, 4, 'www.issucadela.com', 0, 1);
		//Salto de l�nea
		$this->Ln(5);
		$this->SetAlpha(0.1);
		//$this->Image('fondo.png', 16, 100, $fpdf->w, $fpdf->h);
		$this->SetAlpha(1);
	}
	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');
	}
}
$fi = $_POST["start"];
$ff = $_POST["finish"];
$operations = array();
//$operations = AssistanceData::getAllByDateOp($fi, $ff);
$alumns = UserData::getAll();
$pdf  = new PDF('P', 'mm', array(279, 216));
$pdf->AliasNbPages();
$pdf->AddPage();
//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, 'DEL: ' . $fi, 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', 8);
$pdf->Cell(25, 5, 'Empleado', 1, 0);
$range = ((strtotime($ff) - strtotime($fi)) + (24 * 60 * 60)) / (24 * 60 * 60);
for ($i = 0; $i < $range - 1; $i++) {
	$as = date("d", strtotime($fi) + ($i * (24 * 60 * 60)));
	$pdf->Cell(7, 5, '' . $as, 1, 0);
}
$pdf->Cell(7, 5, '' . $as + 1, 1, 1);
$pdf->SetFont('Arial', '', 10);
//Numbers are right-aligned so we give 'R' after new line parameter
//display the items
foreach ($alumns as $al) {
	$alumn = $al;
	$values = array("" => "Sin seleccion", "1" => "Asistencia", "2" => "Falta con permiso", "3" => "Falta sin permiso", "4" => "Retraso", "5" => "Comision", "6" => "Vacacion", "7" => "Permiso", "8" => "Asueto", "9" => "Feriado", "10" => "Fallecimiento", "11" => "Horas Extra");
	$pdf->Cell(25, 5, '' . $alumn->name . ' ' . $alumn->lastname, 1, 1);
	for ($i = 0; $i < $range; $i++) {
		$date_at = date("Y-m-d", strtotime($fi) + ($i * (24 * 60 * 60)));
		$asist = AssistanceData::getByPD($alumn->id, $date_at);
		if ($asist != null) {
			if ($asist->kind_id == 1) {
				$pdf->Cell(7, 5, 'v', 1, 0);
			} else if ($asist->kind_id == 2) {
				$pdf->Cell(7, 5, 'X', 1, 0);
			} else if ($asist->kind_id == 3) {
				$pdf->Cell(7, 5, '!', 1, 0);
			} else if ($asist->kind_id == 4) {
				$pdf->Cell(7, 5, 'R', 1, 0);
			} else if ($asist->kind_id == 5) {
				$pdf->Cell(7, 5, 'C', 1, 0);
			} else if ($asist->kind_id == 6) {
				$pdf->Cell(7, 5, 'V', 1, 0);
			} else if ($asist->kind_id == 7) {
				$pdf->Cell(7, 5, 'P', 1, 0);
			} else if ($asist->kind_id == 8) {
				$pdf->Cell(7, 5, 'A', 1, 0);
			} else if ($asist->kind_id == 9) {
				$pdf->Cell(7, 5, 'F', 1, 0);
			} else if ($asist->kind_id == 10) {
				$pdf->Cell(7, 5, 'FA', 1, 0);
			} else if ($asist->kind_id == 11) {
				$pdf->Cell(7, 5, 'HE', 1, 0);
			}
		} else {
			$pdf->Cell(7, 5, '', 1, 0);
		}
		$pdf->Cell(1, 5, '' . $as, 0, 1);
	}
}
//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();
