<?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>
<body>
     <iframe name="print_frame" width="0px" height="0px" frameborder="0" src="about:blank"></iframe>
    <?php
    # INFORMACION EMPRESA
    $empresa = new EmpresaEntity();
    $empresa->setOptions($empresa->getById(1)); 
    
    $nombreEmpresa  = $empresa->getNombre();
    $direccion      = $empresa->getDireccion();
    $ciudadEstadoZC = $empresa->getCiudad().', '.$empresa->getEstado().' '.$empresa->getCodigoPostal();
    $telefono       = $empresa->getTelefono();  
    $paginaWeb      = $empresa->getPaginaWeb();
    
    #Para obtener el impuesto * partida
    $repoImpuestos = new ImpuestosRepository();
    $dataImpuestos = $repoImpuestos->getById(3);
  
    $idRequisicion = $_GET['idSr'];
   
   // var_dump($idRequisicion); exit;
    $entrega = new SpecialRequisitionRepository();
    //var_dump($entrega->getById($idRequisicion));exit
    $specialRequisitionData = $entrega->getById($idRequisicion);
    $entrega->setOptions($specialRequisitionData);
  //  var_dump($entrega); exit;
    $fechaCreacion = strftime('%d/%m/%y',strtotime($entrega->getDate()));
    $cajero = $entrega->getCreadoPorNombre();
    $ammount = $entrega->getAmmount();
    $saldoPendiente = $entrega->getBalance();
    $fechaEntrega = strftime('%d/%m/%y %H:%M:%S',strtotime($entrega->getDeliveryDate())); 
    $cliente =  $entrega->getCustomerName();
    $telefonoCliente = $entrega->getTelefono();
    $nombreCompany =  $entrega->getCompanyName();  
    
    $telefono1 = $entrega->getTelefono();
    #Se asume que todo precio lleva incluido el monto de impuesto que grava.
    $subtotal = $ammount/(1+$dataImpuestos['tasa_cuota']/100); 
    $montoImpuesto =  ($subtotal) * ($dataImpuestos['tasa_cuota']/100);
    $nombreImpuesto = $dataImpuestos['descripcion'];
    $req_number = $entrega->getReqNumber();   
    
    
    $SucursalRepository = new SucursalRepository();
    $SucursalRepository->setOptions($SucursalRepository->getById($specialRequisitionData['store']));
    
    $nombreSucursal = $SucursalRepository->getNombre();
    $direccion      = $SucursalRepository->getDireccion();
    $ciudadEstadoZC = $SucursalRepository->getCiudad().', '.$SucursalRepository->getEstado().' '.$SucursalRepository->getCodigoPostal();
    $telefono       = $SucursalRepository->getTelefono();  
    
    ?>
        <div id="printArea" style="margin:auto;width: 80mm;font-size: 14px">
        <div style="margin:auto;font-size: 10px;font-family: Arial,Helvetica Neue,Helvetica,sans-serif">
        <div style="text-align: center">
            <div style="margin: 30px;margin-bottom: 10px">
                <img src="../../public/img/logo_login.png" width="50%">
            </div>            
            <h4 style="margin-bottom:0px"><?php echo $nombreEmpresa;?></h4>   
            <br/>
            <p style="margin:0px;"><?php echo $direccion; ?></p>
            <p style="margin:0px;"><?php echo $ciudadEstadoZC; ?></p>
            <p style="margin:0px;"><?php echo $telefono;?></p>
            <br/>
            <p style="margin:0px;">SPECIAL ORDER</p>
            <br/>
        </div> 
        <div>    
            <p style="margin:0px;">Special order #: <?php echo $idRequisicion?></p>
            <p style="margin:0px;">Date: <?php echo $fechaCreacion;?></p>
            <p style="margin:0px;">Store: <?php echo $nombreSucursal?></p>
            <p style="margin:0px;">Cashier: <?php echo $cajero?></p>         
        </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>
            <th style="width:10%">Qty</th>
            <th style="width:65%">Description</th>
            <th style="width:25%;text-align: right">Total</th>
        </thead>
        <tbody>
            <tr style="border: 1px solid #f3f3f3"></tr>
        <tr>
            <!-- 	Pago de orden especial: -->
            <th style="width:10%">1</th>
            <th style="width:65%">Special order payment: # <?php echo $req_number?></th>
            <th style="width:25%;text-align: right"><?php echo number_format(round($ammount,2,PHP_ROUND_HALF_UP),2);?></th>
        <br/>
            
        </tr>    
        <tr>
            <!--
        <tr style="border:0px">
            <td colspan="2" style="border:0px;text-align: right;margin:0px;padding:0px"><?php echo $nombreImpuesto ?>:</td>
            <td style="border:0px;text-align: right;margin:0px;padding:0px">$ <?php echo number_format(round($montoImpuesto,2,PHP_ROUND_HALF_UP),2);?></td>
        </tr>      -->  
        <tr style="border:0px;">
            <td colspan="2" style="border:0px;text-align: right;margin:0px;padding:0px"><b>Total sale:</b>
            <td style="border:0px;text-align: right;margin:0px;padding:0px">$ <?php echo number_format(round($ammount,2,PHP_ROUND_HALF_UP),2);?></td>
            
        <tr style="border:0px;">
            <td colspan="2" style="border:0px;text-align: right;margin:0px;padding:0px"><b>Balance:</b>
            <td style="border:0px;text-align: right;margin:0px;padding:0px">$ <?php echo number_format(round($saldoPendiente,2,PHP_ROUND_HALF_UP),2);?></td>    
        </tbody>
    </table> 
