<?php

require '../../libreriasphp/vendor/autoload.php';
use Spipu\Html2Pdf\Html2Pdf;
session_start();

require_once ("../../config/Cado.php");
require_once ("../../app/venta/cVenta.php");
$oVenta = new cVenta();
require_once ("../../app/venta/cVentapago.php");
$oVentapago = new cVentapago();
require_once ("../../app/producto/cCatalogo.php");
$oCatalogo = new cCatalogo();

require_once ("../../app/caja/cCaja.php");
$oCaja = new cCaja();
require_once ("../../app/empresa/cEmpresa.php");
$oEmpresa = new cEmpresa();
require_once ("../../app/formatos/numletras.php");
require_once ("../../app/formatos/formato.php");

date_default_timezone_set('America/Lima');
$now =  date('d-m-Y h:i:s a');

$hash = $_GET['venid'];


$cont = strlen($hash);

if($cont>20){
     $dts = $oVenta->convertir_hash($hash);
    while($dt = mysqli_fetch_array($dts)){
    $venid = $dt["tb_venta_id"];
    }
}else {
   $venid = $hash;
}



$dts7=$oVentapago->filtrar($venid);
$num_rows7= mysqli_num_rows($dts7);

if($num_rows7==1){
	
	$dtsvenpag =$oVentapago->mostrar_pagos($venid);
	$numrowsvenpag = mysqli_num_rows($dtsvenpag);
	$dtvenpag = mysqli_fetch_array($dtsvenpag);
	$forpag = $dtvenpag['tb_formapago_id'];
	$modpag = $dtvenpag['tb_modopago_id'];
	$venpag_fecven = $dtvenpag['tb_ventapago_fecven'];
	$venpag_mon = $dtvenpag['tb_ventapago_mon'];
	
	if($forpag==1){		
		$compag= 'CONTADO';	
	}else if($forpag==2){
		$compag= 'CREDITO';		
	}
}else{
	$compag= 'CREDITO';		
}





$dts6=$oVentapago->filtrar($venid);
$num_rows6= mysqli_num_rows($dts6);


	$dtsven= $oVenta->mostrarUno_ticket($venid);
	$dtven= mysqli_fetch_array($dtsven);
	//VENTA
	$ven_numDoc	=$dtven['numdoc'];
	$ven_docNom=$dtven['tb_documento_nom'];
	$ven_docAbr=$dtven['tb_documento_abr'];
	$ven_punVen=$dtven['tb_puntoventa_nom'];	
	$ven_venNom=$dtven['tb_usuario_nom'].' '.$dtven['tb_usuario_ape'];
	$ven_fecReg=$dtven['tb_venta_reg'];
	$ven_fec= mostrarFecha($dtven['tb_venta_fec']);
	$ven_est=$dtven['tb_venta_est'];
	$ven_valven=$dtven['tb_venta_valven'];
	$ven_igv=$dtven['tb_venta_igv'];
	$punven_dir = $dtven['tb_puntoventa_dir'];
	$ven_des=$dtven['tb_venta_des'];
	$ven_tot=$dtven['tb_venta_tot'];
	$ven_not=$dtven['tb_venta_not'];
	$ven_pisNom=$dtven['tb_piso_nom'];
	
	$cot_numdoc=$dtven['tb_cotizacion_numdoc'];
	$guia_numdoc=$dtven['tb_guiaremision_numdoc'];
	$guia_fec=mostrarFecha($dtven['tb_guiaremision_fec']);
	
	$ven_igvval = $dtven['tb_venta_igvval'];
	$ven_igvsub=$dtven['tb_venta_igvsub'];
	$ven_igvigv=$dtven['tb_venta_igvigv'];
	$ven_rel=$dtven['tb_venta_rel'];
	$ven_gra=$dtven['tb_venta_gra'];
	$ven_ina=$dtven['tb_venta_ina'];
	$ven_exo=$dtven['tb_venta_exo'];
	$ven_grat=$dtven['tb_venta_grat'];
	$ven_isc=$dtven['tb_venta_isc'];
	$ven_otrtri=$dtven['tb_venta_otrtri'];
	$ven_otrcar=$dtven['tb_venta_otrcar'];
	$ven_anti=$dtven['tb_venta_anti'];
	$empid=$dtven['tb_empresa_id'];
	$modpagid=$dtven['tb_formapago_id'];
	$fecven = mostrarFecha($dtven['tb_ventapago_fecven']);
	$ven_nom = $dtven['tb_usuario_use'];
	
	//CLIENTE
	$ven_pla=$dtven['tb_cliente_pla'];
	$cliNom=$dtven['tb_cliente_nom'];
	
	$vendigval=$dtven['tb_venta_digval'];
	$docabr=$dtven['tb_documento_abr'];
	$cliDoc=$dtven['doc'];
	$cliDir=$dtven['dir'];
	$cliId=$dtven['cliid'];
	$tipcam=$dtven['tb_venta_tipcam'];
	$monid=$dtven['moneid'];
	$ven_det_id	=$dtven['tb_detraccion_id'];
	$ven_det_tas	=$dtven['tb_detraccion_tas'];
	$ven_det_cod	=$dtven['tb_detraccion_cod'];
