<?php if( !$export_excel ){ ?>
<style>
.grid
{
    border-bottom: medium none;
}
.grid th 
{
    border-color: #77d5f7;
    background-color: #FFFFFF;
    font-weight: normal;
    font-size: 11px;
    font-family: Verdana,Arial,sans-serif;
    height: 24px;
    padding: 0 2px;
    color: #000000;
}
.grid td 
{
    /*border-left: 0 none;
    border-right-color: #77d5f7;
    border-right-style: solid;
    border-right-width: 1px;
    border-bottom-color: #77d5f7;
    border-bottom-style: solid;
    border-bottom-width: 1px;
    padding: 0 2px;
    /*white-space: pre;*/
    height: 22px;
    /*border: 1px solid #77d5f7;*/
}
</style>
<?php } ?>
<?php
function ingresar_cabecera( $o_ALM_KardexBN, $s_FechaIni, $s_FechaFin )
{
    ?>
    <table cellspacing="0" cellpadding="0" border="0" style="">
        <tr><td style="font-weight: bold;"><?=GSS_CompaniaFN::buscarCompania( myUser::getUser()->getIdCompania() )->getDescripcionLarga()?></td></tr>
        <tr><td style="font-weight: bold;">Nro de RUC: <?=GSS_CompaniaFN::buscarCompania( myUser::getUser()->getIdCompania() )->getRuc()?></td></tr>
    </table>
    <table cellspacing="0" cellpadding="0" border="0" width="100%" style="">
        <tr>
            <td align="center" style="font-size: 25px">13.1 REGISTRO INVENTARIO PERMANENTE - VALORIZADO</td>
        </tr>
        <tr>
            <td align="center">PERIODO: DEL DIA: <?=$s_FechaIni ?> AL DIA: <?=$s_FechaFin?></td>
        </tr>
    </table>
    <table cellspacing="0" cellpadding="0" border="0" width="100%" style="">
        <tr>
            <td align="center"><b>ESTABLECIMIENTO :</b> <?=$o_ALM_KardexBN->getDescripcionAlmacen()?></td>
            <td align="center"><b>METODO DE LA VALUACION:</b> PROMEDIO PONDERADO</td>
            <td align="center"><b>TIPO EXISTENCIA :</b> 01 MERCADERIAS</td>
        </tr>

        <tr>
            <td align="center"><b>CODIGO EXISTENCIA :</b> <?=$o_ALM_KardexBN->getIdItem() ?></td>
            <td align="center"><b>DESCRIPCION :</b> <?=strtoupper( $o_ALM_KardexBN->getDescripcionItem() ) ?></td>
            <td align="center"><b>U.MEDIDA :</b> 07 UNIDAD</td>
        </tr>
    </table>
    <table class="grid" cellspacing="0" cellpadding="0" border="0" align="center" width="100%" style="border-top: 1px solid #77d5f7;">
        <tbody>
            <tr>
                <th colspan="4" style="border-left: 1px solid #77d5f7; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;">
                     DOCUMENTO DE TRASLADO, COMPROBANTE DE PAGO, DOCUMENTO INTERNO O SIMILAR
                </th>
                <th style="border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2" width="10%"> TIPO DE OPERACION </th>
                <th colspan="3" style=" border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;"> ENTRADAS </th>
                <th colspan="3" style=" border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;"> SALIDAS </th>
                <th colspan="3" style=" border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;"> SALDO FINAL </th>
            </tr>
            <tr style="">
                <th style="border-left: 1px solid #77d5f7; border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center" width="6%"> FECHA </th>
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center" width="13%"> TIPO </th>
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> SERIE </th>
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> NUMERO </th>
                
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> CANTIDAD </th>
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> COSTO UNITARIO </th>
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> COSTO TOTAL </th>
                
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> CANTIDAD </th>
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> COSTO UNITARIO </th>
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> COSTO TOTAL </th>
                
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> CANTIDAD </th>
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> COSTO UNITARIO </th>
                <th style="border-bottom: 1px solid #77d5f7;border-right: 1px solid #77d5f7;" align="center"> COSTO TOTAL </th>
            </tr>
        </tbody>
    <?php
}
function ingresar_data( $o_ALM_KardexBN )
{
    global $a_LstItem;
    $s_IdItem = $o_ALM_KardexBN->getIdItem();
    ?>
    <tbody>
        <tr>
            <td style="text-align: center;"> <?=substr( $o_ALM_KardexBN->getIdFecha(), 0, 10 )?> </td>
            <td style="text-align: left; font-size: 9px;"> <?=$o_ALM_KardexBN->getTipoDocumentoComprobante()?> </td>
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getSerieDocumentoFiscal()?> </td>
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getNumeroDocumentoFiscal()?> </td>
            
            <td style="text-align: center; font-size: 9px;"> <?=$o_ALM_KardexBN->getTipoOperacionKardex()?> </td>
            
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getStockIngreso()?> </td>
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getStockIngreso()?$o_ALM_KardexBN->getPrecioCosto():""?> </td>
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getStockIngreso()?$o_ALM_KardexBN->getCostoTotal():""?> </td>
            
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getStockSalida()?> </td>
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getStockSalida()?$o_ALM_KardexBN->getPrecioCosto():""?> </td>
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getStockSalida()?$o_ALM_KardexBN->getCostoTotal():""?> </td>
            
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getSaldoCantidad()?> </td>
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getSaldoPrecioCosto()?> </td>
            <td style="text-align: center;"> <?=$o_ALM_KardexBN->getSaldoCostoTotal()?> </td>
        </tr>
    </tbody>
    <?php
    if( $o_ALM_KardexBN->getStockIngreso() )
        $a_LstItem[$s_IdItem]['IN_COSTO_TOTAL'] = $a_LstItem[$s_IdItem]['IN_COSTO_TOTAL'] + $o_ALM_KardexBN->getCostoTotal();
    else
        $a_LstItem[$s_IdItem]['SA_COSTO_TOTAL'] = $a_LstItem[$s_IdItem]['SA_COSTO_TOTAL'] + $o_ALM_KardexBN->getCostoTotal();
    $a_LstItem[$s_IdItem]['SF_COSTO_TOTAL'] = $o_ALM_KardexBN->getSaldoCostoTotal();
}
function ingresar_data_saldo( $o_ALM_KardexBN )
{
    if( $o_ALM_KardexBN->getIdTransaccion() != "STI" )
    {
        global $a_LstItem;
        $s_IdItem = $o_ALM_KardexBN->getIdItem();
        $o_TmpALM_KardexBN = ALM_KardexFN::buscarParentRef( $o_ALM_KardexBN->getParentRef() );
        ?>
        <tbody>
            <tr>
                <td style="text-align: center;"> <?=substr( $o_TmpALM_KardexBN->getIdFecha(), 0, 10 )?> </td>
                <td style="text-align: left; font-size: 9px;"> Saldo Anterior - <?=$o_TmpALM_KardexBN->getTipoDocumentoComprobante()?> </td>
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getSerieDocumentoFiscal()?> </td>
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getNumeroDocumentoFiscal()?> </td>
                
                <td style="text-align: center; font-size: 9px;"> 16 SALDO INICIAL <?php //$o_TmpALM_KardexBN->getTipoOperacionKardex() ?> </td>
                
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getStockIngreso()?> </td>
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getStockIngreso()?$o_TmpALM_KardexBN->getPrecioCosto():""?> </td>
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getStockIngreso()?$o_TmpALM_KardexBN->getCostoTotal():""?> </td>
                
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getStockSalida()?> </td>
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getStockSalida()?$o_TmpALM_KardexBN->getPrecioCosto():""?> </td>
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getStockSalida()?$o_TmpALM_KardexBN->getCostoTotal():""?> </td>
                
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getSaldoCantidad()?> </td>
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getSaldoPrecioCosto()?> </td>
                <td style="text-align: center;"> <?=$o_TmpALM_KardexBN->getSaldoCostoTotal()?> </td>
            </tr>
        </tbody>
        <?php
        if( $o_TmpALM_KardexBN->getStockIngreso() )
            $a_LstItem[$s_IdItem]['IN_COSTO_TOTAL'] = $a_LstItem[$s_IdItem]['IN_COSTO_TOTAL'] + $o_TmpALM_KardexBN->getCostoTotal();
        else
            $a_LstItem[$s_IdItem]['SA_COSTO_TOTAL'] = $a_LstItem[$s_IdItem]['SA_COSTO_TOTAL'] + $o_TmpALM_KardexBN->getCostoTotal();
        $a_LstItem[$s_IdItem]['SF_COSTO_TOTAL'] = $o_TmpALM_KardexBN->getSaldoCostoTotal();
    }
}
function ingresar_suma_item( $o_ALM_KardexBN )
{
    if( $o_ALM_KardexBN )
    {
        global $a_LstItem;
        $s_IdItem = $o_ALM_KardexBN->getIdItem();
        ?>
        <tbody>
            <tr>
                <td colspan="5" align="center" style="font-weight: bold; height: 40px;">TOTALES</td>
                
                <td style="border-top: 1px dashed #000000; border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-top: 1px dashed #000000; border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-top: 1px dashed #000000; border-bottom: 1px dashed #000000; text-align: center;"> 
                    <?=$a_LstItem[$s_IdItem]['IN_COSTO_TOTAL']?> 
                </td>
                
                <td style="border-top: 1px dashed #000000; border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-top: 1px dashed #000000; border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-top: 1px dashed #000000; border-bottom: 1px dashed #000000; text-align: center;">
                    <?=$a_LstItem[$s_IdItem]['SA_COSTO_TOTAL']?>
                </td>
                
                <td style="border-top: 1px dashed #000000; border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-top: 1px dashed #000000; border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-top: 1px dashed #000000; border-bottom: 1px dashed #000000; text-align: center;"> 
                    <?=$a_LstItem[$s_IdItem]['SF_COSTO_TOTAL']?> 
                </td>
            </tr>
        </tbody>
        <?php
    }
}
function ingresar_suma_total_pie( $a_LstItem )
{
    $s_SumaInCostoTotal = 0.00;
    $s_SumaSaCostoTotal = 0.00;
    $s_SumaSfCostoTotal = 0.00;
    foreach ( $a_LstItem as $s_IdItem => $a_Values )
    {
        $s_SumaInCostoTotal = $s_SumaInCostoTotal + $a_Values['IN_COSTO_TOTAL'];
        $s_SumaSaCostoTotal = $s_SumaSaCostoTotal + $a_Values['SA_COSTO_TOTAL'];
        $s_SumaSfCostoTotal = $s_SumaSfCostoTotal + $a_Values['SF_COSTO_TOTAL'];
    }
    ?>
        <tbody>
            <tr>
                <td colspan="5" align="center" style="font-weight: bold; height: 40px;">TOTAL GENERAL DEL INVENTARIO VALORIZADO</td>
                
                <td style="border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-bottom: 1px dashed #000000; text-align: center;"> 
                    <?=$s_SumaInCostoTotal?>
                </td>
                
                <td style="border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-bottom: 1px dashed #000000; text-align: center;">
                    <?=$s_SumaSaCostoTotal?>
                </td>
                
                <td style="border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-bottom: 1px dashed #000000;">&nbsp;</td>
                <td style="border-bottom: 1px dashed #000000; text-align: center;"> 
                    <?=$s_SumaSfCostoTotal?>
                </td>
            </tr>
        </tbody>
    </table>
    <?php
}
?>

