<?php
require('fpdf.php');

class PDF extends FPDF
{
//Cabecera de pagina
function Header()
{
    //Logo
    $this->Image('./logo/recibo.jpg',7,8,200);
    $this->Ln(5);	
	  // $this->Image('logo/logo.jpg',12,10,33,23);
   // $this->Ln(5);	
}

//Pie de pgina	
function Footer()
{
    //$this->SetFont('Arial','',6);
//	$this->SetY(-21);
//	$this->Cell(0,10,'HL Soluciones de Ingieneria S.A. ',0,0,'C');
//	$this->SetY(-12);
//    $this->Cell(0,10,'Pagina '.$this->PageNo().'',0,0,'C');	
}

}

// Creación del objeto de la clase heredada
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);




define('FPDF_FONTPATH','font/');


require("../conexion.php");
 $lineas="0";

$pdf->Ln();    

    $consulta = "SELECT * FROM web_0000 ";
	$resultado = $mysqli->query($consulta);
	$fila = $resultado->fetch_array();

         $nomcom = $fila["NOMCOM"];
	     $razsoc = $fila["RAZSOC"];
		 $cedjur = $fila["CEDJUR"];
		 $diremp = $fila["DIREMP"];
		 $numtel_empresa = $fila["NUMTEL"];
		 $numofi = $fila["numofi"];
		 $menfac = $fila["menfac"];
         $intmor = $fila["INTMOR"];
		 $tipimp = $fila["TIPIMP"];
		 $ter001 = $fila["TER001"];
		 $ter002 = $fila["TER002"];
		 $ter003 = $fila["TER003"];
		 
		 
// ***** comparacion de datos entre tablas****

$numrec=$_GET["numrec"];



   $consulta ="Select * from pagos_clientes where numrec = $numrec";
	  $result = $mysqli->query($consulta);
      $row = $result->fetch_array();


        $fecha  = $row["fecrec"];
		$fecrec = implode("-", array_reverse(explode("-", $fecha)));
		$numfac = $row["numfac"];
		$cdgcli = $row["cdgcli"];
		$dsccli = $row["dsccli"];
        $pagcon = $row["pagcon"];		
		$montot = $row["montot"];
    	$cdgusu = $row["cdgcaj"];
		$vuelto = $row["vuelto"];
		$monint = $row["monint"];

	  $fecha = implode("-", array_reverse(explode("-",  $fecha )));

		
	  $usuario = "SELECT * FROM usuarios WHERE codusu='$cdgusu'";
	  $result3 = $mysqli->query($usuario);
      $row3 = $result3->fetch_array();

     $cajero  = $row3["usu"];	
	 $nomcomusu  = $row3["nomcomusu"];		

      $cliente ="Select * from web_0301 where cdgcli= $cdgcli";
	  $result2 = $mysqli->query($cliente);
      $row2 = $result2->fetch_array();

      $saldo_cliente = $row2["SALACT"];
	  $dircli = $row2["DIRCLI"];
	  $cedcli = $row2["CEDCLI"];
	  $numtel = $row2["NUMTEL"];
							

	$pdf->SetFillColor(255,255,255);	
    $pdf->SetTextColor(11,4,4);
    $pdf->SetDrawColor(0,0,0);
    $pdf->SetLineWidth(.2);
    $pdf->SetFont('Arial','B',12);	

//****fecha y numero de recibo****///	
	$pdf->Ln(7);
	$pdf->Cell(150);
	$pdf->Cell(10,4,$fecha,0,0,'L',0);
	$pdf->Cell(7);
	$pdf->Cell(12,4,"",0,0,'L',0);
	$pdf->Cell(12,4,"",0,0,'L',0);
	$pdf->Cell(10,4,"",0,0,'L',0);
	
	$pdf->Ln(15);
	$pdf->Cell(160);
	$pdf->Cell(10,4,$numrec,0,0,'L',0);
	
//****datos del encabezado****///		
	$pdf->SetFillColor(255,255,255);	
    $pdf->SetTextColor(11,4,4);
    $pdf->SetDrawColor(0,0,0);
    $pdf->SetLineWidth(.2);
    $pdf->SetFont('Arial','B',14);
	
	$pdf->SetY(39);	
	$pdf->Ln(-22);
	$pdf->Cell(5);
    $pdf->Cell(10,4,$nomcom,0,0,'L',0);
	
	$pdf->SetFillColor(255,255,255);	
    $pdf->SetTextColor(11,4,4);
    $pdf->SetDrawColor(0,0,0);
    $pdf->SetLineWidth(.2);
    $pdf->SetFont('Arial','B',10);
	
		$pdf->SetY(39);	
	$pdf->Ln(-15);
	$pdf->Cell(5);
    $pdf->Cell(10,4,$razsoc,0,0,'L',0);
	
	
	$cedula=$cedjur;
	$cedula_con= "Cédula: ". $cedula;
	
	$pdf->SetY(23);	
	$pdf->Ln(6);
	$pdf->Cell(5);
    $pdf->Cell(10,4,$cedula_con,0,0,'L',0);

	
	
	$pdf->SetY(27);	
	$pdf->Ln(6);
	$pdf->Cell(5);
    $pdf->Cell(10,4,"Dirección: ".$diremp,0,0,'L',0);
	

	$pdf->SetY(31);	
	$pdf->Ln(6);
	$pdf->Cell(5);
    $pdf->Cell(10,4,"Teléfono: ".$numtel_empresa,0,0,'L',0);
	
		$pdf->SetFillColor(255,255,255);	
    $pdf->SetTextColor(11,4,4);
    $pdf->SetDrawColor(0,0,0);
    $pdf->SetLineWidth(.2);
    $pdf->SetFont('Arial','B',9);
		
