<?php
//include "clase.conexion.php";
class clsRegistroDevolucion extends clsConexion{
	public $varTitulo = "REGISTRO DE DEVOLUCIONES";
	public $varMyTabla  = "_sv_venta";
	public $varMyID  	  = "id_venta";
	function FormuBusqueda() {
		$varEst = array("IN" => "INGRESADO", "AN" => "ANULADO", "FA" => "FACTURADO");
		$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"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", "valor"=>$_POST["ccod"],
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_cliente(ecod.value, this.value)", 
																					 "dclick"=>"fn_cargar_listado_cliente(ecod.value, 'ccod', 'cnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", "valor"=>$_POST["cnom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"vcod", "name"=>"vcod", "valor"=>$_POST["vcod"],
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_vendedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_vendedor('vcod', 'vnom')"),
																			   array("tipo"=>"text", "id"=>"vnom", "name"=>"vnom", "valor"=>$_POST["vnom"], 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Ruta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"rcod", "name"=>"rcod", "valor"=>NULL,
																					 "ancho"=>"50", "alinear"=>"center",
																					 "blur"=>"xajax_seleccionar_ruta(this.value)", 
																					 "dclick"=>"fn_cargar_listado_ruta('rcod', 'rnom')"),
																			   array("tipo"=>"text", "id"=>"rnom", "name"=>"rnom", "valor"=>NULL, 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 	)
											 ),
									   array("titulo"=>"Tipo Doc. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"tcod", "name"=>"tcod", "valor"=>NULL,
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_tipo_docventa(this.value)", 
																					 "dclick"=>"fn_cargar_listado_tipo_doc_venta('tcod', 'tnom')"),
																			   array("tipo"=>"text", "id"=>"tnom", "name"=>"tnom", "valor"=>NULL, 
																					 "ancho"=>"250", "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",
																					 "locked"=>"SI", "ancho"=>"130", "valor"=>date('d/m/Y',time()))
																			   )
														 	)
											 ),
									   array("titulo"=>"Fecha Final :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"texto", "id"=>"ffin", "name"=>"ffin", "alinear"=>"center", 
																					 "locked"=>"SI", "ancho"=>"130", "valor"=>date('d/m/Y',time()))
																			   )
														 	)
											 )
									   ),
					  "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()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varEmp = (isset($varForm["ecod"]) && $varForm["ecod"]<>'')? $varForm["ecod"]:"NULL";
		$varCli = (isset($varForm["ccod"]) && $varForm["ccod"]<>'')? $varForm["ccod"]:"NULL";
		$varVen = (isset($varForm["vcod"]) && $varForm["vcod"]<>'')? $varForm["vcod"]:"NULL";
		$varRut = (isset($varForm["rcod"]) && $varForm["rcod"]<>'')? "'".$varForm["rcod"]."'":"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";
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$sql = "call spQuery_Registro_Ventas_Devolucion($varEmp, $varCli, $varVen, $varRut, $varTip, $varIni, $varFin, $varFie, $varOrd);";
				
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1100", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>20, "titulo"=>"IDE", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"CEMP", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>150,"titulo"=>"EMPRESA", "fijo"=>"SI", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"EMISION", "alinear"=>"center"),
									   array("tamano"=>80, "titulo"=>"DOCUMENTO", "alinear"=>"center", "funcion"=>array("contar")),
									   array("tamano"=>10, "titulo"=>"CCON", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>150,"titulo"=>"CONDICION", "alinear"=>"center"),
									   array("tamano"=>40, "titulo"=>"EST.", "alinear"=>"center"),
									   array("tamano"=>10, "titulo"=>"CTIP", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CCLI", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"CLIENTE", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CVEN", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"VENDEDOR", "fijo"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CRUT", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"RUTA", "fijo"=>"SI", "oculto"=>"SI"),
									   array("tamano"=>10, "titulo"=>"CLIS", "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>250,"titulo"=>"LISTA", "fijo"=>"SI"),
									   array("tamano"=>40, "titulo"=>"PEDIDO","alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>40, "titulo"=>"GUIA",  "alinear"=>"center", "oculto"=>"SI"),
									   array("tamano"=>50, "titulo"=>"TOTAL", "alinear"=>"right", "autosuma"=>"SI"),
									   array("tamano"=>50, "titulo"=>"SALDO", "alinear"=>"right", "autosuma"=>"SI"),
									   array("titulo"=>"FCREADO",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"FUPDATE",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO",  "ancho"=>"50",  "oculto"=>"SI"),
									   array("titulo"=>"UUPDATE",  "ancho"=>"50",  "oculto"=>"SI")
									   ),
						"boton"=>array(array("tipo"=>"img", "id"=>"bdet", "name"=>"bdet", "img"=>"../images/16x16/table_row_delete.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK AQUI PARA<br>"),
															 array("valor"=>"<b>REALIZAR UNA DEVOLUCION PARCIAL</b> DEL DOCUMENTO"),
															 array("valor"=>"<br><b>Empresa : </b>"),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>F. Emision : </b>"),
															 array("valor"=>3, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Documento : </b>"),
															 array("valor"=>4, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Cliente : </b>"),
															 array("valor"=>9, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>10, "tipo"=>"INDEX")
															 ),
											 "click"=>array("funcion"=>"FormuDevolParcialJS",
															"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>1, "tipo"=>"INDEX"),
																		   array("valor"=>2, "tipo"=>"INDEX"),
																		   array("valor"=>3, "tipo"=>"INDEX"),
																		   array("valor"=>4, "tipo"=>"INDEX"),
																		   array("valor"=>9, "tipo"=>"INDEX"),
																		   array("valor"=>10,"tipo"=>"INDEX")
																		   )
															)
											 ),											
										array("tipo"=>"img", "id"=>"bdet", "name"=>"bdet", "img"=>"../images/16x16/table_delete.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK AQUI PARA<br>"),
															 array("valor"=>"<b>REALIZAR UNA DEVOLUCION TOTAL</b> DEL DOCUMENTO"),
															 array("valor"=>"<br><b>Empresa : </b>"),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>F. Emision : </b>"),
															 array("valor"=>3, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Documento : </b>"),
															 array("valor"=>4, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Cliente : </b>"),
															 array("valor"=>9, "tipo"=>"INDEX"),
															 array("valor"=>" - "),
															 array("valor"=>10, "tipo"=>"INDEX")
															),
											 "click"=>array("funcion"=>"FormuDevolTotalJS",
															"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>1, "tipo"=>"INDEX"),
																		   array("valor"=>2, "tipo"=>"INDEX"),
																		   array("valor"=>3, "tipo"=>"INDEX"),
																		   array("valor"=>4, "tipo"=>"INDEX"),
																		   array("valor"=>9, "tipo"=>"INDEX"),
																		   array("valor"=>10,"tipo"=>"INDEX")
																		   )
															)
												 )
										)						
						);
		return $this->SetGridTabla2($varTabla);
		//return $sql;
		}
	
	function FormuDevolParcial($varEmp, $varCod) {
		$sql = "CALL spQuery_Registro_Ventas_Detalle($varCod)";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);		

		$sqlmot = "call spQuery_Combo_Motivo_Rechazo();";
		$varFormu=array("id"=>"formDev", "name"=>"formDev", "metodo"=>"POST");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"550", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - DEVOLUCION PARCIAL",						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>"PAR"),
									   array("tipo"=>"oculto", "id"=>"emp", "name"=>"emp", "valor"=>$varEmp),
									   array("tipo"=>"oculto", "id"=>"ide", "name"=>"ide", "valor"=>$varCod)
									  ),
						"conte"=>array(array("titulo"=>"Fecha Emision :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "texto"=>$Fila["EMISION"], "tamano"=>"100"),
									   array("titulo"=>"Tipo Doc. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"120", 
																					 "valor"=>$Fila["CTIPD"]." - ".$Fila["CTIP"]),
																			   array("tipo"=>"simple", "valor"=>"Nro. Doc. : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "ancho"=>"100", "valor"=>$Fila["NDOC"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Cond. Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"120", 
																					 "valor"=>$Fila["CCON"]." - ".$Fila["CONDICION"]),
																			   array("tipo"=>"simple", "valor"=>"Estado : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "ancho"=>"100", 
																			   		 "valor"=>$Fila["CEST"]." - ".$Fila["ESTADO"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$Fila["CCLI"]." - ".$Fila["CLIENTE"]))
														 	)
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$Fila["CVEN"]." - ".$Fila["VENDEDOR"]))
														 	)
											 ),
									    array("titulo"=>"Monto :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"60", 
																					 "valor"=>number_format($Fila["TOTAL"], 2,'.',',')),
																			   array("tipo"=>"simple", "valor"=>"Pagos : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "ancho"=>"60", 
																			   		 "valor"=>number_format($Fila["PAGOS"], 2,'.',',')),
																			   array("tipo"=>"simple", "valor"=>"Saldo : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", 
																			   		 "valor"=>number_format($Fila["SALDO"], 2,'.',','))
																			   )
														 	)
											 ),
									   array("titulo"=>"Creado Por :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"60", 
																					 "valor"=>$Fila["USER_CREATE"]),
																			   array("tipo"=>"simple", "valor"=>"Fecha/Hora : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "valor"=>$Fila["DATE_CREATE"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Motivo Devol.:", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"mot", "name"=>"mot", "valor"=>NULL,
																				   "sql"=>$sqlmot, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", 
																				   "ancho"=>"280")
																				   )
														 	)
											 )
									   ),
					  "boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"160",
										   "clase"=>"boton_guardar", "texto"=>"Registrar Devolucion", "click"=>"javascrip:xGrabarJS()"),
									 array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Regresar", "click"=>"javascrip:xajax_xRegresar()")
									 )
					);
		
		
		$Titulo1 = "<a href=\"javascript:marcar_todo('formDev')\">Seleccionar Todos</a> | 
					<a href=\"javascript:marcar_ninguno('formDev')\">Seleccionar Ninguno</a>";
									
		$varDia1 = (isset($varDia) && $varDia<>"")?"'".FechaMySql($varDia)."'":"NULL";
		$varVen1  = ($varVen<>"")?"\"(".$varVen.")\"":"NULL";
		$varRut1  = ($varRut<>"")?"\"(".str_replace("\\","",$varRut).")\"":"NULL";
		
		$sql1 = "call spQuery_Registro_Ventas_Contenido_Devolucion($varCod);";
		$this->AbrirConexion();
		$rs1 = $this->Query($sql1);
		$this->CerrarConexion();
		$varExiste = $this->NumFilas($rs1);
		
		$varTab_1=array("id"=>"tab1", "name"=>"tab1", "tamano"=>"840", "clase"=>"FormTitulo", "titulo"=>$Titulo1, "sql"=>$sql1,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num1", "name"=>"num1", "valor"=>$varNum1)),
						"conte"=>array(array("titulo"=>"SEL", "clase"=>"FormTitulo", "tamano"=>"30", "alinear"=>"center", "alto"=>"25",
											 "campo"=>array("tipo"=>"check", "id"=>"pro", "name"=>"pro", "id_name"=>array(1,3), "alinear"=>"center")
											 ),
									   array("titulo"=>"CPRO", "clase"=>"FormTitulo", "tamano"=>"50", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple", "alinear"=>"center")
											),
									   array("titulo"=>"PRODUCTO", "clase"=>"FormTitulo", "tamano"=>"300",
											 "campo"=>array("tipo"=>"texto", "id"=>"des", "name"=>"des", "id_name"=>array(1,3),
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"320")
											),
									   array("titulo"=>"TIP", "clase"=>"FormTitulo", "tamano"=>"50", "fijo"=>"SI", "alinear"=>"center",
											 "campo"=>array("tipo"=>"texto", "id"=>"tip", "name"=>"tip", "id_name"=>array(1,3), "alinear"=>"center", 
											 				"clase"=>"inputDisable", "locked"=>"SI", "ancho"=>"50")
											),										   
									   array("titulo"=>"UM", "clase"=>"FormTitulo", "tamano"=>"50", "fijo"=>"SI", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"PRECIO", "clase"=>"FormTitulo", "tamano"=>"50", "fijo"=>"SI", "alinear"=>"right",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"CANT.", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right",
											 "campo"=>array("tipo"=>"texto", "id"=>"can", "name"=>"can", "alinear"=>"right", 
											 				"clase"=>"inputDisable", "locked"=>"SI", "id_name"=>array(1,3), "ancho"=>"70",
															"keypress"=>"return SoloNumeros(event)")
											),
									   array("titulo"=>"MONTO", "clase"=>"FormTitulo", "tamano"=>"30", "alinear"=>"right", 
											 "campo"=>array("tipo"=>"simple", "alinear"=>"rigth")
											),
									   array("titulo"=>"DEVOL.", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right",
											 "campo"=>array("tipo"=>"texto", "id"=>"dev", "name"=>"dev", "alinear"=>"right", 
											 				"id_name"=>array(1,3), "ancho"=>"70")
											),
									   )
						);
		
		$varTabs =array(array("name"=>"Detalle del Documento",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_1
							  )
						);
		$varReturn.= $this->setTablaFormTabs($varFormu, $varTabla, $varTabs);
		$varReturn.= "</form>";
		if($varExiste>0)
			return $varReturn;
		else {
			$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"530", "clase"=>"FormTitulo", "titulo"=>"NO HAY DATOS QUE MOSTRAR",
							"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST"),						
							"boton"=>array(array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
												 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()"))
							);
			return $this->setTablaForm($varTabla);
			}
		}
		
	function FormuDevolTotal($varEmp, $varCod) {
		$sql = "CALL spQuery_Registro_Ventas_Detalle($varCod)";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);		

		$sqlmot = "call spQuery_Combo_Motivo_Rechazo();";
		$varFormu=array("id"=>"formDev", "name"=>"formDev", "metodo"=>"POST");
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"550", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo." - DEVOLUCION PARCIAL",						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>"TOT"),
									   array("tipo"=>"oculto", "id"=>"emp", "name"=>"emp", "valor"=>$varEmp),
									   array("tipo"=>"oculto", "id"=>"ide", "name"=>"ide", "valor"=>$varCod)
									  ),
						"conte"=>array(array("titulo"=>"Fecha Emision :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "texto"=>$Fila["EMISION"], "tamano"=>"100"),
									   array("titulo"=>"Tipo Doc. :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"120", 
																					 "valor"=>$Fila["CTIPD"]." - ".$Fila["CTIP"]),
																			   array("tipo"=>"simple", "valor"=>"Nro. Doc. : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "ancho"=>"100", "valor"=>$Fila["NDOC"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Cond. Venta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"120", 
																					 "valor"=>$Fila["CCON"]." - ".$Fila["CONDICION"]),
																			   array("tipo"=>"simple", "valor"=>"Estado : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "ancho"=>"100", 
																			   		 "valor"=>$Fila["CEST"]." - ".$Fila["ESTADO"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$Fila["CCLI"]." - ".$Fila["CLIENTE"]))
														 	)
											 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "valor"=>$Fila["CVEN"]." - ".$Fila["VENDEDOR"]))
														 	)
											 ),
									    array("titulo"=>"Monto :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"60", 
																					 "valor"=>number_format($Fila["TOTAL"], 2,'.',',')),
																			   array("tipo"=>"simple", "valor"=>"Pagos : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "ancho"=>"60", 
																			   		 "valor"=>number_format($Fila["PAGOS"], 2,'.',',')),
																			   array("tipo"=>"simple", "valor"=>"Saldo : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", 
																			   		 "valor"=>number_format($Fila["SALDO"], 2,'.',','))
																			   )
														 	)
											 ),
									   array("titulo"=>"Creado Por :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"simple", "ancho"=>"60", 
																					 "valor"=>$Fila["USER_CREATE"]),
																			   array("tipo"=>"simple", "valor"=>"Fecha/Hora : ", 
																			   		 "clase_in"=>"FormCampo1", "ancho"=>"80"),
																			   array("tipo"=>"simple", "valor"=>$Fila["DATE_CREATE"])
																			   )
														 	)
											 ),
									   array("titulo"=>"Motivo Devol.:", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select", "id"=>"mot", "name"=>"mot", "valor"=>NULL,
																				   "sql"=>$sqlmot, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", 
																				   "ancho"=>"280")
																				   )
														 	)
											 )
									   ),
					  "boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"160",
										   "clase"=>"boton_guardar", "texto"=>"Registrar Devolucion", "click"=>"javascrip:xGrabarJS()"),
									 array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Regresar", "click"=>"javascrip:xajax_xRegresar()")
									 )
					);
		
		
		$Titulo1 = "DETALLE DE PRODUCTOS QUE SE DEVOLVERAN";
									
		$varDia1 = (isset($varDia) && $varDia<>"")?"'".FechaMySql($varDia)."'":"NULL";
		$varVen1  = ($varVen<>"")?"\"(".$varVen.")\"":"NULL";
		$varRut1  = ($varRut<>"")?"\"(".str_replace("\\","",$varRut).")\"":"NULL";
		
		$sql1 = "call spQuery_Registro_Ventas_Contenido_Devolucion($varCod);";
		$this->AbrirConexion();
		$rs1 = $this->Query($sql1);
		$this->CerrarConexion();
		$varExiste = $this->NumFilas($rs1);
		
		$varTab_1=array("id"=>"tab1", "name"=>"tab1", "tamano"=>"840", "clase"=>"FormTitulo", "titulo"=>$Titulo1, "sql"=>$sql1,
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"num1", "name"=>"num1", "valor"=>$varNum1)),
						"conte"=>array(array("titulo"=>"SEL", "clase"=>"FormTitulo", "tamano"=>"30", "alinear"=>"center", "alto"=>"25", "oculto"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											 ),
									   array("titulo"=>"CPRO", "clase"=>"FormTitulo", "tamano"=>"50", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"PRODUCTO", "clase"=>"FormTitulo", "tamano"=>"300",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"TIP", "clase"=>"FormTitulo", "tamano"=>"50", "fijo"=>"SI", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple")
											),										   
									   array("titulo"=>"UM", "clase"=>"FormTitulo", "tamano"=>"50", "fijo"=>"SI", "alinear"=>"center",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"PRECIO", "clase"=>"FormTitulo", "tamano"=>"50", "fijo"=>"SI", "alinear"=>"right",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"CANT.", "clase"=>"FormTitulo", "tamano"=>"20", "alinear"=>"right",
											 "campo"=>array("tipo"=>"simple")
											),
									   array("titulo"=>"MONTO", "clase"=>"FormTitulo", "tamano"=>"30", "alinear"=>"right", 
											 "campo"=>array("tipo"=>"simple", "alinear"=>"rigth")
											),
									   array("titulo"=>"DEVOL.", "clase"=>"FormTitulo", "tamano"=>"20", "oculto"=>"SI",
											 "campo"=>array("tipo"=>"simple")
											)
									   )
						);
		
		$varTabs =array(array("name"=>"Detalle del Documento",
							  "tipo"=>"det",  "alto"=>"300", "ancho"=>"850", "tabla"=>$varTab_1
							  )
						);
		$varReturn.= $this->setTablaFormTabs($varFormu, $varTabla, $varTabs);
		$varReturn.= "</form>";
		if($varExiste>0)
			return $varReturn;
		else {
			$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"530", "clase"=>"FormTitulo", "titulo"=>"NO HAY DATOS QUE MOSTRAR",
							"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST"),						
							"boton"=>array(array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
												 "clase"=>"boton_cancelar", "texto"=>"Regresar", "click"=>"javascrip:xajax_xRegresar()"))
							);
			return $this->setTablaForm($varTabla);
			}
		}
			
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))  ? $_SESSION["_CUSE"] : "1";		
		$varEmp = (isset($varForm["emp"]) && $varForm["emp"]<>"")?$varForm["emp"]:"NULL";
		$varVen = (isset($varForm["ide"]) && $varForm["ide"]<>"")?$varForm["ide"]:"NULL";
		$varMot = (isset($varForm["mot"]) && $varForm["mot"]<>"")?$varForm["mot"]:"NULL";
		if($varForm["opt"]=="PAR") {
			foreach ($varForm["pro"] as $varCod) {
					$varTip = $varForm["tip"][$varCod];
					$varPro = substr($varForm["pro"][$varCod],0,6);
					$varDev = $varForm["dev"][$varCod];
					$sql.= "call spMante_Venta_Devolver_Parcial($varEmp, $varVen, '$varPro','$varTip', $varDev, $varMot ,$varUsr);";
					}
			}
		elseif($varForm["opt"]=="TOT") {
			$sql = "call spMante_Venta_Devolver_Total($varEmp, $varVen, $varMot ,$varUsr);";
			}
		
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		return "OK";
		}
	}
	
?>