<?php include 'sesion_user.php';
$d1 = $_POST['d1'];
$d1 = str_pad($d1, 2, "0", STR_PAD_LEFT);
$m1 = $_POST['m1'];
$m1 = str_pad($m1, 2, "0", STR_PAD_LEFT);
$a1 = $_POST['a1'];
$h1 = $_POST['h1'];
$h1 = str_pad($h1, 2, "0", STR_PAD_LEFT);
$min1 = $_POST['min1'];
$min1 = str_pad($min1, 2, "0", STR_PAD_LEFT);
$d2 = $_POST['d2'];
$d2 = str_pad($d2, 2, "0", STR_PAD_LEFT);
$m2 = $_POST['m2'];
$m2 = str_pad($m2, 2, "0", STR_PAD_LEFT);
$a2 = $_POST['a2'];
$h2 = $_POST['h2'];
$h2 = str_pad($h2, 2, "0", STR_PAD_LEFT);
$min2 = $_POST['min2'];
$min2 = str_pad($min2, 2, "0", STR_PAD_LEFT);
$desde ="$a1$m1$d1$h1$min1";
$hasta ="$a2$m2$d2$h2$min2";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Panel</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M"
    crossorigin="anonymous">
  <link href="http://radioshosting.com/css/delalora4new.css" rel="stylesheet">
  <link rel="stylesheet" href="https://unpkg.com/flickity@2/dist/flickity.min.css" />
  <link rel="stylesheet" href="http://ejemplo.radiosnet.com.ar/css/font-awesome.min.css" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <style>
    /* Estilos del modal */
    .modal {
      display: none;
      position: fixed;
      z-index: 1;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      overflow: auto;
      background-color: rgba(0,0,0,0.4);
    }

    .modal-content {
      background-color: #fefefe;
      margin: 10% auto;
      padding: 20px;
      border: 1px solid #888;
      width: 80%;
      max-width: 600px;
    }

    /* Estilos del botón de cierre */
    .close {
      color: #aaa;
      float: right;
      font-size: 28px;
      font-weight: bold;
    }

    .close:hover,
    .close:focus {
      color: black;
      text-decoration: none;
      cursor: pointer;
    }

    /* Estilos del spinner de carga */
    .spinner {
      border: 16px solid #f3f3f3;
      border-top: 16px solid #3498db;
      border-radius: 50%;
      width: 80px;
      height: 80px;
      animation: spin 2s linear infinite;
      margin: 20px auto;
    }

    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }
  </style>
</head>

<body onload="document.forms['form14']['busqueda'].focus()">
  <div class="container-fluid">
    <div class="row">
      <div class="col-lg-3 col-md-3 col-sm-12">
        <?php
include 'nav.php';?>
      </div>
      <div class="col-lg-9 col-md-9 col-sm-12">
        <?php include 'inc_buscar.php';?>
        <a href="nueva_venta.php"><button type="button" class="btn btn-success">INICIAR UNA VENTA</button></a>
        <hr />


        <div style="background-color:#e4ffe4;">
        <p style="background-color: #28a745;
color: white;
padding-left: 15px;"><b>CAJA PRINCIPAL</b></P>

<BR>
        <B>INGRESOS (VENTAS) DESDE <?php echo $d1 ?> / <?php echo $m1 ?> / <?php echo $a1 ?> - <?php echo $h1 ?>:<?php echo $min1 ?>  HASTA <?php echo $d2 ?> / <?php echo $m2 ?> / <?php echo $a2 ?> - <?php echo $h2 ?>:<?php echo $min2 ?></B>
        
        
        <hr />
        <?php
include 'concha.php';
mysql_connect("$host","$usuario","$contra");
mysql_select_db ("$basedatos");
$sql = "SELECT * FROM `ventas` WHERE `fecha` >= '$desde' AND `fecha` <= '$hasta' AND `forma_pago` != 'anulado' AND total != 0 and total > 0";

$consulta = mysql_query ($sql);
while ($row = mysql_fetch_array($consulta))
{
$ID_venta = $row["ID"];
$fecha = $row["fecha"];
$total = $row["total"];
$usuario = $row["usuario"];
$ano = substr($fecha, 0,4);
$mes = substr($fecha, 4,2);
$dia = substr($fecha, 6,2);
$hora = substr($fecha, 8,2);
$min = substr($fecha, 10,2);
$total_tol = $total_tol + $total;



?>
        <?php echo $dia ?>/
        <?php echo $mes ?>/
        <?php echo $ano ?> -
        <?php echo  $hora ?>:
        <?php echo $min ?> / <b>$ <?php echo $total ?></b>

      <button type="button" class="btn btn-success openModal" data-url="ver_detalle_venta.php?ID=<?php echo $ID_venta ?>" style="margin-top: 11px; border: solid;
border-color: black;
border-width: 1px; padding: 4px;">
    <img style="filter: invert();
width: 16px; " src="https://sistemastock.com/misistema/icons/ver_detalles.png">  Ver Detalle</button>
        <hr />
        <?
}
mysql_free_result($consulta);






//opcion23 indica ancho del div que contiene el ticket


$sql = "SELECT opcion25 FROM `configuracion` LIMIT 1";

$consulta = mysql_query ($sql);

while ($row = mysql_fetch_array($consulta))

{

$opcion25 = (int)$row["opcion25"];


}

mysql_free_result($consulta);






?>
          <hr /> TOTAL:
          <h2>$
            <?php echo $total_tol ?>
          </h2>
          </div>

          <hr />

