<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Cotizaci&oacute;n y Nota de Pedido</title>
<link href="../../maincss.css" rel="stylesheet" type="text/css" />
<link href="../../printcss.css" rel="stylesheet" type="text/css" media="print" />

</head>
<?php
include "../../conn.php";
include "../../class.nroenletraver2.php";
include "../../general.php";
include "../../token.php";

//index.php?pkyOrderNote=7&showPrice=1&printAccountEntry=1&user=Luigi&token=123456
$rep=$_GET["rep"];
$tipo=$_GET["tipo"];

$cod_pedido = $_GET["pkyOrderNote"];
$muestra_precio = $_GET["showPrice"];
$muestra_asiento = $_GET["printAccountEntry"];
//$muestra_asiento = 1;
//$mostrar_asiento_cc = $_GET["showCC"];
//$usuario = $_GET["user"];

if($rep == 1) { $muestra_cc = 1; }
if($rep == 2) { $muestra_cc = 0; }
?>
<body>

<?php

// Inicio impresion Nota de Pedido

$result = mysqli_query($link, "select a.pkyOrderNote as codigo_orden, a.fldDate as fecha, a.fldNumber as numero_doc, case when b.fldMiddleName is NULL then concat(b.fldLastName,', ',b.fldFirstName) else concat(b.fldLastName,' ',b.fldMiddleName,', ',b.fldFirstName) end as vendedor, 
case when b.fldMiddleName is NULL then concat(b.fldFirstName,' ',b.fldLastName) else concat(b.fldFirstName,' ',b.fldLastName,' ',b.fldMiddleName) end as vendedor_reves, 															c.fldName as cliente, c.fldNIT as nit, a.codDeliveryAddress as cod_dir, a.codFixedContactPhone as cod_tel, a.codMovilContactPhone as cod_movil, f.fldName as almacen, g.fldName as local_venta, a.codCurrency as cod_moneda, h.fldName as moneda, i.pkyExchangeRate as cod_tc, concat(i.fldDate,' - ',i.fldTime) as fecha_tc, a.fldGrossTotal as total_bruto, a.fldTotalDiscountPercent as total_desc_porciento, a.fldGlobalDiscountPercent as total_desc_porciento_global, a.fldNetTotal as total_neto, a.txtDescription as glosa, a.sysEnabled as enabled, a.sysAuthorized as authorized, a.codType as cod_tipo, j.fldName as tipo_nota, k.fldName as estado, a.codAccountEntry as cod_asiento, a.codAccountReceivable as cod_cxc, a.codItemMovement as cod_mov_merc, m.fldName as usuario_reg, a.sysContext as cod_contexto, s.fldName as contexto   
from slsOrderNote a, agnPerson b, agnCompany c, invWarehouse f, slsSalesPlace g, actCurrency h, actExchangeRate i, slsOrderNoteType j, slsOrderNoteStatus k, accGroup m, srvContext s 
where
a.codSeller = b.pkyPerson and
a.codClient = c.pkyCompany and 
a.codWarehouse = f.pkyWarehouse and
a.codSalesPlace = g.pkySalesPlace and
a.codCurrency = h.pkyCurrency and
a.codExchangeRate = i.pkyExchangeRate and 
a.codType = j.pkyOrderNoteType and 
a.codStatus = k.pkyOrderNoteStatus and 
a.sysAuthorizationGroup = m.pkyGroup and 
a.sysContext = s.pkyContext and 
a.pkyOrderNote = '$cod_pedido' ");
	while ($row = mysqli_fetch_array($result)) {
		$codigo_orden = $row['codigo_orden'];
		$fecha_orden = $row['fecha'];
		$numero_doc = $row['numero_doc'];
		$vendedor = $row['vendedor'];
		$vendedor_reves = $row['vendedor_reves'];
		$cliente = $row['cliente'];
		$nit = $row['nit'];
		$cod_dir = $row['cod_dir'];
		$cod_tel = $row['cod_tel'];
		$cod_movil = $row['cod_movil'];
		$almacen = $row['almacen'];
		$local_venta = $row['local_venta'];
		$cod_moneda = $row['cod_moneda'];
		$moneda = $row['moneda'];
		$cod_tc = $row['cod_tc'];
		$fecha_tc = $row['fecha_tc'];
		$total_bruto = $row['total_bruto'];
		$total_desc_porciento = $row['total_desc_porciento'];
		$total_desc_porciento_global = $row['total_desc_porciento_global'];
		$total_neto = $row['total_neto'];
		$glosa = $row['glosa'];
		$glosa = nl2br($glosa);//quita salto de linea 
		$glosa = str_replace('\n','<br />',$glosa);//reemplaza para salto de linea
		$usuario_reg = $row['usuario_reg'];
		$enabled = $row['enabled'];
		$authorized = $row['authorized'];
		$cod_tipo = $row['cod_tipo'];
		$tipo_nota = $row['tipo_nota']; 
		$estado = $row['estado'];
		$cod_asiento = $row['cod_asiento'];
		$cod_cxc = $row['cod_cxc'];
		$cod_mov_merc = $row['cod_mov_merc'];
		$cod_contexto = $row['cod_contexto'];
		$contexto = $row['contexto'];
	}
	mysqli_free_result($result);
	
$resultdir = mysqli_query($link, "select a.fldAddress as direccion, b.fldName as tipo_dir
from
agnCompanyAddress a, agnAddressType b
where
a.pkyCompanyAddress = '$cod_dir' and 
a.codType = b.pkyAddressType;");
while ($row = mysqli_fetch_array($resultdir)) {
	$direccion = $row['direccion'];
	$tipo_dir = $row['tipo_dir'];
}
mysqli_free_result($resultdir);

$resulttel = mysqli_query($link, "select a.fldPhone as telefono, b.fldName as tipo_tel
from
agnCompanyPhone a, agnPhoneType b
where
a.pkyCompanyPhone = '$cod_tel' and 
a.codType = b.pkyPhoneType;");
while ($row = mysqli_fetch_array($resulttel)) {
	$telef = $row['telefono'];
	$tipo_tel = $row['tipo_tel'];
}
mysqli_free_result($resulttel);

$resultmov = mysqli_query($link, "select a.fldPhone as telefono, b.fldName as tipo_tel
from
agnCompanyPhone a, agnPhoneType b
where
a.pkyCompanyPhone = '$cod_movil' and 
a.codType = b.pkyPhoneType;");
while ($row = mysqli_fetch_array($resultmov)) {
	$celu = $row['telefono'];
	$tipo_cel = $row['tipo_tel'];
}
mysqli_free_result($resultmov);

$resulttc = mysqli_query($link, "select pkyExchangeRate as cod_tc, fldDate as fecha, fldTime as hora
from
actExchangeRate
where
pkyExchangeRate = '$cod_tc';");
while ($row = mysqli_fetch_array($resulttc)) {
	$tc_fecha = $row['fecha'];
	$tc_hora = $row['hora'];
}
mysqli_free_result($resulttc);

$resulttcdet = mysqli_query($link, "select a.pkyExchangeRateDetail as cod_tc_det, a.codBaseCurrency as cod_mon_target, b.fldName as mon_target, b.txtDescription as nom_mon_target, a.codTargetCurrency as cod_mon_base, c.fldName as mon_base, c.txtDescription as nom_mon_base, a.fldRate as tasa
from
actExchangeRateDetail a, actCurrency b, actCurrency c
where
a.codExchangeRate = '$cod_tc' and 
a.codBaseCurrency = '$cod_moneda_principal' and 
a.codBaseCurrency = b.pkyCurrency and 
a.codTargetCurrency = c.pkyCurrency 
order by cod_mon_target, cod_mon_base;");
$ma_tc = array();
$m = 1;
while ($row = mysqli_fetch_array($resulttcdet)) {
	$ma_tc [$m][1] = $row['mon_base'];
	$ma_tc [$m][2] = $row['mon_target'];
	$ma_tc [$m][3] = $row['tasa'];
	$m++;
}
mysqli_free_result($resulttcdet);
$fin_m = $m - 1;

	$result2 = mysqli_query($link, "select a.codItem as cod_item, b.fldName as nombre, a.fldQuantity as cantidad, a.fldPrice as precio, a.fldDiscount as descuento, a.fldTotalNetPrice as total, b.txtDescription as descrip, b.codMinimumStorageUnit as cod_unidad, c.fldName as unidad, b.fldFactoryKey as cod_fabrica, b.codBrand as cod_marca, d.fldName as marca, b.codBrandModel as cod_modelo, case when b.codBrandModel IS NOT NULL then (SELECT a1.fldName FROM invBrandModel a1 WHERE a1.pkyBrandModel = b.codBrandModel) ELSE NULL END as modelo
	from
	slsOrderNoteDetail a, invItem b, invStorageUnit c, invBrand d  
	where
	a.codItem = b.pkyItem and 
	b.codMinimumStorageUnit = c.pkyStorageUnit and 
	b.codBrand = d.pkyBrand and
	a.codOrderNote = '$codigo_orden' 
	order by nombre");
	
if($cod_tipo != 3){//if contrato

	//cuando la nota de pedido es cotización no diferencia si muestra o no precio para autored y bomesco
	//la variable nota_de_pedido_es_cotizacion esta definida en general
	if($nota_de_pedido_es_cotizacion == 1) {//if np es coti
		?>
		<table border="0" align="left" width="100%" cellpadding="5">
			<tr><td align="left" width="40%">
			<img src="../../Images/logo.jpg" alt="Logo" /> <!--espacio para el logo width="100" height="50"-->
			</td>
			<td align="left" width="60%">
			<font size="3"><b>COTIZACIÓN</b></font>
			</td>
			</tr>
		</table>
		
		<table border="1" align="left" width="100%" cellpadding="5">
			<tr>
			<td align="left">
			<b><?php echo $nombre_empresa; ?></b><br />
			<?php echo $mi_direccion; ?><br />
			Tel. <?php echo $mi_telefono; ?><br />
			<?php echo $mi_ciudad; ?> - <?php echo $mi_pais; ?>
			</td>
			<td align="left">
			<table width="100%">
				<tr>
				<td><b>Código: </b></td><td align="right"><?php echo $codigo_orden; ?></td>
				</tr>
				<tr><td>&nbsp;</td></tr>
				<tr>
				<td><b>Fecha: </b></td><td align="right"><?php echo cambiarFormatoFecha($fecha_orden); ?></td>
				</tr>
			</table>
			</td>
			</tr>
		</table>
		<table border="0" align="left" width="100%"><tr><td><br /></td></tr></table><!--espacio entre tablas-->
		<table border="1" align="left" width="100%" cellpadding="5">
			<tr>
			<td align="left">
			<b>Señores:</b><br />
			<?php echo $cliente; ?>
			</td>
			<td align="left">
			<b>Dirección: </b><?php echo $direccion; ?><br />
			<b>Teléfono: </b><?php echo $telef; ?>&nbsp;<?php echo $celu; ?>
			</td>
			</tr>
		</table>
		<table border="0" align="left" width="100%"><tr><td><br /></td></tr></table><!--espacio entre tablas-->
		<table border="1" align="left" width="100%" cellpadding="5">
			<tr>
			<td align="left">
			<?php echo $glosa; ?>
			</td>
			</tr>
		</table>

		<table border="0" align="left" width="100%"><tr><td><br /></td></tr></table><!--espacio entre tablas-->

		<table border="1" align="center" cellpadding="2" width="100%">
		<thead>
		<TR> 
		<TD width="15" align="center"><b>No.</b></TD>
		<TD align="center"><b>Item</b></TD>
		<TD align="center"><b>Marca / Modelo</b></TD>
		<TD align="center"><b>Descripción</b></TD>
		<TD align="center"><b>Cant.</b></TD>
		<TD align="center"><b>Precio Unitario</b></TD>
		<TD align="center"><b>Total</b></TD>
		</TR>
		</thead>
		<tbody class="marcafila">
		<?php
		$color = 2;
		$suma_cant = 0;
		$suma_total = 0;
		while ($row = mysqli_fetch_array($result2)) { //while

			if($color % 2 == 0) { //if color
			printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $color - 1);//no.
			} else {
			printf("<tr><td align='center'>%s</td>", $color - 1);//no.
			} //cierra if color
			printf("<td>%s</td>", $row['nombre']);//nombre item
			if($row['modelo'] != NULL){
				printf("<td align='left'>%s / %s</td>", $row['marca'], $row['modelo']);//marca/modelo
			} else {
				printf("<td align='left'>%s</td>", $row['marca']);//solo marca
			}
			printf("<td align='left'>%s</td>", $row['descrip']);//descripcion
			printf("<td align='right'>%s</td>", number_format($row['cantidad'],$n_cantidad));//cantidad
			printf("<td align='right'>%s</td>", number_format($row['precio'],$n_decimales));//precio unitario
			printf("<td align='right'>%s</td></tr>", number_format($row['total'],$n_decimales));//total
			
			$suma_cant = $suma_cant + $row['cantidad'];
			$suma_total = $suma_total + $row['total'];
			
			$color++;
		}//fin while
		mysqli_free_result($result2);

		//convierte el total en literal
		$letras=new NroEnLetra($suma_total,2);

		$mostrar_letras = ucfirst($letras->getLetra());

		$busca_espacio = substr($mostrar_letras,-6,1);
		if($busca_espacio == ' ') {
			$fin_letras = substr($mostrar_letras,-5);
			$mostrar_letras = substr($mostrar_letras,0,-5);
			$mostrar_letras = $mostrar_letras .'0'. $fin_letras;
		}
		$resultmoneda = mysqli_query($link, "select txtDescription as nom_moneda
		from actCurrency
		where
		pkyCurrency = '$cod_moneda';");
		while ($row = mysqli_fetch_array($resultmoneda)) {
			$nom_moneda_letras_tot = $row['nom_moneda'];
		}
		mysqli_free_result($resultmoneda);
		?>
		<tr BGCOLOR='#ffcccc'>
		<td colspan="4"><b>Total &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $mostrar_letras; ?> <?php echo $nom_moneda_letras_tot; ?></b></td>
		<td align="right"><b><?php echo number_format($suma_cant, $n_cantidad); ?></b></td>
		<td>&nbsp;</td>
		<td align="right"><b><?php echo number_format($suma_total, $n_decimales); ?></b></td></tr>
		</tbody>    
		</table><br />
		<?php
		if($enabled == 0){
					printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO ANULADO</font></td></tr></table>");
				}
		if($authorized == 0){
					printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO PENDIENTE DE AUTORIZACI&Oacute;N</font></td></tr></table>");
				}
		
	}//fin if np es coti



	if($muestra_precio == 0 && $nota_de_pedido_es_cotizacion == 0) {//if muestra 0
		?>
		<table border="0" align="left" width="100%" cellpadding="5">
		<tr><td><?php echo $mostrar_logo_reportes; ?>
		</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
		</td></tr></table>
		<p><br /><center><font color="#000099" size="+1"><b>Nota de Pedido</b></font></center></p>

		<table border="0" cellpadding="2" align="center" width="100%">
		<tr>
		<td> 
			<table border="1" align="center" cellpadding="2" width="100%">
				<TR> 
				<TD width="25%"><b>Cod. Reg.: </b><?php echo $codigo_orden; ?></TD>
				<TD width="25%"><b>Nro. Doc.: </b><?php echo $numero_doc; ?></TD>
				<TD width="25%"><b>Moneda: </b><?php echo $moneda; ?></TD>
				<TD width="25%"><b>Fecha de Reg.: </b><?php echo $fecha_orden; ?></TD>
				</TR>
				<TR>
				<TD><b>Cliente: </b><?php echo $cliente; ?></TD>
				<TD><b>NIT: </b><?php echo $nit; ?></TD>
				<TD><b>Direcci&oacute;n: </b><?php echo $direccion; ?> (<?php echo $tipo_dir; ?>)</TD>
				<TD><b>Tel&eacute;fono: </b><?php echo $telef; ?> (<?php echo $tipo_tel; ?>)</TD>
				</TR>
				<TR>
				<TD><b>Celular: </b><?php echo $celu; ?> (<?php echo $tipo_cel; ?>)</TD>
				<TD><b>Tipo: </b><?php echo $tipo_nota; ?></TD>
				<TD><b>Estado: </b><?php echo $estado; ?></TD>
				<TD><b>Contexto: </b><?php echo $cod_contexto; ?> - <?php echo $contexto; ?></TD>
				</TR>
				<TR>
				<TD colspan="2"><b>Almac&eacute;n: </b><?php echo $almacen; ?></TD>
				<TD><b>Local Venta: </b><?php echo $local_venta; ?></TD>
				<TD><b>Vendedor: </b><?php echo $vendedor; ?></TD>
				</TR>
				<TR>
				<TD colspan="4"><b>Glosa: </b><?php echo $glosa; ?></TD>
				</tr>
			</table>

		</td>
		<td valign="top" width="150">

			<table border="1" align="center" cellpadding="2" width="100%">
			<tr>
			<TD><b>Tipo de Cambio:</b></TD>
			</tr><tr>
			<TD align="center"><a href="../../ModuleAccounting/VoucherExchangeRate/index.php?pkyExchangeRate=<?php echo $cod_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $cod_tc; ?></a> (<?php echo $tc_fecha; ?> - <?php echo $tc_hora; ?>)<br/ >
				<table border="0" cellpadding="2" align="center">
					<?php
					for($m = 1; $m <= $fin_m; $m++) {
					printf("<tr><td align='left'>1 %s</td>", $ma_tc [$m][1]);//moneda base
					printf("<td align='center'>%s</td>", ' = ');//letra a
					printf("<td align='left'>%s %s</td>", number_format($ma_tc [$m][3],$n_tipocambio), $ma_tc [$m][2]);//moneda target y tasa
					//printf("<td align='right'>%s</td></tr>", number_format($ma_tc [$m][3],$n_tipocambio));//tasa
					}
					?>
				</table>
			</TD>
			</tr>
			</table>
			
		</td>
		</tr>
		</table>
		<br />
		<table border="1" align="center" cellpadding="2" width="100%">
			<thead>
			<TR> 
			<TD align="center" width="100"><b>Cod. Item</b></TD>
			<TD align="center" width="100"><b>Cod. Fab.</b></TD>
			<TD align="center"><b>Item</b></TD>
			<TD align="center" width="100"><b>Unidad</b></TD>
			<TD align="center" width="100"><b>Cant.</b></TD>
			</TR>
			</thead>
			<tbody class="marcafila">
			<?php
			$color = 2;
			$suma_cant = 0;
			$uni = array();
			$i = 1;
			while ($row = mysqli_fetch_array($result2)) { //while
				
				$uni[$i] = $row['cod_unidad'];
				$total_unidad = $row['unidad'];
				if($color % 2 == 0) { //if color
				printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $row['cod_item']);//cod item
				} else {
				printf("<tr><td align='center'>%s</td>", $row['cod_item']);//cod item
				} //cierra if color
				printf("<td align='center'>%s</td>", $row['cod_fabrica']);//cod fabrica
				printf("<td>%s</td>", $row['nombre']);//nombre item
				printf("<td align='right'>%s</td>", $row['unidad']);//unidad
				printf("<td align='right'>%s</td></tr>", number_format($row['cantidad'], $n_cantidad));//cantidad
									
				$suma_cant = $suma_cant + $row['cantidad'];
				$i++;
				$color++;
			}//fin while
			mysqli_free_result($result2);
			
			$fin_i = $i;
			$valor_uni = 0;
			$uni_ini = $uni[1];
			for($i = 2; $i < $fin_i; $i++) {
				if($uni_ini != $uni[$i]) { $valor_uni = 1; }
			}
			
			if($valor_uni == 1) { $total_unidad = '(El total es solo referencial, las unidades de los items no son iguales)'; }
			if($valor_uni == 0) { $total_unidad = $total_unidad.'(s)'; }
			
			//convierte el total en literal
			$letras=new NroEnLetra($suma_cant,2);
			
			$mostrar_letras = ucfirst($letras->getLetra());
			
			$busca_espacio = substr($mostrar_letras,-6,1);
			if($busca_espacio == ' ') {
				$fin_letras = substr($mostrar_letras,-5);
				$mostrar_letras = substr($mostrar_letras,0,-5);
				$mostrar_letras = $mostrar_letras .'0'. $fin_letras;
			}
			?>
			<tr BGCOLOR='#ffcccc'><td colspan="4"><b>Total &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $mostrar_letras; ?> <?php echo $total_unidad; ?></b></td>
			<td align="right"><b><?php echo number_format($suma_cant, $n_cantidad); ?></b></td>
			</tr>
		</tbody>    
		</table><br />
		<?php
			if($enabled == 0){
						printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO ANULADO</font></td></tr></table>");
					}
			if($authorized == 0){
						printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO PENDIENTE DE AUTORIZACI&Oacute;N</font></td></tr></table>");
					}
	}//fin if muestra 0
	
	if($muestra_precio == 1 && $nota_de_pedido_es_cotizacion == 0) {//if muestra 1
		?>
		<table border="0" align="left" width="100%" cellpadding="5">
		<tr><td><?php echo $mostrar_logo_reportes; ?>
		</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
		</td></tr></table>
		<p><br /><center><font color="#000099" size="+1"><b>Nota de Pedido</b></font></center></p>

		<table border="0" cellpadding="2" align="center" width="100%">
		<tr>
		<td> 
			<table border="1" align="center" cellpadding="2" width="100%">
				<TR> 
				<TD width="25%"><b>Cod. Reg.: </b><?php echo $codigo_orden; ?></TD>
				<TD width="25%"><b>Nro. Doc.: </b><?php echo $numero_doc; ?></TD>
				<TD width="25%"><b>Moneda: </b><?php echo $moneda; ?></TD>
				<TD width="25%"><b>Fecha de Reg.: </b><?php echo $fecha_orden; ?></TD>
				</TR>
				<TR>
				<TD><b>Cliente: </b><?php echo $cliente; ?></TD>
				<TD><b>NIT: </b><?php echo $nit; ?></TD>
				<TD><b>Direcci&oacute;n: </b><?php echo $direccion; ?> (<?php echo $tipo_dir; ?>)</TD>
				<TD><b>Tel&eacute;fono: </b><?php echo $telef; ?> (<?php echo $tipo_tel; ?>)</TD>
				</TR>
				<TR>
				<TD><b>Celular: </b><?php echo $celu; ?> (<?php echo $tipo_cel; ?>)</TD>
				<TD><b>Tipo: </b><?php echo $tipo_nota; ?></TD>
				<TD><b>Estado: </b><?php echo $estado; ?></TD>
				<TD><b>Contexto: </b><?php echo $cod_contexto; ?> - <?php echo $contexto; ?></TD>
				</TR>
				<TR>
				<TD><b>Almac&eacute;n: </b><?php echo $almacen; ?></TD>
				<TD><b>Local Venta: </b><?php echo $local_venta; ?></TD>
				<TD colspan="2"><b>Vendedor: </b><?php echo $vendedor; ?></TD>
				</TR>
				<TR>
				<TD><b>Asiento: </b><a href="../../ModuleAccounting/VoucherAccountEntry/index.php?pkyAccountEntry=<?php echo $cod_asiento; ?>&showCC=<?php echo $mostrar_asiento_cc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Asiento Contable"><?php echo $cod_asiento; ?></a>
				<table border="0" align="right"><tr><td>
				<?php if($muestra_asiento == 0) { ?>
					<a href="../../ModuleSales/VoucherOrderNote/index.php?pkyOrderNote=<?php echo $cod_pedido; ?>&printAccountEntry=1&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Mostrar Asiento Contable" style="text-decoration:none; color:#0000FF; font-style:normal;"> + </a>
				<?php } else { ?>
					<a href="../../ModuleSales/VoucherOrderNote/index.php?pkyOrderNote=<?php echo $cod_pedido; ?>&printAccountEntry=0&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Ocultar Asiento Contable" style="text-decoration:none; color:#0000FF; font-style:normal;"> - </a>
				<?php } ?>
				</td></tr></table>
				</TD>
				<TD><b>Cuenta x Cobrar: </b><a href="../../ModuleCollections/VoucherAccountsReceivable/index.php?pkyAccountsReceivable=<?php echo $cod_cxc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Nota de Cuenta por Cobrar"><?php echo $cod_cxc; ?></a></TD>
				<TD colspan="2"><b>Mov. de Mercader&iacute;a: </b><a href="../../ModuleInventory/VoucherItemMovement/index.php?pkyItemMovement=<?php echo $cod_mov_merc; ?>&showBatch=1&printAccountEntry=0&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Nota de Movimiento de Mercaderia con Lotes"><?php echo $cod_mov_merc; ?></a></TD>        
				</TR>
				<TR>
				<TD><b>Desc. Parcial (%): </b><?php echo number_format($total_desc_porciento, $n_descuento); ?>%</TD>
				<TD><b>Desc. Parcial: </b><?php echo number_format($total_bruto * $total_desc_porciento / 100,$n_descuento); ?></TD>
				<TD><b>Desc. Global (%): </b><?php echo number_format($total_desc_porciento_global,$n_descuento); ?>%</TD>
				<TD><b>Desc. Global: </b><?php echo number_format($total_bruto * $total_desc_porciento_global / 100,$n_descuento); ?></TD>
				</TR>
				<TR>
				<TD colspan="2"><b>Total Bruto: </b><?php echo number_format($total_bruto, $n_decimales); ?></TD>
				<TD colspan="2"><b>Total Neto: </b><?php echo number_format($total_neto, $n_decimales); ?></TD>
				</TR>
				<TR>
				<TD colspan="4"><b>Glosa: </b><?php echo $glosa; ?></TD>
				</tr>
			</table>

		</td>
		<td valign="top" width="150">

			<table border="1" align="center" cellpadding="2" width="100%">
			<tr>
			<TD><b>Tipo de Cambio:</b></TD>
			</tr><tr>
			<TD align="center"><a href="../../ModuleAccounting/VoucherExchangeRate/index.php?pkyExchangeRate=<?php echo $cod_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $cod_tc; ?></a> (<?php echo $tc_fecha; ?> - <?php echo $tc_hora; ?>)<br/ >
				<table border="0" cellpadding="2" align="center">
					<?php
					for($m = 1; $m <= $fin_m; $m++) {
					printf("<tr><td align='left'>1 %s</td>", $ma_tc [$m][1]);//moneda base
					printf("<td align='center'>%s</td>", ' = ');//letra a
					printf("<td align='left'>%s %s</td>", number_format($ma_tc [$m][3],$n_tipocambio), $ma_tc [$m][2]);//moneda target y tasa
					//printf("<td align='right'>%s</td></tr>", number_format($ma_tc [$m][3],$n_tipocambio));//tasa
					}
					?>
				</table>
			</TD>
			</tr>
			</table>
			
		</td>
		</tr>
		</table>
		<br />
		<table border="1" align="center" cellpadding="2" width="100%">
			<thead>
			<TR> 
			<TD width="60" align="center"><b>Cod. Item</b></TD>
			<TD width="60" align="center"><b>Cod. Fab.</b></TD>
			<TD align="center"><b>Item</b></TD>
			<TD width="100" align="center"><b>Unidad</b></TD>
			<TD width="100" align="center"><b>Cant.</b></TD>
			<TD width="100" align="center"><b>Precio</b></TD>
			<TD width="100" align="center"><b>Desc. %</b></TD>
			<TD width="100" align="center"><b>Total</b></TD>
			</TR>
			</thead>
			<tbody class="marcafila">
			<?php
			$color = 2;
			$suma_cant = 0;
			$suma_precio = 0;
			$suma_desc = 0;
			$suma_total = 0;
			while ($row = mysqli_fetch_array($result2)) { //while
			
				if($color % 2 == 0) { //if color
				printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $row['cod_item']);//cod item
				} else {
				printf("<tr><td align='center'>%s</td>", $row['cod_item']);//cod item
				} //cierra if color
				printf("<td align='center'>%s</td>", $row['cod_fabrica']);//cod fabrica
				printf("<td>%s</td>", $row['nombre']);//nombre item
				printf("<td align='right'>%s</td>", $row['unidad']);//unidad
				printf("<td align='right'>%s</td>", number_format($row['cantidad'],$n_cantidad));//cantidad
				printf("<td align='right'>%s</td>", number_format($row['precio'],$n_decimales));//precio
				printf("<td align='right'>%s</td>", number_format($row['descuento'],$n_descuento));//descuento
				printf("<td align='right'>%s</td></tr>", number_format($row['total'],$n_decimales));//total
				
				$suma_cant = $suma_cant + $row['cantidad'];
				$suma_precio = $suma_precio + $row['precio'];
				$suma_desc = $suma_desc + $row['descuento'];
				$suma_total = $suma_total + $row['total'];
				
				$color++;
			}//fin while
		mysqli_free_result($result2);
			
			//convierte el total en literal
			$letras=new NroEnLetra($suma_total,2);
			
			$mostrar_letras = ucfirst($letras->getLetra());
			
			$busca_espacio = substr($mostrar_letras,-6,1);
			if($busca_espacio == ' ') {
				$fin_letras = substr($mostrar_letras,-5);
				$mostrar_letras = substr($mostrar_letras,0,-5);
				$mostrar_letras = $mostrar_letras .'0'. $fin_letras;
			}
			$resultmoneda = mysqli_query($link, "select txtDescription as nom_moneda
			from actCurrency
			where
			pkyCurrency = '$cod_moneda';");
			while ($row = mysqli_fetch_array($resultmoneda)) {
				$nom_moneda_letras_tot = $row['nom_moneda'];
			}
			mysqli_free_result($resultmoneda);
			?>
			<tr BGCOLOR='#ffcccc'>
			<td colspan="4"><b>Total &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $mostrar_letras; ?> <?php echo $nom_moneda_letras_tot; ?></b></td>
			<td align="right"><b><?php echo number_format($suma_cant, $n_cantidad); ?></b></td>
			<td align="right"><b><?php echo number_format($suma_precio, $n_decimales); ?></b></td>
			<td align="right"><b><?php echo number_format($suma_desc, $n_descuento); ?></b></td>
			<td align="right"><b><?php echo number_format($suma_total, $n_decimales); ?></b></td></tr>
		</tbody>    
		</table><br />
		<?php
			if($enabled == 0){
						printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO ANULADO</font></td></tr></table>");
					}
			if($authorized == 0){
						printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO PENDIENTE DE AUTORIZACI&Oacute;N</font></td></tr></table>");
					}
	}//fin if muestra 1
	?>

	<?php
	if($muestra_asiento == 1) {//if muestra_asiento 1
		
		if($cod_asiento != NULL){//if cod_asiento
			$result3 = mysqli_query($link, "select a.pkyAccountEntry as cod_mov_det, a.fldTransactionNumber as nro_trans, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, b.fldName as tipo, a.codExchangeRate as cod_tc, a.txtDescription as glosa, a.sysEnabled as enabled, a.sysAuthorized as authorized
			from actAccountEntry a, actAccountEntryType b
			where
			a.pkyAccountEntry = '$cod_asiento' and
			a.codType = b.pkyAccountEntryType;");
			while ($row = mysqli_fetch_array($result3)) {
			$cod_asiento2 = $row['cod_mov_det'];
			$nro_trans2 = $row['nro_trans'];
			$nro_doc2 = $row['nro_doc'];
			$fecha_asiento2 = $row['fecha'];
			$tipo_asiento2 = $row['tipo'];
			$cod_tc2 = $row['cod_tc'];
			$glosa2 = $row['glosa'];
			$glosa2 = nl2br($glosa2);
			$glosa2 = str_replace('\n','<br />',$glosa2);
			$enabled2 = $row['enabled'];
			$authorized2 = $row['authorized'];
			}
			mysqli_free_result($result3);
			
			$result6 = mysqli_query($link, "select a.pkyAccountEntryDetail as cod_asiento_det, a.codAccountEntry as cod_asiento, a.codAccount as cod_cuenta, b.fldName as nom_cuenta, a.fldDebit as debe, a.fldCredit as haber
			from actAccountEntryDetail a, actAccount b
			where
			a.codAccountEntry = '$cod_asiento2' and
			a.codAccount = b.pkyAccount 
			order by haber, cod_asiento_det;");
			
			if($muestra_cc == 1){
			$texto_asiento = '<a href="../../ModuleSales/VoucherOrderNote/index.php?pkyOrderNote='.$cod_pedido.'&printAccountEntry=1&rep=2&user='.$usuario.'&token='.$token.'" title="Asiento Contable, Sin Centros de Costo" style="text-decoration:none; color:#000099; font-style:normal;">Asiento Contable, Con Centros de Costo</a>';
			} else {
			$texto_asiento = '<a href="../../ModuleSales/VoucherOrderNote/index.php?pkyOrderNote='.$cod_pedido.'&printAccountEntry=1&rep=1&user='.$usuario.'&token='.$token.'" title="Asiento Contable, Con Centros de Costo" style="text-decoration:none; color:#000099; font-style:normal;">Asiento Contable</a>';
			}
			$control_vista_asiento = 1;
		} else {//else cod_asiento
			$texto_asiento = "Asiento Contable<br /><br /><table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>NO EXISTE ASIENTO CONTABLE ASOCIADO A ESTE MOVIMIENTO</font></td></tr></table>";
			$enabled2 = 1;
			$authorized2 = 1;
			$control_vista_asiento = 0;
		}//fin if else cod_asiento
		
		
		?>
		<p>&nbsp;</p>
		<p><center><font color="#000099"><b><?php echo $texto_asiento; ?></b></font></center></p>
		<?php
		if($control_vista_asiento == 1) {//if $control_vista_asiento = 1
		?>
		<table border="1" align="center" cellpadding="2" width="100%">
			<TR> 
			<TD width="25%"><b>Cod. Reg.: </b><?php echo $cod_asiento2; ?></TD>
			<TD width="25%"><b>Nro. Doc.: </b><?php echo $nro_doc2; ?></TD>
			<TD width="25%"><b>Moneda: </b><?php echo $nom_moneda_principal; ?></TD>
			<TD width="25%"><b>Fecha de Reg.: </b><?php echo $fecha_asiento2; ?></TD>
			</TR>
			<TR>
			<TD colspan="2"><b>Tipo de Asiento: </b><?php echo $tipo_asiento2; ?></TD>
			<TD colspan="2"><b>Nro. Transacci&oacute;n: </b><?php echo $nro_trans2; ?></TD>
			</TR>
			<TR>
			<TD colspan="4"><b>Glosa: </b><?php echo $glosa2; ?></TD>
			</tr>
		</table>

		<br />
		<table border="1" align="center" cellpadding="2" width="100%">
			<thead>
			<TR> 
			<TD align="center"><b>Cod.</b></TD>
			<TD align="center"><b>Cod. Asiento</b></TD>
			<TD align="center"><b>Cod. Cuenta</b></TD>
			<TD align="center"><b>Cuenta</b></TD>
			<TD align="center"><b>Debe</b></TD>
			<TD align="center"><b>Haber</b></TD>
			</TR>
			</thead>
			<tbody class="marcafila">
			<?php
			$color = 2;
			$suma_debe = 0;
			$suma_haber = 0;
			while ($row = mysqli_fetch_array($result6)) { //while 6
				$cod_detalle_ = $row['cod_asiento_det'];
				$cod_asiento_ = $row['cod_asiento'];//cod asiento
				$cod_cuenta_ = $row['cod_cuenta'];//cod cuenta
				$nom_cuenta_ = $row['nom_cuenta'];//nombre cuenta
				if($mi_cod_pais == 1) {
				$debe_ = $row['debe'];
				$haber_ = $row['haber'];
				}
				if($mi_cod_pais == 176) {
				$debe_ = round($row['debe'], $n_decimales);
				$haber_ = round($row['haber'], $n_decimales);
				}
					$$result7 = mysqli_query($link, "select a.codCostCenter as cod_cc, b.fldName as nombre, b.codType as cod_tipo_cc, c.fldName as tipo_cc, a.fldPercent as porcentaje
					from
					actAccountEntryDetailCC a, actCostCenter b, actCostCenterType c
					where
					a.codAccountEntryDetail = '$cod_detalle_' and 
					a.codCostCenter = b.pkyCostCenter and 
					b.codType = c.pkyCostCenterType;");
					$matriz_cc = array();
					$c = 1;
					while ($row = mysqli_fetch_array($result7)) {
					$matriz_cc [$c][1] = $row['cod_cc'];
					$matriz_cc [$c][2] = $row['nombre'];
					$matriz_cc [$c][3] = $row['porcentaje'];
					$matriz_cc [$c][4] = $row['porcentaje'] / 100 * $debe_;
					$matriz_cc [$c][5] = $row['porcentaje'] / 100 * $haber_;
					$matriz_cc [$c][6] = $row['cod_tipo_cc'];
					$matriz_cc [$c][7] = $row['tipo_cc'];
					$c++;
					}
					mysqli_free_result($result7);
					$fin_cc = $c - 1;
					
				if($color % 2 == 0) { //if color
				printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $cod_detalle_);//cod 
				} else {
				printf("<tr><td align='center'>%s</td>", $cod_detalle_);//cod
				} //cierra if color
				printf("<td align='center'>%s</td>", $cod_asiento_);//cod asiento
				printf("<td align='center'>%s</td>", $cod_cuenta_);//cod cuenta
				if($muestra_cc == 0) {//if muestra_cc = 0
					if($haber_ == 0) { //if identado haber
						printf("<td align='left'>%s</td>", $nom_cuenta_);//nombre cuenta
					} else {
						printf("<td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s</td>", $nom_cuenta_);//nombre cuenta
					} //fin if identado haber
				} else {
					$sum_porc_cc = 0;
					$sum_cc = 0;
					if($haber_ == 0) { //if identado haber2
						echo "<td align='left'>" .$nom_cuenta_. "<br/>";
					} else {
						echo "<td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$nom_cuenta_. "<br/>";
					} //fin if identado haber2
					$fila_titulo_cc = 0;
					echo "<table border='0' align='left' cellpadding='2'>";
					for($c = 1; $c <= $fin_cc; $c++){//for $c
						//si el cod_tipo es diferente de 0 para mostrar el titulo en cada grupo de cc
						if($fila_titulo_cc != $matriz_cc [$c][6]){
							echo "<tr><td colspan='4'><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$matriz_cc [$c][7]. "</b></td></tr>";
							$fila_titulo_cc = $matriz_cc [$c][6];
						}
						echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$matriz_cc [$c][1]. "</td>";
						echo "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$matriz_cc [$c][2]. "</td>";
						echo "<td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;" .number_format($matriz_cc [$c][3], $n_descuento). "%" . "</td>";
						if($matriz_cc [$c][4] != 0){
							echo "<td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;" .number_format($matriz_cc [$c][4], $n_decimales). "</td>";
							$sum_cc = $sum_cc + $matriz_cc [$c][4];
						} else {
							echo "<td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;" .number_format($matriz_cc [$c][5], $n_decimales). "</td>";
							$sum_cc = $sum_cc + $matriz_cc [$c][5];
						}
						echo "</tr>";
						$sum_porc_cc = $sum_porc_cc + $matriz_cc [$c][3];
						if($fila_titulo_cc != $matriz_cc [$c+1][6]){
							echo "<tr><td colspan='2'>&nbsp;</td>";
							echo "<td align='right'><HR width='90%' align='right'>" . "</td>";
							echo "<td align='right'><HR width='90%' align='right'>" . "</td>";
							echo "<tr><td colspan='2'>&nbsp;</td>";
							echo "<td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;" .number_format($sum_porc_cc, $n_descuento). "%" . "</td>";
							echo "<td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;" .number_format($sum_cc, $n_decimales). "</td></tr>";
							$sum_cc = 0;
							$sum_porc_cc = 0;
						}
					}//fin for $c
					
					echo "</table></td>";
				}//fin if muestra_cc = 0
				printf("<td align='right'>%s</td>", number_format($debe_, $n_decimales));//debe
				printf("<td align='right'>%s</td></tr>", number_format($haber_, $n_decimales));//haber
				
				$suma_debe = $suma_debe + $debe_;
				$suma_haber = $suma_haber + $haber_;
				$color++;
			}//fin while 6
			mysqli_free_result($result6);
			
			//convierte el total en literal
			$letras=new NroEnLetra($suma_debe,2);
			
			$mostrar_letras = ucfirst($letras->getLetra());
			
			$busca_espacio = substr($mostrar_letras,-6,1);
			if($busca_espacio == ' ') {
				$fin_letras = substr($mostrar_letras,-5);
				$mostrar_letras = substr($mostrar_letras,0,-5);
				$mostrar_letras = $mostrar_letras .'0'. $fin_letras;
			}
			?>
			<tr BGCOLOR='#ffcccc'><td colspan="4"><b>Total &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $mostrar_letras; ?> <?php echo $nom_moneda_letras; ?></b></td>
			<td align="right"><b><?php echo number_format($suma_debe, $n_decimales); ?></b></td>
			<td align="right"><b><?php echo number_format($suma_haber, $n_decimales); ?></b></td>
			</tr>
		</tbody>    
		</table>
		<br />

		<?php
			if($enabled2 == 0){
						printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>ASIENTO ANULADO</font></td></tr></table>");
					}
			if($authorized2 == 0){
						printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>ASIENTO PENDIENTE DE AUTORIZACI&Oacute;N</font></td></tr></table>");
					}
			} //fin if $control_vista_asiento = 1
	}//fin if muestra_asiento 1
	
	if($nota_de_pedido_es_cotizacion == 0){ //if var control	
		?>

		<p>&nbsp;</p>
		<br /><br /><br /><br />
		<table border="0" align="center" cellpadding="2" width="90%">
		<tr>
		<td align="center">----------------------------------------</td>
		<td align="center">----------------------------------------</td>
		<td align="center">----------------------------------------</td>
		<td align="center">----------------------------------------</td>
		</tr><tr>
		<td align="center">Elaborado por: <?php echo $usuario_reg; ?></td>
		<td align="center"><?php echo $firma_contabilidad; ?></td>
		<td align="center"><?php echo $firma_gerencia; ?></td>
		<td align="center"><?php echo $firma_interesado; ?></td>
		</tr><tr>
		<td align="left">Nombre:__________________________</td>
		<td align="left">Nombre:__________________________</td>
		<td align="left">Nombre:__________________________</td>
		<td align="left">Nombre:__________________________</td>
		</tr><tr>
		<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
		<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
		<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
		<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
		</tr>
		</table>

		<?php
	} else { //else if var control
		?>
		
		<br /><br /><br /><br />
		<table border="0" align="center" cellpadding="2" width="800">
		<tr><td align="center">-------------------------------------------------</td></tr>
		<tr><td align="center"><font size="2"><?php echo $vendedor_reves; ?></font></td></tr>
		<tr><td align="center"><font size="2">Representante de ventas</font></td></tr>
		</table>
		
		<?php
	} //fin if var control


} else { //else if contrato

	//extrae el valor del item km extra configurado en el modulo 
	$resultkm = mysqli_query($link, "select codMileageItem as cod_km 
	from
	vhcVehiclesConfig 
	where 
	sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultkm)) {
		$valor_km = $row['cod_km'];
	}
	mysqli_free_result($resultkm);

	//inicia muestra la cotizacion
	$dia_ini = substr($fecha_orden,-2);
	$mes_ini = substr($fecha_orden,5,2);
	$ano_ini = substr($fecha_orden,0,4);
	if($mes_ini == 1) { $mes_nom = 'Enero'; }
	if($mes_ini == 2) { $mes_nom = 'Febrero'; }
	if($mes_ini == 3) { $mes_nom = 'Marzo'; }
	if($mes_ini == 4) { $mes_nom = 'Abril'; }
	if($mes_ini == 5) { $mes_nom = 'Mayo'; }
	if($mes_ini == 6) { $mes_nom = 'Junio'; }
	if($mes_ini == 7) { $mes_nom = 'Julio'; }
	if($mes_ini == 8) { $mes_nom = 'Agosto'; }
	if($mes_ini == 9) { $mes_nom = 'Septiembre'; }
	if($mes_ini == 10) { $mes_nom = 'Octubre'; }
	if($mes_ini == 11) { $mes_nom = 'Noviembre'; }
	if($mes_ini == 12) { $mes_nom = 'Diciembre'; }
	?>
	<font size="3">
	<p><img src="../../Images/logo.jpg" alt="Logo" /><img src="../../Images/texto_encabezado.jpg" alt="Encabezado" align="right" /><br /><hr /></p>
	<p align="right"><?php echo $local_venta; ?>, <?php echo $dia_ini; ?> de <?php echo $mes_nom; ?> de <?php echo $ano_ini; ?></p>

	<p><br />Se&ntilde;ores:
	<br /><b><?php echo $cliente; ?></b>
	<br />Direcci&oacute;n: <?php echo $direccion; ?> 
	<br />Tel&eacute;fono: <?php echo $telef; ?>
	<br />Celular: <?php echo $celu; ?> 
	<br />NIT: <?php echo $nit; ?>
	<br />Cotizaci&oacute;n Nro. <?php echo $numero_doc; ?>, C&oacute;digo <?php echo $codigo_orden; ?>
	<br /><u>Presente</u>.-
	<br /><br />De acuerdo a su solicitud, tengo a bien hacerles llegar la presente cotizaci&oacute;n, expresada en <?php echo $moneda; ?>:</p>

	<table border="1" align="center" cellpadding="2" width="100%">
		<TR> 
		<TD width="75" align="center"><b><font size="3">Cod. Item</font></b></TD>
		<TD align="center"><b><font size="3">Descripci&oacute;n</font></b></TD>
		<TD width="70" align="center"><b><font size="3">Cant.</font></b></TD>
		<TD width="110" align="center"><b><font size="3">Precio <?php echo $moneda; ?></font></b></TD>
		<TD width="70" align="center"><b><font size="3">Desc. %</font></b></TD>
		<TD width="110" align="center"><b><font size="3">Total <?php echo $moneda; ?></font></b></TD>
		</TR>
		<?php
		$color = 2;
		$suma_cant = 0;
		$suma_precio = 0;
		$suma_desc = 0;
		$suma_total = 0;
		while ($row = mysqli_fetch_array($result2)) { //while
			
			if($color % 2 == 0) { //if color
			printf("<tr BGCOLOR='#e2e7fa'><td align='center'><font size='3'>%s</font></td>", $row['cod_item']);//cod item
			} else {
			printf("<tr><td align='center'><font size='3'>%s</font></td>", $row['cod_item']);//cod item
			} //cierra if color
			$descrip = $row['descrip'];
			$descrip = nl2br($descrip);//quita salto de linea 
			$descrip = str_replace('\n','<br />',$descrip);//reemplaza para salto de linea
			if($valor_km != $row['cod_item'] && $row['cantidad'] <= 1) { //verifica que no sea el item km extra y no sea mayor a 1
				printf("<td><font size='3'>%s<br />%s</font></td>", $row['nombre'], $descrip);//nombre item
			} else {
				printf("<td><font size='3'>%s (Este monto no suma en el total)<br />%s</font></td>", $row['nombre'], $descrip);//nombre item
			} //fin verifica que no sea el item km extra y no sea mayor a 1
			printf("<td align='right'><font size='3'>%s</font></td>", number_format($row['cantidad'],$n_cantidad));//cant
			printf("<td align='right'><font size='3'>%s</font></td>", number_format($row['precio'],$n_decimales));//precio
			printf("<td align='right'><font size='3'>%s</font></td>", number_format($row['descuento'],$n_descuento));//desc
			printf("<td align='right'><font size='3'>%s</font></td></tr>", number_format($row['total'],$n_decimales));//total
			
			if($valor_km != $row['cod_item'] && $row['cantidad'] <= 1) { //verifica que no sea el item km extra y no sea mayor a 1
			$suma_cant = $suma_cant + $row['cantidad'];
			$suma_precio = $suma_precio + $row['precio'];
			$suma_desc = $suma_desc + $row['descuento'];
			$suma_total = $suma_total + $row['total'];
			} //fin verifica que no sea el item km extra y no sea mayor a 1
			
			$color++;
		}//fin while
		mysqli_free_result($result2);
		
		?>
		<tr BGCOLOR='#ffcccc'>
		<td colspan="3"><b><font size='3'>Totales</font></b></td>
		<!--<td align="right"><b><?php echo number_format($suma_cant, $n_cantidad); ?></b></td>-->
		<td align="right"><b><font size='3'><?php echo number_format($suma_precio, $n_decimales); ?></font></b></td>
		<!--<td align="right"><b><?php echo number_format($suma_desc, $n_descuento); ?></b></td>-->
		<td align="right">&nbsp;</td>
		<td align="right"><b><font size='3'><?php echo number_format($suma_total, $n_decimales); ?></font></b></td></tr>
		
	</table><br />

	<p align="justify"><?php echo $glosa; ?></p>

	<?php
		if($enabled == 0){
			printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO ANULADO</font></td></tr></table>");
		}
		if($authorized == 0){
			printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO PENDIENTE DE AUTORIZACI&Oacute;N</font></td></tr></table>");
		}

		?>

	<br /><br /><br /><br />
	<table border="0" align="center" cellpadding="2" width="800">
	<tr><td align="center">-------------------------------------------------</td></tr>
	<tr><td align="center"><font size="3"><?php echo $vendedor_reves; ?></font></td></tr>
	<tr><td align="center"><font size="3">Representante de ventas</font></td></tr>
	</table>
	</font>
	<?php
}//fin if contrato
?>
</body>
</html>