//	$tipcam=$dtven['tb_venta_tipcam'];
	mysqli_free_result($dtsven);
	
	
	 if($ven_igvval==0){
	$ven_igvval	=1;
	$ven_igvsub	=1;
	$ven_igvigv = 1;
  }
	
	
	
	if($ven_det_id>0){
		$mondet = ($ven_tot * $ven_det_tas) / 100;
		$ven_det_tot = $mondet*$tipcam;
	}
	
	if($ven_rel==0){
		
	}else{
		
	$dtsrel= $oVenta->mostrarUno_ticket($ven_rel);
	$dtrel= mysqli_fetch_array($dtsrel);	
	$cot_numdoc=$dtrel['tb_cotizacion_numdoc'];
	$guia_numdoc=$dtrel['tb_guiaremision_numdoc'];
	$guia_fec=mostrarFecha($dtrel['tb_guiaremision_fec']);
	}
	
	
	if($ven_pla==""){
		$vehi = '';
	}else{
		$vehi = ' VEHICULO : '.$ven_pla;
	}
	
	if($monid==1){
		$mon ="S/ ";
		$lblmon="SOLES";
	}else if($monid==2)
	{
		$lblmon="DOLARES AMERICANOS";
		$mon ="US$ ";
	}
	
	if($docabr=="F"){
		$tipodoc = 'FACTURA ELECTRONICA';
		$tipcom="01";
	}else if($docabr=="B"){
		$tipodoc = 'BOLETA ELECTRONICA';
		$tipcom="03";
	}else if($docabr=="T"){
	    
		$tipodoc = 'TICKET INTERNO';
		//$tipcom="03";
	}
	
	
$ser =  substr($ven_numDoc,0,4); 
$corr =  substr($ven_numDoc,5,13); 
	
$cont = strlen($cliDoc);

if($cont==11){
	$tipdoc = '06';
}else if($cont==8){
	$tipdoc = '01';
}

if($empid==1){
    $logurl = "https://boticafernandez.tec.ovh/imagenes/logopri.png";
}else {
    $logurl = "https://boticafernandez.tec.ovh/imagenes/logo.png";
}

	
$cts = $oCaja->filtro('2','',$empid);

$dts=$oEmpresa->mostrarUno($empid);
$dt = mysqli_fetch_array($dts);
	$emp_ruc=$dt['tb_empresa_ruc'];
	$emp_nomcom=$dt['tb_empresa_nomcom'];
	$emp_razsoc=$dt['tb_empresa_razsoc'];
	$emp_dir=$dt['tb_empresa_dir'];
	$emp_dir2=$dt['tb_empresa_dir2'];
	$emp_tel=$dt['tb_empresa_tel'];
	$emp_ema=$dt['tb_empresa_ema'];
	$emp_fir=$dt['tb_empresa_fir'];		
