diff --git a/distoq-capstonem3/src/components/dashboard-components/ComprasPage/ComprasCard/index.jsx b/distoq-capstonem3/src/components/dashboard-components/ComprasPage/ComprasCard/index.jsx index 0291577..86a23be 100644 --- a/distoq-capstonem3/src/components/dashboard-components/ComprasPage/ComprasCard/index.jsx +++ b/distoq-capstonem3/src/components/dashboard-components/ComprasPage/ComprasCard/index.jsx @@ -16,7 +16,8 @@ import { useStockList } from "../../../../Providers/Stock"; export const CardCompras = ({ order, getOrdersList, setOrdersList, token }) => { const { id, providerData, quantity, status, supplyData, totalValue } = order; const [selectValue, setSelectValue] = useState(""); - const { getListStock } = useStockList(); + const { stockList, getListStock } = useStockList(); + return ( { }); if (e.target.value === "Finalizado") { - api - .post( - "/stock", - { - ...order, - ownerId: 1, - userId: 1, - }, - { - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, - }, - } + console.log(stockList); + console.log(supplyData); + console.log(order); + + if ( + stockList.some( + (ele) => ele.supplyData.name === supplyData.name ) - .then((res) => { - getListStock(); - }); + ) { + const itemInStock = stockList.filter( + (ele) => ele.supplyData.name === supplyData.name + ); + + console.log(itemInStock); + console.log(itemInStock[0].id); + + api + .patch( + `/stock/${itemInStock[0].id}`, + { + ...itemInStock[0], + quantity: +itemInStock[0].quantity + +order.quantity, + }, + { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + } + ) + .then((rep) => { + getOrdersList(); + }); + } else { + api + .post( + "/stock", + { + ...order, + ownerId: 1, + userId: 1, + }, + { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + } + ) + .then((res) => { + getListStock(); + }); + } } + setSelectValue(e.target.value); }} > diff --git a/distoq-capstonem3/src/components/dashboard-components/DashboardPage/index.jsx b/distoq-capstonem3/src/components/dashboard-components/DashboardPage/index.jsx index bcc0695..1e6858e 100644 --- a/distoq-capstonem3/src/components/dashboard-components/DashboardPage/index.jsx +++ b/distoq-capstonem3/src/components/dashboard-components/DashboardPage/index.jsx @@ -2,16 +2,13 @@ import { Box, Flex, Heading, - Stack, Text, useRadio, useRadioGroup, VStack, } from "@chakra-ui/react"; import { motion } from "framer-motion"; -import { GoSearch } from "react-icons/go"; import { useActivePage } from "../../../Providers/DashboardPageController"; -import { useUser } from "../../../Providers/Users"; import AOS from "aos"; import "aos/dist/aos.css"; import Example from "../../lottie/lottie"; @@ -20,7 +17,7 @@ AOS.init(); export const DashboardPage = () => { const { activeDashboardPage, setActiveDashboardPage, handleIcons, options } = useActivePage(); - const { userLogin } = useUser(); + const userLogin = JSON.parse(localStorage.getItem("@DEStoq:user")) || "" const { getRootProps, getRadioProps } = useRadioGroup({ name: "menuOptions", @@ -105,14 +102,6 @@ export const DashboardPage = () => { bgRepeat="no-repeat" backgroundSize="100% 100%" > - - Dashboard Page - { const { activeDashboardPage, setActiveDashboardPage, handleIcons, options } = @@ -159,7 +160,6 @@ export const DevelopersPage = () => { textAlign="center" > Developers - { mt={"170px"} direction={"column"} > - + - Developed with by : + Developed with and , by: { "transform": "scale(1.05)", "boxShadow":" 0px 20px 40px rgba(0, 0, 0, 0.25)", "border": "solid 1px #de9e36" - }} listStyleType={"none"} transition= "all ease .5s" diff --git a/distoq-capstonem3/src/components/dashboard-components/EstoquePage/index.jsx b/distoq-capstonem3/src/components/dashboard-components/EstoquePage/index.jsx index f4629b8..d4809c9 100644 --- a/distoq-capstonem3/src/components/dashboard-components/EstoquePage/index.jsx +++ b/distoq-capstonem3/src/components/dashboard-components/EstoquePage/index.jsx @@ -21,7 +21,7 @@ import { VStack, } from "@chakra-ui/react"; import { motion } from "framer-motion"; -import { useContext, useState } from "react"; +import { useContext, useState, useEffect } from "react"; import { useActivePage } from "../../../Providers/DashboardPageController"; import { useStockList } from "../../../Providers/Stock"; import { StockList } from "./StockList"; @@ -33,7 +33,7 @@ export const EstoquePage = () => { ); const { activeDashboardPage, setActiveDashboardPage, handleIcons, options } = useActivePage(); - const { stockList } = useStockList(); + const { stockList, getListStock } = useStockList(); const { inputSearch } = useContext(DashFilterContext); const filteredStockList = stockList.filter( @@ -49,13 +49,16 @@ export const EstoquePage = () => { .toLowerCase() .includes(inputSearch.toLowerCase()) ); - const { getRootProps, getRadioProps } = useRadioGroup({ name: "menuOptions", defaultValue: activeDashboardPage, onChange: setActiveDashboardPage, }); + useEffect(() => { + getListStock(); + }, []); + const group = getRootProps(); const formSchema = yup.object().shape({ min: yup diff --git a/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/Graficos/index.jsx b/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/Graficos/index.jsx index 56e0b94..f3f9450 100644 --- a/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/Graficos/index.jsx +++ b/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/Graficos/index.jsx @@ -9,52 +9,66 @@ import { motion } from "framer-motion"; export const CardChart = () => { - const faturamento = [ - {name: 'Mar', uv: 150, pv: 2400, amt: 2400}, - {name: 'Abr', uv: 200, pv: 2400, amt: 2400}, - {name: 'Mai', uv: 350, pv: 2400, amt: 2400}, + const primeiroTrimestre = [ + {name: 'Jan', uv: 100, pv: 2400, amt: 2400}, + {name: 'Fev', uv: 200, pv: 2400, amt: 2400}, + {name: 'Mar', uv: 350, pv: 2400, amt: 2400}, ]; - const vendas = [ - {name: 'Page A', uv: 150, pv: 2400, amt: 2400}, - {name: 'Page B', uv: 200, pv: 2400, amt: 2400}, - {name: 'Page C', uv: 350, pv: 2400, amt: 2400}, + const faturamento = [ + {name: 'Abr', uv: 180, pv: 2400, amt: 2400}, + {name: 'Mai', uv: 200, pv: 2400, amt: 2400}, + {name: 'Jun', uv: 350, pv: 2400, amt: 2400}, + + ]; + const mensal = [ + {name: 'Sem 1', semana: 100, pv: 2400, amt: 2400}, + {name: 'Sem 2', semana: 200, pv: 2400, amt: 2400}, + {name: 'Sem 3', semana: 220, pv: 2400, amt: 2400}, + {name: 'Sem 4', semana: 350, pv: 2400, amt: 2400}, + + ]; + const mensal2 = [ + {name: 'Sem 1', semana: 90, pv: 2400, amt: 2400}, + {name: 'Sem 2', semana: 150, pv: 2400, amt: 2400}, + {name: 'Sem 3', semana: 80, pv: 2400, amt: 2400}, + {name: 'Sem 4', semana: 350, pv: 2400, amt: 2400}, ]; const data = [ { name: 'Janeiro', - uv: 590, + mês: 590, pv: 800, amt: 1400, }, { name: 'Fevereiro', - uv: 868, + mês: 868, pv: 967, amt: 1506, }, { name: 'Março', - uv: 1397, + mês: 1397, pv: 1098, amt: 989, }, { name: 'Abril', - uv: 1480, + mês: 1480, pv: 1200, amt: 1228, }, { name: 'Maio', - uv: 1520, + mês: 1520, pv: 1108, amt: 1100, }, { name: 'Junho', - uv: 1400, + mês: 1400, pv: 680, amt: 1700, }, @@ -81,12 +95,12 @@ export const CardChart = () => { padding={"0 30px"} borderRadius={"10px"} > - Resultado Mensal + Resultado Mensal { left: 20, }} > - - - + + + - - + + { left: 20, }} > - - - + + + - - + + - Resultado Trimestral + Resultado Trimestral { left: 20, }} > - - - + + + - - + + { left: 20, }} > - - - + + + - - + + - Resultado Anual + Resultado Anual { left: 20, }} > - - - + + + - - + + { left: 20, }} > - - - + + + - - + + - - ); -}; - -{/* - - - Resumo - - - Gráficos - - - - - Teste - - */} - {/* - - - - - - - - - - - - - - - - - - - - Resultado Mensal - - - - - - - - - - - - - - - - - - - - - Resultado Trimestral - - - - - - - - - - - - - - - - - - - - - Resultado Anual - - - - - - - - - - - - - - - - - - - - - - - - - - - - */} - - {/* - - - Faturamento Bruto - - - - - - - - - - Vendas Trimestral - - - - - - - - */} - - - {/* - - - - - - - - - - */} - - {/* - - */} - {/* - - */} - {/* - - */} - {/* - - */} - {/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */} \ No newline at end of file +}; \ No newline at end of file diff --git a/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/Tabelas/index.jsx b/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/Tabelas/index.jsx index 6a0b005..a91dbcc 100644 --- a/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/Tabelas/index.jsx +++ b/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/Tabelas/index.jsx @@ -12,79 +12,73 @@ export const CardTable = () => { flexWrap={"wrap"} > - +
- - - + + + - - + + - - - + + + - - + + - - - + + + - - - - - - - - - - - - - + + + + + - - - + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + +
TipoPrazoValorTipoPrazoValor
Vendasmillimetres (mm)R$ 2500MensalR$ 33.320,00
Comprascentimetres (cm)R$ 2500ComprasMensalR$ -12.210,50
Gastosmetres (m)R$ 2500MensalR$ -5.250,00
À pagarcentimetres (cm)R$ 2500À pagarSemanalR$ -2.350,00
yardsmetres (m)0.91444
feetcentimetres (cm)R$ 2500
yardsmetres (m)R$ 2500Saldo-R$ 13.509,50
feetcentimetres (cm)R$ 2500EstoqueQuantidadeValor
yardsmetres (m)R$ 2500Cervejas20 cxR$ 2.500,00
feetcentimetres (cm)30.48Refrigerantes180 LatasR$ 810,50
yardsmetres (m)R$ 2500Laticínios22 cxR$ 3.120,00
feetcentimetres (cm)30.48Panificadora250cxR$ 1.125,00
yardsmetres (m)0.91444Total-R$ 7.555,00
diff --git a/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/index.jsx b/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/index.jsx index 8300f35..c2e5d79 100644 --- a/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/index.jsx +++ b/distoq-capstonem3/src/components/dashboard-components/FinanceiroPage/index.jsx @@ -131,40 +131,44 @@ export const FinanceiroPage = () => { isFitted variant="enclosed" w={"100%"} - backgroundColor={"#434343"} + // backgroundColor={"#434343"} borderRadius={"20px"} > Gráficos Resumo diff --git a/distoq-capstonem3/src/components/dashboard-components/FornecedoresPage/index.jsx b/distoq-capstonem3/src/components/dashboard-components/FornecedoresPage/index.jsx index d1b07f8..5e26d1c 100644 --- a/distoq-capstonem3/src/components/dashboard-components/FornecedoresPage/index.jsx +++ b/distoq-capstonem3/src/components/dashboard-components/FornecedoresPage/index.jsx @@ -120,15 +120,6 @@ export const FornecedoresPage = () => { bgRepeat="no-repeat" backgroundSize="100% 100%" > - - Fornecedores - - { > Listar Fornecedores @@ -174,9 +165,8 @@ export const FornecedoresPage = () => { { + const { id, clientInfo, ticketProducts, status } = ticket; + const [selectValue, setSelectValue] = useState(""); + + const { stockList, getListStock } = useStockList(); + console.log(id); + console.log(ticket); + console.log(ticketProducts); + console.log(stockList); + + const reduceStock = (id, quantity) => { + console.log(id); + api + .get(`/stock/${id}`) + .then( + (res) => { + console.log(res.data); + api.patch(`/stock/${res.data.id}`, { + ...res.data, + quantity: +res.data.quantity - quantity, + }); + }, + { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + } + ) + .then((res) => getListStock()); + }; + + return ( + + + + Pedido: #{id} + + + + Status: + + + + + + + + + Cliente #{clientInfo.id} + + + Nome: {clientInfo.name} + + + Endereço: {clientInfo.addressInfo && clientInfo.addressInfo.address} + , {clientInfo.addressInfo && clientInfo.addressInfo.number} + + + {clientInfo.addressInfo && clientInfo.addressInfo.city},{" "} + {clientInfo.addressInfo && clientInfo.addressInfo.state}{" "} + + + CEP: {clientInfo.addressInfo && clientInfo.addressInfo.cep}{" "} + + + + + + + + + + + + Pedido + + {ticket.ticketProducts.map((el) => ( + + {el.quantity} un. - {el.name} - Total: R${" "} + {(el.price * el.quantity).toFixed(2)} + + ))} + + + + + + + + Total + + + + acc + el.price * el.quantity, 0) + .toFixed(2)} + width={"100px"} + type="number" + backgroundColor={"#fff"} + disabled + /> + + + + + + + + + ); +}; diff --git a/distoq-capstonem3/src/components/dashboard-components/PedidosPage/index.jsx b/distoq-capstonem3/src/components/dashboard-components/PedidosPage/index.jsx index 5679697..49a7ec4 100644 --- a/distoq-capstonem3/src/components/dashboard-components/PedidosPage/index.jsx +++ b/distoq-capstonem3/src/components/dashboard-components/PedidosPage/index.jsx @@ -5,20 +5,144 @@ import { Heading, Input, InputGroup, + InputLeftAddon, + InputLeftElement, + InputRightAddon, InputRightElement, + Select, + Stack, + Tab, + TabList, + TabPanel, + TabPanels, + Tabs, + Text, useRadio, useRadioGroup, VStack, } from "@chakra-ui/react"; +import * as yup from "yup"; +import { useForm } from "react-hook-form"; +import { yupResolver } from "@hookform/resolvers/yup"; +import { useEffect, useState } from "react"; import { motion } from "framer-motion"; import { GoSearch } from "react-icons/go"; import { useActivePage } from "../../../Providers/DashboardPageController"; +import { useToken } from "../../../Providers/Token"; +import api from "../../../services/api"; +import { CardPedidos } from "./TicketCard"; + export const PedidosPage = () => { const { activeDashboardPage, setActiveDashboardPage, handleIcons, options } = useActivePage(); + const { token } = useToken(); + + const [clientsList, setClientsList] = useState([]); + const [productsList, setProductsList] = useState([]); + const [ticketItem, setTicketItem] = useState(null); + const [ticketItensList, setTicketItensList] = useState([]); + const [ticketTotalPrice, setTicketTotalPrice] = useState(0); + + const [showError, setShowError] = useState(false); + + const [inputClient, setInputClient] = useState(""); + const [ticketItemId, setTicketItemId] = useState(""); + const [ticketItemQuantity, setTicketItemQuantity] = useState(""); + + const [ticketsList, setTicketList] = useState([]); + + const [stockList, setStockList] = useState([]); + + const getStockList = () => { + api.get(`/stock`).then((resp) => setStockList(resp.data)); + }; + + console.log(stockList); + + const getProductsList = () => { + api + .get("/products") + .then((res) => setProductsList(res.data)) + .catch((err) => err); + }; + const getClientsList = () => { + api + .get("/users") + .then((res) => { + setClientsList(res.data.filter((client) => client.id !== 1)); + }) + .catch((err) => err); + }; + + const getTicketsList = () => { + api + .get("/tickets?_sort=id&_order=desc") + .then((res) => setTicketList(res.data)) + .catch((err) => err); + }; + + useEffect(() => { + getProductsList(); + getClientsList(); + getTicketsList(); + getStockList(); + }, []); + + useEffect(() => { + setTicketTotalPrice( + ticketItensList.reduce((acc, prod) => acc + prod.quantity * prod.price, 0) + ); + }, [ticketItensList]); + + const handleInputsFields = () => { + setInputClient(""); + setTicketTotalPrice(0); + setTicketItensList([]); + }; + + const formSchema = yup.object().shape({ + client: yup.string().required("Cliente obrigatório!"), + }); + + const { + register, + handleSubmit, + formState: { errors }, + } = useForm({ + resolver: yupResolver(formSchema), + }); + + const onSubmitFunction = (data) => { + if (ticketItensList.length === 0) { + setShowError(true); + } else { + const clientData = clientsList.filter((ele) => ele.id == data.client); + const ticketData = { + clientInfo: { ...clientData[0] }, + ownerId: 1, + userId: 1, + ticketProducts: [...ticketItensList], + status: "Realizado", + }; + console.log(data); + console.log(ticketData); + + api + .post(`/tickets`, ticketData, { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }) + .then(() => getTicketsList()); + + handleInputsFields(); + } + }; + const { getRootProps, getRadioProps } = useRadioGroup({ name: "menuOptions", defaultValue: activeDashboardPage, @@ -68,7 +192,6 @@ export const PedidosPage = () => { ); } return ( - //FULL CONTAINER { bgRepeat="no-repeat" backgroundSize="100% 100%" > - - Pedidos Page - - - - - - - { justifyContent={"center"} > - CONTEUDO AQUI!!!! + + + + + Pedidos + + + Adicionar Novo Pedido + + + + + {ticketsList?.map((ele) => ( + + ))} + + + + + Adicionar Pedido + + {errors.client && ( + + {errors.client.message} + + )} + + + + + { + setTicketItemQuantity(e.target.value); + }} + /> + + + {ticketItensList?.map((ele, index) => ( + + {index + 1}. {ele.name} - {ele.quantity} un. + Total: R$ + {(+ele.quantity * +ele.price).toFixed(2)} + + + ))} + + {showError && ( + + Adicione ao menos um produto! + + )} + + + + + + + + + + + + + @@ -153,5 +531,4 @@ export const PedidosPage = () => { ); }; - -export default PedidosPage; +export default PedidosPage; \ No newline at end of file diff --git a/distoq-capstonem3/src/components/dashboard-components/ProdutosPage/ProdutosCard/index.jsx b/distoq-capstonem3/src/components/dashboard-components/ProdutosPage/ProdutosCard/index.jsx index 444e925..d19f0d0 100644 --- a/distoq-capstonem3/src/components/dashboard-components/ProdutosPage/ProdutosCard/index.jsx +++ b/distoq-capstonem3/src/components/dashboard-components/ProdutosPage/ProdutosCard/index.jsx @@ -8,10 +8,8 @@ import { PopoverContent, PopoverHeader, PopoverBody, - PopoverFooter, PopoverArrow, PopoverCloseButton, - PopoverAnchor, Button, Flex, Image, @@ -50,7 +48,7 @@ export const CardProdutos = ({ product, setProductsList, getProductsList }) => { key={id} id={id} width={"100%"} - maxWidth={"335px"} + maxWidth={"290px"} height={"fit-content"} borderRadius={"10px"} margin={"10px 10px"} @@ -71,40 +69,10 @@ export const CardProdutos = ({ product, setProductsList, getProductsList }) => { alignItems={"center"} justifyContent={"space-between"} > - - Categoria: - {category} - - - - - - - - - - - Descrição: - {description} - - - - Preço: R$ - {price.toFixed(2)} - - - P.Id: #{id} - + + + +
+ + + + Descrição: + {description} + + Preço: R$ {price.toFixed(2)} diff --git a/distoq-capstonem3/src/components/home-components/HomeFilter/index.jsx b/distoq-capstonem3/src/components/home-components/HomeFilter/index.jsx index 90812d1..1cb1d0f 100644 --- a/distoq-capstonem3/src/components/home-components/HomeFilter/index.jsx +++ b/distoq-capstonem3/src/components/home-components/HomeFilter/index.jsx @@ -5,25 +5,51 @@ const HomeFilter = () => { const { addInputSearch } = useInputHome(); return ( - + - - - - diff --git a/distoq-capstonem3/src/pages/dashboard/index.jsx b/distoq-capstonem3/src/pages/dashboard/index.jsx index 95cb370..d96781f 100644 --- a/distoq-capstonem3/src/pages/dashboard/index.jsx +++ b/distoq-capstonem3/src/pages/dashboard/index.jsx @@ -16,19 +16,16 @@ import { useToken } from "../../Providers/Token"; const Dashboard = () => { const { activeDashboardPage } = useActivePage(); - + const userLogin = JSON.parse(localStorage.getItem("@DEStoq:user")) || ""; const {token} = useToken(); const { decodedToken, isExpired } = useJwt(token); const navigate = useNavigate(); - const isLoggedIn = token && !isExpired; - const isAdmin = decodedToken?.sub; + const isAdmin = userLogin.userId - if (!isLoggedIn) { - return navigate("/login"); - } - if (isAdmin !== "1") { + + if (isAdmin != "1") { return navigate("/"); }