<?php $r="../";
require_once($r."inc/funciones.php");
$titlepage = "Cotizaciones";
validNotSession($r);

$spe=$_SESSION['perfil'];
$mysqli = connectDB($r);
roleaccess(1810);
$iduser=$_SESSION['userid'];
$fecha_hoy = date("Y-m-d"); // Obtener la fecha actual en formato YYYY-MM-DD
$fecha_seis_meses_atras = date("Y-m-d", strtotime("-6 months", strtotime($fecha_hoy))); // Restar 6 meses a la fecha actual

$row1 = $mysqli->query("SELECT * FROM z_cotizacion WHERE estado=0 AND fecha >= '$fecha_seis_meses_atras'");
?>
  <?php include $r."inc/head.php"; ?>
  
 
<body class="fixed-nav sidenav-toggled sticky-footer bg-dark" id="page-top">
  <?php include $r."inc/nav.php"; ?>
  <div class="content-wrapper">
    <div class="container-fluid">
      <div class="card mb-3">
        <div class="card-header">
          <a class="btn btn-primary float-right text-white m-1" href="nueva_electro.php">Cotización Electrónica</a>
          <a class="btn btn-primary float-right text-white m-1" href="nueva_remi.php">Cotización Remi</a>
          <a class="btn btn-primary float-right text-white m-1" href="proformas.php">Ver Pro-Formas</a>
         </div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
              <thead>
                <tr>
                  <th>Empresa</th>
                  <th>Contacto</th>
                  <th>Telefono</th>
                  <th>Fecha</th>
                  <th>Codigo</th>
                  <th>Tipo</th>
                  <th></th>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <th>Empresa</th>
                  <th>Contacto</th>
                  <th>Telefono</th>
                  <th>Fecha</th>
                  <th>Codigo</th>
                  <th>Tipo</th>
                  <th></th>
                </tr>
              </tfoot>
              <tbody>
                    <?php
                    while($row2 = $row1->fetch_assoc()) {
                    ?>
                      <tr>
                        <td><?= $row2['empresa']; ?></td>
                        <td><?= $row2['contacto'];?></td>
                        <td><?= $row2["telefono"]; ?></td>
                        <td><?= $row2["fecha"]; ?></td>
                        <td><? if($row2["remision"]){ echo 'RM '; }else{ echo 'FC ';} ?></td>
                        <td><?= $row2["id"]; ?></td>
                        <td class="p-1" width="105px">
                            <i class="btn fa fa-print fa-lg p-0 m-1 text-primary" onClick="return popitup('print-cotizacion.php?code=<?php echo $row2["id"] ?>')" title="Imprimir Cotizacion"></i>
                            <? if(!$row2["remision"]){  ?>
                                <i class="btn fa fa-pencil fa-lg p-0 m-1 text-secondary" onClick="window.location.href = 'cotizacion_electro.php?code=<?php echo $row2["id"] ?>'" title="Editar Cotizacion Electronica"></i>
                                <i class="btn fa fa-arrow-up fa-lg p-0 m-1 text-success" onClick="window.location.href = 'proforma_electro.php?code=<?php echo $row2["id"] ?>'" title="Pasar a Pro-Forma Electronica"></i>
                            <? }else{ ?>
                                <i class="btn fa fa-pencil fa-lg p-0 m-1 text-secondary" onClick="window.location.href = 'cotizacion_remi.php?code=<?php echo $row2["id"] ?>'" title="Editar Cotizacion Remision"></i>
                                <i class="btn fa fa-arrow-up fa-lg p-0 m-1 text-success" onClick="window.location.href = 'proforma_remi.php?code=<?php echo $row2["id"] ?>'" title="Pasar a Pro-Forma Remision"></i>
                            <?} ?></td>
                            <!--
                            <? if($row2["revisar"]=='1'){?><a class="btn_default text-warning h5" href="editar.php?id=<?= $row2["codigopedido"] ?>"><i class="fa fa-info"></i></a>
                        <?} ?>
                        <a class="btn_default text-success h5" target="_blank" href="https://api.whatsapp.com/send?phone=57<? echo $celular; ?>&text=<? echo $dominio; ?>/admin/pedido/aprobando.php?code%3D<?= $row2["codigopedido"] ?>"><i class="fa fa-whatsapp"></i></a>
                        <a class="btn_default text-primary h5" href="editar.php?id=<?= $row2["codigopedido"] ?>"><i class="fa fa-pencil"></i></a>
                        <a class="btn_default text-danger h5 eliminar" href="eliminar-pedido.php?id=<?= $row2["codigopedido"] ?>"><i class="fa fa-close"></i></a>--></td>
                        </tr>
                    <?php
                    }
                    ?>
              <tbody>
            </table>
          </div>
        </div>
      </div><a class="btn btn-primary btn-block" href="nueva.php" title="Nuevo Pedido">Nueva Cotización</a>
    </div>
  </div>
  <?php include $r."inc/foot.php"; ?>
  
  <script>
    $('#dataTable').DataTable( {
        "order": [[ 5, "desc" ]],
        "lengthMenu": [[25, 50, 100, 500, -1], [25, 50, 100, 500, "All"]]
    } );
    
    function popitup(url){
	    newwindow=window.open(url,'name','height=1170,width=826'); 
	    if (window.focus) {newwindow.print();}
	    return false; 
    }
  </script>
</body>
</html>    
    