<?php
//include "clase.conexion.php";
class clsReporteMovimientos extends clsConexion{
	public $varTitulo = "REPORTE DE MOVIMIENTOS";
	function FormuBusqueda() {
		$sqlalm = "select id_almacen, nombre from _sv_almacen where _estado='A';";
		$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"=>"opt", "name"=>"opt", "valor"=>$Opcion)
									  ),
						"conte"=>array(array("titulo"=>"Almacen :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"alm", "name"=>"alm", "valor"=>NULL,
																					 "combo"=>array("sql"=>$sqlalm, "ancho"=>"200", "sincod"=>"SI"))
																			   )
														 	)
											 ),
									   array("titulo"=>"Producto :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"acod", "name"=>"acod", 
																					 "ancho"=>"65", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_articulo(this.value)", 
																					 "dclick"=>"fn_cargar_listado_producto('acod', 'anom')"),
																			   array("tipo"=>"text", "id"=>"anom", "name"=>"anom", 
																					 "ancho"=>"300", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Inicial :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"fini", "name"=>"fini", "alinear"=>"center",
																					 "ancho"=>"130", "valor"=>NULL)
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Final :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center", 
																					 "ancho"=>"130", "valor"=>NULL)
																			   )
														 	)
											 )
									 ),
					  "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($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$varAlm = (isset($varForm["alm"]) && $varForm["alm"]<>'Ninguno')?$varForm["alm"]:"NULL";
		$varPro = (isset($varForm["acod"]) && $varForm["acod"]<>'')?"'".$varForm["acod"]."'":"NULL";
		$varIni = (isset($varForm["fini"]) && $varForm["fini"]<>'')? "'".FechaMySql($varForm["fini"])."'":"NULL";
		$varFin = (isset($varForm["ffin"]) && $varForm["ffin"]<>'')? "'".FechaMySql($varForm["ffin"])."'":"NULL";
		
		$sql = "call spQuery_Movimientos($varAlm, $varPro, $varIni, $varFin, $varFie, $varOrd);";
		
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1000", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>20, "titulo"=>"IDE", "alinear"=>"center", "clase"=>"sortable-numeric"),
									   array("tamano"=>50, "titulo"=>"FMOV", "alinear"=>"center"),
									   array("tamano"=>20, "titulo"=>"CMOV", "alinear"=>"center"),
									   array("tamano"=>200,"titulo"=>"MOVIMIENTO", "fijo"=>"SI"),
									   array("tamano"=>100,"titulo"=>"ABREV", "oculto"=>"SI"),
									   array("tamano"=>10, "titulo"=>"TIPO", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"CPRO", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"PRODUCTO", "fijo"=>"SI", "oculto"=>"SI"),
									   array("tamano"=>10, "titulo"=>"FVENC.", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"LOTE", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CREF", "alinear"=>"center"),
									   array("tamano"=>20, "titulo"=>"FEMI", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"CTIPD", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"TIPO DOC", "fijo"=>"SI"),
									   array("tamano"=>50, "titulo"=>"DOCUMENTO", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"CANE", "alinear"=>"center"),
									   array("tamano"=>200,"titulo"=>"ANEXO", "fijo"=>"SI"),
									   array("tamano"=>50, "titulo"=>"INGRESO", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>50, "titulo"=>"SALIDA", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>50, "titulo"=>"USUARIO", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"CVEN", "alinear"=>"center"),
									   array("tamano"=>200,"titulo"=>"VENDEDOR", "fijo"=>"SI")
									   )
							);
		return $this->SetGridTabla2($varTabla);
		//return $sql;
		}
	
	function Imprimir ($varAlm = NULL,
					   $varPro = NULL, 
					   $varIni = NULL,
					   $varFin = NULL
					   )  {	
		$varAlm = (isset($varAlm) && $varAlm<>'Ninguno')?$varAlm:"NULL";					  
		$varPro = (isset($varPro) && $varPro<>'')?"'".$varPro."'":"NULL";
		$varFIni = (isset($varIni) && $varIni<>'')?"'".FechaMySql($varIni)."'":"NULL";
		$varFFin = (isset($varFin) && $varFin<>'')?"'".FechaMySql($varFin)."'":"NULL";
		
		$sqlalm = "select id_almacen, nombre from _sv_almacen where id_almacen = $varAlm;";
		$this->AbrirConexion();
		$rsalm = $this->Query($sqlalm);
		$this->CerrarConexion();
		$filaalm = $this->FetchArray($rsalm);
		
		$sqlpro = "select id_producto, descripcion from _sv_producto where id_producto = $varPro;";
		$this->AbrirConexion();
		$rspro = $this->Query($sqlpro);
		$this->CerrarConexion();
		$filapro = $this->FetchArray($rspro);
		$sql = "call spQuery_Movimientos($varAlm, $varPro, $varFIni, $varFFin, NULL, NULL);";
		
		$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 colspan="3" 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: 5%; vertical-align: middle; text-align:left;"><b>Almacen</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;">'.$filaalm[0].' - '.$filaalm[1].'</td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.MostrarFechaActual().'</b></td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>Producto</b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;">'.$filapro[0].' - '.$filapro[1].'</td>';
			$html.='<td style="vertical-align: middle; text-align:right;"></td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>Fecha</b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;">'.$varIni.' - '.$varFin.'</td>';
			$html.='<td 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.='<thead>';
			$html.='<tr class="head">';
			$html.='<td width="30" align="center">IDE</td>';
			$html.='<td width="30" align="center">FMOV</td>';
			$html.='<td width="30" align="center">CMOV</td>';
			$html.='<td width="30">MOVIMIENTO</td>';
			$html.='<td width="50" align="center">FVEN</td>';
			$html.='<td width="20">LOTE</td>';
			$html.='<td width="50" align="center">CREF</td>';
			$html.='<td width="20" align="center">FEMI</td>';
			$html.='<td width="25" nowrap>TIPODOC</td>';
			$html.='<td width="25" align="center">NDOC</td>';
			$html.='<td width="100" nowrap>ANEXO</td>';
			$html.='<td width="25" class="right">INGRESO</td>';
			$html.='<td width="25" class="right">SALIDAS</td>';
			$html.='</tr>';
			$html.='</thead>';
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$varTotal1 = 0;
			$varTotal2 = 0;
			$varTotal3 = 0;
			while($fila = $this->FetchArray($rs))	{
				$varTot1 = $varTot1 + $fila["INGRESO"];
				$varTot2 = $varTot2 + $fila["SALIDA"];
				$html.='<tr class="list_row">';
				$html.='<td NOWRAP align="center">'.$fila["IDE"].'</td>';
				$html.='<td NOWRAP align="center">'.$fila["FMOV"].'</td>';
				$html.='<td NOWRAP align="center">'.$fila["CMOV"].'</td>';
				$html.='<td NOWRAP>'.$fila["ABREV"].'</td>';
				$html.='<td NOWRAP align="center">'.$fila["FVEN"].'</td>';
				$html.='<td NOWRAP>'.$fila["LOTE"].'</td>';
				$html.='<td NOWRAP align="center">'.$fila["CREF"].'</td>';
				$html.='<td NOWRAP align="center">'.$fila["FEMI"].'</td>';
				$html.='<td NOWRAP>'.$fila["CTIPD"].' - '.$fila["TIPO_DOC"].'</td>';
				$html.='<td NOWRAP align="center">'.$fila["NDOC"].'</td>';
				$html.='<td NOWRAP>'.str_pad($fila["CANE"], 5, "0", STR_PAD_LEFT).' - '.$fila["ANEXO"].'</td>';
				$html.='<td class="right">';
				$html.=($fila["INGRESO"]<>"")?number_format($fila["INGRESO"],"0",".",","):"";
				$html.='</td>';
				$html.='<td class="right">';
				$html.=($fila["SALIDA"]<>"")?number_format($fila["SALIDA"],"0",".",","):"";
				$html.='</td>';
				$html.='</tr>';
				}
			$html.='<tr class="head">';
			$html.='<td colspan="11" class="left"><strong>Totales :</strong></td>';
			$html.='<td class="right">'.number_format($varTot1,"0",".",",").'</td>';
			$html.='<td class="right">'.number_format($varTot2,"0",".",",").'</td>';
			$html.='</tr>';
	
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
				
		$html.='</table>';
		return $html;
		}
	}
	
?>