<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Pantalla Reporte Gastos por Item</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";

$rep=$_GET["rep"];
$tipo=$_GET["tipo"];
$item=$_POST["item"];
$con_gasto=$_POST["gasto"];
$con_egreso=$_POST["egreso"];
$documento=$_POST["documento"];
$marca=$_POST["marca"];
$modelo=$_POST["modelo"];
$familia=$_POST["familia"];
$subfamilia=$_POST["subfamilia"];
$grupo=$_POST["grupo"];
$subgrupo=$_POST["subgrupo"];
$otra_moneda=$_POST["otra_moneda"];
$cod_contexto=$_POST["contexto"];
$usuario=$_POST["usuario"];
$fechaini=$_POST["fechaini"];
$fechafin=$_POST["fechafin"];
$orden=$_POST["orden"];

$item_det=$_GET["item_det"];
$con_gasto_det=$_GET["gasto_det"];
$con_egreso_det=$_GET["egreso_det"];
$documento_det=$_GET["documento_det"];
$marca_det=$_GET["marca_det"];
$modelo_det=$_GET["modelo_det"];
$familia_det=$_GET["familia_det"];
$subfamilia_det=$_GET["subfamilia_det"];
$grupo_det=$_GET["grupo_det"];
$subgrupo_det=$_GET["subgrupo_det"];
$otra_moneda_det=$_GET["otra_moneda_det"];
$cod_contexto_det=$_GET["contexto_det"];
$usuario_det=$_GET["usuario_det"];
$fechaini_det=$_GET["fechaini_det"];
$fechafin_det=$_GET["fechafin_det"];
//$n_decimales = 6;

if ($familia == '') { $familia = 0;}
if ($subfamilia == '') { $subfamilia = 0;}
if ($grupo == '') { $grupo = 0;}
if ($subgrupo == '') { $subgrupo = 0;}

// para que filtre solo uno de los conceptos elegidos, si se quita del index la opcion con -1
//if($con_gasto != 0 && $con_egreso == 0) { $con_egreso = -1; }
//if($con_egreso != 0 && $con_gasto == 0) { $con_gasto = -1; }


//verificar el tipo de usuario 3 es normal (no muestra CxP)
$resultuser = mysqli_query($link, "select pkyUser as cod_user, codType as cod_tipo 
from accUser
where fldLogin = '$usuario' and
sysEnabled = 1 and sysAuthorized = 1;");
		
while ($row = mysqli_fetch_array($resultuser)) {
$cod_usuario = $row['cod_user'];
$cod_tipo_usuario = $row['cod_tipo'];
}
mysqli_free_result($resultuser);

if($cod_tipo_usuario == 3) { 
	$valor_ver_cxp = ' c.sysVisible <> 1 and ';
} else {
	$valor_ver_cxp = ' ';
}

//verificar el tipo de usuario 3 es normal (no muestra CxP) para el detalle
$resultuser = mysqli_query($link, "select pkyUser as cod_user, codType as cod_tipo 
from accUser
where fldLogin = '$usuario_det' and
sysEnabled = 1 and sysAuthorized = 1;");
		
while ($row = mysqli_fetch_array($resultuser)) {
$cod_usuario_det = $row['cod_user'];
$cod_tipo_usuario_det = $row['cod_tipo'];
}
mysqli_free_result($resultuser);

if($cod_tipo_usuario_det == 3) { 
	$valor_ver_cxp_det = ' c.sysVisible <> 1 and ';
} else {
	$valor_ver_cxp_det = ' ';
}

?>
<body>
<?php



//Inicio reporte gastos por item, tc de la fecha en que se hizo el gasto

if($rep == 5 && $tipo == 1) { // if rep

//nombre otra moneda
$resultotra = mysqli_query($link, "SELECT fldName as otra_moneda
from
actCurrency
where
pkyCurrency = '$otra_moneda' and
sysEnabled = 1 and sysAuthorized = 1;");
		
	while ($row = mysqli_fetch_array($resultotra)) {
	$nom_otra_moneda = $row['otra_moneda'];
	}
	mysqli_free_result($resultotra);


//item
if($item == 0) {//if item
	$nom_item = 'Todos';
	$valor_item = '';
} else {//else if item
	$resultitem = mysqli_query($link, "select pkyItem as cod_item, fldName as item, fldFactoryKey as cod_fabrica
	from
	invItem
	where
	pkyItem = '$item' and
	sysEnabled = 1 and sysAuthorized = 1;");
		
	while ($row = mysqli_fetch_array($resultitem)) {
	$nom_item = $row['item'];
	}
	mysqli_free_result($resultitem);
	$valor_item = ' a.codItem = '.$item.' and ';
}//fin if item

//concepto de gasto
if ($con_gasto == 0) { //if concepto de gasto
	$nom_con_gasto = 'Todos';
	$valor_con_gasto = ' ';
} else { 
    if ($con_gasto == -1) { //if concepto de gasto 2
	$nom_con_gasto = 'Solo Concepto de Egreso (Mov. Merc.)';
  	} else {
	//nombre del concepto de gasto
	$resultgasto = mysqli_query($link, "select pkyExpensesConcept as codigo, fldName as gasto
	from payExpensesConcept 
	where
	pkyExpensesConcept = '$con_gasto' and 
	sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultgasto)) {
			$nom_con_gasto = $row['gasto'];
		}
		mysqli_free_result($resultgasto);
	} //fin if concepto de gasto 2
	$valor_con_gasto = ' a.codExpensesConcept = '.$con_gasto.' and ';
} //fin if concepto de gasto

//concepto de egreso
if ($con_egreso == 0) { //if concepto de egreso
	$nom_con_egreso = 'Todos';
	$valor_con_egreso = ' ';
} else { 
    if ($con_egreso == -1) { //if concepto de egreso 2
	$nom_con_egreso = 'Solo Concepto de Gasto';
  	} else {
	//nombre del concepto de egreso
	$resultegreso = mysqli_query($link, "select pkyItemMovementTypeConcept as codigo, fldName as egreso
	from
	invItemMovementTypeConcept
	where
	pkyItemMovementTypeConcept = '$con_egreso' and 
	sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultegreso)) {
			$nom_con_egreso = $row['egreso'];
		}
		mysqli_free_result($resultegreso);
	} //fin if concepto de egreso 2
	$valor_con_egreso = ' a.codTypeConcept = '.$con_egreso.' and ';
} //fin if concepto de egreso

//documento 
if ($documento == 0) { //if documento
	$nom_documento = 'Todos';
	$valor_documento = ' ';
} else { 
	if($documento == 999) { //if documento 2
	$nom_documento = 'Egresos';
	} else {
	//esto es para limitar solo a gasto
	$nom_con_egreso = 'Solo Concepto de Gasto';
  	$valor_con_egreso = ' a.codTypeConcept = '.$con_egreso.' and ';
	//nombre del documento
	$resultdoc = mysqli_query($link, "select pkyDocumentType as codigo, fldName as dcto
	from txsDocumentType 
	where 
	pkyDocumentType = '$documento' and 
	sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultdoc)) {
			$nom_documento = $row['dcto'];
		}
		mysqli_free_result($resultdoc);
	} //fin if documento 2
  	$valor_documento = ' a.codDocumentType = '.$documento.' and ';
} //fin if documento

//marca
if ($marca == 0) { // if marca
		$nom_marca = 'Todos';
		$valor_marca = ' ';
	} else {
		//nombre marca
		$resultmar = mysqli_query($link, "select pkyBrand as cod, fldName as marca
							from 
							invBrand
							where
							pkyBrand = '$marca' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultmar)) {
			$nom_marca = $row['marca'];
		}
		mysqli_free_result($resultmar);
		$valor_marca = ' e.codBrand = ' .$marca. ' and ';
	} //fin if marca
	
//modelo
if ($modelo == 0) { // if modelo
		$nom_modelo = 'Todos';
		$valor_modelo = ' ';
	} else {
		//nombre modelo
		$resultmod = mysqli_query($link, "select pkyBrandModel as cod, fldName as modelo
							from 
							invBrandModel
							where
							pkyBrandModel = '$modelo' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultmod)) {
			$nom_modelo = $row['modelo'];
		}
		mysqli_free_result($resultmod);
		$valor_modelo = ' e.codBrandModel = ' .$modelo. ' and ';
	} //fin if modelo

