<?php
//include "clase.conexion.php";
class clsCliente extends clsConexion{
	public $varTitulo 	= "MAESTRO DE CLIENTES";
	public $varMyTabla  = "_sv_cliente";
	public $varMyID  	= "id_cliente";
	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"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
										 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "valor"=>$_POST["cod"], 
										 "alinear"=>"center", "ancho"=>"70")),								   
								   array("titulo"=>"Nombre :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam", "valor"=>$_POST["nam"], "ancho"=>"306")),
								   array("titulo"=>"Direccion :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
										 "campo" =>array("tipo"=>"texto", "id"=>"dire", "name"=>"dire", "valor"=>$_POST["dire"], "ancho"=>"306")),
								   array("titulo"=>"Ruta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										 "campo"=>array("tipo"=>"varios",
														"contenido"=>array(array("tipo"=>"text", "id"=>"rcod", "name"=>"rcod", "valor"=>$_POST["rcod"], 
																				 "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"=>$_POST["rnom"], 
																			   	 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																		   )
														)
										 ),
								   array("titulo"=>"Modulo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										 "campo"=>array("tipo"=>"varios",
														"contenido"=>array(array("tipo"=>"text", "id"=>"mcod", "name"=>"mcod", "valor"=>$_POST["mcod"], 
																				 "ancho"=>"50", "alinear"=>"center", 
																				 "blur"=>"xajax_seleccionar_modulo(rcod.value, this.value)", 
																				 "dclick"=>"fn_cargar_listado_modulo(rcod.value, 'mcod', 'mnom')"),
																		   array("tipo"=>"text", "id"=>"mnom", "name"=>"mnom", "valor"=>$_POST["mnom"], 
																			   	 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																		   )
														)
										 ),
								   array("titulo"=>"Lista Precios :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										 "campo"=>array("tipo"=>"varios",
														"contenido"=>array(array("tipo"=>"text", "id"=>"lcod", "name"=>"lcod", "valor"=>$_POST["lcod"], 
																				 "ancho"=>"50", "alinear"=>"center", 
																				 "blur"=>"xajax_seleccionar_lista_precios(this.value)", 
																				 "dclick"=>"fn_cargar_listado_precios('lcod', 'lnom')"),
																		   array("tipo"=>"text", "id"=>"lnom", "name"=>"lnom", "valor"=>$_POST["lnom"], 
																			   	 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																		   )
														)
										 )
								   ),
					  "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()"),								
									 array("tipo"=>"button", "id"=>"bimp", "name"=>"bimp", "ancho"=>"100", "texto"=>"Imprimir", 
										   "clase"=>"boton_imprimir", "click"=>"javascript:xImprimirJS()"),
									 array("tipo"=>"button", "id"=>"bnew", "name"=>"bnew", "ancho"=>"100", "texto"=>"Nuevo", 
										   "clase"=>"boton_nuevo", "click"=>"javascript:FormuRegistroJS('', 'NEW')"),
									 )
					);
		return $this->setTablaForm($varTabla);
		}
 	function GridDatos($varForm  = NULL, 
					   $varField = NULL, 
					   $varOrder = NULL
					   ) {
		$varFie = (isset($varField) && $varField<>'')? "'$varField'":"NULL";
		$varOrd = (isset($varOrder) && $varOrder<>'')? "'$varOrder'":"NULL";
		$sql = "call spQuery_Cliente('$varForm[cod]', '$varForm[nam]', '$varForm[dire]', '$varForm[rcod]', '$varForm[mcod]', '$varForm[lcod]', $varFie, $varOrd)";
		$varTabla=array("id"=>"theTable", "name"=>"theTable", "tamano"=>"1200", "sql_cab"=>utf8_decode($sql),	"pages"=>50,
						"conte"=>array(array("titulo"=>"CCLI",   	"ancho"=>"20" , "alinear"=>"center", "clase"=>"sortable-numeric", "tipo"=>"texto"),
									   array("titulo"=>"SECC",   	"ancho"=>"30" , "alinear"=>"center", "clase"=>"sortable-numeric", "tipo"=>"texto"), 
									   array("titulo"=>"CLIENTE",	"ancho"=>"300", "clase"  =>"sortable", "fijo"=>"SI", "funcion"=>array("contar")),
									   array("titulo"=>"DNI", 	 	"ancho"=>"60" , "alinear"=>"center", "clase"=>"sortable-numeric"),
									   array("titulo"=>"RUC", 	 	"ancho"=>"60" , "alinear"=>"center", "clase"=>"sortable-numeric"),
									   array("titulo"=>"DIRECCION", "ancho"=>"200", "clase"=>"sortable", "fijo"=>"SI"),
									   array("titulo"=>"CRUT",     	"ancho"=>"20", "alinear"=>"center"), 
									   array("titulo"=>"RUTA",		"ancho"=>"100", "clase"  =>"sortable", "fijo"=>"SI"),
									   array("titulo"=>"CMOD",     	"ancho"=>"20", "alinear"=>"center"), 
									   array("titulo"=>"MODULO",	"ancho"=>"100", "clase"  =>"sortable"),
									   array("titulo"=>"CLIS",     	"ancho"=>"20" , "oculto"=>"SI"), 
									   array("titulo"=>"LISTA PRECIOS","ancho"=>"100", "clase"  =>"sortable"),
									   array("titulo"=>"CUBI",     "ancho"=>"20" , "oculto"=>"SI"),
									   array("titulo"=>"DEPARTAMENTO", "ancho"=>"100", "clase"=>"sortable", "oculto"=>"SI"),
									   array("titulo"=>"PROVINCIA", "ancho"=>"100", "clase"=>"sortable", "oculto"=>"SI"),
									   array("titulo"=>"DISTRITO", "ancho"=>"100", "clase"=>"sortable", "oculto"=>"SI"),
									   array("titulo"=>"TELEF",  "ancho"=>"60",  "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"CELU.",  "ancho"=>"60",  "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"RPM",    "ancho"=>"60",  "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"RPC",    "ancho"=>"60",  "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"NEXTEL", "ancho"=>"60",  "alinear"=>"center", "oculto"=>"SI"),
									   array("titulo"=>"FCREADO",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"FUPDATE",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UCREADO",  "ancho"=>"100", "oculto"=>"SI"),
									   array("titulo"=>"UUPDATE",  "ancho"=>"100", "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 REGISTRO<br><b>"),
																 array("valor"=>0, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"</b>")
																),
											 "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 REGISTRO<br><b>"),
																 array("valor"=>0, "tipo"=>"INDEX"),
																 array("valor"=>" - "),
																 array("valor"=>2, "tipo"=>"INDEX"),
																 array("valor"=>"</b>")
																),
											 "click"=>array("funcion"=>"xEliminarJS",
															"param"=>array(array("valor"=>0, "tipo"=>"INDEX"),
																		   array("valor"=>2, "tipo"=>"INDEX"),
																		   array("valor"=>"this", "tipo"=>"NUM"),
																		   )
															)
											 )
									)
						);
		return $this->SetGridTabla2($varTabla);
		}
	function FormuRegistro($varCod=NULL,$varOpt=NULL) {
		if($varOpt=="NEW") {
			$SubTit = $this->varTitulo." - NUEVO";
			$Permite = $_SESSION["_FINS"];
			$varLock = "NO";
			$Fila = NULL;
			$Fila["CDEP"] = "14";
			$Fila["CPRO"] = "1401";
			$Fila["CDIS"] = "140101";
			}
		else {
			$SubTit =  $this->varTitulo." - EDITAR";
			$varLock = "SI";
			$sql = "select id_cliente, id_ruta, id_modulo, id_tipo_cliente, id_lista, secuencia,
					substring(id_ubigeo,1,2) as CDEP, substring(id_ubigeo,1,4) as CPRO, id_ubigeo as CDIS,
					nombre, dni, ruc, direccion, referencia, telefono, celular, rpm, rpc, nextel 
					from ".$this->varMyTabla." where ".$this->varMyID." = $varCod";	
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$Fila = $this->FetchArray($rs);
			}
		$sqldep = "call spQuery_Lista_Ubigeo_Dep();";
		$sqlpro = "call spQuery_Lista_Ubigeo_Pro('$Fila[CDEP]');";
		$sqldis = "call spQuery_Lista_Ubigeo_Dis('$Fila[CPRO]');";
		$sqlrut = "call spQuery_Combo_Ruta();";
		$sqltip = "call spQuery_Combo_Tipo_Cliente();";
		$sqlmod = "call spQuery_Combo_Modulo('$Fila[id_ruta]');";
		$sqlven = "call spQuery_Combo_Lista_Precios();";
		
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"400", "clase"=>"FormTitulo", "titulo"=>$SubTit,
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo),
									   array("tipo"=>"oculto", "id"=>"opt", "name"=>"opt", "valor"=>$varOpt)
									  ),
						"conte"=>array(array("titulo"=>"Codigo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "tamano"=>"100",
											 "campo" =>array("tipo"=>"texto", "id"=>"cod", "name"=>"cod", "clase"=>"inputDisable",
											 "valor"=>$Fila[$this->varMyID], "alinear"=>"center", "locked"=>"SI", "ancho"=>"70")),								   
									   array("titulo"=>"Nombre :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"nam", "name"=>"nam", "valor"=>$Fila["nombre"], "ancho"=>"280")),
									   array("titulo"=>"Nro. DNI :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"dni", "name"=>"dni", "valor"=>$Fila["dni"],
																					 "ancho"=>"100", "keypress"=>"return SoloEnteros(event)", "maxchar"=>8),
																			   array("tipo"=>"simple", "valor"=>"Nro. RUC : ", "clase_in"=>"FormCampo1", "ancho"=>"100"),
																			   array("tipo"=>"text", "id"=>"ruc", "name"=>"ruc", "valor"=>$Fila["ruc"],
																					 "ancho"=>"100", "maxchar"=>11),
																			   )
														 	)
											 ),
									   array("titulo"=>"Direccion :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"dir", "name"=>"dir", "valor"=>$Fila["direccion"], "ancho"=>"280")),
									   array("titulo"=>"Referencia :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"area", "id"=>"ref", "name"=>"ref", "valor"=>$Fila["referencia"], "ancho"=>"280")),
									   array("titulo"=>"Tipo de Cliente :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select", "id"=>"tip", "name"=>"tip", "valor"=>$Fila["id_tipo_cliente"],
															"combo"=>array("sql"=>$sqltip, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", 
															"ancho"=>"280"))),
									   array("titulo"=>"Ruta :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select", "id"=>"rut", "name"=>"rut", "valor"=>$Fila["id_ruta"],
															"combo"=>array("sql"=>$sqlrut, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", 
															"ancho"=>"280", "reload"=>"xajax_comboModulo(this.value)"))),
									   array("titulo"=>"Modulo :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divMod",
											 "campo"=>array("tipo"=>"select", "id"=>"mod", "name"=>"mod", "valor"=>$Fila["id_modulo"], "ancho"=>"100",
															"combo"=>array("sql"=>$sqlmod, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", "ancho"=>"280", 
															"reload"=>"xajax_comboDist(this.value)"))),
									   array("titulo"=>"Lista Precios :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"select", "id"=>"lis", "name"=>"lis", "valor"=>$Fila["id_lista"],
															"combo"=>array("sql"=>$sqlven,  "sincod"=>"SI", 
															"ancho"=>"280"))),
									   array("titulo"=>"Secuencia :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"sec", "name"=>"sec", "valor"=>$Fila["secuencia"], "ancho"=>"100",
															 "keypress"=>"return SoloEnteros(event)", "alinear"=>"center")),
									   array("titulo"=>"Departamento :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo"=>array("tipo"=>"select", "id"=>"dep", "name"=>"dep", "valor"=>$Fila["CDEP"], "ancho"=>"100",
															"combo"=>array("sql"=>$sqldep, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", 
															"ancho"=>"180", "reload"=>"xajax_comboProv(this.value)"))),
									   array("titulo"=>"Provincia :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divProv",
											 "campo"=>array("tipo"=>"select", "id"=>"pro", "name"=>"pro", "valor"=>$Fila["CPRO"], "ancho"=>"100",
															"combo"=>array("sql"=>$sqlpro, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", "ancho"=>"180", 
															"reload"=>"xajax_comboDist(this.value)"))),
									   array("titulo"=>"Distrito :", "clase1"=>"FormCampo1", "clase2"=>"interior", "div"=>"divDist",
											 "campo"=>array("tipo"=>"select", "id"=>"dis", "name"=>"dis", "valor"=>$Fila["CDIS"], "ancho"=>"100",
															"combo"=>array("sql"=>$sqldis, "titulo"=>" --[[SELECCIONAR]]-- ", "sincod"=>"SI", 
															"ancho"=>"180"))),
									   array("titulo"=>"# Telefono :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"tel", "name"=>"tel", "valor"=>$_POST["telefono"],
																					 "ancho"=>"100", "keypress"=>"return SoloEnteros(event)"),
																			   array("tipo"=>"simple", "valor"=>"# Celular : ", "clase_in"=>"FormCampo1", "ancho"=>"100"),
																			   array("tipo"=>"text", "id"=>"cel", "name"=>"cel", "valor"=>$_POST["celular"],
																					 "ancho"=>"100", "keypress"=>"return SoloEnteros(event)"),
																			   )
														 	)
											 ),
									   array("titulo"=>"# RPM :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"rpm", "name"=>"rpm", "valor"=>$_POST["rpm"],
																					 "ancho"=>"100", "keypress"=>"return SoloEnteros(event)"),
																			   array("tipo"=>"simple", "valor"=>"# RPC : ", "clase_in"=>"FormCampo1", "ancho"=>"100"),
																			   array("tipo"=>"text", "id"=>"rpc", "name"=>"rpc", "valor"=>$_POST["rpc"],
																					 "ancho"=>"100"),
																			   )
														 	)
											 ),
									   array("titulo"=>"# Nextel :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"nex", "name"=>"nex", "valor"=>$_POST["nextel"],
																					 "ancho"=>"100")
																			   )
														 	)
											 )
									   ),
						"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);	
		}
		
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varCod = ($varForm["cod"]=="")? "NULL" : "$varForm[cod]";
		$varNam = ($varForm["nam"]=="")? "NULL" : "'$varForm[nam]'";
		$varDni = ($varForm["dni"]=="")? "NULL" : "'$varForm[dni]'";
		$varRuc = ($varForm["ruc"]=="")? "NULL" : "'$varForm[ruc]'";	
		$varDir = ($varForm["dir"]=="")? "NULL" : "'$varForm[dir]'";
		$varTip = ($varForm["tip"]=="Ninguno")? "0" : "$varForm[tip]";
		$varRut = ($varForm["rut"]=="Ninguno")? "'0'" : "'$varForm[rut]'";
		$varMod = ($varForm["mod"]=="Ninguno")? "0" : "$varForm[mod]";	
		$varLis = ($varForm["lis"]=="Ninguno")? "0" : "$varForm[lis]";	
		$varDis = ($varForm["dis"]=="")? "NULL" : "'$varForm[dis]'";	
		$varTel = ($varForm["tel"]=="")? "NULL" : "'$varForm[tel]'";
		$varCel = ($varForm["cel"]=="")? "NULL" : "'$varForm[cel]'";
		$varRpm = ($varForm["rpm"]=="")? "NULL" : "'$varForm[rpm]'";
		$varRpc = ($varForm["rpc"]=="")? "NULL" : "'$varForm[rpc]'";
		$varNex = ($varForm["nex"]=="")? "NULL" : "'$varForm[nex]'";
		$varSec = ($varForm["sec"]=="")? "NULL" : "$varForm[sec]";
		$varRef = ($varForm["ref"]=="")? "NULL" : "'$varForm[ref]'";
		
		$sql = "call spMante_Cliente('$varForm[opt]', $varCod, $varNam, $varDni, $varRuc, $varDir, $varRef, $varTip, $varRut, '$varMod', $varLis, $varDis,
									 $varTel, $varCel, $varRpm, $varRpc, $varNex, $varSec, $varUsr);";
									 
		$this->AbrirConexion();
		$rs = $this->Query(utf8_decode($sql));
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		return $Fila[0];		
		}
	function ProcesoEliminar($varCod) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "update ".$this->varMyTabla." set _estado = 'X', _date_update=NOW(), _user_update=$varUsr where ".$this->varMyID."= '".$varCod."';";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		}
	function Imprimir($varRut = NULL
					  )  {		
		$sql = "select
				C.id_ruta as CRUT, R.nombre as RUTA,
				IFNULL(C.id_modulo,0) AS CMOD, IFNULL(M.nombre,'SIN MODULO') AS MODULO,
				LPAD(ifnull(SECUENCIA,0),5,'0') as SECUENCIA, T.nombre as TIPO,
				LPAD(id_cliente,6,'0') AS CCLI, UPPER(C.nombre) AS CLIENTE, C.DIRECCION,
				case when ifnull(ruc,'')='' then CONCAT('DNI/',dni) else CONCAT('RUC/',RUC) end as DOCIDE,
				id_lista as LP,
				DATEDIFF(now(),ultima_compra) as DIASNC
				from _sv_cliente C
				left join _sv_tipo_cliente T ON C.id_tipo_cliente = T.id_tipo_cliente
				inner join _sv_ruta R ON C.id_ruta = R.id_ruta
				left join _sv_modulo M ON C.id_modulo = M.id_modulo
				where C._estado = 'A'
				and C.id_ruta like '%$varRut%'
				order by C.id_ruta, IFNULL(C.id_modulo,0), C.secuencia, C.nombre;";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$varNumCol = $this->NumField($rs);
		$varNumCom = 
		$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="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></b></td>';
			$html.='<td style="font-size:9px;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="10">&nbsp;&nbsp;</td>';
			$html.='<td width="10"  style="font-size:9px;">SEC</td>';
			$html.='<td width="10"  style="font-size:9px;">CCLI</td>';
			$html.='<td width="150" style="font-size:9px;">CLIENTE</td>';
			$html.='<td width="150" style="font-size:9px;">DIRECCION</td>';
			$html.='<td width="50"  class="left" style="font-size:9px;">DNI/RUC</td>';
			$html.='<td width="50"  class="right" style="font-size:9px;">LP</td>';
			$html.='<td width="50"  class="right" style="font-size:9px;">NC</td>';
			$html.='</tr>';
			$html.='</thead>';
			
			$varRut_Ant = $varRut_Act = "";
			$varMod_Ant = $varMod_Act = "";
			while($fila = $this->FetchArray($rs))	{
				$varRut_Act = $fila["CRUT"];
				$varMod_Act = $fila["CMOD"];
				$varTotal1 = $varTotal1 + $fila["CANTIDAD"];
				$varTotal2 = $varTotal2 + $fila["MONTO"];
				$varNumDoc++;
				if($varRut_Act <> $varRut_Ant) {
					$varRut_Ant = $fila["CRUT"];
					$varMod_Ant = $fila["CMOD"];
					$html.='<tr class="head">';
					$html.='<td colspan="8" style="font-size:9px;"><b>'.$fila["CRUT"].' - '.$fila["RUTA"].'</b></td>';
					$html.='</tr>';
					$html.='<tr class="head">';
					$html.='<td colspan="8" style="font-size:9px;"><b>'.$fila["CMOD"].' - '.$fila["MODULO"].'</b></td>';
					$html.='</tr>';
					}
				if($varMod_Act <> $varMod_Ant) {
					$varMod_Ant = $fila["CMOD"];					
					$html.='<tr class="head">';
					$html.='<td colspan="8" style="font-size:9px;"><b>'.$fila["CMOD"].' - '.$fila["MODULO"].'</b></td>';
					$html.='</tr>';
					}
				$html.='<tr class="list_row">';
				$html.='<td></td>';
				$html.='<td>'.$fila["SECUENCIA"].'</td>';
				$html.='<td NOWRAP>'.$fila["CCLI"].'</td>';
				$html.='<td NOWRAP>'.$fila["CLIENTE"].'</td>';
				$html.='<td NOWRAP>'.$fila["DIRECCION"].'</td>';
				$html.='<td NOWRAP>'.$fila["DOCIDE"].'</td>';
				$html.='<td class="center" NOWRAP>'.$fila["LP"].'</td>';
				$html.='<td class="right" NOWRAP>'.$fila["DIASNC"].'</td>';
				$html.='</tr>';
				}
			$html.='<tr class="head">';
			$html.='<td colspan="4" class="left"><strong>Totales :</strong></td>';
			$html.='<td >'.number_format($varNumDoc,"0",".",",").' Clientes</td>';
			$html.='<td class="right"></td>';
			$html.='<td class="right"></td>';
			$html.='<td class="right"></td>';	
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
				
		$html.='</table>		
				</body>
				</html>';
		return $html;
		}
	}
	
?>