<!--@Header-->
<?php

session_start();
if(isset($_SESSION['nomUsuario'])){
  
  $usuario = $_SESSION['nomUsuario'];
  $rol_usuario=$_SESSION['rolUsuario'];
  $id=$_SESSION['cveUsuario'];

  if($rol_usuario=="ADMINISTRADOR"){
    include("../usuario_administrador/path/header.php");
  }else {
    include("path/header.php");
  }
  $datos_notas = get_notas($rol_usuario,$id);
  $datos_productos = get_productos();
  $dato_usuarios=get_usuarios();
}else{
echo "<script> 
      document.location.href='/aqua-restaurant/';
  </script>";
}


?>

<div class="row">
  <div class="col-lg-12">
    <div class="row">
      <div class="col-md-12 mb-lg-0">
        <!--
        <div class="card-header pb-0 p-2">
          
          <div class="row">
            <div class="col-2">
              <i class="material-icons ms-auto text-dark cursor-pointer redondo-b" data-bs-toggle="tooltip" data-bs-placement="top" title="Cerrar"><img style="padding: 20%;" width="50" src="../assets/img/icons/cerrar.png"></i>
            </div>
            <div class="col-2">
              <i class="material-icons ms-auto text-dark cursor-pointer redondo-b" data-bs-toggle="tooltip" data-bs-placement="top" title="Refrescar"><img style="padding: 20%;" width="50" src="../assets/img/icons/refresh.png"></i>
            </div>
            <div class="col-2">
              <i class="material-icons ms-auto text-dark cursor-pointer redondo-b" type="button" data-bs-toggle="modal" data-bs-placement="top" title="Ver usuarios ON" data-bs-target="#modalUser"><img style="padding: 20%;" width="50" src="../assets/img/icons/user.png"></i>
            </div> 
            
            <div class="col-2">
              <a href="/aqua-restaurant/functions/salir.php"><i class="material-icons ms-auto text-dark cursor-pointer redondo-b" data-bs-toggle="tooltip" data-bs-placement="top" title="Cerrar Sesion"><img style="padding: 20%;" width="50" src="../assets/img/icons/sesion.png"></i></a>
            </div>
            <div class="col-4 d-flex mb-4 justify-content-center">
              <img width="130" src="../assets/img/logos/logo.png">
            </div>
          </div>
        </div>-->
        <div class="card mt-1">
          <div class="card-body p-1">
            <div class="row">
              <div class="col-md-4 mb-md-0 mb-4">
                <div class="card card-body card-plain border-radius-lg d-flex align-items-center flex-row">
                  <a href="nota_venta.php" hidden>
                    <i class="material-icons text-dark cursor-pointer redondo-g" data-bs-toggle="tooltip" data-bs-placement="top" title="Nueva nota de venta"><img style="padding: 20%;" width="50" src="../assets/img/icons/nota.png"></i>
                  </a>
                  <div class="row" >
                      <div id="content" class="col-lg-12">  
                          <div class="date" style="display: none;">
                              <span id="weekDay" class="weekDay"></span>, 
                              <span id="day" class="day"></span> de
                              <span id="month" class="month"></span> del
                              <span id="year" class="year"></span>
                          </div>
                          <div style="position: relative; left: 10px;" class="clock pt-1">
                              <span class="hours h4">Hora: </span>
                              <span id="hours" class="hours h4"></span> :
                              <span id="minutes" class="minutes h4"></span> :
                              <span id="seconds" class="seconds h4"></span>
                          </div>
                      </div>
                  </div>
                  <!-- <i class="material-icons ms-auto text-dark cursor-pointer redondo-g" type="button" data-bs-toggle="modal" data-bs-placement="top" title="Ver menu" data-bs-target="#Modal-2"><img style="padding: 20%;" width="50" src="../assets/img/icons/menu.png"></i> -->
                  <!--<i class="material-icons ms-auto text-dark cursor-pointer redondo-g" data-bs-toggle="tooltip" data-bs-placement="top" title="Edit Card"><img style="padding: 20%;" width="50" src="../assets/img/icons/salir_nota.png"></i>-->
                </div>
              </div>
              <div class="col-md-8 pt-3">
                <div class="card card-body card-plain d-flex justify-content-center flex-row text-center banner-titulo" style="  background: #052659; border-top-left-radius: 50px; border-bottom-left-radius: 50px; border-top-right-radius: 0; border-bottom-right-radius: 0; box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2);">
                  <h6 class="font-weight-bold mb-1 mt-1 text-white" style="font-size: 25px; line-height: 1;">Listado de nota de ventas</h6>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      
      <div class="col-12">
        <div class="card my-1">
          <div class="card-body px-0">
            <div class="table-responsive" style="max-height: 430px; overflow-y: auto;">
              <table class="table" id="tabla_notas">
                <thead style="background: #D5D8DC;">
                  <tr >
                    <th class="align-middle text-center" scope="col">#</th>
                    <th class="align-middle text-center" scope="col">Nota</th>
                    <th class="align-middle text-center" scope="col">Fecha</th>
                    <th class="align-middle text-center" scope="col">Último cambio</th>
                    <th class="align-middle text-center" scope="col">Estatus</th>
                    <th class="align-middle text-center" scope="col">M</th>
                    <th class="align-middle text-center" scope="col">C</th>
                    <th class="align-middle text-center" scope="col">P</th>
                    <th class="align-middle text-center" scope="col">Mesero</th>
                    <th class="align-middle text-center" scope="col">Edt</th>
                    <?php if($rol_usuario=="ADMINISTRADOR"){?>
                    <th class="align-middle text-center" scope="col">Elm</th>
                    
                    <!-- <th class="align-middle text-center" scope="col">Fin</th>-->
                    <?php } ?> 
                    <th class="align-middle text-center" scope="col">Imprimir</th>
                  </tr>
                </thead>
                <tbody class="tabla_notas_body" id="tbody_tabla_notas">
                <?php
                  
                  for($rr=0;$rr<count($datos_notas);$rr++){
                    if($datos_notas[$rr]["ESTATUS"]=="impreso"){

                ?>
                
                  <tr id="tr_notas">
                    <th class="align-middle text-center change_color_imp"> <?php echo $datos_notas[$rr]["ID"]?></th>
                    <td class="align-middle text-center change_color_imp"> <?php echo $datos_notas[$rr]["CLAVE"]?></td>
                    <td class="align-middle text-center change_color_imp"><?php echo $datos_notas[$rr]["FECHA"]?></td>
                    <td class="align-middle text-center change_color_imp"><?php echo $datos_notas[$rr]["ULTIMO_CAMBIO"]?></td>
                    <?php if ($datos_notas[$rr]["ESTATUS"]=="pagado") {?>
                      <td class="align-middle text-center change_color_imp change_color_status" style="font-weight: bold;"><?php echo $datos_notas[$rr]["ESTATUS"]?></td>
                    <?php } else{?>
                      <td class="align-middle text-center change_color_imp" ><?php echo $datos_notas[$rr]["ESTATUS"]?></td>
                    <?php }?>
                    <td class="align-middle text-center change_color_imp"><?php echo $datos_notas[$rr]["NO_MESA"]?></td>
                    <td class="align-middle text-center change_color_imp"><?php echo $datos_notas[$rr]["COMENSAL"]?></td>
                    <td class="align-middle text-center change_color_imp"><?php echo $datos_notas[$rr]["NO_PERSONAS"]?></td>
                    <td class="align-middle text-center change_color_imp"><?php echo $datos_notas[$rr]["NOMBRE"]?></td>
                    <td class="align-middle text-center change_color_imp">
                    <form action="editar_nota.php" method="post" id="formularioEditarNota">
                      <button class="badge badge-sm btn bg-gradient-info" type="submit" style="margin-bottom: 0;" value="<?php echo $datos_notas[$rr]['ID']?>"  name="boton_editar" id="boton_editar"><img width="20" src="../assets/img/icons/iconos-13.png" ></button>
                    </form>
                      
                    </td>
                     <?php if($rol_usuario=="ADMINISTRADOR"){?>
                    <td class="align-middle text-center change_color_imp">
                      <button type="button" data-bs-toggle="modal" data-bs-placement="top" title="Eliminar Nota" data-bs-target="#ModalEliminar" class="badge badge-sm btn bg-gradient-danger" name="boton_eliminar" data-id="<?php echo $datos_notas[$rr]['ID']?>"><img width="20" src="../assets/img/icons/eliminar.png" ></button>
                    </td>
                   <!--
                    <td class="align-middle text-center change_color_imp">
                        <button class="badge badge-sm btn bg-gradient-primary" type="button" data-bs-toggle="modal" data-bs-placement="top" title="Finalizar" data-bs-target="#ModalFinalizarNota" name="btn_finalizar" id="btn_finalizar" data-id="<?php echo $datos_notas[$rr]['ID']?>"><img width="20" src="../assets/img/icons/ok.png"></button>
                        
                    </td> -->
                    <?php } ?>
                    <td class="align-middle text-center change_color_imp">
                        <!--<form action="../ticket/ticket_nota_venta.php" method="post"></form>-->
                        <button class="badge badge-sm btn bg-gradient-success" type="button" data-bs-toggle="modal" data-bs-placement="top" title="Imprimir" data-bs-target="#ModalImprimir" name="boton_imprimir" id="boton_imprimir" data-id="<?php echo $datos_notas[$rr]['ID']?>"><img width="20" src="../assets/img/icons/impresion.png"></button>
                    </td>
                  </tr>
                  <?php
                    }else{
                  ?>
                  <tr id="tr_notas">
                    <th class="align-middle text-center"> <?php echo $datos_notas[$rr]["ID"]?></th>
                    <td class="align-middle text-center"> <?php echo $datos_notas[$rr]["CLAVE"]?></td>
                    <td class="align-middle text-center "><?php echo $datos_notas[$rr]["FECHA"]?></td>
                    <td class="align-middle text-center "><?php echo $datos_notas[$rr]["ULTIMO_CAMBIO"]?></td>
                    <?php if ($datos_notas[$rr]["ESTATUS"]=="pagado") {?>
                      <td class="align-middle text-center change_color_status" style=" font-weight: bold;"><?php echo $datos_notas[$rr]["ESTATUS"]?></td>
                    <?php } else{?>
                      <td class="align-middle text-center" ><?php echo $datos_notas[$rr]["ESTATUS"]?></td>
                    <?php }?>
                    <td class="align-middle text-center "><?php echo $datos_notas[$rr]["NO_MESA"]?></td>
                    <td class="align-middle text-center "><?php echo $datos_notas[$rr]["COMENSAL"]?></td>
                    <td class="align-middle text-center "><?php echo $datos_notas[$rr]["NO_PERSONAS"]?></td>
                    <td class="align-middle text-center "><?php echo $datos_notas[$rr]["NOMBRE"]?></td>
                    <td class="align-middle text-center ">
                    <form action="editar_nota.php" method="post" id="formularioEditarNota">
                      <button class="badge badge-sm btn bg-gradient-info" type="submit" style="margin-bottom: 0;" value="<?php echo $datos_notas[$rr]['ID']?>"  name="boton_editar" id="boton_editar"><img width="20" src="../assets/img/icons/iconos-13.png" ></button>
                    </form>
                      
                    </td>
                     <?php if($rol_usuario=="ADMINISTRADOR"){?>
                    <td class="align-middle text-center ">
                      <button type="button" data-bs-toggle="modal" data-bs-placement="top" title="Eliminar Nota" data-bs-target="#ModalEliminar" class="badge badge-sm btn bg-gradient-danger" name="boton_eliminar" data-id="<?php echo $datos_notas[$rr]['ID']?>"><img width="20" src="../assets/img/icons/eliminar.png" ></button>
                    </td>
                   <!--
                    <td class="align-middle text-center ">
                        <button class="badge badge-sm btn bg-gradient-primary" type="button" data-bs-toggle="modal" data-bs-placement="top" title="Finalizar" data-bs-target="#ModalFinalizarNota" name="btn_finalizar" id="btn_finalizar" data-id="<?php echo $datos_notas[$rr]['ID']?>"><img width="20" src="../assets/img/icons/ok.png"></button>
                        
                    </td>-->
                    <?php } ?> 
                    <td class="align-middle text-center ">
                        <button class="badge badge-sm btn bg-gradient-success" type="button" data-bs-toggle="modal" data-bs-placement="top" title="Imprimir" data-bs-target="#ModalImprimir" name="boton_imprimir" id="boton_imprimir" data-id="<?php echo $datos_notas[$rr]['ID']?>"><img width="20" src="../assets/img/icons/impresion.png"></button>
                    </td>
                  </tr>
                  <?php
                      }
                    }
                  ?>
                </tbody>
              </table>
            </div>
          </div>

        </div>
      </div>

    </div>
  </div>
  <!--<div class="col-lg-4">
          <div class="card h-100">
            <div class="card-header pb-0 p-3">
              <div class="row">
                <div class="col-6 d-flex align-items-center">
                  <h6 class="mb-0">Invoices</h6>
                </div>
                <div class="col-6 text-end">
                  <button class="btn btn-outline-primary btn-sm mb-0">View All</button>
                </div>
              </div>
            </div>
            <div class="card-body p-3 pb-0">
              <ul class="list-group">
                <li class="list-group-item border-0 d-flex justify-content-between ps-0 mb-2 border-radius-lg">
                  <div class="d-flex flex-column">
                    <h6 class="mb-1 text-dark font-weight-bold text-sm">March, 01, 2020</h6>
                    <span class="text-xs">#MS-415646</span>
                  </div>
                  <div class="d-flex align-items-center text-sm">
                    $180
                    <button class="btn btn-link text-dark text-sm mb-0 px-0 ms-4"><i class="material-icons text-lg position-relative me-1">picture_as_pdf</i> PDF</button>
                  </div>
                </li>
                <li class="list-group-item border-0 d-flex justify-content-between ps-0 mb-2 border-radius-lg">
                  <div class="d-flex flex-column">
                    <h6 class="text-dark mb-1 font-weight-bold text-sm">February, 10, 2021</h6>
                    <span class="text-xs">#RV-126749</span>
                  </div>
                  <div class="d-flex align-items-center text-sm">
                    $250
                    <button class="btn btn-link text-dark text-sm mb-0 px-0 ms-4"><i class="material-icons text-lg position-relative me-1">picture_as_pdf</i> PDF</button>
                  </div>
                </li>
                <li class="list-group-item border-0 d-flex justify-content-between ps-0 mb-2 border-radius-lg">
                  <div class="d-flex flex-column">
                    <h6 class="text-dark mb-1 font-weight-bold text-sm">April, 05, 2020</h6>
                    <span class="text-xs">#FB-212562</span>
                  </div>
                  <div class="d-flex align-items-center text-sm">
                    $560
                    <button class="btn btn-link text-dark text-sm mb-0 px-0 ms-4"><i class="material-icons text-lg position-relative me-1">picture_as_pdf</i> PDF</button>
                  </div>
                </li>
                <li class="list-group-item border-0 d-flex justify-content-between ps-0 mb-2 border-radius-lg">
                  <div class="d-flex flex-column">
                    <h6 class="text-dark mb-1 font-weight-bold text-sm">June, 25, 2019</h6>
                    <span class="text-xs">#QW-103578</span>
                  </div>
                  <div class="d-flex align-items-center text-sm">
                    $120
                    <button class="btn btn-link text-dark text-sm mb-0 px-0 ms-4"><i class="material-icons text-lg position-relative me-1">picture_as_pdf</i> PDF</button>
                  </div>
                </li>
                <li class="list-group-item border-0 d-flex justify-content-between ps-0 border-radius-lg">
                  <div class="d-flex flex-column">
                    <h6 class="text-dark mb-1 font-weight-bold text-sm">March, 01, 2019</h6>
                    <span class="text-xs">#AR-803481</span>
                  </div>
                  <div class="d-flex align-items-center text-sm">
                    $300
                    <button class="btn btn-link text-dark text-sm mb-0 px-0 ms-4"><i class="material-icons text-lg position-relative me-1">picture_as_pdf</i> PDF</button>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </div>-->
