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

$spe=$_SESSION['perfil'];
$mysqli = connectDB($r);
roleaccess(1830);
$iduser=$_SESSION['userid'];
$row1 = $mysqli->query("SELECT * FROM z_cotizacion WHERE estado=1 ");
?>

  <?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.php">Nueva Cotizacion</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></th>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <th>Empresa</th>
                  <th>Contacto</th>
                  <th>Telefono</th>
                  <th>Fecha</th>
                  <th>Codigo</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><?= $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-proforma.php?code=<?php echo $row2["id"] ?>')"></i>
                            <i class="btn fa fa-pencil fa-lg p-0 m-1 text-secondary" onClick="window.location.href = 'proforma.php?code=<?php echo $row2["id"] ?>'"></i>
                            <? if($row2["fecha_remision"]==''){ ?><i class="btn fa fa-arrow-up fa-lg p-0 m-1 text-warning"  onClick="window.location.href = 'remision.php?code=<?php echo $row2["id"] ?>'" title="Pasar a remisión"></i><? } ?>
                            <? /*<? if(empty($row2['idcliente'])){ ?><i class="btn fa fa-user-plus fa-lg p-0 m-1 text-warning" onClick="newclient(<?= $row2["id"] ?>)"></i>
                            <? }else{ ?><i class="btn fa fa-check fa-lg p-0 m-1 text-success" onClick="window.location.href = 'pedido-proforma.php?code=<?php echo $row2["id"] ?>'"></i><? } */?></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": [[ 4, "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; 
    }
    function newclient(postData)
{
    var postFormStr = "<form method='POST' action='nuevo-cliente.php'>\n";
    postFormStr += "<input type='hidden' name='idcode' value='" + postData + "'></input>";
    postFormStr += "</form>";
    var formElement = $(postFormStr);

    $('body').append(formElement);
    $(formElement).submit();
}
  </script>
</body>
</html>    
    