<?php 
    $controller = 'POS';
    $action = 'print';
    include $_SERVER["DOCUMENT_ROOT"].'/app/include/bootstrap.php';?>
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link href="<?php echo ROOT_HOST?>/public/bootstrap/css/bootstrap.min.css" rel="stylesheet">     
</head><?php
/* INFORMACION EMPRESA */
#Cuando envio impresion desde boton en listado AperturaCierreCaja.php utilizando javascript printOpening();
$empresa = new EmpresaEntity();
$empresa->setOptions($empresa->getById(1)); 

$nombreEmpresa  = $empresa->getNombre();
$direccion      = $empresa->getDireccion();
$ciudadEstadoZC = $empresa->getCiudad().', '.$empresa->getEstado().' '.$empresa->getCodigoPostal();
$telefono       = $empresa->getTelefono();  

/* INFORMACION APERTURA DE CAJA */
$operacionesTarjeta = new OperacionesTarjetasRepository();
$dataCharge = $operacionesTarjeta->getDataPayment($_GET['reference']);
//$originCharge = $operacionesTarjeta->getByReference($dataCharge['data']['parent_reference']);

$charge = $dataCharge['data'];
$log = $dataCharge['log'];
$total_refund = 0;
$date = '';
    
if($log){
    foreach($log as $operation){
        if($operation['type'] == 'refund'){
            $date = $operation['date_formated'];
            break;
        }
    }
}
?>
<div id="printArea">
    <div style="margin:auto;text-align: center;font-size: 10px;font-family: Arial,Helvetica Neue,Helvetica,sans-serif">
        <div style="margin: 30px;margin-bottom: 10px">
            <img src="../../public/img/logo_login.png" width="50%">
        </div>
        <div style="text-align: center">
            <h4><?php echo $nombreEmpresa;?></h4>
            <p class="m-a-0"><?php echo $direccion; ?></p>
            <p class="m-a-0"><?php echo $ciudadEstadoZC; ?></p>
            <p class="m-a-0"><?php echo $telefono;?></p>
        </div> 
        <div class="m-t-1">    
            <h4 class="m-a-0 text-center w-100">* * * * <?php echo $_translator->_getTranslation('Reembolso')?> * * * *</h4>           
        </div>   
        <style>.table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th{padding:2px; font-size: 12px}</style>
        <table class="m-t-1 table table-condensed tableTicket">
        <thead>
            <tr>
                <th style="width:20%;text-align: center"><?php echo $_translator->_getTranslation('Reembolsado')?></th>
                <th style="width:40%;text-align: center"><?php echo $_translator->_getTranslation('Fecha')?></th>
                <th style="width:40%;text-align: center"><?php echo $_translator->_getTranslation('Reembolsado a')?></th>
            </tr>
            <tr>
                <td style="widtd:20%;text-align: center">$<?php echo number_format($charge['refund_amount'],2)?></td>
                <td style="widtd:40%;text-align: center"><?php echo $date;?></td>
                <td style="widtd:40%;text-align: center"><?php echo $charge['brand'].' - '.$charge['last_4']?></td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td colspan="3" style="text-align: left;height:60px;vertical-align: middle">
                    This receipt is to confirm that your refund has been issued by <?php echo $nombreEmpresa ?>. It can take 10+ days to appear on your statement, if it takes longer please contact your bank for assistance. 
                </td>
            </tr>
            <tr>
                <td colspan='3' style="text-align:left;height:40px;vertical-align: middle"><?php echo $_translator->_getTranslation('Resumen'); ?></td>
            </tr>
            <tr>
                <td style="text-align: left" colspan="2"><?php echo $_translator->_getTranslation('Total cargo')?></td>
                <td style="text-align: right">$<?php echo number_format($charge['amount'],2)?></td>
            </tr>
            <?php
            foreach($log as $refund){
                if($refund['type'] === 'refund'){?>
                    <tr>
                        <td style="text-align: left" colspan="2"><?php echo $_translator->_getTranslation('Monto reembolsado el:').' '.$refund['date_formated']?></td>
                        <td style="text-align: right">$<?php echo number_format($refund['amount'],2)?></td>
                    </tr><?php
                }
            }
            ?>
            <tr>
                <td style="text-align: left" colspan="2"><?php echo $_translator->_getTranslation('Total ajustado')?></td>
                <td style="text-align: right">$<?php echo number_format($charge['amount'] - $charge['refund_amount'],2)?></td>
            </tr>
        </tbody>
        </table>
    </div>
</div>
    <script type="text/javascript">
        self.print();
    </script>
</body>
</html>