//****datos de cliente****///		
	$pdf->SetY(35);	
	$pdf->Ln(12);
	$pdf->Cell(38);
    $pdf->Cell(100,6,$cdgcli. " - ".$dsccli,0,0,'L',0);
	
	$pdf->SetY(41);	
	$pdf->Ln(12);
	$pdf->Cell(38);
    $pdf->Cell(35,8,$cedcli,0,0,'L',0);  
	
		$pdf->Ln(0);
	$pdf->Cell(125);
    $pdf->Cell(35,8,"Teléfono: ".$numtel,0,0,'L',0);    

	$pdf->SetY(47);	
	$pdf->Ln(12);
	$pdf->Cell(38);
    $pdf->Cell(35,8,$dircli,0,0,'L',0);                              
	

	
			
			
    //ahora mostramos las lneas de la factura
			$pdf->SetFillColor(255,255,255);	
    $pdf->SetTextColor(11,4,4);
    $pdf->SetDrawColor(0,0,0);
    $pdf->SetLineWidth(.2);
    $pdf->SetFont('Arial','B',10);	


	$pdf->SetY(80);		
	
		 
	$consulta3 = "SELECT * FROM pagos_clientes_recibos_lineas WHERE numrec='$numrec' ORDER BY numlinea ASC";
if ($resultado3 = $mysqli->query($consulta3)) 
$contador=0;

		 while ($fila = $resultado3->fetch_assoc()) {

        $numlinea = $fila["numlinea"];
        $salfac   = $fila["salfac"];
        $numfac   = substr($fila["numfac"],-10);
		$monabo   = $fila["monabo"];
		$totfac   = $fila["totfac"];
		$monint   = $fila["monint"];
		$intfac   = $fila["intfac"];
		$fecfac   = $fila["fecfac"];


	  $pdf->Cell(3);
	  $contador++;
	
	  
	 $pdf->Cell(27,0,$numfac,0,0,'L');
		
	
	 $fecfac= implode("-", array_reverse(explode("-", $fecfac)));
	 $pdf->Cell(12,0,$fecfac,0,0,'C');
  
      $pdf->Cell(12);
	  $totfac= number_format($totfac,2,".",",");	 
	  $pdf->Cell(40,0,$totfac,0,0,'L');
	  
	  $monabo= number_format($monabo,2,".",",");	 
	  $pdf->Cell(40,0,$monabo,0,0,'L');


	 $monint= number_format($monint,2,".",",");	 
	  $pdf->Cell(33,0,$monint,0,0,'L');
	  
	  
	   $salfac= number_format($salfac,2,".",",");	 

	  $pdf->Cell(40,0,$salfac,0,0,'L');
	

	  $contador=$contador + 1;
	  $lineas=$lineas + 1;	
	  
	  

  $pdf->Ln(5);	
	};


	$pdf->SetFillColor(255,255,255);	
    $pdf->SetTextColor(11,4,4);
    $pdf->SetDrawColor(0,0,0);
    $pdf->SetLineWidth(.2);
    $pdf->SetFont('Arial','B',10);	

	$pdf->SetY(244);	
	$pdf->Cell(152);
    $pdf->Cell(32,5,number_format(($montot),2,".",","),0,0,'R',0);
	$pdf->Ln(6);

	$pdf->SetY(249);	
	$pdf->Cell(152);
	$pdf->Cell(32,5,number_format(($pagcon),2,".",","),0,0,'R',0);
	$pdf->Ln(7);
		
	$pdf->SetY(255);	
	$pdf->Cell(152);
	$pdf->Cell(32,5,number_format(($vuelto),2,".",","),0,0,'R',0);
	$pdf->Ln(8);
	

	//Calculamos de numero a palabras
	//$nw = new Numbers_Words();
	 $pdf->SetY(246);	
	$pdf->Cell(34);
    $pdf->Cell(32,5,$nomcomusu,0,0,'C',0);
	$pdf->Ln(8);
	
	 $pdf->SetY(251);	
	$pdf->Cell(34);
    $pdf->Cell(32,5,"Firma y Sello",0,0,'C',0);
	$pdf->Ln(8);
	//Calculamos de numero a palabras
	//$nw = new Numbers_Words();
		
	$pdf->SetY(148);
	$pdf->Cell(15);
	
	//Modificamos esta parte para que también muestra la parte fraccionaria y M.N.
	//$decimales = explode(".",$total);	
	//$pdf->Cell(35,4,strtoupper($nw->toWords(round($total,0), "es") ." pesos ".$decimales[1]."/100 M.N."),0,0,'L',0);
	//$pdf->Cell(40,4,strtoupper($nw->toWords($decimales[0], "es") ." pesos ".$decimales[1]."/100 M.N."),0,0,'L',0);
	
		
     
	  
      $pdf->Output($name=("Recibo.pdf"),'I');


?>