<?php
	include('../clases/clase.conexion.php');
	include('../funciones/variables.php');
	include('../funciones/funciones.php');
	$var = VarServer("MYSQLI");
	$obj = new clsConexion($var[0],$var[1],$var[2],$var[3],$var[4]);
	$varTitu = "AVANCE DE VENTAS POR LINEA";
	$varFIni = ($_GET["fini"]=="") ? "NULL" : "'".FechaMySql($_GET["fini"])."'";
	$varFFin = ($_GET["ffin"]=="") ? "NULL" : "'".FechaMySql($_GET["ffin"])."'";
			
	$varVenAnt = $varVenAct = $varRutAnt = $varRutAct = "";

	$html = '
		<!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
		<head>
		<title>'.$varTitu.'</title>
		<link rel="STYLESHEET" href="../css/print_avance_ventas.css" type="text/css" />
		</HEAD>
		<body class="page">';
		
	$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($_GET[mes]).' - '.$_GET[anio].'</b></td>';
		$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.$varSysEmpresa.'</b></td>';
		$html.='</tr>';
		$html.='<tr>';
		$html.='<td style="vertical-align: middle; text-align:left;"><b>Fecha</b></td>';
		$html.='<td style="vertical-align: middle; text-align:center;"><b>:</b></td>';
		$html.='<td style="vertical-align: middle; text-align:left;"><b>'.$_GET[fini].' - '.$_GET[ffin].'</b></td>';
		$html.='<td style="vertical-align: middle; text-align:right;"><b>'.$varTitu.'</b></td>';
		$html.='</tr>';
		$html.='<tr>';
		$html.='<td style="vertical-align: middle; text-align:left;"><b>Vendedor</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[ven]<>"") {
			$sqlp = "select id_vendedor, nombre from _sv_vendedor where id_vendedor=".$_GET[ven];
			$obj->AbrirConexion();
			$rsp = $obj->Query($sqlp);
			$obj->CerrarConexion();
			$filap = $obj->FetchArray($rsp);
			$html.= $filap[0].' - '.$filap[1];
			}
		else {
			$html.= 'TODOS LOS VENDEDORES';
			}
		$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.='<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="2" class="center">CVEN</td>';
		$html.='<td width="150">LINEA</td>';
		$html.='<td width="60" class="right">META</td>';
		$html.='<td width="60" class="right">AVANCE</td>';
		$html.='<td width="60" class="right">% AVANC</td>';
		$html.='<td width="60" class="right">TENDENCIA</td>';
		$html.='<td width="60" class="right">% TEND.</td>';
		$html.='</tr>';
		$html.='</thead>';
		$sql = "call spQuery_Avance_Ventas_Proveedor('$_GET[anio]', '$_GET[mes]', '$_GET[ven]', $varFIni, $varFFin);";
		$obj->AbrirConexion();
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$varTotal_1 = 0;
		$varTotal_2 = 0;
		$varTotal_3 = 0;
		$varNumDoc = 0;
		while($fila = $obj->FetchArray($rs))	{
			$varTotal_1 = $varTotal_1 + $fila["META"];
			$varTotal_2 = $varTotal_2 + $fila["VENTA"];
			$varTotal_3 = $varTotal_3 + $fila["TENDENCIA"];
			$varNumDoc++;
			$html.='<tr class="list_row">';
			$html.='<td class="center">&nbsp;</td>';
			$html.='<td class="center">'.$fila["CLIN"].'</td>';
			$html.='<td NOWRAP>'.$fila["LINEA"].'</td>';
			$html.='<td class="right">';
			if(!is_null($fila["META"]) && $fila["META"] <> 0)
				$html.=number_format($fila["META"],"2",".",",");
			$html.='</td>';
			$html.='<td class="right">';
			if(!is_null($fila["VENTA"]) && $fila["VENTA"] <> 0)
				$html.=number_format($fila["VENTA"],"2",".",",");
			$html.='</td>';
			$html.='<td class="right">';
			if(!is_null($fila["PORC_AVANCE"]) && $fila["PORC_AVANCE"] <> 0)
				$html.=number_format($fila["PORC_AVANCE"],"2",".",",")."%";
			$html.='</td>';
			$html.='<td class="right">';
			if(!is_null($fila["TENDENCIA"]) && $fila["TENDENCIA"] <> 0)
				$html.=number_format($fila["TENDENCIA"],"2",".",",");
			$html.='</td>';
			$html.='<td class="right">';
			if(!is_null($fila["PORC_TENDENCIA"]) && $fila["PORC_TENDENCIA"] <> 0)
				$html.=number_format($fila["PORC_TENDENCIA"],"2",".",",")."%";
			$html.='</td>';
			$html.='</tr>';
			}
		$html.='<tr class="list_foot">';
		$html.='<td class="left"></td>';
		$html.='<td class="left"></td>';
		$html.='<td class="left">'.number_format($varNumDoc,"0",".",",").' Registros</td>';
		$html.='<td class="right">'.number_format($varTotal_1,"2",".",",").'</td>';
		$html.='<td class="right">'.number_format($varTotal_2,"2",".",",").'</td>';
		$html.='<td class="right">';
		$html.= ($varTotal_1==0)?"0.00":number_format($varTotal_2/$varTotal_1*100,"2",".",",");
		$html.='%</td>';
		$html.='<td class="right">'.number_format($varTotal_3,"2",".",",").'</td>';
		$html.='<td class="right">';
		$html.= ($varTotal_1==0)?"0.00":number_format($varTotal_3/$varTotal_1*100,"2",".",",");
		$html.='%</td>';
		$html.='</tr>';

		$html.='</table>';
	$html.='</td>';
	$html.='</tr>';
			
$html.='</table>		
		</body>
		</html>';
	echo $html;
?>