<?php
//include "clase.conexion.php";
class clsCuotaVenta extends clsConexion{
	public $varTitulo 	= "CUOTAS DE VENTA POR FAMILIA & SUBFAMILIA";
	function FormuBusqueda() {
		$sqlmes = "call spQuery_Combo_CuotaVenta_Mes('Ninguno');";
		$sqanio = "call spQuery_Combo_CuotaVenta_Anio();";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"430", "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"=>NULL, 
																					 "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"=>NULL, 
																					 "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",
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_vendedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_vendedor('vcod', 'vnom')"),
																			   array("tipo"=>"text", "id"=>"vnom", "name"=>"vnom", 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),
									   array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"pcod", "name"=>"pcod",
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "blur"=>"xajax_seleccionar_proveedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_proveedor('pcod', 'pnom','PR')"),
																			   array("tipo"=>"text", "id"=>"pnom", "name"=>"pnom", 
																					 "ancho"=>"250", "clase"=>"inputDisable", "locked"=>"SI")
																			   )
															)
											 ),
									   array("titulo"=>"Periodo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"anio", "name"=>"anio", 
																					 "valor"=>"Ninguno", "sql"=>$sqanio, "sincod"=>"SI", 
																					 "titulo"=>"--[[ANIO]]--",
																				     "ancho"=>"83", "reload"=>"xajax_comboMesMetas(this.value)"),
																			   array("tipo"=>"select", "id"=>"mes", "name"=>"mes", "valor"=>NULL, 
																			   		 "div"=>"divMes", "sql"=>$sqlmes, "titulo"=>"--[[ MES ]]--",
																					 "ancho"=>"160")
																			   )
														   )
										    )
									   ),
						  "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
					   ) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varAni = ($varForm["anio"]=="Ninguno")?"NULL":"'".$varForm["anio"]."'";
		$varMes = ($varForm["mes"]=="Ninguno")?"NULL":"'".$varForm["mes"]."'";
		$varEmp = ($varForm["ecod"]=="")?"NULL":$varForm["ecod"];
		$varVen = ($varForm["vcod"]=="")?"NULL":$varForm["vcod"];
		$varPro = ($varForm["pcod"]=="")?"NULL":$varForm["pcod"];
		$sql = "call spQuery_Cuota_Venta_Familia($varAni, $varMes, $varEmp, $varPro, $varVen, $varUsr, 'CEMP, CPRO, CVEN, CTIP, CFAM, CSUB', NULL)";
		$varCab = array(array("cab"=>"FAMILIA", "det"=>array("CTIP","TIPO","CFAM","FAMILIA","CSUB","SUB FAMILIA")),
						array("cab"=>"CUOTA ".$varForm["anio"]."-".$varForm["mes"], "det"=>array("MONTO","CANTIDAD"))
						);
		$varNiv = array(0 =>array("COD"=>"CVEN","DES"=>"VENDEDOR"),
						1 =>array("COD"=>"CPRO","DES"=>"PROVEEDOR"),
						2 =>array("COD"=>"CEMP","DES"=>"EMPRESA"));
		$varFor = array(4=>array("tipodat"=>"texto", "alinear"=>"center"),
						6=>array("tipodat"=>"texto", "alinear"=>"center"),
						7=>array("tipodat"=>"texto", "alinear"=>"left"),
						8=>array("tipodat"=>"texto", "alinear"=>"center"),
						9=>array("tipodat"=>"texto", "alinear"=>"left"),
						10=>array("tipodat"=>"texto", "alinear"=>"center"),
						11=>array("tipodat"=>"texto", "alinear"=>"left"),
						);
		$varBot = array(array("tipo"=>"img", "id"=>"bbus", "name"=>"bbus", "img"=>"../images/16x16/table_edit.png", 
							  "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>EDITAR</b> EL REGISTRO<br>"),
											  array("valor"=>"<b>Periodo &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</b> "),
											  array("valor"=>$varForm["anio"], "tipo"=>"TEXTO"),
											  array("valor"=>" - "),
											  array("valor"=>$varForm["mes"], "tipo"=>"TEXTO"),
											  array("valor"=>"<br><b>Empresa &nbsp;&nbsp;&nbsp;: </b>"),
											  array("valor"=>0, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>1, "tipo"=>"INDEX"),
											  array("valor"=>"<br><b>Vendedor &nbsp;&nbsp;: </b>"),
											  array("valor"=>4, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>5, "tipo"=>"INDEX"),
											  array("valor"=>"<br><b>Proveedor : </b>"),
											  array("valor"=>2, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>3, "tipo"=>"INDEX"),
											  array("valor"=>"<br><b>Tipo &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </b>"),
											  array("valor"=>6, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>7, "tipo"=>"INDEX"),
											  array("valor"=>"<br><b>Familia &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </b>"),
											  array("valor"=>8, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>9, "tipo"=>"INDEX"),
											  array("valor"=>"<br><b>Sub Familia : </b>"),
											  array("valor"=>10, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>11, "tipo"=>"INDEX")
											  ),
							  "click"=>array("funcion"=>"FormuRegistroJS",
											 "param"=>array(array("valor"=>"EDIT", "tipo"=>"TEXTO"),
														    array("valor"=>$varForm["anio"], "tipo"=>"TEXTO"),
														    array("valor"=>$varForm["mes"],	"tipo"=>"TEXTO"),
														    array("valor"=>0, 	  "tipo"=>"INDEX"),
														    array("valor"=>4, 	  "tipo"=>"INDEX"),
														    array("valor"=>2, 	  "tipo"=>"INDEX"),
															array("valor"=>6, 	  "tipo"=>"INDEX"),
															array("valor"=>8, 	  "tipo"=>"INDEX"),
															array("valor"=>10, 	  "tipo"=>"INDEX")
														    )
											 )
							 
							  ),
					    array("tipo"=>"img", "id"=>"badd", "name"=>"badd", "img"=>"../images/16x16/table_delete.png", 
							  "toltip"=>array(array("valor"=>"HAGA CLICK PARA <b>ELIMINAR</b> EL REGISTRO<br>"),
											  array("valor"=>"<b>Periodo &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</b> "),
											  array("valor"=>$varForm["anio"], "tipo"=>"TEXTO"),
											  array("valor"=>" - "),
											  array("valor"=>$varForm["mes"], "tipo"=>"TEXTO"),
											  array("valor"=>"<br><b>Empresa &nbsp;&nbsp;&nbsp;: </b>"),
											  array("valor"=>0, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>1, "tipo"=>"INDEX"),
											  array("valor"=>"<br><b>Vendedor &nbsp;&nbsp;: </b>"),
											  array("valor"=>4, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>5, "tipo"=>"INDEX"),
											  array("valor"=>"<br><b>Proveedor : </b>"),
											  array("valor"=>2, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>3, "tipo"=>"INDEX"),
											  array("valor"=>"<br><b>Tipo &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </b>"),
											  array("valor"=>6, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>7, "tipo"=>"INDEX"),
											  array("valor"=>"<br><b>Familia &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </b>"),
											  array("valor"=>8, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>9, "tipo"=>"INDEX"),
											  array("valor"=>"<br><b>Sub Familia : </b>"),
											  array("valor"=>10, "tipo"=>"INDEX"),
											  array("valor"=>" - "),
											  array("valor"=>11, "tipo"=>"INDEX")
											 ),
							  "click"=>array("funcion"=>"xEliminarJS",
											 "param"=>array(array("valor"=>$varForm["anio"], "tipo"=>"TEXTO"),
														    array("valor"=>$varForm["mes"],	"tipo"=>"TEXTO"),
														    array("valor"=>0, 	  "tipo"=>"INDEX"),
														    array("valor"=>4, 	  "tipo"=>"INDEX"),
														    array("valor"=>2, 	  "tipo"=>"INDEX"),
														    array("valor"=>6, 	  "tipo"=>"INDEX"),
															array("valor"=>8, 	  "tipo"=>"INDEX"),
															array("valor"=>10, 	  "tipo"=>"INDEX"),
														    array("valor"=>"this", "tipo"=>"NUM"),
														    )
											 )
							  )
						);
		$varReturn.=  $this->setGridCombina($varCab, $sql, $varNiv, $varBot, $varFor);
		return$varReturn;
		}
	
	function FormuRegistro($varOpt=NULL, $varAnio=NULL, $varMes=NULL, $varEmp=NULL, $varVen=NULL, $varPro=NULL, 
						   $varTip=NULL, $varFam=NULL, $varSub=NULL) {
		if($varOpt=="NEW") {
			$SubTit = $this->varTitulo." - NUEVO";
			$Permite = $_SESSION["_FINS"];
			$varLock = "NO";
			$Fila = NULL;
			$sqlpro = "";
			$sqlven = "";
			$sqltip = "call spQuery_Lista_Producto_Tipo_Prov(0);";
			$sqlfam = "call spQuery_Lista_Producto_Familia_Prov(0, NULL);";
			$sqlsub = "call spQuery_Lista_Producto_SubFamilia_Prov(0, NULL);";
			}
		else {
			$SubTit =  $this->varTitulo." - EDITAR";
			$varLock = "SI";
			$sql = "select id_anio, id_mes, id_empresa, id_proveedor, id_trabajador, id_tipo, id_familia, id_sub_familia, monto, cantidad
					from _sv_cuota_venta_familia
					where id_anio 		= '$varAnio'
					and id_mes 	  		= '".substr($varMes,0,2)."'
					and id_empresa		= $varEmp
					and id_trabajador 	= $varVen
					and id_proveedor 	= $varPro
					and id_tipo 		= '$varTip'
					and id_familia 		= '$varFam'
					and id_sub_familia 	= '$varSub'
					;";	
			$this->AbrirConexion();
			$rs = $this->Query($sql);
			$this->CerrarConexion();
			$Fila = $this->FetchArray($rs);
			$sqltip = "call spQuery_Lista_Producto_Tipo_Prov($Fila[id_proveedor]);";
			$sqlfam = "call spQuery_Lista_Producto_Familia_Prov($Fila[id_proveedor], '$Fila[id_tipo]');";
			$sqlsub = "call spQuery_Lista_Producto_SubFamilia_Prov($Fila[id_proveedor], '$Fila[id_familia]');";
			}
		$sqlemp = "call spQuery_Lista_Empresa($_SESSION[_CUSE], NULL,NULL);";
		$sqlpro = "call spQuery_Lista_Proveedor('PR', NULL, NULL);";
		$sqlven = "call spQuery_Lista_Trabajador('VEN',NULL,NULL,NULL);";
		$sqanio = "call spQuery_Anio();";
		$sqlmes = array("01"=>"ENERO",
						"02"=>"FEBRERO",
						"03"=>"MARZO",
						"04"=>"ABRIL",
						"05"=>"MAYO",
						"06"=>"JUNIO",
						"07"=>"JULIO",
						"08"=>"AGOSTO",
						"09"=>"SETIEMBRE",
						"10"=>"OCTUBRE",
						"11"=>"NOVIEMBRE",
						"12"=>"DICIEMBRE");
		
		
		$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),
									   array("tipo"=>"oculto", "id"=>"anio1",  "name"=>"anio1",  "valor"=>$Fila["id_anio"]),
									   array("tipo"=>"oculto", "id"=>"mes1",  "name"=>"mes1",  "valor"=>$Fila["id_mes"]),
									   array("tipo"=>"oculto", "id"=>"emp1",  "name"=>"emp1",  "valor"=>$Fila["id_empresa"]),
									   array("tipo"=>"oculto", "id"=>"ven1",  "name"=>"ven1",  "valor"=>$Fila["id_trabajador"]),
									   array("tipo"=>"oculto", "id"=>"pro1",  "name"=>"pro1",  "valor"=>$Fila["id_proveedor"]),
									   array("tipo"=>"oculto", "id"=>"tip1",  "name"=>"tip1",  "valor"=>$Fila["id_tipo"]),
									   array("tipo"=>"oculto", "id"=>"fam1",  "name"=>"fam1",  "valor"=>$Fila["id_familia"]),
									   array("tipo"=>"oculto", "id"=>"sub1",  "name"=>"sub1",  "valor"=>$Fila["id_sub_familia"])
									   ),
						"conte"=>array(array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"emp", "name"=>"emp", 
																					 "valor"=>$Fila["id_empresa"],
																					 "sql"=>$sqlemp, "titulo"=>"--[[SELECCIONAR]]--", "ancho"=>"300", 
																					 "locked"=>$varLock,
																					 "valor"=>$Fila["id_empresa"])
																			   )
														   )
										     ),
									   array("titulo"=>"Periodo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"anio", "name"=>"anio", 
																					 "valor"=>$Fila["id_anio"], "sql"=>$sqanio, "titulo"=>"--[[ANIO]]--", 
																					 "ancho"=>"86", "sincod"=>"SI", "locked"=>$varLock),
																			   array("tipo"=>"select_simple", "id"=>"mes", "name"=>"mes", 
																			   		 "valor"=>$Fila["id_mes"], 
																				     "combo"=>array("sql"=>$sqlmes, "titulo"=>"--[[ MES ]]--", 
																					 "ancho"=>"210", "locked"=>$varLock))
																			   )
														   )
										     ),
										array("titulo"=>"Vendedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"ven", "name"=>"ven", "div"=>"divVen",
																					 "valor"=>$Fila["id_trabajador"], "sql"=>$sqlven, 
																					 "titulo"=>"--[[SELECCIONAR]]--", "ancho"=>"300", "locked"=>$varLock)
																			   )
														   )
										     ),
										array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"pro", "name"=>"pro", "div"=>"divPro",
																					 "valor"=>$Fila["id_proveedor"], "sql"=>$sqlpro, 
																					 "titulo"=>"--[[SELECCIONAR]]--", "ancho"=>"300", "locked"=>$varLock,
																					 "reload"=>"xajax_Combo_Producto_Tipo_Prov(this.value, 'tip','300')")
																			   )
														   )
										     ),
										array("titulo"=>"Tipo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"tip", "name"=>"tip", "div"=>"divTip",
																					 "valor"=>$Fila["id_tipo"], 
																					 "sql"=>$sqltip, "sincod"=>"SI", "titulo"=>"--[[SELECCIONAR]]--", 
																					 "ancho"=>"300", "locked"=>$varLock,
																					 "reload"=>"xajax_Combo_Producto_Familia_Prov(pro,value, this.value, 
																					 'fam', '300')")
																			   )
														   )
										     ),
										array("titulo"=>"Familia :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"fam", "name"=>"fam", "div"=>"divFam",
																					 "valor"=>$Fila["id_familia"], 
																					 "sql"=>$sqlfam, "sincod"=>"SI", "titulo"=>"--[[SELECCIONAR]]--", 
																					 "ancho"=>"300", "locked"=>$varLock,
																					 "reload"=>"xajax_Combo_Producto_SubFamilia_Prov(pro,value, 
																					 this.value, 'sub', '300')")
																			   )
														   )
										     ),
										array("titulo"=>"Sub Familia :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"sub", "name"=>"sub", "div"=>"divSub",
																					 "valor"=>$Fila["id_sub_familia"], 
																					 "sql"=>$sqlsub, "sincod"=>"SI", "titulo"=>"--[[SELECCIONAR]]--", 
																					 "ancho"=>"300", "locked"=>$varLock)
																			   )
														   )
										     ),
										array("titulo"=>"Monto :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"mon", "name"=>"mon", "valor"=>$Fila["monto"], "ancho"=>"100",
															 "keypress"=>"return SoloNumeros(event)", "alinear"=>"center")
											),
									   array("titulo"=>"Cantidad :", "clase1"=>"FormCampo1", "clase2"=>"interior", 
											 "campo" =>array("tipo"=>"texto", "id"=>"can", "name"=>"can", "valor"=>$Fila["cantidad"], "ancho"=>"100",
															 "keypress"=>"return SoloNumeros(event)", "alinear"=>"center")
											),
									   ),
						"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 Imprimir (
					$varAni = NULL, 
					$varMes = NULL,
					$varEmp = NULL,
					$varPro = NULL, 
					$varVen = NULL
					)  {
		
		if($varEmp<>"") {
			$sql_emp = "select concat(id_empresa, ' - ', nombre) as empresa from _sv_empresa where id_empresa=$varEmp;";
			$this->AbrirConexion();
			$rs_emp = $this->Query($sql_emp);
			$this->CerrarConexion();
			$fila_emp = $this->FetchArray($rs_emp);
			$varCadEmp = $fila_emp[0];
			}
		else $varCadEmp = "TODAS LAS EMPRESAS";
		
		if($varPro<>"") {
			$sql_pro = "select concat(id_proveedor, ' - ', nombre) as proveedor from _sv_proveedor where id_proveedor=$varPro;";
			$this->AbrirConexion();
			$rs_pro = $this->Query($sql_pro);
			$this->CerrarConexion();
			$fila_pro = $this->FetchArray($rs_pro);
			$varCadPro = $fila_pro[0];
			}
		else {
			$varCadPro = "TODOS LOS PROVEEDORES";
			$varPro = "NULL";
			}
							  
		$varCadPer = MesNombreLargo($varMes).' - '.$varAni;
		$varPer = $varAni."-".$varMes;
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varAni = ($varAni=="Ninguno")?"NULL":"'".$varAni."'";
		$varMes = ($varMes=="Ninguno")?"NULL":"'".$varMes."'";
		$varEmp = ($varEmp=="")?"NULL":$varEmp;
		$varVen = ($varForm["vcod"]=="")?"NULL":$varForm["vcod"];
		$varPro = ($varForm["pcod"]=="")?"NULL":$varForm["pcod"];
		$sql = "call spQuery_Cuota_Venta_Familia($varAni, $varMes, $varEmp, $varPro, $varVen, $varUsr, 'CEMP, CPRO, CVEN, CTIP, CFAM, CSUB', NULL)";
		$varCab = array(array("cab"=>"FAMILIA", "det"=>array("CTIP","TIPO","CFAM","FAMILIA","CSUB","SUB FAMILIA")),
						array("cab"=>"CUOTA ".$varPer, "det"=>array("MONTO","CANTIDAD"))
						);
		$varNiv = array(0 =>array("COD"=>"CVEN","DES"=>"VENDEDOR"),
						1 =>array("COD"=>"CPRO","DES"=>"PROVEEDOR"),
						2 =>array("COD"=>"CEMP","DES"=>"EMPRESA"));
		$varFor = array(4=>array("tipodat"=>"texto", "alinear"=>"center"),
						6=>array("tipodat"=>"texto", "alinear"=>"center"),
						7=>array("tipodat"=>"texto", "alinear"=>"left"),
						8=>array("tipodat"=>"texto", "alinear"=>"center"),
						9=>array("tipodat"=>"texto", "alinear"=>"left"),
						10=>array("tipodat"=>"texto", "alinear"=>"center"),
						11=>array("tipodat"=>"texto", "alinear"=>"left"),
						);
							
		$html='<table style="width: 98%; padding: 0; margin-top:10px; margin-bottom:10px; border-collapse:collapse;" align="center">';
		$html.='<thead>';
		$html.='<tr>';
		$html.='<td>';
			$html.='<table style="width: 100%;" cellspacing="0" cellpadding="0">';
			$html.='<tr class="titu_sup" height="25px">';
			$html.='<td colspan="2"><b>'.$this->varTitulo.'</b></td>';
			$html.='</tr>';
			$html.='<tr class="titu_inf">';
			$html.='<td colspan="2">';
			$html.='<div align="left" style=" width:50%;float:left;">'.$_SESSION["_CABR"].' : '.$_SESSION["_NSYS"].'</div>';
    		$html.='<div align="right" style="width:50%;float:left">'.MostrarFechaActual().'</div>';
			$html.='</td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';		
		$html.='<tr>';
		$html.='<td>';
			$html.='<table style="width: 100%;" cellspacing="0" cellpadding="0">';
			$html.='<tr>';
			$html.='<td style="width: 8%; vertical-align: middle; text-align:left;"><b>Empresa </b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="width: 42%; vertical-align: middle; text-align:left;">'.$varCadEmp.'</td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b></b></td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="width: 10%; vertical-align: middle; text-align:left;"><b>Periodo </b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="width: 40%; vertical-align: middle; text-align:left;" nowrap>'.$varCadPer.'</td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"></td>';
			$html.='</tr>';
			$html.='<tr>';
			$html.='<td style="width: 10%; vertical-align: middle; text-align:left;"><b>Proveedor </b></td>';
			$html.='<td style="vertical-align: middle; text-align:left;"><b>:</b></td>';
			$html.='<td style="width: 40%; vertical-align: middle; text-align:left;" nowrap>'.$varCadPro.'</td>';
			$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"></td>';
			$html.='</tr>';
			$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
		$html.='</thead>';	
		$html.='<tr>';
		$html.='<td>';				
		$html.= $this->setGridCombinaPrint($varCab, $sql, $varNiv, NULL, $varFor);
		$html.='</td>';
		$html.='</tr>';			
		$html.='</table>';
		return $html;
		}
		
	function ProcesoGrabar($varForm = NULL) {		
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varOpt = "'".$varForm["opt"]."'";
		$varAni = ($varForm["opt"]=="NEW")?"'".$varForm["anio"]."'":"'".$varForm["anio1"]."'";
		$varMes = ($varForm["opt"]=="NEW")?"'".$varForm["mes"]."'":"'".$varForm["mes1"]."'";
		$varEmp = ($varForm["opt"]=="NEW")?$varForm["emp"]:$varForm["emp1"];
		$varVen = ($varForm["opt"]=="NEW")?$varForm["ven"]:$varForm["ven1"];
		$varPro = ($varForm["opt"]=="NEW")?$varForm["pro"]:$varForm["pro1"];
		$varTip = ($varForm["opt"]=="NEW")?"'".$varForm["tip"]."'":"'".$varForm["tip1"]."'";
		$varFam = ($varForm["opt"]=="NEW")?"'".$varForm["fam"]."'":"'".$varForm["fam1"]."'";
		$varSub = ($varForm["opt"]=="NEW")?"'".$varForm["sub"]."'":"'".$varForm["sub1"]."'";
		$varMon = ($varForm["mon"]=="")?0:$varForm["mon"];
		$varCan = ($varForm["can"]=="")?0:$varForm["can"];
		$sql = "call spMante_Cuota_Venta_Familia($varOpt, $varAni, $varMes,$varEmp, $varVen, $varPro, $varTip, $varFam, $varSub, 
				$varMon, $varCan, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$Fila = $this->FetchArray($rs);
		return $Fila[0];
		}
	function ProcesoEliminar($varAni, $varMes, $varEmp, $varVen, $varPro, $varTip, $varFam, $varSub) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$sql = "delete from _sv_cuota_venta_familia
				where id_anio		= '$varAni'
				and id_mes			= '".substr($varMes,0,2)."'
				and id_empresa		= $varEmp
				and id_trabajador	= $varVen
				and id_tipo			= $varTip
				and id_familia		= $varFam
				and id_sub_familia	= $varSub
				;";
		$this->AbrirConexion();
		$this->Query($sql);
		$this->CerrarConexion();
		}
	}
	
?>