<?php
//include "clase.conexion.php";
class clsAvanceVentasFamilia extends clsConexion{
	public $varTitulo 	= "AVANCE DE VENTAS POR FAMILIA";
	function FormuBusqueda() {
		$sqlmes = "call spQuery_ComboMes_CuotaVentaFamilia('Ninguno');";
		$sqanio = "select distinct id_anio, id_anio from _sv_cuota_venta_familia order by id_anio desc;";
		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"470", "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)
									  ),
						"conte"=>array(array("titulo"=>"Periodo Cuota :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"anio", "name"=>"anio", "valor"=>$_POST[anio],
																				     "combo"=>array("sql"=>$sqanio, "sincod"=>"SI", "titulo"=>"--[[ANIO]]--",
																				     "ancho"=>"83", "reload"=>"xajax_comboCuotaVentaFamilia_Mes(this.value)")),
																			   array("tipo"=>"select", "id"=>"mes", "name"=>"mes", "valor"=>$_POST[mes], 
																			   		 "div"=>"divMes",
																				     "combo"=>array("sql"=>$sqlmes, "titulo"=>"--[[ MES ]]--","ancho"=>"160"))
																			   )
														   )
										    ),
									   array("titulo"=>"Proveedor :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"pcod", "name"=>"pcod", 
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_proveedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_proveedor('pcod', 'pnom')"),
																			   array("tipo"=>"text", "id"=>"pnom", "name"=>"pnom", 
																					 "ancho"=>"300", "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", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_vendedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_vendedor('vcod', 'vnom')"),
																			   array("tipo"=>"text", "id"=>"vnom", "name"=>"vnom", 
																					 "ancho"=>"300", "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"=>"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('', 'NEW')"),
									 )
						);
		return $this->setTablaForm($varTabla);
		}
 	function GridDatos($varForm = NULL
					   )  {
			$varAni = ($varForm["anio"]<>"Ninguno")?"'".$varForm["anio"]."'":"NULL";
			$varMes = ($varForm["mes"]<>"Ninguno")?"'".$varForm["mes"]."'":"NULL";
			$varPro = ($varForm["pcod"]<>"")?$varForm["pcod"]:"NULL";
			$varVen = ($varForm["vcod"]<>"")?$varForm["vcod"]:"NULL";
			$varIni = ($varForm["fini"]<>"")?"'".FechaMySql($varForm["fini"])."'":"NULL";
			$varFin = ($varForm["ffin"]<>"")?"'".FechaMySql($varForm["ffin"])."'":"NULL";
			$sql = "call spQuery_Avance_Ventas_Familia($varAni, $varMes, $varPro, $varVen, $varIni, $varFin);";
			$varCab = array(array("cab"=>"MONTO EN SOLES", "det"=>array("CUOTA","VENTA","%AVAN","NECDIA","TEND","%TEND")),
							array("cab"=>"CANTIDADES", "det"=>array("CUOTA","VENTA","%AVAN","NECDIA","TEND","%TEND")),
							array("cab"=>"COBERTURA", "det"=>array("PDV","PEDID"))
							);
			$varNiv = array(0 =>array("COD"=>"CFAM","DES"=>"FAMILIA"),
							1 =>array("COD"=>"CVEN","DES"=>"VENDEDOR"),
							2 =>array("COD"=>"CTIP","DES"=>"TIPOVEN"));
			$varFor = array(8=>array("tipodat"=>"porc", "formula"=>array("valor1"=>6, "valor2"=>7, "funcion"=>"porc")),
							11=>array("tipodat"=>"porc", "formula"=>array("valor1"=>6, "valor2"=>10, "funcion"=>"porc")),
							14=>array("tipodat"=>"porc", "formula"=>array("valor1"=>12, "valor2"=>13, "funcion"=>"porc")),
							17=>array("tipodat"=>"porc", "formula"=>array("valor1"=>12, "valor2"=>16, "funcion"=>"porc")),
							);
			$varReturn =  $this->setGridCombina($varCab, $sql, $varNiv, NULL, $varFor);
		return $varReturn;
		}
	function Imprimir (	$varAni = NULL, 
						$varMes = NULL,
						$varPro = NULL,
						$varVen = NULL, 
						$varIni = NULL,
						$varFin = NULL
						)  {
						  
		$varAniC = (isset($varAni) && $varAni<>"Ninguno")?"'".$varAni."'":"NULL";
		$varMesC = (isset($varMes) && $varMes<>"Ninguno")?"'".$varMes."'":"NULL";
		$varProC = (isset($varPro) && $varPro<>"")?$varPro:"NULL";
		$varVenC = (isset($varVen) && $varVen<>"")?$varVen:"NULL";
		$varIniC = (isset($varIni) && $varIni<>"")?"'".FechaMySql($varIni)."'":"NULL";
		$varFinC = (isset($varFin) && $varFin<>"")?"'".FechaMySql($varFin)."'":"NULL";
		
		$sql = "call spQuery_Avance_Ventas_Familia($varAniC, $varMesC, $varProC, $varVenC, $varIniC, $varFinC);";
		$varCab = array(array("cab"=>"MONTO EN SOLES", "det"=>array("CUOTA","VENTA","%AVAN","NECDIA","TEND","%TEND")),
						array("cab"=>"CANTIDADES", "det"=>array("CUOTA","VENTA","%AVAN","NECDIA","TEND","%TEND")),
						array("cab"=>"COBERTURA", "det"=>array("PDV","PEDID"))
						);
		$varNiv = array(0 =>array("COD"=>"CFAM","DES"=>"FAMILIA"),
						1 =>array("COD"=>"CVEN","DES"=>"VENDEDOR"),
						2 =>array("COD"=>"CTIP","DES"=>"TIPOVEN"));
		$varFor = array(8=>array("tipodat"=>"porc", "formula"=>array("valor1"=>6, "valor2"=>7, "funcion"=>"porc")),
						11=>array("tipodat"=>"porc", "formula"=>array("valor1"=>6, "valor2"=>10, "funcion"=>"porc")),
						14=>array("tipodat"=>"porc", "formula"=>array("valor1"=>12, "valor2"=>13, "funcion"=>"porc")),
						17=>array("tipodat"=>"porc", "formula"=>array("valor1"=>12, "valor2"=>16, "funcion"=>"porc")),
						);
		
		$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%;">';
		$html.='<tr>';
		$html.='<td style="width: 9%; vertical-align: middle; text-align:left;"><b>Periodo</b></td>';
		$html.='<td style="width: 1%; vertical-align: middle; text-align:center;"><b>:</b></td>';
		$html.='<td style="width: 40%; vertical-align: middle; text-align:left;"><b>'.MesNombreLargo($varMes).' - '.$varAni.'</b></td>';
		$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.Config("SYSEMP").'</b></td>';
		$html.='</tr>';
		$html.='<tr>';
		$html.='<td style="vertical-align: middle; text-align:left;"><b>Periodo</b></td>';
		$html.='<td style="vertical-align: middle; text-align:center;"><b>:</b></td>';
		$html.='<td style="vertical-align: middle; text-align:left;"><b>'.$varIni.' - '.$varFin.'</b></td>';
		$html.='<td style="vertical-align: middle; text-align:right;"><b>'.$this->varTitulo.'</b></td>';
		$html.='</tr>';
		$html.='<tr>';
		$html.='<td style="vertical-align: middle; text-align:left;"><b>Proveedor</b></td>';
		$html.='<td style="vertical-align: middle; text-align:center;"><b>:</b></td>';
		$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"><b>';
		if ($_GET[pro]<>"") {
			$sqlp = "select id_proveedor, nombre from _sv_proveedor where id_proveedor=".$varPro;
			$this->AbrirConexion();
			$rsp = $this->Query($sqlp);
			$this->CerrarConexion();
			$filap = $this->FetchArray($rsp);
			$html.= $filap[0].' - '.$filap[1];
			}
		else {
			$html.= 'TODOS LOS PROVEEDORES';
			}
		$html.='</b></td>';
		$html.='<td style="width: 50%; vertical-align: middle; text-align:right;">'.MostrarFechaActual().'</td>';
		$html.='</tr>';
		$html.='</table>';
		$html.='</td>';
		$html.='</tr>';
		$html.='</thead>';	
		$html.='<tr>';
		$html.='<td>';				
		$html.= $this->setGridCombinaPrint($varCab, $sql, $varNiv, $varFor);
		$html.='</td>';
		$html.='</tr>';			
		$html.='</table>';
		return $html;
		}
	}
?>