//contexto
if($cod_contexto == -1){ 
	$nom_contexto = 'Todos';
	$valor_contexto = ' ';
	$valor_contexto2 = ' ';
} else {
	$resultcontx = mysqli_query($link, "select pkyContext as cod_contexto, fldName as contexto, codCostCenter as cod_cc 
	from srvContext
	where 
	pkyContext = '$cod_contexto';");
		while ($row = mysqli_fetch_array($resultcontx)) {   
			$nom_contexto = $row['cod_contexto'].' - '.$row['contexto'];
		}
		mysqli_free_result($resultcontx);
	$valor_contexto = ' a.sysContext = '.$cod_contexto.' and ';	
	$valor_contexto2 = ' c.sysContext = '.$cod_contexto.' and ';	
}


//familia
if ($familia == 0) { // if familia
		$nom_familia = 'Todos';
		$valor_familia = ' ';
	} else {
		//nombre familia
		$resultfam = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$familia' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultfam)) {
			$nom_familia = $row['nombre'];
		}
		mysqli_free_result($resultfam);
		$valor_familia = ' e.codFamily = ' .$familia. ' and ';
	} //fin if familia

//sub familia
if ($subfamilia == 0) { // if subfamilia
		$nom_subfamilia = 'Todos';
		$valor_subfamilia = ' ';
	} else {
		//nombre sub familia
		$resultsubf = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$subfamilia' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultsubf)) {
			$nom_subfamilia = $row['nombre'];
		}
		mysqli_free_result($resultsubf);
		$valor_subfamilia = ' e.codSubFamily = ' .$subfamilia. ' and ';
	} //fin if subfamilia

//grupo	
if ($grupo == 0) { // if grupo
		$nom_grupo = 'Todos';
		$valor_grupo = ' ';
	} else {
		//nombre grupo
		$resultgru = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$grupo' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultgru)) {
			$nom_grupo = $row['nombre'];
		}
		mysqli_free_result($resultgru);
		$valor_grupo = ' e.codGroup = ' .$grupo. ' and ';
	} //fin if grupo

//subgrupo	
if ($subgrupo == 0) { // if subgrupo
		$nom_subgrupo = 'Todos';
		$valor_subgrupo = ' ';
	} else {
		//nombre sub grupo
		$resultsubg = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$subgrupo' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultsubg)) {
			$nom_subgrupo = $row['nombre'];
		}
		mysqli_free_result($resultsubg);
		$valor_subgrupo = ' e.codSubGroup = ' .$subgrupo. ' and ';
	} //fin if subgrupo

//orden
if($orden == 0) {
	$nom_orden = 'Nombre';
	$valor_orden = ' order by t.item ';
}

if($orden == 1) {
	$nom_orden = 'C&oacute;digo';
	$valor_orden = ' order by t.cod_item ';
}

if($orden == 2) {
	$nom_orden = 'C&oacute;digo de F&aacute;brica';
	$valor_orden = ' order by t.cod_fab ';
}

if($orden == 3) {
	$nom_orden = 'Familia (C&oacute;digo)';
	$valor_orden = ' order by t.cod_familia ';
}



