<?php
include_once ($_SERVER['DOCUMENT_ROOT'].'/fpdf.php');
include_once ($_SERVER['DOCUMENT_ROOT'].'/includes/claseConexion.php');
include_once ($_SERVER['DOCUMENT_ROOT'].'/models/claseCaja.php');
function obtenerh($ids){
try
{
$conexion = Conexion::singleton_conexion();
$query="SELECT horainicio FROM sesiones WHERE idsesion=".$ids.";";
$conexion->beginTransaction();
$arrayr=$conexion->query($query);
$conexion->commit();
return $arrayr;
}
catch(Exception $e)
{
die($e->getMessage());
}
}
function obtenergastos($ids){
try
{
$conexion = Conexion::singleton_conexion();
$query="SELECT * FROM cajagrande WHERE idsesion=".$ids.";";
$conexion->beginTransaction();
$arrayg=$conexion->query($query);
$conexion->commit();
return $arrayg;
}
catch(Exception $e)
{
die($e->getMessage());
}
}
$mov=new Caja();
date_default_timezone_set("America/Argentina/Buenos_Aires");
$fecha=date("d/m/y");
$cajero=$_POST['cajero'];
$sesion=$_POST['idsesion'];
$cambio=$_POST['cambio'];
$arraymov=$mov->obtenerMovs($cajero,$sesion);
$arraygastos=obtenergastos($sesion);
$pdf = new FPDF();
$pdf->SetLeftMargin(10);
$pdf->SetRightMargin(10);
//$pdf->AddPage('P','mio');
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$pdf->Cell(175,10,'CERVEZERIA OTTRA',0,1,'C');
$pdf->Cell(175,3,'VENTA DE CERVEZA ARTESANAL ',0,1,'C');
$array=obtenerh($sesion);
$hora=$array[0]['horainicio'];
$pdf->Cell(175,5,'RESUMEN DE VENTAS Y ENTRADAS DE CAJA.. '.$fecha.' DESDE '.$hora.' HASTA '.date("H:i"). '',0,1,'C');
$pdf->SetFont('courier','B',12);
$pdf->Cell(30,5,"FECHA..:".$fecha,0,1,'L');
$pdf->Cell(30,5,"CAJERO..:".$_POST['nombre'],0,1,'L');
$pdf->SetFont('courier','B',12);
$pdf->Cell(15,6,'Cant',1,0,"C");
$pdf->Cell(90,6,utf8_decode('Descripción'),1,0,"C");
$pdf->Cell(10,6,'P/U',1,0,0);
$pdf->Cell(30,6,'Sub',1,0,"C");
$pdf->Cell(20,6,'Desc',1,0,"C");
$pdf->Cell(20,6,'Total',1,0,"C");
$pdf->ln(2);
foreach($arraymov as $f=>$r){
if ($r['granel']==1){
if (isset($r['descu'])){
$descuento=$r['descu'];
}else{
$descuento=0;
}
$cant=$r['3'];
$descripcion=$r['nombre'] . " ". $r['medida'];
$pu=$r['4'];
}else{
if (isset($r['descu'])){
$descuento=$r['descu'];
}else{
$descuento=0;
}
$cant=$r['5'];
$descripcion=$r['nombre'] . " ". $r['medida'];
$pu=$r['4'];
}
$importe=$cant * $pu;
$subtotal=$importe - $descuento;
$total=$total+$subtotal;
$pdf-> cell(15,12,$cant,0,0,'R');
$y = $pdf->GetY();
//$pdf-> cell(58,4,$descripcion,0,0,'R');
$pdf-> Multicell(70,12,utf8_decode($descripcion),0,'L',0);
//$pdf->SetY(40); /* Set 20 Eje Y */
$pdf->SetXY(60,$y);
$pdf->cell(75,12,'$'.$pu,0,'C',0);
$pdf->cell(20,12,'$'.$importe,0,'C',0);
$pdf->cell(20,12,'$'.$descuento,0,'C',0);
$pdf->cell(30,12,'$'.$subtotal,0,1,'C',0);
$yFin = $pdf->GetY();
}
$posicion=0;
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$pdf->Cell(175,10,'CERVEZERIA OTTRA',0,1,'C');
$pdf->SetFont('Times','',7);
$pdf->Cell(175,3,'VENTA DE CERVEZA ARTESANAL ',0,1,'C');
$array=obtenerh($sesion);
$hora=$array[0]['horainicio'];
$pdf->Cell(175,5,'RESUMEN DE GASTOS DE CAJA.. '.$fecha.' DESDE '.$hora.' HASTA '.date("H:i"). '',0,1,'C');
$pdf->SetFont('courier','B',12);
$pdf->Cell(70,5,$fecha,0,1,'R');
$pdf->SetFont('courier','B',12);
$pdf->Cell(15,6,'Cant',1,0);
$pdf->Cell(120,6,utf8_decode('Descripción'),1,0,"C");
$pdf->Cell(20,6,'COSTO',1,0);
$pdf->Cell(20,6,'Total',1,0);
$pdf->ln(2);
$posicion=0;
$totalg=0;
var_dump($arraygastos);
foreach($arraygastos as $g=>$gasto){
$pdf-> cell(15,12,'1',0,0,'R');
$y = $pdf->GetY();
//$pdf-> cell(58,4,$descripcion,0,0,'R');
$pdf-> Multicell(200,12,utf8_decode($gasto['detalle']),0,'L',0);
//$pdf->SetY(40); /* Set 20 Eje Y */
$pdf->SetY($yFin);
$pdf->SetXY(60,$y);
$pdf->cell(60,12,'$'.$gasto['monto'],0,'C',0);
$pdf->cell(50,12,'$'.$gasto['monto'],0,1,'C',0);
$yFin = $pdf->GetY();
$totalg=$totalg + $gasto['monto'];
}
$pdf->ln(4);
$pdf->Cell(76,6,'---------------------------',0,1);
$pdf->Cell(76,6,'---------------------------',0,1);
$pdf->ln(2);
$pdf->SetFont('Arial','B',12);
$pdf->Cell(50,6,'SubTotal Movimientos............ $'.$total,0,1);
$pdf->Cell(50,6,'CAMBIO....................... $'.$cambio,0,1);
$pdf->Cell(50,6,'GASTOS....................... $'.$totalg,0,1);
$pdf->Cell(70,6,'Total........................ $'.($total - $cambio -
$totalg),0,'L',1);
//$pdf->Cell(76,1,'--------------------------------------------------',0,1);
$pdf->ln(10);
$pdf->SetFont('Times','I',7);
$pdf->Output('ficha.pdf','I');
$pdf->Output();