<?php
//include "clase.conexion.php";
class clsAsignacionReporteDescuentos extends clsConexion{
	public $varTitulo = "REPORTE DE FALTANTES Y SOBRANTES DE MERCADERIA";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"430", "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),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion),
									   array("tipo"=>"oculto", "id"=>"dni", "name"=>"dni", "valor"=>"dni"),
									   array("tipo"=>"oculto", "id"=>"cos", "name"=>"cos", "valor"=>"cos")
									  ),
						"conte"=>array(array("titulo"=>"Repartidor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod", "name"=>"vcod", 
																					 "valor"=>NULL, "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_repartidor(this.value, 'vcod', 'vnom')", 
																					 "dclick"=>"fn_cargar_listado_repartidor('vcod','vnom','dni','cos')"),
																			   array("tipo"=>"text", "id"=>"vnom", "name"=>"vnom", "valor"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),	
									   
									 array("titulo"=>"F.Inicial :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"fini", "name"=>"fini", "alinear"=>"center"))
														 	)
											 ),
									   array("titulo"=>"F.Final :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center"))
														 	)
											 ),					   
								   ),
					  "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()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   )  {
						  
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$varVen = (isset($varForm["vcod"]) && $varForm["vcod"]<>'')?$varForm["vcod"]:"NULL";
		$varIni = (isset($varForm["fini"]) && $varForm["fini"]<>'')?"'".FechaMySql($varForm["fini"])."'":"NULL";
		$varFin = (isset($varForm["ffin"]) && $varForm["ffin"]<>'')?"'".FechaMySql($varForm["ffin"])."'":"NULL";

		$sql = "call spQuery_LiqReparto_Reporte_FaltaSobra($varIni, $varFin, $varVen, $varFie, $varOrd);";
		
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1000", "sql_cab"=>$sql,	"pages"=>20,
					    "conte"=>array(array("titulo"=>"TIPO",  "ancho"=>"30", "alinear"=>"center"),
									   array("titulo"=>"FREP",  "ancho"=>"30", "alinear"=>"center"),
									   array("titulo"=>"NASI", "ancho"=>"50"),
									   array("titulo"=>"CCON", "ancho"=>"30", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"CONDUCTOR","ancho"=>"200", "fijo"=>"SI"),
									   array("titulo"=>"CVEH",  "ancho"=>"30", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"PLACA", "ancho"=>"50", "alinear"=>"center"),
									   array("titulo"=>"CTRA", "ancho"=>"30", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"TRABAJADOR","ancho"=>"200", "fijo"=>"SI"),
									   array("titulo"=>"FEMI",  "ancho"=>"30", "alinear"=>"center"),
									   array("titulo"=>"DOCUMENTO", "ancho"=>"50", "alinear"=>"center"),
									   array("titulo"=>"CPRO", "ancho"=>"30", "alinear"=>"center"),
									   array("titulo"=>"PRODUCTO","ancho"=>"200", "fijo"=>"SI"),
									   array("titulo"=>"UM", "ancho"=>"30", "alinear"=>"center"),
									   array("titulo"=>"CANT", "ancho"=>"50", "alinear"=>"right", "decimal"=>"2"),
									   array("titulo"=>"MONTO", "ancho"=>"50", "alinear"=>"right", "decimal"=>"2", "funcion"=>array("autosuma")),
									   array("titulo"=>"FCREADO", "ancho"=>"100", "fijo"=>"SI"),
									   array("titulo"=>"UCREADO", "ancho"=>"100", "alinear"=>"center", "fijo"=>"SI")
									   )
							);
		return $this->SetGridTabla2($varTabla);
		}
	function Imprimir($varVen = NULL, $varIni = NULL, $varFin = NULL)  {
		if($varIni=="" && $varFin=="")
			$varCadFec = "";
		elseif($varIni=="")
			$varCadFec = "Desde ".$varFin." Hacia Atras";
		elseif($varFin=="")
			$varCadFec = "Desde ".$varIni." Hacia Adelante";
		else
			$varCadFec = "Desde ".$varIni." Hasta ".$varFin;
		
		$varVen = (isset($varVen) && $varVen<>'')?$varVen:"NULL";
		$varIni = (isset($varIni) && $varIni<>'')?"'".FechaMySql($varIni)."'":"NULL";
		$varFin = (isset($varFin) && $varFin<>'')?"'".FechaMySql($varFin)."'":"NULL";
		$sqlven = "call spQuery_LiqReparto_Reporte_FaltaSobra_Cab($varIni, $varFin, $varVen);";
		$this->AbrirConexion();
		$rsven = $this->Query($sqlven);
		$this->CerrarConexion();
		$html = "";
		while ($filaven = $this->FetchArray($rsven)) {
			$html.='<div id="container">';
			$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.='</table>';
			$html.='</td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td>';
				$html.='<table style="width: 100%;">';
				$html.='<tr>';
				$html.='<td style="width: 5%; vertical-align: middle; text-align:left;" nowrap="nowrap"><b>Vendedor</b></td>';
				$html.='<td style="width: 1%; vertical-align: middle; text-align:left;"><b>:</b></td>';
				$html.='<td style="width: 44%; vertical-align: middle; text-align:left;">';
				$html.='<b>'.$filaven[0].' - '.$filaven[1].'</b></td>';
				$html.='<td style="width: 50%; vertical-align: middle; text-align:right;">'.MostrarFechaActual().'</td>';
				$html.='</tr>';
				$html.='<tr>';
				$html.='<td style="vertical-align: middle; text-align:left;" nowrap="nowrap"><b>Fechas</b></td>';
				$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
				$html.='<td style="vertical-align: middle; text-align:left;">'.$varCadFec.'</td>';
				$html.='<td style="vertical-align: middle; text-align:right;"></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.='<tr class="head">';
			$html.='<td width="5"></td>';
			$html.='<td width="2" class="center">FREP</td>';
			$html.='<td width="2" class="center">N&deg;ASI</td>';
			$html.='<td width="2" class="center">PLACA</td>';
			$html.='<td width="2">FEMI</td>';
			$html.='<td width="50">DOCUMENTO</td>';
			$html.='<td width="2" class="center">CPRO</td>';
			$html.='<td width="150">PRODUCTO</td>';
			$html.='<td width="30">U.M.</td>';
			$html.='<td width="30">CANT</td>';
			$html.='<td width="25" class="right" nowrap>MONTO</td>';
			$html.='<td width="30">USUARIO</td>';
			$html.='</tr>';
			$sql = "call spQuery_LiqReparto_Reporte_FaltaSobra($varIni, $varFin, $filaven[0], NULL, NULL);";
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$varTotal = 0;
			$varNumDo = 0;
			$varSub = 0;
			$varMot_Act = "";
			$varMot_Ant = "";
			while($fila = $this->FetchArray($rs))	{
				$varMot_Act = $fila["TIPO"];
				$varTotal = $varTotal + $fila["TOTAL"];
				$varNumDo++;
				if($varMot_Act <> $varMot_Ant) {
					if($varMot_Ant<>"") {
						$html.='<tr class="list_row">';
						$html.='<td NOWRAP colspan="10" class="right"><b>SUB TOTAL '.$varMot_Ant.' DE MERCADERIA'.'</b></td>';
						$html.='<td class="right" NOWRAP><b>'.number_format($varSub,"2",".",",").'</b></td>';
						$html.='<td class="right"></td>';
						$html.='</tr>';
						$varSub = 0;
						}
					$html.='<tr class="list_row">';
					$html.='<td NOWRAP colspan="11"><b>'.$fila["TIPO"].' DE MERCADERIA</b></td>';
					$html.='<td class="right"></td>';
					$html.='</tr>';
					$varMot_Ant = $varMot_Act;
					}
				$varSub = $varSub + $fila["TOTAL"];
				$html.='<tr class="list_row">';
				$html.='<td NOWRAP></td>';
				$html.='<td NOWRAP>'.$fila["FECHA"].'</td>';
				$html.='<td NOWRAP>'.$fila["CASI"].'</td>';
				$html.='<td NOWRAP>'.$fila["PLACA"].'</td>';
				$html.='<td NOWRAP>'.$fila["FEMI"].'</td>';
				$html.='<td NOWRAP>'.$fila["DOCUMENTO"].'</td>';
				$html.='<td NOWRAP>'.$fila["CPRO"].'</td>';
				$html.='<td NOWRAP>'.$fila["PRODUCTO"].'</td>';
				$html.='<td NOWRAP>'.$fila["UM"].'</td>';
				$html.='<td class="right">'.number_format($fila["CANT"],"0",".",",").'</td>';
				$html.='<td class="right">'.number_format($fila["TOTAL"],"2",".",",").'</td>';
				$html.='<td NOWRAP>'.$fila["USER_CREADO"].'</td>';
				$html.='</tr>';
				}
			$html.='<tr class="list_row">';
			$html.='<td NOWRAP colspan="10" class="right"><b>SUB TOTAL '.$varMot_Act.' DE MERCADERIA</b></td>';
			$html.='<td class="right" NOWRAP><b>'.number_format($varSub,"2",".",",").'</b></td>';
			$html.='<td class="right"></td>';
			$html.='</tr>';
			$html.='<tr class="head">';
			$html.='<td class="right"></td>';
			$html.='<td colspan="2" class="left"><strong>Totales :</strong></td>';
			$html.='<td colspan="3" class="left">'.number_format($varNumDo,"0",".",",").' Registros</td>';
			$html.='<td class="right"></td>';
			$html.='<td class="right"></td>';
			$html.='<td class="right"></td>';
			$html.='<td class="right"></td>';
			$html.='<td class="right">'.number_format($varTotal,"2",".",",").'</td>';
			$html.='<td class="right"></td>';
			$html.='</tr>';	
			$html.='</table>';
			$html.='</td>';
			$html.='</tr>';
			$html.='</table>';
			$html.='</div>';
			}
		return $html;
		}
	}
	
?>