<?php
//include "clase.conexion.php";
class clsRegistroTransferencia extends clsConexion{
	public $varTitulo = "REGISTRO DE TRANSFERENCIAS";
	public $varMyTabla  = "_sv_compra";
	public $varMyID  	  = "id_compra";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - BUSQUEDA",
						"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"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ecod", "name"=>"ecod", "valor"=>$_POST["ecod"], 
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_empresa(this.value)", 
																					 "dclick"=>"fn_cargar_listado_empresa('ecod', 'enom')"),
																			   array("tipo"=>"text", "id"=>"enom", "name"=>"enom", "valor"=>$_POST["enom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),
									   array("titulo"=>"Fecha Incial :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"fecha", "id"=>"fini", "name"=>"fini", "alinear"=>"center"))
														 	)
											 ),								  							  
									   array("titulo"=>"Fecha Final :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"fecha", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center"))
														 	)
											 )
									 ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"120", "texto"=>"Buscar",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()"),
									 array("tipo"=>"button", "id"=>"bexp", "name"=>"bexp", "ancho"=>"120", "texto"=>"Exportar",
									 	   "clase"=>"boton_exportar", "click"=>"javascript:xExportarJS()"),								
									 array("tipo"=>"button", "id"=>"bnew", "name"=>"bnew", "ancho"=>"150", "texto"=>"Nueva Transferencia", 
										   "clase"=>"boton_nuevo", "click"=>"javascript:FormuRegistroJS('NEW','')"),
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varEmp = (isset($varForm["ecod"]) && $varForm["ecod"]<>'')? $varForm["ecod"]:"NULL";
		$varPro = (isset($varForm["pcod"]) && $varForm["pcod"]<>'')? $varForm["pcod"]:"NULL";
		$varTip = (isset($varForm["tcod"]) && $varForm["tcod"]<>'')? $varForm["tcod"]:"NULL";
		$varIni = (isset($varForm["fini"]) && $varForm["fini"]<>'')? "'".FechaMySql($varForm["fini"])."'":"NULL";
		$varFin = (isset($varForm["ffin"]) && $varForm["ffin"]<>'')? "'".FechaMySql($varForm["ffin"])."'":"NULL";
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		
		$sql = "call spQuery_Registro_Compras($varEmp, $varPro, $varTip, $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"),
									   array("tamano"=>10, "titulo"=>"CEMP", "alinear"=>"center"),
									   array("tamano"=>250,"titulo"=>"EMPRESA", "fijo"=>"SI"),
									   array("tamano"=>50, "titulo"=>"EMISION", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"CTIP", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"TIPO DOC", "fijo"=>"SI"),
									   array("tamano"=>90, "titulo"=>"DOCUMENTO", "alinear"=>"center"),
									   array("tamano"=>40, "titulo"=>"EST.", "alinear"=>"center"),										   
									   array("tamano"=>10, "titulo"=>"CPRO", "alinear"=>"center"),
									   array("tamano"=>250,"titulo"=>"PROVEEDOR", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("tamano"=>60, "titulo"=>"SUB TOTAL", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>60, "titulo"=>"IGV", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>60, "titulo"=>"TOTAL", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("tamano"=>120, "titulo"=>"FCREADO", "alinear"=>"center", "fijo"=>"SI"),
									   array("tamano"=>100, "titulo"=>"FMODIFI", "alinear"=>"center", "fijo"=>"SI", "oculto"=>"SI"),
									   array("tamano"=>100, "titulo"=>"UCREADO", "alinear"=>"center"),
									   array("tamano"=>100, "titulo"=>"UMODIFI", "alinear"=>"center", "oculto"=>"SI")
									   ),
						"boton"=>array(array("cond"=>array(array(3,"<>","AN")),
										   		 "tipo"=>"img", "id"=>"banu", "name"=>"banu", "img"=>"../images/16x16/table_delete.png", 
												 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ANULAR</b> LA COMPRA"),
												 				 array("valor"=>"<br><b>Empresa : </b>"),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Proveedor : </b>"),
																 array("valor"=>8, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>9, "tipo"=>"INDEX"),
																 array("<br><b>Fecha Emisi&oacute;n : </b>"),
																 array("valor"=>3, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Tipo Doc. : </b>"),
																 array("valor"=>4, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>5, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Documento : </b>"),
																 array("valor"=>6, "tipo"=>"INDEX")
												   				),
												 "click"=>array("funcion"=>"xEliminarJS",
																"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																			   array("valor"=>1, "tipo"=>"INDEX"),
																			   array("valor"=>2, "tipo"=>"INDEX"),
																			   array("valor"=>8, "tipo"=>"INDEX"),
																			   array("valor"=>9, "tipo"=>"INDEX"),
																			   array("valor"=>3, "tipo"=>"INDEX"),
																			   array("valor"=>4, "tipo"=>"INDEX"),
																			   array("valor"=>5, "tipo"=>"INDEX"),
																			   array("valor"=>6, "tipo"=>"INDEX"),
																			   array("valor"=>"this", "tipo"=>"NUM") 
																			  )
																)												 
												),									  
										   array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/table.png", 
												 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>VER EL DETALLE DE</b> LA COMPRA"),
												 				 array("valor"=>"<br><b>Empresa : </b>"),
																 array("valor"=>1, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Proveedor : </b>"),
																 array("valor"=>8, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>9, "tipo"=>"INDEX"),
																 array("<br><b>Fecha Emisi&oacute;n : </b>"),
																 array("valor"=>3, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Tipo Doc. : </b>"),
																 array("valor"=>4, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>5, "tipo"=>"INDEX"),
																 array("valor"=>"<br><b>Documento : </b>"),
																 array("valor"=>6, "tipo"=>"INDEX")
												   				),
												 "click"=>array("funcion"=>"FormuDetalleJS",
																"param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"))
																)
												 
												),
										)
							);
		return $this->SetGridTabla2($varTabla);
		//return $sql;
		}
	
	function FormuRegistro($varOpt=NULL, $varCod=NULL) {
		$sqldoc = "call spQuery_Lista_Tipo_DocCompra('','');";
		$sqlcon = "select id_condicion, nombre from _sv_tipo_condicion where _estado='A' order by id_condicion desc";
		$varFlagIgv = array("S" => "PRECIOS SI INCLUYEN IGV", "N" => "PRECIOS NO INCLUYEN IGV");
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], '','%');";
		
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"Formtitulo", "titulo"=>$this->varTitulo." - NUEVA COMPRA",						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion),
									   array("tipo"=>"oculto", "id"=>"tdoc1", "name"=>"tdoc1", "valor"=>$_POST[tdoc1]),
									   array("tipo"=>"oculto", "id"=>"ndoc1", "name"=>"ndoc1", "valor"=>$_POST[ndoc1]),
									   array("tipo"=>"oculto", "id"=>"femi1", "name"=>"femi1", "valor"=>$_POST[femi1]),
									   array("tipo"=>"oculto", "id"=>"fmov1", "name"=>"fmov1", "valor"=>$_POST[fmov1]),
									   array("tipo"=>"oculto", "id"=>"pcod1", "name"=>"pcod1", "valor"=>$_POST[pcod1])
									  ),
						"conte"=>array(array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
										     "campo"=>array("tipo"=>"select", "id"=>"emp", "name"=>"emp", "sql"=>$sqlemp, "titulo"=>"--[[SELECCIONAR]]--",
														    "ancho"=>"300",  "reload"=>"xajax_comboListaAlmacenTrans(this.value, $_SESSION[_CUSE])")
										    ),
									   array("titulo"=>"Alm. Origen :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divAlmOri",
											 "campo"=>array("tipo"=>"select", "id"=>"almo", "name"=>"almo", "sql"=>"", "ancho"=>"300",
											 				"titulo"=>" --[[SELECCIONAR]]-- ")),
									   array("titulo"=>"Alm. Destino :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divAlmDes",
											 "campo"=>array("tipo"=>"select", "id"=>"almd", "name"=>"almd", "sql"=>"", "ancho"=>"300",
															"titulo"=>" --[[SELECCIONAR]]-- ")),
									   array("titulo"=>"Fecha :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"texto", "id"=>"femi", "name"=>"femi", 
															"ancho"=>"100", "locked"=>"SI", "clase"=>"campo_fecha")),
									   array("titulo"=>"Glosa :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"area", "id"=>"glo", "name"=>"glo", "ancho"=>"309", "alto"=>"40"))
									   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"100",
											 "clase"=>"boton_agregar", "texto"=>"Agregar", "click"=>"javascrip:addProductoTransferencia()"),
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()")
									   )
						);
		$varReturn = "<form id=\"form\" name=\"form\" method=\"POST\"  onSubmit=\"return validaRegistroCompra(this)\">";
		$varReturn.= $this->setTablaForm($varTabla);
		$varReturn.= "<br>";
		$varReturn.= "<table id=\"tblSample\" style=\"padding:0;margin-top:0px;border-collapse:collapse;\" ";
		$varReturn.= "width=550 align=center cellpadding=0 cellspacing=0>";
		$varReturn.= "<tr>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"90\">Codigo";
		$varReturn.= "<input name=\"num\" type=\"hidden\" class=\"input\" id=\"num\" value=\"0\"/>";
		$varReturn.= "</td>";	
		$varReturn.= "<td class=\"FormCampo2\" width=\"360\">Descripcion</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">U.M.</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"50\">Cantidad</td>";
		$varReturn.= "<td class=\"FormCampo2\" width=\"10\"></td>";
		$varReturn.= "</tr>";
		$varReturn.= "<tbody id=cuerpoTabla>";
		$varReturn.= "</tbody>";
		$varReturn.= "</table>";	
		$varReturn.= "</form>";
		return $varReturn;
		}
		
	function FormuDetalle($varCod=NULL) {
		$sql = "CALL spQuery_Registro_Compras_Cabecera($varCod)";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);

		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"500", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - DETALLE",					
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo." - ".$Fila["LISTA"]),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt",   "valor"=>"DET")
									  ),
						"conte"=>array(array("titulo"=>"Ide :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "clase"=>"inputDisable",
											 "valor"=>$Fila["IDE"], "alinear"=>"center", "locked"=>"SI", "ancho"=>"70")),
									   array("titulo"=>"Fecha Emision :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "texto"=>$Fila["FEMI"], "tamano"=>"120"),
									   array("titulo"=>"Fecha Movimiento :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "texto"=>$Fila["FMOV"]),
									   array("titulo"=>"Documento :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
									   		 "texto"=>$Fila["CTIP"]." &nbsp; ".$Fila["NDOC"]),
									   array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["CPRO"].' - '.$Fila["PROVEEDOR"]),
									   array("titulo"=>"Sub Total :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>number_format($Fila["SUBTOTAL"], 2,'.',',')),
									   array("titulo"=>"IGV :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>number_format($Fila["IGV"], 2,'.',',')),
									   array("titulo"=>"Total :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>number_format($Fila["TOTAL"], 2,'.',',')),
									   array("titulo"=>"Estado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["ESTADO"]),
									   array("titulo"=>"F/U Creado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["USER_CREATE"]." &nbsp; - &nbsp; ".$Fila["DATE_CREATE"]),
									   array("titulo"=>"F/U Modificado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["USER_UPDATE"]." &nbsp; - &nbsp; ".$Fila["DATE_UPDATE"])
									   ),
							  "boton"=>array(array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
												   "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()"),
											 array("tipo"=>"button", "id"=>"bnew", "name"=>"bnew", "ancho"=>"120", "texto"=>"Nueva Compra", 
										   		   "clase"=>"boton_nuevo", "click"=>"javascript:FormuRegistroJS('NEW','')"),
											)
						);		
		$varReturn = $this->setTablaForm($varTabla);
		
		$sql = "CALL spQuery_Registro_Compras_Contenido($varCod)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>20, "titulo"=>"CPRO", "alinear"=>"center"),
									   array("tamano"=>400, "titulo"=>"PRODUCTO", "fijo"=>"SI"),
									   array("tamano"=>50, "titulo"=>"UM", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"PRE. SIN_IGV", "alinear"=>"right", "decimal"=>5),
									   array("tamano"=>50, "titulo"=>"PRE. CON_IGV", "alinear"=>"right", "decimal"=>5),
									   array("tamano"=>50, "titulo"=>"CANTIDAD", "alinear"=>"right"),
									   array("tamano"=>50, "titulo"=>"% DESC1", "alinear"=>"center", "tipodat"=>"porc"),
									   array("tamano"=>50, "titulo"=>"% DESC2", "alinear"=>"center", "tipodat"=>"porc"),
									   array("tamano"=>50, "titulo"=>"SUBTOTAL", "alinear"=>"right"),
									   array("tamano"=>50, "titulo"=>"IGV", "alinear"=>"right"),
									   array("tamano"=>50, "titulo"=>"TOTAL", "alinear"=>"right")
									   )
						);
		$varReturn.= "<div id=\"divDatos\">";
		$varReturn.= $this->SetGridTabla($varTabla);
		$varReturn.= "</div>";
		
		return $varReturn;
		}
	
	function FormuDetalleFloat($varCod=NULL) {
		$sql = "CALL spQuery_Registro_Compras_Cabecera($varCod)";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);

		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"500", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - DETALLE",					
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo." - ".$Fila["LISTA"]),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt",   "valor"=>"DET")
									  ),
						"conte"=>array(array("titulo"=>"Ide :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"80",
											 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "clase"=>"inputDisable",
											 "valor"=>$Fila["IDE"], "alinear"=>"center", "locked"=>"SI", "ancho"=>"70")),
									   array("titulo"=>"Fecha Emision :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "texto"=>$Fila["FEMI"], "tamano"=>"120"),
									   array("titulo"=>"Fecha Movimiento :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "texto"=>$Fila["FMOV"]),
									   array("titulo"=>"Documento :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
									   		 "texto"=>$Fila["CTIP"]." &nbsp; ".$Fila["NDOC"]),
									   array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["CPRO"].' - '.$Fila["PROVEEDOR"]),
									   array("titulo"=>"Sub Total :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>number_format($Fila["SUBTOTAL"], 2,'.',',')),
									   array("titulo"=>"IGV :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>number_format($Fila["IGV"], 2,'.',',')),
									   array("titulo"=>"Total :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>number_format($Fila["TOTAL"], 2,'.',',')),
									   array("titulo"=>"Estado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["ESTADO"]),
									   array("titulo"=>"F/U Creado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["USER_CREATE"]." &nbsp; - &nbsp; ".$Fila["DATE_CREATE"]),
									   array("titulo"=>"F/U Modificado :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "texto"=>$Fila["USER_UPDATE"]." &nbsp; - &nbsp; ".$Fila["DATE_UPDATE"])
									   ),
							  "boton"=>array(array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											   "clase"=>"boton_cancelar", "texto"=>"Cerrar", "click"=>"window.close()")
										)
						);		
		$varReturn = $this->setTablaForm($varTabla);
		
		$sql = "CALL spQuery_Registro_Compras_Contenido($varCod)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>20, "titulo"=>"CPRO", "alinear"=>"center"),
									   array("tamano"=>400, "titulo"=>"PRODUCTO", "fijo"=>"SI"),
									   array("tamano"=>50, "titulo"=>"UM", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"PRE. SIN_IGV", "alinear"=>"right", "decimal"=>5),
									   array("tamano"=>50, "titulo"=>"PRE. CON_IGV", "alinear"=>"right", "decimal"=>5),
									   array("tamano"=>50, "titulo"=>"CANTIDAD", "alinear"=>"right"),
									   array("tamano"=>50, "titulo"=>"% DESC1", "alinear"=>"center", "tipodat"=>"porc"),
									   array("tamano"=>50, "titulo"=>"% DESC2", "alinear"=>"center", "tipodat"=>"porc"),
									   array("tamano"=>50, "titulo"=>"SUBTOTAL", "alinear"=>"right"),
									   array("tamano"=>50, "titulo"=>"IGV", "alinear"=>"right"),
									   array("tamano"=>50, "titulo"=>"TOTAL", "alinear"=>"right")
									   )
						);
		$varReturn.= "<div id=\"divDatos\">";
		$varReturn.= $this->SetGridTabla($varTabla);
		$varReturn.= "</div>";
		
		return $varReturn;
		}
		
	function ProcesoGrabar($varForm = NULL) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varCod = ($varForm["cod"]=="")? "NULL" : "'$varForm[cod]'";
		$varNam = ($varForm["nam"]=="")? "NULL" : "'$varForm[nam]'";
		$varPes = ($varForm["pes"]=="")? "NULL" : $varForm[pes];
		
		
		$Usr = (isset($_SESSION["_CUSE"]))  ? $_SESSION["_CUSE"] : "1";
		$vnum = $varForm["num"];
		$femi = FechaMySql($varForm["femi1"]);
		$fmov = FechaMySql($varForm["fmov1"]);	
		
		$varTotal 	= $varForm["tot"];
		$varEmp 	= $varForm["emp"];
		$varAlm 	= $varForm["alm"];
		$varPro 	= (isset($varForm["pcod1"]) && $varForm["pcod1"]<>"")? $varForm[pcod1] : "NULL";
		$varPrN 	= (isset($varForm["pnom"]) && $varForm["pnom"]<>"")? "'".$varForm[pnom]."'": "NULL";	
		$varCon 	= (isset($varForm["con"])  && $varForm["con"]<>"")?$varForm[con]:"NULL";
		$varGlo 	= (isset($varForm["glos"]) && $varForm["glos"]<>"")? "'".$varForm[glos]."'":"NULL";
		$varFlagIgv = (isset($varForm["flag_igv"]) && $varForm["flag_igv"]<>"")?$varForm[flag_igv]:"N";
		$varDoc 	= $varForm["nser"]."-".$varForm["nnum"];
	
		$sql1 = "call spMante_Compra_Cab($varEmp, $varAlm, $varForm[tdoc1], '$varDoc', $varCon, '$femi', '$fmov', $varPro, $varPrN, $varGlo, $varTotal, $Usr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql1);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		$varError[0]  = $Fila[0];
		$varError[1]  = $Fila[1];
		$NumCompra 	  = $Fila[1];
		$sql_det="";
		if ($varError[0]=="OK") {
			foreach ($varForm["icod"] as $varIde=>$varPro) {
				$varPro = str_pad($varForm["icod"][$varIde], 6, "0", STR_PAD_LEFT);
				$varPre = $varForm["ipre"][$varIde];
				$varCan = $varForm["ican"][$varIde];
				$varDe1 = $varForm["ides1"][$varIde];
				$varDe2 = $varForm["ides2"][$varIde];
				$varUme = "'".$varForm["iuni"][$varIde]."'";
				$sql_det.= "call spMante_Compra_Det($varEmp, $varAlm, $NumCompra, '$varFlagIgv', '$varPro',  $varCan, $varPre, $varDe1, $varDe2, $varUme, '$femi', $Usr);";		
				}			
			}
		$this->AbrirConexion();
		$rs = $this->Query($sql_det);
		$this->CerrarConexion();
		return $varError;
		}
		
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "call spMante_Compra_Anular($varCod, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();	
		$varTipo = $this->NumField($rs);
		$varReturn = "";
		if ($varTipo==1) {
			$fila = $this->FetchArray($rs);
			$varReturn = $fila[0];
			}
		else {
			$varReturn.="CPRO\tPRODUCTO\t\t\t\t\t\t\t\t\tUM_COMP.\tCANT.COM.\tCANT.COM2\tUM_STK\tCANT.STK\tDIFER\n";
			$varReturn.="---------------------------------------------------------------------------------------------------------------------";
			$varReturn.="--------------------------------------------------------\n";
			while($fila = $this->FetchArray($rs)) {				
				$varReturn.=$fila["CPRO"]."\t".$fila["PRODUCTO"]."\t\t".$fila["UM_COMPRA"]."\t\t".number_format($fila["CANT_COMPRA"], 2,'.',',')."\t\t";
				$varReturn.=number_format($fila["CANT_COMPRA_STOCK"], 2,'.',',')."\t\t";
				$varReturn.=$fila["UM_STOCK"]."\t\t".str_pad(number_format($fila["CANT_STOCK"], 2,'.',','),6, STR_PAD_LEFT)."\t\t";
				$varReturn.=str_pad(number_format($fila["DIFERENCIA"], 2,'.',','),6, STR_PAD_LEFT)."\n";
				}
			}
		return $varReturn;
		}
	}
	
?>