//este query calcula con el tc en el que se hizo la transacción
$result = mysqli_query($link, "select t.cod_item as cod_item, t.cod_fab as cod_fab, t.item as item, t.cod_familia as cod_familia, t.cod_subfamilia as cod_subfamilia, t.cod_grupo as cod_grupo, t.cod_subgrupo as cod_subgrupo, t.cod_marca as cod_marca, t.cod_modelo as cod_modelo, t.cod_gasto as cod_gasto, t.concepto_gasto as concepto_gasto, sum(t.monto_om) as monto_om, t.tipo_con as tipo_con
from (
select e.pkyItem as cod_item, e.fldFactoryKey as cod_fab, e.fldName as item, e.codFamily as cod_familia, e.codSubFamily as cod_subfamilia, e.codGroup as cod_grupo, e.codSubGroup as cod_subgrupo, e.codBrand as cod_marca, e.codBrandModel as cod_modelo, a.codExpensesConcept as cod_gasto, b.fldName as concepto_gasto, a.fldAmount as monto, c.codCurrency as cod_moneda, c.codExchangeRate as cod_tc, d.fldRate as tc, a.fldAmount * d.fldRate as monto_om, 0 as tipo_con
from
payAccountsPayableDetail a, payExpensesConcept b, payAccountsPayable c, actExchangeRateDetail d, invItem e
where 
$valor_item 
$valor_con_gasto 
$valor_documento  
$valor_familia 
$valor_subfamilia 
$valor_grupo 
$valor_subgrupo 
$valor_marca 
$valor_modelo 
$valor_ver_cxp 
$valor_contexto2 
b.pkyExpensesConcept <> 20 and 
a.codExpensesConcept = b.pkyExpensesConcept and 
a.codAccountsPayable = c.pkyAccountsPayable and 
c.codExchangeRate = d.codExchangeRate and 
a.codItem = e.pkyItem and 
c.fldDate >= '$fechaini' and 
c.fldDate <= '$fechafin' and 
d.codBaseCurrency = '$otra_moneda' and 
d.codTargetCurrency = c.codCurrency and 
c.sysEnabled = 1 and c.sysAuthorized = 1

union all

select e.pkyItem as cod_item, e.fldFactoryKey as cod_fab, e.fldName as item, e.codFamily as cod_familia, e.codSubFamily as cod_subfamilia, e.codGroup as cod_grupo, e.codSubGroup as cod_subgrupo, e.codBrand as cod_marca, e.codBrandModel as cod_modelo, a.codExpensesConcept as cod_gasto, b.fldName as concepto_gasto, a.fldAmount as monto, c.codCurrency as cod_moneda, c.codExchangeRate as cod_tc, 1 as tc, a.fldAmount * 1 as monto_om, 0 as tipo_con
from
payAccountsPayableDetail a, payExpensesConcept b, payAccountsPayable c, invItem e
where 
$valor_item 
$valor_con_gasto 
$valor_documento 
$valor_familia 
$valor_subfamilia 
$valor_grupo 
$valor_subgrupo 
$valor_marca 
$valor_modelo 
$valor_ver_cxp 
$valor_contexto2 
b.pkyExpensesConcept <> 20 and 
a.codExpensesConcept = b.pkyExpensesConcept and 
a.codAccountsPayable = c.pkyAccountsPayable and 
a.codItem = e.pkyItem and 
c.fldDate >= '$fechaini' and 
c.fldDate <= '$fechafin' and 
c.codCurrency = '$otra_moneda' and
c.sysEnabled = 1 and c.sysAuthorized = 1

UNION ALL 

select e.pkyItem as cod_item, e.fldFactoryKey as cod_fab, e.fldName as item, e.codFamily as cod_familia, e.codSubFamily as cod_subfamilia, e.codGroup as cod_grupo, e.codSubGroup as cod_subgrupo, e.codBrand as cod_marca, e.codBrandModel as cod_modelo, b.pkyItemMovementTypeConcept as cod_gasto, b.fldName as concepto_gasto, c.fldTotaCost as monto, a.codCurrency as cod_moneda, a.codExchangeRate as cod_tc , d.fldRate as tc, c.fldTotaCost * d.fldRate as monto_om, 1 as tipo_con
from
invItemMovement a, invItemMovementTypeConcept b, invItemMovementDetail c, actExchangeRateDetail d, invItem e
where 
$valor_item 
$valor_con_egreso 
$valor_familia 
$valor_subfamilia 
$valor_grupo 
$valor_subgrupo 
$valor_marca 
$valor_modelo 
$valor_contexto 
a.codTypeConcept = b.pkyItemMovementTypeConcept and 
a.codType = 2 and 
a.pkyItemMovement = c.codItemMovement and 
b.fldItemControl = 1 and 
a.codExchangeRate = d.codExchangeRate and 
a.codItem = e.pkyItem and 
a.fldDate >= '$fechaini' and 
a.fldDate <= '$fechafin' and 
d.codBaseCurrency = '$otra_moneda' and 
d.codTargetCurrency = a.codCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1

union all 

select e.pkyItem as cod_item, e.fldFactoryKey as cod_fab, e.fldName as item, e.codFamily as cod_familia, e.codSubFamily as cod_subfamilia, e.codGroup as cod_grupo, e.codSubGroup as cod_subgrupo, e.codBrand as cod_marca, e.codBrandModel as cod_modelo, b.pkyItemMovementTypeConcept as cod_gasto, b.fldName as concepto_gasto, c.fldTotaCost as monto, a.codCurrency as cod_moneda, a.codExchangeRate as cod_tc , 1 as tc, c.fldTotaCost * 1 as monto_om, 1 as tipo_con
from
invItemMovement a, invItemMovementTypeConcept b, invItemMovementDetail c, invItem e
where 
$valor_item 
$valor_con_egreso 
$valor_familia 
$valor_subfamilia 
$valor_grupo 
$valor_subgrupo 
$valor_marca 
$valor_modelo 
$valor_contexto 
a.codTypeConcept = b.pkyItemMovementTypeConcept and 
a.codType = 2 and 
a.pkyItemMovement = c.codItemMovement and 
b.fldItemControl = 1 and 
a.codItem = e.pkyItem and 
a.fldDate >= '$fechaini' and 
a.fldDate <= '$fechafin' and 
a.codCurrency = '$otra_moneda' and 
a.sysEnabled = 1 and a.sysAuthorized = 1) t
group by t.cod_item 
$valor_orden;");

$mat_gas = array();
$m = 1;
while ($row = mysqli_fetch_array($result)) {
	$mat_gas [$m][1] = $row['cod_item'];
	$mat_gas [$m][2] = $row['cod_fab'];
	$mat_gas [$m][3] = $row['item'];
	$mat_gas [$m][4] = $row['cod_familia'];
	$mat_gas [$m][5] = NULL; //nombre familia
	$mat_gas [$m][6] = $row['cod_subfamilia'];
	$mat_gas [$m][7] = NULL; //nombre subfamilia
	$mat_gas [$m][8] = $row['cod_grupo'];
	$mat_gas [$m][9] = NULL; //nombre grupo
	$mat_gas [$m][10] = $row['cod_subgrupo'];
	$mat_gas [$m][11] = NULL; //nombre subgrupo
	$mat_gas [$m][12] = $row['cod_marca'];
	$mat_gas [$m][13] = NULL; //nombre marca
	$mat_gas [$m][14] = $row['cod_modelo'];
	$mat_gas [$m][15] = NULL; //nombre modelo
	$mat_gas [$m][16] = $row['monto_om'];
	$cod_fam = $row['cod_familia'];
	$cod_sfam = $row['cod_subfamilia'];
	$cod_gru = $row['cod_grupo'];
	$cod_sgru = $row['cod_subgrupo'];
	$cod_mod = $row['cod_modelo'];
	$cod_mar = $row['cod_marca'];
	
	//nombre familia
		$resultfam = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$cod_fam' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultfam)) {
			$mat_gas [$m][5] = $row['nombre'];
		}
		mysqli_free_result($resultfam);
		
	//nombre sub familia
		$resultsubf = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$cod_sfam' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultsubf)) {
			$mat_gas [$m][7] = $row['nombre'];
		}
		mysqli_free_result($resultsubf);
	
	//nombre grupo
		$resultgru = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$cod_gru' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultgru)) {
			$mat_gas [$m][9] = $row['nombre'];
		}
		mysqli_free_result($resultgru);
	
	//nombre sub grupo
		$resultsubg = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$cod_sgru' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultsubg)) {
			$mat_gas [$m][11] = $row['nombre'];
		}
		mysqli_free_result($resultsubg);
	
	//nombre marca
		$resultmar = mysqli_query($link, "select pkyBrand as cod, fldName as marca
							from 
							invBrand
							where
							pkyBrand = '$cod_mar' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultmar)) {
			$mat_gas [$m][13] = $row['marca'];
		}
		mysqli_free_result($resultmar);
	
	//nombre modelo
		$resultmod = mysqli_query($link, "select pkyBrandModel as cod, fldName as modelo
							from 
							invBrandModel
							where
							pkyBrandModel = '$cod_mod' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultmod)) {
			$mat_gas [$m][15] = $row['modelo'];
		}
		mysqli_free_result($resultmod);
		
	$m++;
}
mysqli_free_result($result);
$fin_g = $m - 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>Gastos por Item</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 colspan="2"><b>Item: </b><?php echo $nom_item; ?></TD>
        <TD width="25%"><b>Concepto de Gasto: </b><?php echo $nom_con_gasto; ?></TD>
        <TD width="25%"><b>Concepto de Egreso: </b><?php echo $nom_con_egreso; ?></TD>
        </TR>
        <TR> 
        <TD><b>Tipo de Documento: </b><?php echo $nom_documento; ?></TD>
        <TD><b>Marca: </b><?php echo $nom_marca; ?></TD>
        <TD><b>Modelo: </b><?php echo $nom_modelo; ?></TD>
        <TD><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        </TR>
        <TR> 
        <TD><b>Familia: </b><?php echo $nom_familia; ?></TD>
        <TD><b>Sub Familia: </b><?php echo $nom_subfamilia; ?></TD>
        <TD><b>Grupo: </b><?php echo $nom_grupo; ?></TD>
        <TD><b>Sub Grupo: </b><?php echo $nom_subgrupo; ?></TD>
        </TR>
        <TR>
        <TD><b>Ordenado por: </b><?php echo $nom_orden; ?></TD>
        <TD colspan="2"><b>De Fecha: </b><?php echo $fechaini; ?> <b>a Fecha: </b><?php echo $fechafin; ?></TD>
        <TD><b>Valorado en: </b><?php echo $nom_otra_moneda; ?></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; ?>" 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></tr>", 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>Cod. Fab.</b></TD>
    <TD align="center"><b>Item</b></TD>
    <TD align="center"><b>Familia</b></TD>
    <TD align="center"><b>Sub Familia</b></TD>
    <TD align="center"><b>Grupo</b></TD>
    <TD align="center"><b>Sub Grupo</b></TD>
    <TD align="center"><b>Marca</b></TD>
    <TD align="center"><b>Modelo</b></TD>
	<TD align="center"><b>Monto</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$suma_gastos = 0;
