From 9414e30ceabdc3cd59c192619e6fba513e8a7aff Mon Sep 17 00:00:00 2001 From: csawatzky Date: Thu, 5 Mar 2026 12:45:36 -0600 Subject: [PATCH] updated the yard with the new ton stuff working through contracts --- src/bin/BinyardDisplay.tsx | 48 ++++++++-------- src/bin/graphs/BinLevelOverTime.tsx | 27 ++++++--- src/contract/contractSettings.tsx | 24 ++++++-- src/navigation/Router.tsx | 4 ++ src/pages/Bins.tsx | 63 +++++++++++++++------ src/pages/SignupCallback.tsx | 3 +- src/transactions/transactionDataDisplay.tsx | 14 ++++- 7 files changed, 126 insertions(+), 57 deletions(-) diff --git a/src/bin/BinyardDisplay.tsx b/src/bin/BinyardDisplay.tsx index 667b558..b639759 100644 --- a/src/bin/BinyardDisplay.tsx +++ b/src/bin/BinyardDisplay.tsx @@ -668,25 +668,31 @@ export default function BinyardDisplay(props: Props) { } }; - const grainQuantityDisplay = (bushels: number, custom?: pond.CustomInventory) => { - if (custom && custom.bushelsPerTonne <= 1) { - return bushels; + const customQuantityDisplay = (customInventory: pond.CustomInventory, bushels: number) => { + let amount = bushels + if(customInventory.bushelsPerTonne > 1){ + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){ + amount = bushels/customInventory.bushelsPerTonne + }else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){ + amount = bushels/(customInventory.bushelsPerTonne*0.907) + } } - - switch (getGrainUnit()) { - case pond.GrainUnit.GRAIN_UNIT_TONNE: - return " mT"; - case pond.GrainUnit.GRAIN_UNIT_TON: - return " t"; - default: - return bushels; + return Math.round(amount*100)/100 + } + + const supportedGrainDisplay = (grain: pond.Grain, bushels: number) => { + const describer = GrainDescriber(grain) + let amount = bushels + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){ + amount = bushels/describer.bushelsPerTonne + }else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){ + amount = bushels/describer.bushelsPerTon } + return Math.round(amount*100)/100 } const binUtilizationList = () => { const hasInventory = binMetrics && binMetrics.grainInventory.length > 0; - console.log(binMetrics) - const useWeight = getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT; return ( { setContentFilter(pond.Grain[inv.grainType]); loadMoreBins(pond.Grain[inv.grainType]); @@ -757,8 +755,8 @@ export default function BinyardDisplay(props: Props) { cap = cap * 35.239; unit = " L"; }else{ - amount - cap + amount = customQuantityDisplay(inv, amount) + cap = customQuantityDisplay(inv, cap) unit = grainUnitDisplay(inv) } diff --git a/src/bin/graphs/BinLevelOverTime.tsx b/src/bin/graphs/BinLevelOverTime.tsx index 1d4a657..a691fe6 100644 --- a/src/bin/graphs/BinLevelOverTime.tsx +++ b/src/bin/graphs/BinLevelOverTime.tsx @@ -120,12 +120,17 @@ export default function BinLevelOverTime(props: Props) { let currentTime = moment().valueOf(); if (data.length === 0) { let bushels = bin.bushels(); + let grainDisplay = bushels + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){ + grainDisplay = Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100; + } + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTon() > 1){ + grainDisplay = Math.round((bushels / bin.bushelsPerTon()) * 100) / 100; + } data.push({ value: fertilizerBin ? Math.round(bushels * 35.239) - : getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT - ? Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100 - : bushels, + : grainDisplay, timestamp: currentTime }); } @@ -151,9 +156,12 @@ export default function BinLevelOverTime(props: Props) { if (fertilizerBin && cap) { cap = cap * 35.239; } - if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && cap) { + if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && cap) { cap = cap / bin.bushelsPerTonne(); } + if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && cap) { + cap = cap / bin.bushelsPerTon(); + } setCapacity(cap); let autoBarData: BarData[] = []; @@ -190,12 +198,17 @@ export default function BinLevelOverTime(props: Props) { if (autoBarData.length === 0) { let bushels = bin.bushels(); let currentTime = moment().valueOf(); + let grainDisplay = bushels + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){ + grainDisplay = Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100; + } + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTon() > 1){ + grainDisplay = Math.round((bushels / bin.bushelsPerTon()) * 100) / 100; + } autoBarData.push({ value: fertilizerBin ? Math.round(bushels * 35.239) - : getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT - ? Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100 - : bushels, + : grainDisplay, timestamp: currentTime }); } diff --git a/src/contract/contractSettings.tsx b/src/contract/contractSettings.tsx index 097c9d5..692a481 100644 --- a/src/contract/contractSettings.tsx +++ b/src/contract/contractSettings.tsx @@ -102,12 +102,21 @@ export default function ContractSettings(props: Props) { useEffect(() => { switch (contractType) { case pond.ContractType.CONTRACT_TYPE_GRAIN: + let conversionLabel = "Bushels Per Tonne" + let adornment = "bu" + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){ + adornment = "mT" + } + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){ + conversionLabel = "Bushels Per Ton" + adornment = "t" + } setLabels({ sizeLabel: "Total Grain on Contract", commodityLabel: "Select Grain Type", - conversionLabel: "Bushels Per Tonne", + conversionLabel: conversionLabel, deliveryLabel: "Grain Delivered", - adornment: getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? "mT" : "bu" + adornment: adornment }); break; default: @@ -148,7 +157,12 @@ export default function ContractSettings(props: Props) { }; const submit = () => { - const conVal = isNaN(parseFloat(conversionValue)) ? 1 : parseFloat(conversionValue); + let conVal = isNaN(parseFloat(conversionValue)) ? 1 : parseFloat(conversionValue); + if(contractType === pond.ContractType.CONTRACT_TYPE_GRAIN){ + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){ + conVal = conVal/1.102 //convert the ton they entered to mT to be sotred in the contract + } + } const deliveredVal = isNaN(parseFloat(deliveredAmount)) ? 0 : Math.round(Contract.toStoredUnit(parseFloat(deliveredAmount), contractType, conVal)); @@ -490,7 +504,9 @@ export default function ContractSettings(props: Props) { InputLabelProps={{ shrink: true }} error={isNaN(parseFloat(conversionValue))} helperText={isNaN(parseFloat(conversionValue)) ? "Must be a valid number" : ""} - onChange={e => setConversionValue(e.target.value)} + onChange={e => { + setConversionValue(e.target.value) + }} /> )} diff --git a/src/navigation/Router.tsx b/src/navigation/Router.tsx index cb97f67..94ce101 100644 --- a/src/navigation/Router.tsx +++ b/src/navigation/Router.tsx @@ -278,6 +278,10 @@ export default function Router() { path="/:groupID/devices/:deviceID" element={} /> + } + /> } diff --git a/src/pages/Bins.tsx b/src/pages/Bins.tsx index f17125e..1b9c75e 100644 --- a/src/pages/Bins.tsx +++ b/src/pages/Bins.tsx @@ -928,9 +928,47 @@ export default function Bins(props: Props) { ); }; + const grainUnitDisplay = (custom?: pond.CustomInventory) => { + // If custom and not convertible, always bushels + if (custom && custom.bushelsPerTonne <= 1) { + return " bu"; + } + + switch (getGrainUnit()) { + case pond.GrainUnit.GRAIN_UNIT_TONNE: + return " mT"; + case pond.GrainUnit.GRAIN_UNIT_TON: + return " t"; + default: + return " bu"; + } + }; + + const customQuantityDisplay = (customInventory: pond.CustomInventory, bushels: number) => { + let amount = bushels + if(customInventory.bushelsPerTonne > 1){ + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){ + amount = bushels/customInventory.bushelsPerTonne + }else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){ + amount = bushels/(customInventory.bushelsPerTonne*0.907) + } + } + return Math.round(amount*100)/100 + } + + const supportedGrainDisplay = (grain: pond.Grain, bushels: number) => { + const describer = GrainDescriber(grain) + let amount = bushels + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){ + amount = bushels/describer.bushelsPerTonne + }else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){ + amount = bushels/describer.bushelsPerTon + } + return Math.round(amount*100)/100 + } + const binUtilizationList = () => { const hasInventory = binMetrics && binMetrics.grainInventory.length > 0; - const useWeight = getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT; return ( { setContentFilter(pond.Grain[inv.grainType]); loadMoreBins(pond.Grain[inv.grainType]); @@ -1001,11 +1031,10 @@ export default function Bins(props: Props) { amount = amount * 35.239; cap = cap * 35.239; unit = " L"; - } - if (useWeight && inv.bushelsPerTonne > 1) { - amount = amount / inv.bushelsPerTonne; - cap = cap / inv.bushelsPerTonne; - unit = " mT"; + } else { + amount = customQuantityDisplay(inv, amount) + cap = customQuantityDisplay(inv, cap) + unit = grainUnitDisplay(inv); } return ( diff --git a/src/pages/SignupCallback.tsx b/src/pages/SignupCallback.tsx index 43c8c5b..e315eda 100644 --- a/src/pages/SignupCallback.tsx +++ b/src/pages/SignupCallback.tsx @@ -168,7 +168,8 @@ export default function SignupCallback () { variant="outlined" InputLabelProps={{ shrink: true }}> Bushels (bu) - Tonnes (mT) + Tonnes (mT) + US Tons (t) )} diff --git a/src/transactions/transactionDataDisplay.tsx b/src/transactions/transactionDataDisplay.tsx index 1b8d91b..873192b 100644 --- a/src/transactions/transactionDataDisplay.tsx +++ b/src/transactions/transactionDataDisplay.tsx @@ -13,6 +13,16 @@ export default function TransactionDataDisplay(props: Props) { const { transaction } = props; console.log(transaction) + const grainDisplay = (gt: pond.GrainTransaction) => { + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && gt.bushelsPerTonne > 1){ + return "Weight: " + Math.round(gt.bushels / gt.bushelsPerTonne*100)/100 + " mT" + } + if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && gt.bushelsPerTon > 1){ + return "Weight: " + Math.round(gt.bushels / gt.bushelsPerTon*100)/100 + " t" + } + return "Bushels: " + gt.bushels + } + const display = () => { let transactionData = transaction.transaction.transaction; if (transactionData) { @@ -28,9 +38,7 @@ export default function TransactionDataDisplay(props: Props) { Variant: {gt.subtype} - {getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && gt.bushelsPerTonne > 1 - ? "Weight: " + gt.bushels / gt.bushelsPerTonne + " mT" - : "Bushels: " + gt.bushels} + {grainDisplay(gt)} Message: {gt.message}