updated the yard with the new ton stuff working through contracts

This commit is contained in:
csawatzky 2026-03-05 12:45:36 -06:00
parent dd6a842fda
commit 9414e30cea
7 changed files with 126 additions and 57 deletions

View file

@ -668,25 +668,31 @@ export default function BinyardDisplay(props: Props) {
} }
}; };
const grainQuantityDisplay = (bushels: number, custom?: pond.CustomInventory) => { const customQuantityDisplay = (customInventory: pond.CustomInventory, bushels: number) => {
if (custom && custom.bushelsPerTonne <= 1) { let amount = bushels
return 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
}
switch (getGrainUnit()) { const supportedGrainDisplay = (grain: pond.Grain, bushels: number) => {
case pond.GrainUnit.GRAIN_UNIT_TONNE: const describer = GrainDescriber(grain)
return " mT"; let amount = bushels
case pond.GrainUnit.GRAIN_UNIT_TON: if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
return " t"; amount = bushels/describer.bushelsPerTonne
default: }else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
return bushels; amount = bushels/describer.bushelsPerTon
} }
return Math.round(amount*100)/100
} }
const binUtilizationList = () => { const binUtilizationList = () => {
const hasInventory = binMetrics && binMetrics.grainInventory.length > 0; const hasInventory = binMetrics && binMetrics.grainInventory.length > 0;
console.log(binMetrics)
const useWeight = getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT;
return ( return (
<Accordion <Accordion
className={classes.accordion} className={classes.accordion}
@ -728,16 +734,8 @@ export default function BinyardDisplay(props: Props) {
<BinUtilizationChart <BinUtilizationChart
grain={inv.grainType} grain={inv.grainType}
customUnit={grainUnitDisplay()} customUnit={grainUnitDisplay()}
bushelAmount={ bushelAmount={supportedGrainDisplay(inv.grainType, inv.bushelAmount)}
useWeight bushelCapacity={supportedGrainDisplay(inv.grainType, inv.bushelCapacity)}
? inv.bushelAmount / GrainDescriber(inv.grainType).bushelsPerTonne
: inv.bushelAmount
}
bushelCapacity={
useWeight
? inv.bushelCapacity / GrainDescriber(inv.grainType).bushelsPerTonne
: inv.bushelCapacity
}
onClick={() => { onClick={() => {
setContentFilter(pond.Grain[inv.grainType]); setContentFilter(pond.Grain[inv.grainType]);
loadMoreBins(pond.Grain[inv.grainType]); loadMoreBins(pond.Grain[inv.grainType]);
@ -757,8 +755,8 @@ export default function BinyardDisplay(props: Props) {
cap = cap * 35.239; cap = cap * 35.239;
unit = " L"; unit = " L";
}else{ }else{
amount amount = customQuantityDisplay(inv, amount)
cap cap = customQuantityDisplay(inv, cap)
unit = grainUnitDisplay(inv) unit = grainUnitDisplay(inv)
} }

View file

@ -120,12 +120,17 @@ export default function BinLevelOverTime(props: Props) {
let currentTime = moment().valueOf(); let currentTime = moment().valueOf();
if (data.length === 0) { if (data.length === 0) {
let bushels = bin.bushels(); 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({ data.push({
value: fertilizerBin value: fertilizerBin
? Math.round(bushels * 35.239) ? Math.round(bushels * 35.239)
: getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT : grainDisplay,
? Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100
: bushels,
timestamp: currentTime timestamp: currentTime
}); });
} }
@ -151,9 +156,12 @@ export default function BinLevelOverTime(props: Props) {
if (fertilizerBin && cap) { if (fertilizerBin && cap) {
cap = cap * 35.239; cap = cap * 35.239;
} }
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && cap) { if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && cap) {
cap = cap / bin.bushelsPerTonne(); cap = cap / bin.bushelsPerTonne();
} }
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && cap) {
cap = cap / bin.bushelsPerTon();
}
setCapacity(cap); setCapacity(cap);
let autoBarData: BarData[] = []; let autoBarData: BarData[] = [];
@ -190,12 +198,17 @@ export default function BinLevelOverTime(props: Props) {
if (autoBarData.length === 0) { if (autoBarData.length === 0) {
let bushels = bin.bushels(); let bushels = bin.bushels();
let currentTime = moment().valueOf(); 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({ autoBarData.push({
value: fertilizerBin value: fertilizerBin
? Math.round(bushels * 35.239) ? Math.round(bushels * 35.239)
: getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT : grainDisplay,
? Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100
: bushels,
timestamp: currentTime timestamp: currentTime
}); });
} }

View file

@ -102,12 +102,21 @@ export default function ContractSettings(props: Props) {
useEffect(() => { useEffect(() => {
switch (contractType) { switch (contractType) {
case pond.ContractType.CONTRACT_TYPE_GRAIN: 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({ setLabels({
sizeLabel: "Total Grain on Contract", sizeLabel: "Total Grain on Contract",
commodityLabel: "Select Grain Type", commodityLabel: "Select Grain Type",
conversionLabel: "Bushels Per Tonne", conversionLabel: conversionLabel,
deliveryLabel: "Grain Delivered", deliveryLabel: "Grain Delivered",
adornment: getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? "mT" : "bu" adornment: adornment
}); });
break; break;
default: default:
@ -148,7 +157,12 @@ export default function ContractSettings(props: Props) {
}; };
const submit = () => { 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)) const deliveredVal = isNaN(parseFloat(deliveredAmount))
? 0 ? 0
: Math.round(Contract.toStoredUnit(parseFloat(deliveredAmount), contractType, conVal)); : Math.round(Contract.toStoredUnit(parseFloat(deliveredAmount), contractType, conVal));
@ -490,7 +504,9 @@ export default function ContractSettings(props: Props) {
InputLabelProps={{ shrink: true }} InputLabelProps={{ shrink: true }}
error={isNaN(parseFloat(conversionValue))} error={isNaN(parseFloat(conversionValue))}
helperText={isNaN(parseFloat(conversionValue)) ? "Must be a valid number" : ""} helperText={isNaN(parseFloat(conversionValue)) ? "Must be a valid number" : ""}
onChange={e => setConversionValue(e.target.value)} onChange={e => {
setConversionValue(e.target.value)
}}
/> />
</React.Fragment> </React.Fragment>
)} )}

View file

@ -278,6 +278,10 @@ export default function Router() {
path="/:groupID/devices/:deviceID" path="/:groupID/devices/:deviceID"
element={<DevicePage />} element={<DevicePage />}
/> />
<Route
path="/:groupID/devices/:deviceID/components/:componentID"
element={<DeviceComponent />}
/>
<Route <Route
path="/:groupID/devices/:deviceID/*" path="/:groupID/devices/:deviceID/*"
element={<RelativeRoutes />} element={<RelativeRoutes />}

View file

@ -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 binUtilizationList = () => {
const hasInventory = binMetrics && binMetrics.grainInventory.length > 0; const hasInventory = binMetrics && binMetrics.grainInventory.length > 0;
const useWeight = getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT;
return ( return (
<Accordion <Accordion
className={classes.accordion} className={classes.accordion}
@ -972,17 +1010,9 @@ export default function Bins(props: Props) {
<ImageListItem key={key}> <ImageListItem key={key}>
<BinUtilizationChart <BinUtilizationChart
grain={inv.grainType} grain={inv.grainType}
customUnit={useWeight ? " mT" : " bu"} customUnit={grainUnitDisplay()}
bushelAmount={ bushelAmount={supportedGrainDisplay(inv.grainType, inv.bushelAmount)}
useWeight bushelCapacity={supportedGrainDisplay(inv.grainType, inv.bushelCapacity)}
? inv.bushelAmount / GrainDescriber(inv.grainType).bushelsPerTonne
: inv.bushelAmount
}
bushelCapacity={
useWeight
? inv.bushelCapacity / GrainDescriber(inv.grainType).bushelsPerTonne
: inv.bushelCapacity
}
onClick={() => { onClick={() => {
setContentFilter(pond.Grain[inv.grainType]); setContentFilter(pond.Grain[inv.grainType]);
loadMoreBins(pond.Grain[inv.grainType]); loadMoreBins(pond.Grain[inv.grainType]);
@ -1001,11 +1031,10 @@ export default function Bins(props: Props) {
amount = amount * 35.239; amount = amount * 35.239;
cap = cap * 35.239; cap = cap * 35.239;
unit = " L"; unit = " L";
} } else {
if (useWeight && inv.bushelsPerTonne > 1) { amount = customQuantityDisplay(inv, amount)
amount = amount / inv.bushelsPerTonne; cap = customQuantityDisplay(inv, cap)
cap = cap / inv.bushelsPerTonne; unit = grainUnitDisplay(inv);
unit = " mT";
} }
return ( return (

View file

@ -168,7 +168,8 @@ export default function SignupCallback () {
variant="outlined" variant="outlined"
InputLabelProps={{ shrink: true }}> InputLabelProps={{ shrink: true }}>
<MenuItem value={pond.GrainUnit.GRAIN_UNIT_BUSHELS}>Bushels (bu)</MenuItem> <MenuItem value={pond.GrainUnit.GRAIN_UNIT_BUSHELS}>Bushels (bu)</MenuItem>
<MenuItem value={pond.GrainUnit.GRAIN_UNIT_WEIGHT}>Tonnes (mT)</MenuItem> <MenuItem value={pond.GrainUnit.GRAIN_UNIT_TONNE}>Tonnes (mT)</MenuItem>
<MenuItem value={pond.GrainUnit.GRAIN_UNIT_TON}>US Tons (t)</MenuItem>
</TextField> </TextField>
</Grid2> </Grid2>
)} )}

View file

@ -13,6 +13,16 @@ export default function TransactionDataDisplay(props: Props) {
const { transaction } = props; const { transaction } = props;
console.log(transaction) 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 = () => { const display = () => {
let transactionData = transaction.transaction.transaction; let transactionData = transaction.transaction.transaction;
if (transactionData) { if (transactionData) {
@ -28,9 +38,7 @@ export default function TransactionDataDisplay(props: Props) {
</Typography> </Typography>
<Typography>Variant: {gt.subtype}</Typography> <Typography>Variant: {gt.subtype}</Typography>
<Typography> <Typography>
{getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && gt.bushelsPerTonne > 1 {grainDisplay(gt)}
? "Weight: " + gt.bushels / gt.bushelsPerTonne + " mT"
: "Bushels: " + gt.bushels}
</Typography> </Typography>
<Typography>Message: {gt.message}</Typography> <Typography>Message: {gt.message}</Typography>
</Box> </Box>