</div>

<!-- Modal Usuarios -->
<div class="modal fade" id="modalUser" tabindex="-1" aria-labelledby="modalUserLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalUserLabel">Usuarios Activos</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="card h-100">
          <div class="card-header pb-0 p-3">
            <div class="row">
              <div class="col-6 d-flex align-items-center">
                <h6 class="mb-0">Usuario:</h6>
              </div>
            </div>
          </div>
          <div class="card-body p-3 pb-0">
            <ul class="list-group">
              <?php
                for($rr=0;$rr<count($dato_usuarios);$rr++){
              ?>
              <li class="list-group-item border-0 d-flex justify-content-between ps-0 mb-2 border-radius-lg">
                <div class="d-flex flex-column">
                  <h6 class="mb-1 text-dark font-weight-bold text-sm"><?php echo $dato_usuarios[$rr]['NOMBRE']?></h6>
                </div>
              </li>
              <?php
                }
              ?>
              
            </ul>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal 2-->
<div class="modal fade" id="Modal-2" tabindex="-1" aria-labelledby="Modal-2Label" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="Modal-2Label">Ver carta</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-sm-10">
            <div class="ms-md-auto pe-md-3 d-flex align-items-center">
              <div class="input-group input-group-outline ">
                <label class="form-label">Buscador...</label>
                <input type="text" class="form-control" id="caja_buscar_producto1">
              </div>
            </div>
          </div>
          <div class="col-sm-2">
            <button type="button" class="btn btn-primary" style="padding-top: 5px; padding-bottom: 6px;"><img width="15" src="../assets/img/icons/buscar.png"></button>
          </div>
        </div>
        <div class="table-responsive pt-2">
          <div id="modal_2"></div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal 3-->
