<?php

require_once('pdf/pdf_js.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
require_once("DF80000.php");
include("DMMYSQLG.php");
//include("DSA3000.php");
class PDF extends PDF_JavaScript{
	function AutoPrint($dialog=false){
		//Open the print dialog or start printing immediately on the standard printer
		$param=($dialog ? 'true' : 'false');
		$script="print($param);";
		$this->IncludeJS($script);
	}
	
	function AutoPrintToPrinter($server, $printer, $dialog=false){
		//Print on a shared printer (requires at least Acrobat 6)
		$script = "var pp = getPrintParams();";
		if($dialog)
			$script .= "pp.interactive = pp.constants.interactionLevel.full;";
		else
			$script .= "pp.interactive = pp.constants.interactionLevel.automatic;";
		$script .= "pp.printerName = '\\\\\\\\".$server."\\\\".$printer."';";
		$script .= "print(pp);";
		$this->IncludeJS($script);
	}
	function SendToDefaultPrinter($dialog=false,$printer="",$arrOpt=NULL){
		//$script ='trustedPrint = app.trustedFunction(function(){';
		//$script .= '	app.beginPriv();';
		$script .= "	var pp = getPrintParams();";
		$script .= "	fv = pp.constants.flagValues;";
		$script .= "	pp.flags |=(fv.suppressCenter|fv.suppressRotate);";
		$script .= "	pp.pageHandling=pp.constants.handling.none;";		
		($dialog)?($script .= "	pp.interactive = pp.constants.interactionLevel.full;"):($script .= "pp.interactive = pp.constants.interactionLevel.automatic;");
		//$script .= "this.print(pp);";
		$script .= "	this.print(pp);";
		$script .= "	this.print(pp);";
		$script .= "	this.print(pp);";
		//$script .= "	app.endPriv();";
		//$script .= '}';
		//$script .='trustedPrint();';
				
		$this->IncludeJS($script);				
	}
	
}
$dt_parame =mysqli_fetch_array(mysqli_query($con ,"select * from dgparame"));

$arrHoja=array(180,215);
$pdf=new PDF('P','mm',$arrHoja);
$pdf->SetMargins(6,0,5);
$pdf->SetAutoPageBreak(true,5);
$pdf->AddFont('verdana');
$pdf->AddPage();
$dt_factur=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgfactur WHERE fol_fac = '".$_REQUEST['bot']."'"));
$dt_catcli=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgcatcli WHERE cod_cli = '".$dt_factur['cod_cli']."'"));
$dt_catven=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgcatven WHERE cod_ven = '".$dt_factur['cod_ven']."'"));
$dt_tipven=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgtipven WHERE tip_ven = '".$dt_factur['tip_ven']."'"));
$pdf->SetFont('verdana','',9);
$pdf->Ln(20);
$pdf->SetXY(140,66);
$pdf->Cell(35,5,chfecha($dt_factur['fec_fac'],'Y-m-d','d/m/Y'),0,1,'C');
$pdf->SetXY(140,71);
if($_POST['imp_fac_cop'])
	$pdf->Cell(15,5,"COPIA",0,2,'L');
if(trim($dt_factur['con_cre'])=="R")
	$pdf->Cell(35,5,"CREDITO",0,1,'C');
else
	$pdf->Cell(35,5,"CONTADO",0,1,'C');
$pdf->SetXY(105,46);
$pdf->Cell(30,5,$dt_tipven['tip_fac'].$dt_factur['num_fac'],0,1,'C');
$pdf->SetXY(105,51);
$pdf->Cell(30,5,$dt_factur['fol_ven'],0,1,'C');

@$dt_bascps=mysqli_fetch_array(mysqli_query($con ,"select * from dxbascps where codigo = '".$dt_catcli['codigo']."'"));
@$dt_coloni=mysqli_fetch_array(mysqli_query($con ,"select * from geoyos_jc.dxcoloni where cve_col = '".$dt_bascps['des_colonia']."'"));
@$dt_delmun=mysqli_fetch_array(mysqli_query($con ,"select * from geoyos_jc.dxdelmun where cve_delmun = '".$dt_bascps['cve_delmun']."'"));
@$dt_estado=mysqli_fetch_array(mysqli_query($con ,"select * from geoyos_jc.dxestado where cve_estado = '".$dt_bascps['cve_estado']."'"));

$pdf->SetXY(20,48);
$pdf->Cell(50,4,trim($dt_catcli['codigo']),0,0,'L');
if($dt_parame['cod_pubgral']!=$dt_catcli['cod_cli'])
	$pdf->SetXY(7,55);
else
	$pdf->SetXY(7,55);
$pdf->Cell(132,4,trim($dt_catcli['ap_pat_cli'] . ' ' . $dt_catcli['ap_mat_cli'].' '.$dt_catcli['nom_cli']),0,0,'L');
$bIVA=false;
if($dt_parame['cod_pubgral']!=$dt_catcli['cod_cli'] && $dt_factur['iva_des']=='1'){
	$bIVA=true;
	$pdf->SetXY(25,60);
	$pdf->Cell(110,4,$dt_bascps['calle'].' '.$dt_bascps['no_ext'].' '.$dt_bascps['no_int'],0,1,'L');
	if(trim($dt_bascps['entre_calle'])!=''){
		$pdf->SetXY(25,64);
		$pdf->Cell(110,4,$dt_bascps['entre_calle'].' '.$dt_bascps['y_calle'],0,1,'L');		
	}
	$pdf->SetXY(25,68);
	$pdf->Cell(110,4,"COL.".$dt_coloni['des_colonia']." CP.".str_pad($dt_bascps['cod_pos'],5,'0',STR_PAD_LEFT)." ".$dt_delmun['des_delmun']." ".$dt_estado['des_estado'],0,0,'L');
	$pdf->SetXY(15,72);	
	$pdf->Cell(40,4,$dt_catcli['rfc_cli'],0,1,'L');
}
if($dt_factur['es_glo']){
	$resu3=mysqli_query($con ,"SELECT '1' as can_ref,dgfactur.sub_ven as pre_uni,(dgfactur.sub_ven+dgfactur.iva_ven) as pre_bas,GROUP_CONCAT(dgpemema.con_ven SEPARATOR ',') as np_desc1 FROM dgfactur INNER JOIN dgpemema ON(dgpemema.num_fac=dgfactur.num_fac AND dgpemema.tip_ven=dgfactur.tip_ven) WHERE dgfactur.fol_fac = '".$dt_factur['fol_fac']."' group by dgfactur.fol_fac");
	$leyDet="FACTURACION GLOBAL POR VENTAS DEL DIA ".whatDay($dt_factur['fec_fac'])." ".chfecha($dt_factur['fec_fac'],'Y-m-d','d/m/Y').", CON NUMEROS DE FOLIO: ";
}
else{
	@$resu3=mysqli_query($con ,"select dgfactud.*,dginvent.np_desc1 from dgfactud LEFT JOIN dginvent ON(dginvent.nparte1=dgfactud.nparte1) where dgfactud.cons_fac = '".$dt_factur['fol_fac']."'");
}
$pdf->SetXY(5,85);
$pdf->SetWidths(array(13,1,20,83,1,23,1,27));
$pdf->SetDrawColor(255,255,255);
$pdf->SetAligns(array('R','C','L','L','C','R','C','R'));
while(@$rego3=mysqli_fetch_array($resu3)){
	//@$regox=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '".$rego3['nparte1']."'"));
	if($bIVA){
		$preUni=$rego3['pre_uni'];
	}else{
		$preUni=$rego3['pre_bas'];
	}
	$pdf->row(	array($rego3['can_ref'],
				' ',
				$rego3['nparte1'],
				$leyDet.$rego3['np_desc1'],
				' ',
				number_format($preUni,2, '.', ','),
				' ',
				number_format(($preUni*$rego3['can_ref']), 2, '.', ',')
		));
	$num_elementos1 += 1;
}
$pdf->SetXY(148,181);
if($bIVA){
	$totIVA=$dt_factur['iva_ven'];
	$subTot=$dt_factur['sub_ven'];
}else{
	$subTot=$dt_factur['tot_ven'];
	$totIVA=0.00;
}
$pdf->Cell(27,5,number_format($subTot, 2, '.', ','),0,1,'R');

$pdf->SetXY(148,188);
$pdf->Cell(27,4,number_format($totIVA, 2, '.', ','),0,1,'R');

$pdf->SetXY(148,195);
$pdf->Cell(27,4,number_format($dt_factur['tot_ven'], 2, '.', ','),0,1,'R');

$pdf->SetXY(58,186);
$pdf->Cell(29,4,$dt_catven['cod_ven'],0,1,'C');
$pdf->SetXY(58,190);
$pdf->Cell(29,4,$dt_catven['nom_ven'],0,1,'C');
include("DF10000.php");
$can=number_format($dt_factur['tot_ven'],2,'.','');
$parTot=explode(".","$can");
//if($parTot[1]==0 || $parTot[1]==''){
//	$parTot[1]='00';
//}
$pre_let=num2letras(number_format($parTot[0], 2, '.', ''));
$pdf->SetXY(6,170);

$pdf->Cell(118,5,"PAGADO EN UNA SOLA EXHIBICION EFECTOS FISCALES AL COBRO",0,0,'L');
$pdf->SetXY(6,175);
$pdf->Cell(118,5,"(".$pre_let.' PESOS '."$parTot[1]".'/100 M.N.'.")",0,0,'L');
if(!$_POST['imp_fac_cop'])
	$pdf-> SendToDefaultPrinter(false);
$pdf->Output("FACTURA $dt_factur['tip_fac']$dt_factur['num_fac'].pdf",'I');
?>