finished updating for US tons
This commit is contained in:
parent
9414e30cea
commit
62c2f6a63c
16 changed files with 180 additions and 211 deletions
|
|
@ -36,11 +36,14 @@ export default function GrainBagInventoryGraph(props: Props) {
|
|||
//let time = hist.timestamp;
|
||||
let val = hist.object.grainBagSettings.currentBushels ?? 0;
|
||||
if (
|
||||
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT &&
|
||||
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE &&
|
||||
grainBag.bushelsPerTonne() > 1
|
||||
) {
|
||||
val = Math.round((val / grainBag.bushelsPerTonne()) * 100) / 100;
|
||||
}
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
|
||||
val = Math.round((val / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
|
||||
}
|
||||
if (val !== lastBushels) {
|
||||
lastBushels = val;
|
||||
barData.push({
|
||||
|
|
@ -51,13 +54,16 @@ export default function GrainBagInventoryGraph(props: Props) {
|
|||
}
|
||||
});
|
||||
if (barData.length === 0) {
|
||||
let val = grainBag.bushels()
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1){
|
||||
val = grainBag.bushels() / grainBag.bushelsPerTonne()
|
||||
}
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
|
||||
val = grainBag.bushels() / (grainBag.bushelsPerTonne() * 0.907)
|
||||
}
|
||||
barData.push({
|
||||
timestamp: moment.now().valueOf(),
|
||||
value:
|
||||
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT &&
|
||||
grainBag.bushelsPerTonne() > 1
|
||||
? Math.round((grainBag.bushels() / grainBag.bushelsPerTonne()) * 100) / 100
|
||||
: grainBag.bushels()
|
||||
value: Math.round(val*100)/100
|
||||
});
|
||||
}
|
||||
setData(barData);
|
||||
|
|
@ -71,6 +77,17 @@ export default function GrainBagInventoryGraph(props: Props) {
|
|||
}
|
||||
}, [grainBagAPI, grainBag, startDate, endDate, openSnack]); //eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const maxYAxis = () => {
|
||||
let val = grainBag.capacity()
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||
val = Math.round((val / grainBag.bushelsPerTonne()) * 100) / 100;
|
||||
}
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
|
||||
val = Math.round((val / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
return (
|
||||
<Card raised>
|
||||
<Box padding={2}>
|
||||
|
|
@ -87,11 +104,7 @@ export default function GrainBagInventoryGraph(props: Props) {
|
|||
}
|
||||
data={data}
|
||||
yMin={0}
|
||||
yMax={
|
||||
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT
|
||||
? grainBag.capacity() / grainBag.bushelsPerTonne()
|
||||
: grainBag.capacity()
|
||||
}
|
||||
yMax={maxYAxis()}
|
||||
customHeight={customHeight}
|
||||
useGradient
|
||||
labels
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ export default function GrainBagSettings(props: Props) {
|
|||
const theme = useTheme();
|
||||
const [grainUpdate, setGrainUpdate] = useState(false);
|
||||
const [grainDiff, setGrainDiff] = useState(0);
|
||||
const [bushelsPerTonne, setBushelsPerTonne] = useState(0);
|
||||
const [bushelConversion, setBushelConversion] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (grainBag) {
|
||||
|
|
@ -84,8 +84,10 @@ export default function GrainBagSettings(props: Props) {
|
|||
: grainBag.settings.length
|
||||
);
|
||||
let grainVal = grainBag.bushels();
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT) {
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE) {
|
||||
grainVal = grainBag.bushels() / grainBag.bushelsPerTonne();
|
||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
|
||||
grainVal = grainBag.bushels() / (grainBag.bushelsPerTonne() * 0.907)
|
||||
}
|
||||
setGrainFill(grainVal.toFixed(2));
|
||||
setBagName(grainBag.name());
|
||||
|
|
@ -117,6 +119,10 @@ export default function GrainBagSettings(props: Props) {
|
|||
|
||||
const submit = () => {
|
||||
//if a bag was passed in do an update
|
||||
let tonneConversion = bushelConversion
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||
tonneConversion = bushelConversion / 0.907
|
||||
}
|
||||
if (grainBag) {
|
||||
grainBag.title = bagName;
|
||||
grainBag.settings.initialMoisture = initialMoisture;
|
||||
|
|
@ -127,7 +133,7 @@ export default function GrainBagSettings(props: Props) {
|
|||
grainBag.settings.bushelCapacity = grainCapacity;
|
||||
grainBag.settings.grainSubtype = grainSubtype;
|
||||
grainBag.settings.fillDate = fillDate;
|
||||
grainBag.settings.bushelsPerTonne = bushelsPerTonne;
|
||||
grainBag.settings.bushelsPerTonne = tonneConversion;
|
||||
grainBag.settings.storageType = isCustom
|
||||
? pond.BinStorage.BIN_STORAGE_UNSUPPORTED_GRAIN
|
||||
: pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN;
|
||||
|
|
@ -161,7 +167,7 @@ export default function GrainBagSettings(props: Props) {
|
|||
settings.currentBushels = grainBushels;
|
||||
settings.grainSubtype = grainSubtype;
|
||||
settings.fillDate = fillDate;
|
||||
settings.bushelsPerTonne = bushelsPerTonne;
|
||||
settings.bushelsPerTonne = tonneConversion;
|
||||
settings.storageType = isCustom
|
||||
? pond.BinStorage.BIN_STORAGE_UNSUPPORTED_GRAIN
|
||||
: pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN;
|
||||
|
|
@ -206,10 +212,10 @@ export default function GrainBagSettings(props: Props) {
|
|||
/>
|
||||
<TextField
|
||||
label="Bushels Per Tonne"
|
||||
value={bushelsPerTonne}
|
||||
value={bushelConversion}
|
||||
type="number"
|
||||
onChange={event => {
|
||||
setBushelsPerTonne(+event.target.value);
|
||||
setBushelConversion(+event.target.value);
|
||||
}}
|
||||
fullWidth
|
||||
className={classes.bottomSpacing}
|
||||
|
|
@ -228,7 +234,7 @@ export default function GrainBagSettings(props: Props) {
|
|||
? pond.Grain[option.value as keyof typeof pond.Grain]
|
||||
: pond.Grain.GRAIN_INVALID;
|
||||
setSupportedGrainType(newGrainType);
|
||||
setBushelsPerTonne(GrainDescriber(newGrainType).bushelsPerTonne);
|
||||
setBushelConversion(GrainDescriber(newGrainType).bushelsPerTonne);
|
||||
setSelectedGrainOp(option);
|
||||
}}
|
||||
group
|
||||
|
|
@ -247,6 +253,18 @@ export default function GrainBagSettings(props: Props) {
|
|||
return invalid;
|
||||
};
|
||||
|
||||
const grainUnitDisplay = () => {
|
||||
if(bushelConversion > 1){
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||
return "mT"
|
||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||
return "t"
|
||||
}
|
||||
}else{
|
||||
return "bu"
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<GrainTransaction
|
||||
|
|
@ -390,30 +408,24 @@ export default function GrainBagSettings(props: Props) {
|
|||
className={classes.bottomSpacing}
|
||||
/>
|
||||
<TextField
|
||||
label={
|
||||
"Current " +
|
||||
(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && bushelsPerTonne > 0
|
||||
? "Weight"
|
||||
: "Bushels")
|
||||
}
|
||||
label={"Current Inventory"}
|
||||
fullWidth
|
||||
type="number"
|
||||
variant="outlined"
|
||||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && bushelsPerTonne > 0
|
||||
? "mT"
|
||||
: "bu"}
|
||||
{grainUnitDisplay()}
|
||||
</InputAdornment>
|
||||
)
|
||||
}}
|
||||
value={grainFill}
|
||||
onChange={e => {
|
||||
let bushelVal = +e.target.value;
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT) {
|
||||
//convert the number as a weight into the bushel value
|
||||
bushelVal = +e.target.value * (bushelsPerTonne > 0 ? bushelsPerTonne : 1);
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE || getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
|
||||
//convert the number as a weight into the bushel value, no changing or conversions necessary
|
||||
// since these are both user entered fields and should be the same unit (ton or tonne)
|
||||
bushelVal = +e.target.value * (bushelConversion > 0 ? bushelConversion : 1);
|
||||
}
|
||||
if (bushelVal > grainCapacity) {
|
||||
bushelVal = grainCapacity;
|
||||
|
|
|
|||
|
|
@ -83,12 +83,19 @@ export default function GrainBagVisualizer(props: Props) {
|
|||
const grainOverlay = () => {
|
||||
let displayPending = pendingGrainAmount;
|
||||
let displayDiff = grainDiff;
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && grainBag.bushelsPerTonne() > 1) {
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1) {
|
||||
if (displayPending && displayDiff) {
|
||||
displayPending = Math.round((displayPending / grainBag.bushelsPerTonne()) * 100) / 100;
|
||||
displayDiff = Math.round((displayDiff / grainBag.bushelsPerTonne()) * 100) / 100;
|
||||
}
|
||||
}
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1) {
|
||||
if (displayPending && displayDiff) {
|
||||
displayPending = Math.round((displayPending / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
|
||||
displayDiff = Math.round((displayDiff / (grainBag.bushelsPerTonne()* 0.907)) * 100) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Box>
|
||||
{grainDiff !== undefined && grainDiff > 0 && (
|
||||
|
|
@ -141,7 +148,7 @@ export default function GrainBagVisualizer(props: Props) {
|
|||
};
|
||||
|
||||
const grainAmountDisplay = () => {
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && grainBag.bushelsPerTonne() > 1) {
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1) {
|
||||
return (
|
||||
<div style={{ display: "flex", flexDirection: "row" }}>
|
||||
<Typography variant="body2" style={{ fontWeight: "bold", marginRight: "4px" }}>
|
||||
|
|
@ -150,6 +157,15 @@ export default function GrainBagVisualizer(props: Props) {
|
|||
<Typography variant="body2">({grainBag.fillPercent()}%)</Typography>
|
||||
</div>
|
||||
);
|
||||
} else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1) {
|
||||
return (
|
||||
<div style={{ display: "flex", flexDirection: "row" }}>
|
||||
<Typography variant="body2" style={{ fontWeight: "bold", marginRight: "4px" }}>
|
||||
{(grainBag.bushels() / (grainBag.bushelsPerTonne()*0.907)).toFixed(2) + " t"}
|
||||
</Typography>
|
||||
<Typography variant="body2">({grainBag.fillPercent()}%)</Typography>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div style={{ display: "flex", flexDirection: "row" }}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue