<?php 
function construir_cabecera( &$a_Data )
{
    $o_GSS_CompaniaBN  = $a_Data['o_GSS_CompaniaBN'];
    $o_PRD_OrdenCabBN = $a_Data['o_PRD_OrdenCabBN'];
    ?>
        <table style="width: 100%;" border="0" cellpadding="0" cellspacing="0"  >
            <tr>
                <td style="width: 30%">

                    <div style="">
                        <table style="width: 100%;" border="0" cellpadding="0" cellspacing="0"  >
                            <tr>
                                <td style=""> <img src="web/images/logo/<?=$o_GSS_CompaniaBN->getRuc()?>.jpg" style="width: <?=$o_GSS_CompaniaBN->getLogoFileAncho()?>px; height: <?=$o_GSS_CompaniaBN->getLogoFileAlto()?>px;" > </td>
                            </tr>
                        </table>
                    </div>
                </td>
                <td style="width: 38%">
                    <table style="width: 100%;" border="0" cellpadding="0" cellspacing="0" >
                        <tr>
                            <td style="font-size: 15px;" align="center">
                                <label><b>ANALISIS DE PRECIOS UNITARIOS</b></label>
                            </td>
                        </tr>
                    </table>
                </td>
                <td style="width: 30%;">

                    <div style=" vertical-align: top;  padding: 5px; 
                        border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px;
                        border: 1px solid #B9B5B5;
                        ">
                        <div style="text-align: center;"><label style="font-size: 18px; font-weight: bold;">PRODUCCION</label></div>
                        <div style="text-align: center;"> <label style="font-size: 18px; font-weight: bold;"><?=str_pad( $o_PRD_OrdenCabBN->getIdOrdenCab(), 10, "0", STR_PAD_LEFT )?></label> </div>
                        <div style="text-align: center;"><label style="font-size: 12px; font-weight: bold;">Fecha: <?=date( "Y-m-d" )?></label></div>
                        <!-- <div style="text-align: center;"><label style="font-size: 12px; font-weight: bold;">Elaborado: <?=$o_PRD_OrdenCabBN->getUsuarioCreacion()?></label></div> -->
                    </div>

                </td>
            </tr>
        </table>
    <?php
}

function construir_pie( &$a_Data )
{
    ?>
    <table style="width: 100%; font-size: 10px; text-align:justify; " border="0" cellpadding="0" cellspacing="0"  >
        <tr>
            <td style="width: 82%; vertical-align: top;">

                <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin-top: 10px;
                    border: 1px solid #B9B5B5; padding: 5px; margin-right: 2px;">
                    <label> 
                        <b>NOTA:</b>No se esta considerando mantenimiento de las maquinas utilizadas, debido a que se esta verificando y se esta recolectando informaciòn para el repectivo analisis
                    </label>
                </div>

            </td>
        </tr>
    </table>
    <?php
}