<div class="modal fade" id="ModalPago" tabindex="-1" aria-labelledby="ModalPagoLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="ModalPagoLabel">Tipo de Pago</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="card h-100">
          <div class="card-header pb-0 p-3">
            <div class="row">
              <div class="col-12 d-flex align-items-center">
                <h6 class="mb-0">Selecciona el tipo de pago:</h6>
              </div>
            </div>
          </div>
          <div class="card-body p-3 pb-0">
            <div class="form-check pt-1">
              <input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault3" checked>
              <label class="form-check-label" for="flexRadioDefault3">
                Efectivo
              </label>
            </div>
            <div class="form-check pt-1">
              <input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault2">
              <label class="form-check-label" for="flexRadioDefault2">
                Tarjeta de Credito
              </label>
            </div>
            <div class="form-check pt-1">
              <input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault1" onChange="comprobar(this);">
              <label class="form-check-label" for="flexRadioDefault1">
                Ambas
              </label>
              <br>
              <label class="form-check-label" for="efectivo">
                Efectivo:
              </label>
              <input class="form-control" type="text" name="efectivo" id="efectivo" style="display:none; border-color: #8d7662;" />
              <br>
              <label class="form-check-label" for="tarjeta">
                Tarjeta:
              </label>
              <input class="form-control" type="text" name="tarjeta" id="tarjeta" style="display:none; border-color: #8d7662;" />

            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
        <button type="button" class="btn btn-primary">Ok</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal 4 -->
