<?php
//include "clase.conexion.php";
class clsInventario extends clsConexion{
	public $varTitulo 	= "INVENTARIO ACTUAL";
	function FormuBusqueda() {
		$Array = array("T" => "TODOS LOS PRODUCTOS", "S" => "SOLO PRODUCTOS CON STOCK");
		$sqltip = "call spQuery_Combo_Producto_Tipo();";
		$sqlfam = "call spQuery_Combo_Producto_Familia('$Fila[id_tipo]');";
		$sqlsub = "call spQuery_Combo_Producto_Sub_Familia('$Fila[id_familia]');";	
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '','%');";
		
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "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"=>"Tipo Reporte :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										     "campo"=>array("tipo"=>"select_simple", "id"=>"tipo", "name"=>"tipo", "valor"=>$varTipo, "ancho"=>"100",
														    "combo"=>array("sql"=>$Array, "sincod"=>"SI", "ancho"=>"300"))),
									   array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divPro",
										     "campo"=>array("tipo"=>"select", "id"=>"emp", "name"=>"emp", "sql"=>$sqlemp,
														    "titulo"=>"--[[SELECCIONAR]]--", "ancho"=>"300", "locked"=>$varLock,
															"reload"=>"xajax_ComboListaAlmacen(this.value, $_SESSION[_CUSE],300)")
										    ),
									   array("titulo"=>"Almacen :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divAlm",
										     "campo"=>array("tipo"=>"select", "id"=>"alm", "name"=>"alm", "ancho"=>"100",
														    "titulo"=>"--[[SELECCIONAR]]--", "sql"=>NULL, "sincod"=>"SI", "ancho"=>"300")),	
									   array("titulo"=>"Linea :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select", "id"=>"tip", "name"=>"tip", "valor"=>$Fila["id_tipo"],
															"sql"=>$sqltip, "ancho"=>"300", "titulo"=>"--[[SELECCIONAR]]--",
															"reload"=>"xajax_comboFamilia(this.value)")),
									   array("titulo"=>"Familia :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divFam",
											 "campo"=>array("tipo"=>"select", "id"=>"fam", "name"=>"fam", "valor"=>$Fila["id_familia"],
															"sql"=>$sqlfam, "ancho"=>"300",  "titulo"=>"--[[SELECCIONAR]]--", 
															"sincod"=>"SI", "reload"=>"xajax_comboSubFamilia(this.value)")),
									   array("titulo"=>"Sub Familia :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divSub",
											 "campo"=>array("tipo"=>"select", "id"=>"sub", "name"=>"sub", "valor"=>$Fila["id_sub_familia"],
															"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($varForm = NULL
					  )  {						  
		$varEmp  = ($varForm["emp"]<>"Ninguno")?"'".$varForm["emp"]."'":"NULL";
		$varAlm  = ($varForm["alm"]<>"Ninguno")?"'".$varForm["alm"]."'":"NULL";
		$varLin  = ($varForm["tip"]<>"Ninguno")?"'".$varForm["tip"]."'":"NULL";
		$varFam  = ($varForm["fam"]<>"Ninguno")?"'".$varForm["fam"]."'":"NULL";
		$varSub  = ($varForm["sub"]<>"Ninguno")?"'".$varForm["sub"]."'":"NULL";	
		$sql = "call spQuery_Logisitica_Inventario_Actual('$varForm[tipo]', $varEmp, $varAlm, $varLin, $varFam, $varSub)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"700", "sql_cab"=>$sql,	"pages"=>50,
						"conte"=>array(array("tamano"=>20, "titulo"=>"XPRO", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"PROVEEDOR", "oculto"=>"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"=>250, "titulo"=>"ARTICULO", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("tamano"=>50, "titulo"=>"UM_STOCK", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"STOCK", "alinear"=>"right", "decimal"=>"2")
									   )
						);
		
		return $this->SetGridTabla($varTabla);
		}
	function Imprimir($varTip = NULL,
					  $varEmp = NULL,
					  $varAlm = NULL,
					  $varLin = NULL,
					  $varFam = NULL,
					  $varSub = NULL
					  )  {	
		$varLin  = ($varLin<>"Ninguno")?"'".$varLin."'":"NULL";
		$varFam  = ($varFam<>"Ninguno")?"'".$varFam."'":"NULL";
		$varSub  = ($varSub<>"Ninguno")?"'".$varSub."'":"NULL";	
		
		$sql_emp = "select concat(id_empresa, ' - ', nombre) as empresa from _sv_empresa where id_empresa=$varEmp;";
		$this->AbrirConexion();
		$rs_emp = $this->Query($sql_emp);
		$this->CerrarConexion();
		$fila_emp = $this->FetchArray($rs_emp);
		$varCadEmp = $fila_emp[0];
		
		$sql_alm = "select concat(id_almacen, ' - ', nombre) as almacen from _sv_almacen where id_almacen = $varAlm;";
		$this->AbrirConexion();
		$rs_alm = $this->Query($sql_alm);
		$this->CerrarConexion();
		$fila_alm = $this->FetchArray($rs_alm);
		$varCadAlm = $fila_alm[0];
		
		$sql = "call spQuery_Logisitica_Inventario_Actual('$varTip', $varEmp, $varAlm, $varLin, $varFam, $varSub)";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$varNumCol = $this->NumField($rs);
		$varNumCom = 
		$html.='<table style="width: 98%; 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_inf">';
			$html.='<td colspan="2">';
			$html.='<div align="left" style=" width:50%;float:left;">'.$_SESSION["_CABR"].' : '.$_SESSION["_NSYS"].'</div>';
    		$html.='<div align="right" style="width:50%;float:left">'.MostrarFechaActual().'</div>';
			$html.='</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:80px;vertical-align: middle; text-align:left;"><b>Empresa </b></td>';
			$html.='<td style="width:10px;vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;">'.$varCadEmp.'</td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>Almacen </b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;" nowrap>'.$varCadAlm.'</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="200" class="left">PRODUCTO</td>';
			$html.='<td width="50" NOWRAP>UM</td>';
			$html.='<td width="50" class="right" NOWRAP>STOCK</td>';
			$html.='</tr>';
			$html.='</thead>';
			$varLin_Ant = $varLin_Act = "";
			$varFam_Ant = $varFam_Act = "";
			$varSub_Ant = $varSub_Act = "";
			$varCant = $this->NumFilas($rs);
			$varTotVen = 0;
			$varTotMar = 0;
			while($fila = $this->FetchArray($rs)){
				$varPro_Act = $fila["XPRO"];
				$varSub_Act = $fila["CSUB"];
				$varTotal1 = $varTotal1 + $fila["CANTIDAD"];
				$varTotal2 = $varTotal2 + $fila["MONTO"];
				$varNumDoc++;
				if($varPro_Act <> $varPro_Ant) {
					$varPro_Ant = $fila["XPRO"];
					$varSub_Ant = $fila["CSUB"];
					$html.='<tr class="head">';
					$html.='<td class="center"><b>'.$fila["XPRO"].'</b></td>';
					$html.='<td colspan="4"><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 colspan="3"><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 colspan="3"><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["CPRO"].'</td>
						<td NOWRAP>'.$fila["PRODUCTO"].'</td>
						<td NOWRAP>'.$fila["UM"].'</td>						
						<td class="right">'.number_format($fila["STOCK"],"2",".",",").'</td>';
				$html.='</tr>';
				}
			$html.='<tr class="titu_tabla">';			
			$html.='<td align="left" colspan="2"><b>TOTALES</b></td>';
			$html.='<td align="right" colspan="3"><b>'.$varCant.' Producto(s)</b></td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
				
		$html.='</table>		
				</body>
				</html>';
		return $html;
		}
	}
?>