<?php
//include "clase.conexion.php";
class clsPreciosReporte extends clsConexion{
	public $varTitulo 	= "REPORTE LISTADO DE PRECIOS";
	function FormuBusqueda() {
		$sqllis = "call spQuery_Lista_Precios2(1, NULL, NULL, NULL, NULL);";
		$Array  = array("T" => "TODOS LOS PRODUCTOS", "S" => "SOLO PRODUCTOS CON STOCK");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"500", "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"=>"tip", "name"=>"tip", "valor"=>"T")
									  ),
						"conte"=>array(array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"pcod", "name"=>"pcod", "valor"=>$_POST["pcod"], 
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_proveedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_proveedor('pcod', 'pnom')"),
																			   array("tipo"=>"text", "id"=>"pnom", "name"=>"pnom", "valor"=>$_POST["pnom"], 
																					 "ancho"=>"300", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),
									   array("titulo"=>"Lista P. :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"lista_doble", "filas"=>8, "ancho"=>"180", "sql"=>$sqllis,
											 				"id1"=>"lis", "name1"=>"lis", "id2"=>"lcod", "name2"=>"lcod",
															"dclick1"=>"mover_lista('right','lis','lcod')", "dclick2"=>"mover_lista('left','lis','lcod')"															
															)
											),
									   /*
									   array("titulo"=>"Tipo Report :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										     "campo"=>array("tipo"=>"select_simple", "id"=>"tip", "name"=>"tip", "valor"=>$varTipo, "ancho"=>"100",
														    "combo"=>array("sql"=>$Array, "sincod"=>"SI", "ancho"=>"220"))),	
									   */
									   ),
						"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($varPro = NULL, $varLis = NULL, $varTip = NULL)  {	
		$varPro = (isset($varPro) && $varPro<>"")?$varPro:"NULL";
		$varLis = ($varLis<>"")?"\"(".$varLis.")\"":"NULL";
		$varTip = (isset($varTip) && $varTip<>"")?"'".$varTip."'":"NULL";		
		$sql = "call spQuery_Report_Lista_Precios($varPro, $varLis);";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql,	"pages"=>50,
						"conte"=>array(array("tamano"=>20, "titulo"=>"CPRO", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"PROVEEDOR", "fijo"=>"SI"),
									   array("tamano"=>20, "titulo"=>"CTIP", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"TIPO", "oculto"=>"SI"),
									   array("tamano"=>20, "titulo"=>"CFAM", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"FAMILIA", "oculto"=>"SI"),
									   array("tamano"=>20, "titulo"=>"CSUB", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"SUB FAMILIA", "oculto"=>"SI"),
									   array("tamano"=>20, "titulo"=>"CART", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"ARTICULO", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("tamano"=>80, "titulo"=>"UM", "alinear"=>"center")
									   )
						);
		
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$varNumCab = $this->NumField($rs);
		for($i=11;$i<=$varNumCab-1;$i++) {
			$varTabla["conte"][$i]["alinear"]="right";
			$varTabla["conte"][$i]["tamano"]="60";
			$varTabla["conte"][$i]["decimal"]="5";
			}
		
		return $this->SetGridTabla($varTabla);
		}
	function Imprimir($varPro = NULL, $varLis = NULL, $varTip = NULL)  {		
		$varPro = (isset($varPro) && $varPro<>"")?$varPro:"NULL";
		$varLis = ($varLis<>"")?"\"(".$varLis.")\"":"NULL";
		$varTip = (isset($varTip) && $varTip<>"")?"'".$varTip."'":"NULL";		
		$sql = "call spQuery_Report_Lista_Precios($varPro, $varLis);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$varNumCol = $this->NumField($rs);
		$varNumCom = 
		$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="font-size:11px;width:50%;vertical-align:middle;text-align:left;"><b>'.Config("SYSEMP").'</b></td>';
			$html.='<td style="font-size:11px;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></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="left">CPRO</td>';
			$html.='<td width="150" class="left">PRODUCTO</td>';
			$html.='<td width="50">U.M.</td>';
			for($i=11;$i<=$varNumCol-1;$i++) {
					$html.='<td width="25" class="right">'.$this->FieldName($rs,$i).'</td>';
				}
			
			$html.='</tr>';
			$html.='</thead>';
			
			$varPro_Ant = $varPro_Act = "";
			$varSub_Ant = $varSub_Act = "";
			while($fila = $this->FetchArray($rs))	{
				$varPro_Act = $fila["CPRO"];
				$varSub_Act = $fila["CSUB"];
				$varTotal1 = $varTotal1 + $fila["CANTIDAD"];
				$varTotal2 = $varTotal2 + $fila["MONTO"];
				$varNumDoc++;
				if($varPro_Act <> $varPro_Ant) {
					$varPro_Ant = $fila["CPRO"];
					$varSub_Ant = $fila["CSUB"];
					$html.='<tr class="head">';
					$html.='<td class="center"><b>'.$fila["CPRO"].'</b></td>';
					$html.='<td class="left" colspan="'.($varNumCol-8).'"><b>'.$fila["PROVEEDOR"].'</b></td>';
					$html.='</tr>';
					$html.='<tr class="head">';
					$html.='<td class="center"><b></b></td>';
					$html.='<td class="center"><b>'.$fila["CSUB"].'</b></td>';
					$html.='<td class="left" colspan="'.($varNumCol-9).'"><b>'.$fila["TIPO"].' - '.$fila["FAMILIA"].' - '.$fila["SUB_FAMILIA"].'</b></td>';
					$html.='</tr>';
					}
				if($varSub_Act <> $varSub_Ant) {
					$varSub_Ant = $fila["CSUB"];					
					$html.='<tr class="head">';
					$html.='<td class="center"><b></b></td>';
					$html.='<td class="center"><b>'.$fila["CSUB"].'</b></td>';
					$html.='<td class="left" colspan="'.($varNumCol-9).'"><b>'.$fila["TIPO"].' - '.$fila["FAMILIA"].' - '.$fila["SUB_FAMILIA"].'</b></td>';
					$html.='</tr>';
					}
				$html.='<tr class="list_row">
						<td class="center">&nbsp;</td>
						<td class="left">'.$fila["CART"].'</td>
						<td NOWRAP>'.$fila["ARTICULO"].'</td>
						<td NOWRAP>'.$fila["UM"].'</td>';
						for($i=11;$i<=$varNumCol-1;$i++) {
							$html.='<td class="right">'.number_format($fila[$i],"5",".",",").'</td>';
						}
				
				$html.='</tr>';
				}
			$html.='<tr class="head">';
			$html.='<td colspan="2" class="left"><strong>Totales :</strong></td>';
			$html.='<td colspan="'.($varNumCol-9).'" class="left">'.number_format($varNumDoc,"0",".",",").' Productos</td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
				
		$html.='</table>		
				</body>
				</html>';
		return $html;
		}
	}
?>