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

class PDF extends FPDF
{
// Cabecera de página
function Header(){
include('librerias/conex.php');

if (isset($_REQUEST['pnrocmp'])){$pnrocmp=$_REQUEST['pnrocmp'];}else{$pnrocmp="";} 
if (isset($_REQUEST['pnriper'])){$pnriper=$_REQUEST['pnriper'];}else{$pnriper="";} 
if (isset($_REQUEST['pcodemp'])){$pcodemp=$_REQUEST['pcodemp'];}else{$pcodemp="";}


$link=@Conectarse(); 
$correr=0;
$Sqlconsulta="select nomcmp.*,admemp.diremp,admemp.nitemp,admemp.digemp,admemp.obsemp,admemp.nomemp from nomcmp,admemp where nomcmp.codsed=admemp.codsed and nomcmp.nrocmp='".$pnrocmp."' and nomcmp.estcmp!='Eliminado' ";

$resultcar = mysql_query($Sqlconsulta,$link);
while($rowcar = mysql_fetch_array($resultcar)){
extract($rowcar);
//llenar datos del JSON
	$nriper=$rowcar['nriper'];
	$nomper=$rowcar['nomper'];
	$fchcmp=$rowcar['fchcmp'];
	$nrofac=$rowcar['nrocmp'];
	$dirter="";
	$nrorem="";
	$fincmp=$rowcar['fincmp'];
	$inicmp=$rowcar['inicmp'];
	$ciuter="";
	$telter="";
	$dirent="";
	$cttord="";
	$cttprv="";
	$emlprv="";
	$nomemp=$rowcar['nomemp'];
	$nitemp=$rowcar['nitemp'];
	$diremp=$rowcar['diremp'];
	$obsemp=$rowcar['obsemp'];
    $correr=$correr+1;
}
mysql_free_result($resultcar);
mysql_close($link);
	
    // Logo
     $this->Image('themes/images/logo.png',10,1,50);
	 $this->Image('themes/images/linea.png',10,58,195);
	 $this->Image('themes/images/cuadro.png',150,31,0);
	  
    // Arial bold 15
    $this->SetFont('Arial','B',15);
    // Movernos a la derecha
    $this->Cell(50,1);
    // Título
     $this->Cell(10,1,$nomemp,0,0,'0');
	 $this->Cell(100,1);
	 $this->SetFont('Arial','',7);
	 $this->Cell(10,1,'EM-EMPIRE',0,0,'0');
	
    // Salto de línea
     $this->Ln(5);
	 $this->Cell(90,1);
	 $this->SetFont('Arial','B',10);
	 $this->Cell(10,1,'NIT:'+$nitemp,0,0,'0');
	 $this->Cell(55,1);
	 $this->SetFont('Arial','',9);
	 $DateOfRequest =  date("d/m/Y H:i:s"); 
	 $this->Cell(90,1,$DateOfRequest,0,0,'0');
	 
	 $this->Ln(5);
	 $this->Cell(60,1);
	 $this->SetFont('Arial','',9);
	 $this->Cell(10,1,$obsemp,0,0,'0');
	 $this->Ln(8);
	 
	 $this->Cell(140,1);
	 $this->SetFont('Arial','B',10);
	 $this->Cell(2,1,'VOLANTE No.'.$pnrocmp,0,0,'0');
	 $this->Ln(6);
	 
	 $this->Cell(1,1);
	 $this->SetFont('Arial','B',10);
	 $this->Cell(2,1,'EMPLEADO ',0,0,'0');
	 
	 $this->Cell(22,1);
	 $this->SetFont('Arial','',9);
	 $this->Cell(2,1,rtrim($nriper)."-".rtrim($nomper),0,0,'0');
	 

	 
	 $this->Cell(113,1);
	 $this->SetFont('Arial','B',9);
	 $this->Cell(2,1,'       PERIODO DE TRABAJO',0,0,'0');

	 $this->Ln(5);
	 
	 $this->Cell(1,1);
	 $this->SetFont('Arial','B',9);
	 $this->Cell(2,1,'CARGO: ',0,0,'0');
	 $this->Cell(21,1);
	 $this->SetFont('Arial','',9);
	 $this->Cell(2,1,$nomcrg,0,0,'0');
	 
	
	 
	 $this->Cell(114,1);
	 $this->SetFont('Arial','B',9);
	 $this->Cell(2,1,'Inicia: ',0,0,'0');
	 $this->Cell(12,1);
	 $this->SetFont('Arial','',9);
	 $this->Cell(2,1,rtrim($inicmp),0,0,'0');
	 $this->Ln(5);
	 
	 
	 if($nomsed=="")$nomsed="PRINCIPAL";
	 $this->Cell(1,1);
	 $this->SetFont('Arial','B',9);
	 $this->Cell(2,1,'SEDE: ',0,0,'0');
	 $this->Cell(21,1);
	 $this->SetFont('Arial','',9);
	 $this->Cell(2,1,$nomsed,0,0,'0');
	 
	 
	 $this->Cell(114,1);
	 $this->SetFont('Arial','B',9);
	 $this->Cell(2,1,'Finaliza ',0,0,'0');
	 $this->Cell(13,1);
	 $this->SetFont('Arial','',9);
	 $this->Cell(2,1,rtrim($fincmp),0,0,'0');
	 
	 
	  $this->Ln(5);
	 
	 $this->Cell(1,1);
	 $this->SetFont('Arial','B',9);
	 $this->Cell(2,1,'EPS:',0,0,'0');
	 $this->Cell(21,1);
	 $this->SetFont('Arial','',8);
	 $this->Cell(2,1,$epsper,0,0,'0');
	 
	 
	  $this->Cell(114,1);
	 $this->SetFont('Arial','B',9);
	 $this->Cell(2,1,'Dias Lab: ',0,0,'0');
	 $this->Cell(13,1);
	 $this->SetFont('Arial','',9);
	 $this->Cell(2,1,rtrim($dialab),0,0,'0');
	 
	 
	 $this->Ln(5);
	 
	 $this->Cell(1,1);
	 $this->SetFont('Arial','B',8);
	 $this->Cell(2,1,'PENSION:',0,0,'0');
	 $this->Cell(21,1);
	 $this->SetFont('Arial','',8);
	 $this->Cell(2,1,$penper,0,0,'0');
	 
	 
	 $this->Cell(114,1);
	 $this->SetFont('Arial','B',9);
	 $this->Cell(2,1,'Salario:',0,0,'0');
	 $this->Cell(12,1);
	 $this->SetFont('Arial','',9);
	 $this->Cell(2,1,number_format($vlrsal),0,0,'0');
	 $this->Ln(7);
	 
   
   

	 
}


// Pie de página
function Footer()
{
	

    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Número de página
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

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

	 $pdf->Cell(1,1);
	 $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(2,1,'CONCEPTO',0,0,'0');
	 
	 $pdf->Cell(45,1);
	 $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(2,1,'CANTIDAD',0,0,'0');
	 
	 $pdf->Cell(20,1);
	 $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(2,1,'V. UNITARIO',0,0,'0');
	 
	 $pdf->Cell(25,1);
	 $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(2,1,'DEVENGOS',0,0,'0');
	 
	 $pdf->Cell(30,1);
	 $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(2,1,'DEDUCCIONES',0,0,'0');
	 
	 $pdf->Cell(35,1);
	 $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(2,1,'ASIGNACIONES',0,0,'0');
$pdf->Ln(5);

if (isset($_REQUEST['pnrocmp'])){$pnrocmp=$_REQUEST['pnrocmp'];}else{$pnrocmp="";}
$link=@Conectarse(); 
$correr=0;
$Sqlconsulta="select nompre.*,nomcmp.obscmp as obscmp from nompre,nomcmp where nomcmp.nrocmp=nompre.nrocmp and nompre.nrocmp='".$pnrocmp."' order by codknp";
$resultcar = mysql_query($Sqlconsulta,$link);

$totaldevengo=0;
$totaldedu=0;

while($rowcar = mysql_fetch_array($resultcar)){
extract($rowcar);
//llenar datos del JSON
$detalle=substr($rowcar['codknp']."-".$rowcar['nomknp'],0, 28);
	 $pdf->Cell(1,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,$detalle,0,0,'0');
	 
	 if($rowcar['canknp']==0){$cantidad=1;}else{$cantidad=$rowcar['canknp'];};
	 $pdf->Cell(50,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,$cantidad,0,0,'0');
	 
	 $valor=number_format($rowcar['vlrknp']);
	 if($valor<=0)$valor="";
	 $pdf->Cell(20,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,$valor,0,0,'0');
	 
	 
	  $totaldevengo=$totaldevengo+$rowcar['devnom'];
	  
	 $pdf->Cell(25,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,number_format($rowcar['devnom']),0,0,'0');
	 
	 $totaldedu=$totaldedu+$rowcar['dednom'];
	 $valort=number_format($rowcar['dednom']);
	 $pdf->Cell(30,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,  $valort,0,0,'0');
	 
	 $pdf->Cell(35,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,'',0,0,'0');
     $pdf->Ln(5);
    $correr=$correr+1;
	$observacio=$rowcar['obscmp'];
}

	 $pdf->Cell(1,1);
	 $pdf->Cell(2,1,"__________________________________________________________________________________________________________",0,0,'0');
$pdf->Ln(5);

	 $pdf->Cell(95,1);
	 $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(2,1,number_format($totaldevengo),0,0,'0');
	 
	 $pdf->Cell(32,1);
	 $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(2,1,number_format($totaldedu),0,0,'0');
	 $pdf->Ln(1);
	 
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(90,1);
	 $pdf->Cell(2,1,"________________________________________________________",0,0,'0');

      $pdf->Ln(5);
	  
      $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(100,1);
	 $pdf->Cell(2,1,"TOTAL NETO A PAGAR",0,0,'0');
	  
      $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(65,1);
	 $pdf->Cell(2,1,number_format($totaldevengo-$totaldedu),0,0,'0');


 $pdf->Ln(1);
 
     $observacio1= substr($observacio,0,130);
	 $pdf->Cell(1,1);
	 $pdf->SetFont('Arial','B',9);
	 $pdf->Cell(2,1,'OBSERVACION:',0,0,'0');
	 $pdf->Ln(5);
	 $pdf->Cell(1,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,$observacio1,0,0,'0');
	 
	 $pdf->Ln(3);
	 $observacio2= substr($observacio,130,130);
	 $pdf->Cell(1,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,$observacio2,0,0,'0');
	 
	 $pdf->Ln(3);
	 $observacio2= substr($observacio,130*2,130);
	 $pdf->Cell(1,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,$observacio2,0,0,'0');

     $pdf->Ln(3);
	 $observacio3= substr($observacio,130*3,130);
	 $pdf->Cell(1,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,$observacio3,0,0,'0');
	 
	 
	 
	 $pdf->Ln(10);
	 $pdf->Cell(1,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,"RECIBI CONFORME:_____________________________",0,0,'0');
	 
	 if (isset($_REQUEST['pnriper'])){$pnriper=$_REQUEST['pnriper'];}else{$pnriper="";} 
    $pdf->Ln(5);
	 $pdf->Cell(30,1);
	 $pdf->SetFont('Arial','',9);
	 $pdf->Cell(2,1,"C:C.".$pnriper,0,0,'0');
	 
mysql_free_result($resultcar);
mysql_close($link);
$pdf->Output();

mysql_close($link);

?>