<?php 
global $a_LstItem;
$b_Control = true;
$a_LstItem = array();
$o_OldALM_KardexBN = null;
$i = 0;
?>
<?php //$i_NumRows = mysql_num_rows( $o_ResultSelect ) ?>
<?php $i_NumRows = $o_ResultSelect->getRecordCount() ?>
<?php //mysql_data_seek( $o_ResultSelect, 0) ?>
<?php //while ( $o_ALM_Kardex = mysql_fetch_object( $o_ResultSelect ) ){ ?>
<?php while( $o_ResultSelect->next() ){ ?>
    <?php
    $o_ALM_Kardex = $o_ResultSelect->getRow();
    $i++;
    $o_ALM_KardexFN = new ALM_KardexFN() ;
    $o_ALM_KardexBN = $o_ALM_KardexFN->insertObjectBN( $o_ALM_Kardex );
    $s_IdItem = $o_ALM_KardexBN->getIdItem();
    ?>

    <?php if( !isset( $a_LstItem[$s_IdItem] ) ){ ?>

        <?php ingresar_suma_item( $o_OldALM_KardexBN ) ?>

        <?php $a_LstItem[$s_IdItem] = array( "IN_COSTO_TOTAL" => 0.00, "SA_COSTO_TOTAL" => 0.00, "SF_COSTO_TOTAL" => 0.00 ) ?>
        <?php ingresar_cabecera( $o_ALM_KardexBN, $s_FechaIni, $s_FechaFin ) ?>
        <?php //if( $i == 1 ){ ?>
        <?php //ingresar_data_saldo( $o_ALM_KardexBN ) ?>
        <?php //} ?>

    <?php } ?>

    <?php ingresar_data( $o_ALM_KardexBN ) ?>

    <?php $o_OldALM_KardexBN = $o_ALM_KardexBN ?>

    <?php if( $i == $i_NumRows ){ ?>
        <?php ingresar_suma_item( $o_ALM_KardexBN ) ?>
        <?php ingresar_suma_total_pie( $a_LstItem ) ?>
    <?php } ?>
<?php } ?>



