working on US ton stuff

This commit is contained in:
csawatzky 2026-03-04 12:51:10 -06:00
parent 3401cc7c15
commit 29d9e7377c
18 changed files with 474 additions and 117 deletions

View file

@ -225,12 +225,19 @@ export default function GrainTransaction(props: Props) {
const createTransaction = (finalVal: number) => {
let dest = selectedDestination;
let source = selectedSource;
let bpt = 1;
let bPerTonne = 1;
let bPerTon = 1;
//use the sources bushel per tonne if one was selected otherwise use the destination
if (source) {
bpt = source.value.bushelsPerTonne();
bPerTonne = source.value.bushelsPerTonne();
if(source.value.bushelsPerTon){
bPerTon = source.value.bushelsPerTon()
}
} else if (dest) {
bpt = dest.value.bushelsPerTonne();
bPerTonne = dest.value.bushelsPerTonne();
if(dest.value.bushelsPerTon){
bPerTon = dest.value.bushelsPerTon()
}
}
let newTransaction = pond.Transaction.create({
@ -239,7 +246,8 @@ export default function GrainTransaction(props: Props) {
grainTransaction: pond.GrainTransaction.create({
bushels: finalVal,
message: grainMessage,
bushelsPerTonne: bpt
bushelsPerTonne: bPerTonne,
bushelsPerTon: bPerTonne * 0.907
})
})
});
@ -449,6 +457,17 @@ export default function GrainTransaction(props: Props) {
);
};
const grainUnitDisplay = () => {
switch (getGrainUnit()){
case pond.GrainUnit.GRAIN_UNIT_TONNE:
return "mT"
case pond.GrainUnit.GRAIN_UNIT_TON:
return "t"
default:
return "bu"
}
}
return (
<ResponsiveDialog
open={open}
@ -506,14 +525,14 @@ export default function GrainTransaction(props: Props) {
InputProps={{
endAdornment: (
<InputAdornment position="end">
{getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? "mT" : "bu"}
{grainUnitDisplay()}
</InputAdornment>
)
}}
onChange={e => {
//if the user is viewing the grain in weight
let grainVal = e.target.value;
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT) {
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE) {
//need to convert what the user input (weight) into what is actually stored (bushels)
//use source of the conversion value if it was selected, otherwise use the destination
if (!isNaN(parseFloat(e.target.value))) {
@ -523,6 +542,22 @@ export default function GrainTransaction(props: Props) {
grainVal = (+grainVal * selectedDestination.value.bushelsPerTonne()).toFixed(2);
}
}
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE) {
if (!isNaN(parseFloat(e.target.value))) {
if (selectedSource) {
if(selectedSource.value.bushelsPerTonne){
grainVal = (+grainVal * selectedSource.value.bushelsPerTon()).toFixed(2);
}else{
grainVal = (+grainVal * (selectedSource.value.bushelsPerTonne() * 0.907)).toFixed(2);
}
} else if (selectedDestination) {
if(selectedDestination.value.bushelsPerTonne){
grainVal = (+grainVal * selectedDestination.value.bushelsPerTon()).toFixed(2);
}else{
grainVal = (+grainVal * (selectedDestination.value.bushelsPerTonne() * 0.907)).toFixed(2);
}
}
}
}
setGrainEntry(e.target.value);
setGrainChangeVal(grainVal);