<?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 VENDEDOR / LINEA";
	$varFec = (isset($_GET["eini"]))?FechaMySql($_GET["eini"]):NULL;
	$varVen = (isset($_GET["vcod"]))?$_GET["vcod"]:NULL;
	$varRut = (isset($_GET["rcod"]))?$_GET["rcod"]:NULL;
	$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>
		<link rel="STYLESHEET" href="css/print_inventario.css" type="text/css" />
		</HEAD>
		<body class="page">';
		
	$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="width: 50%; vertical-align: middle; text-align:left;"><b>'.$varSysEmpresa.'</b></td>';
		$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b>'.$varTitu.'</b></td>';
		$html.='</tr>';
		$html.='<tr>';
		$html.='<td style="width: 50%; vertical-align: middle; text-align:left;"><b>Fecha: '.$_GET[eini].'</b></td>';
		$html.='<td style="width: 50%; vertical-align: middle; text-align:right;"><b></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="2">&nbsp;</td>';
		$html.='<td width="2" class="center">CCLI</td>';
		$html.='<td width="150">CLIENTE</td>';
		$html.='<td width="150">DIRECCION</td>';
		$html.='<td width="50">DOC.VENTA</td>';
		$html.='<td width="30">PEDIDO</td>';
		$html.='<td width="25" class="right">MONTO S/.</td>';
		$html.='<td width="25" class="right">CONTADO</td>';
		$html.='<td width="25" class="right">CREDITO</td>';
		$html.='<td width="25" class="right">PARCIAL</td>';
		$html.='<td width="25" class="right">ANULAD.</td>';
		$html.='</tr>';
		$html.='</thead>';
		$sql = "call spQuery_Packing_Documentos('$varFec','$varVen','$varRut')";
		$obj->AbrirConexion();
		$rs = $obj->Query($sql);
		$obj->CerrarConexion();
		$varTotal1 = 0;
		$varTotal2 = 0;
		while($fila = $obj->FetchArray($rs))	{
			$varTotal1 = $varTotal1 + $fila["MONTO"];
			$varVenAct = $fila["CVEN"];
			$varRutAct = $fila["CRUT"];
			if($varVenAct <> $varVenAnt) {
				$varVenAnt = $fila["CVEN"];
				$html.='<tr class="list_row">';
				$html.='<td class="center"><b>'.$fila["CVEN"].'</b></td>';
				$html.='<td colspan="10"><b>'.$fila["VENDEDOR"].'</b></td>';
				$html.='</tr>';
				}
			if($varRutAct <> $varRutAnt) {
				$varRutAnt = $fila["CRUT"];
				$html.='<tr class="list_row">';
				$html.='<td></td>';
				$html.='<td class="center"><b>'.$fila["CRUT"].'</b></td>';
				$html.='<td colspan="9"><b>'.$fila["RUTA"].'</b></td>';
				$html.='</tr>';
				}
			$html.='<tr class="list_row">
					<td class="center">&nbsp;</td>
					<td class="center">'.$fila["CCLI"].'</td>
					<td>'.$fila["CLIENTE"].'</td>
					<td>'.$fila["DIRECCION"].'</td>
					<td>'.$fila["CTIP"].' '.$fila["NDOC"].'</td>
					<td>'.$fila["PEDIDO"].'</td>
					<td class="right">'.number_format($fila["MONTO"],"2",".",",").'</td>
					<td class="right"></td>
					<td class="right"></td>
					<td class="right"></td>
					<td class="right"></td>
					</tr>';
			}
		$html.='<tr class="head">';
		$html.='<td colspan="6" class="left"><strong>Totales :</strong></td>';
		$html.='<td class="right">'.number_format($varTotal1,"2",".",",").'</td>';
		$html.='<td class="right"></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>';
	echo $html;
?>