<?php

session_cache_limiter('private');
session_start();
include('pdf/fpdf.php');
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
require_once("DF80000.php"); 
class PDF extends FPDF
{
	//Cabecera de Página
	function Header()
	{
	    //Logotipo
	         include("DYIM_VER.php");
	    //Arial Bold (14)
	    $this->SetFont('Arial','B',11);
	    //Espacio
		
	    //Título
	    $this->Cell(180,3,'ARQUEO CAJA',0,1,'C');
		$this->SetFont('Arial','I',8);
		$dt_catven=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgcatven WHERE cod_ven='".$_SESSION['vendedor']."'"));
		 $this->Cell(180,3,"(Fecha:".chfecha($_SESSION['fecven'],'Y-m-d','d/m/Y').", CAJERO:'".$dt_catven['nom_ven']."' '".$dt_catven['ap_pat_ven']."' '".$dt_catven['ap_mat_ven']."')",0,1,'C');
	    //Salto de línea
	    $this->Ln(3);
		$this->SetFont('Arial','',7);
		$this->SetFillColor(235);

		$this->Cell(80,3,'ARTICULO',1,0,'C',1);
		$this->Cell(30,3,'CAN.',1,0,'C',1);	
		$this->Cell(30,3,'TOTAL',1,1,'C',1);			
		$this->Ln(2);
	}
	//Pie de Página
	function Footer()
	{
	    //Posición: 1,5 cm del Final
	    $this->SetY(-15);
	    //Arial Italic 8
	    $this->SetFont('Arial','I',8);
	    //Número de página
	    $this->Cell(0,0, $this->PageNo(),0,0,'C');
	}
}

$pdf=new PDF('P','mm','Letter');
$pdf->AddPage();

//se da formato a fechas
$fecVen=$_SESSION['fecven'];
$codVen=$_SESSION['vendedor'];
@$sq = "SELECT dginvent.nparte1 as idInvent, dginvent.np_desc1 as desProd, SUM(dgpememd.can_ref) as canProd,SUM(dgpememd.total_cd) as totProd FROM dgpememd INNER JOIN dginvent ON dgpememd.nparte1 = dginvent.nparte1 inner join dgpemema on dgpemema.fol_ven=dgpememd.cons_ven INNER JOIN dgger_cajerosj ON(dgger_cajerosj.pedido=dgpemema.fol_ven) WHERE dgpemema.fec_ven='$fecVen' AND dgpemema.cod_ven='$codVen' AND dgger_cajerosj.corte='0' group by dgpememd.nparte1 order by dginvent.np_desc1";
$sql = mysqli_query($con ,$sq);
echo mysqli_error($con);
$idProdAct='-1';
$pdf->SetFillColor(248);
while(@$reg = mysqli_fetch_array($sql)){

	$pdf->Cell(80,3,$reg['desProd'],0,0,'L',0);
	$pdf->Cell(30,3,number_format($reg['canProd'],2,'.',','),0,0,'R',0);	
	$pdf->Cell(30,3,number_format($reg['totProd'],2,'.',','),0,1,'R',0);					
	$totProd +=$reg['totProd'];
}

$pdf->Cell(110,3,"TOTAL: ",0,0,'R',1);	
$pdf->Cell(30,3,number_format($totProd,2,'.',','),0,1,'R',1);					
$sq_caj=mysqli_query($con ,$sq="
	SELECT 
		dgger_cajerosj.fec_rec as fecPag,
		dgger_cajerosj.vendedor as idCatVen,
		dgger_cajerosd.tip_pag as idTipPag,
		dgtippag.desc_pag as desTipPag,
		SUM(dgger_cajerosd.importe) as impPag
	FROM
		dgger_cajerosd
		INNER JOIN dgger_cajerosj ON(dgger_cajerosj.n_rec=dgger_cajerosd.n_rec)
		INNER JOIN dgtippag ON(dgtippag.tip_pag=dgger_cajerosd.tip_pag)
	WHERE
		dgger_cajerosj.fec_rec='$fecVen' AND dgger_cajerosj.vendedor='$codVen' AND corte='0'
	GROUP BY
		dgger_cajerosd.tip_pag
	ORDER BY 
		dgtippag.desc_pag
");
$pdf->SetFillColor(243);
$pdf->Ln(5);
$pdf->Cell(50,3,"TIPO PAGO",1,0,'C',1);
$pdf->Cell(30,3,"IMP. SIS.",1,0,'C',1);
$pdf->Cell(30,3,"IMP. FIS.",1,0,'C',1);
$pdf->Cell(30,3,"DIFERENCIA",1,1,'C',1);
$auxFis=$_REQUEST['totFis'];
$auxArrFis=explode('|',$auxFis);
$i=0;
while($dt_caj=mysqli_fetch_array($sq_caj)){
	$pdf->Cell(50,3,$dt_caj['desTipPag'],0,0,'L',0);
	$pdf->Cell(30,3,number_format($dt_caj['impPag'],2,'.',','),0,0,'R',0);
	$pdf->Cell(30,3,number_format($auxArrFis[$i],2,'.',','),0,0,'R',0);
	$pdf->Cell(30,3,number_format($dt_caj['impPag']-$auxArrFis[$i],2,'.',','),0,1,'R',0);
	$totImpFis +=$auxArrFis[$i];
	$totImpCaj +=$dt_caj['impPag'];
	$i++;
}
$pdf->SetFillColor(243);
$pdf->Cell(50,3,"TOTAL:",0,0,'R',1);
$pdf->Cell(30,3,number_format($totImpCaj,2,'.',','),0,0,'R',1);
$pdf->Cell(30,3,number_format($totImpFis,2,'.',','),0,0,'R',1);
$pdf->Cell(30,3,number_format($totImpCaj-$totImpFis,2,'.',','),0,1,'R',1);
$pdf->Ln(20);
$dt_catven=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgcatven WHERE cod_ven='".$_SESSION['vendedor']."'"));
$pdf->Cell(30,3,"",'',0,'R',0);
$pdf->Cell(50,3,"CAJERO",'T',0,'C',0);
$pdf->Cell(10,3,"",'',0,'R',0);
$pdf->Cell(50,3,"SUPERVISOR",'T',0,'C',0);
$pdf->Output("ARQUEO.pdf","I");
?>