<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nota de Orden de Producci&oacute;n</title>
<link href="../../maincss.css" rel="stylesheet" type="text/css" />
<link href="../../printcss.css" rel="stylesheet" type="text/css" media="print" />
<script language="JavaScript"> 
 
function oculta(id){
	 var elDiv = document.getElementById(id); //se define la variable "elDiv" igual a nuestro div
	 elDiv.style.display='none'; //damos un atributo display:none que oculta el div	 
	}
 
function muestra(id){
	 var elDiv = document.getElementById(id); //se define la variable "elDiv" igual a nuestro div
	 elDiv.style.display='block';//damos un atributo display:block que  el div	 
	}
 
window.onload = function(){/*hace que se cargue la función */
/* "Mandamos como parametro el nombre de la Div para ocultar" */
oculta('Pcostoind');
}
</script>

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

$rep=$_GET["rep"];
$tipo=$_GET["tipo"];

//index.php?pkyProductionOrder=1&user=Luigi
$cod_prod = $_GET["pkyProductionOrder"];
$muestra_asiento = $_GET["printAccountEntry"];
//$muestra_asiento = 1;
//$mostrar_indirecto = $_GET["showIndirect"]; //si es 1 muestra los costos indirectos, si es 0 no

//if($mostrar_indirecto == NULL) { $mostrar_indirecto = 0; }


$usuario = $_GET["user"];
//$n_decimales = 6;
if($rep == 1) { $muestra_cc = 1; }
if($rep == 2) { $muestra_cc = 0; }


?>
<body>

<?php
	
// Inicio impresion nota de produccion

