From b2614da18b41bbc95b7f85cb823da7ef8cc1f076 Mon Sep 17 00:00:00 2001 From: Aashita Date: Sun, 12 May 2024 20:41:19 -0400 Subject: [PATCH] changed reports to pet type --- frontend/package-lock.json | 128 ++- frontend/package.json | 2 +- frontend/src/app/reports/Chart.tsx | 9 +- frontend/src/app/reports/Dashboard.tsx | 1021 ++++++------------------ 4 files changed, 325 insertions(+), 835 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 78b07ad..49e2de4 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -12,7 +12,7 @@ "html2canvas": "^1.4.1", "jspdf": "^2.5.1", "jspdf-autotable": "^3.8.2", - "next": "14.0.4", + "next": "^14.2.3", "react": "^18", "react-datepicker": "^6.6.0", "react-dom": "^18", @@ -1508,9 +1508,9 @@ "integrity": "sha512-fuscdXJ9G1qb7W8VdHi+IwRqij3lBkosAm4ydQtEmbY58OzHXqQhvlxqEkoz0yssNVn38bcpRWgA9PP+OGoisw==" }, "node_modules/@next/env": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/env/-/env-14.0.4.tgz", - "integrity": "sha512-irQnbMLbUNQpP1wcE5NstJtbuA/69kRfzBrpAD7Gsn8zm/CY6YQYc3HQBz8QPxwISG26tIm5afvvVbu508oBeQ==" + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.3.tgz", + "integrity": "sha512-W7fd7IbkfmeeY2gXrzJYDx8D2lWKbVoTIj1o1ScPHNzvp30s1AuoEFSdr39bC5sjxJaxTtq3OTCZboNp0lNWHA==" }, "node_modules/@next/eslint-plugin-next": { "version": "14.0.4", @@ -1522,9 +1522,9 @@ } }, "node_modules/@next/swc-darwin-arm64": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.0.4.tgz", - "integrity": "sha512-mF05E/5uPthWzyYDyptcwHptucf/jj09i2SXBPwNzbgBNc+XnwzrL0U6BmPjQeOL+FiB+iG1gwBeq7mlDjSRPg==", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.3.tgz", + "integrity": "sha512-3pEYo/RaGqPP0YzwnlmPN2puaF2WMLM3apt5jLW2fFdXD9+pqcoTzRk+iZsf8ta7+quAe4Q6Ms0nR0SFGFdS1A==", "cpu": [ "arm64" ], @@ -1537,9 +1537,9 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.0.4.tgz", - "integrity": "sha512-IZQ3C7Bx0k2rYtrZZxKKiusMTM9WWcK5ajyhOZkYYTCc8xytmwSzR1skU7qLgVT/EY9xtXDG0WhY6fyujnI3rw==", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.3.tgz", + "integrity": "sha512-6adp7waE6P1TYFSXpY366xwsOnEXM+y1kgRpjSRVI2CBDOcbRjsJ67Z6EgKIqWIue52d2q/Mx8g9MszARj8IEA==", "cpu": [ "x64" ], @@ -1552,9 +1552,9 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.0.4.tgz", - "integrity": "sha512-VwwZKrBQo/MGb1VOrxJ6LrKvbpo7UbROuyMRvQKTFKhNaXjUmKTu7wxVkIuCARAfiI8JpaWAnKR+D6tzpCcM4w==", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.3.tgz", + "integrity": "sha512-cuzCE/1G0ZSnTAHJPUT1rPgQx1w5tzSX7POXSLaS7w2nIUJUD+e25QoXD/hMfxbsT9rslEXugWypJMILBj/QsA==", "cpu": [ "arm64" ], @@ -1567,9 +1567,9 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.0.4.tgz", - "integrity": "sha512-8QftwPEW37XxXoAwsn+nXlodKWHfpMaSvt81W43Wh8dv0gkheD+30ezWMcFGHLI71KiWmHK5PSQbTQGUiidvLQ==", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.3.tgz", + "integrity": "sha512-0D4/oMM2Y9Ta3nGuCcQN8jjJjmDPYpHX9OJzqk42NZGJocU2MqhBq5tWkJrUQOQY9N+In9xOdymzapM09GeiZw==", "cpu": [ "arm64" ], @@ -1582,9 +1582,9 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.0.4.tgz", - "integrity": "sha512-/s/Pme3VKfZAfISlYVq2hzFS8AcAIOTnoKupc/j4WlvF6GQ0VouS2Q2KEgPuO1eMBwakWPB1aYFIA4VNVh667A==", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.3.tgz", + "integrity": "sha512-ENPiNnBNDInBLyUU5ii8PMQh+4XLr4pG51tOp6aJ9xqFQ2iRI6IH0Ds2yJkAzNV1CfyagcyzPfROMViS2wOZ9w==", "cpu": [ "x64" ], @@ -1597,9 +1597,9 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.0.4.tgz", - "integrity": "sha512-m8z/6Fyal4L9Bnlxde5g2Mfa1Z7dasMQyhEhskDATpqr+Y0mjOBZcXQ7G5U+vgL22cI4T7MfvgtrM2jdopqWaw==", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.3.tgz", + "integrity": "sha512-BTAbq0LnCbF5MtoM7I/9UeUu/8ZBY0i8SFjUMCbPDOLv+un67e2JgyN4pmgfXBwy/I+RHu8q+k+MCkDN6P9ViQ==", "cpu": [ "x64" ], @@ -1612,9 +1612,9 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.0.4.tgz", - "integrity": "sha512-7Wv4PRiWIAWbm5XrGz3D8HUkCVDMMz9igffZG4NB1p4u1KoItwx9qjATHz88kwCEal/HXmbShucaslXCQXUM5w==", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.3.tgz", + "integrity": "sha512-AEHIw/dhAMLNFJFJIJIyOFDzrzI5bAjI9J26gbO5xhAKHYTZ9Or04BesFPXiAYXDNdrwTP2dQceYA4dL1geu8A==", "cpu": [ "arm64" ], @@ -1627,9 +1627,9 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.0.4.tgz", - "integrity": "sha512-zLeNEAPULsl0phfGb4kdzF/cAVIfaC7hY+kt0/d+y9mzcZHsMS3hAS829WbJ31DkSlVKQeHEjZHIdhN+Pg7Gyg==", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.3.tgz", + "integrity": "sha512-vga40n1q6aYb0CLrM+eEmisfKCR45ixQYXuBXxOOmmoV8sYST9k7E3US32FsY+CkkF7NtzdcebiFT4CHuMSyZw==", "cpu": [ "ia32" ], @@ -1642,9 +1642,9 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.0.4.tgz", - "integrity": "sha512-yEh2+R8qDlDCjxVpzOTEpBLQTEFAcP2A8fUFLaWNap9GitYKkKv1//y2S6XY6zsR4rCOPRpU7plYDR+az2n30A==", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.3.tgz", + "integrity": "sha512-Q1/zm43RWynxrO7lW4ehciQVj+5ePBhOK+/K2P7pLFX3JaJ/IZVC69SHidrmZSOkqz7ECIOhhy7XhAFG4JYyHA==", "cpu": [ "x64" ], @@ -1727,11 +1727,17 @@ "@sinonjs/commons": "^3.0.0" } }, + "node_modules/@swc/counter": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz", + "integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==" + }, "node_modules/@swc/helpers": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.2.tgz", - "integrity": "sha512-E4KcWTpoLHqwPHLxidpOqQbcrZVgi0rsmmZXUle1jXmJfuIf/UWpczUJ7MZZ5tlxytgJXyp0w4PGkkeLiuIdZw==", + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.5.tgz", + "integrity": "sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==", "dependencies": { + "@swc/counter": "^0.1.3", "tslib": "^2.4.0" } }, @@ -5109,11 +5115,6 @@ "node": ">=10.13.0" } }, - "node_modules/glob-to-regexp": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", - "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==" - }, "node_modules/glob/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -7530,18 +7531,17 @@ "dev": true }, "node_modules/next": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/next/-/next-14.0.4.tgz", - "integrity": "sha512-qbwypnM7327SadwFtxXnQdGiKpkuhaRLE2uq62/nRul9cj9KhQ5LhHmlziTNqUidZotw/Q1I9OjirBROdUJNgA==", + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/next/-/next-14.2.3.tgz", + "integrity": "sha512-dowFkFTR8v79NPJO4QsBUtxv0g9BrS/phluVpMAt2ku7H+cbcBJlopXjkWlwxrk/xGqMemr7JkGPGemPrLLX7A==", "dependencies": { - "@next/env": "14.0.4", - "@swc/helpers": "0.5.2", + "@next/env": "14.2.3", + "@swc/helpers": "0.5.5", "busboy": "1.6.0", - "caniuse-lite": "^1.0.30001406", + "caniuse-lite": "^1.0.30001579", "graceful-fs": "^4.2.11", "postcss": "8.4.31", - "styled-jsx": "5.1.1", - "watchpack": "2.4.0" + "styled-jsx": "5.1.1" }, "bin": { "next": "dist/bin/next" @@ -7550,18 +7550,19 @@ "node": ">=18.17.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "14.0.4", - "@next/swc-darwin-x64": "14.0.4", - "@next/swc-linux-arm64-gnu": "14.0.4", - "@next/swc-linux-arm64-musl": "14.0.4", - "@next/swc-linux-x64-gnu": "14.0.4", - "@next/swc-linux-x64-musl": "14.0.4", - "@next/swc-win32-arm64-msvc": "14.0.4", - "@next/swc-win32-ia32-msvc": "14.0.4", - "@next/swc-win32-x64-msvc": "14.0.4" + "@next/swc-darwin-arm64": "14.2.3", + "@next/swc-darwin-x64": "14.2.3", + "@next/swc-linux-arm64-gnu": "14.2.3", + "@next/swc-linux-arm64-musl": "14.2.3", + "@next/swc-linux-x64-gnu": "14.2.3", + "@next/swc-linux-x64-musl": "14.2.3", + "@next/swc-win32-arm64-msvc": "14.2.3", + "@next/swc-win32-ia32-msvc": "14.2.3", + "@next/swc-win32-x64-msvc": "14.2.3" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", + "@playwright/test": "^1.41.2", "react": "^18.2.0", "react-dom": "^18.2.0", "sass": "^1.3.0" @@ -7570,6 +7571,9 @@ "@opentelemetry/api": { "optional": true }, + "@playwright/test": { + "optional": true + }, "sass": { "optional": true } @@ -9886,18 +9890,6 @@ "makeerror": "1.0.12" } }, - "node_modules/watchpack": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", - "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", - "dependencies": { - "glob-to-regexp": "^0.4.1", - "graceful-fs": "^4.1.2" - }, - "engines": { - "node": ">=10.13.0" - } - }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 4b3ad9b..8a8f85d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -17,7 +17,7 @@ "html2canvas": "^1.4.1", "jspdf": "^2.5.1", "jspdf-autotable": "^3.8.2", - "next": "14.0.4", + "next": "^14.2.3", "react": "^18", "react-datepicker": "^6.6.0", "react-dom": "^18", diff --git a/frontend/src/app/reports/Chart.tsx b/frontend/src/app/reports/Chart.tsx index c3d3e8e..15c3d99 100644 --- a/frontend/src/app/reports/Chart.tsx +++ b/frontend/src/app/reports/Chart.tsx @@ -1,7 +1,7 @@ 'use client'; import { useEffect, useState, useRef, MouseEvent } from 'react'; import ChartJS from 'chart.js/auto'; -import { calcAllLbsPerBrand, calculateLbsPerBrand } from './Dashboard'; +import { calculateLbsPerAnimal } from './Dashboard'; import { Button } from '@/components/core/Button'; import jsPDF from 'jspdf'; import 'jspdf-autotable'; @@ -37,9 +37,9 @@ const Chart: React.FC<{ // Extracting data for the chart const labels: string[] = data.map((item: any) => item.foodItems.brand); const allFoodOrdersData: { [key: string]: number } = - calcAllLbsPerBrand(exportable); + calculateLbsPerAnimal(exportable); const foodOrdersData: { [key: string]: number } = - calculateLbsPerBrand(data); + calculateLbsPerAnimal(data); const costs: number[] = data.map((item: any) => item['Total cost ($)']); const colors: string[] = [ @@ -48,6 +48,9 @@ const Chart: React.FC<{ '#A9BCFF', '#FFCF33', '#92E08B', + '#FFCF33', + '#A9BCFF', + '#FFB7A9' ]; const colors1: string[] = [ '#fbd4db', diff --git a/frontend/src/app/reports/Dashboard.tsx b/frontend/src/app/reports/Dashboard.tsx index ce77483..f18d8ed 100644 --- a/frontend/src/app/reports/Dashboard.tsx +++ b/frontend/src/app/reports/Dashboard.tsx @@ -59,18 +59,18 @@ export function getWeightsByLocation( if (counties.includes(locationName)) { orderData.forEach((order: any) => { - //if (order.Client) { - //console.log(order.Client.region) - if (countyLocations[locationName].includes(order.Client.region)) { + //if (order.client) { + //console.log(order.client.region) + if (countyLocations[locationName].includes(order.client.region || order.client.city)) { costsForLocation.push(order); } //}else{console.log(order.id)} }); } else { orderData.forEach((order: any) => { - //if (order.Client) { + //if (order.client) { if ( - order.Client.region.toLowerCase() == locationName.toLowerCase() + order.client.region.toLowerCase() == locationName.toLowerCase() || order.client.city.toLowerCase() == locationName.toLowerCase() ) { costsForLocation.push(order); } @@ -80,6 +80,9 @@ export function getWeightsByLocation( return costsForLocation; } + + + export function getWeightsByDate(orderData: any[], date: Date): any[] { const costsForDate: any[] = []; let index = 0; @@ -95,15 +98,31 @@ export function getWeightsByDate(orderData: any[], date: Date): any[] { return costsForDate; } -// BY ORDERRRRR -export function calculateLbsPerBrand(orderData: any[]): { + + +export function calculateLbsPerAnimal(orderData: any[]): { [key: string]: number; } { const costPerBrand: { [key: string]: number } = {}; orderData.forEach((order: any) => { - if (order.foodItems !== undefined) { - order.foodItems.forEach((foodItem: any) => { + + // go into order's client + // iterate through the pets + // add the pets names (cats, dogs, etc.) + + if (order.client.pets !== undefined) { + order.client.pets.forEach((pet: any , index: number) => { + const animal = pet.animal.toLowerCase(); + const weight = order.foodItems[index].weight; + costPerBrand[animal] = (costPerBrand[animal] || 0) + weight; + }); + } + + + + /*if (order.foodItems !== undefined) { + order.foodItems.forEach((foodItems: any) => { const brands = [ 'Friskies', 'HEB Texas Pets', @@ -111,24 +130,30 @@ export function calculateLbsPerBrand(orderData: any[]): { 'Wholesomes', 'Other', ]; - const brand = brands.includes(foodItem.brand) - ? foodItem.brand + const brand = brands.includes(foodItems.brand) + ? foodItems.brand : 'Other'; - const weight = foodItem.weight; + const weight = foodItems.weight; + + costPerBrand[brand] = (costPerBrand[brand] || 0) + weight; }); - } + }*/ + }); return costPerBrand; } -export function calcAllLbsPerBrand(orderData: any[]): { + + + +/*export function calcAllLbsPerBrand(orderData: any[]): { [key: string]: number; } { const costPerBrand: { [key: string]: number } = {}; orderData.forEach((order: any) => { if (order.foodItems !== undefined) { - order.foodItems.forEach((foodItem: any) => { + order.foodItems.forEach((foodItems: any) => { const brands = [ 'Friskies', 'HEB Texas Pets', @@ -136,30 +161,34 @@ export function calcAllLbsPerBrand(orderData: any[]): { 'Wholesomes', 'Other', ]; - const brand = brands.includes(foodItem.brand) - ? foodItem.brand - : foodItem.brand; - const weight = foodItem.weight; + const brand = brands.includes(foodItems.brand) + ? foodItems.brand + : foodItems.brand; + const weight = foodItems.weight; costPerBrand[brand] = (costPerBrand[brand] || 0) + weight; }); } }); return costPerBrand; -} +}*/ + + -export function calculateLbsPerOtherBrands( + + +/*export function calculateLbsPerOtherBrands( orderData: any[], otherBrands: string[] ): { [key: string]: number } { const lbsPerOtherBrand: { [key: string]: number } = {}; orderData.forEach((order: any) => { if (order.foodItems !== undefined) { - order.foodItems.forEach((foodItem: any) => { - if (otherBrands.includes(foodItem.brand)) { + order.foodItems.forEach((foodItems: any) => { + if (otherBrands.includes(foodItems.brand)) { //const brands = ['Friskies','HEB Texas Pets', 'Nutrena', 'Wholesomes', 'Other'] //co nsole.log(otherBrands); - const brand = foodItem.brand; - const lbs = foodItem.weight; + const brand = foodItems.brand; + const lbs = foodItems.weight; lbsPerOtherBrand[brand] = (lbsPerOtherBrand[brand] || 0) + lbs; //co nsole.log(lbs); @@ -180,9 +209,12 @@ export function calculateLbsPerOtherBrands( Object.fromEntries(sortedEntries); return sortedLbsPerOtherBrand; -} +}*/ -export function makeOtherBrandsArray(orderData: any[]): string[] { + + + +/*export function makeOtherBrandsArray(orderData: any[]): string[] { // THIS FUNCTION ADDS ALL OTHER BRANDS TO AN ARRAY REGARDLESS OF ORIGINAL BRANDS //const otherBrands: {[key: number]: string} = {} const otherBrands: string[] = []; @@ -196,12 +228,12 @@ export function makeOtherBrandsArray(orderData: any[]): string[] { ]; orderData.forEach((order: any) => { - order.foodItems.forEach((foodItem: any) => { + order.foodItems.forEach((foodItems: any) => { if ( - !otherBrands.includes(foodItem.brand) && - !brands.includes(foodItem.brand) + !otherBrands.includes(foodItems.brand) && + !brands.includes(foodItems.brand) ) { - const brand = foodItem.brand; + const brand = foodItems.brand; otherBrands[otherBrandsAmt] = brand; otherBrandsAmt++; } //FIX THIS UPPP @@ -209,6 +241,30 @@ export function makeOtherBrandsArray(orderData: any[]): string[] { }); return otherBrands; } +*/ + + + + +export function getTypesOfPets (orderData:any[]): string[]{ + const animalTypes: string[] = []; + let otherBrandsAmt = 0; + + orderData.forEach((order: any) => { + order.client.pets.forEach((pet: any) => { + if ( + !animalTypes.includes(pet.animal.toLowerCase()) + ) { + animalTypes[otherBrandsAmt] = pet.animal.toLowerCase(); + otherBrandsAmt++; + } + }); + }); + return animalTypes; +} + + + export function filterBySuccessfulStatus(orderData: any[]): any[] { const filteredBySuccess: any[] = []; @@ -220,6 +276,9 @@ export function filterBySuccessfulStatus(orderData: any[]): any[] { return filteredBySuccess; } +// client request: change by brand instead into by animal type +// currently at + export default function Dashboard() { const [clientData, setClientData] = useState([]); //type of clientModel const [orderData, setOrderData] = useState([]); //type of orderModel @@ -235,655 +294,187 @@ export default function Dashboard() { const [previousOrderData, setPreviousOrderData] = useState([]); const { accessToken } = useUserContext(); - const FAKE_ORDER_DATA = [ - { - client: { - _id: '65d91d857b2e523b16d35778', - name: 'Adventurous Arjun', - age: 32, - region: 'Lockhart', - pets: [ - { - isActive: true, - animal: 'cat', - vet: false, - food: 'Friskies', - lbs: 6, - }, - { - isActive: true, - animal: 'small dog', - vet: true, - food: 'HEB Texas Pets', - lbs: 10, - }, - ], - }, - createdOn: new Date('2015-07-15T12:00:00Z'), - deliverBy: new Date('2015-07-15T12:00:00Z'), - foodItems: [ - { - brand: 'Friskies', - weight: 6, - }, + const FAKE_ORDER_DATA= + [{ + "client": { + "_id": "65d91d857b2e523b16d35778", + "name": "Adventurous Arjun", + "age": 32, + "region": "Lockhart", + "city":"Lockhart", + "pets": [ { - brand: 'HEB Texas Pets', - weight: 10, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d35779', - name: 'Brave Bianca', - age: 28, - region: 'Wimberley', - pets: [ - { - isActive: true, - animal: 'large dog', - vet: true, - food: 'Nutrena', - lbs: 12, - }, - ], - }, - createdOn: new Date('2016-09-23T12:00:00Z'), - deliverBy: new Date('2016-09-23T12:00:00Z'), - foodItems: [ - { - brand: 'Nutrena', - weight: 12, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d3577a', - name: 'Caring Cody', - age: 45, - region: 'La Vista', - pets: [ - { - isActive: true, - animal: 'large dog', - vet: false, - food: 'Wholesomes', - lbs: 15, - }, - ], - }, - createdOn: new Date('2017-04-17T12:00:00Z'), - deliverBy: new Date('2017-04-17T12:00:00Z'), - foodItems: [ - { - brand: 'Wholesomes', - weight: 15, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d3577b', - name: 'Daring Daisy', - age: 37, - region: 'Giddings', - pets: [ - { - isActive: true, - animal: 'cat', - vet: true, - food: 'Friskies', - lbs: 7, - }, - ], - }, - createdOn: new Date('2018-11-04T12:00:00Z'), - deliverBy: new Date('2018-11-04T12:00:00Z'), - foodItems: [ - { - brand: 'Friskies', - weight: 7, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d3577c', - name: 'Energetic Elena', - age: 29, - region: 'Schulenberg', - pets: [ - { - isActive: true, - animal: 'small dog', - vet: true, - food: 'Foodimals', - lbs: 9, - }, - { - isActive: true, - animal: 'small dog', - vet: true, - food: 'Petsmart', - lbs: 8, - }, - ], - }, - createdOn: new Date('2019-02-21T12:00:00Z'), - deliverBy: new Date('2019-02-21T12:00:00Z'), - foodItems: [ - { - brand: 'Foodimals', - weight: 9, - }, - { - brand: 'Petsmart', - weight: 8, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d3577d', - name: 'Fearless Fernando', - age: 41, - region: 'Buda', - pets: [ - { - isActive: true, - animal: 'cat', - vet: false, - food: 'Friskies', - lbs: 5, - }, - ], - }, - createdOn: new Date('2010-10-19T12:00:00Z'), - deliverBy: new Date('2010-10-19T12:00:00Z'), - foodItems: [ - { - brand: 'Friskies', - weight: 5, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d3577e', - name: 'Gentle Giselle', - age: 33, - region: 'prairie Lea', - pets: [ - { - isActive: true, - animal: 'large dog', - vet: true, - food: 'HEB Texas Pets', - lbs: 18, - }, - ], - }, - createdOn: new Date('2010-10-28T12:00:00Z'), - deliverBy: new Date('2010-10-28T12:00:00Z'), - foodItems: [ - { - brand: 'HEB Texas Pets', - weight: 18, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d3577f', - name: 'Helpful Hector', - age: 49, - region: 'Johnson City Resource Center', - pets: [ - { - isActive: true, - animal: 'large dog', - vet: true, - food: 'Nutrena', - lbs: 14, + "isActive": true, + "animal": "cat", + "vet": false, + "food":{ + "kind": "HEB Texas Pets", + "lbs": 5 }, - ], - }, - createdOn: new Date('2012-01-14T12:00:00Z'), - deliverBy: new Date('2012-01-14T12:00:00Z'), - foodItems: [ - { - brand: 'Nutrena', - weight: 14, + "lbs": 6 }, - ], - status: 'successful', - }, - // Add 12 more orders below: - { - client: { - _id: '65d91d857b2e523b16d35780', - name: 'Graceful Gabrielle', - age: 31, - region: 'Flatonia', - pets: [ - { - isActive: true, - animal: 'cat', - vet: true, - food: 'Petsmart', - lbs: 6, - }, - ], - }, - createdOn: new Date('2021-03-10T12:00:00Z'), - deliverBy: new Date('2021-03-10T12:00:00Z'), - foodItems: [ { - brand: 'Petsmart', - weight: 6, - }, - ], - status: 'failed', - }, - { - client: { - _id: '65d91d857b2e523b16d35781', - name: 'Harmonious Harper', - age: 42, - region: 'Carmine', - pets: [ - { - isActive: true, - animal: 'large dog', - vet: false, - food: 'Friskies', - lbs: 10, + "isActive": true, + "animal": "small dog", + "vet": true, + "food": { + "kind": "Other", + "lbs": 6 }, - ], - }, - createdOn: new Date('2021-05-05T12:00:00Z'), - deliverBy: new Date('2021-05-05T12:00:00Z'), - foodItems: [ - { - brand: 'Friskies', - weight: 10, - }, - ], - status: 'pending', + "lbs": 10 + } + ] }, - { - client: { - _id: '65d91d857b2e523b16d35782', - name: 'Inventive Isaac', - age: 35, - region: 'San Marcos Housing Authority', - pets: [ - { - isActive: true, - animal: 'cat', - vet: true, - food: 'BirdFoods', - lbs: 8, - }, - ], - }, - createdOn: new Date('2021-08-20T12:00:00Z'), - deliverBy: new Date('2021-08-20T12:00:00Z'), - foodItems: [ + "createdOn": "2024-05-12T08:00:00.000Z", + "deliverBy": "2024-05-13T12:00:00.000Z", + "foodItems": [ + { + "brand": "Acme Pet Foods", + "weight": 2 + }, + { + "brand": "Healthy Paws", + "weight": 1.5 + } + ], + "status": "successful" + },{ + "client": { + "_id": "65d91d857b2e523b16d35778", + "name": "Adventurous Arjun", + "age": 32, + "region": "Lockhart", + "city":"Lockhart", + "pets": [ { - brand: 'BirdFoods', - weight: 8, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d35783', - name: 'Joyful Jordan', - age: 30, - region: 'San Marcos Senior Center', - pets: [ - { - isActive: true, - animal: 'small dog', - vet: false, - food: 'Fiesta', - lbs: 9, + "isActive": true, + "animal": "cat", + "vet": false, + "food":{ + "kind": "HEB Texas Pets", + "lbs": 5 }, - ], - }, - createdOn: new Date('2021-10-15T12:00:00Z'), - deliverBy: new Date('2021-10-15T12:00:00Z'), - foodItems: [ - { - brand: 'Fiesta', - weight: 9, + "lbs": 6 }, - ], - status: 'pending', - }, - { - client: { - _id: '65d91d857b2e523b16d35784', - name: 'Keen Kelly', - age: 48, - region: 'Kyle', - pets: [ - { - isActive: true, - animal: 'large dog', - vet: true, - food: 'Wholesomes', - lbs: 16, - }, - ], - }, - createdOn: new Date('2022-01-05T12:00:00Z'), - deliverBy: new Date('2022-01-05T12:00:00Z'), - foodItems: [ { - brand: 'Wholesomes', - weight: 16, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d35785', - name: 'Loyal Liam', - age: 34, - region: 'La Vista', - pets: [ - { - isActive: true, - animal: 'small dog', - vet: true, - food: 'Nutrena', - lbs: 12, + "isActive": true, + "animal": "big dog", + "vet": true, + "food": { + "kind": "Other", + "lbs": 6 }, - ], - }, - createdOn: new Date('2022-03-10T12:00:00Z'), - deliverBy: new Date('2022-03-10T12:00:00Z'), - foodItems: [ - { - brand: 'Nutrena', - weight: 12, - }, - ], - status: 'successful', + "lbs": 10 + } + ] }, + "createdOn": "2024-05-12T08:00:00.000Z", + "deliverBy": "2024-05-13T12:00:00.000Z", + "foodItems": [ + { + "brand": "Acme Pet Foods", + "weight": 2 + }, + { + "brand": "Healthy Paws", + "weight": 5 + } + ], + "status": "successful" + }, { - client: { - _id: '65d91d857b2e523b16d35786', - name: 'Merry Melissa', - age: 39, - region: 'Trinity Lutheran', - pets: [ - { - isActive: true, - animal: 'cat', - vet: false, - food: 'Foodimals', - lbs: 7, - }, - ], - }, - createdOn: new Date('2022-04-18T12:00:00Z'), - deliverBy: new Date('2022-04-18T12:00:00Z'), - foodItems: [ + "client": { + "_id": "65d91d857b2e523b16d35778", + "name": "Adventurous Arjun", + "age": 32, + "region": "Lockhart", + "city":"Lockhart", + "pets": [ { - brand: 'Foodimals', - weight: 7, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d35787', - name: 'Noble Nathan', - age: 43, - region: 'Lockhart', - pets: [ - { - isActive: true, - animal: 'large dog', - vet: true, - food: 'Fiesta', - lbs: 22, + "isActive": true, + "animal": "Cockatiel", + "vet": false, + "food":{ + "kind": "HEB Texas Pets", + "lbs": 5 }, - ], - }, - createdOn: new Date('2022-06-05T12:00:00Z'), - deliverBy: new Date('2022-06-05T12:00:00Z'), - foodItems: [ - { - brand: 'Fiesta', - weight: 22, + "lbs": 6 }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d35788', - name: 'Optimistic Olivia', - age: 26, - region: 'Prairie Lea', - pets: [ - { - isActive: true, - animal: 'cat', - vet: true, - food: 'Petsmart', - lbs: 6, - }, - ], - }, - createdOn: new Date('2022-08-20T12:00:00Z'), - deliverBy: new Date('2022-08-20T12:00:00Z'), - foodItems: [ { - brand: 'Petsmart', - weight: 6, - }, - ], - status: 'pending', - }, - { - client: { - _id: '65d91d857b2e523b16d35789', - name: 'Patient Paul', - age: 51, - region: 'La Vista', - pets: [ - { - isActive: true, - animal: 'small dog', - vet: false, - food: 'HEB Texas Pets', - lbs: 8, + "isActive": true, + "animal": "medium dog", + "vet": true, + "food": { + "kind": "Other", + "lbs": 6 }, - ], - }, - createdOn: new Date('2022-10-15T12:00:00Z'), - deliverBy: new Date('2022-10-15T12:00:00Z'), - foodItems: [ - { - brand: 'HEB Texas Pets', - weight: 8, - }, - ], - status: 'successful', + "lbs": 10 + } + ] }, + "createdOn": "2024-05-12T08:00:00.000Z", + "deliverBy": "2024-05-13T12:00:00.000Z", + "foodItems": [ + { + "brand": "Acme Pet Foods", + "weight": 2 + }, + { + "brand": "Healthy Paws", + "weight": 1.5 + } + ], + "status": "successful" + }, { - client: { - _id: '65d91d857b2e523b16d3578a', - name: 'Quirky Quentin', - age: 38, - region: 'Smithville', - pets: [ - { - isActive: true, - animal: 'cat', - vet: true, - food: 'Wholesomes', - lbs: 5, - }, - ], - }, - createdOn: new Date('2022-12-25T12:00:00Z'), - deliverBy: new Date('2022-12-25T12:00:00Z'), - foodItems: [ + "client": { + "_id": "65d91d857b2e523b16d35778", + "name": "Adventurous Arjun", + "age": 32, + "region": "Lockhart", + "city":"Lockhart", + "pets": [ { - brand: 'Wholesomes', - weight: 5, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d3578b', - name: 'Resilient Rachel', - age: 44, - region: 'Giddings', - pets: [ - { - isActive: true, - animal: 'large dog', - vet: true, - food: 'Nutrena', - lbs: 18, + "isActive": true, + "animal": "Cat", + "vet": false, + "food":{ + "kind": "HEB Texas Pets", + "lbs": 5 }, - ], - }, - createdOn: new Date('2023-02-10T12:00:00Z'), - deliverBy: new Date('2023-02-10T12:00:00Z'), - foodItems: [ - { - brand: 'Nutrena', - weight: 18, + "lbs": 6 }, - ], - status: 'failed', - }, - { - client: { - _id: '65d91d857b2e523b16d3578c', - name: 'Sincere Sarah', - age: 29, - region: 'Bastrop', - pets: [ - { - isActive: true, - animal: 'small dog', - vet: true, - food: 'HEB Texas Pets', - lbs: 10, - }, - ], - }, - createdOn: new Date('2023-03-20T12:00:00Z'), - deliverBy: new Date('2023-03-20T12:00:00Z'), - foodItems: [ { - brand: 'HEB Texas Pets', - weight: 10, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d3578d', - name: 'Tender Thomas', - age: 46, - region: 'Luling', - pets: [ - { - isActive: true, - animal: 'cat', - vet: false, - food: 'Friskies', - lbs: 7, - }, - ], - }, - createdOn: new Date('2023-04-05T12:00:00Z'), - deliverBy: new Date('2023-04-05T12:00:00Z'), - foodItems: [ - { - brand: 'Friskies', - weight: 7, - }, - ], - status: 'pending', - }, - { - client: { - _id: '65d91d857b2e523b16d3578e', - name: 'Understanding Ursula', - age: 33, - region: 'Wimberley', - pets: [ - { - isActive: true, - animal: 'large dog', - vet: true, - food: 'Foodimals', - lbs: 20, - }, - ], - }, - createdOn: new Date('2023-06-15T12:00:00Z'), - deliverBy: new Date('2023-06-15T12:00:00Z'), - foodItems: [ - { - brand: 'Foodimals', - weight: 20, - }, - ], - status: 'successful', - }, - { - client: { - _id: '65d91d857b2e523b16d3578f', - name: 'Valiant Victor', - age: 47, - region: 'Elgin', - pets: [ - { - isActive: true, - animal: 'cat', - vet: true, - food: 'Fiesta', - lbs: 9, + "isActive": true, + "animal": "small dog", + "vet": true, + "food": { + "kind": "Other", + "lbs": 6 }, - ], - }, - createdOn: new Date('2023-08-02T12:00:00Z'), - deliverBy: new Date('2023-08-02T12:00:00Z'), - foodItems: [ - { - brand: 'Fiesta', - weight: 9, - }, - ], - status: 'successful', + "lbs": 10 + } + ] }, - ]; + "createdOn": "2024-05-12T08:00:00.000Z", + "deliverBy": "2024-05-13T12:00:00.000Z", + "foodItems": [ + { + "brand": "Acme Pet Foods", + "weight": 2 + }, + { + "brand": "Healthy Paws", + "weight": 1.5 + } + ], + "status": "successful" + } + ]; + + + + // currently have the orderData filtered by successful status, the cost by brand has to be changed into cost by animal type useEffect(() => { fetch(process.env.NEXT_PUBLIC_API_BASE_URL + '/orders/all', { @@ -896,13 +487,16 @@ export default function Dashboard() { .then((orderData) => { setOrderData(filterBySuccessfulStatus(orderData)); setDisplayedData(filterBySuccessfulStatus(orderData)); - }); // */ - //setOrderData(filterBySuccessfulStatus(FAKE_ORDER_DATA)); - //setDisplayedData(filterBySuccessfulStatus(FAKE_ORDER_DATA)); - //setOtherBrands(makeOtherBrandsArray(FAKE_ORDER_DATA)); + }); // */ + + /*setOrderData(filterBySuccessfulStatus(FAKE_ORDER_DATA)); + setDisplayedData(filterBySuccessfulStatus(FAKE_ORDER_DATA)); + // setOtherBrands(makeOtherBrandsArray(FAKE_ORDER_DATA)); + //*/ //co nsole.log(otherBrands); }, []); + if (orderData.length === 0) return (
@@ -912,11 +506,7 @@ export default function Dashboard() {
); - const lbsPerBrand = calculateLbsPerBrand(displayedData); - const lbsPerOtherBrands = calculateLbsPerOtherBrands( - displayedData, - otherBrands - ); + const lbsPerAnimal = calculateLbsPerAnimal(displayedData); // CURRENT DATE var today = new Date(); @@ -981,18 +571,9 @@ export default function Dashboard() { countyLocations[county].push(locationName); }); - const brands = [ - 'Friskies', - 'HEB Texas Pets', - 'Nutrena', - 'Wholesomes', - 'Other', - ]; + const petTypes = getTypesOfPets(orderData); - const totalLbs = brands.map((brand) => lbsPerBrand[brand]); - const totalOtherLbs = otherBrands.map( - (otherBrand) => lbsPerOtherBrands[otherBrand] - ); + const totalLbs = petTypes.map((type) => lbsPerAnimal[type]); //co nsole.log(totalOtherLbs); return ( @@ -1119,7 +700,7 @@ export default function Dashboard() { - + @@ -1127,10 +708,10 @@ export default function Dashboard() { - {brands.map((brand, index) => ( + {petTypes.map((type, index) => (
BrandType of Pet Total food orders (lbs)
- {brand} + {type} {totalLbs[index] | 0} @@ -1140,92 +721,6 @@ export default function Dashboard() { ))}
- -