<html>
    <head>
        <style type="text/css">
            @page 
            {
                size: A4 landscape;
                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:   6cm;
                left:     11cm;

                /** 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>
		<?php $InfoRuta = $o_RutaDetalle[0] ?>
		<?php 
		$FacturaFN = new VTA_DocumentoFN();
		$FacturaFN->setNumeroDocumento($InfoRuta->getDocumentRefId());
		$Factura = $FacturaFN->select_one();
		//pr($Factura);
		$Almacen1FN = new ALM_AlmacenMastFN();
		$Origen = $Almacen1FN->selectByPK($Factura->getIdAlmacen());
		
		$Almacen2FN = new ALM_AlmacenMastFN();
		$Destino = $Almacen2FN->selectByPK($Factura->getAlmacenDespacho());
		
		$TurnoFN = new TR_TurnoFN();
		$Turno = $TurnoFN->selectByPK($o_Ruta->getIdTurno());
		$HoraTurno = $Turno->getTurnoDescHora() . ":" . str_pad($Turno->getTurnoDescMin(), 2 , "0" , STR_PAD_LEFT);
		
		$ChoferFN = new TR_ChoferFN();
		$Chofer = $ChoferFN->selectByPK($o_Ruta->getIdChofer());
		
		$VehiculoFN = new TR_VehiculoFN();
		$Vehiculo = $VehiculoFN->selectByPK($o_Ruta->getIdVehiculo());
		
		$TotalSuma = 0;
        $TotalSuma2 = 0;
		
		?>
        <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: 18px;" align="center">
                                <label><b>Control de Manifiesto Interno</b></label>
                            </td>
                        </tr>
                    </table>
                </td>
                <td style="width: 30%;">
            

                    <table style="width: 100%;" border="0" cellpadding="0" cellspacing="0" >
                        <tr>
                            <td style="font-size: 10px;" align="center">
                                <label><b>Fecha de Emision: <?=date( "Y-m-d H:i:s" )?></b></label>
                            </td>
                        </tr>
                    </table>

                </td>
            </tr>
        </table>
        <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="1" cellspacing="0">
                <tr>
                    <td style="width: 15%; font-weight: bold;" align="left">Sucursal Origen</td>
                    <td style="width: 20%;">&nbsp;<?=$Origen->getDescripcionLocal();?></td>
                    <td style="font-weight: bold;" align="left">Direccion Origen</td>
                    <td colspan="3">&nbsp;<?=$s_DireccionOrigen;?></td>
                </tr>
                <tr>
                    <td style="width: 8%; font-weight: bold;" align="left">Sucursal Destino</td>
                    <td style="width: 25%;">&nbsp;<?=$Destino->getDescripcionLocal();?></td>
                    <td style="font-weight: bold;" align="left">Direccion Destino</td>
                    <td colspan="3">&nbsp;<?=$s_DireccionDestino?></td>
                </tr>
                <tr>
                    <td style="font-weight: bold;" align="left">Fecha</td>
                    <td>&nbsp;<?=substr( $o_Ruta->getRutaFechaProgramada(), 0, 10 ); ?></td>
                    <td style="font-weight: bold;" align="left">Turno</td>
                    <td>&nbsp;<?=$Turno->getTurnoDescripcion()?></td>
                    <td style="font-weight: bold;" align="left">Hora</td>
                    <td>&nbsp;<?=$HoraTurno;?></td>
                </tr>
                <tr>	
                    <td style="font-weight: bold;" align="left">Chofer</td>
                    <td>&nbsp;<?=$Chofer->getChoferNombre(); ?></td>
                    <td style="font-weight: bold;" align="left">Vehiculo</td>
                    <td>&nbsp;<?=$Vehiculo->getVehiculoMarca() ?> - <?=$Vehiculo->getVehiculoMdelo() ?></td>
                    <td style="font-weight: bold;" align="left">Placa</td>
                    <td>&nbsp;<?=$Vehiculo->getVehiculoPlaca() ?></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: 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>Documento</b>
                    </td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>Razon Social</b></td>
                    <td style="width: 10%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>Cobrado</b></td>
                    <td style="width: 5%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>Nro de Bultos</b></td>
                    <td style="width: 5%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>Guia Transportista</b></td>
                    <td style="width: 5%; background-color: #EEEEEE; border-bottom: 1px solid; border-top: 1px solid; border-color: #B9B5B5;" align="center"><b>Total Comp</b></td>
                    <td style="width: 5%; 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>Saldo x Cob</b>
                    </td>
                </tr>
                
                <?php foreach ( $o_RutaDetalle as $i_Key => $a_Data ){ ?>
                    <?php 
                    $o_VTA_DocumentoFN = new VTA_DocumentoFN();
                    $o_VTA_DocumentoFN->setNumeroDocumento($a_Data->getDocumentRefId());
                    $a_Documento = $o_VTA_DocumentoFN->select();
                    $o_Documento = $a_Documento[0];
                    
                    $o_VTA_OrdenFN = new VTA_OrdenFN();
                    $o_VTA_OrdenBN = $o_VTA_OrdenFN->selectByPK( $o_Documento->getDocumentoParentId() );
                    
                    $o_VTA_OrdenDetalle = $o_VTA_OrdenBN->getArrayDetalles();
                    $i_SumaBultos = 0;
                    foreach ( $o_VTA_OrdenDetalle as $o_VTA_OrdenDetalleBN )
                    {
                        $i_Bultos = $o_VTA_OrdenDetalleBN->getBultos();
                        $i_SumaBultos = $i_SumaBultos + $i_Bultos;
                    }
                    
                    //pr($o_Documento);
                    
                    ?>
                    <?php $s_Background = "background-color: #F0F0F0;"; ?>
                <tr style="<?=$s_Background?>">
                   	<td style="" align="center" colspan="1"><b><?=$a_Data->getRutaDocDespacho();?></b></td>
                    <td style="" align="center" colspan="1"><?=$o_Documento->getClienteNombre();?></td>
                    <td style="" align="center" colspan="1"><?php if ( $o_Documento->getCobranzaEstado() == "CO" ){?> Cobrado <?php }?><?php if ( $o_Documento->getCobranzaEstado() == "PE" ){?> Pendiente <?php }?></td>
                    <td style="" align="center" colspan="1"><?=$i_SumaBultos?></td>
                    <td style="" align="center" colspan="1"><?=$a_Data->getSerieDocumentoRef()?>-<?=$a_Data->getNumeroDocumentoRef()?></td>
                    <td style="" align="center" colspan="1">S/. <?=$o_Documento->getMontoTotal();?></td>
                    <td style="" align="center" colspan="1">S/. <?=$o_Documento->getMontoSaldo();?></td>
                </tr>
                    
	                <?php $TotalSuma = $TotalSuma + $o_Documento->getMontoTotal(); ?>
                    <?php $TotalSuma2 = $TotalSuma2 + $o_Documento->getMontoSaldo(); ?>
	            <?php } ?>
            <tr>
                <td style="" colspan="4">&nbsp;</td>
                <td style="" align="center" ><b>TOTAL   </b>&nbsp;&nbsp;</td>
                <td style="border-top: solid 1px #000000;" align="center"><b>S/. &nbsp;&nbsp;<?=$TotalSuma?></b></td>
                <td style="border-top: solid 1px #000000;" align="center"><b>S/. &nbsp;&nbsp;<?=$TotalSuma2?></b></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: 10px;
                border: 1px solid #B9B5B5; padding: 5px; ">

            <p> OBSERVACIONES: _____________________________________________________________________________________________________________________________________________________________________________ </p>
            <p> ______________________________________________________________________________________________________________________________________________________________________________________________ </p>

        </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: 10px;
                border: 1px solid #B9B5B5; padding: 5px; ">
            <br><br><br><br>
            <table style="width: 100%;" border="0" cellpadding="3" cellspacing="0" >
                <tr>
                    <td style="width: 50%; text-align: center;">_ _ _ _ _ _ _ _ _ _ _ _ _ _ </td>
                    <td style="width: 50%; text-align: center;">_ _ _ _ _ _ _ _ _ _ _ _ _ _ </td>
                </tr>
                <tr>
                    <td style="width: 50%; text-align: center;">Firma de Chofer</td>
                    <td style="width: 50%; text-align: center;">Administrador</td>
                </tr>

            </table>

        </div>
        
    </body>
</html>