<div class="modal fade" id="Modal-4" tabindex="-1" aria-labelledby="Modal-4Label" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="Modal-4Label">¡La nota <strong id="no_nota"></strong> ha sido exitosamente finalizada!</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-sm-10">
            <div class="ms-md-auto pe-md-3 d-flex align-items-center">
              <div class="row">
                <div class="col-2"> <h6>Fecha: </h6 ></div>
                <div class="col-4"><h6 id="fecha_creacion_nota"></h6 ></div>
                <div class="col-4"><h6>Hora final de edicion: </h6 ></div>
                <div class="col-2"><h6 id="hora_final_nota"></h6 ></div>
                <div class="col-4"><h6 > Numero de personas: </h6 ></div>
                <div class="col-2"><h6 id="num_personas"></h6 ></div>
                <div class="col-4"><h6 > Numero de mesa: </h6 ></div>
                <div class="col-2"><h6 id="num_mesa"></h6 ></div>
                <div class="col-4"><h6 > Tipo de pago: </h6 ></div>
                <div class="col-6"><h6 id="tipo_pago"></h6 ></div>
              </div>
            </div>
          </div>
        </div>
      </div>
      
    </div>
  </div>
</div>
<!-- Modal Eliminar Nota -->
<div class="modal fade" id="ModalFinalizarNota" tabindex="-1" aria-labelledby="ModalFinalizarNotaLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h3 class="modal-title" id="ModalFinalizarNotaLabel">FINALIZAR NOTA <strong id="clave_nota"></strong></h3>
        
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-sm-10">
            <div class="ms-md-auto">
              <div class="row">
                <div class="col-10">
                  <h5>¿Estas seguro de finalizar la nota <strong id="clave_nota_venta"></strong>?</h5>
                </div>
                <div class="col-2">
                  <h5>Mesa: <strong id="mesa_nota_venta"></strong></h5>
                </div>
              </div>
              <br>
              <div class="row">
                <div class="col-10">
                  <h5>Personas: <strong id="presonas_nota_venta"></strong></h5>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
        <button type="button" class="btn btn-primary" id="btn_finalizar_nota" onclick="confirmarFinalizacion()">Finalizar</button>
      </div>
    </div>
  </div>
