<?php
	session_start();
	include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
	if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
	//-------------------------		
	if(strlen($_SESSION['SYS_USER_ID'])==0){
	JsDir("login.php");	return;
}
	//-------------------------
	$StrId=V($_POST['TxtId']);
	$StrCmd=V($_POST['TxtAc']);
	//-------------------------
	$StrAlm=V($_POST['CboAlm']);		
	$StrCom=V($_POST['CboCom']);		
	$StrSer=V($_POST['TxtSer']);		
	$StrNum=V($_POST['TxtNum']);		
	$StrDex=V($_POST['TxtDex']);		
	$StrHax=V($_POST['TxtHax']);			
	$StrPro=V($_POST['TxtPro']);			
	$StrSN=V($_POST['CboSN']);
	$StrDes=V($_POST['TxtDes']);		
	$StrMar=V($_POST['TxtMar']);			
	
	//-------------------------
	if($_SESSION['SYS_USER_ALM']=="%"){
		if(strlen($StrAlm)==0)$StrAlm=GetSO("alm_nombre","almacenes","","alm_nombre");
	}else{
		$StrAlm=$_SESSION['SYS_USER_ALM'];
	}
	if(strlen($StrCom)==0) $StrCom="TODOS";	
	if(strlen($StrSN)==0) $StrSN="NO";	
	$StrSN_=substr($StrSN,0,1);
	$StrDes_=$StrDes."%";
	$StrMar_=$StrMar."%";
	//-------------------------
	if($StrCom=="TODOS"){
		$StrCom_="%";
	}else{
		$StrCom_=$StrCom;
	}
	$StrNum_=$StrNum."%";
	$StrSer_=$StrSer."%";
	if(strlen($StrDex)==0){
		$StrDex_="2000-01-01";
	}else{
		$StrDex_=ToDate($StrDex);
	}
	if(strlen($StrHax)==0){
		$StrHax_="2020-12-01";
	}else{
		$StrHax_=ToDate($StrHax);
	}
	$StrPro_=$StrPro."%";
	//-------------------------
	$FF="ID>0 AND ALM LIKE '$StrAlm' AND COM LIKE '$StrCom_' AND 
		NUM LIKE '$StrNum_' AND SER LIKE '$StrSer_' AND 
		FEC >= '$StrDex_' AND FEC <= '$StrHax_' AND 
		CLI LIKE '$StrPro_' AND ANU LIKE '$StrSN_' AND
		DES LIKE '$StrDes_' AND MAR LIKE '$StrMar_'";
	$LStrTR=gn("count(*)","vcotizaciones_det",$FF);
	$LStrPag=V($_POST['TxtPag']);	
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=50000;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cotizaciones - Buscar- Detallado</title>
<script type="text/javascript" src="funciones.js"></script>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="jquery.maskedinput.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$("#TxtDex").mask("99-99-99");
});


function fGenPDF(){	
	document.getElementById("TxtAc").value="GEN_PDF";
	document.getElementById("Frm").submit();
}

function fGenPDF_2(){	
	document.getElementById("TxtAc").value="GEN_PDF_2";
	document.getElementById("Frm").submit();
}

</script>