function construir_cuerpo( &$a_Data, $ini, $fin, $s_vHtml )
{
    $o_VTA_OrdenBN      = $a_Data['o_VTA_OrdenBN'];
    
    if( $o_VTA_OrdenBN->getOrdenTipoClasificacionId() == VTA_OrdenBN::TIPO_PRODUCTOS_TERMINADOS )
    {
        $a_OrdenDetalle = $o_VTA_OrdenBN->getArrayDetallesFinal();
    }
    else
    {
        $a_OrdenDetalle = $o_VTA_OrdenBN->getArrayDetalles();
    }    
    ?>

        <?=construir_cabecera( $a_Data )?>

        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin-top: 10px;
                    border: 1px solid #B9B5B5; padding: 5px; ">

            <table style="width: 100%;" border="0" cellpadding="3" cellspacing="0" >
                <tr>
                    <!-- 1% -->
                    <td style="width: 5%; background-color: #EEEEEE; border-bottom: 1px solid ; border-left: 1px solid; border-top: 1px solid; border-color: #B9B5B5;
                            border-top-left-radius: 5px; border-bottom-left-radius: 5px;
                            " align="center">
                        <b>ITEM</b>
                    </td>
                    <td style="width: 5%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>CNT</b></td>
                    <td style="width: 6%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>U.M</b></td>
                    <td style="width: 50%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;"><b>DESCRIPCION</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="right"><b>P/U</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-right: 1px solid; border-color: #B9B5B5; 
                               border-bottom-right-radius: 5px; border-top-right-radius: 5px;" align="right">
                        <b>IMPORTE</b>
                    </td>
                </tr>

<?php $f_SumaTotalPeso = 0; ?>
<?php if ( $a_OrdenDetalle ){ ?>
    <?php for ( $i=$ini; $i < $fin; $i++) { ?>
        <?php if( isset( $a_OrdenDetalle[$i] ) ){ ?>
        <?php
        if( $o_VTA_OrdenBN->getOrdenTipoClasificacionId() == VTA_OrdenBN::TIPO_PRODUCTOS_TERMINADOS )
        {
            $b_Control              = true;
            $s_ItemCod              = $a_OrdenDetalle[$i]->getIdItem();
            $f_Cantidad             = $a_OrdenDetalle[$i]->getCantidad();
            $s_DetalleUnidad        = $a_OrdenDetalle[$i]->getObjectUnidad()->getDescripcionExtranjera();
            $s_DetalleDescripcion   = $a_OrdenDetalle[$i]->getDetalleDescripcion();
            $f_PrecioUnidad         = $a_OrdenDetalle[$i]->getPrecioUnitario();
            $f_SubTotalVenta        = $a_OrdenDetalle[$i]->getSubTotalSinIGV();
        }
        else
        {
            $b_Control              = $a_OrdenDetalle[$i]->getItemTipo()==VTA_OrdenDetalleBN::TIPO_PRODUCTO || $a_OrdenDetalle[$i]->getItemTipo()==VTA_OrdenDetalleBN::TIPO_PRODUCTO_SERVICIO ? true : false;
            
            $s_ItemCod              = $a_OrdenDetalle[$i]->getItemCod();
            $f_Cantidad             = $a_OrdenDetalle[$i]->getOrdenDetalleCantidad();
            $s_DetalleUnidad        = $a_OrdenDetalle[$i]->getObjectUnidad()->getDescripcionExtranjera();
            $s_DetalleDescripcion   = $a_OrdenDetalle[$i]->getOrdenDetalleDescripcion();
            $f_PrecioUnidad         = $a_OrdenDetalle[$i]->getOrdenDetallePrecioUnidad();
            $f_SubTotalVenta        = $a_OrdenDetalle[$i]->getOrdenDetalleSubTotalVenta();
            
            $o_ALM_ItemMastBN       = $a_OrdenDetalle[$i]->getObjectItem();
            $f_SubTotalPeso         = $o_ALM_ItemMastBN->getPesoGramos() * $f_Cantidad;
            $f_SumaTotalPeso        = $f_SumaTotalPeso + $f_SubTotalPeso;
        }
        
        $s_Background = $i%2==0 ? "" : "background-color: #F0F0F0;";
        
        ?>
            <tr style="<?=$s_Background?>">
                <td style="" align="center"><?=$s_ItemCod ?></td>
                <td style="" align="center"><?=$b_Control? $f_Cantidad : "" ?></td>
                <td style="" align="center"><?=$s_DetalleUnidad?></td>
                <td style=""><?= $s_DetalleDescripcion ?></td>
                <td style="" align="right"><?=$b_Control?number_format( $f_PrecioUnidad, 2 ):"" ?></td>
                <td style="" align="right"><?=$b_Control?number_format( $f_SubTotalVenta, 2 ):"" ?></td>
            </tr>
        <?php }else{ ?>
            <tr>
                <!--<td style="" align="center">&nbsp;</td>-->
                <td style="" align="center">&nbsp;</td>
                <td style="" align="center">&nbsp;</td>
                <td style="" align="center">&nbsp;</td>
                <td style="" align="center">&nbsp;</td>
                <td style="" align="center">&nbsp;</td>
                <td style="" align="right">&nbsp;</td>
            </tr>
        <?php } ?>
    <?php } ?>
<?php } ?>

    
                <tr>
                    <td style="" colspan="3">&nbsp;</td>
                    <td style="" align="right" colspan="2"><b>GRAVADA <?=GSS_MonedaMastFN::getSiglaxId( $o_VTA_OrdenBN->getMonedaCod() )?></b>&nbsp;&nbsp;</td>
                    <td style="" align="right"><b><?=number_format( ( $o_VTA_OrdenBN->getOrdenVenta() ), 2 )?></b></td>
                </tr>
                <tr>
                    <td style="" colspan="3">&nbsp;</td>
                    <td style="" align="right" colspan="2"><b>TOTAL DESCUENTO <?=GSS_MonedaMastFN::getSiglaxId( $o_VTA_OrdenBN->getMonedaCod() )?></b>&nbsp;&nbsp;</td>
                    <td style="" align="right"><b><?=number_format( ( $o_VTA_OrdenBN->getOrdenDscto() ), 2 )?></b></td>
                </tr>
                <tr>
                    <td style="" colspan="3">&nbsp;</td>
                    <td style="" align="right" colspan="2"><b>BASE IMPONIBLE <?=GSS_MonedaMastFN::getSiglaxId( $o_VTA_OrdenBN->getMonedaCod() )?></b>&nbsp;&nbsp;</td>
                    <td style="" align="right"><b><?=number_format( ( $o_VTA_OrdenBN->getOrdenBaseImponible() ), 2 )?></b></td>
                </tr>
                
                <tr>
                    <td style="" colspan="3">&nbsp;</td>
                    <td style="" align="right" colspan="2"><b>IGV <?=GSS_ParametroMastFN::getTextoIgvActual()?> <?=GSS_MonedaMastFN::getSiglaxId( $o_VTA_OrdenBN->getMonedaCod() )?></b>&nbsp;&nbsp;</td>
                    <td style="" align="right"><b><?=number_format( ( $o_VTA_OrdenBN->getOrdenImpuestoConDscto() ), 2 )?></b></td>
                </tr>
                <tr>
                    <td style="" colspan="3">&nbsp;</td>
                    <td style="" align="right" colspan="2"><b>TOTAL A PAGAR <?=GSS_MonedaMastFN::getSiglaxId( $o_VTA_OrdenBN->getMonedaCod() )?></b>&nbsp;&nbsp;</td>
                    <td style="" align="right"><b><?=number_format( ( $o_VTA_OrdenBN->getOrdenTotalaPagar() ), 2 )?></b></td>
                </tr>
            </table>
        
        </div>
        
        <?=construir_pie( $a_Data )?>

    <?php
}
?>

