
<link rel="stylesheet" type="text/css" media="screen" href="https://cdn.datatables.net/responsive/2.2.5/css/responsive.bootstrap4.min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="https://cdn.datatables.net/fixedheader/3.1.7/css/fixedHeader.dataTables.min.css" />

<!--<link rel="stylesheet" type="text/css" media="screen" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css" />-->

<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/responsive/2.2.5/js/dataTables.responsive.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/responsive/2.2.5/js/responsive.bootstrap4.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/fixedheader/3.1.7/js/dataTables.fixedHeader.min.js"></script>

<style type="text/css">
/*
#example_wrapper .row
{
    margin-right: 0;
    margin-left: 0;
}
table.dataTable tbody tr:hover 
{
   background-color: #DAE6FE !important;;
}
*/
.table td, .table th 
{
    /*padding: 8px;*/
    font-size: 13px;
}
th { white-space: nowrap; }

</style>

        
<table id="example" class="table table-striped table-bordered" style="width:100%">
    <thead>
        <tr class="table-primary">
            <th scope="col" style="text-align: center;" rowspan="2"> ITEM </th>
            <th scope="col" rowspan="2"> DESCRIPCION </th>
            <th scope="col" style="text-align: center;" rowspan="2"> MARCA </th>
            <th scope="col" style="text-align: center;" rowspan="2"> LINEA </th>
            <th scope="col" style="text-align: center;" rowspan="2"> FAMILIA </th>
            <th scope="col" style="text-align: center;" rowspan="2"> COSTO </th>
            <th scope="col" style="text-align: center;" rowspan=""> &nbsp; </th>
            <?php foreach ( $a_ALM_AlmacenMast as $o_ALM_AlmacenMastBN ) { ?>
                <?php 
                //$s_Codigo = $o_ALM_AlmacenMastBN->getCodigo()=="" ? $o_ALM_AlmacenMastBN->getDescripcionLocal() : $o_ALM_AlmacenMastBN->getCodigo();
                $s_Codigo = $o_ALM_AlmacenMastBN->getDescripcionLocal();
                ?>
            <th style="text-align: center;"> 
                <?=$s_Codigo?>
            </th>
            <?php } ?>
            <th scope="col" style="text-align: center;" rowspan=""> &nbsp; </th>
            <th scope="col" style="text-align: center;" nowrap="" colspan="2"> 1 a 15 DIAS </th>
            <th scope="col" style="text-align: center;" nowrap="" colspan="2"> 16 a 30 DIAS </th>
            <th scope="col" style="text-align: center;" nowrap="" colspan="2"> 31 a 45 DIAS </th>
            <th scope="col" style="text-align: center;" nowrap="" colspan="2"> 46 a 60 DIAS </th>
            <th scope="col" style="text-align: center;" nowrap="" colspan="2"> 61 a 75 DIAS </th>
            <th scope="col" style="text-align: center;" nowrap="" colspan="2"> 76 a 90 DIAS </th>
            <th scope="col" style="text-align: center;" nowrap="" colspan="2"> 151 a 165 DIAS </th>
            <th scope="col" style="text-align: center;" nowrap="" colspan="2"> 181 a 195 DIAS </th>
            <th scope="col" style="text-align: center;" nowrap="" colspan="2"> 196 a 999999 DIAS </th>
            <th scope="col" style="text-align: center;" rowspan="2"> TOTAL <?=GSS_MonedaMastFN::getSiglaxId( $s_IdMoneda )?> </th>
            <th scope="col" style="text-align: center;" rowspan="2"> TOTAL UNID </th>
        </tr>
        <tr class="table-primary">
            <th scope="col" style="text-align: center;" rowspan=""> &nbsp; </th>
            <?php foreach ( $a_ALM_AlmacenMast as $o_ALM_AlmacenMastBN ) { ?>
            <th scope="col" style="text-align: center;"> UNID </th>
            <?php } ?>
            <th scope="col" style="text-align: center;" rowspan=""> &nbsp; </th>

            <th scope="col" style="text-align: center;"> <?=GSS_MonedaMastFN::getSiglaxId( $s_IdMoneda )?> </th>
            <th scope="col" style="text-align: center;"> UNID </th>

            <th scope="col" style="text-align: center;"> <?=GSS_MonedaMastFN::getSiglaxId( $s_IdMoneda )?> </th>
            <th scope="col" style="text-align: center;"> UNID </th>

            <th scope="col" style="text-align: center;"> <?=GSS_MonedaMastFN::getSiglaxId( $s_IdMoneda )?> </th>
            <th scope="col" style="text-align: center;"> UNID </th>

            <th scope="col" style="text-align: center;"> <?=GSS_MonedaMastFN::getSiglaxId( $s_IdMoneda )?> </th>
            <th scope="col" style="text-align: center;"> UNID </th>

            <th scope="col" style="text-align: center;"> <?=GSS_MonedaMastFN::getSiglaxId( $s_IdMoneda )?> </th>
            <th scope="col" style="text-align: center;"> UNID </th>

            <th scope="col" style="text-align: center;"> <?=GSS_MonedaMastFN::getSiglaxId( $s_IdMoneda )?> </th>
            <th scope="col" style="text-align: center;"> UNID </th>

            <th scope="col" style="text-align: center;"> <?=GSS_MonedaMastFN::getSiglaxId( $s_IdMoneda )?> </th>
            <th scope="col" style="text-align: center;"> UNID </th>

            <th scope="col" style="text-align: center;"> <?=GSS_MonedaMastFN::getSiglaxId( $s_IdMoneda )?> </th>
            <th scope="col" style="text-align: center;"> UNID </th>

            <th scope="col" style="text-align: center;"> <?=GSS_MonedaMastFN::getSiglaxId( $s_IdMoneda )?> </th>
            <th scope="col" style="text-align: center;"> UNID </th>
        </tr>
    </thead>

    <tbody>
        <?php 
        $a_TotalPorAlmacen = array();
        
        $f_SumaTotal_15 = 0;
        $i_SumaCanti_15 = 0;
        
        $f_SumaTotal_30 = 0;
        $i_SumaCanti_30 = 0;
        
        $f_SumaTotal_45 = 0;
        $i_SumaCanti_45 = 0;
        
        $f_SumaTotal_60 = 0;
        $i_SumaCanti_60 = 0;
        
        $f_SumaTotal_75 = 0;
        $i_SumaCanti_75 = 0;
        
        $f_SumaTotal_90 = 0;
        $i_SumaCanti_90 = 0;
        
        $f_SumaTotal_165 = 0;
        $i_SumaCanti_165 = 0;
        
        $f_SumaTotal_195 = 0;
        $i_SumaCanti_195 = 0;
        
        $f_SumaTotal_999999 = 0;
        $i_SumaCanti_999999 = 0;
        ?>
        <?php foreach ( $a_DataItem as $a_Data ) { ?>
            <?php
            $i_SumaTotalUnid  = 0;
            $f_SumaTotalCosto = 0;
            ?>
            <tr>
                <td align="center"> <?=$a_Data['IdItem']?> </td>
                <td align="left" nowrap=""> <?=$a_Data['DescripcionCompleta']?> </td>
                <td align="center" nowrap=""> <?=$a_Data['MarcaDesc']?> </td>
                <td align="center" nowrap=""> <?=$a_Data['LineaDesc']?> </td>
                <td align="center" nowrap=""> <?=$a_Data['FamiliaDesc']?> </td>
                <td align="center" nowrap=""> <?=number_format( $a_Data['PrecioCosto'], 2 )?> </td>
                
                <td align="center"> &nbsp; </td>
                <?php foreach ( $a_ALM_AlmacenMast as $o_ALM_AlmacenMastBN ) { ?>
                    <?php
                    if( !isset( $a_TotalPorAlmacen[$o_ALM_AlmacenMastBN->getIdAlmacen()] ) ){ $a_TotalPorAlmacen[$o_ALM_AlmacenMastBN->getIdAlmacen()] = 0; }
                    
                    $f_TotalStock       = ALM_ItemAlmacenStockFN::getStockFisicoTotal( $a_Data['IdItem'], $o_ALM_AlmacenMastBN->getIdAlmacen() );
                    $i_SumaTotalUnid    = $i_SumaTotalUnid + $f_TotalStock;
                    $a_TotalPorAlmacen[$o_ALM_AlmacenMastBN->getIdAlmacen()] = $a_TotalPorAlmacen[$o_ALM_AlmacenMastBN->getIdAlmacen()] + $f_TotalStock;
                    ?>
                <td align="center"> <?=$f_TotalStock?> </td>
                <?php } ?>
                <td align="center"> &nbsp; </td>

                <?php 
                $i_CantSaldoTotal = $buscarDocumentosRelacionados( $a_Data['IdItem'], 0, 15 );
                $f_CostoTotal     = $i_CantSaldoTotal * $a_Data['PrecioCosto'];
                $f_SumaTotalCosto = $f_SumaTotalCosto + $f_CostoTotal;
                
                $f_SumaTotal_15   = $f_SumaTotal_15 + $f_CostoTotal;
                $i_SumaCanti_15   = $i_SumaCanti_15 + $i_CantSaldoTotal;
                ?>
                <td align="center"> <?=number_format( $f_CostoTotal, 2 ) ?> </td>
                <td align="center"> <?=$i_CantSaldoTotal?> </td>

                <?php 
                $i_CantSaldoTotal = $buscarDocumentosRelacionados( $a_Data['IdItem'], 16, 30 );
                $f_CostoTotal     = $i_CantSaldoTotal * $a_Data['PrecioCosto'];
                $f_SumaTotalCosto = $f_SumaTotalCosto + $f_CostoTotal;
                
                $f_SumaTotal_30   = $f_SumaTotal_30 + $f_CostoTotal;
                $i_SumaCanti_30   = $i_SumaCanti_30 + $i_CantSaldoTotal;
                ?>
                <td align="center"> <?=number_format( $f_CostoTotal, 2 ) ?> </td>
                <td align="center"> <?=$i_CantSaldoTotal?> </td>

                <?php 
                $i_CantSaldoTotal = $buscarDocumentosRelacionados( $a_Data['IdItem'], 31, 45 );
                $f_CostoTotal     = $i_CantSaldoTotal * $a_Data['PrecioCosto'];
                $f_SumaTotalCosto = $f_SumaTotalCosto + $f_CostoTotal;
                
                $f_SumaTotal_45   = $f_SumaTotal_45 + $f_CostoTotal;
                $i_SumaCanti_45   = $i_SumaCanti_45 + $i_CantSaldoTotal;
                ?>
                <td align="center"> <?=number_format( $f_CostoTotal, 2 ) ?> </td>
                <td align="center"> <?=$i_CantSaldoTotal?> </td>

                <?php 
                $i_CantSaldoTotal = $buscarDocumentosRelacionados( $a_Data['IdItem'], 46, 60 );
                $f_CostoTotal     = $i_CantSaldoTotal * $a_Data['PrecioCosto'];
                $f_SumaTotalCosto = $f_SumaTotalCosto + $f_CostoTotal;
                
                $f_SumaTotal_60   = $f_SumaTotal_60 + $f_CostoTotal;
                $i_SumaCanti_60   = $i_SumaCanti_60 + $i_CantSaldoTotal;
                ?>
                <td align="center"> <?=number_format( $f_CostoTotal, 2 ) ?> </td>
                <td align="center"> <?=$i_CantSaldoTotal?> </td>

                <?php 
                $i_CantSaldoTotal = $buscarDocumentosRelacionados( $a_Data['IdItem'], 61, 75 );
                $f_CostoTotal     = $i_CantSaldoTotal * $a_Data['PrecioCosto'];
                $f_SumaTotalCosto = $f_SumaTotalCosto + $f_CostoTotal;
                
                $f_SumaTotal_75   = $f_SumaTotal_75 + $f_CostoTotal;
                $i_SumaCanti_75   = $i_SumaCanti_75 + $i_CantSaldoTotal;
                ?>
                <td align="center"> <?=number_format( $f_CostoTotal, 2 ) ?> </td>
                <td align="center"> <?=$i_CantSaldoTotal?> </td>

                <?php 
                $i_CantSaldoTotal = $buscarDocumentosRelacionados( $a_Data['IdItem'], 76, 90 );
                $f_CostoTotal     = $i_CantSaldoTotal * $a_Data['PrecioCosto'];
                $f_SumaTotalCosto = $f_SumaTotalCosto + $f_CostoTotal;
                
                $f_SumaTotal_90   = $f_SumaTotal_90 + $f_CostoTotal;
                $i_SumaCanti_90   = $i_SumaCanti_90 + $i_CantSaldoTotal;
                ?>
                <td align="center"> <?=number_format( $f_CostoTotal, 2 ) ?> </td>
                <td align="center"> <?=$i_CantSaldoTotal?> </td>

                <?php 
                $i_CantSaldoTotal = $buscarDocumentosRelacionados( $a_Data['IdItem'], 91, 165 );
                $f_CostoTotal     = $i_CantSaldoTotal * $a_Data['PrecioCosto'];
                $f_SumaTotalCosto = $f_SumaTotalCosto + $f_CostoTotal;
                
                $f_SumaTotal_165   = $f_SumaTotal_165 + $f_CostoTotal;
                $i_SumaCanti_165   = $i_SumaCanti_165 + $i_CantSaldoTotal;
                ?>
                <td align="center"> <?=number_format( $f_CostoTotal, 2 ) ?> </td>
                <td align="center"> <?=$i_CantSaldoTotal?> </td>

                <?php 
                $i_CantSaldoTotal = $buscarDocumentosRelacionados( $a_Data['IdItem'], 166, 195 );
                $f_CostoTotal     = $i_CantSaldoTotal * $a_Data['PrecioCosto'];
                $f_SumaTotalCosto = $f_SumaTotalCosto + $f_CostoTotal;
                
                $f_SumaTotal_195   = $f_SumaTotal_195 + $f_CostoTotal;
                $i_SumaCanti_195   = $i_SumaCanti_195 + $i_CantSaldoTotal;
                ?>
                <td align="center"> <?=number_format( $f_CostoTotal, 2 ) ?> </td>
                <td align="center"> <?=$i_CantSaldoTotal?> </td>

                <?php 
                $i_CantSaldoTotal = $buscarDocumentosRelacionados( $a_Data['IdItem'], 196, 999999 );
                $f_CostoTotal     = $i_CantSaldoTotal * $a_Data['PrecioCosto'];
                $f_SumaTotalCosto = $f_SumaTotalCosto + $f_CostoTotal;
                
                $f_SumaTotal_999999   = $f_SumaTotal_999999 + $f_CostoTotal;
                $i_SumaCanti_999999   = $i_SumaCanti_999999 + $i_CantSaldoTotal;
                ?>
                <td align="center"> <?=number_format( $f_CostoTotal, 2 ) ?> </td>
                <td align="center"> <?=$i_CantSaldoTotal?> </td>

                <td align="center"> <?=number_format( $f_SumaTotalCosto, 2 ) ?> </td>
                <td align="center"> <?=$i_SumaTotalUnid?> </td>                        
            </tr>
        <?php } ?>

    </tbody>
    
    <tbody>
        <tr class="table-primary">
            
            <td align="center" colspan="6"> <B>TOTAL</B> </td>

            <td align="center"> &nbsp; </td>
            <?php foreach ( $a_TotalPorAlmacen as $i_Total ) { ?>
            <td align="center"> <?=$i_Total?> </td>
            <?php } ?>
            <td align="center"> &nbsp; </td>

            <td align="center"> <?=number_format( $f_SumaTotal_15, 2 )?> </td>
            <td align="center"> <?=$i_SumaCanti_15?> </td>

            <td align="center"> <?=number_format( $f_SumaTotal_30, 2 )?> </td>
            <td align="center"> <?=$i_SumaCanti_30?> </td>

            <td align="center"> <?=number_format( $f_SumaTotal_45, 2 )?> </td>
            <td align="center"> <?=$i_SumaCanti_45?> </td>

            <td align="center"> <?=number_format( $f_SumaTotal_60, 2 )?> </td>
            <td align="center"> <?=$i_SumaCanti_60?> </td>

            <td align="center"> <?=number_format( $f_SumaTotal_75, 2 )?> </td>
            <td align="center"> <?=$i_SumaCanti_75?> </td>

            <td align="center"> <?=number_format( $f_SumaTotal_90, 2 )?> </td>
            <td align="center"> <?=$i_SumaCanti_90?> </td>

            <td align="center"> <?=number_format( $f_SumaTotal_165, 2 )?> </td>
            <td align="center"> <?=$i_SumaCanti_165?> </td>

            <td align="center"> <?=number_format( $f_SumaTotal_195, 2 )?> </td>
            <td align="center"> <?=$i_SumaCanti_195?> </td>

            <td align="center"> <?=number_format( $f_SumaTotal_999999, 2 )?> </td>
            <td align="center"> <?=$i_SumaCanti_999999?> </td>

            <td align="center"> 0 </td>
            <td align="center"> 0 </td>
        </tr>
    </tbody>

</table>
        
<script type="text/javascript">
configurarDataTable = function()
{
    $( '#example' ).DataTable
    (
        {
            language:       { "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Spanish.json" },
            responsive:     false,
            searching:      false,
            info:           false,
            lengthChange:   false,
            paging:         false,
            dom:            'lrtip',
            fixedHeader: 
            {
                header: true,
                footer: true
            }
        }
    );
}

setTimeout
(
    function () 
    {
        configurarDataTable();
    }, 
    1000
);
</script>