<div class="box-header"> 
    <h3><i class='fa-fw fa fa-shopping-basket'></i><?php echo $_translator->_getTranslation(ucfirst($_reporte->getTituloReporte()));?></h3>
    
    <div class='box-icon dropdown'>
        <i class='icon fa fa-tasks' id="moreOptions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></i>
        <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="moreOptions">
            <li><a href="<?php echo $_reporte->getStringToSendGET().'&action=create&output=excel' ?>"><i class="fa fa-file-excel-o"></i>Export to excel</a></li>
            <li><a href="<?php echo $_reporte->getStringToSendGET().'&enviarPorMail' ?>" class="linkSendMail"><i class="fa fa-envelope"></i>Send to email</a></li>
        </ul>
    </div>
</div>
<div class='box-content'>
    <div class='row'>
        <div class="col-lg-12">
            <?php
            $result = $_reporte->getReporte();
            //var_dump($result);exit;
            $data = $result['data'];?>
            
            <ul class="data_summary_rpt"><?php           
                $options = $_reporte->getOptions();
                if($options['status']==='null' || $options['status'] === '2'){?>
                        <li class="_border-primary">
                            <span class="_number"><h3><?php echo number_format($result['ventasPagadas']); ?></h3></span><br/><br/>
                            <span class="_text"><?php echo $_translator->_getTranslation('Cantidad ventas pagadas'); ?></span>
                        </li>
                        <li class="_border-primary">
                            <span class="_number"><h3>$<?php echo number_format($result['ventasPagadasMonto'],2); ?></h3></span><br/><br/>
                            <span class="_text"><?php echo $_translator->_getTranslation('Monto ventas pagadas'); ?></span>
                        </li>          
                <?php }         
                
                if($options['status']==='null' || $options['status'] === '3'){?>
                    <li class="_border-danger">
                        <span class="_number"><h3><?php echo number_format($result['ventasCanceladas']); ?></h3></span><br/><br/>
                        <span class="_text"><?php echo $_translator->_getTranslation('Cantidad ventas canceladas'); ?></span>
                    </li>
                    <li class="_border-danger">
                        <span class="_number"><h3>$<?php echo number_format($result['ventasCanceladasMonto'],2); ?></h3></span><br/><br/>
                        <span class="_text"><?php echo $_translator->_getTranslation('Monto ventas canceladas'); ?></span>
                    </li>          
                <?php } ?>         
            </ul>  
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">
            <div class="table-responsive">
            <table id="tblReport" class="table table-striped table-bordered table-condensed table-hover font-size-10">
            <thead class="table-header">
            <tr>
                <td class="text-center"><?php echo $_translator->_getTranslation('Sucursal');?></td>
                <td class="text-center"><?php echo $_translator->_getTranslation('Num');?></td>
                <td class="text-center"><?php echo $_translator->_getTranslation('Fecha');?></td>
                <td class="text-center"><?php echo $_translator->_getTranslation('Hora');?></td>
                <td class="text-center"><?php echo $_translator->_getTranslation('Forma de pago');?></td>
                <td class="text-center"><?php echo $_translator->_getTranslation('Tarjeta');?></td>
                <td class="text-center"><?php echo $_translator->_getTranslation('Monto con FP');?></td>
                <td class="text-right"><?php echo $_translator->_getTranslation('Importe');?></td>
                <td class="text-right"><?php echo $_translator->_getTranslation('Descuento');?></td>                
                <td class="text-right"><?php echo $_translator->_getTranslation('Impuestos');?></td>
                <td class="text-right"><?php echo $_translator->_getTranslation('Total');?></td>
                <td class="text-right"><?php echo $_translator->_getTranslation('Status');?></td>
                <td class="text-right"><?php echo $_translator->_getTranslation('Accion');?></td>
            </tr>
            </thead>
            <tfoot>
            <tr>
                <th class='filter'><?php echo $_translator->_getTranslation('Sucursal');?></th>
                <th class='filter'><?php echo $_translator->_getTranslation('Num');?></th>
                <th class='filter'><?php echo $_translator->_getTranslation('Fecha');?></th>
                <th class='filter'><?php echo $_translator->_getTranslation('Hora');?></th>
                <th class="filter"><?php echo $_translator->_getTranslation('Forma de pago');?></th>
                <th class="filter"><?php echo $_translator->_getTranslation('Tarjeta');?></th>
                <th class="filter"><?php echo $_translator->_getTranslation('Monto con FP');?></th>
                <th class="filter"><?php echo $_translator->_getTranslation('Importe');?></th>
                <th class="filter"><?php echo $_translator->_getTranslation('Descuento');?></th>                
                <th class="filter"><?php echo $_translator->_getTranslation('Impuestos');?></th>
                <th class="filter"><?php echo $_translator->_getTranslation('Total');?></th>
                <th class="filter"><?php echo $_translator->_getTranslation('Status');?></th>
                <td></td>
            </tr>
            </tfoot>
            <tbody>
            <?php
                foreach($data as $row){  ?>
                    
                <tr>
                        <td class="text-center"><?php echo $row['sucursalName'];?></td>
                        <td class="text-center"><?php echo $row['num_venta'];?></td>
                        <td class="text-center"><?php echo $row['fecha'];?></td>
                        <td class="text-center"><?php echo $row['hora'];?></td>
                        <?php 
                        if($row['formaPago'] === '5' || $row['formaPago'] === '6'){?>
                        <td class="text-center _getCardOperation" style="cursor: pointer" data-sale="<?php echo $row['id'] ?>" data-toggle="modal" data-target="#modalCardOperations">
                            <a href="#" style="cursor: pointer"><?php echo $row['formaPagoConcat'];?></a>
                        </td><?php
                        }else{?>
                             <td class="text-center"><?php echo $row['formaPagoConcat'];?></td><?php
                        } ?>     
                        <td class="text-center"><?php echo $row['last4Concat'];?></td>  
                        <td class="text-right"><?php echo number_format($row['monto_con_fp'],2);?></td>
                        <td class="text-right"><?php if($row['subTotal']!=''){ echo number_format($row['subTotal'],2);}?></td>                        
                        <td class="text-right"><?php if($row['descuento']!=''){ echo number_format($row['descuento'],2);}?></td>                                                
                        <td class="text-right"><?php if($row['impuestos']!=''){echo number_format($row['impuestos'],2);}?></td>
                        <td class="text-right"><?php if($row['total_venta']!=''){echo number_format($row['total_venta'],2);}?></td>
                        <td class="text-center venta_<?php echo $row['id']?>"><?php echo $row['statusName'];?></td>  
                        <td class="text-center">              
                            <div class='dropup' style="display: inline">
                                <button class='btn btn-sm btn-default' data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><i class="fa fa-tasks"></i></button>
                                <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="moreOptions">
                                    
                                    <li><span <?php if($row['status'] == '3'){ echo 'style="pointer-events:none;"';} ?> class="span_on_dropdown_menu" onclick="deleteReportSaleList(<?php echo $row['id']?>)"><i class="fa fa-trash"></i> <?php echo $_translator->_getTranslation('Cancelar');?></span></li>
                                    <li><span class="span_on_dropdown_menu" onclick="javascript: void window.open('https://edinburg.pos.parisbakery.app/View/Tickets/viewTicketVenta.php?id=<?php echo $row['id']?>','','width=700,height=500,status=1,scrollbars=1,resizable=1')"><i class="fa fa-trash"></i> <?php echo $_translator->_getTranslation('Ver ticket');?></span></li>
                                </ul>
                            </div>
                        </td>
                    </tr><?php 
                }?>
            </tbody>
            </table>
            </div>
        </div>
    </div>
