diff --git a/src/app/Inicio/layout.tsx b/src/app/Inicio/layout.tsx index f52dae6..309a9ce 100644 --- a/src/app/Inicio/layout.tsx +++ b/src/app/Inicio/layout.tsx @@ -1,46 +1,50 @@ -"use client" -import { deleteCookie, getCookie, processEnv } from '@/utils/cookies' -import { Inter } from 'next/font/google' -import Link from 'next/link' -import { usePathname } from 'next/navigation' -import { useEffect } from 'react' +"use client"; +import { deleteCookie, getCookie, processEnv } from "@/utils/cookies"; +import { Inter } from "next/font/google"; +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import { useEffect } from "react"; -const inter = Inter({ subsets: ['latin'] }) +const inter = Inter({ subsets: ["latin"] }); -interface PathInterface { -} +interface PathInterface {} export default function RootLayout({ children, }: { - children: React.ReactNode + children: React.ReactNode; }) { - - const pathNameActual = usePathname() + const pathNameActual = usePathname(); const styleselectbuttom = { - display: 'flex', - width: '47px', - height: '48px', - padding: '9px 8px 9px 9px', - flexShrink: '0', - borderRadius: '5px', - background: '#acacac', + display: "flex", + width: "47px", + height: "48px", + padding: "9px 8px 9px 9px", + flexShrink: "0", + borderRadius: "5px", + background: "#acacac", }; const pathNameSpliteado = () => { - const splitPath = pathNameActual.split("/") - return `/${splitPath[1]}${splitPath[2] ? `/${splitPath[2]}` : ''}` - } - const pathBusqueda = pathNameSpliteado() - const sectionactual = ["/Inicio", "/Inicio/routes", "/Inicio/employees", "/Inicio/vehicle", "/Inicio/court", "/Inicio/product"].indexOf(pathBusqueda) - - - - const handleSessionClose = ()=>{ + const splitPath = pathNameActual.split("/"); + return `/${splitPath[1]}${splitPath[2] ? `/${splitPath[2]}` : ""}`; + }; + const pathBusqueda = pathNameSpliteado(); + const sectionactual = [ + "/Inicio", + "/Inicio/routes", + "/Inicio/employees", + "/Inicio/vehicle", + "/Inicio/court", + "/Inicio/product", + ].indexOf(pathBusqueda); + + const handleSessionClose = () => { deleteCookie(processEnv.jtIdentity); - window.location.href = '/'; - } + window.location.href = "/"; + }; + // useEffect(() => { // getCookie(processEnv.name) // .catch(() => { @@ -49,71 +53,139 @@ export default function RootLayout({ // }, []) return ( -
+
- {/* Home */} - +
- - + +
{/* Rutas */} - +
- - + +
{/* Empleados */} - +
- - + +
{/* Unidades/Vehículos */} - +
- - + +
{/* Sistema de Corte */} - +
- - + +
{/* Productos */} - +
- - + +
-
- - +
+ +
- {children} - + {children}
- ) + ); } diff --git a/src/app/Inicio/sales/page.tsx b/src/app/Inicio/sales/page.tsx index 72f276c..c7541cc 100644 --- a/src/app/Inicio/sales/page.tsx +++ b/src/app/Inicio/sales/page.tsx @@ -1,74 +1,88 @@ -'use client' +"use client"; -import React, { useState, useEffect } from 'react' -import { getAllFetchDataValues } from '@/utils/api' -import { MessageProduct, RootProduct } from '@/types/product' -import { Table, SearchInput } from '@/components' -import Swal from 'sweetalert2' -import { ButtonCrud } from '@/components/buttons/ButtonCrud' +import React, { useState, useEffect } from "react"; +import { getAllFetchDataValues } from "@/utils/api"; +import { MessageProduct, RootProduct } from "@/types/product"; +import { Table, SearchInput } from "@/components"; +import Swal from "sweetalert2"; +import { ButtonCrud } from "@/components/buttons/ButtonCrud"; export default function Sales() { - const [products, setProducts] = useState() - const [clickInProduct, setClickInProduct] = useState() - const [search, setSearch] = useState('') + const [products, setProducts] = useState(); + const [clickInProduct, setClickInProduct] = useState(); + const [search, setSearch] = useState(""); const getProducts = async () => { - const products = await getAllFetchDataValues( - `${process.env.NEXT_PUBLIC_BACK_URL}products` - ) - setProducts(products) - } + const productsget = await getAllFetchDataValues( + `${process.env.NEXT_PUBLIC_BACK_URL}view-products` + ); + setProducts(productsget.details); + }; useEffect(() => { - getProducts() - }, []) + getProducts(); + }, []); - const filteredProducts = products?.message.filter(product => + const filteredProducts = products?.message.filter((product) => product.productName.toLowerCase().includes(search.toLowerCase()) - ) + ); function saleProduct() { if (!clickInProduct) { Swal.fire({ - icon: 'error', - title: 'Error al intentar hacer la compra', - text: 'Por favor seleccione un producto', + icon: "error", + title: "Error al intentar hacer la compra", + text: "Por favor seleccione un producto", toast: true, timer: 2500, - position: 'bottom-right', - background: '#a00', - color: '#fff', + position: "bottom-right", + background: "#a00", + color: "#fff", timerProgressBar: true, showConfirmButton: false, - }) + }); } - console.log(clickInProduct) + console.log(clickInProduct); } return ( <> -
-
-
-

Ventas

- Selecione los productos -
- -
- - - -
+
+
+
+

Ventas

+ Selecione los productos +
+
+ + + + +
+
+ className="flex flex-col pl-3 max-h-[100vh] h-full " + style={{ alignSelf: "flex-start" }} + > @@ -82,5 +96,5 @@ export default function Sales() { )}
- ) + ); } diff --git a/src/app/Inicio/vehicle/page.tsx b/src/app/Inicio/vehicle/page.tsx index 6a3de5b..9b3af6d 100644 --- a/src/app/Inicio/vehicle/page.tsx +++ b/src/app/Inicio/vehicle/page.tsx @@ -8,7 +8,7 @@ import { } from "@/utils/api"; import React, { FormEvent, useEffect, useRef, useState } from "react"; import Swal from "sweetalert2"; -import { ButtonCrud } from "@/components/buttons/ButtonCrud"; +import { ButtonCrud } from "@/components/buttons/ButtonCrud"; export default function Vehicle() { const [dataVehicle, setDataVehicle] = useState(null); @@ -28,16 +28,30 @@ export default function Vehicle() { const input_ultimoCambioAceite = useRef(null); const input_proximoCambioAceite = useRef(null); + // const getDaysDiference = (dateCurrent: string) => { + // const days: number = Math.floor( + // (new Date(dateCurrent).getTime() - actualTime.getTime()) / timeInDay + // ); + // return days == 0 + // ? "Hoy" + // : days < 0 + // ? `Hace ${Math.abs(days)} días` + // : `En ${days} días`; + // }; + const getDaysDiference = (dateCurrent: string) => { - const days: number = Math.floor( - (new Date(dateCurrent).getTime() - actualTime.getTime()) / timeInDay - ); - return days == 0 - ? "Hoy" - : days < 0 - ? `Hace ${Math.abs(days)} días` - : `En ${days} días`; - }; + const currentDate = new Date(dateCurrent); //FECHA EN UN OBJETO DATE + const differenceInDays = Math.floor((currentDate.getTime() - actualTime.getTime()) / timeInDay); //CALCULAR LA DIFERENCIA EN DIAS + + if(differenceInDays === 0){ + return 'Hoy'; + }else if (differenceInDays < 0){ + return `Hace ${Math.abs(differenceInDays)} dias(s)`; + }else{ + return `En ${(differenceInDays)} dias(s)`; + } + } + const updateTable = async () => { await getAllFetchDataValues( `${process.env.NEXT_PUBLIC_BACK_URL}cars-units` @@ -221,7 +235,7 @@ export default function Vehicle() {
-
+
@@ -251,20 +265,43 @@ export default function Vehicle() { setclickInVehicle(clickInVehicle != null ? null : data) } className={`bg-[linear-gradient(225deg,_#a1c4fd_10%,_#c2e9fb_90%)] - relative my-2 py-6 md:py-2 rounded-xl flex flex-col px-3 pl-5 gap-1 font-semibold hover:bg-slate-200 cursor-pointer ${clickInVehicle?._id == data._id ? "bg-[linear-gradient(225deg,_#acfca2_10%,_#c0faea_90%)]" : " md:bg-none"} - md:grid justify-items-center md:rounded-full overflow-hidden md:items-center`} + relative my-2 py-6 md:py-2 rounded-xl flex flex-col px-3 pl-5 gap-1 font-semibold hover:bg-slate-200 cursor-pointer ${ + clickInVehicle?._id == data._id + ? "bg-[linear-gradient(225deg,_#acfca2_10%,_#c0faea_90%)]" + : " md:bg-none" + } + md:grid justify-items-center md:rounded-full overflow-hidden md:items-center`} style={{ gridTemplateColumns: "50px 1fr 1fr 1fr 1fr" }} > - ID:{index} - Marca:{data.marca} - Modelo:{data.modelo} - Último cambio de aceite: + + ID: + {index} + + + Marca: + {data.marca} + + + Modelo: + {data.modelo} + + + + Último cambio de aceite: + {getDaysDiference(data.lastOilChange)} - Próximo cambio de aceite + + + Próximo cambio de aceite + {getDaysDiference(data.nextOilChange)} -

vehiculo

+ +

+ vehiculo +

+
) ) @@ -431,3 +468,7 @@ export default function Vehicle() { ); } +function getDate() { + throw new Error("Function not implemented."); +} + diff --git a/src/components/tables/Table.tsx b/src/components/tables/Table.tsx index 9f1d52a..04a02c7 100644 --- a/src/components/tables/Table.tsx +++ b/src/components/tables/Table.tsx @@ -25,7 +25,7 @@ export function Table({ { // @ts-ignore - products && + products.productIsSold && products?.map((data: MessageProduct, index: number) => (