<?php
//include "clase.conexion.php";
class clsCXC_EstadoCuenta extends clsConexion{
	public $varTitulo = "ESTADO DE CUENTA DE CLIENTE";
	function FormuBusqueda() {
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"420", "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"=>"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()"),
									 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
					   ) {
		$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;
		
		$sql = "call spQuery_Estado_Cuenta_CxC($varForm[ccod], $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($varCli = NULL,
					  $varIni = NULL,
					  $varFin = NULL
					  )  {		
		$varIni = (isset($varIni) && $varIni<>'')? "'".FechaMySql($varIni)."'":"NULL";
		$varFin = (isset($varFin) && $varFin<>'')? "'".FechaMySql($varFin)."'":"NULL";
		$sql_cli = "select * from _sv_cliente where id_cliente = $varCli";
		$this->AbrirConexion();
		$rs_cli = $this->Query($sql_cli);
		$this->CerrarConexion();
		$fila_cli = $this->FetchArray($rs_cli);
		
		$sql = "call spQuery_Estado_Cuenta_CxC($varCli, $varIni, $varFin);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$varNumCol = $this->NumField($rs);
		$varNumCom = 
		$html.='<table style="width: 98%; padding: 0; margin-top:10px; margin-bottom:10px; margin-left:10px; margin-right:10px; border-collapse:collapse;" align="center">';
		$html.='<thead>';
		$html.='<tr>';
		$html.='<td>';
			$html.='<table style="width: 100%;">';
			$html.='<tr>';
			$html.='<td style="font-size:11px;width:50%;vertical-align:middle;text-align:left;"><b>'.Config("SYSEMP").'</b></td>';
			$html.='<td style="font-size:11px;width:50%;vertical-align:middle;text-align:right;"><b>'.$this->varTitulo.'</b></td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"><b>'.$fila_cli["id_cliente"].' - '.$fila_cli["nombre"].'&nbsp;&nbsp;&nbsp;&nbsp;DNI/'.$fila_cli["dni"].' - RUC/'.$fila_cli["ruc"].'</b></td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.MostrarFechaActual().'</b></td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;">'.$fila_cli["direccion"].'</td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b></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="2" 	class="center">&nbsp;</td>';
			$html.='<td width="10" 	class="left">IDE</td>';
			$html.='<td width="60" class="left">FECHA</td>';
			$html.='<td width="80" class="left">DOCUMENTO</td>';
			$html.='<td width="350" >DESCRIPCION</td>';
			$html.='<td width="60" class="right">DEBE</td>';
			$html.='<td width="600" class="right">HABER</td>';
			$html.='<td width="600" class="right">SALDO</td>';
			$html.='<td width="2" 	class="center">&nbsp;</td>';
			$html.='</tr>';
			$html.='</thead>';
			
			$varSaldo;
			
			while($fila = $this->FetchArray($rs))	{
				$varSaldo = $fila["saldo"];
				$html.='<tr class="list_row">
							<td class="center">&nbsp;</td>
							<td class="left">'.$fila["ide"].'</td>
							<td NOWRAP>'.$fila["fecha"].'</td>
							<td NOWRAP>'.$fila["documento"].'</td>
							<td NOWRAP>'.$fila["descripcion"].'</td>
							<td class="right">'.number_format($fila["debe"],"2",".",",").'</td>
							<td class="right">'.number_format($fila["haber"],"2",".",",").'</td>
							<td class="right">'.number_format($fila["saldo"],"2",".",",").'</td>
							<td class="center">&nbsp;</td>
						</tr>';
				}
			$html.='<tr class="head">';
			$html.='<td class="center"></td>';
			$html.='<td colspan="6" class="left"><strong>SALDO TOTAL DEL CLIENTE</strong></td>';
			$html.='<td class="right">'.number_format($varSaldo,"2",".",",").'</td>';
			$html.='<td class="center"></td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
				
		$html.='</table>		
				</body>
				</html>';
		return $html;
		}		
	}
	
?>