<!-- https://ourcodeworld.com/articles/read/687/how-to-configure-a-header-and-footer-in-dompdf -->
<html>
    <head>
        <style type="text/css">
            @page 
            {
                size: A4 portrait;
                margin: 0cm 0cm;
            }

            header 
            {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 10px;
            }

            footer 
            {
                bottom: 0cm; 
                left: 0cm; 
                right: 0cm;
            }

            body 
            {
                margin : 0.5cm;
                /*margin-top: 1cm;*/
                font-family: Arial, Helvetica, sans-serif;
                font-size: 10px;
                /*margin-top: 0.5cm;
                margin-left: 0.5cm;
                margin-right: 0.5cm;
                margin-bottom: 0.5cm;*/
            }

            table
            {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 10px;
            }

            .new-page{ page-break-before: always; }
            
            #watermark 
            {
                position: fixed;
                opacity: 0.2;
                /** 
                    Establece una posición en la página para tu imagen
                    Esto debería centrarlo verticalmente
                **/
                bottom:   13cm;
                left:     6.5cm;

                /** Cambiar las dimensiones de la imagen **/
                width:    8cm;
                height:   8cm;

                /** Tu marca de agua debe estar detrás de cada contenido **/
                z-index:  -1000;
            }

        </style>
    </head>
    <!--<body style="page-break-before: always;">-->
    <body>
    
        <div id="watermark">
            <img src="web/images/logo/<?=$o_GSS_CompaniaBN->getRuc()?>_black.jpg" height="100%" width="100%" >
        </div>

        <?=construir_cabecera( $a_Data )?>
        
        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin-top: 10px;
                    border: 1px solid #B9B5B5; padding: 5px; ">
            <table style="width: 100%;" border="0" cellpadding="3" cellspacing="0" >
                <tr>
                    <td style="width: 5%; background-color: #EEEEEE; border-bottom: 1px solid ; border-left: 1px solid; border-top: 1px solid; border-color: #B9B5B5;
                            border-top-left-radius: 5px; border-bottom-left-radius: 5px;
                            " align="center">
                        <b>ITEM</b>
                    </td>
                    <td style="width: 20%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;"><b>DESCRIPCION</b></td>
                    <td style="width: 25%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>FOTO REFERENCIAL</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>UNIDAD</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-right: 1px solid; border-color: #B9B5B5; 
                               border-bottom-right-radius: 5px; border-top-right-radius: 5px;" align="center">
                        <b>CANTIDAD</b>
                    </td>
                </tr>
                <?php
                $o_PRD_OrdenDetFN = new PRD_OrdenDetFN();
                $o_PRD_OrdenDetFN->setItemTipo( "PF" );
                $o_PRD_OrdenDetFN->setIdOrdenCab( $s_IdOrdenCab );
                $a_PRD_OrdenDet = $o_PRD_OrdenDetFN->select();
                $f_CostoUnitarioPF = 0;
                $f_CostoTotalPF    = 0;
                ?>
                <?php foreach ( $a_PRD_OrdenDet as $i_Key => $o_PRD_OrdenDetBN ){ ?>
                    <?php
                    $s_Background = $i_Key%2==0 ? "" : "background-color: #F0F0F0;";
                    $f_CostoUnitarioPF = $o_PRD_OrdenDetBN->getPrecioCostoUnit();
                    $f_CostoTotalPF    = $o_PRD_OrdenDetBN->getPrecioCostoTotal();
                    ?>
                    <tr>
                        <td style="" align="center"><?=$o_PRD_OrdenDetBN->getIdItem()?></td>
                        <td style="" align=""><?=$o_PRD_OrdenDetBN->getDescripcionItem()?></td>
                        <td style="" align="center"><img src="web/images/productos/<?=$o_PRD_OrdenDetBN->getObjectItem()->getNombreArchivoFinal()?>" height="100" width="100" ></td>
                        <td style="" align="center"><?=$o_PRD_OrdenDetBN->getObjectUnidad()->getDescripcionCorta()?></td>
                        <td style="" align="center"><?=$o_PRD_OrdenDetBN->getCantidadPedida() ?></td>
                    </tr>
                <?php } ?>
            </table>
        </div>
        
        <div style="margin-top: 10px;">
            <table style="width: 100%;" border="0" cellpadding="1" cellspacing="0">
                <tr>
                    <td style="width: 20%; font-weight: bold;" align="left">
                        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; border: 1px solid #B9B5B5;
                            border: 1px solid #B9B5B5; padding: 5px; ">
                            &nbsp;&nbsp;&nbsp;&nbsp;I. MANO DE OBRA
                        </div>
                    </td> 
                    <td>&nbsp;</td>
                </tr>
            </table>
        </div>
        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin-top: 1px;
                    border: 1px solid #B9B5B5; padding: 5px; ">

            <table style="width: 100%;" border="0" cellpadding="3" cellspacing="0" >
                <tr>
                    <td style="width: 5%; background-color: #EEEEEE; border-bottom: 1px solid ; border-left: 1px solid; border-top: 1px solid; border-color: #B9B5B5;
                            border-top-left-radius: 5px; border-bottom-left-radius: 5px;
                            " align="center">
                        <b>ITEM</b>
                    </td>
                    <td style="width: 35%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;"><b>DESCRIPCION</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>UNIDAD</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>CANTIDAD</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="right"><b>VALOR UNI</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-right: 1px solid; border-color: #B9B5B5; 
                               border-bottom-right-radius: 5px; border-top-right-radius: 5px;" align="right">
                        <b>VALOR TOT</b>
                    </td>
                </tr>
                <?php
                $o_PRD_OrdenDetFN = new PRD_OrdenDetFN();
                $o_PRD_OrdenDetFN->addCondition( PRD_OrdenDetFN::ItemTipo, "IN", "('PM')", false );
                $o_PRD_OrdenDetFN->setIdOrdenCab( $s_IdOrdenCab );
                $a_PRD_OrdenDet = $o_PRD_OrdenDetFN->select();
                $f_SumaTotalPR = 0;
                ?>
                <?php foreach ( $a_PRD_OrdenDet as $i_Key => $o_PRD_OrdenDetBN ){ ?>
                    <?php
                    $s_Background = $i_Key%2==0 ? "" : "background-color: #F0F0F0;";
                    $f_SumaTotalPR = $f_SumaTotalPR + $o_PRD_OrdenDetBN->getPrecioCostoTotal();
                    ?>
                    <tr>
                        <td style="" align="center"><?=$o_PRD_OrdenDetBN->getIdItem()?></td>
                        <td style="" align=""><?=$o_PRD_OrdenDetBN->getDescripcionItem()?></td>
                        <td style="" align="center">UNIDAD</td>
                        <td style="" align="center"><?=$o_PRD_OrdenDetBN->getCantidadPedida() ?></td>
                        <td style="" align="right"><?=number_format( $o_PRD_OrdenDetBN->getPrecioCostoUnit(), 2 ) ?></td>
                        <td style="" align="right"><?=number_format( $o_PRD_OrdenDetBN->getPrecioCostoTotal(), 2 ) ?></td>
                    </tr>
                <?php } ?>
                <tr>
                    <td style="" colspan="3">&nbsp;</td>
                    <td style="" align="right" colspan="2"><b>SUB TOTAL</b>&nbsp;&nbsp;</td>
                    <td style="border-top: 1px solid #B9B5B5;" align="right"><b><?=number_format( ( $f_SumaTotalPR ), 2 )?></b></td>
                </tr>
            </table>
        </div>
        
        <div style="margin-top: 10px;">
            <table style="width: 100%;" border="0" cellpadding="1" cellspacing="0">
                <tr>
                    <td style="width: 20%; font-weight: bold;" align="left">
                        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; border: 1px solid #B9B5B5;
                            border: 1px solid #B9B5B5; padding: 5px; ">
                            &nbsp;&nbsp;&nbsp;&nbsp;II. MATERIALES
                        </div>
                    </td> 
                    <td>&nbsp;</td>
                </tr>
            </table>
        </div>
        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin-top: 1px;
                    border: 1px solid #B9B5B5; padding: 5px; ">

            <table style="width: 100%;" border="0" cellpadding="3" cellspacing="0" >
                <tr>
                    <td style="width: 5%; background-color: #EEEEEE; border-bottom: 1px solid ; border-left: 1px solid; border-top: 1px solid; border-color: #B9B5B5;
                            border-top-left-radius: 5px; border-bottom-left-radius: 5px;
                            " align="center">
                        <b>ITEM</b>
                    </td>
                    <td style="width: 35%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;"><b>DESCRIPCION</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>UNIDAD</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>CANTIDAD</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="right"><b>VALOR UNI</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-right: 1px solid; border-color: #B9B5B5; 
                               border-bottom-right-radius: 5px; border-top-right-radius: 5px;" align="right">
                        <b>VALOR TOT</b>
                    </td>
                </tr>
                <?php
                $o_PRD_OrdenDetFN = new PRD_OrdenDetFN();
                $o_PRD_OrdenDetFN->addCondition( PRD_OrdenDetFN::ItemTipo, "IN", "('PR','PE')", false );
                $o_PRD_OrdenDetFN->setIdOrdenCab( $s_IdOrdenCab );
                $a_PRD_OrdenDet = $o_PRD_OrdenDetFN->select();
                $f_SumaTotalPR = 0;
                ?>
                <?php foreach ( $a_PRD_OrdenDet as $i_Key => $o_PRD_OrdenDetBN ){ ?>
                    <?php
                    $s_Background = $i_Key%2==0 ? "" : "background-color: #F0F0F0;";
                    $f_SumaTotalPR = $f_SumaTotalPR + $o_PRD_OrdenDetBN->getPrecioCostoTotal();
                    ?>
                    <tr>
                        <td style="" align="center"><?=$o_PRD_OrdenDetBN->getIdItem()?></td>
                        <td style="" align=""><?=$o_PRD_OrdenDetBN->getDescripcionItem()?></td>
                        <td style="" align="center"><?=$o_PRD_OrdenDetBN->getObjectUnidad()->getDescripcionCorta()?></td>
                        <td style="" align="center"><?=$o_PRD_OrdenDetBN->getCantidadPedida() ?></td>
                        <td style="" align="right"><?=number_format( $o_PRD_OrdenDetBN->getPrecioCostoUnit(), 2 ) ?></td>
                        <td style="" align="right"><?=number_format( $o_PRD_OrdenDetBN->getPrecioCostoTotal(), 2 ) ?></td>
                    </tr>
                <?php } ?>
                <tr>
                    <td style="" colspan="3">&nbsp;</td>
                    <td style="" align="right" colspan="2"><b>SUB TOTAL</b>&nbsp;&nbsp;</td>
                    <td style="border-top: 1px solid #B9B5B5;" align="right"><b><?=number_format( ( $f_SumaTotalPR ), 2 )?></b></td>
                </tr>
            </table>
        </div>
        
        <div style="margin-top: 10px;">
            <table style="width: 100%;" border="0" cellpadding="1" cellspacing="0">
                <tr>
                    <td style="width: 20%; font-weight: bold;" align="left">
                        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; border: 1px solid #B9B5B5;
                            border: 1px solid #B9B5B5; padding: 5px; ">
                            &nbsp;&nbsp;&nbsp;&nbsp;III. SERVICIO EXTERNO
                        </div>
                    </td> 
                    <td>&nbsp;</td>
                </tr>
            </table>
        </div>
        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin-top: 1px;
                    border: 1px solid #B9B5B5; padding: 5px; ">

            <table style="width: 100%;" border="0" cellpadding="3" cellspacing="0" >
                <tr>
                    <td style="width: 5%; background-color: #EEEEEE; border-bottom: 1px solid ; border-left: 1px solid; border-top: 1px solid; border-color: #B9B5B5;
                            border-top-left-radius: 5px; border-bottom-left-radius: 5px;
                            " align="center">
                        <b>ITEM</b>
                    </td>
                    <td style="width: 35%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;"><b>DESCRIPCION</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>UNIDAD</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>CANTIDAD</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="right"><b>VALOR UNI</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-right: 1px solid; border-color: #B9B5B5; 
                               border-bottom-right-radius: 5px; border-top-right-radius: 5px;" align="right">
                        <b>VALOR TOT</b>
                    </td>
                </tr>
                <?php
                $o_PRD_OrdenDetFN = new PRD_OrdenDetFN();
                $o_PRD_OrdenDetFN->addCondition( PRD_OrdenDetFN::ItemTipo, "IN", "('PS')", false );
                $o_PRD_OrdenDetFN->setIdOrdenCab( $s_IdOrdenCab );
                $a_PRD_OrdenDet = $o_PRD_OrdenDetFN->select();
                $f_SumaTotalPR = 0;
                ?>
                <?php foreach ( $a_PRD_OrdenDet as $i_Key => $o_PRD_OrdenDetBN ){ ?>
                    <?php
                    $s_Background = $i_Key%2==0 ? "" : "background-color: #F0F0F0;";
                    $f_SumaTotalPR = $f_SumaTotalPR + $o_PRD_OrdenDetBN->getPrecioCostoTotal();
                    ?>
                    <tr>
                        <td style="" align="center"><?=$i_Key+1?></td>
                        <td style="" align=""><?=$o_PRD_OrdenDetBN->getDescripcionItem()?></td>
                        <td style="" align="center">UNIDAD</td>
                        <td style="" align="center"><?=$o_PRD_OrdenDetBN->getCantidadPedida() ?></td>
                        <td style="" align="right"><?=number_format( $o_PRD_OrdenDetBN->getPrecioCostoUnit(), 2 ) ?></td>
                        <td style="" align="right"><?=number_format( $o_PRD_OrdenDetBN->getPrecioCostoTotal(), 2 ) ?></td>
                    </tr>
                <?php } ?>
                <tr>
                    <td style="" colspan="3">&nbsp;</td>
                    <td style="" align="right" colspan="2"><b>SUB TOTAL</b>&nbsp;&nbsp;</td>
                    <td style="border-top: 1px solid #B9B5B5;" align="right"><b><?=number_format( ( $f_SumaTotalPR ), 2 )?></b></td>
                </tr>
            </table>
        </div>
        
        <BR>
        
        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin-top: 1px;
                    border: 1px solid #B9B5B5; padding: 5px; ">

            <table style="width: 100%;" border="0" cellpadding="3" cellspacing="0" >
                <tr>
                    <td style="width: 5%;" align="center">
                        &nbsp;
                    </td>
                    <td style="width: 35%; ">&nbsp;</td>
                    <td style="width: 10%; " align="center"><b>&nbsp;</b></td>
                    <td style="width: 10%; " align="center"><b>&nbsp;</b></td>
                    <td style="width: 10%; " align="right"><b>TOTAL</b></td>
                    <td style="width: 10%; " align="right">
                        <b> <?=number_format( $f_CostoTotalPF, 2 )?> </b>
                    </td>
                </tr>
            </table>
        </div>
        <br>
        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin-top: 1px;
                    border: 1px solid #B9B5B5; padding: 5px; ">

            <table style="width: 100%;" border="0" cellpadding="3" cellspacing="0" >
                <tr>
                    <td style="" align="right" colspan="5"><b>COSTO UNITARIO SIN IGV</b></td>
                    <td style="width: 10%; " align="right">
                        <b> <?=number_format( $f_CostoUnitarioPF, 2 )?> </b>
                    </td>
                </tr>
            </table>
        </div>
        <br>
        <div style="border-top-right-radius: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin-top: 1px;
                    border: 1px solid #B9B5B5; padding: 5px; ">

            <table style="width: 100%;" border="0" cellpadding="3" cellspacing="0" >
                <tr>
                    <td style="" align="right" colspan="5"><b>COSTO UNITARIO INCLUIDO IGV</b></td>
                    <td style="width: 10%; " align="right">
                        <b> <?=number_format( $f_CostoUnitarioPF * 1.18, 2 )?> </b>
                    </td>
                </tr>
            </table>
        </div>
        
        <?=construir_pie( $a_Data )?>

    </body>
</html>