<br/>

        <table class="m-t-1 table table-condensed tableTicket">
           
            <tbody>           
                <tr>
                    <td style="border:0px;text-align: left;margin:0px;padding:0px"><b>Delivery:</b>
                    <td style="border:0px;text-align: right;margin:0px;padding:0px"><?php echo $fechaEntrega?></td>
                </tr >   
                <tr >
                    <td style="border:0px;text-align: left;margin:0px;padding:0px"><b>Customer:</b>
                    <td style="border:0px;text-align: right;margin:0px;padding:0px"><?php echo $cliente ?></td>
                </tr>  
                <tr>
                    <td  style="border:0px;text-align: left;margin:0px;padding:0px"><b>Phone:</b>
                    <td style="border:0px;text-align: right;margin:0px;padding:0px"><?php echo $telefonoCliente ?></td>
                </tr>  
                <!--
                <tr>
                    <td  style="border:0px;text-align: left;margin:0px;padding:0px"><b>Telefono 1:</b>
                    <td style="border:0px;text-align: right;margin:0px;padding:0px"><?php echo $telefono1 ?></td>
                </tr>  
                <tr>
                    <td  style="border:0px;text-align: left;margin:0px;padding:0px"><b>Telefono 2:</b>
                    <td style="border:0px;text-align: right;margin:0px;padding:0px"><?php echo $telefono2 ?></td>
                </tr>  
                <tr>
                    <td style="border:0px;text-align: left;margin:0px;padding:0px"><b>Empresa/Negocio:</b>
                    <td style="border:0px;text-align: right;margin:0px;padding:0px"><?php echo $nombreCompany ?></td>
                </tr> 
                <tr>
                    <td style="border:0px;text-align: left;margin:0px;padding:0px"><b>Parque:</b>
                    <td style="border:0px;text-align: right;margin:0px;padding:0px"><?php echo $parque ?></td>
                </tr> 
                 <tr >
                    <td style="border:0px;text-align: left;margin:0px;padding:0px"><b>Departamento</b>
                    <td style="border:0px;text-align: right;margin:0px;padding:0px"><?php echo $departamento ?></td>
                </tr>       
                -->
            </tbody>
        </table>  
<br/>
<?php

    #Detalles de pedido
    $requisition = new SpecialRequisitionRepository();
    $requisitionData = $requisition->getById($idRequisicion);
    $detalles = $requisition->getRequisitionDetailsSaved($idRequisicion);
    if($detalles){ 
        $prefix = ""; ?>
  
        <table class="m-t-1 table table-condensed tableTicket">
            <thead>
                <tr>
                    <!--<th style="width:10%">PE #</th>-->
                   <!-- <th style="width:15%">Categoria</th> -->                  
                    <th>Description</th>
                    <th>Size</th>
                    <th>Quantity</th>
                </tr>
            </thead>
            <tbody >
             <?php foreach ($detalles as $detalle ){
                 $prefix = ""; ?>                  
                      <tr>      
                        <!--<td style="widtd:10%"><?php echo $detalle['multiple'] ?></td>-->
                        <!--<td style="widtd:15%"><?php echo $detalle[$prefix.'category'] ?></td>-->
                        <td><?php echo $detalle[$prefix.'description'] ?></td>
                        <td><?php echo $detalle[$prefix.'size'] ?></td>
                        <td style=" text-align:center"><?php echo $detalle['quantity'] ?></td>
                      </tr> 
            <?php }?><tr>
                        <td colspan="3"><?php echo $requisitionData['comments_1'] ?></td>
                     </tr>
            </tbody>
        </table> 
<?php }?>
        <br/>
        
    <div style="text-align: center"></td>
        </tr>
        </tbody>
        <p>Our products do not contain preservatives; consume within 36 hours of purchasing.</p>
        <p>Once product has left the store, it can not be returned or exchanged.</p>
        <p>Changes and cancellations on special orders must be requested 72 hours before date of delivery.</p>
        
        <p style="margin:0px">Thank you for visiting</p>
        <p style="margin:0px">Have a nice day</p>
    </div>           
    
    </div>
    </div>

<script type="text/javascript">  
        //printDivCSS = new String ();
        
        function print(ticket){
            window.frames["print_frame"].document.body.innerHTML = document.getElementById(ticket).innerHTML;
            window.frames["print_frame"].window.focus();
            window.frames["print_frame"].window.print();
        }
        
        print('printArea');
        //setTimeout("print('printArea')",1000);
    </script>
</body>
</html>