</div>
<!-- Modal Eliminar Nota -->
<div class="modal fade" id="ModalEliminar" tabindex="-1" aria-labelledby="ModalEliminarLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="ModalEliminarLabel">ELIMINAR NOTA</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-sm-10">
            <div class="ms-md-auto pe-md-3 d-flex align-items-center">
              <div class="input-group input-group-outline ">
                <h3>¿Estas seguro de eliminar la nota?</h3>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
        <button type="button" class="btn btn-danger" id="btn_eliminar_nota" onclick="confirmarEliminacion()">Eliminar</button>
      </div>
    </div>
  </div>
</div>
<!-- Modal Imprimir Nota -->
<div class="modal fade" id="ModalImprimir" tabindex="-1" aria-labelledby="ModalImprimirLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
       
        <h5 class="modal-title" id="ModalImprimirLabel">NOTA: <strong id="clv_nota_im"></strong></h5>

        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="card h-50">
            <div class="card-header">
              <div class="row">
                <div class="col-12 d-flex align-items-center">
                  <h6 class="mb-0">Datos de la nota:</h6>
                </div>
              </div>
            </div>
            <div class="card-body p-3 pb-0">
              <div class="row">
                <div class="col-8">
                  <h8 >Clave de la nota: </h8><h8 id="clv_nota_venta_im"></h8>
                </div>
                <div class="col-4">
                  <h8 for="" >Mesa: </h8> <h8 id="msa_im"></h8>
                </div>
              </div>
              <br>
              <div class="row">
                <div class="col-8">
                  <h8 for=""> Total a pagar: </h8><h8 id="total_im" data-value=''></h8>
                </div>
                <div class="col-4">
                  <h8 for="">Mesero: </h8><h8 id="mesero"></h8>
                </div>
              </div>
            </div>
          </div>
          <div class="card h-100">
            <div class="card-header pb-0 p-3">
              <div class="row">
                <div class="col-12 d-flex align-items-center">
                  <h6 class="mb-0">Selecciona el metodo de pago:</h6>
                </div>
              </div>
            </div>
            <div class="card-body pt-2 align-items-center">
              <div class="form-check pt-4 pb-4" style="display: inline; border: 1px solid #d5d8dc; border-radius: 10px; padding-left: 1rem; padding-right: 1rem; background-color: #aed6f1;">
                <input class="form-check-input" type="radio" name="flexRadioDefault1" id="flexRadioDefault6" checked>
                <label class="form-check-label pt-3 pb-3" style="padding-right: 2rem" for="flexRadioDefault6">
                  <p style="font-size: 18px;"><b>Tarjeta de credito</b></p>
                </label>
              </div>
              <div class="form-check pt-4 pb-4" style="display: inline; border: 1px solid #d5d8dc; border-radius: 10px; padding-left: 1rem; padding-right: 1rem; background-color: #edbb99 ;">
                <input class="form-check-input" type="radio" name="flexRadioDefault1" id="flexRadioDefault5">
                <label class="form-check-label pt-3 pb-3" style="padding-right: 3rem" for="flexRadioDefault5">
                  <p style="font-size: 18px;"><b>Efectivo</b></p>
                </label>
              </div>
              <div class="form-check pt-4 pb-4" style="display: inline; border: 1px solid #d5d8dc; border-radius: 10px; padding-left: 1rem; padding-right: 1rem; background-color: #82e0aa;">
                <input class="form-check-input" type="radio" name="flexRadioDefault1" id="flexRadioDefault4">
                <label class="form-check-label pt-3 pb-3" style="padding-right: 3rem" for="flexRadioDefault4">
                  <p style="font-size: 18px;"><b>AMBOS</b></p>
                </label>
              </div>
            </div>
          </div>
          <div id="pago_efec_tarj"></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="btn_imprimir_nota" onclick="elegirTipoPago()">Finalizar</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal Imprimir Nota -->
