<?php
//include "clase.conexion.php";
class clsPackingLiquidacion extends clsConexion{
	public $varTitulo 	= "PACKING DE LIQUIDACION";
	function FormuBusqueda() {
		$sqlven = "call spQuery_Lista_Vendedor('','','');";
		$sqlrut = "call spQuery_Lista_Ruta('','%');";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"650", "clase"=>"Formtitulo", "titulo"=>$this->varTitulo,
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo)
									  ),
						"conte"=>array(array("titulo"=>"Fecha Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>100,
											 "campo"=>array("tipo"=>"fecha", "id"=>"eini", "name"=>"eini", "alinear"=>"center",
											 				"valor"=>$varFINI) 
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"lista_doble", "filas"=>8, "ancho"=>"250", "sql"=>$sqlven,
											 				"id1"=>"ven", "name1"=>"ven", "id2"=>"vcod", "name2"=>"vcod",
															"dclick1"=>"mover_lista('right','ven','vcod')", "dclick2"=>"mover_lista('left','ven','vcod')"															
															)
											),									   
									   array("titulo"=>"Ruta :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"lista_doble", "filas"=>8, "ancho"=>"250", "sql"=>$sqlrut,
											 				"id1"=>"rut", "name1"=>"rut", "id2"=>"rcod", "name2"=>"rcod",
															"dclick1"=>"mover_lista('right','rut','rcod')", "dclick2"=>"mover_lista('left','rut','rcod')"															
															)
											),
									   ),
						"boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"100", "texto"=>"Buscar",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()"),
									 array("tipo"=>"button", "id"=>"bexp", "name"=>"bexp", "ancho"=>"100", "texto"=>"Exportar",
									 	   "clase"=>"boton_exportar", "click"=>"javascript:xExportarJS()"),								
									 array("tipo"=>"button", "id"=>"bimp", "name"=>"bimp", "ancho"=>"100", "texto"=>"Imprimir", 
										   "clase"=>"boton_imprimir", "click"=>"javascript:xImprimirJS('', 'NEW')"),
									 )
						);
		return $this->setTablaForm($varTabla);
		}
 	function GridDatos($varDia = NULL, 
					   $varVen = NULL, 
					   $varRut = NULL
					   )  {
						  
		$varDia = (isset($varDia) && $varDia<>"")?"'".FechaMySql($varDia)."'":"NULL";
		$varVen  = ($varVen<>"")?"\"(".$varVen.")\"":"NULL";
		$varRut  = ($varRut<>"")?"\"(".str_replace("\\","",$varRut).")\"":"NULL";
		
		$sql = "call spQuery_Packing_Documentos_Liquidados($varDia,$varVen,$varRut)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1500", "sql_cab"=>$sql,	"pages"=>100,
						"conte"=>array(array("titulo"=>"CVEN",    	"ancho"=>"20",  "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"VENDEDOR", 	"ancho"=>"200", "clase"  =>"sortable", "fijo"=>"SI"),
									   array("titulo"=>"CCLI",      "ancho"=>"20" , "alinear"=>"center", "clase"=>"sortable-numeric"), 
									   array("titulo"=>"CLIENTE",  	"ancho"=>"200", "clase"  =>"sortable", "funcion"=>array("contar"), "fijo"=>"SI"),
									   array("titulo"=>"DIRECCION",	"ancho"=>"250", "fijo"=>"SI"), 
									   array("titulo"=>"CRUT",    	"ancho"=>"20",  "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"RUTA",  	"ancho"=>"100", "fijo"=>"SI"),
									   array("titulo"=>"CTIP",    	"ancho"=>"20",  "alinear"=>"center"),
									   array("titulo"=>"NDOC",    	"ancho"=>"20",  "alinear"=>"center"),
									   array("titulo"=>"NPED",    	"ancho"=>"20",  "alinear"=>"center"),
									   array("titulo"=>"NVEN",    	"ancho"=>"20",  "alinear"=>"center"),
									   array("titulo"=>"CCON",    	"ancho"=>"20",  "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"CONDICION",	"ancho"=>"60", "fijo"=>"SI"),
									   array("titulo"=>"CMOV",    	"ancho"=>"20",  "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"MOTIVO",	"ancho"=>"60", "clase"  =>"sortable"),
									   array("titulo"=>"TOTAL GRAL.", "ancho"=>"50",  "alinear"=>"right", "clase"=>"sortable-numeric", "autosuma"=>"SI"),
									   array("titulo"=>"CONTADO", "ancho"=>"50",  "alinear"=>"right", "clase"=>"sortable-numeric", "autosuma"=>"SI"),
									   array("titulo"=>"CREDITO", "ancho"=>"50",  "alinear"=>"right", "clase"=>"sortable-numeric", "autosuma"=>"SI"),
									   array("titulo"=>"PARCIAL", "ancho"=>"50",  "alinear"=>"right", "clase"=>"sortable-numeric", "autosuma"=>"SI"),
									   array("titulo"=>"RECHAZO", "ancho"=>"50",  "alinear"=>"right", "clase"=>"sortable-numeric", "autosuma"=>"SI")
									   )
						);
		return $this->SetGridTabla($varTabla);
		}
	function Imprimir($varDia = NULL, 
					  $varVen = NULL, 
					  $varRut = NULL
					  )  {
						  
		$varFech = (isset($varDia) && $varDia<>"")?"'".FechaMySql($varDia)."'":"NULL";
		$varVend = ($varVen<>"")?"\"(".$varVen.")\"":"NULL";
		$varRuta = ($varRut<>"")?"\"(".str_replace("\\","",$varRut).")\"":"NULL";
		
		$sql = "call spQuery_Packing_Documentos_Liquidados($varFech, $varVend, $varRuta)";
		$html.='<table style="width: 95%; padding: 0; margin-top:10px; margin-bottom:10px; border-collapse:collapse;" align="center">';
		$html.='<thead>';
		$html.='<tr>';
		$html.='<td>';
			$html.='<table style="width: 100%;">';
			$html.='<tr>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"><b>'.Config("SYSEMP").'</b></td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.$this->varTitulo.'</b></td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"><b>Fecha Emision: '.$varDia.'</b></td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.MostrarFechaActual().'</b></td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
		$html.='</thead>';	
		$html.='<tr>';
		$html.='<td>';
			$html.='<table style="width: 100%;padding: 0; margin-top:0px; margin-bottom:0px; border-collapse:collapse;">';
			$html.='<thead>';
			$html.='<tr class="head">';
			$html.='<td width="2" class="center">&nbsp;</td>';
			$html.='<td width="2" class="center">CCLI</td>';
			$html.='<td width="150">CLIENTE</td>';
			$html.='<td width="150">DIRECCION</td>';
			$html.='<td width="50">DOC.VENTA</td>';
			$html.='<td width="30">CONDICION</td>';
			$html.='<td width="25" class="right">TOTAL</td>';
			$html.='<td width="25" class="right">CONTADO</td>';
			$html.='<td width="25" class="right">CREDITO</td>';
			$html.='<td width="25" class="right">PARCIAL</td>';
			$html.='<td width="25" class="right">ANULAD.</td>';
			$html.='<td width="50">MOTIVO RECHA.</td>';
			$html.='</tr>';
			$html.='</thead>';
			
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$varTotal = 0;
			$varConta = 0;
			$varCredi = 0;
			$varParci = 0;
			$varRecha = 0;
			$varNumDoc = 0;
			while($fila = $this->FetchArray($rs))	{
				$varTotal = $varTotal + $fila["TOTAL_GRAL"];
				$varConta = $varConta + $fila["CONTADO"];
				$varCredi = $varCredi + $fila["CREDITO"];
				$varParci = $varParci + $fila["PARCIAL"];
				$varRecha = $varRecha + $fila["RECHAZO"];
				$varVenAct = $fila["CVEN"];
				$varRutAct = $fila["CRUT"];
				$varNumDoc++;
				if($varVenAct <> $varVenAnt) {
					$varVenAnt = $fila["CVEN"];
					$varRutAnt = $fila["CRUT"];
					$html.='<tr class="list_row">';
					$html.='<td class="right"><b>'.$fila["CVEN"].'</b></td>';
					$html.='<td colspan="11"><b>'.$fila["VENDEDOR"].'</b></td>';
					$html.='</tr>';
					$html.='<tr class="list_row">';
					$html.='<td></td>';
					$html.='<td class="center"><b>'.$fila["CRUT"].'</b></td>';
					$html.='<td colspan="9"><b>'.$fila["RUTA"].'</b></td>';
					$html.='</tr>';
					}
				if($varRutAct <> $varRutAnt) {
					$varRutAnt = $fila["CRUT"];
					$html.='<tr class="list_row">';
					$html.='<td></td>';
					$html.='<td class="center"><b>'.$fila["CRUT"].'</b></td>';
					$html.='<td colspan="10"><b>'.$fila["RUTA"].'</b></td>';
					$html.='</tr>';
					}
				$html.='<tr class="list_row">
						<td class="center">&nbsp;</td>
						<td class="center">'.$fila["CCLI"].'</td>
						<td NOWRAP>'.$fila["CLIENTE"].'</td>
						<td NOWRAP>'.substr($fila["DIRECCION"],0,35).'</td>
						<td NOWRAP>'.$fila["CTIP"].' '.$fila["NDOC"].'</td>
						<td NOWRAP>'.$fila["CONDICION"].'</td>
						<td class="right">'.number_format($fila["TOTAL_GRAL"],"2",".",",").'</td>';
				$html.='<td class="right">&nbsp;';
				if(!is_null($fila["CONTADO"]) && $fila["CONTADO"]>0)
						$html.= number_format($fila["CONTADO"],"2",".",",");
				$html.='</td>';
				$html.='<td class="right">&nbsp;';
				if(!is_null($fila["CREDITO"]) && $fila["CREDITO"]>0)
						$html.= number_format($fila["CREDITO"],"2",".",",");
				$html.='</td>';
				$html.='<td class="right">&nbsp;';
				if(!is_null($fila["PARCIAL"]) && $fila["PARCIAL"]>0)
						$html.= number_format($fila["PARCIAL"],"2",".",",");
				$html.='</td>';
				$html.='<td class="right">&nbsp;';
				if(!is_null($fila["RECHAZO"]) && $fila["RECHAZO"]>0)
						$html.= number_format($fila["RECHAZO"],"2",".",",");
				$html.='</td>';
				$html.='<td>&nbsp;'.$fila["MOTIVO"].'</td>';
				$html.='</tr>';
				}
			$html.='<tr class="head">';
			$html.='<td colspan="4" class="left"><strong>Totales :</strong></td>';
			$html.='<td class="left" colspan="2">'.number_format($varNumDoc,"0",".",",").' Documentos</td>';
			$html.='<td class="right">'.number_format($varTotal,"2",".",",").'</td>';
			$html.='<td class="right">'.number_format($varConta,"2",".",",").'</td>';
			$html.='<td class="right">'.number_format($varCredi,"2",".",",").'</td>';
			$html.='<td class="right">'.number_format($varParci,"2",".",",").'</td>';
			$html.='<td class="right">'.number_format($varRecha,"2",".",",").'</td>';
			$html.='<td class="right"></td>';
			$html.='</tr>';
	
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';				
		$html.='</table>';	
		return $html;
		}
	}
?>