<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Pantalla Reporte Almacenes</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 "../../general.php";
include "../../token.php";

$rep=$_GET["rep"];
$tipo=$_GET["tipo"];
$almacen=$_POST["almacen"];
$ciudad=$_POST["ciudad"];
$orden=$_POST["orden"];
//$usuario=$_POST["usuario"];

//$n_decimales = 6;

?>
<body>
<?php

//Inicio reporte almacenes

if($rep == 13 && $tipo == 1) { // if 2

  	if ($almacen == 0) { // if 2.0
		$nom_almacen = 'Todos';
		$valor_almacen = ' ';
	} else {
		//nombre almacen
		$result2 = mysqli_query($link, "select pkyWarehouse as cod_almacen, fldName as almacen
								from
								invWarehouse 
								where
								pkyWarehouse = '$almacen' and
								sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($result2)) {
			$nom_almacen = $row['almacen'];
		}
		mysqli_free_result($result2);
		$valor_almacen = ' a.pkyWarehouse = ' .$almacen. ' and ';
	} //fin if 2.0
	
	if ($ciudad == 0) { // if 2.1
		$nom_ciudad = 'Todos';
		$valor_ciudad = ' ';
	} else {
		//nombre ciudad
		$result3 = mysqli_query($link, "select a.pkyCity as cod_ciu, a.fldName as ciudad, a.codCountry as cod_pais, b.fldName as pais
								from
								regCity a, regCountry b
								where 
								a.codCountry = b.pkyCountry and 
								a.pkyCity = '$ciudad' and
								a.sysEnabled = 1 and a.sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($result3)) {
			$nom_ciudad = $row['ciudad'].' - '.$row['pais'];
		}
		mysqli_free_result($result3);
		$valor_ciudad = ' a.codCity = ' .$ciudad. ' and ';
	} //fin if 2.1
	
		
	if ($orden == 0) { // if 2.6
		$nom_orden = 'Almac&eacute;n';
		$valor_orden = ' order by a.fldName ';
	} else {
		$nom_orden = 'Ciudad';
		$valor_orden = ' order by b.fldName, a.fldName ';
	} //fin if 2.6

//listado almacenes
$result = mysqli_query($link, "select a.pkyWarehouse as cod_alm, a.fldName as almacen, a.codCity as cod_ciu, b.fldName as ciudad, a.codAccount as cod_cta, c.fldName as cuenta, a.txtDescription as descripcion, d.fldName as pais, a.fldAcceptNegative as negativo 
from 
invWarehouse a, regCity b, actAccount c, regCountry d 
where 
$valor_almacen 
$valor_ciudad 
a.codCity = b.pkyCity and 
a.codAccount = c.pkyAccount and 
b.codCountry = d.pkyCountry and
a.sysEnabled = 1 and a.sysAuthorized = 1 
$valor_orden ;");

$matriz_almacen = array();
$i = 1;
while ($row = mysqli_fetch_array($result)) {
	$matriz_almacen [$i][1] = $row['cod_alm'];
	$matriz_almacen [$i][2] = $row['almacen'];
	$matriz_almacen [$i][3] = $row['cod_ciu'];
	$matriz_almacen [$i][4] = $row['ciudad'];
	$matriz_almacen [$i][5] = $row['cod_cta'];
	$matriz_almacen [$i][6] = $row['cuenta'];
	$matriz_almacen [$i][7] = $row['descripcion'];
	$matriz_almacen [$i][8] = $row['pais'];
	$matriz_almacen [$i][9] = $row['negativo'];
	$i++;
}
$fin = $i - 1;
mysqli_free_result($result);


?>
<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>Listado de Almacenes</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="33%" colspan="2"><b>Almac&eacute;n: </b><?php echo $nom_almacen; ?></TD>
        <TD width="33%"><b>Ciudad: </b><?php echo $nom_ciudad; ?></TD>
        <TD width="33%"><b>Ordenado por: </b><?php echo $nom_orden; ?></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 $ultimo_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $ultimo_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"><b>Cod.</b></TD>
        <TD align="center"><b>Almacen</b></TD>
        <TD align="center"><b>Ciudad - Pais</b></TD>
        <TD align="center"><b>Cod. Cuenta</b></TD>
		<TD align="center"><b>Cuenta</b></TD>
        <TD align="center"><b>Acepta Inventarios Negativos</b></TD>
    	<TD align="center"><b>Descripci&oacute;n</b></TD>
        </TR>
	</thead>
    <tbody class="marcafila">
  <?php
  $color = 2;
     
  $j = 1;
  while ($j <= $fin) { //while
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $matriz_almacen [$j][1]);//cod almacen
	} else {
	printf("<tr><td align='center'>%s</td>", $matriz_almacen [$j][1]);//cod almacen
	}//fin if color
	printf("<td align='left'>%s</td>", $matriz_almacen [$j][2]);//almacen
	printf("<td align='left'>%s - %s</td>", $matriz_almacen [$j][4], $matriz_almacen [$j][8]);//ciudad - pais
	printf("<td align='left'>%s</td>", $matriz_almacen [$j][5]);//cod cuenta
	printf("<td align='left'>%s</td>", $matriz_almacen [$j][6]);//cuenta
	if($matriz_almacen [$j][9] == 0) {
		printf("<td align='center'>No</td>");//negativo
	} else {
		printf("<td align='center'>Si</td>");//negativo
	}
	printf("<td align='left'>%s</td>", $matriz_almacen [$j][7]);//descripcion
	$color++;
	$j++;
  }//fin while
?>
<tr BGCOLOR='#ffcccc'><td colspan="6"><b>Total almacenes</b></td>
<td align="right"><?php printf("<b>%s</b>", $fin); ?></td></tr>
</tbody>
</table>
<?php
} //fin if 2

?>

</body>
</html>