$m = 1;	
while ($m <= $fin_g) { //while
		
	$cod_item = $mat_gas [$m][1];
	if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $mat_gas [$m][1]);//cod item
	} else {
		printf("<tr><td align='center'>%s</td>", $mat_gas [$m][1]);//cod item
	}//cierra if color
	printf("<td align='center'>%s</td>", $mat_gas [$m][2]);//cod fabrica
	printf("<td align='left'>%s</td>", $mat_gas [$m][3]);//item
	printf("<td align='left'>%s</td>", $mat_gas [$m][5]);//familia
	printf("<td align='left'>%s</td>", $mat_gas [$m][7]);//sub familia
	printf("<td align='left'>%s</td>", $mat_gas [$m][9]);//grupo
	printf("<td align='left'>%s</td>", $mat_gas [$m][11]);//sub grupo
	printf("<td align='left'>%s</td>", $mat_gas [$m][13]);//marca
	printf("<td align='left'>%s</td>", $mat_gas [$m][15]);//modelo
	
	printf("<td align='right'><a href='report.php?rep=5&tipo=2&item_det=$cod_item&con_gasto_det=$con_gasto&con_egreso_det=$con_egreso&documento_det=$documento&marca_det=$marca&modelo_det=$modelo&familia_det=$familia&subfamilia_det=$subfamilia&grupo_det=$grupo&subgrupo_det=$subgrupo&otra_moneda_det=$otra_moneda&fechaini_det=$fechaini&fechafin_det=$fechafin&contexto_det=$cod_contexto&usuario_det=$usuario' title='Detalle de Gastos'>%s</a></td></tr>", number_format($mat_gas [$m][16],$n_decimales));//monto
	
	$suma_gastos = $suma_gastos + $mat_gas [$m][16];
	$m++;
	$color++;
}//fin while

	
?>

