<?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/RegistrationData.php";
include "core/app/model/MiterData.php";
include "core/app/model/UserData.php";
include "core/app/model/SpendBoxData.php";
include "core/app/model/ProductData.php";
include "core/app/model/OperationTypeData.php";


$sells = RegistrationData::getLast();
//$sdate = $sell->created_at;
$dia = date('d', strtotime($sdate));
$anio = date('Y', strtotime($sdate));
$mes = date('m', strtotime($sdate));
//$us = UserData::getById($sell->user_id);


$pdf = new FPDF($orientation = 'P', $unit = 'mm', array(80, 1200));
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 8);    //Letra Arial, negrita (Bold), tam. 20
$textypos = 5;
$pdf->setY(2);
$pdf->setX(2);
$pdf->Cell(5, $textypos, "CANIAX SRL");
$pdf->SetFont('Arial', '', 7);    //Letra Arial, negrita (Bold), tam. 20
$textypos += 6;
$pdf->setX(2);
$pdf->Cell(5, $textypos, '-----------------------------------');
foreach ($sells as $sell) {
    $textypos += 6;
    $pdf->setX(2);
    $di = date_create($sell->created_at);
    $df = date_format($di, 'd/m/Y');
    $pdf->Cell(5, $textypos, "MANGUERA: " . $sell->getMiter()->getProduct()->name . ' ' . $sell->getMiter()->name);
    $textypos += 6;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, 'FECHA: ' . $df);
    $textypos += 6;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, 'USUARIO: ' . $us->name . ' ' . $us->lastname);
    $textypos += 6;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, "MEDIDA INICIAL: " . $sell->q_i);
    $textypos += 6;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, "MEDIDA FINAL: " . $sell->q_f);
    $textypos += 6;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, "BIDONES: Bs. " . $sell->b * 10);
    $textypos += 6;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, "CHUTOS: Bs. " . $sell->ch * 10);
    $textypos += 6;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, "MOTOS: Bs. " . $sell->m * 5);
    $textypos += 6;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, "CAMIONES: Bs. " . $sell->c * 100);
    $textypos += 6;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, "TURRILES: Bs. " . $sell->t);
    $textypos += 30;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, 'FIRMA A CONFORMIDAD');
    $textypos += 6;
    $pdf->setX(2);
    $pdf->Cell(5, $textypos, '-----------------------------------');
}
$pdf->setX(2);
$pdf->Cell(5, $textypos + 26, '');
// $total = 0;
// $off = $textypos + 6;

// $pdf->setX(2);
// $pdf->Cell(5, $off, $sell->q_f - $sell->q_i);
// $pdf->setX(10);
// $pdf->Cell(11, $off,  "Bs. " . number_format($sell->getMiter()->getProduct()->price_out, 2, ".", ","), 0, 0, "R");
// $pdf->setX(32);
// $pdf->Cell(11, $off,  "Bs. " . number_format(($sell->q_f - $sell->q_i) * $sell->getMiter()->getProduct()->price_out, 2, ".", ","), 0, 0, "R");

// $off += 6;

// $textypos = $off + 6;

// $pdf->setX(2);
// $pdf->Cell(5, $textypos, "TOTAL: ");
// $pdf->setX(38);
// $pdf->Cell(5, $textypos, "Bs. " . number_format(($sell->q_f - $sell->q_i) * $sell->getMiter()->getProduct()->price_out, 2, ".", ","), 0, 0, "R");



$pdf->output();
