<?php
  require $_SERVER["DOCUMENT_ROOT"].'/inc/topo.php';
  require $_SERVER["DOCUMENT_ROOT"].'/inc/menu.php';
  require $_SERVER["DOCUMENT_ROOT"].'/api/pages/caixa.php';
  requerPermissao('21:24:17');
?>
<style> .main-header { z-index: 2 !important; } </style>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
   <!-- Content Header (Page header) -->
   <section class="content-header">
      <h1>
         Bilhetes
         <small>Gestão de Banca</small>
      </h1>
      <a href="#" class="btn btn-success pull-right" style=" margin-top: -38px; "><i class="ti-plus"></i> &nbsp; Nova Aposta</a>
   </section>
   <!-- Main content -->
   <section class="content">
      <br />
      <div class="row">
         <div class="col-lg-4 col-12">
            <!-- AREA CHART -->
            <form action="">
             <?php if(isset($_GET["user"])){ echo '<input type="hidden" name="user" value="'.$_GET["user"].'" />'; } ?>
              <select name="type" class="form-control">
                <option value="">Tipo de consulta</option>
                <?php
                  if(in_array('24', $_SESSION["usuario"]["permissoes"])){ echo '<option '; if($_GET["type"] == 'general'){ echo 'selected'; } echo ' value="general">Caixa geral</option>'; }
                  if(in_array('21', $_SESSION["usuario"]["permissoes"])){ echo '<option '; if($_GET["type"] == 'personal'){ echo 'selected'; } echo ' value="personal">Meu caixa</option>'; }
                ?>

              </select>
              <div class="input-group">
                <input type="text" name="date" class="form-control pull-right" id="datepicker" placeholder="De" value="<?php echo $api['date']; ?>">
                <span class="input-group-addon">&nbsp; até &nbsp;</span>
                <input type="text" name="enddate" class="form-control pull-right" id="datepicker" placeholder="Até" value="<?php echo $api['enddate']; ?>">
              </div>
              <button type="submit" class="btn btn-info btn-md btn-block"><i class="fa fa-search"></i> &nbsp; Aplicar</button><br />
            </form>
         </div>
         <div class="col-lg-8 col-12">
            <div class="box">
               <div class="box-header with-border">
                  <h3 class="box-title">Bilhetes</h3>
                  <a href="javascript:history.back('-1');" class="btn btn-danger btn-md pull-right"><i class="fa fa-reply"></i> &nbsp; Voltar</a>
               </div>
               <!-- /.box-header -->
               <div class="box-body">
                  <div class="table-responsive">
                     <table id="example" class="table table-bordered table-hover display nowrap margin-top-10 w-p100">
                        <thead>
                           <tr>
                              <th>-</th>
                              <th>Código</th>
                              <th>Data</th>
                              <th>Cliente</th>
                              <th>Colaborador</th>
                              <th>Valor</th>
                              <th>Poss. Ret.</th>
                              <th>Status</th>
                              <th>Opções</th>
                           </tr>
                        </thead>
                        <tbody>
                           <?php $i = 1; foreach ($api['coupons'] as $code => $v) { ?>
                           <tr>
                              <td align="center"><?php echo $i; ?></td>
                              <td align="center"><b><?php echo $code; ?></b></td>
                              <td align="center"><?php echo $v["date"]; ?></td>
                              <td><?php echo $v["client"]; ?></td>
                              <td><?php echo $v["seller"]; ?></td>
                              <td align="center">R$<?php echo $v["price"]; ?></td>
                              <td align="center">R$<?php if($v["status"] <> '2'){ echo $v["return"]; } else { echo $v["rewards"]; } ?></td>
                              <td align="center">
                                 <?php
                                    switch ($v["status"]) {
                                       case '1':
                                          echo '<span class="badge badge-info">Aberto</span>';
                                          break;

                                       case '2':
                                          echo '<span class="badge badge-success">Ganhou</span>';
                                          break;

                                       case '3':
                                          echo '<span class="badge badge-danger">Perdeu</span>';
                                          break;

                                       case '4':
                                          echo '<span class="badge bg-navy">Cancelado</span>';
                                          break;

                                       case '11':
                                          echo '<span class="badge bg-cyan">Process. Parcial</span>';
                                          break;

                                       default:
                                          echo '<span class="badge badge-warning">Indefinido</span>';
                                          break;
                                    }
                                 ?>
                              </td>
                              <td align="center">
                                 <div class="input-group-btn">
                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Opções</button>
                                    <div class="dropdown-menu" x-placement="bottom-start" style="position: absolute; transform: translate3d(0px, 37px, 0px); top: 0px; left: 0px; will-change: transform;">
                                       <a class="dropdown-item" href="/bilhetes/conferir?code=<?php echo $code; ?>"><i class="fa fa-eye"></i> &nbsp; Visualizar</a>
                                       <a class="dropdown-item" target="framePrint" href="/imprimir/<?php echo $code; ?>"><i class="fa fa-print"></i> &nbsp; Imprimir</a>
                                       <a class="dropdown-item" href="/bilhetes/atualizar/<?php echo $code; ?>"><i class="fa fa-refresh"></i> &nbsp; Atualizar</a>
                                       <div class="dropdown-divider"></div>
                                       <a class="dropdown-item" target="framePrint" href="/bilhetes/cancelar/<?php echo $code; ?>"><i class="fa fa-ban"></i> &nbsp; Cancelar</a>
                                    </div>
                                 </div>
                              </td>
                           </tr>
                           <?php $i++; } ?>
                        </tbody>
                        <tfoot>
                           <tr>
                              <th>-</th>
                              <th>Código</th>
                              <th>Data</th>
                              <th>Cliente</th>
                              <th>Colaborador</th>
                              <th>Valor</th>
                              <th>Poss. Ret.</th>
                              <th>Status</th>
                              <th>Opções</th>
                           </tr>
                        </tfoot>
                     </table>
                  </div>
               </div>
               <!-- /.box-body -->
            </div>
            <!-- /.box -->
         </div>
      </div>
      <!-- /.row -->
   </section>
   <!-- /.content -->
</div>
<!-- /.content-wrapper -->
<!-- ./wrapper -->
<?php require $_SERVER["DOCUMENT_ROOT"].'/inc/rodape.php'; ?>

<!-- InputMask -->
<script src="/assets/vendor_plugins/input-mask/jquery.inputmask.js"></script>
<script src="/assets/vendor_plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="/assets/vendor_components/bootstrap-daterangepicker/daterangepicker.js"></script>
<script src="/assets/vendor_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script> $(function(){ $('[id="datepicker"]').datepicker({ autoclose: true, format: 'yyyy-mm-dd' }); }); </script>
<!-- popper -->
<script src="/assets/vendor_components/popper/dist/popper.min.js"></script>
<!-- DataTables -->
<script src="/assets/vendor_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="/assets/vendor_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/media/js/jquery.dataTables.min.js"></script>
<!-- start - This is for export functionality only -->
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/dataTables.buttons.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/buttons.flash.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/ex-js/jszip.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/ex-js/pdfmake.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/ex-js/vfs_fonts.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/buttons.html5.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/buttons.print.min.js"></script>
<!-- end - This is for export functionality only -->
<!-- Unique_Admin for Data Table -->
<script src="/js/pages/data-table.js"></script>
<iframe src="" frameborder="0" id="framePrint" name="framePrint" height="0"></iframe>