<script language="javascript">
$(document).ready(function() {
	$(".botonExcel").click(function(event) {
		$("#datos_a_enviar").val( $("<div>").append( $("#Exportar_a_Excel").eq(0).clone()).html());
		$("#FormularioExportacion").submit();
});
});
</script>
<style type="text/css">
<!--
body {
	background-color: #CCC;
}
#Layer1 {
	position:absolute;
	left:345px;
	top:115px;
	width:123px;
	height:35px;
	z-index:1;
}
.centrarFrm{
	width:1000px;
	height:600px;
	position:absolute;
	left:50%;
	top:50%;
	background-color:#006699;
	margin:-300px 0 0 -500px;
}
#Layer2 {
	position:absolute;
	left:409px;
	top:205px;
	width:82px;
	height:24px;
	z-index:1;
}
.Estilo1 {
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	color: #FFFFFF;
}
.Estilo2 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #FFFFFF; font-size: 12px; }
.Estilo3 {color: #FFFFFF; font-size: 12px; font-family: Arial, Helvetica, sans-serif;}
.eS4 {color: #000099}
.Estilo5 {color: #000000}

-->
</style>

</head>
<body  <?php echo $StrMsg;?>>
<div Id="DivFRM"  class="centrarFrm" >
<form id="Frm" name="Frm" method="post" action="cotizaciones_buscar_det.php">
<center> 
  
    <div id="layer6" style="position:absolute; left: 305px; top: 116px; width: 74px;">
      <div align="left" class="Estilo2">NUMERO</div>
    </div>
    <div id="layer5" style="position:absolute; left: 79px; top: 50px; width: 406px; height: 28px;">
      <div align="left" class="Estilo2">
        <input name="CmdV" type="button" id="CmdV" 
        value="Volver" onclick="fVolver('cotizaciones.php');" />

        <input name="CmdPDF" type="button" id="CmdPDF" 
		style="width:100px"
        value="Generar.PDF" onclick="fGenPDF_2();"
        tabindex="38"/>

        <input name="CmdPDF" type="button" id="CmdPDF" 
        value="PDF.Detallado" onclick="fGenPDF();" 
        tabindex="39"/>
      </div>
    </div>
    <div id="layer3" style="position:absolute; left: 25px; top: 160px; width: 958px; height: 391px; overflow:auto">
      <div align="left" class="Estilo2">
        <table id="Exportar_a_Excel" width="942" height="19" border="1" cellpadding="0" cellspacing="0">
        <tr  >
            <td height="18" colspan="10" bgcolor="#666666" align="center">
<?php //echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
            </td>
           
          </tr>
<tr>
<td width="90" bgcolor="#999999"><span class="eS4">ALMACEN</span></td>
<td width="97" bgcolor="#999999"><span class="eS4">COMPROB</span></td>
<td width="89" bgcolor="#999999"><span class="eS4">NUMERO</span></td>
<td width="75" bgcolor="#999999"><span class="eS4">FECHA</span></td>
<td width="141" bgcolor="#999999"><span class="eS4">CLIENTE</span></td>
<td width="180" bgcolor="#999999"><span class="eS4">DESCRIPCION</span></td>
<td width="99" bgcolor="#999999"><span class="eS4">MARCA</span></td>
<td width="54" bgcolor="#999999" align="right"><span class="eS4">CAN</span></td>
<td width="38" bgcolor="#999999" align="right"><span class="eS4">PRE</span></td>
<td width="57" bgcolor="#999999" align="right"><span class="eS4">IMP</span></td>

</tr>
<?php		  		
	$ss="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),CLI,DES,MAR,
		 KA,PR,IMP 
		 FROM vcotizaciones_det WHERE $FF ORDER BY ALM,COM,SER,NUM,FEC,CLI ";

	$X1="<td bgcolor=\"#FFFFFF\"><span class=\"Estilo5\">";
	$X1B="<td bgcolor=\"#FFFFFF\" align=\"right\"><span class=\"Estilo5\">";
	$X2="</span></td>";
	//$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
	$result = grs($ss);				
	while ($row = $result->fetch_row()){
		echo "<tr ondblclick=\"location.href='cotizaciones.php?Id=$row[0]&Pag=0';\">";
		echo $X1.$row[1].$X2;
		echo $X1.$row[2].$X2;
		echo "<td bgcolor=\"#FFFFFF\"><a target=\"_blank\" href=\"cotizaciones.php?Id=$row[0]\">'$row[3]</a></td>";
		echo $X1.$row[4].$X2;
		echo $X1.vbl($row[5],20).$X2;
		echo $X1.$row[6].$X2;
		echo $X1.$row[7].$X2;
		echo $X1B.$row[8].$X2;
		echo $X1B.NF2($row[9],1).$X2;
		echo $X1B.NF2($row[10],1).$X2;
		$ST=$ST+$row[10];
	}

?>		  
<tr>
<td colspan="9" bgcolor="#999999" style="text-align:right"><span class="eS4">TOTAL</span></td>
<td width="57" bgcolor="#999999" align="right"><span class="eS4"><?php echo NF2($ST,1); ?></span></td>
</tr>
      
</table>
      </div>
    </div>
    <div id="layer" style="position:absolute; left: 79px; top: 30px; width: 412px; height: 24px;">
      <div align="left" class="Estilo1">COTIZACIONES - BUSCAR
        <input name="TxtId" type="hidden" id="TxtId" value="<?php echo $StrId;?>"/>
        <input name="TxtPag" type="hidden" id="TxtPag" value="<?php echo $LStrPag; ?>" />
		<input name="TxtAc" type="hidden" id="TxtAc" value="" />
      - Detallado</div>
    </div>
    <div id="layer2" style="position:absolute; left: 306px; top: 131px; width: 63px; height: 25px;">
      <div align="left" class="Estilo2">        
          <input name="TxtNum" type="text" id="TxtNum" 
          style="width:60px" value="<?php echo $StrNum;?>"  
          onkeydown="return SoloTextoEx(event,'TxtDex');"
          tabindex="1" />
      </div>
    </div>
    <div id="LblTit" style="position:absolute; left: 20px; top: 25px; width: 64px;">
    <div align="left" class="Estilo1"><img src="img/buscar.png" width="57" height="60" /></div>
  </div>	
    <div id="layer4" style="position:absolute; left: 922px; top: 131px; width: 57px; height: 26px;">
      <div align="left" class="Estilo2">
        <input name="CmdB" type="button" id="CmdB" value="Filtrar" onclick="fFiltrar();" />
      </div>
    </div>
    <div id="layer7" style="position:absolute; left: 377px; top: 116px; width: 45px;">
      <div align="left" class="Estilo2">DESDE</div>
    </div>
    <div id="layer8" style="position:absolute; left: 377px; top: 131px; width: 73px; height: 25px;">
      <div align="left" class="Estilo2">
        <input name="TxtDex" type="text" id="TxtDex" 
        style="width:65px" value="<?php echo $StrDex;?>"  
        onkeydown="return SoloFec(this,event,'TxtHax');"
        tabindex="1" />
      </div>
    </div>
    <div id="layer9" style="position:absolute; left: 531px; top: 131px; width: 102px; height: 25px;">
      <div align="left" class="Estilo2">
<input name="TxtPro" type="text" id="TxtPro" 
style="width:100px" value="<?php echo $StrPro;?>"  
onkeydown="return SoloTextoEx(event,'CboSN');" 
tabindex="1" />
      </div>
    </div>
    <div id="layer10" style="position:absolute; left: 533px; top: 116px; width: 100px;">
      <div align="left" class="Estilo2">CLIENTE</div>
    </div>
    <div id="layer11" style="position:absolute; left: 456px; top: 116px; width: 60px;">
      <div align="left" class="Estilo2">HASTA</div>
    </div>
    <div id="layer12" style="position:absolute; left: 455px; top: 131px; width: 73px; height: 25px;">
      <div align="left" class="Estilo2">
        <input name="TxtHax" type="text" id="TxtHax" 
        style="width:65px" 
        value="<?php echo $StrHax;?>"  
        onkeydown="return SoloFec(this,event,'TxtPro');"
        tabindex="1" />
      </div>
    </div>
    <div id="layer29" style="position:absolute; left: 142px; top: 131px; width: 92px; height: 25px;">
      <div align="left" class="Estilo2">
        <select name="CboCom" id="CboCom" 
        style="width:100px" 
onkeydown="return SoloTextoEx(event,'TxtSer');">
          <option value="PROFORMA" selected="selected">PROFORMA</option>

        </select>
      </div>
    </div>
    <div id="layer13" style="position:absolute; left: 143px; top: 116px; width: 102px;">
      <div align="left" class="Estilo2">COMPROBANTE</div>
    </div>
    <div id="layer26" style="position:absolute; left: 24px; top: 131px; width: 109px; height: 25px;">
      <div align="left" class="Estilo2">
<select name="CboAlm" id="CboAlm" style="width:110px" 
onkeydown="return SoloTextoEx(event,'CboCom');">
<?php echo ListALM($StrAlm); ?>
</select>
      </div>
    </div>
    <div id="layer14" style="position:absolute; left: 26px; top: 116px; width: 102px;">
      <div align="left" class="Estilo2">ALMACEN</div>
    </div>

<div id="layer14" style="position:absolute; left: 24px; top: 560px; width: 166px;">
<div align="left" class="Estilo2">Doble Click sobre el registro para activar Actualizacion </div></div>

    <div id="layer15" style="position:absolute; left: 251px; top: 116px; width: 46px;">
      <div align="left" class="Estilo2">SERIE</div>
    </div>
    <div id="layer16" style="position:absolute; left: 251px; top: 131px; width: 50px; height: 25px;">
      <div align="left" class="Estilo2">
        <input name="TxtSer" type="text" id="TxtSer" 
          style="width:45px" value="<?php echo $StrSer;?>"  
          onkeydown="return SoloTextoEx(event,'TxtNum');"
          tabindex="1" />
      </div>
    </div>
    <div id="layer17" style="position:absolute; left: 642px; top: 116px; width: 75px;">
      <div align="left" class="Estilo2">ANULADO</div>
    </div>
    <div id="layer18" style="position:absolute; left: 640px; top: 131px; width: 59px; height: 25px;">
      <div align="left" class="Estilo2">
        <select name="CboSN" id="CboSN" 
style="width:60px" 
onkeydown="return SoloTextoEx(event,'TxtDes');">
          <?php
	if($StrSN=="" || $StrSN=="NO"){
		AD("NO",1);	AD("SI",0);
	}else{
		AD("NO",0);	AD("SI",1);
	}
?>
        </select>
      </div>
    </div>
    <div id="layer19" style="position:absolute; left: 711px; top: 117px; width: 74px;">
      <div align="left" class="Estilo2">DESCRIPCION</div>
    </div>
    <div id="layer20" style="position:absolute; left: 709px; top: 131px; width: 96px; height: 25px;">
      <div align="left" class="Estilo2">
        <input name="TxtDes" type="text" id="TxtDes" 
          style="width:95px" value="<?php echo $StrDes;?>"  
          onkeydown="return SoloTextoEx(event,'TxtMar');"
          tabindex="1" />
      </div>
    </div>
    <div id="layer21" style="position:absolute; left: 817px; top: 117px; width: 74px;">
      <div align="left" class="Estilo2">MARCA</div>
    </div>
    <div id="layer22" style="position:absolute; left: 815px; top: 131px; width: 102px; height: 25px;">
      <div align="left" class="Estilo2">
        <input name="TxtMar" type="text" id="TxtMar" 
          style="width:95px" value="<?php echo $StrMar;?>"  
          onkeydown="return SoloTextoEx(event,'CmdB');"
          tabindex="1" />
      </div>
    </div>
  
</center>	
</form>

<form action="ficheroExcel.php" 
method="post" target="_blank" 
id="FormularioExportacion" >

<div 
style="position:absolute; left: 344px; top: 50px; width: 45px; height: 15px;">  
<input name="" type="button" class="botonExcel" value="Exportar" />
<input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
</div>

</form>
<?php
if($StrCmd=="GEN_PDF_2"){
	$_PDF=GEN_PDF_2($FF,$StrAlm,$StrCom,$StrSer,$StrNum,$StrDex,$StrHax,$StrPro,$StrSN,$StrDes,$StrMar);
	$StrDES_2=$_PDF;
}

function GEN_PDF_2($FF,$StrAlm,$StrCom,$StrSer,$StrNum,$StrDex,$StrHax,$StrPro,$StrSN,$StrDes,$StrMar){
$_CxL=90;
$_S=10;	

$pdf = new PDF('P','mm',A4);
$pdf->AddPage();$pdf->SetFont('courier','',10);
$pdf->Cell(0,4,"",0,1);	
$pdf->Cell(0,4,"COTIZACIONES",0,1);	
$pdf->Cell(0,4,"",0,1);	
//------------------------------------------

if(strlen($StrAlm)>0){
$_ENC=vbl("ALMACEN".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrAlm.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrCom)>0){
$_ENC=vbl("COMPROBANTE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrCom.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrSer)>0){
$_ENC=vbl("SERIE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrSer.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrNum)>0){
$_ENC=vbl("NUMERO".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrNum.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrDex)>0){
$_ENC=vbl("DESDE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrDex.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrHax)>0){
$_ENC=vbl("HASTA".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrHax.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrPro)>0){
$_ENC=vbl("CLIENTE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrPro.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrDes)>0){
$_ENC=vbl("DESCRIPCION".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrDes.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrMar)>0){
$_ENC=vbl("MARCA".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrMar.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrSN)>0){
$_ENC=vbl("ANULADO S/N".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrSN.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}
$pdf->Cell(0,4,"",0,1);
$pdf->Cell(0,4,"",0,1);
//------------------------------------------
$P=0;
$P++;	$T[$P]=8;	$_ENC=vbl("ALMACEN".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=5;	$_ENC=$_ENC." ".vbl("COMPROBANTE".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=9;	$_ENC=$_ENC." ".vbl("NUMERO".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=8;	$_ENC=$_ENC." ".vbl("FECHA".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=12;	$_ENC=$_ENC." ".vbl("CLIENTE".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=14;	$_ENC=$_ENC." ".vbl("DESCIPCION".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=7;	$_ENC=$_ENC." ".vbl("MARCA".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=4;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P])."CAN",$T[$P]);
$P++;	$T[$P]=6;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P])."PRE",$T[$P]);
$P++;	$T[$P]=8;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P])."IMP",$T[$P]);
$pdf->Cell(0,4,$_ENC,0,1);
$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	
//
$s="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),CLI,
	DES,MAR,KA,FORMAT(PR - DT,1),IMP FROM 
	vcotizaciones_det WHERE $FF ORDER BY ALM,COM,SER,NUM,FEC,CLI ";
$result = grs($s);
while ($row = $result->fetch_row()){	
	$P=0;
	$P++;	$_ENC=vbl($row[1].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbl($row[2].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbl($row[3].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbl($row[4].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbl($row[5].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbl($row[6].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbl($row[7].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P]).$row[8],$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P]).NF2($row[9],1),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P]).NF2($row[10],1),$T[$P]);
	$pdf->Cell(0,4,$_ENC,0,1);
	$TOT=$TOT+$row[10];
}

$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	
$_TI=vbr(vbfill(" ",75)."TOTAL :",75);
$_TD=vbr(vbfill(" ",14).NF2($TOT,1),14);
$pdf->Cell(0,4,$_TI." ".$_TD,0,1);	

$_S=20;
$pdf->Cell(0,4,"",0,1);	
$pdf->Cell(0,4,"",0,1);	
//
$PDF_NAME="Cotizaciones.pdf";
$pdf->Output($PDF_NAME);
return $PDF_NAME;
}
?>

<?php
if($StrCmd=="GEN_PDF"){
	$_PDF=GEN_PDF($FF,$StrAlm,$StrCom,$StrSer,$StrNum,$StrDex,$StrHax,$StrPro,$StrSN,$StrDes,$StrMar);
	$StrDESCARGAR=$_PDF;
}

function GEN_PDF($FF,$StrAlm,$StrCom,$StrSer,$StrNum,$StrDex,$StrHax,$StrPro,$StrSN,$StrDes,$StrMar){
$_CxL=90;
$_S=10;	

$pdf = new PDF('P','mm',A4);
$pdf->AddPage();$pdf->SetFont('courier','',10);
$pdf->Cell(0,4,"",0,1);	
$pdf->Cell(0,4,"COTIZACIONES DETALLADO",0,1);	
$pdf->Cell(0,4,"",0,1);	
//------------------------------------------

if(strlen($StrAlm)>0){
$_ENC=vbl("ALMACEN".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrAlm.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrCom)>0){
$_ENC=vbl("COMPROBANTE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrCom.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrSer)>0){
$_ENC=vbl("SERIE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrSer.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrNum)>0){
$_ENC=vbl("NUMERO".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrNum.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrDex)>0){
$_ENC=vbl("DESDE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrDex.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrHax)>0){
$_ENC=vbl("HASTA".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrHax.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrPro)>0){
$_ENC=vbl("CLIENTE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrPro.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrDes)>0){
$_ENC=vbl("DESCRIPCION".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrDes.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrMar)>0){
$_ENC=vbl("MARCA".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrMar.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrSN)>0){
$_ENC=vbl("ANULADO S/N".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrSN.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

$pdf->Cell(0,4,"",0,1);
$pdf->Cell(0,4,"",0,1);	
//------------------------------------------	
$s="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),CLI,
	DES,MAR,KA,FORMAT(PR - DT,1),IMP FROM 
	vcotizaciones_det WHERE $FF GROUP BY ID ORDER BY ALM,COM,SER,NUM,FEC,CLI ";
$result = grs($s);
while ($row = $result->fetch_row()){
	$_ENC=vbl("COM: ".$row[2].vbfill(" ",15),15);
	$_ENC=$_ENC." ".vbl("NUM: ".$row[3].vbfill(" ",17),17);
	$_ENC=$_ENC." ".vbl("FEC: ".$row[4].vbfill(" ",15),15);
	$_ENC=$_ENC." ".vbl("CLI: ".$row[5].vbfill(" ",39),39);
	$pdf->Cell(0,4,$_ENC,0,1);	

	$_ENC=vbl("DESCRIPCION".vbfill(" ",33),33);
	$_ENC=$_ENC." ".vbl("MARCA".vbfill(" ",23),23);
	$_ENC=$_ENC." ".vbr(vbfill(" ",10)."CAN",10);
	$_ENC=$_ENC." ".vbr(vbfill(" ",10)."PRE",10);
	$_ENC=$_ENC." ".vbr(vbfill(" ",10)."IMP",10);
	$pdf->Cell(0,4,$_ENC,0,1);
	$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	

	$TOT=0;

	$sS="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),CLI,
		DES,MAR,KA,FORMAT(PR - DT,1),IMP FROM 
		vcotizaciones_det WHERE ID=$row[0] ORDER BY ALM,COM,SER,NUM,FEC,CLI ";
	$resultS = grs($sS);
	while ($rowS = $resultS->fetch_row()){	
	$_ENC=vbl($rowS[6].vbfill(" ",33),33);
	$_ENC=$_ENC." ".vbl($rowS[7].vbfill(" ",23),23);
	$_ENC=$_ENC." ".vbr(vbfill(" ",10).$rowS[8],10);
	$_ENC=$_ENC." ".vbr(vbfill(" ",10).NF2($rowS[9],1),10);
	$_ENC=$_ENC." ".vbr(vbfill(" ",10).NF2($rowS[10],1),10);
	$pdf->Cell(0,4,$_ENC,0,1);	
	$TOT=$TOT+$rowS[10];
	}
	$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);
	$_TI=vbr(vbfill(" ",75)."TOTAL :",75);
	$_TD=vbr(vbfill(" ",14).NF2($TOT,1),14);
	$pdf->Cell(0,4,$_TI." ".$_TD,0,1);
	$pdf->Cell(0,4,"",0,1);		
	$pdf->Cell(0,4,"",0,1);	
}
$_S=20;
$pdf->Cell(0,4,"",0,1);	
$pdf->Cell(0,4,"",0,1);	
//
$PDF_NAME="Cotizaciones_Detallado.pdf";
$pdf->Output($PDF_NAME);
return $PDF_NAME;
}
?>

<?php
if(strlen($StrDES_2)>0){
echo "<div id=\"layer51\" 
	  style=\"position:absolute; left: 135px; top: 82px; 
	  width: 100px; background-color: #FFCC00; layer-background-color: #FFCC00; 
	  border: 1px none #000000; height: 17px;\">";
echo "<div align=\"center\" class=\"Estilo2\"> ";
echo " <a href=\"$StrDES_2\" download>Descargar PDF</a> ";
echo "</div>";
echo "</div>";
}
?>

<?php
if(strlen($StrDESCARGAR)>0){
echo "<div id=\"layer51\" 
	  style=\"position:absolute; left: 238px; top: 82px; 
	  width: 100px; background-color: #FFCC00; layer-background-color: #FFCC00; 
	  border: 1px none #000000; height: 17px;\">";
echo "<div align=\"center\" class=\"Estilo2\"> ";
echo " <a href=\"$StrDESCARGAR\" download>Descargar PDF</a> ";
echo "</div>";
echo "</div>";
}
?>


</div>
</body>
</html>
