<?php
//include "clase.conexion.php";
class clsCXPEstadoCuenta extends clsConexion{
	public $varTitulo = "ESTADO DE CUENTA PROVEEDORES";
	public $varMyTabla  = "_sv_compra";
	public $varMyID  	  = "id_compra";
	function FormuBusqueda() {
		$varEst = array("AC"=>"ACTIVO", "CA"=>"CANCELADO","AN"=>"ANULADO");
		$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),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$Opcion)
									  ),
						"conte"=>array(array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"text", "id"=>"pcod", "name"=>"pcod", "valor"=>$varPCOD, 
																					 "ancho"=>"50",  "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_proveedor_cxp(this.value)", 
																					 "dclick"=>"fn_cargar_listado_proveedor_cxp('pcod', 'pnom')"),
																			   array("tipo"=>"text", "id"=>"pnom", "name"=>"pnom", "valor"=>$varPNOM, 
																			   		 "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",
																					 "ancho"=>"130", "valor"=>$varFINI)
																			   )
														 	)
											 ),
									   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"=>$varFFIN)
																			   )
														 	)
											 )
									 ),
					  "boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"100", "texto"=>"Buscar",
					  					   "clase"=>"boton_buscar", "click"=>"javascript:xBuscarJS()"),							
									 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, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varPro = (isset($varForm["pcod"]) && $varForm["pcod"]<>'')? $varForm["pcod"]:"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_CXP_Estado_Cuenta($varPro, $varIni, $varFin);";
		
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"800", "sql_cab"=>$sql, "pages"=>50,
						"conte"=>array(array("tamano"=>20, "titulo"=>"IDE", "alinear"=>"center"),
									   array("tamano"=>30, "titulo"=>"FECHA", "alinear"=>"center"),
									   array("tamano"=>50, "titulo"=>"DOCUMENTO", "funcion"=>array("contar")),
									   array("tamano"=>250,"titulo"=>"DESCRIPCION", "fijo"=>"SI"),							   
									   array("tamano"=>60, "titulo"=>"DEBE", "alinear"=>"right"),
									   array("tamano"=>60, "titulo"=>"HABER", "alinear"=>"right"),
									   array("tamano"=>60, "titulo"=>"SALDO", "alinear"=>"right")
									   )
						);
		return $this->SetGridTabla($varTabla);
		}
	
	function Imprimir ($varPro = NULL, 
					   $varIni = NULL,
					   $varFin = NULL
					   )  {
						  
		$varPro = (isset($varPro) && $varPro<>'')?$varPro:"NULL";
		$varIni = (isset($varIni) && $varIni<>'')?"'".FechaMySql($varIni)."'":"NULL";
		$varFin = (isset($varFin) && $varFin<>'')?"'".FechaMySql($varFin)."'":"NULL";
		
		$sql = "call spQuery_CXP_Estado_Cuenta($varPro, $varIni, $varFin);";
		
		$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 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>REPORTE DE PAGOS A PROVEEDORES</b></td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"><b></b></td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.MostrarFechaActual().'</b></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">FECHA</td>';
			$html.='<td width="30">&nbsp;&nbsp;DOCUMENTO</td>';
			$html.='<td width="50">&nbsp;&nbsp;DESCRIPCION</td>';
			$html.='<td width="50" align="right">DEBE</td>';
			$html.='<td width="50" align="right">HABER</td>';
			$html.='<td width="50" align="right">SALDO</td>';
			$html.='</tr>';
			$html.='</thead>';
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			while($fila = $this->FetchArray($rs))	{
				$varSaldo = $fila["saldo"];
				$html.='<tr class="list_row">
						<td NOWRAP align="center">'.$fila["ide"].'</td>
						<td NOWRAP align="center">'.$fila["fecha"].'</td>
						<td NOWRAP>'.$fila["documento"].'</td>
						<td NOWRAP>'.$fila["descripcion"].'</td>
						<td NOWRAP align="right">'.number_format($fila["debe"],"2",".",",").'</td>
						<td NOWRAP align="right">'.number_format($fila["haber"],"2",".",",").'</td>
						<td NOWRAP align="right">'.number_format($fila["saldo"],"2",".",",").'</td>
						</tr>';
				}
			$html.='<tr class="head">';
			$html.='<td colspan="6" align="left"><strong>SALDO TOTAL DEL PROVEEDOR :</strong></td>';
			$html.='<td colspan="2" align="right">'.number_format($varSaldo,"2",".",",").'</td>';
			$html.='</tr>';
	
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
				
		$html.='</table>';
		return $html;
		}
		
	function ProcesoGrabar($varForm = NULL) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varPro = (isset($varForm["pro"]) && $varForm["pro"]<>"")? $varForm["pro"] : "NULL";
		$varIde = (isset($varForm["cpag"]) && $varForm["cpag"]<>"")? $varForm["cpag"] : "NULL";
		$varCom = (isset($varForm["ccom"]) && $varForm["ccom"]<>"")? $varForm["ccom"] : "NULL";
		$varTip = (isset($varForm["tip"]) && $varForm["tip"]<>"Ninguno")? $varForm["tip"] : "NULL";
		$varNum = (isset($varForm["num"]) && $varForm["num"]<>"")?"'".$varForm["num"]."'": "NULL";
		$varFec = ($varForm["fpag"]<>"")?"'".FechaMySql($varForm["fpag"])."'":"NULL";
		$varPro = (isset($varForm["pro"]) && $varForm["pro"]<>"")? $varForm["pro"] : "NULL";
		$varSal = (isset($varForm["sal"]) && $varForm["sal"]<>"")? $varForm["sal"] : "NULL";
		$varPag = (isset($varForm["pag"]) && $varForm["pag"]<>"")? $varForm["pag"] : "NULL";
		$varObs = (isset($varForm["obs"]) && $varForm["obs"]<>"")?"'".$varForm["obs"]."'": "NULL";		
		$sql = "CALL spMante_Pago_CxP('EDIT', $varIde, $varPro, $varCom, $varTip, $varNum, $varFec, $varSal, $varPag, $varObs, $varUsr);";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();	
		return "OK";
		}
		
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "call spMante_Pago_CxP_Anular($varCod, $varUsr);";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();	
		return "OK";
		}
	}
	
?>