<div class="modal fade" id="ModalImprimir2" tabindex="-1" aria-labelledby="ModalImprimir2Label" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
       
        <h5 class="modal-title" id="ModalImprimir2Label">NOTA: <strong id="clv_nota_im"></strong></h5>

        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
          <div class="card h-100">
            <div class="card-header pb-0 p-3">
              <div class="row">
                <div class="col-12 d-flex align-items-center">
                  <h6 class="mb-0">Selecciona la impresora:</h6>
                </div>
              </div>
            </div>
            <div class="card-body p-3 pb-0">
              <div class="form-check pt-1">
                <input class="form-check-input" type="radio" name="flexRadioDefault3" id="flexRadioDefault17" checked>
                <label class="form-check-label" for="flexRadioDefault17">
                  EPSON-TM-T20II
                </label>
              </div>
              <div class="form-check pt-1">
                <input class="form-check-input" type="radio" name="flexRadioDefault3" id="flexRadioDefault18">
                <label class="form-check-label" for="flexRadioDefault18">
                  BIXOLON-SRP-350plusIII
                </label>
              </div>
              <div class="form-check pt-1">
                <input class="form-check-input" type="radio" name="flexRadioDefault3" id="flexRadioDefault21">
                <label class="form-check-label" for="flexRadioDefault21">
                  PDF
                </label>
              </div>
            </div>
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
        <button type="button" class="btn btn-primary" id="btn_imprimir_nota" onclick="imprimir()">Imprimir</button>
      </div>
    </div>
  </div>
</div>
<!-- Modal NOTA NO PAGADA -->
<div class="modal fade" id="ModalNoFinalizadaNota" tabindex="-1" aria-labelledby="ModalNoFinalizadaNota" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="ModalNoFinalizadaNota">NO SE PUEDE REALIZAR LA ACCION</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-sm-10">
            <div class="ms-md-auto pe-md-3 d-flex align-items-center">
              <div class="input-group input-group-outline ">
                <h3>No se puede finalizar una nota que no ha sido pagada</h3>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal Faltan DINERO PARA PROCESAR EL PAGO -->
<div class="modal fade" id="modalErrProcesarPago" tabindex="-1" aria-labelledby="modalErrProcesarPago" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalErrProcesarPago">NO SE PUEDE COMPLETAR EL PAGO</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
      
        <div class="row">
          <div class="col-10 d-flex align-items-center">
            <h6 class="mb-0">Revisa que la suma de las cantidades sea la misma que el total </h6>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
      </div>
    </div>
  </div>
</div>
<!-- Modal Faltan DINERO PARA PROCESAR EL PAGO -->
<div class="modal fade" id="modalProcesarPagoExitoso" tabindex="-1" aria-labelledby="modalProcesarPagoExitoso" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalProcesarPagoExitoso">SE HA COMPLETADO EL PAGO</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
      
        <div class="row">
          <div class="col-10 d-flex align-items-center">
            <h6 class="mb-0">¡El pago ha sido realizado!</h6>
          </div>
        </div>
      </div>
     
    </div>
  </div>
</div>
<!-- Modal Faltan Productos en la nota -->
<div class="modal fade" id="modalFalloProductosNota" tabindex="-1" aria-labelledby="modalFalloProductosNota" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalFalloProductosNota"> FALLO AL IMPRIMIR LA NOTA</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
      
        <div class="row">
          <div class="col-10 d-flex align-items-center">
            <h6 class="mb-0">¡La nota no ha podido ser generada debido a que no cuenta con los datos suficientes para procesar el pago!</h6>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
      </div>
    </div>
    
  </div>
</div>
<script src="../assets/js/jquery-3.5.1.min.js"></script>
<script src="../assets/js/clock.js"></script>

<script>
  function comprobar(obj) {
    if (obj.checked) {

      document.getElementById('efectivo').style.display = "";
      document.getElementById('tarjeta').style.display = "";

    } else {

      document.getElementById('efectivo').style.display = "none";
      document.getElementById('tarjeta').style.display = "none";
    }

  }
</script>

<script>
  
$(ver_menu());
  $(document).on('keyup','#caja_buscar_producto1', function(){
    var valor = $(this).val();
    if(valor != ""){
        ver_menu(valor);
    }else{
        ver_menu();
    }
});

function ver_menu(consulta){
    $.ajax({
        data: {consulta: consulta},
        url: '../functions/modal_2.php',
        type: 'post',
        dataType:'html',
        success:  function (response) {
            $('#modal_2').html(response);
        },
        error: function (error) {
            console.log(error); 
        }
    });

}
$(document).ready(function() {
  $('#ModalEliminar').on('show.bs.modal', function(e) {
    var button = $(e.relatedTarget); // Botón que activó el modal
    var id = button.data('id'); // ID del registro correspondiente
    var modal = $(this);
    modal.find('#btn_eliminar_nota').data('id', id); // Asignar ID al botón de eliminar en el modal
  });

  $('#ModalImprimir').on('show.bs.modal', function(e) {
    var button = $(e.relatedTarget); // Botón que activó el modal
    var id = button.data('id'); // ID del registro correspondiente
    var modal = $(this);
    modal.find('#btn_imprimir_nota').data('id', id); // Asignar ID al botón de imprimir en el modal


    $.ajax({
        data: {id_nota: id},
        url: '../functions/finalizar_nota_1.php',
        type: 'GET',
        dataType: 'json',
        success:  function (data) {
          if (data.clave_nota) {
            $('#clv_nota_im').text(data.clave_nota);
            $('#clv_nota_venta_im').text(data.clave_nota);
            $('#mesero').text(data.uss_nombre);
            $('#msa_im').text(data.no_mesa);
            $('#total_im').text('$'+data.total_nota);
            $('#total_im').attr('data-value',(data.total_nota));
          }
          
        },
        error: function (error) {
          console.log(error); 
         
        }
    });
  });

  $('#ModalFinalizarNota').on('show.bs.modal', function(e) {
    var button = $(e.relatedTarget); // Botón que activó el modal
    var id = button.data('id'); // ID del registro correspondiente
    var modal = $(this);
    modal.find('#btn_finalizar_nota').data('id', id); // Asignar ID al botón de eliminar en el modal
    

    $.ajax({
        data: {id_nota: id},
        url: '../functions/finalizar_nota_1.php',
        type: 'GET',
        dataType: 'json',
        success:  function (data) {
          //mesa_nota_venta presonas_nota_venta
          if (data.clave_nota) {
            $('#clave_nota_venta').text(data.clave_nota);
            $('#clave_nota').text(data.clave_nota);
            $('#mesa_nota_venta').text(data.no_mesa);
            $('#presonas_nota_venta').text(data.no_personas);
          }
          
        },
        error: function (error) {
          console.log(error); 
         
        }
    });
  });
  
  $('#flexRadioDefault4').on('change', function(){
    $('#pago_efec_tarj').load('../functions/pagos_efec_tarj.php');
  });
  $('#flexRadioDefault5').on('change', function(){
    $('#pago_efec_tarj').empty();
  });
  $('#flexRadioDefault6').on('change', function(){
    $('#pago_efec_tarj').empty();
  });
  
  
});

