From 97bbd4149266ce1b2968f323c166ba8c632d1662 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Tue, 8 Apr 2025 11:43:39 -0600 Subject: [PATCH 1/3] adding the transaction page --- src/bin/BinSettings.tsx | 30 ++-- src/grain/GrainTransaction.tsx | 4 + src/models/Transaction.ts | 19 +++ src/navigation/Router.tsx | 2 + src/pages/Transactions.tsx | 165 ++++++++++++++++++++ src/transactions/transactionDataDisplay.tsx | 42 +++++ src/transactions/transactionViewer.tsx | 124 +++++++++++++++ 7 files changed, 371 insertions(+), 15 deletions(-) create mode 100644 src/models/Transaction.ts create mode 100644 src/pages/Transactions.tsx create mode 100644 src/transactions/transactionDataDisplay.tsx create mode 100644 src/transactions/transactionViewer.tsx diff --git a/src/bin/BinSettings.tsx b/src/bin/BinSettings.tsx index 345812e..8816314 100644 --- a/src/bin/BinSettings.tsx +++ b/src/bin/BinSettings.tsx @@ -50,7 +50,7 @@ import { // import FanPicker from "fans/fanPicker"; import { GrainOptions, ToGrainOption } from "grain"; import GrainDescriber from "grain/GrainDescriber"; -// import GrainTransaction from "grain/GrainTransaction"; +import GrainTransaction from "grain/GrainTransaction"; import { GetGrainUseOptions, ToGrainUseOption } from "grain/GrainUse"; import { useMobile, useSnackbar } from "hooks"; import { clone, cloneDeep } from "lodash"; @@ -424,6 +424,7 @@ export default function BinSettings(props: Props) { }; const updateBin = () => { + console.log("bin settings update") // If initial moisture is updated, so does the timestamp if (form.inventory?.initialMoisture !== bin?.settings.inventory?.initialMoisture) { if (form.inventory) form.inventory.initialTimestamp = moment().format(); @@ -450,7 +451,7 @@ export default function BinSettings(props: Props) { form.lowTemp = lowTempC; form.autoGrainNode = autoTopNode; if (form.inventory) form.inventory.inventoryControl = inventoryControl; - + console.log("bin api update") binAPI .updateBin(bin.key(), form) .then(response => { @@ -473,19 +474,18 @@ export default function BinSettings(props: Props) { newBin.settings.inventory.grainBushels = bin.settings.inventory?.grainBushels ?? 0; //but also need to use the old inventory amount so the diff is applied correctly } return ( - // { - // setGrainUpdate(false); - // setGrainDiff(0); - // }} - // callback={() => { - // close(true); - // }} - // /> - null + { + setGrainUpdate(false); + setGrainDiff(0); + }} + callback={() => { + close(true); + }} + /> ); } }; diff --git a/src/grain/GrainTransaction.tsx b/src/grain/GrainTransaction.tsx index 469cbc7..562e5b2 100644 --- a/src/grain/GrainTransaction.tsx +++ b/src/grain/GrainTransaction.tsx @@ -203,6 +203,7 @@ export default function GrainTransaction(props: Props) { //create a transaction to enter into the table const createTransaction = (finalVal: number) => { + console.log("create transaction") let dest = selectedDestination; let source = selectedSource; let bpt = 1; @@ -248,13 +249,16 @@ export default function GrainTransaction(props: Props) { grainTransaction.subtype = obj.subtype(); } } + console.log(newTransaction) transactionAPI.addTransaction(newTransaction, imageIDs).then(resp => { + console.log(resp) newTransaction.key = resp.data.key; closeDialogs(true, newTransaction); }); }; const updateInventory = () => { + console.log("update inventory") //this is the amount to add to the destination let destinationAdd = Math.abs( isNaN(parseFloat(grainChangeVal)) ? 1 : parseFloat(grainChangeVal) diff --git a/src/models/Transaction.ts b/src/models/Transaction.ts new file mode 100644 index 0000000..b5d3804 --- /dev/null +++ b/src/models/Transaction.ts @@ -0,0 +1,19 @@ +import { cloneDeep } from "lodash"; +import { pond } from "protobuf-ts/pond"; +import { or } from "utils/types"; + +export class Transaction { + public transaction: pond.Transaction = pond.Transaction.create(); + + public static create(pb?: pond.Transaction): Transaction { + let my = new Transaction(); + if (pb) { + my.transaction = pond.Transaction.fromObject(cloneDeep(or(pb, {}))); + } + return my; + } + + public static any(data: any): Transaction { + return Transaction.create(pond.Transaction.fromObject(cloneDeep(data))); + } +} \ No newline at end of file diff --git a/src/navigation/Router.tsx b/src/navigation/Router.tsx index a281c13..5d1e931 100644 --- a/src/navigation/Router.tsx +++ b/src/navigation/Router.tsx @@ -18,6 +18,7 @@ import Site from "pages/Site"; import Heaters from "pages/Heaters"; import Heater from "pages/Heater"; import Tasks from "pages/Tasks"; +import Transactions from "pages/Transactions"; //import Site from "pages/Site"; const DeviceHistory = lazy(() => import("pages/DeviceHistory")); @@ -301,6 +302,7 @@ export default function Router(props: Props) { {/* Hello!} /> */} } /> } /> + } /> {/* Map pages */} } /> diff --git a/src/pages/Transactions.tsx b/src/pages/Transactions.tsx new file mode 100644 index 0000000..1f2a747 --- /dev/null +++ b/src/pages/Transactions.tsx @@ -0,0 +1,165 @@ +import { useEffect, useState } from "react"; +import PageContainer from "./PageContainer"; +import { Box, Grid2 as Grid, TextField, Typography } from "@mui/material"; +import { Moment } from "moment"; +import { pond } from "protobuf-ts/pond"; +import SearchSelect, { Option } from "common/SearchSelect"; +import TransactionViewer from "transactions/transactionViewer"; +import { TransactionOptions } from "objects/ObjectDescriber"; +import { GetDefaultDateRange } from "common/time/DateRange"; +import TimeBar from "common/time/TimeBar"; +import { useTransactionAPI } from "providers"; +import { Transaction } from "models/Transaction"; +import { makeStyles } from "@mui/styles"; + +const useStyles = makeStyles(() => { + return ({ + page: { + padding: 10 + } + }); +}); + +//this page will have the dropdown selectors to set the variables for query +export default function Transactions() { + const classes = useStyles(); + const defaultDateRange = GetDefaultDateRange(); + const [startDate, setStartDate] = useState(defaultDateRange.start); + const [endDate, setEndDate] = useState(defaultDateRange.end); + //these two variables are the object type + const [fromObject, setFromObject] = useState(undefined); + const [toObject, setToObject] = useState(undefined); + //these are simply for controlling what is shown in the select boxes + const [selectedFromObject, setSelectedFromObject] = useState