</div>
<?php
    include ROOT."/View/Modal/operacionesTarjeta.php";
    include ROOT."/View/Modal/operacionesTarjetaDetalles.php";
    include ROOT."/View/Modal/refund.php";
 ?>
<style>
    tfoot {
        display: table-header-group;
    }
    .span_on_dropdown_menu{
        padding:3px 20px;
        cursor: pointer;
        width: 100%
    }
    
    .span_on_dropdown_menu:hover{
        background-color: #f5f5f5;
    }
</style>

<script type="text/javascript" language="javascript">
    $('#tblReport').DataTable({
        paginate:false,
        filter:true,
        bFilter:true,
        aaSorting:[]
    });
    
    $('#tblReport')
            .removeClass( 'display' )
            .addClass('table table-striped table-bordered');
        
    $('#tblReport tfoot th.filter').each( function () {
        var title = $(this).text();
        $(this).html( '<input type="text" placeholder="Buscar" style="width:100%" />' );
    } );  
 
    var table = $('#tblReport').DataTable();
    // Apply the search
    table.columns().every( function () {
        var that = this; 
        $( 'input', this.footer() ).on( 'keyup change', function () {
            if ( that.search() !== this.value ) {
                that
                    .search (this.value.replace("/;/g", "|"), true, false)
                    .draw();
            }
        } );
    } );
    
    $('._getCardOperation').on('click',function(){
        getCardOperationBySale($(this).data('sale'));
    });
    
    
</script>