function confirmarFinalizacion(){
  var modal = document.getElementById("ModalFinalizarNota");
  var id_nota = $(modal).find('#btn_finalizar_nota').data('id'); // Obtener ID del botón de eliminar en el modal
  $('#ModalFinalizarNota').modal('toggle'); 
  //console.log(id_nota);
  
  
  $.ajax({
        data: {id_nota: id_nota},
        url: '../functions/finalizar_nota.php',
        type: 'GET',
        dataType: 'json',
        success:  function (data) {
          console.log(data);
          
          if (data.clave_nota) {
            $('#Modal-4').modal('show'); 
            $('#no_nota').text(data.clave_nota);
            $('#fecha_creacion_nota').text(data.fecha_creacion_nota);
            $('#hora_final_nota').text(data.hora_edt_nota);
            $('#num_personas').text(data.no_personas);
            $('#num_mesa').text(data.no_mesa);
            $('#tipo_pago').text(data.tipo_pago);
            
            setTimeout(function() {
              $('#Modal-4').modal('toggle'); 
              location.href='/aqua-restaurant/usuario_mesero/notas_de_venta.php';
            }, 5000);
          } else {
            $('#ModalNoFinalizadaNota').modal('show'); 
          }
        
        },
        error: function (error) {
          console.log(error); 
         
        }
    });
}
$(document).ready(function() {
  var tipo_pago = 0;
  var pago_total_tarjeta =0;
  var pago_total_efectivo=0;
  var id_nota ;
  var imp=0;
});

function confirmarEliminacion() {
  var modal = document.getElementById("ModalEliminar");
  var id = $(modal).find('#btn_eliminar_nota').data('id'); // Obtener ID del botón de eliminar en el modal

  $.ajax({
        data: {id: id},
        url: '../functions/eliminar_nota.php',
        type: 'post',
        success:  function (response) {
          location.href='/aqua-restaurant/usuario_mesero/notas_de_venta.php';
        },
        error: function (error) {
            console.log(error); 
        }
    });
}

function elegirTipoPago(){
  var modal = document.getElementById("ModalImprimir");
  id_nota = $(modal).find('#btn_imprimir_nota').data('id'); // Obtener ID del botón de eliminar en el modal

  if($('#flexRadioDefault6').is(':checked')){
    tipo_pago = 1;
    pago_total_tarjeta =0;
    pago_total_efectivo=0;
  }

  if($('#flexRadioDefault5').is(':checked')){
    tipo_pago = 2;
    pago_total_tarjeta =0;
    pago_total_efectivo=0;
  }

  if($('#flexRadioDefault4').is(':checked')){
    pago_total_tarjeta = document.getElementById('pago_total_tarjeta').value;
    pago_total_efectivo = document.getElementById('pago_total_efectivo').value;
    tipo_pago = 3;
  }
  //$('#ModalImprimir').modal('toggle');
  
  console.log(tipo_pago);
  console.log('Imprimiendo...');
  if($('#flexRadioDefault4').is(':checked')){
    //console.log();
    var tarjeta = parseInt(document.getElementById('pago_total_tarjeta').value);
    var efectivo = parseInt(document.getElementById('pago_total_efectivo').value);
    var suma_pago = tarjeta + efectivo;
    var total = parseInt($("#total_im").attr('data-value'));
    //console.log(suma_pago);
    var datos2 = {
        "tipo_pago": tipo_pago, 
        "id_nota": id_nota,  
        "pago_total_efectivo":pago_total_efectivo,
        "pago_total_tarjeta":pago_total_tarjeta,
      };
    if (suma_pago>=total) {
      terminar_nota(datos2);
    } else {
      $('#ModalImprimir').modal('toggle'); 
      $('#modalErrProcesarPago').modal('show'); 
    }
      
  }else{
    if($('#flexRadioDefault5').is(':checked') || $('#flexRadioDefault6').is(':checked')){
      var datos2 = {
        "tipo_pago": tipo_pago, 
        "id_nota": id_nota,  
        "pago_total_efectivo":pago_total_efectivo,
        "pago_total_tarjeta":pago_total_tarjeta,
      };
      terminar_nota(datos2)
        
    }
  }
 ///////////////////////////////////////////////////////////////////////////
 /*
  */
  ///////////////////////////////////////////////////////////////////////////
      /*
  
    */
}


