added bitacora mesa
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
"use client";
|
||||
import SearchDate from "../SearchDate/SearchDate";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import axios from "axios";
|
||||
import { envConfig } from "@/app/lib/config";
|
||||
|
||||
interface tables {
|
||||
interface Tables {
|
||||
no_mesa: number;
|
||||
no_cuenta: number;
|
||||
hora_entrada: string;
|
||||
@@ -11,11 +14,29 @@ interface tables {
|
||||
}
|
||||
|
||||
function BitacoraMesas() {
|
||||
const [tables, setTables] = useState<tables[]>([]);
|
||||
const [tables, setTables] = useState<Tables[]>([]);
|
||||
const searchParams = useSearchParams();
|
||||
const date = searchParams.get("date");
|
||||
|
||||
useEffect(() => {
|
||||
if (!date) return;
|
||||
|
||||
axios.post(`${envConfig.apiUrl}/bitacora-mesa/mesas-por-dia`, {
|
||||
fecha: date,
|
||||
})
|
||||
.then(res => {
|
||||
setTables(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
}, [date]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SearchDate />
|
||||
|
||||
<div>
|
||||
<table>
|
||||
<thead>
|
||||
@@ -28,15 +49,23 @@ function BitacoraMesas() {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{tables.map((table, index) => (
|
||||
<tr key={index}>
|
||||
<td>{table.no_mesa}</td>
|
||||
<td>{table.no_cuenta}</td>
|
||||
<td>{table.hora_entrada}</td>
|
||||
<td>{table.tiempo_asignado}</td>
|
||||
<td>{table.hora_salida}</td>
|
||||
{tables.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={5} style={{ textAlign: "center" }}>
|
||||
No hubo mesas utilizadas en esta fecha
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
) : (
|
||||
tables.map((table, index) => (
|
||||
<tr key={index}>
|
||||
<td>{table.no_mesa}</td>
|
||||
<td>{table.no_cuenta}</td>
|
||||
<td>{new Date(table.hora_entrada).toLocaleString()}</td>
|
||||
<td>{table.tiempo_asignado}</td>
|
||||
<td>{new Date(table.hora_salida).toLocaleString()}</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -37,12 +37,13 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) {
|
||||
const [bitacora, setBitacora] = useState<any>(null);
|
||||
const [tiempoRestante, setTiempoRestante] = useState<string>("");
|
||||
const [minutos, setMinutos] = useState<number>();
|
||||
const [error, setError] = useState()
|
||||
|
||||
const fetchByCuenta = async (idCuenta: number) => {
|
||||
const result = await getEquipoByCount(idCuenta);
|
||||
|
||||
if (result?.error) {
|
||||
toast.error(result.error);
|
||||
setError(result.error);
|
||||
setBitacora(null);
|
||||
} else {
|
||||
setBitacora(result);
|
||||
@@ -53,7 +54,7 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) {
|
||||
const result = await getEquipoId(idEquipo);
|
||||
|
||||
if (result?.error) {
|
||||
toast.error(result.error);
|
||||
setError(result.error);
|
||||
setBitacora(null);
|
||||
} else {
|
||||
setBitacora(result);
|
||||
@@ -107,13 +108,13 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) {
|
||||
`${envConfig.apiUrl}/bitacora/cancelar/${bitacora.id_bitacora}`,
|
||||
{ tiempo_asignado: minutos },
|
||||
);
|
||||
|
||||
|
||||
toast.success("Tiempo cancelado");
|
||||
Swal.fire({
|
||||
title: "Tiempo cancelado!",
|
||||
icon: "success",
|
||||
draggable: true,
|
||||
});
|
||||
Swal.fire({
|
||||
title: "Tiempo cancelado!",
|
||||
icon: "success",
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
if (modo === "Cuenta" && numAcount) {
|
||||
fetchByCuenta(parseInt(numAcount));
|
||||
@@ -153,6 +154,8 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) {
|
||||
{modo === "Cuenta" && <SearchUser value={numAcount ?? null} />}
|
||||
{modo === "Equipo" && <SearchEquipo value={machine ?? null} />}
|
||||
|
||||
<h2 style={{marginTop:"10px"}}>{error}</h2>
|
||||
|
||||
{bitacora && (
|
||||
<>
|
||||
<Information
|
||||
|
||||
@@ -21,12 +21,13 @@ export default function CheckBoxMesa({ numAcount, table }: props) {
|
||||
const [bitacora, setBitacora] = useState<any>(null);
|
||||
const [tiempoRestante, setTiempoRestante] = useState<string>("");
|
||||
const [minutos, setMinutos] = useState<number>();
|
||||
const [error,setError]=useState()
|
||||
|
||||
const fetchByCuenta = async (idCuenta: number) => {
|
||||
const result = await getMesaByCount(idCuenta);
|
||||
|
||||
if (result?.error) {
|
||||
toast.error(result.error);
|
||||
setError(result.error);
|
||||
setBitacora(null);
|
||||
} else {
|
||||
setBitacora(result);
|
||||
@@ -37,7 +38,7 @@ export default function CheckBoxMesa({ numAcount, table }: props) {
|
||||
const result = await getTableByCount(idEquipo);
|
||||
|
||||
if (result?.error) {
|
||||
toast.error(result.error);
|
||||
setError(result.error);
|
||||
setBitacora(null);
|
||||
} else {
|
||||
setBitacora(result);
|
||||
@@ -137,6 +138,8 @@ export default function CheckBoxMesa({ numAcount, table }: props) {
|
||||
{modo === "Cuenta" && <SearchUser value={numAcount ?? null} />}
|
||||
{modo === "Mesa" && <SearchMesa />}
|
||||
|
||||
<h2 style={{marginTop:"10px"}}>{error}</h2>
|
||||
|
||||
{bitacora && (
|
||||
<>
|
||||
<Information
|
||||
|
||||
Reference in New Issue
Block a user