<tr BGCOLOR='#ffcccc'><td colspan="9"><b>Total</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_gastos,$n_decimales)); ?></td></tr>
</tbody>
</table>
<?php

} //fin if rep



// inicio muestra detalle, tc a la fecha de la transaccion

if($rep == 5 && $tipo == 2) { // if 3


//nombre otra moneda
$resultotra = mysqli_query($link, "SELECT fldName as otra_moneda
from
actCurrency
where
pkyCurrency = '$otra_moneda_det' and
sysEnabled = 1 and sysAuthorized = 1;");
		
while ($row = mysqli_fetch_array($resultotra)) {
	$nom_otra_moneda_det = $row['otra_moneda'];
}
mysqli_free_result($resultotra);

//item
	$resultitem = mysqli_query($link, "select pkyItem as cod_item, fldName as item, fldFactoryKey as cod_fabrica
	from
	invItem
	where
	pkyItem = '$item_det' and
	sysEnabled = 1 and sysAuthorized = 1;");
		
	while ($row = mysqli_fetch_array($resultitem)) {
	$nom_item_det = $row['cod_item'].' - '.$row['cod_fabrica'].' - '.$row['item'];
	}
	mysqli_free_result($resultitem);

//concepto de gasto
if ($con_gasto_det == 0) { //if concepto de gasto
	$nom_con_gasto_det = 'Todos';
	$valor_con_gasto_det = ' ';
} else { 
    if ($con_gasto_det == -1) { //if concepto de gasto 2
	$nom_con_gasto_det = 'Solo Concepto de Egreso (Mov. Merc.)';
  	} else {
	//nombre del concepto de gasto
	$resultgasto = mysqli_query($link, "select pkyExpensesConcept as codigo, fldName as gasto
	from payExpensesConcept 
	where
	pkyExpensesConcept = '$con_gasto_det' and 
	sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultgasto)) {
			$nom_con_gasto_det = $row['gasto'];
		}
		mysqli_free_result($resultgasto);
	} //fin if concepto de gasto 2
	$valor_con_gasto_det = ' a.codExpensesConcept = '.$con_gasto_det.' and ';
} //fin if concepto de gasto

//concepto de egreso
if ($con_egreso_det == 0) { //if concepto de egreso
	$nom_con_egreso_det = 'Todos';
	$valor_con_egreso_det = ' ';
} else { 
    if ($con_egreso_det == -1) { //if concepto de egreso 2
	$nom_con_egreso_det = 'Solo Concepto de Gasto';
  	} else {
	//nombre del concepto de egreso
	$resultegreso = mysqli_query($link, "select pkyItemMovementTypeConcept as codigo, fldName as egreso
	from
	invItemMovementTypeConcept
	where
	pkyItemMovementTypeConcept = '$con_egreso_det' and 
	sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultegreso)) {
			$nom_con_egreso_det = $row['egreso'];
		}
		mysqli_free_result($resultegreso);
	} //fin if concepto de egreso 2
	$valor_con_egreso_det = ' a.codTypeConcept = '.$con_egreso_det.' and ';
} //fin if concepto de egreso

//documento 
if ($documento_det == 0) { //if documento
	$nom_documento_det = 'Todos';
	$valor_documento_det = ' ';
} else { 
	if($documento_det == 999) { //if documento 2
	$nom_documento_det = 'Egresos';
	} else {
	//esto es para limitar solo a gasto
	$nom_con_egreso = 'Solo Concepto de Gasto';
  	$valor_con_egreso = ' a.codTypeConcept = '.$con_egreso_det.' and ';
	//nombre del documento
	$resultdoc = mysqli_query($link, "select pkyDocumentType as codigo, fldName as dcto
	from txsDocumentType 
	where 
	pkyDocumentType = '$documento_det' and 
	sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultdoc)) {
			$nom_documento_det = $row['dcto'];
		}
		mysqli_free_result($resultdoc);
	} //fin if documento 2
  	$valor_documento_det = ' a.codDocumentType = '.$documento_det.' and ';
} //fin if documento

//marca
if ($marca_det == 0) { // if marca
		$nom_marca_det = 'Todos';
		$valor_marca_det = ' ';
	} else {
		//nombre marca
		$resultmar = mysqli_query($link, "select pkyBrand as cod, fldName as marca
							from 
							invBrand
							where
							pkyBrand = '$marca_det' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultmar)) {
			$nom_marca_det = $row['marca'];
		}
		mysqli_free_result($resultmar);
		$valor_marca_det = ' e.codBrand = ' .$marca_det. ' and ';
	} //fin if marca
	