function imprimir(){
  
  console.log(tipo_pago);
  console.log('Imprimiendo...');
  if($('#flexRadioDefault4').is(':checked')){
    //console.log();
    var tarjeta = parseInt(document.getElementById('pago_total_tarjeta').value);
    var efectivo = parseInt(document.getElementById('pago_total_efectivo').value);
    var suma_pago = tarjeta + efectivo;
    var total = parseInt($("#total_im").attr('data-value'));
    //console.log(suma_pago);
    var datos2 = {
        "tipo_pago": tipo_pago, 
        "id_nota": id_nota,  
        "pago_total_efectivo":pago_total_efectivo,
        "pago_total_tarjeta":pago_total_tarjeta,
      };
    if (suma_pago>=total) {
      terminar_nota(datos2);
    } else {
      $('#ModalImprimir').modal('toggle'); 
      $('#modalErrProcesarPago').modal('show'); 
    }
      
  }else{
    if($('#flexRadioDefault5').is(':checked') || $('#flexRadioDefault6').is(':checked')){
      var datos2 = {
        "tipo_pago": tipo_pago, 
        "id_nota": id_nota,  
        "pago_total_efectivo":pago_total_efectivo,
        "pago_total_tarjeta":pago_total_tarjeta,
      };
      terminar_nota(datos2)
        
    }
  }
 
  //console.log(pago_total_tarjeta);
   /*
  if($('#flexRadioDefault17').is(':checked')){
    tipo =3;
    imp=11;
    impresora = "smb://xolotl-work:12345678@DESKTOP-GBG920T/BIXOLON-SRP-350plusIII";
  }
  if($('#flexRadioDefault18').is(':checked')){
    
    tipo =3;
    imp=12;
    impresora = "EPSON-TM-T20II";
  }
  if($('#flexRadioDefault19').is(':checked')){
    tipo =3;
    imp=13;
    impresora = "smb://CABANITA:1234@Micabanita2/BIXOLON-SRP-F312";
  }
  if($('#flexRadioDefault20').is(':checked')){
    tipo =3;
    imp=14;
    impresora = "cocina";
  }
  if($('#flexRadioDefault21').is(':checked')){
    tipo =3;
    imp=15;
    impresora = "local";
  }
  
  
  if($('#flexRadioDefault4').is(':checked')){
    //console.log();
    var tarjeta = parseInt(document.getElementById('pago_total_tarjeta').value);
    var efectivo = parseInt(document.getElementById('pago_total_efectivo').value);
    var suma_pago = tarjeta + efectivo;
    var total = parseInt($("#total_im").attr('data-value'));
    console.log(suma_pago);
    
    if (suma_pago>=total) {
      //terminar_nota(datos2);
    } else {
      $('#ModalImprimir').modal('toggle'); 
      $('#modalErrProcesarPago').modal('show'); 
    }
      
  }
  if (imp == 11||imp == 12||imp == 13) {
    var datos2 = {
        "tipo_pago": tipo_pago, 
        "id_nota": id_nota,  
        "pago_total_efectivo":pago_total_efectivo,
        "pago_total_tarjeta":pago_total_tarjeta,
        "opcionImprComanda":impresora,
      };
      
    terminar_cuenta_red(datos2);
  }
  if (imp == 15) {
    var datos2 = {
        "tipo_pago": tipo_pago, 
        "id_nota": id_nota,  
        "pago_total_efectivo":pago_total_efectivo,
        "pago_total_tarjeta":pago_total_tarjeta,
      };
      terminar_nota(datos2);
  }*/
}
function terminar_nota(datos2){
  
  $.ajax({
        data: datos2,
        url: '../functions/terminar_nota_1.php',
        type: 'post',
        success:  function (response) {
          console.log(response);
          if(response==1){
            location.href ="/aqua-restaurant/usuario_mesero/notas_de_venta.php";
          }else{
            
            $('#ModalImprimir').modal('toggle');
            $('#modalFalloProductosNota').modal('show');
          }
          
        },
        error: function (error) {
            console.log(error); 
        }
      });
}
function terminar_cuenta_red(datos2){
  
    console.log(imp);
      $.ajax({
        data: datos2,
        url: '../ticket/ticket_nota_venta_red_2.php',
        type: 'post',
        success:  function (response) {
          console.log(response);
          if(response==0){
            $('#ModalImprimir2').modal('toggle');
            $('#modalFalloProductosNota').modal('show');
          }
          
        },
        error: function (error) {
            console.log(error); 
        }
      });
    }

</script>
<!--
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js"></script>
<script>
  $(document).ready(function () {
      $('#tabla_notas').DataTable();
  });
</script>-->

<!--@Footer-->
<?php
include("path/footer.php");
?>