mysqli_free_result($dts);



	
if($docabr=='T'){
	
	$ru = '';
	
		$anular = '
		<tr>
		<td width="50%"></td>
	    <td width="50%" style="text-align: right">
		<strong style="color:red;font-size:10pt;" >NO VALIDA PARA EFECTOS TRIBUTARIOS</strong> 
		</td>
		</tr>
		';
}else{
	$anular = '';
	$ru = 'RUC : '.$emp_ruc;
}

	
$title = "Representacion de ".$ven_numDoc;
$nombre_archivo = $emp_ruc.'_'.$ven_numDoc.'_'.$cliDoc.'.pdf';

// $file_name = 'FA-'.$serie.'-'.$numero.'-code.png';
// $path = 'temp/'.$file_name;
// $type = pathinfo($path, PATHINFO_EXTENSION);
// $data = file_get_contents($path);
// $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);


class MYPDF extends TCPDF
{

    public function Header() {	
      //$image_file = K_PATH_IMAGES.'logo.jpg';
      //$this->Image($image_file, 20, 10, 71, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
      // Set font
      //$this->SetFont('helvetica', 'B', 20);
      // Title
      //$this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }

    public function Footer() 
    {
      // $style = array(
      //   'position' => 'L',
      //   'align' => 'L',
      //   'stretch' => false,
      //   'fitwidth' => true,
      //   'cellfitalign' => '',
      //   'border' => false,
      //   'padding' => 0,
      //   'fgcolor' => array(0,0,0),
      //   'bgcolor' => false,
      //   'text' => false
      // //     'font' => 'helvetica',
      // //     'fontsize' => 8,
      // //     'stretchtext' => 4
      // );

      // $this -> SetY(-24);
      // // Page number
      // $this->SetFont('helvetica', '', 9);
      // //$this->SetTextColor(0,0,0);
      // $this->Cell(0, 0, 'Página '.$this->getAliasNumPage().' de '.$this->getAliasNbPages(), 'T', 1, 'R', 0, '', 0, false, 'T', 'M');
      
      // $codigo='CAV-'.str_pad($_GET['d1'], 4, "0", STR_PAD_LEFT);
      
      // $this->write1DBarcode($codigo, 'C128', '', 273, '', 6, 0.3, $style, 'N');
      // $this->Cell(0, 0, 'www.prestamosdelnortechiclayo.com', 0, 1, 'C', 0, '', 0, false, 'T', 'M');        
    }
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('https://infosisperu.com.pe');
$pdf->SetTitle($title);

$pdf->SetSubject('https://infosisperu.com.pe');
$pdf->SetKeywords('https://infosisperu.com.pe');

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(12,15, 12);// left top right
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
//$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 15);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// add a page
$pdf->AddPage('P', 'A4');

//font-family: Consolas, monaco, monospace;
//helvetica, monaco, monospace;

// Introducimos HTML de prueba
$html = '
<!DOCTYPE html>
<html lang="es">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	 <link rel="shortcut icon" href="../../admin/bootstrap/images/favicon.png">
</head>
<style type="text/css">
    body {
        color: black;
        font-family: Verdana, Arial, Consolas;
        margin: 0px;
        padding-top: 0px;
        font-size: 7.5pt;
    }
    .header_row th {
		font-size:28px;
		background-color:#eee;
        border-bottom: 0.9px solid #010101;
        border-right: 0.9px solid #010101;
        border-left: 0.9px solid #010101;
        border-top: 0.9px solid #010101;
    }
    .odd_row td {
        background-color: transparent;
        border-bottom: 0.9px solid #010101;
        padding-top: 5px;
        padding-bottom: 5px;
    }
    .even_row td {
        padding-top: 5px;
        padding-bottom: 5px;
       border-bottom: 0.9px solid #010101;
    }
    .row td{
        border-right: 0.9px solid #010101;
        border-left: 0.9px solid #010101;
    }
</style>

<style media="print">
    .oculto{
        display: none;
    }

</style>
<body>




<table width="100%" style="" > '.$anular.'
<tr>
<td width="25%" >
';

if($docabr=="T"){
     $html.='
<br />
		<br />
		';
}else{
 $html.='
	<img style="" src="'.$logurl.'" alt="" />

        <strong style="font-size:20px;">'.$emp_razsoc.'</strong>
		<br>
        '.$punven_dir.'<br/>  
        Telf.: '.$emp_tel.' <br/> E-mail.: '.$emp_ema.'
		<br /> 
		
		';
}
	
$html.='
        
	</td>
	
        <td style="text-align:center;" width="10%">
	      
		</td>   
	   <td width="" style="text-align:center;">
        
        <div style="background-color:#EEEEEE;border-radius:20%;border:1px solid #E0E0E0;">
       <strong style="font-size: 20px">'.$ru.'<br>
       '.$tipodoc.'<br>
            '.$ven_numDoc.'</strong>
			  <br>
			  </div>
        </td>
    </tr>
</table>

<br />

<table width="100%" >
    
    <tr>
    
	<td width="65%">
	
	<div style="border-radius:20%;border:1px solid #E0E0E0;padding:10%;">
	
    <table  >
        <tr  style="border:1px solid #010101" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="25%"><strong></strong></td>
            <td style="text-align: left;padding:15%;font-size:10px" width="75%"></td>
        </tr>
        
        <tr  style="border:1px solid #010101" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="25%"><strong>SEÑOR(ES)</strong></td>
            <td style="text-align: left;padding:15%;font-size:10px" width="75%">'.$cliNom.'</td>
        </tr>
        
        <tr  style="border:1px solid #010101" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="25%">RUC</td>
            <td style="text-align: left;font-size:10px" width="75%">'.$cliDoc.'</td>
        </tr>
        
        <tr>
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="25%">DIRECCIÓN</td>
            <td style="text-align: left;font-size:10px" width="75%">'.$cliDir.'</td>
		</tr>
    </table>
    </div>
    
	</td>
    <td width="5%">
	      
	</td>
	
	<td width="30%" style="border-radius:20%;border:1px solid #E0E0E0;" >
        

	
    <table  >
       
        
        <tr  style="border:1px solid #010101" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="45%"><strong>VENDEDOR</strong></td>
            <td style="text-align: left;padding:15%;font-size:10px" width="55%">'.$ven_nom.'</td>
        </tr>
        
        <tr  style="border:1px solid #010101" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="45%">MONEDA</td>
            <td style="text-align: left;font-size:10px" width="55%">'.$lblmon.'</td>
        </tr>
        
        <tr>
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="45%">COND. PAGO</td>
            <td style="text-align: left;font-size:10px" width="55%">'.$compag.'</td>
		</tr>
    </table>
   
    
        
        
    </td>
    
    </tr>
    
</table>

<br />

<div style="border-radius:20%;border:1px solid #E0E0E0;">
<table width="100%;" style="border-collapse: collapse;"  >
    <tbody >
    
        <tr  style="border:1px solid #010101" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="25%"><strong></strong></td>
            <td style="text-align: left;padding:15%;font-size:10px" width="75%"></td>
        </tr>
        
        <tr class="" style="font-weight:bold;padding:10%;font-size:10px;">
            <th style="text-align:center; width:20%;padding:10%;" >FECHA EMISION</th>
            <th style="text-align:center; width:20%;padding:10%;" >FECHA VCTO</th>
            <th style="text-align:center; width:20%;padding:10%;" >N° GUIA</th>
            <th style="text-align:center; width:20%;padding:10%;" >FECHA GUIA</th>
        </tr>
		
		<tr style="padding:10%;font-size:10px;">		
		<td style="padding:10%;text-align:center;" >'.$ven_fec.'</td>
		<td style="padding:10%;text-align:center;" >'.$fecven.'</td>
		<td style="padding:10%;text-align:center;" >'.$guia_numdoc.'</td>
		<td style="padding:10%;text-align:center;" >'.$guia_fec.'</td>		
		</tr>
	
	</tbody>
</table>

</div>

<br />

<table width="100%;" style="border-collapse: collapse;height:400px;"  >
    <tbody >
        <tr class="" style="font-weight:bold;border:1px solid #010101;background-color:#EEEEEE;padding:15%;font-size:11px;">
            <th style="text-align:center; width:10%;background-color:#EEEEEE;padding:10%;" >CODIGO</th>
            <th style="text-align:right; width:5%;background-color:#EEEEEE;padding:10%;" >CAN</th>	
            <th style="text-align:center; width:35%;background-color:#EEEEEE;padding:10%;" >DESCRIPCION</th>
            <th style="text-align:center; width:15%;background-color:#EEEEEE;padding:10%;" >LAB</th>
            <th style="text-align:center; width:10%;background-color:#EEEEEE;padding:10%;" >LOTE</th>
            <th style="text-align:right; width:11%;background-color:#EEEEEE;padding:10%;" >FEC. VEN.</th>			
            <th style="text-align:right; width:7%;background-color:#EEEEEE;padding:10%;" >P/U</th>
            <th style="text-align:right; width:7%;background-color:#EEEEEE;padding:10%;" >P/T</th>
        </tr>
';

$dtsdetven=$oVenta->mostrar_venta_detalle($venid);
$cont=1;
while($dt1 = mysqli_fetch_array($dtsdetven))
	{
		$dts1=$oCatalogo->mostrarUno($dt1['tb_catalogo_id'],$dt1['tb_marca_id']);
		$dt = mysqli_fetch_array($dts1);
		$emp_fac =  $dt['tb_empaque_fac'];
		
    	$can = $dt1['tb_ventadetalle_can']*1;
		
		$pre_uni=$dt1['tb_ventadetalle_preuni'];
		$val_uni=$pre_uni/$ven_igvsub;
		$pre_tot = $pre_uni * $can;
		$igv_uni = $val_uni *$ven_igvigv;
		
		
		
			if($can>=$emp_fac){
				$can = $can/$emp_fac;
			}else{
				$can = $can;
			}
		
		
			
			//$can = $detven_can/$emp_fac;
		
			list($cane,$canf) = explode('.',$can);
			$canf = $canf * 1;
			
			//echo $cane.'--'.$canf ;
			//echo $canf.'-' ;


			if($cane!=="" && $canf==""){ 
				$can = $cane;
			}else if($cane=="" && $canf!==""){ 
				$can = $canf;
			}
			else if($cane!=="" && $canf!==""){ 
			
				$can = $can1;
			}
		
		
		$val_tot = $val_uni * $can;
		$igv_tot = $igv_uni * $can;
		
		 if($ven_igvval==1){
		 $igv_tot =0;
		 $igv_uni =0;
	 }
		
		
		$pre_tot = $val_tot + $igv_tot;


		
		$html.='
		<tr style="margin:15%;font-size:10px;border-top:1px solid #E0E0E0;">
		<td style="" >'.$dt1['tb_producto_codint'].'</td>
		<td style="text-align:right;" >'.$can .'</td>
		<td style="" >'.$dt1["tb_ventadetalle_nom"].'</td>
		<td style="font-size:11px;" >'.$dt['tb_marca_nom'].'</td>
		<td style="" >'.$dt1["tb_ventadetalle_lot"].'</td>
		<td style="" >'.$dt['tb_productomarca_fecven'].'</td>
		<td style="text-align:right;" >'.formato_money($pre_uni).'</td>
		<td style="text-align:right;" >'.formato_money($pre_tot).'</td>
		
		</tr>
		
		';				
		
		$cont++;
	}
	mysqli_free_result($dtsdetven);	




$html.='</tbody>
</table>
<br />
<br />
<table width="100%;"   >
    <tbody >
    
        <tr  style="border:1px solid #010101" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="70%"></td>
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="15%"><strong>OP. GRAVADA</strong></td>
            <td style="text-align: right;padding:15%;font-size:12px" width="15%"><strong>'.$mon.' '.formato_money($ven_valven).'</strong></td>
        </tr>  
        
         <tr  style="border:1px solid #010101" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="70%"></td>
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="15%"><strong>IGV (18%)</strong></td>
            <td style="text-align: right;padding:15%;font-size:12px" width="15%"><strong>'.$mon.' '.formato_money($ven_igv).'</strong></td>
        </tr>  
        
         <tr  style="border:1px solid #010101" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="70%"></td>
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="15%"><strong>TOTAL</strong></td>
            <td style="text-align: right;padding:15%;font-size:12px" width="15%"><strong>'.$mon.' '.formato_money($ven_tot).'</strong></td>
        </tr>  
        
	</tbody>
</table>

<br />
<br />

<div style="border-radius:20%;border:1px solid #E0E0E0;">

<table width="100%;"  >
    <tbody >
        <tr  style="" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="100%"></td>
        </tr>  
        
		<tr style="font-size:12px" >
		    <td style="padding:10%;text-align:left;" > SON '.numtoletras($ven_tot).' '.$lblmon.' </td>
		</tr>
		
	</tbody>
</table>

';

if($ven_det_id>0){
$html.='
<table width="100%;"  >
    <tbody >
       <tr  style="" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="100%"></td>
        </tr> 
        
		
		<tr style="font-size:12px" >
		    <td style="padding:10%;text-align:left;" colspan="2" > INFORMACION DE LA DETRACCION </td>
		</tr>
		
		<tr style="font-size:12px" >
		    <td style="padding:10%;text-align:left;" width="20%" > Leyenda: </td>
		    <td style="padding:10%;text-align:left;" > Operación sujeta al Sistema de Pago de Obligaciones Tributarias con el Gobierno Central </td>
		</tr>
		<tr style="font-size:12px" >
		    <td style="padding:10%;text-align:left;" width="20%" > Bien o Servicio: </td>
		    <td style="padding:10%;text-align:left;" > 039 Minerales no metálicos </td>
		</tr>
		<tr style="font-size:12px" >
		    <td style="padding:10%;text-align:left;" width="20%" > Medio de pago: </td>
		    <td style="padding:10%;text-align:left;" > 001 Depósito en cuenta </td>
		</tr>
		<tr style="font-size:12px" >
		    <td style="padding:10%;text-align:left;" width="30%" > Nro. Cta. Banco de la Nación: </td>
		    <td style="padding:10%;text-align:left;" > 00741716429 </td>
		</tr>
		<tr style="font-size:12px" >
		    <td style="padding:10%;text-align:left;" width="30%" > Porcentaje de detracción: </td>
		    <td style="padding:10%;text-align:left;" width="20%" >'.formato_money($ven_det_tas).'</td>
		    <td style="padding:10%;text-align:left;"  width="30%" > Monto detracción: </td>
		    <td style="padding:10%;text-align:left;" width="20%" >S/ '.number_format($ven_det_tot,0).'</td>
		</tr>
		
		
		
		
	</tbody>
</table>
';
}






if($num_rows6>0){
$html.='
<table width="50%;"  >
    <tbody >
       <tr  style="" >
            <td style="text-align: left;font-weight:bold;padding:10%;font-size:12px;" width="100%"></td>
        </tr> 
        
		
		<tr style="font-size:12px" >
		    <td style="padding:10%;text-align:left;" colspan="2" > INFORMACION DE LAS CUOTAS </td>
		</tr>
		
		
		<tr class="" style="font-weight:bold;border:1px solid #010101;background-color:#EEEEEE;padding:15%;font-size:11px;">
            <th style="text-align:right; width:15%;background-color:#EEEEEE;padding:10%;" >CUOTA</th>
            <th style="text-align:right; width:40%;background-color:#EEEEEE;padding:10%;" >FECHA VENCIMIENTO</th>
            <th style="text-align:right; width:20%;background-color:#EEEEEE;padding:10%;" >MONTO</th>
        </tr>
        
        ';
        
    while($dt6 = mysqli_fetch_array($dts6))
	{
	    $i++;
        $html.='
        
        <tr style="margin:15%;font-size:10px;border-top:1px solid #E0E0E0;">
		<td style="text-align:right;" >'.$i.'</td>
		<td style="text-align:right;" >'.mostrarFecha($dt6['tb_ventapago_fecven']).'</td>
		<td style="text-align:right;" >'.formato_money($dt6['tb_ventapago_mon']).'</td>
		
		</tr>
		
        
        ';
	}
		
	
		

		
	$html.='	
		
	</tbody>
</table>
';
}



$html.='

</div>

<br />


';





if($docabr=="T"){

}
else{
$html.=
'


<table width="100%;"  >


<tr>
<td width="75%;"  >
<br />
<br />
<br />
<p style="font-size:10pt">
Código de Seguridad (Hash): '.$vendigval.'<br>
Representación Impresa de la '.$tipodoc.'.<br>
Esta puede ser consultada en: <strong>http://e-consulta.sunat.gob.pe/ol-ti-itconsvalicpe/ConsValiCpe.htm</strong><br>
Autorizado mediante Resolucion de Superintendencia SUNAT
</p>
</td>

<td>

';

$style = array(
	'border' => 1,
	'vpadding' => 'auto',
	'hpadding' => 'auto',
	'fgcolor' => array(0,0,0),
	'bgcolor' => false, //array(255,255,255)
	'module_width' => 1, // width of a single module in points
	'module_height' => 1 // height of a single module in points
);

$params = $pdf->serializeTCPDFtagParameters(array($emp_ruc.'|'.$tipcom.'|'.$ser.'|'.$corr.'|'.$ven_igv.'|'.$ven_tot.'|'.$ven_fec.'|'.$tipdoc.'|'.$cliDoc.'|', 'QRCODE,Q', '', '', 40, 40, $style, 'N'));
$html .= '<tcpdf method="write2DBarcode" params="'.$params.'" />
</td>
</tr>
</table>

';
}



$html.='
<br />
<br />
<table width="100%;"  style="border-collapse: collapse">
<tr style="font-weight:bold;border:1px solid #010101;background-color:#EEEEEE;padding:15%;font-size:31px;" >
    <td style="text-align: left;font-weight:bold;padding:10%;font-size:10px;background-color:#EEEEEE;width:30%;" >BANCO</td>
    <td style="text-align: left;font-weight:bold;padding:10%;font-size:10px;background-color:#EEEEEE" >MONEDA</td>
    <td style="text-align: left;font-weight:bold;padding:10%;font-size:10px;background-color:#EEEEEE" >CUENTA</td>
    <td style="text-align: left;font-weight:bold;padding:10%;font-size:10px;background-color:#EEEEEE" >CCI</td>
</tr>
';




while($ct1 = mysqli_fetch_array($cts)){
$html.='
<tr>   
<td style="text-align: left;font-weight:bold;padding:10%;font-size:10px;" >'.'<strong>'.$ct1['tb_banco_nom'].'</strong></td>
<td style="text-align: left;font-weight:bold;padding:10%;font-size:10px;" >'.$ct1['tb_moneda_nom'].'</td>
<td style="text-align: left;font-size:10px" >'.$ct1['tb_caja_nom'].'</td>
<td style="text-align: left;font-size:10px" >'.$ct1['tb_caja_cci'].'</td>
</tr>
';
}
$html.='
</table> 
';




$html.='
</body>
</html>';

$pdf->writeHTML($html, true, 0, true, true);

//$pdf->write2DBarcode($ruc_empresa.'|'.$idcomprobante.'|'.$serie.'|'.$numero.'|'.$toigv.'|'.$importetotal.'|'.fecha_mysql($fecha).'|'.$idtipodni.'|'.$ruc.'|', 'QRCODE,Q', 157, 99, 40, 40, $style, 'N');

$pdf->Output($nombre_archivo, 'I');
