<?php
//include "clase.conexion.php";
class clsCXC_Pagos extends clsConexion{
	public $varTitulo = "MODIFICACION DE PAGOS [CXC]";
	function FormuBusqueda() {
		$sqlven = "call spQuery_Lista_Vendedor('','','');";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"600", "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"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"text", "id"=>"ccod", "name"=>"ccod", "valor"=>$varPCOD, 
																					 "ancho"=>"50",  "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_cliente(this.value)", 
																					 "dclick"=>"fn_cargar_listado_cliente('ccod', 'cnom')"),
																			   array("tipo"=>"text", "id"=>"cnom", "name"=>"cnom", "valor"=>$varPNOM, 
																			   		 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
														 )
										  	 ),
									   array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"lista_doble", "filas"=>8, "ancho"=>"230", "sql"=>$sqlven,
											 				"id1"=>"ven", "name1"=>"ven", "id2"=>"vcod", "name2"=>"vcod",
															"dclick1"=>"mover_lista('right','ven','vcod')", "dclick2"=>"mover_lista('left','ven','vcod')"															
															)
											),
									   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"=>"100", "texto"=>"Buscar",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()")
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	
	function GridDatos($varCli	 = NULL, 
					   $varVen	 = NULL, 
					   $varIni	 = NULL,  
					   $varFin	 = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varCli = (isset($varCli) && $varCli<>'')?$varCli:"NULL";
		$varVen = ($varVen<>"")?"\"(".$varVen.")\"":"NULL";
		$varIni = (isset($varIni) && $varIni<>'')? "'".FechaMySql($varIni)."'":"NULL";
		$varFin = (isset($varFin) && $varFin<>'')? "'".FechaMySql($varFin)."'":"NULL";
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";

		$sql = "call spQuery_Pagos_CxC($varCli, $varVen, $varIni, $varFin, $varFie, $varOrd);";

		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"900", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>20, "titulo"=>"IDE", "alinear"=>"center"),
									   array("tamano"=>30, "titulo"=>"CCLI", "alinear"=>"center"),
									   array("tamano"=>250,"titulo"=>"CLIENTE", "fijo"=>"SI"),
									   array("tamano"=>50, "titulo"=>"DOCUMENTO", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("tamano"=>30, "titulo"=>"CFOR", "alinear"=>"center"),
									   array("tamano"=>250,"titulo"=>"FORMA PAGO", "fijo"=>"SI"),
									   array("tamano"=>30, "titulo"=>"NRO.PAGO", "alinear"=>"center"),
									   array("tamano"=>30, "titulo"=>"FECHA", "alinear"=>"center"),									   
									   array("tamano"=>60, "titulo"=>"MONTO", "alinear"=>"right", "funcion"=>array("autosuma")),
									   array("titulo"=>"FCREADO",  "ancho"=>"100", "alinear"=>"center", "fijo"=>"SI"),
									   array("titulo"=>"FUPDATE",  "ancho"=>"100", "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO",  "ancho"=>"50", "alinear"=>"center"),
									   array("titulo"=>"UUPDATE",  "ancho"=>"50", "alinear"=>"center", "oculto"=>"SI")
									   ),
						"boton"=>array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"images/b_table_edit.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR</b> EL PAGO<br><b>Documento :</b> "),
															 array("valor"=>3, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Cliente :</b> "),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"-"),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Forma Pago :</b> "),
															 array("valor"=>5, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Nro. Pago :</b> "),
															 array("valor"=>6, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Fecha :</b> "),
															 array("valor"=>7, "tipo"=>"INDEX"),
																),
											 "click"=>array("funcion"=>"FormuRegistroJS",
															"param"=>array(array("valor"=>0, 	  "tipo"=>"INDEX"),
																		   array("valor"=>"EDIT", "tipo"=>"TEXTO")
																		  )
															)
											 
											 ),
									   array("tipo"=>"img", "id"=>"badd", "name"=>"badd", "img"=>"images/b_table_delete.png", 
											 "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ELIMINAR</b> EL PAGO<br><b>Documento :</b> "),
															 array("valor"=>3, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Cliente :</b> "),
															 array("valor"=>1, "tipo"=>"INDEX"),
															 array("valor"=>"-"),
															 array("valor"=>2, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Forma Pago :</b> "),
															 array("valor"=>5, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Nro. Pago :</b> "),
															 array("valor"=>6, "tipo"=>"INDEX"),
															 array("valor"=>"<br><b>Fecha :</b> "),
															 array("valor"=>7, "tipo"=>"INDEX"),
															),
											 "click"=>array("funcion"=>"xEliminarJS",
															"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>"this", "tipo"=>"NUM"),
																		   )
															)
											 )
									)
						);
		return $this->SetGridTabla2($varTabla);
		}
	
	function FormuRegistro($varCod=NULL,$varOpt=NULL) {
		$sql = "CALL spQuery_Pagos_CxC_Editar($varCod);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>$this->varTitulo,
						"conte"=>array(array("titulo"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
										 	 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "clase"=>"inputDisable",
										 	 "valor"=>$Fila["CPAG"], "alinear"=>"center", "locked"=>"SI", "ancho"=>"70")),								   
								   	   array("titulo"=>"Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 	 "campo" =>array("tipo"=>"simple", "valor"=>$Fila["CCLI"]." - ".$Fila["CLIENTE"])),
									   array("titulo"=>"Tipo Doc. Pago :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 	 "campo" =>array("tipo"=>"simple", "valor"=>$Fila["CTIP"]." - ".$Fila["TIPO"])),
									   array("titulo"=>"Nro. Doc. Pago :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 	 "campo" =>array("tipo"=>"simple", "valor"=>$Fila["NPAGO"])),
									   array("titulo"=>"Fecha Pago :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 	 "campo" =>array("tipo"=>"simple", "valor"=>$Fila["FECHA"])),
									   array("titulo"=>"Monto :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 	 "campo" =>array("tipo"=>"simple", "valor"=>$Fila["MONTO"])),
								   	   )
						);
		$varTabla2=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>"DOCUMENTO REFERENCIA",
						"conte"=>array(array("titulo"=>"Documento :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
										 	 "campo" =>array("tipo"=>"simple", "ancho"=>"70", "valor"=>$Fila["DOCUMENTO"])),								   
								   	   array("titulo"=>"Fecha :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 	 "campo" =>array("tipo"=>"simple", "valor"=>$Fila["FECHA_EMI"])),
									   array("titulo"=>"Monto Total :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 	 "campo" =>array("tipo"=>"simple", "valor"=>number_format($Fila["MONTO_DOC"], 2,'.',','))),
									   array("titulo"=>"Pagos :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 	 "campo" =>array("tipo"=>"simple", "valor"=>number_format($Fila["PAGOS"], 2,'.',','))),
									   array("titulo"=>"Saldo :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 	 "campo" =>array("tipo"=>"simple", "valor"=>number_format($Fila["SALDO"], 2,'.',',')))
								   	   )
						);
		$varTabla3=array("id"=>"tabla", "name"=>"table", "tamano"=>"450", "clase"=>"FormTitulo", "titulo"=>"NUEVO MONTO DEL PAGO",
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"cod", "name"=>"cod", "valor"=>$Fila["CPAG"]),
									   array("tipo"=>"oculto", "id"=>"sal", "name"=>"sal", "valor"=>$Fila["SALDO_MAX"])
									  ),
						"conte"=>array(array("titulo"=>"Monto Nuevo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
										 	 "campo" =>array("tipo"=>"texto", "id"=>"monto",  "name"=>"monto", "ancho"=>"70", "keypress"=>"return SoloNumeros(event)"))
								   	   ),
						"boton"=>array(array("tipo"=>"button", "id"=>"bsav", "name"=>"bsav", "ancho"=>"100",
											 "clase"=>"boton_guardar", "texto"=>"Grabar", "click"=>"javascrip:xGrabarJS()"),			  
									   array("tipo"=>"button", "id"=>"breg", "name"=>"breg", "ancho"=>"100",
											 "clase"=>"boton_cancelar", "texto"=>"Cancelar", "click"=>"javascrip:xajax_xRegresar()"),
									)
						);
		return $this->setTablaForm($varTabla).$this->setTablaForm($varTabla2).$this->setTablaForm($varTabla3);	
		}
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "CALL spMante_Pago_CxC_Modificar($varForm[cod], $varForm[monto],  '', $varUsr)";  

		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		//$Fila = $this->FetchArray($rs);
		return "OK";
		}
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "call spMante_Pago_CxC_Anular($varCod, $varUsr)";			
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		}
	}
	
?>