//modelo
if ($modelo_det == 0) { // if modelo
		$nom_modelo_det = 'Todos';
		$valor_modelo_det = ' ';
	} else {
		//nombre modelo
		$resultmod = mysqli_query($link, "select pkyBrandModel as cod, fldName as modelo
							from 
							invBrandModel
							where
							pkyBrandModel = '$modelo_det' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultmod)) {
			$nom_modelo_det = $row['modelo'];
		}
		mysqli_free_result($resultmod);
		$valor_modelo_det = ' e.codBrandModel = ' .$modelo_det. ' and ';
	} //fin if modelo

//contexto
if($cod_contexto_det == -1){ 
	$nom_contexto_det = 'Todos';
	$valor_contexto_det = ' ';
	$valor_contexto_det2 = ' ';
} else {
	$resultcontx = mysqli_query($link, "select pkyContext as cod_contexto, fldName as contexto, codCostCenter as cod_cc 
	from srvContext
	where 
	pkyContext = '$cod_contexto_det';");
		while ($row = mysqli_fetch_array($resultcontx)) {   
			$nom_contexto_det = $row['cod_contexto'].' - '.$row['contexto'];
		}
		mysqli_free_result($resultcontx);
	$valor_contexto_det = ' a.sysContext = '.$cod_contexto_det.' and ';	
	$valor_contexto_det2 = ' c.sysContext = '.$cod_contexto_det.' and ';	
}

//familia
if ($familia_det == 0) { // if familia
		$nom_familia_det = 'Todos';
		$valor_familia_det = ' ';
	} else {
		//nombre familia
		$resultfam = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$familia_det' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultfam)) {
			$nom_familia_det = $row['nombre'];
		}
		mysqli_free_result($resultfam);
		$valor_familia_det = ' e.codFamily = ' .$familia_det. ' and ';
	} //fin if familia

//sub familia
if ($subfamilia_det == 0) { // if subfamilia
		$nom_subfamilia_det = 'Todos';
		$valor_subfamilia_det = ' ';
	} else {
		//nombre sub familia
		$resultsubf = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$subfamilia_det' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultsubf)) {
			$nom_subfamilia_det = $row['nombre'];
		}
		mysqli_free_result($resultsubf);
		$valor_subfamilia_det = ' e.codSubFamily = ' .$subfamilia_det. ' and ';
	} //fin if subfamilia

//grupo	
if ($grupo_det == 0) { // if grupo
		$nom_grupo_det = 'Todos';
		$valor_grupo_det = ' ';
	} else {
		//nombre grupo
		$resultgru = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$grupo_det' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultgru)) {
			$nom_grupo_det = $row['nombre'];
		}
		mysqli_free_result($resultgru);
		$valor_grupo_det = ' e.codGroup = ' .$grupo_det. ' and ';
	} //fin if grupo

//subgrupo	
if ($subgrupo_det == 0) { // if subgrupo
		$nom_subgrupo_det = 'Todos';
		$valor_subgrupo_det = ' ';
	} else {
		//nombre sub grupo
		$resultsubg = mysqli_query($link, "select pkyItemCategory as cod, fldName as nombre
							from 
							invItemCategory
							where
							pkyItemCategory = '$subgrupo_det' and 
							sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultsubg)) {
			$nom_subgrupo_det = $row['nombre'];
		}
		mysqli_free_result($resultsubg);
		$valor_subgrupo_det = ' e.codSubGroup = ' .$subgrupo_det. ' and ';
	} //fin if subgrupo



