<?php
//include "clase.conexion.php";
class clsPreciosReporte extends clsConexion{
	public $varTitulo 	= "REPORTE LISTADO DE PRECIOS";
	private $sqltip	= array("T"=>"TODOS LOS PRODUCTOS", "S"=>"SOLO PRODUCTOS CON STOCK");
	function FormuBusqueda() {
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '', '');";
		$sqllin = "call spQuery_Combo_Producto_Tipo();";
		$sqlfam = "call spQuery_Combo_Producto_Familia('$Fila[id_tipo]');";
		$sqlsub = "call spQuery_Combo_Producto_Sub_Familia('$Fila[id_familia]');";
		
		$varXajaxEmp = "xajax_liscomboListaPrecios(this.value, 'divLis', 'lis', 'lcod', 180)";
		$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)
									  ),
						"conte"=>array(array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"varios",
														   "contenido"=>array(array("tipo"=>"select", "id"=>"emp", "name"=>"emp", "ancho"=>"300",
														   							"sql"=>$sqlemp, "titulo"=>"--[[SELECCIONAR]]--",
																					"reload"=>$varXajaxEmp)
																			  )
														   )
										   ),
									   array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"varios",
														   "contenido"=>array(array("tipo"=>"text", "id"=>"pcod", "name"=>"pcod", 
																					"ancho"=>"45",  "alinear"=>"center", 
																					"blur"=>"xajax_seleccionar_proveedor('PRO',this.value)", 
																					"dclick"=>"fn_cargar_listado_proveedor('pcod', 'pnom','PR')"),
																			  array("tipo"=>"text", "id"=>"pnom", "name"=>"pnom",
																					"ancho"=>"251", "clase"=>"inputDisable", "locked"=>"SI")
																			  )
														   )
										   ),
									  array("titulo"=>"Lista P. :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divLis",
											 "campo"=>array("tipo"=>"lista_doble", "filas"=>8, "ancho"=>"180", "sql"=>NULL,
											 				"id1"=>"lis", "name1"=>"lis", "id2"=>"lcod", "name2"=>"lcod",
															"dclick1"=>"mover_lista('right','lis','lcod')", 
															"dclick2"=>"mover_lista('left','lis','lcod')"															
															)
											),
									  array("titulo"=>"Opcion :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"varios",
														   "contenido"=>array(array("tipo"=>"select_simple", "id"=>"opt", "name"=>"opt", 
														   							"combo"=>array("sql"=>$this->sqltip, "ancho"=>"300"))
																			  )
														   )
										   ),
									  array("titulo"=>"Linea :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"varios",
														   "contenido"=>array(array("tipo"=>"select", "id"=>"tip", "name"=>"tip", 
														   							"sql"=>$sqllin, "ancho"=>"300", 
																					"titulo"=>"--[[SELECCIONAR]]--",
																					"reload"=>"xajax_comboFamilia(this.value)")
																			  )
														   )
										   ),
									  array("titulo"=>"Familia :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"varios",
														   "contenido"=>array(array("tipo"=>"select", "id"=>"fam", "name"=>"fam", "div"=>"divFam",
																					"sql"=>$sqlfam, "ancho"=>"300",  
																					"titulo"=>"--[[SELECCIONAR]]--", "sincod"=>"SI", 
																					"reload"=>"xajax_comboSubFamilia(this.value)")
																			  )
														   )
										   ),
									  array("titulo"=>"Sub Familia :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											"campo"=>array("tipo"=>"varios",
														   "contenido"=>array(array("tipo"=>"select", "id"=>"sub", "name"=>"sub", "div"=>"divSub",
																					"sql"=>$sqlsub, "ancho"=>"300",  
																					"titulo"=>"--[[SELECCIONAR]]--", "sincod"=>"SI")
																			  )
														   )
										   )
									   ),
						"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($varEmp=NULL, $varPro=NULL, $varLis=NULL, $varOpt=NULL, $varTip=NULL, $varFam=NULL, $varSub=NULL)  {
		$varEmp = ($varEmp<>"" && $varEmp<>"Ninguno")?$varEmp:"NULL";
		$varPro = ($varPro<>"")?$varPro:"NULL";
		$varLis = ($varLis<>"")?"\"(".$varLis.")\"":"NULL";
		$varOpt = ($varOpt<>"Ninguno")?"'".$varOpt."'":"NULL";
		$varTip = ($varTip<>"Ninguno")?"'".$varTip."'":"NULL";
		$varFam = ($varFam<>"Ninguno")?"'".$varFam."'":"NULL";
		$varSub = ($varSub<>"Ninguno")?"'".$varSub."'":"NULL";		
		$sql = "call spQuery_Report_Lista_Precios($varEmp, $varPro, $varLis, $varOpt, $varTip, $varFam, $varSub);";
		$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", "fijo"=>"SI"),
									   array("tamano"=>20, "titulo"=>"CFAM", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"FAMILIA", "fijo"=>"SI"),
									   array("tamano"=>20, "titulo"=>"CSUB", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"SUB FAMILIA", "fijo"=>"SI"),
									   array("tamano"=>20, "titulo"=>"CART", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"ARTICULO", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("tamano"=>60, "titulo"=>"U.M.", "alinear"=>"center"),
									   array("tamano"=>60, "alinear"=>"right"),
									   array("tamano"=>60, "alinear"=>"right"),
									   array("tamano"=>60, "alinear"=>"right"),
									   array("tamano"=>60, "alinear"=>"right"),
									   array("tamano"=>60, "alinear"=>"right")
									   )
						);
		
		$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($varEmp = NULL, $varPro = NULL, $varLis = NULL, $varOpt=NULL, $varTip = NULL, $varFam = NULL, $varSub = NULL)  {		
		$sql_emp = "select concat(id_empresa, '. ', nombre) as empresa from _sv_empresa where id_empresa=$varEmp;";
		$fila_emp = $this->GetFilas($sql_emp);
		$varCadEmp = $fila_emp[0];
		
		if($varPro<>"") {
			$sql_pro = "select concat(id_proveedor, ' - ', nombre) as proveedor from _sv_proveedor where id_proveedor=$varPro;";
			$fila_pro = $this->GetFilas($sql_pro);
			$varCadPro = $fila_pro[0];
			}
		else {
			$varCadPro = "TODOS LOS PROVEEDORES";
			}
		$varCadOpt = $varOpt." - ".$this->sqltip[$varOpt];
		$varEmp = ($varEmp<>"" && $varEmp<>"Ninguno")?$varEmp:"NULL";
		$varPro = ($varPro<>"")?$varPro:"NULL";
		$varLis = ($varLis<>"")?"\"(".$varLis.")\"":"NULL";
		$varOpt = ($varOpt<>"Ninguno")?"'".$varOpt."'":"NULL";
		$varTip = ($varTip<>"Ninguno")?"'".$varTip."'":"NULL";
		$varFam = ($varFam<>"Ninguno")?"'".$varFam."'":"NULL";
		$varSub = ($varSub<>"Ninguno")?"'".$varSub."'":"NULL";		
		$sql = "call spQuery_Report_Lista_Precios($varEmp, $varPro, $varLis, $varOpt, $varTip, $varFam, $varSub);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$varNumCol = $this->NumField($rs);
		$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%;" cellspacing="0" cellpadding="0">';
			$html.='<tr class="titu_sup" height="25px">';
			$html.='<td colspan="2"><b>'.$this->varTitulo.'</b></td>';
			$html.='</tr>';
			$html.='<tr class="titu_sup2">';
			$html.='<td align="left"><b>'.$_SESSION["_CABR"].' : '.$_SESSION["_NSYS"].'</b></td>';
			$html.='<td align="right"><b>'.MostrarHora().'</b></td>';
			$html.='</tr>';
			$html.='<tr class="titu_inf">';
			$html.='<td align="left"><b>'.$varCadEmp.'</b></td>';
			$html.='<td align="right"><b>'.MostrarFecha().'</b></td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
		$html.='<tr>';
		$html.='<td>';
			$html.='<table style="width: 100%;" cellspacing="0" cellpadding="0">';
			$html.='<tr>';
			$html.='<td style="width: 8%; vertical-align: middle; text-align:left;"><b>Proveedor(es) </b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="width: 90%; vertical-align: middle; text-align:left;">'.$varCadPro.'</td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="width: 8%; vertical-align: middle; text-align:left;"><b>Opci&oacute;n </b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="width: 90%; vertical-align: middle; text-align:left;">'.$varCadOpt.'</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;" align="center">';
			$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><b></b></td>';
					$html.='<td align="center"><b>'.$fila["CSUB"].'</b></td>';
					$html.='<td 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><b></b></td>';
					$html.='<td align="center"><b>'.$fila["CSUB"].'</b></td>';
					$html.='<td align="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 align="center" NOWRAP>'.$fila["CART"].'</td>
						<td NOWRAP>'.$fila["ARTICULO"].'</td>
						<td NOWRAP>'.$fila["UM"].'</td>';
				$html.='<td class="right">'.number_format($fila["STOCK"],"1",".",",").'</td>';
						for($i=12;$i<=$varNumCol-1;$i++) {
							$html.='<td class="right">'.number_format($fila[$i],"5",".",",").'</td>';
						}
				
				$html.='</tr>';
				}
			/*
			$varLin_Ant = $varLin_Act = "";
			$varFam_Ant = $varFam_Act = "";
			$varSub_Ant = $varSub_Act = "";
			
			while($fila = $this->FetchArray($rs))	{
				$varLin_Act = $fila["CTIP"];
				$varFam_Act = $fila["CFAM"];
				$varSub_Act = $fila["CSUB"];
				$varTotal1 = $varTotal1 + $fila["CANTIDAD"];
				$varTotal2 = $varTotal2 + $fila["MONTO"];
				$varNumDoc++;
				if($varLin_Act <> $varLin_Ant) {
					$varLin_Ant = $fila["CTIP"];
					$html.='<tr class="titu_tabla">';
					$html.='<td align="left"><b>'.$fila["CTIP"].'</b></td>';
					$html.='<td align="left" colspan="'.($varNumCol-4).'"><b>'.$fila["TIPO"].'</b></td>';
					$html.='</tr>';
					}
				if($varFam_Act <> $varFam_Ant) {
					$varFam_Ant = $fila["CFAM"];
					$html.='<tr class="titu_tabla">';
					$html.='<td align="center"></td>';
					$html.='<td align="left"><b>'.$fila["CFAM"].'</b></td>';
					$html.='<td align="left" colspan="'.($varNumCol-5).'"><b>'.$fila["FAMILIA"].'</b></td>';
					$html.='</tr>';
					}
				if($varSub_Act <> $varSub_Ant) {					
					$varSub_Ant = $fila["CSUB"];
					$html.='<tr class="titu_tabla">';
					$html.='<td align="left"></td>';
					$html.='<td align="left"></td>';
					$html.='<td align="left"><b>'.$fila["CSUB"].'</b></td>';
					$html.='<td align="left" colspan="'.($varNumCol-6).'"><b>'.$fila["SUB_FAMILIA"].'</b></td>';
					$html.='</tr>';					
					$varSub_Tot = $fila["VALORIZA"];
					}
				$html.='<tr class="cont_tabla">
						<td align="center">&nbsp;</td>
						<td align="center">&nbsp;</td>
						<td align="center">&nbsp;</td>
						<td align="left">'.$fila["CART"].'</td>
						<td align="left" NOWRAP>'.$fila["ARTICULO"].'</td>
						<td NOWRAP>'.$fila["UM"].'</td>';
						for($i=9;$i<=$varNumCol-1;$i++) {
							$html.='<td class="right">'.number_format($fila[$i],"5",".",",").'</td>';
						}
				
				$html.='</tr>';
				}
			*/
			$html.='<tr class="titu_tabla">';
			$html.='<td colspan="3" class="left"><strong>TOTALES :</strong></td>';
			$html.='<td align="right" colspan="'.($varNumCol-11+3).'">'.number_format($varNumDoc,"0",".",",").' Producto(s)</td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
				
		$html.='</table>		
				</body>
				</html>';
		return $html;
		}
	}
?>