<? if  ($opcion25 == 0){?>

<div style="background-color:#ffeded;">
          <p style="background-color: red;
color: white;
padding-left: 15px;"><b>CAJA CON COSTO DISCRIMINADO</b></p>

<p>ESTA CUENTA SOLO FUNCIONA SI TODOS LOS PRODUCTOS TIENEN COLOCADO EL PRECIO DE COSTO. <BR>EN CASO DE NO UTILIZAR ESTA CAJA, PUEDE DESACTIVARLA HACIENDO <a href="desactivar_funcion.php?c=opcion25">CLIC AQUÍ.</a></p>

<A href="https://docs.google.com/document/d/19sNNhZ2jJPDuNihgaGk4lbDWGwkvm7xasH1EFU-Lkiw/edit?usp=sharing" target="_blank">
    <img src="AYUDAMINI.png" style="width:70px"></a><br>

          <hr />
          <B>MOVIMIENTOS DESDE <?php echo $d1 ?> / <?php echo $m1 ?> / <?php echo $a1 ?> - <?php echo $h1 ?>:<?php echo $min1 ?>  HASTA <?php echo $d2 ?> / <?php echo $m2 ?> / <?php echo $a2 ?> - <?php echo $h2 ?>:<?php echo $min2 ?></B><br /> Hoy es
          <?php echo date(d)?>/
          <?php echo date(m) ?>/
          <?php echo date(Y) ?>
          <hr />
          <?php
$total_tol = 0;
include 'concha.php';
mysql_connect("$host","$usuario","$contra");
mysql_select_db ("$basedatos");
$sql = "SELECT * FROM `ventas_costo` WHERE `fecha` >= '$desde' AND `fecha` <= '$hasta' AND `forma_pago` != 'anulado' AND total != 0 and total > 0";
$consulta = mysql_query ($sql);
while ($row = mysql_fetch_array($consulta))
{
$ID_venta = $row["ID"];
$fecha = $row["fecha"];
$total = $row["total"];
$total_costo = $row["total_costo"];
$usuario = $row["usuario"];
$ano = substr($fecha, 0,4);
$mes = substr($fecha, 4,2);
$dia = substr($fecha, 6,2);
$hora = substr($fecha, 8,2);
$min = substr($fecha, 10,2);
$total_tol_costo = $total_tol_costo + $total_costo;
$total_tol = $total_tol + $total;
?>
          <?php echo $dia ?>/
          <?php echo $mes ?>/
          <?php echo $ano ?> -
          <?php echo  $hora ?>:
          <?php echo $min ?> / <b>$ <?php echo $total ?> </b>$ <?php echo $total_costo ?> Gan: $ <?
$gan = $total - $total_costo;
echo $gan;
?></b>
          <a href="javascript:ventanaSecundaria56('ver_detalle_venta.php?ID=<?php echo $ID_venta ?>')"> <i class="fa fa-list" aria-hidden="true"></i> Ver Detalle </a>
          <hr />
          <?
}
mysql_free_result($consulta);
?>
            <hr /> TOTAL:
            <h2>$
              <?php echo $total_tol ?>
            </h2>
            TOTAL COSTOS:
            <h2>$
              <?php echo $total_tol_costo ?>
            </h2>
            GANANCIA:
            <h2>$
              <?php
$gan2 = $total_tol - $total_tol_costo;
echo $gan2 ?>
            </h2>

</div>
<? } else { ?> PUEDE ACTIVAR <b>CAJA CON COSTO DISCRIMINADO</b> HACIENDO <a href="activar_funcion.php?c=opcion25">CLIC AQUÍ.</a></p><? } ?>
      </div>
    </div>
  </div>

  <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4"
    crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1"
    crossorigin="anonymous"></script>


  <script type="text/javascript">
    window.setInterval(function(){
      $('.grid').isotope({
      itemSelector: '.grid-item'
    });
    }, 2000);
  </script>
  <script language=javascript>
    function ventanaSecundaria56 (URL){
       window.open(URL,"ventana1","width=600,height=500,scrollbars=NO")
    }
  </script>
  
<!-- Modal -->
<div id="myModal" class="modal">
  <div class="modal-content">
    <span class="close">&times;</span>
    <div id="spinner" class="spinner"></div>
    <iframe id="myIframe" src="" style="width: 100%; height: 400px;"></iframe>
  </div>
</div>

<script>
  // Obtener elementos del DOM
  var modal = document.getElementById("myModal");
  var btns = document.getElementsByClassName("openModal");
  var closeBtn = document.getElementsByClassName("close")[0];
  var iframe = document.getElementById("myIframe");
  var spinner = document.getElementById("spinner");

  // Función para abrir el modal y actualizar el iframe
  function openModal(url) {
    modal.style.display = "block";
    spinner.style.display = "block";
    iframe.style.display = "none";
    iframe.src = url;
  }

  // Función para cerrar el modal
  function closeModal() {
    modal.style.display = "none";
    spinner.style.display = "none";
    iframe.src = "";
  }

  // Asignar eventos a los botones
  for (var i = 0; i < btns.length; i++) {
    btns[i].addEventListener("click", function() {
      var url = this.getAttribute("data-url");
      openModal(url);
    });
  }

  closeBtn.addEventListener("click", closeModal);
  window.addEventListener("click", function(event) {
    if (event.target == modal) {
      closeModal();
    }
  });

  // Evento de carga completada del iframe
  iframe.addEventListener("load", function() {
    spinner.style.display = "none";
    iframe.style.display = "block";
  });
</script>
</body>

</html>
