<?php
//include "clase.conexion.php";
class clsAnalCompVendedor extends clsConexion{
	public $varTitulo 	= "ANALISIS COMPARATIVO POR DIA DE VENTAS POR VENDEDOR";
	function FormuBusqueda() {
		$sqlani = "select distinct id_anio, id_anio from _sv_metas order by id_anio desc;";
		$sqltip = array("V" => "VALOR VENTA", "I" => "IGV", "T" => "VENTA TOTAL");
		$varMes = array("01"=>"01 - ENERO",
						"02"=>"02 - FEBRERO",
						"03"=>"03 - MARZO",
						"04"=>"04 - ABRIL",
						"05"=>"05 - MAYO",
						"06"=>"06 - JUNIO",
						"07"=>"07 - JULIO",
						"08"=>"08 - AGOSTO",
						"09"=>"09 - SETIEMBRE",
						"10"=>"10 - OCTUBRE",
						"11"=>"11 - NOVIEMBRE",
						"12"=>"12 - DICIEMBRE");
		$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)
									  ),
						"conte"=>array(array("titulo"=>"Empresa :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"text", "id"=>"ecod", "name"=>"ecod", "valor"=>$_POST["ecod"], 
																					 "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"=>$_POST["enom"], 
																					 "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", 
																					 "valor"=>$_POST["pcod"],
																					 "ancho"=>"50", "alinear"=>"center", 
																					 "keypress"=>"return SoloEnteros(event)",
																					 "blur"=>"xajax_seleccionar_proveedor(this.value)", 
																					 "dclick"=>"fn_cargar_listado_proveedor('pcod', 'pnom','PR')"),
																			   array("tipo"=>"text", "id"=>"pnom", "name"=>"pnom", 
																			   		 "valor"=>$_POST["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",
															  						 "sql"=>$sqlani, "sincod"=>"SI", "ancho"=>"110"),
																			   array("tipo"=>"select_simple", "id"=>"mes", "name"=>"mes",  
																				     "combo"=>array("sql"=>$varMes, "titulo"=>"--[[ MES ]]--", "ancho"=>"190"))
																			   )
														 	)
											 ),
									   array("titulo"=>"Tipo Datos :", "clase1"=>"FormCampo1", "clase2"=>"interior",
											 "campo"=>array("tipo"=>"varios",
															"contenido"=>array(array("tipo"=>"select_simple", "id"=>"tip", "name"=>"tip",
															  						 "combo"=>array("sql"=>$sqltip, "sincod"=>"SI", "ancho"=>"110"))
																			   )
														 	)
											 )
									   ),
						"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()"),
									 )
						);
		return $this->setTablaForm($varTabla);
		}
 	function GridDatos($varForm = NULL
					  )  {						  
		$varEmp  = ($varForm["ecod"]<>"")?$varForm["ecod"]:"NULL";
		$varPro  = ($varForm["pcod"]<>"")?$varForm["pcod"]:"NULL";
		$varAni  = ($varForm["anio"]<>"")?$varForm["anio"]:"NULL";
		$varMes  = ($varForm["mes"]<>"")?$varForm["mes"]:"NULL";
		$varTip  = ($varForm["tip"]<>"")?"'".$varForm["tip"]."'":"NULL";
		
		$sql = "call spQuery_Report_AnalCompDia_Vendedor($varEmp, $varPro, '$varAni', '$varMes', $varTip);";
			
		$varCab = array(array("cab"=>"VENTA DEL MES DE ".MesNombreLargo($varMes)." ".$varAni));
		$varDias = UltimoDiaMes(intval($varMes), intval($varAni));
		for($i=1; $i<=$varDias;$i++) {
			$varCab[0]["det"][$i-1]= "DIA_".str_pad($i,2,"0",STR_PAD_LEFT);
			}
		$varCab[0]["det"][$i+1]= "TOTAL";
		$varNiv = array(0 =>array("COD"=>"CVEN","DES"=>"VENDEDOR"),
						1 =>array("COD"=>"CTIP","DES"=>"TIPO"),
						2 =>array("COD"=>"CEMP","DES"=>"EMPRESA"));
	

		return $this->setGridCombina($varCab, $sql, $varNiv, NULL, NULL);
		}

	function Imprimir($varEmp = NULL,
					  $varPro = NULL,
					  $varAni = NULL,
					  $varMes = NULL,
					  $varTip = NULL
					  )  {			
		$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];
		
		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";
		$varTipo = array("V" => "VALOR VENTA", "I" => "IGV", "T" => "VENTA TOTAL");
		$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>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.='<tr>';
			$html.='<td style="width: 10%; vertical-align: middle; text-align:left;"><b>Datos </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>'.$varAni." - ".$varTipo[$varTip].'</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>';
			$varPro = ($varPro=="")?"NULL":$varPro;
			$sql = "call spQuery_Report_AnalCompDia_Vendedor($varEmp, $varPro, '$varAni', '$varMes', '$varTip');";
				
			$varCab = array(array("cab"=>"VENTA DEL MES DE ".MesNombreLargo($varMes)." ".$varAni));
			$varDias = UltimoDiaMes(intval($varMes), intval($varAni));
			for($i=1; $i<=$varDias;$i++) {
				$varCab[0]["det"][$i-1]= "DIA_".str_pad($i,2,"0",STR_PAD_LEFT);
				}
			$varCab[0]["det"][$i+1]= "TOTAL";
			$varNiv = array(0 =>array("COD"=>"CVEN","DES"=>"VENDEDOR"),
							1 =>array("COD"=>"CTIP","DES"=>"TIPO"),
							2 =>array("COD"=>"CEMP","DES"=>"EMPRESA"));
			
			$html.= $this->setGridCombinaPrint($varCab, $sql, $varNiv, NULL);		
		$html.='</td>';
		$html.='</tr>';
				
		$html.='</table>';
		return $html;
		}
	}
?>