$result3 = mysqli_query($link, "select a.pkyProductionOrder as cod_prod, a.fldDocumentNumber as nro_doc, 
a.fldDate as fecha, b.fldName as linea_prod, a.codItemMovementOut as egreso_alm, a.codItemMovementIn as ingreso_alm, a.codAccountEntry as cod_asiento, a.codProjection as cod_proy, a.txtDescription as glosa, a.sysEnabled as enabled, a.sysAuthorized as authorized, g.fldName as usuario_reg, a.sysContext as cod_contexto, s.fldName as contexto
from prdProductionOrder a, prdProductionLine b, accGroup g, srvContext s  
where 
a.codProductionLine = b.pkyProductionLine and 
a.sysAuthorizationGroup = g.pkyGroup and 
a.sysContext = s.pkyContext and 
a.pkyProductionOrder = '$cod_prod';");
	while ($row = mysqli_fetch_array($result3)) {
	$nro_doc = $row['nro_doc'];
	$fecha = $row['fecha'];
	$linea_prod = $row['linea_prod'];
	$egreso_alm = $row['egreso_alm'];
	$ingreso_alm = $row['ingreso_alm'];
	$cod_asiento = $row['cod_asiento'];
	$cod_proy = $row['cod_proy'];
	$glosa = $row['glosa'];
	$glosa = nl2br($glosa);
	$glosa = str_replace('\n','<br />',$glosa);
	$usuario_reg = $row['usuario_reg'];
	$enabled = $row['enabled'];
	$authorized = $row['authorized'];
	$cod_contexto = $row['cod_contexto'];
	$contexto = $row['contexto'];
	}
	mysqli_free_result($result3);

//proyeccion
$result31 = mysqli_query($link, "select fldDocumentNumber as nro_doc 
from prdProductionProjection 
where 
pkyProductionProjection = '$cod_proy';");
	while ($row = mysqli_fetch_array($result31)) {
	$nombre_proy = $row['nro_doc'];
	}
	mysqli_free_result($result31);

//detalle
$result2 = mysqli_query($link, "select a.pkyProductionOrderDetail as cod_prod_det, a.codItem as cod_item, b.fldName as item, a.fldQuantity as cantidad, b.codMinimumStorageUnit as cod_unidad, c.fldName as unidad, a.fldExtraCost as costo_extra, d.pkyRecipe as cod_receta
from prdProductionOrderDetail a, invItem b, invStorageUnit c, prdRecipe d  
where 
a.codItem = b.pkyItem and 
b.codMinimumStorageUnit = c.pkyStorageUnit and 
a.codItem = d.codItem and 
a.codProductionOrder = '$cod_prod'
order by b.fldName;");

//costos indirectos
$result4 = mysqli_query($link, "select a.pkyProductionOrderConcept as cod_con_prod, b.fldName as con_prod, a.fldAmount as monto, a.codItem as cod_item, c.fldName as item 
from prdProductionOrderConcept a, prdProductionConcept b, invItem c
where 
a.codProductionConcept = b.pkyProductionConcept and 
a.codItem = c.pkyItem and 
a.codProductionOrder = '$cod_prod'
order by b.fldName;");

//insumos extra
$result5 = mysqli_query($link, "select a.pkyExtraItem as cod_extra, a.codItem as cod_item, b.fldName as item, b.fldBarcode as cod_barra, a.fldQuantity as cantidad, a.fldCost as costo, a.fldTotaCost as total_costo 
from prdExtraItem a, invItem b
where 
a.codItem = b.pkyItem and 
a.codProductionOrder = '$cod_prod'
order by b.fldName;");


?>
<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 Orden de Producci&oacute;n</b></font></center></p>
	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="25%"><b>Cod. Reg.: </b><?php echo $cod_prod; ?></TD>
        <TD width="25%"><b>Nro. Doc.: </b><?php echo $nro_doc; ?></TD>
        <TD width="25%"><b>Fecha de Reg.: </b><?php echo $fecha; ?></TD>
        <TD width="25%"><b>L&iacute;nea de Producci&oacute;n: </b><?php echo $linea_prod; ?></TD>
        </TR>
        <TR>
        <TD><b>Proyecci&oacute;n: </b><a href="../../ModuleProduction/VoucherProductionProjection/index.php?pkyProductionProjection=<?php echo $cod_proy; ?>&user=<?php echo $usuario; ?>" title="Proyecci&oacute;n de Producci&oacute;n"><?php echo $cod_proy; ?></a> - <?php echo $nombre_proy; ?></TD>
        <TD><b>Asiento: </b><a href="../../ModuleAccounting/VoucherAccountEntry/index.php?pkyAccountEntry=<?php echo $cod_asiento; ?>&showCC=0&user=<?php echo $usuario; ?>" title="Asiento Contable"><?php echo $cod_asiento; ?></a></TD>
        <TD><b>Egr. Materia Prima: </b><a href="../../ModuleInventory/VoucherItemMovement/index.php?pkyItemMovement=<?php echo $egreso_alm; ?>&showBatch=0&printAccountEntry=0&user=<?php echo $usuario; ?>" title="Nota de Movimiento de Mercaderia"><?php echo $egreso_alm; ?></a></TD>
        <TD><b>Ing. Prod. Terminado: </b><a href="../../ModuleInventory/VoucherItemMovement/index.php?pkyItemMovement=<?php echo $ingreso_alm; ?>&showBatch=0&printAccountEntry=0&user=<?php echo $usuario; ?>" title="Nota de Movimiento de Mercaderia"><?php echo $ingreso_alm; ?></a></TD>
        </TR>
        <TD  colspan="4"><b>Contexto: </b><?php echo $cod_contexto; ?> - <?php echo $contexto; ?></TD>
        <TR> 
        <TD colspan="4"><b>Descripci&oacute;n: </b><?php echo $glosa; ?></TD>
        </TR>
    </table>
<br />
<b>Detalle:</b>
<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center" width="100"><b>Cod.</b></TD>
    <TD align="center" width="100"><b>Cod. Item</b></TD>
    <TD align="center"><b>Item</b></TD>
    <TD align="center" width="100"><b>Receta</b></TD>
    <TD align="center" width="100"><b>Unidad</b></TD>
    <TD align="center" width="100"><b>Cant.</b></TD>
    <TD align="center" width="100"><b>Costo Extra en <?php echo $nom_moneda_principal; ?></b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">
   
    <?php
    $color = 2;
	$suma_cantidad = 0;
	$suma_costo_extra = 0;
	$uni = array();
	$i = 1;
		
	while ($row = mysqli_fetch_array($result2)) { //while
		
		$uni[$i] = $row['cod_unidad'];
		$total_unidad = $row['unidad'];
		$cod_receta = $row['cod_receta'];
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $row['cod_prod_det']);//cod produccion detalle
		} else {
		printf("<tr><td align='center'>%s</td>", $row['cod_prod_det']);//cod produccion detalle
		} //cierra if color
		printf("<td align='center'>%s</td>", $row['cod_item']);//cod item
		printf("<td align='left'>%s</td>", $row['item']);//item
		printf("<td align='center'><a href='../../ModuleProduction/VoucherRecipe/index.php?pkyRecipe=$cod_receta&user=$usuario' title='Receta'>%s</a></td>", $row['cod_receta']);//cod receta
		printf("<td align='left'>%s</td>", $row['unidad']);//unidad
		printf("<td align='right'>%s</td>", number_format($row['cantidad'], $n_cantidad));//cantidad
		printf("<td align='right'>%s</td></tr>", number_format($row['costo_extra'], $n_decimales));//costo extra
				
		$suma_cantidad = $suma_cantidad + $row['cantidad'];
		$suma_costo_extra = $suma_costo_extra + $row['costo_extra'];
		$color++;
		$i++;
	}//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 en cantidad es solo referencial, las unidades de los items no son iguales)'; }
	if($valor_uni == 0) { $total_unidad = ' '; }
/*	
	//convierte el total en literal
	$letras=new NroEnLetra($suma_cantidad,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="5"><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_cantidad, $n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_costo_extra, $n_decimales); ?></b></td>
    </tr>
</tbody>    
</table>
<br />
<b>Costos Indirectos:</b> <button onclick="muestra('Pcostoind')" class="boton">Mostrar</button> <button onclick="oculta('Pcostoind')" class="boton">Ocultar</button> 
<table border="1" align="center" cellpadding="2" width="100%" id="Pcostoind">
 	<thead>
    <TR> 
    <TD align="center" width="100"><b>Cod.</b></TD>
    <TD align="center" width="65%"><b>Concepto de Producci&oacute;n</b></TD>
    <TD align="center" width="100"><b>Monto en <?php echo $nom_moneda_principal; ?></b></TD>
    <TD align="center" width="100"><b>Cod. Item</b></TD>
    <TD align="center" width="100"><b>Item</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">
   
    <?php
    $color = 2;
	$suma_monto = 0;
	$i = 1;
		
	while ($row = mysqli_fetch_array($result4)) { //while
		
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $row['cod_con_prod']);//cod concepto produccion
		} else {
		printf("<tr><td align='center'>%s</td>", $row['cod_con_prod']);//cod concepto produccion
		} //cierra if color
		printf("<td align='left'>%s</td>", $row['con_prod']);//concepto produccion
		printf("<td align='right'>%s</td>", number_format($row['monto'], $n_decimales));//monto
		printf("<td align='center'>%s</td>", $row['cod_item']);//cod item
		printf("<td align='left'>%s</td></tr>", $row['item']);//item
				
		$suma_monto = $suma_monto + $row['monto'];
		$color++;
		$i++;
	}//fin while
	mysqli_free_result($result4);
	
	?>
	<tr BGCOLOR='#ffcccc'><td colspan="2"><b>Total</b></td>
    <td align="right"><b><?php echo number_format($suma_monto, $n_decimales); ?></b></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
</tbody>    
</table>
<br />
<b>Insumos Extra:</b>
<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center" width="100"><b>Cod.</b></TD>
    <TD align="center" width="100"><b>Cod. Item</b></TD>
    <TD align="center" width="100"><b>Cod. de Barra</b></TD>
    <TD align="center"><b>Item</b></TD>
    <TD align="center" width="100"><b>Cant.</b></TD>
    <TD align="center" width="100"><b>Costo en <?php echo $nom_moneda_principal; ?></b></TD>
    <TD align="center" width="100"><b>Costo Total en <?php echo $nom_moneda_principal; ?></b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">
   
    <?php
    $color = 2;
	$suma_cantidad_ = 0;
	$suma_costo_ = 0;
	$suma_costo_total_ = 0;
	$i = 1;
		
	while ($row = mysqli_fetch_array($result5)) { //while
		
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $row['cod_extra']);//cod extra
		} else {
		printf("<tr><td align='center'>%s</td>", $row['cod_extra']);//cod extra
		} //cierra if color
		printf("<td align='center'>%s</td>", $row['cod_item']);//cod item
		printf("<td align='center'>%s</td>", $row['cod_barra']);//cod barra
		printf("<td align='left'>%s</td>", $row['item']);//item
		printf("<td align='right'>%s</td>", number_format($row['cantidad'], $n_cantidad));//cantidad
		printf("<td align='right'>%s</td>", number_format($row['costo'], $n_decimales));//costo
		printf("<td align='right'>%s</td></tr>", number_format($row['total_costo'], $n_decimales));//total costo
				
		$suma_cantidad_ = $suma_cantidad_ + $row['cantidad'];
		$suma_costo_ = $suma_costo_ + $row['costo'];
		$suma_costo_total_ = $suma_costo_total_ + $row['total_costo'];
		$color++;
		$i++;
	}//fin while
	mysqli_free_result($result5);
	
	?>
	<tr BGCOLOR='#ffcccc'><td colspan="4"><b>Total</b></td>
    <td align="right"><b><?php echo number_format($suma_cantidad_, $n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_costo_, $n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_costo_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>");
			}
?>


<?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="../../ModuleProduction/VoucherProductionOrder/index.php?pkyProductionOrder='.$cod_prod.'&printAccountEntry=1&rep=2&user='.$usuario.'" 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="../../ModuleProduction/VoucherProductionOrder/index.php?pkyProductionOrder='.$cod_prod.'&printAccountEntry=1&rep=1&user='.$usuario.'" 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,
			a.fldPercent as porcentaje
			from
			actAccountEntryDetailCC a, actCostCenter b
			where
			a.codAccountEntryDetail = '$cod_detalle_' and 
			a.codCostCenter = b.pkyCostCenter;");
			$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_;
			$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
			echo "<table border='0' align='left' cellpadding='2'><tr>";
			for($c = 1; $c <= $fin_cc; $c++){//for $c
			echo "<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];
			
			}//fin for $c
			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>";
			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
?>

<p>&nbsp;</p>
<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>

</body>
</html>