//este query calcula con el tc en el que se hizo la transacción, mismo de arriba sin agrupacion, se aumento fecha, cod de cxc, cod mov merc y documento
$result_det = mysqli_query($link, "select t.cod_item as cod_item, t.cod_fab as cod_fab, t.item as item, t.fecha as fecha, t.cod_cxp_mov as cod_cxp_mov, t.cod_doc as cod_doc, t.documento as documento, t.cod_familia as cod_familia, t.cod_subfamilia as cod_subfamilia, t.cod_grupo as cod_grupo, t.cod_subgrupo as cod_subgrupo, t.cod_marca as cod_marca, t.cod_modelo as cod_modelo, t.cod_gasto as cod_gasto, t.concepto_gasto as concepto_gasto, mo.fldName as moneda, t.monto as monto, t.tc as tc, t.monto_om as monto_om, t.tipo_con as tipo_con, t.papa as papa, t.cod_papa as cod_papa
from (
select e.pkyItem as cod_item, e.fldFactoryKey as cod_fab, e.fldName as item, c.fldDate as fecha, c.pkyAccountsPayable as cod_cxp_mov, a.codDocumentType as cod_doc, f.fldName as documento, e.codFamily as cod_familia, e.codSubFamily as cod_subfamilia, e.codGroup as cod_grupo, e.codSubGroup as cod_subgrupo, e.codBrand as cod_marca, e.codBrandModel as cod_modelo, a.codExpensesConcept as cod_gasto, b.fldName as concepto_gasto, a.fldAmount as monto, c.codCurrency as cod_moneda, c.codExchangeRate as cod_tc, d.fldRate as tc, a.fldAmount * d.fldRate as monto_om, 0 as tipo_con, c.fldParentComponent as papa, c.cosComponentKey as cod_papa
from
payAccountsPayableDetail a, payExpensesConcept b, payAccountsPayable c, actExchangeRateDetail d, invItem e, txsDocumentType f
where 
$valor_documento_det 
$valor_con_gasto_det 
$valor_familia_det 
$valor_subfamilia_det 
$valor_grupo_det 
$valor_subgrupo_det 
$valor_marca_det 
$valor_modelo_det 
$valor_ver_cxp_det 
$valor_contexto_det2 
b.pkyExpensesConcept <> 20 and 
a.codItem = '$item_det' and 
a.codExpensesConcept = b.pkyExpensesConcept and 
a.codAccountsPayable = c.pkyAccountsPayable and 
c.codExchangeRate = d.codExchangeRate and 
a.codItem = e.pkyItem and 
c.fldDate >= '$fechaini_det' and 
c.fldDate <= '$fechafin_det' and 
d.codBaseCurrency = '$otra_moneda_det' and 
d.codTargetCurrency = c.codCurrency and 
a.codDocumentType = f.pkyDocumentType and 
c.sysEnabled = 1 and c.sysAuthorized = 1

union all

select e.pkyItem as cod_item, e.fldFactoryKey as cod_fab, e.fldName as item, c.fldDate as fecha, c.pkyAccountsPayable as cod_cxp_mov, a.codDocumentType as cod_doc, f.fldName as documento, e.codFamily as cod_familia, e.codSubFamily as cod_subfamilia, e.codGroup as cod_grupo, e.codSubGroup as cod_subgrupo, e.codBrand as cod_marca, e.codBrandModel as cod_modelo, a.codExpensesConcept as cod_gasto, b.fldName as concepto_gasto, a.fldAmount as monto, c.codCurrency as cod_moneda, c.codExchangeRate as cod_tc, 1 as tc, a.fldAmount * 1 as monto_om, 0 as tipo_con, c.fldParentComponent as papa, c.cosComponentKey as cod_papa
from
payAccountsPayableDetail a, payExpensesConcept b, payAccountsPayable c, invItem e, txsDocumentType f
where 
$valor_documento_det 
$valor_con_gasto_det 
$valor_familia_det 
$valor_subfamilia_det 
$valor_grupo_det 
$valor_subgrupo_det 
$valor_marca_det 
$valor_modelo_det 
$valor_ver_cxp_det 
$valor_contexto_det2 
b.pkyExpensesConcept <> 20 and 
a.codItem = '$item_det' and 
a.codExpensesConcept = b.pkyExpensesConcept and 
a.codAccountsPayable = c.pkyAccountsPayable and 
a.codItem = e.pkyItem and 
c.fldDate >= '$fechaini_det' and 
c.fldDate <= '$fechafin_det' and 
c.codCurrency = '$otra_moneda_det' and 
a.codDocumentType = f.pkyDocumentType and 
c.sysEnabled = 1 and c.sysAuthorized = 1

UNION ALL 

select e.pkyItem as cod_item, e.fldFactoryKey as cod_fab, e.fldName as item, a.fldDate as fecha, a.pkyItemMovement as cod_cxp_mov, 999 as cod_doc, 'Egresos' as documento, e.codFamily as cod_familia, e.codSubFamily as cod_subfamilia, e.codGroup as cod_grupo, e.codSubGroup as cod_subgrupo, e.codBrand as cod_marca, e.codBrandModel as cod_modelo, b.pkyItemMovementTypeConcept as cod_gasto, concat(b.fldName, ' (', h.fldName, ') - ', round(c.fldQuantity,2)) as concepto_gasto, c.fldTotaCost as monto, a.codCurrency as cod_moneda, a.codExchangeRate as cod_tc , d.fldRate as tc, c.fldTotaCost * d.fldRate as monto_om, 1 as tipo_con, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from
invItemMovement a, invItemMovementTypeConcept b, invItemMovementDetail c, actExchangeRateDetail d, invItem e, invItem h
where 
$valor_con_egreso_det 
$valor_familia_det 
$valor_subfamilia_det 
$valor_grupo_det 
$valor_subgrupo_det 
$valor_marca_det 
$valor_modelo_det 
$valor_contexto_det 
a.codItem = '$item_det' and 
a.codTypeConcept = b.pkyItemMovementTypeConcept and 
a.codType = 2 and 
a.pkyItemMovement = c.codItemMovement and 
b.fldItemControl = 1 and 
a.codExchangeRate = d.codExchangeRate and 
a.codItem = e.pkyItem and 
a.fldDate >= '$fechaini_det' and 
a.fldDate <= '$fechafin_det' and 
d.codBaseCurrency = '$otra_moneda_det' and 
d.codTargetCurrency = a.codCurrency and 
c.codItem = h.pkyItem and 
a.sysEnabled = 1 and a.sysAuthorized = 1

union all 

select e.pkyItem as cod_item, e.fldFactoryKey as cod_fab, e.fldName as item, a.fldDate as fecha, a.pkyItemMovement as cod_cxp_mov, 999 as cod_doc, 'Egresos' as documento, e.codFamily as cod_familia, e.codSubFamily as cod_subfamilia, e.codGroup as cod_grupo, e.codSubGroup as cod_subgrupo, e.codBrand as cod_marca, e.codBrandModel as cod_modelo, b.pkyItemMovementTypeConcept as cod_gasto, concat(b.fldName, ' (', h.fldName, ') - ', round(c.fldQuantity,2)) as concepto_gasto, c.fldTotaCost as monto, a.codCurrency as cod_moneda, a.codExchangeRate as cod_tc , 1 as tc, c.fldTotaCost * 1 as monto_om, 1 as tipo_con, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from
invItemMovement a, invItemMovementTypeConcept b, invItemMovementDetail c, invItem e, invItem h
where 
$valor_con_egreso_det 
$valor_familia_det 
$valor_subfamilia_det 
$valor_grupo_det 
$valor_subgrupo_det 
$valor_marca_det 
$valor_modelo_det 
$valor_contexto_det 
a.codItem = '$item_det' and 
a.codTypeConcept = b.pkyItemMovementTypeConcept and 
a.codType = 2 and 
a.pkyItemMovement = c.codItemMovement and 
b.fldItemControl = 1 and 
a.codItem = e.pkyItem and 
a.fldDate >= '$fechaini_det' and 
a.fldDate <= '$fechafin_det' and 
a.codCurrency = '$otra_moneda_det' and 
c.codItem = h.pkyItem and 
a.sysEnabled = 1 and a.sysAuthorized = 1) t, actCurrency mo
where 
t.cod_moneda = mo.pkyCurrency 
order by t.fecha, t.concepto_gasto;");

$mat_gas_det = array();
$m = 1;
while ($row = mysqli_fetch_array($result_det)) {
	$mat_gas_det [$m][1] = $row['cod_cxp_mov'];
	$mat_gas_det [$m][2] = $row['concepto_gasto'];
	$mat_gas_det [$m][3] = $row['documento'];
	$mat_gas_det [$m][4] = $row['moneda'];
	$mat_gas_det [$m][5] = $row['monto'];
	$mat_gas_det [$m][6] = $row['tc'];
	$mat_gas_det [$m][7] = $row['monto_om'];
	$mat_gas_det [$m][8] = $row['tipo_con'];
	
	//para enlazar al que genero el asiento
	$papa_componente = $row['papa'];
	$papa_codigo = $row['cod_papa'];
	$usuario = $usuario_det;
	include "../../generadopor.php";
	$mat_gas_det [$m][9] = $papa_enlace;
		
	$m++;
}
mysqli_free_result($result_det);
$fin_det = $m - 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_det; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Detalle Gastos por Item</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 colspan="2"><b>Item: </b><?php echo $nom_item_det; ?></TD>
        <TD width="25%"><b>Concepto de Gasto: </b><?php echo $nom_con_gasto_det; ?></TD>
        <TD width="25%"><b>Concepto de Egreso: </b><?php echo $nom_con_egreso_det; ?></TD>
        </TR>
        <TR> 
        <TD><b>Tipo de Documento: </b><?php echo $nom_documento_det; ?></TD>
        <TD><b>Marca: </b><?php echo $nom_marca_det; ?></TD>
        <TD><b>Modelo: </b><?php echo $nom_modelo_det; ?></TD>
        <TD><b>Contexto: </b><?php echo $nom_contexto_det; ?></TD>
        </TR>
        <TR> 
        <TD><b>Familia: </b><?php echo $nom_familia_det; ?></TD>
        <TD><b>Sub Familia: </b><?php echo $nom_subfamilia_det; ?></TD>
        <TD><b>Grupo: </b><?php echo $nom_grupo_det; ?></TD>
        <TD><b>Sub Grupo: </b><?php echo $nom_subgrupo_det; ?></TD>
        </TR>
        <TR>
        <TD><b>Ordenado por: </b>Fecha</TD>
        <TD colspan="2"><b>De Fecha: </b><?php echo $fechaini_det; ?> <b>a Fecha: </b><?php echo $fechafin_det; ?></TD>
        <TD><b>Valorado en: </b><?php echo $nom_otra_moneda_det; ?></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_det; ?>&user=<?php echo $usuario; ?>" title="Tipo de Cambio"><?php echo $ultimo_tc_det; ?></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></tr>", 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>Concepto de Gasto/Egreso</b></TD>
    <TD align="center"><b>Tipo de Doc.</b></TD>
    <TD align="center"><b>Gen. Por</b></TD>
    <TD align="center"><b>Mon.</b></TD>
    <TD align="center"><b>Monto</b></TD>
    <TD align="center"><b>Tasa</b></TD>
    <TD align="center"><b>Monto en <?php echo $nom_otra_moneda_det; ?></b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$suma_gastos_det = 0;
$m = 1;	
while ($m <= $fin_det) { //while
	$cod_cxp_mov = $mat_gas_det [$m][1];	
	$cod_tipo = $mat_gas_det [$m][8];
	if($color % 2 == 0) { //if color
		if($cod_tipo == 0) {//if 0
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'><a href='../../ModulePayments/VoucherAccountsPayable/index.php?pkyAccountsPayable=$cod_cxp_mov&user=$usuario_det' title='Nota de Cuenta por Pagar'>%s</a></td>", $mat_gas_det [$m][1]);//cod cxp
		} else {//else if 0
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'><a href='../../ModuleInventory/VoucherItemMovement/index.php?pkyItemMovement=$cod_cxp_mov&showBatch=0&printAccountEntry=0&user=$usuario_det' title='Movimiento de Mercader&iacute;a'>%s</a></td>", $mat_gas_det [$m][1]);//cod mov merc
		}//fin if 0
	} else { //else if color
		if($cod_tipo == 0) {//if 0
		printf("<tr><td align='center'><a href='../../ModulePayments/VoucherAccountsPayable/index.php?pkyAccountsPayable=$cod_cxp_mov&user=$usuario_det' title='Nota de Cuenta por Pagar'>%s</a></td>", $mat_gas_det [$m][1]);//cod cxp
		} else {//else if 0
		printf("<tr><td align='center'><a href='../../ModuleInventory/VoucherItemMovement/index.php?pkyItemMovement=$cod_cxp_mov&showBatch=0&printAccountEntry=0&user=$usuario_det' title='Movimiento de Mercader&iacute;a'>%s</a></td>", $mat_gas_det [$m][1]);//cod mov merc
		}//fin if 0
	}//cierra if color
	printf("<td align='left'>%s</td>", $mat_gas_det [$m][2]);//concepto de gasto
	printf("<td align='left'>%s</td>", $mat_gas_det [$m][3]);//documento
	printf("<td align='center'>%s</td>", $mat_gas_det [$m][9]);//gen por
	printf("<td align='left'>%s</td>", $mat_gas_det [$m][4]);//moneda
	printf("<td align='right'>%s</td>", number_format($mat_gas_det [$m][5],$n_decimales));//monto
	printf("<td align='right'>%s</td>", number_format($mat_gas_det [$m][6],$n_tipocambio));//tasa
	printf("<td align='right'>%s</td>", number_format($mat_gas_det [$m][7],$n_decimales));//monto om
	
	$suma_gastos_det = $suma_gastos_det + $mat_gas_det [$m][7];
	$m++;
	$color++;
}//fin while
	


?>
<tr BGCOLOR='#ffcccc'><td colspan="7"><b>Total</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_gastos_det,$n_decimales)); ?></td></tr>
</tbody>
</table>

<?php
} //fin if 3
?>
</body>
</html>
