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

2
package-lock.json generated
View file

@ -11967,7 +11967,7 @@
}, },
"node_modules/protobuf-ts": { "node_modules/protobuf-ts": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#7649feaa2222b555fe15fe9e4a19244c23f0e442", "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#8281f64aa2c8db09a73f5a2eb8a1b97a63bcc653",
"dependencies": { "dependencies": {
"protobufjs": "^6.8.8" "protobufjs": "^6.8.8"
} }

View file

@ -443,14 +443,24 @@ export default function BinCard(props: Props) {
" L" " L"
); );
} }
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && bin.bushelsPerTonne() > 1) {
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1) {
return ( return (
bin.grainTonnes().toLocaleString() + bin.grainTonnes().toLocaleString() +
" mT " + " mT " +
bin.fillPercent() + bin.fillPercent() +
"%" "%"
); );
} else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTon() > 1) {
return (
bin.grainTons().toLocaleString() +
" t " +
bin.fillPercent() +
"%"
);
} }
return ( return (
current.toLocaleString() + current.toLocaleString() +
"/" + "/" +

View file

@ -126,14 +126,13 @@ interface BinFormExtension {
hopperHeight: string; hopperHeight: string;
diameter: string; diameter: string;
grainBushels: string; grainBushels: string;
grainTonnes: string; grainWeight: string;
grainType: Option | null; grainType: Option | null;
grainUse: Option | null; grainUse: Option | null;
grainSubtype: string; grainSubtype: string;
customTypeName: string; customTypeName: string;
highTemp: number; highTemp: number;
lowTemp: number; lowTemp: number;
bushelsPerTonne: string;
tempTarget: number; tempTarget: number;
} }
@ -160,14 +159,13 @@ export default function BinSettings(props: Props) {
hopperHeight: "", hopperHeight: "",
diameter: "", diameter: "",
grainBushels: "", grainBushels: "",
grainTonnes: "", grainWeight: "",
grainType: null, grainType: null,
grainUse: null, grainUse: null,
grainSubtype: "", grainSubtype: "",
customTypeName: "", customTypeName: "",
highTemp: 20, highTemp: 20,
lowTemp: 10, lowTemp: 10,
bushelsPerTonne: "",
tempTarget: 15 tempTarget: 15
}); });
const [initialized, setInitialized] = useState(false); const [initialized, setInitialized] = useState(false);
@ -194,6 +192,7 @@ export default function BinSettings(props: Props) {
const [isCustomBin, setIsCustomBin] = useState(false); const [isCustomBin, setIsCustomBin] = useState(false);
const [binModelOps, setBinModelOptions] = useState<Option[]>([]); const [binModelOps, setBinModelOptions] = useState<Option[]>([]);
const [selectedBinModel, setSelectedBinModel] = useState<Option | null>(null); const [selectedBinModel, setSelectedBinModel] = useState<Option | null>(null);
const [bushelConversion, setBushelConversion] = useState(0) //the number used to convert the bushels to either tonne or ton based on user preference
const [modelID, setModelID] = useState(0); const [modelID, setModelID] = useState(0);
const [autoTopNode, setAutoTopNode] = useState(false); const [autoTopNode, setAutoTopNode] = useState(false);
const [inventoryControl, setInventoryControl] = useState<pond.BinInventoryControl>( const [inventoryControl, setInventoryControl] = useState<pond.BinInventoryControl>(
@ -232,14 +231,30 @@ export default function BinSettings(props: Props) {
if (initForm.inventory) { if (initForm.inventory) {
setInventoryControl(initForm.inventory.inventoryControl); setInventoryControl(initForm.inventory.inventoryControl);
//make sure bushels per tonne is set so bins that don't have it in the settings yet can still do it before they get updated properly //make sure bushels per ton/ne is set so bins that don't have it in the settings yet can still do it before they get updated properly
if (!initForm.inventory.bushelsPerTonne) { const grain = GrainDescriber(
initForm.inventory.bushelsPerTonne = GrainDescriber(
initForm.inventory.grainType initForm.inventory.grainType
).bushelsPerTonne; )
if (!initForm.inventory.bushelsPerTonne) {
initForm.inventory.bushelsPerTonne = grain.bushelsPerTonne;
}
if (!initForm.inventory.bushelsPerTon) {
initForm.inventory.bushelsPerTon = grain.bushelsPerTon;
}
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
setBushelConversion(initForm.inventory.bushelsPerTonne)
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
setBushelConversion(initForm.inventory.bushelsPerTon)
} }
if (initForm.inventory.customGrain){ if (initForm.inventory.customGrain){
setCustomGrain(initForm.inventory.customGrain) setCustomGrain(initForm.inventory.customGrain)
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
setBushelConversion(initForm.inventory.customGrain.bushelsPerTonne)
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
setBushelConversion(initForm.inventory.customGrain.bushelsPerTon)
}
} }
//if the target temp is not set (older bins) make it the midpoint of the high and low temps assuming they are set otherwise make it 15 //if the target temp is not set (older bins) make it the midpoint of the high and low temps assuming they are set otherwise make it 15
if (!initForm.inventory.targetTemperature || initForm.inventory.targetTemperature) { if (!initForm.inventory.targetTemperature || initForm.inventory.targetTemperature) {
@ -290,6 +305,21 @@ export default function BinSettings(props: Props) {
? initForm.inventory.grainBushels * 35.239 ? initForm.inventory.grainBushels * 35.239
: 0 : 0
: initForm.inventory?.grainBushels ?? 0; : initForm.inventory?.grainBushels ?? 0;
let weight = ""
if(initForm.inventory){
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
weight = (gb/initForm.inventory.bushelsPerTonne).toFixed(2)
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
weight = (gb/initForm.inventory.bushelsPerTon).toFixed(2)
}
if(initForm.inventory.customGrain){
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
weight = (gb/initForm.inventory.customGrain.bushelsPerTonne).toFixed(2)
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
weight = (gb/initForm.inventory.customGrain.bushelsPerTon).toFixed(2)
}
}
}
setForm(initForm); setForm(initForm);
setHighTempC(initForm.highTemp ?? 20); setHighTempC(initForm.highTemp ?? 20);
@ -299,9 +329,10 @@ export default function BinSettings(props: Props) {
height: h, height: h,
diameter: d, diameter: d,
grainBushels: gb.toFixed(2), grainBushels: gb.toFixed(2),
grainTonnes: initForm.inventory?.bushelsPerTonne grainWeight: weight,
? (gb / initForm.inventory.bushelsPerTonne).toFixed(2) // grainTons: initForm.inventory?.bushelsPerTon
: "", // ? (gb / initForm.inventory.bushelsPerTon).toFixed(2)
// : "",
grainType: initForm.inventory?.grainType grainType: initForm.inventory?.grainType
? ToGrainOption(initForm.inventory.grainType) ? ToGrainOption(initForm.inventory.grainType)
: null, : null,
@ -315,8 +346,7 @@ export default function BinSettings(props: Props) {
tempTarget: target, tempTarget: target,
hopperHeight: hopperHeight, hopperHeight: hopperHeight,
topConeHeight: topconeHeight, topConeHeight: topconeHeight,
sidewallHeight: sidewallHeight, sidewallHeight: sidewallHeight
bushelsPerTonne: initForm.inventory?.bushelsPerTonne.toString() ?? "0"
}); });
setInMoistureString(initForm.inventory?.initialMoisture.toString() ?? "0"); setInMoistureString(initForm.inventory?.initialMoisture.toString() ?? "0");
setTMoistureString(initForm.inventory?.targetMoisture.toString() ?? "0"); setTMoistureString(initForm.inventory?.targetMoisture.toString() ?? "0");
@ -771,12 +801,103 @@ export default function BinSettings(props: Props) {
} }
}; };
const inventoryAmount = () => {
const grainWeight = formExtension.grainWeight;
const binQuantity = formExtension.grainBushels;
//as long as the storage type is not fertilizer it is some sort of grain, whether it is supported or custom is not important in this instance so we do not need to check for unknown
if(storageType !== pond.BinStorage.BIN_STORAGE_FERTILIZER && ((getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE || getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) && bushelConversion !== 0 && grainWeight !== "")){
return (
<TextField
label="Amount"
value={grainWeight}
type="number"
onChange={event => {
let newWeight = event.target.value;
//get the bushel amount
if (!isNaN(+newWeight)) {
let newBushels = Math.round(+newWeight * bushelConversion * 100) / 100;
updateForm(
"inventory",
pond.BinInventory.create({
...form.inventory,
grainBushels: newBushels
})
);
//updateFormExtension("grainBushels", newBushels.toString())
updateFormExtension("grainWeight", newWeight);
}
}}
fullWidth
variant="outlined"
disabled={!canEdit}
InputProps={{
endAdornment: <InputAdornment position="end">{getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE ? "mT" : "t"}</InputAdornment>
}}
className={classes.bottomSpacing}
/>
)
}else{
return (
<TextField
label="Amount"
value={binQuantity}
type="number"
onChange={event => {
let capacity =
bin?.settings.storage === pond.BinStorage.BIN_STORAGE_FERTILIZER
? +inputCapacity * 35.239
: inputCapacity;
let value = event?.target.value;
let v =
value === ""
? 0
: isNaN(parseFloat(value))
? 0
: parseFloat(value) >= +capacity
? +capacity
: parseFloat(value) <= 0
? 0
: parseFloat(value);
if (bin?.storage() === pond.BinStorage.BIN_STORAGE_FERTILIZER && v) {
v = v / 35.239;
}
//setNewGrainQuantity(v);
updateForm(
"inventory",
pond.BinInventory.create({
...form.inventory,
grainBushels: v
})
);
updateFormExtension("grainBushels", value);
}}
InputProps={{
endAdornment: (
<InputAdornment position="end">
{storageType === pond.BinStorage.BIN_STORAGE_FERTILIZER
? "Litres"
: "Bushels"}
</InputAdornment>
)
}}
fullWidth
variant="outlined"
disabled={
!canEdit ||
inventoryControl === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_AUTOMATIC
}
className={classes.bottomSpacing}
/>
)
}
}
const inventoryForm = () => { const inventoryForm = () => {
const inventory = form.inventory; const inventory = form.inventory;
const empty = inventory ? inventory.empty : false; const empty = inventory ? inventory.empty : false;
const bushPerTonne = formExtension.bushelsPerTonne;
const binQuantity = formExtension.grainBushels; const binQuantity = formExtension.grainBushels;
const grainTonnes = formExtension.grainTonnes;
const grainType = formExtension.grainType; const grainType = formExtension.grainType;
const grainSubtype = formExtension.grainSubtype; const grainSubtype = formExtension.grainSubtype;
const grainUse = formExtension.grainUse; const grainUse = formExtension.grainUse;
@ -805,11 +926,12 @@ export default function BinSettings(props: Props) {
pond.BinInventory.create({ pond.BinInventory.create({
...form.inventory, ...form.inventory,
grainType: pond.Grain.GRAIN_CUSTOM, grainType: pond.Grain.GRAIN_CUSTOM,
bushelsPerTonne: 0 bushelsPerTonne: 0,
bushelsPerTon: 0
}) })
); );
updateFormExtension("grainType", null); updateFormExtension("grainType", null);
updateFormExtension("bushelsPerTonne", ""); setBushelConversion(0)
} else { } else {
setStorageType(pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN); setStorageType(pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN);
updateForm( updateForm(
@ -859,7 +981,8 @@ export default function BinSettings(props: Props) {
let storageType = parseFloat(value) as pond.BinStorage; let storageType = parseFloat(value) as pond.BinStorage;
setStorageType(storageType); setStorageType(storageType);
if (storageType === pond.BinStorage.BIN_STORAGE_FERTILIZER) { if (storageType === pond.BinStorage.BIN_STORAGE_FERTILIZER) {
formExtension.bushelsPerTonne = ""; // formExtension.bushelsPerTonne = "";
setBushelConversion(0)
formExtension.grainBushels = ( formExtension.grainBushels = (
parseFloat(formExtension.grainBushels) * 35.239 parseFloat(formExtension.grainBushels) * 35.239
).toFixed(0); ).toFixed(0);
@ -1054,7 +1177,30 @@ export default function BinSettings(props: Props) {
</React.Fragment> </React.Fragment>
: :
<Box sx={{border: "1px solid white", borderRadius: 2, padding: 2, marginBottom: 2}}> <Box sx={{border: "1px solid white", borderRadius: 2, padding: 2, marginBottom: 2}}>
<CustomGrainSelector initialGrain={customGrain} onGrainSettingsChange={(newGrainSettings) => {setCustomGrain(newGrainSettings)}}/> <CustomGrainSelector
initialGrain={customGrain}
onGrainSettingsChange={(newGrainSettings) => {
setCustomGrain(newGrainSettings)
let conversion = 0
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
conversion = newGrainSettings.bushelsPerTonne
}else if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
conversion = newGrainSettings.bushelsPerTon
}
updateForm(
"inventory",
pond.BinInventory.create({
...form.inventory,
bushelsPerTonne: newGrainSettings.bushelsPerTonne,
bushelsPerTon: newGrainSettings.bushelsPerTon
})
);
setBushelConversion(conversion)
if(conversion !== 0 && !isNaN(+binQuantity)){
updateFormExtension("grainWeight", (+binQuantity/conversion).toFixed(2))
}
}}/>
</Box> </Box>
} }
</React.Fragment> </React.Fragment>
@ -1073,11 +1219,22 @@ export default function BinSettings(props: Props) {
pond.BinInventory.create({ pond.BinInventory.create({
...form.inventory, ...form.inventory,
grainType: newGrainType, grainType: newGrainType,
bushelsPerTonne: GrainDescriber(newGrainType).bushelsPerTonne bushelsPerTonne: GrainDescriber(newGrainType).bushelsPerTonne,
bushelsPerTon: GrainDescriber(newGrainType).bushelsPerTon
}) })
); );
//doesn't need to update the form extension to display the bushels per tonne as it is not changeable for the supported grain let conversion = 0
//and is reset whenever the user switches between custom or not if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
conversion = GrainDescriber(newGrainType).bushelsPerTonne
}else if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
conversion = GrainDescriber(newGrainType).bushelsPerTon
}
setBushelConversion(conversion)
if(conversion !== 0 && !isNaN(+binQuantity)){
//updateFormExtension("grainWeight", (+binQuantity/conversion).toFixed(2))
let newWeight = (+binQuantity/conversion).toFixed(2)
formExtension.grainWeight = newWeight
}
updateFormExtension("grainType", option); updateFormExtension("grainType", option);
}} }}
group group
@ -1106,7 +1263,8 @@ export default function BinSettings(props: Props) {
/> />
</React.Fragment> </React.Fragment>
} }
{getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_BUSHELS || {inventoryAmount()}
{/* {getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_BUSHELS ||
storageType === pond.BinStorage.BIN_STORAGE_FERTILIZER || storageType === pond.BinStorage.BIN_STORAGE_FERTILIZER ||
formExtension.bushelsPerTonne === "0" || formExtension.bushelsPerTonne === "0" ||
formExtension.bushelsPerTonne === "" ? ( formExtension.bushelsPerTonne === "" ? (
@ -1163,7 +1321,7 @@ export default function BinSettings(props: Props) {
) : ( ) : (
<TextField <TextField
label="Amount" label="Amount"
value={grainTonnes} value={grainWeight}
type="number" type="number"
onChange={event => { onChange={event => {
let newWeight = event.target.value; let newWeight = event.target.value;
@ -1180,7 +1338,7 @@ export default function BinSettings(props: Props) {
}) })
); );
//updateFormExtension("grainBushels", newBushels.toString()) //updateFormExtension("grainBushels", newBushels.toString())
updateFormExtension("grainTonnes", newWeight); updateFormExtension("grainWeight", newWeight);
} }
}} }}
fullWidth fullWidth
@ -1191,7 +1349,7 @@ export default function BinSettings(props: Props) {
}} }}
className={classes.bottomSpacing} className={classes.bottomSpacing}
/> />
)} )} */}
{!isCustomInventory && ( {!isCustomInventory && (
<SearchSelect <SearchSelect
label="Use" label="Use"

View file

@ -196,14 +196,27 @@ export default function BinTransactions(props: Props){
} }
} }
const grainQuantityDisplay = (bushels: number) => {
const grainTransaction = selectedTransaction?.transaction.transaction?.grainTransaction ?? pond.GrainTransaction.create()
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainTransaction.bushelsPerTonne > 1){
let tonneWeight = bushels / grainTransaction.bushelsPerTonne
return tonneWeight + " mT"
}
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainTransaction.bushelsPerTon > 1){
let tonneWeight = bushels / grainTransaction.bushelsPerTon
return tonneWeight + " t"
}
return bushels + " bushels"
}
// dialog for approving a transaction // dialog for approving a transaction
const approvalDialog = () => { const approvalDialog = () => {
// get the display information for the transaction // get the display information for the transaction
const grainTransaction = selectedTransaction?.transaction.transaction?.grainTransaction ?? pond.GrainTransaction.create() const grainTransaction = selectedTransaction?.transaction.transaction?.grainTransaction ?? pond.GrainTransaction.create()
const bushels = grainTransaction.bushels ?? 0 const bushels = grainTransaction.bushels ?? 0
const weight = bushels / grainTransaction.bushelsPerTonne //const weight = bushels / grainTransaction.bushelsPerTonne
let graintype = grainTransaction.grainType ?? pond.Grain.GRAIN_INVALID let graintype = grainTransaction.grainType ?? pond.Grain.GRAIN_INVALID
const grainDisplay = graintype === pond.Grain.GRAIN_CUSTOM const grainTypeDisplay = graintype === pond.Grain.GRAIN_CUSTOM
? grainTransaction.customGrain ? grainTransaction.customGrain
: GrainDescriber(grainTransaction.grainType).name : GrainDescriber(grainTransaction.grainType).name
@ -215,7 +228,7 @@ export default function BinTransactions(props: Props){
<DialogTitle>Accept Transaction</DialogTitle> <DialogTitle>Accept Transaction</DialogTitle>
<DialogContent> <DialogContent>
<Box> <Box>
<Typography>{getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? weight + " mT" : bushels + " bushels"} of {grainTransaction.subtype} {grainDisplay} moved</Typography> <Typography>{grainQuantityDisplay(bushels)} of {grainTransaction.subtype} {grainTypeDisplay} moved</Typography>
<Typography margin={1} fontWeight={650}>From:</Typography> <Typography margin={1} fontWeight={650}>From:</Typography>
{/*Object type selection*/} {/*Object type selection*/}
<Autocomplete <Autocomplete
@ -378,9 +391,9 @@ export default function BinTransactions(props: Props){
// get the display information for the transaction // get the display information for the transaction
const grainTransaction = t.transaction.transaction?.grainTransaction ?? pond.GrainTransaction.create() const grainTransaction = t.transaction.transaction?.grainTransaction ?? pond.GrainTransaction.create()
const bushels = grainTransaction.bushels ?? 0 const bushels = grainTransaction.bushels ?? 0
const weight = bushels / grainTransaction.bushelsPerTonne // const weight = bushels / grainTransaction.bushelsPerTonne
let graintype = grainTransaction.grainType ?? pond.Grain.GRAIN_INVALID let graintype = grainTransaction.grainType ?? pond.Grain.GRAIN_INVALID
const grainDisplay = graintype === pond.Grain.GRAIN_CUSTOM const grainTypeDisplay = graintype === pond.Grain.GRAIN_CUSTOM
? grainTransaction.customGrain ? grainTransaction.customGrain
: GrainDescriber(grainTransaction.grainType).name : GrainDescriber(grainTransaction.grainType).name
return ( return (
@ -394,7 +407,7 @@ export default function BinTransactions(props: Props){
</Box> </Box>
</Box> </Box>
<Box display="flex" justifyContent="space-between"> <Box display="flex" justifyContent="space-between">
<Typography sx={{margin: "auto", marginLeft: 0}}>{getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? weight + " mT" : bushels + " bushels"} of {grainTransaction.subtype} {grainDisplay} moved</Typography> <Typography sx={{margin: "auto", marginLeft: 0}}>{grainQuantityDisplay(bushels)} of {grainTransaction.subtype} {grainTypeDisplay} moved</Typography>
<Button <Button
variant="contained" variant="contained"
disabled={selectedMatch?.transaction.key === t.transaction.key} disabled={selectedMatch?.transaction.key === t.transaction.key}

View file

@ -270,7 +270,7 @@ export default function BinVisualizer(props: Props) {
const [storageType, setStorageType] = useState<pond.BinStorage>( const [storageType, setStorageType] = useState<pond.BinStorage>(
pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN
); );
const [bushPerTonne, setBushPerTonne] = useState("0"); //const [bushPerTonne, setBushPerTonne] = useState("0");
const [grainSubtype, setGrainSubtype] = useState(""); const [grainSubtype, setGrainSubtype] = useState("");
const [loadingTrend, setLoadingTrend] = useState(false); const [loadingTrend, setLoadingTrend] = useState(false);
@ -326,7 +326,7 @@ export default function BinVisualizer(props: Props) {
setCustomTypeName(bin.settings.inventory.customTypeName); setCustomTypeName(bin.settings.inventory.customTypeName);
setGrainType(bin.settings.inventory.grainType); setGrainType(bin.settings.inventory.grainType);
setGrainOption(ToGrainOption(bin.settings.inventory.grainType)); setGrainOption(ToGrainOption(bin.settings.inventory.grainType));
setBushPerTonne(bin.settings.inventory.bushelsPerTonne.toFixed(2)); //setBushPerTonne(bin.settings.inventory.bushelsPerTonne.toFixed(2));
setGrainSubtype(bin.subtype()); setGrainSubtype(bin.subtype());
setNewBinMode(bin.settings.mode); setNewBinMode(bin.settings.mode);
setNewGrainSettings(bin.customGrain()); setNewGrainSettings(bin.customGrain());
@ -495,8 +495,10 @@ export default function BinVisualizer(props: Props) {
if (bin.storage() === pond.BinStorage.BIN_STORAGE_FERTILIZER) { if (bin.storage() === pond.BinStorage.BIN_STORAGE_FERTILIZER) {
return Math.round(val * 35.239 * 100) / 100; return Math.round(val * 35.239 * 100) / 100;
} else { } else {
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && bin.bushelsPerTonne() > 1) { if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1) {
return Math.round((val / bin.bushelsPerTonne()) * 100) / 100; return Math.round((val / bin.bushelsPerTonne()) * 100) / 100;
} else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTon() > 1) {
return Math.round((val / bin.bushelsPerTon()) * 100) / 100;
} }
} }
return val; return val;
@ -511,17 +513,19 @@ export default function BinVisualizer(props: Props) {
if (bin.storage() === pond.BinStorage.BIN_STORAGE_FERTILIZER) { if (bin.storage() === pond.BinStorage.BIN_STORAGE_FERTILIZER) {
return " / " + capacity.toLocaleString() + " L"; return " / " + capacity.toLocaleString() + " L";
} }
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && bin.bushelsPerTonne() > 1) { if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1) {
return "mT (" + bin.fillPercent() + "%)"; return "mT (" + bin.fillPercent() + "%)";
} else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTon() > 1) {
return "t (" + bin.fillPercent() + "%)";
} else { } else {
return " / " + capacity.toLocaleString() + " bu"; return " / " + capacity.toLocaleString() + " bu";
} }
}; };
const grainErrorCheck = () => { // const grainErrorCheck = () => {
if (isNaN(parseFloat(bushPerTonne))) return true; // if (isNaN(parseFloat(bushPerTonne))) return true;
return false; // return false;
}; // };
const inventoryOverview = () => { const inventoryOverview = () => {
const capacity = bin.settings.specs?.bushelCapacity ?? 0; const capacity = bin.settings.specs?.bushelCapacity ?? 0;
@ -774,7 +778,7 @@ export default function BinVisualizer(props: Props) {
setCustomTypeName(bin.settings.inventory.customTypeName); setCustomTypeName(bin.settings.inventory.customTypeName);
setGrainType(bin.settings.inventory.grainType); setGrainType(bin.settings.inventory.grainType);
setGrainOption(ToGrainOption(bin.settings.inventory.grainType)); setGrainOption(ToGrainOption(bin.settings.inventory.grainType));
setBushPerTonne(bin.settings.inventory.bushelsPerTonne.toFixed(2)); //setBushPerTonne(bin.settings.inventory.bushelsPerTonne.toFixed(2));
setNewGrainSettings(bin.customGrain()) setNewGrainSettings(bin.customGrain())
setGrainSubtype(bin.subtype()); setGrainSubtype(bin.subtype());
} }
@ -802,7 +806,7 @@ export default function BinVisualizer(props: Props) {
checked={isCustomInventory} checked={isCustomInventory}
onChange={(_, checked) => { onChange={(_, checked) => {
setIsCustomInventory(checked); setIsCustomInventory(checked);
setBushPerTonne("0"); //setBushPerTonne("0");
setGrainSubtype(""); setGrainSubtype("");
setCustomTypeName(""); setCustomTypeName("");
setGrainOption(ToGrainOption(pond.Grain.GRAIN_NONE)); setGrainOption(ToGrainOption(pond.Grain.GRAIN_NONE));
@ -834,7 +838,7 @@ export default function BinVisualizer(props: Props) {
: pond.Grain.GRAIN_INVALID; : pond.Grain.GRAIN_INVALID;
setGrainOption(ToGrainOption(newGrainType)); setGrainOption(ToGrainOption(newGrainType));
setGrainType(newGrainType); setGrainType(newGrainType);
setBushPerTonne(GrainDescriber(newGrainType).bushelsPerTonne.toFixed(2)); //setBushPerTonne(GrainDescriber(newGrainType).bushelsPerTonne.toFixed(2));
}} }}
group group
disabled={!canEdit} disabled={!canEdit}
@ -897,7 +901,7 @@ export default function BinVisualizer(props: Props) {
<Button <Button
variant="contained" variant="contained"
color="primary" color="primary"
disabled={grainErrorCheck()} // disabled={grainErrorCheck()}
onClick={() => { onClick={() => {
updateBin(); updateBin();
setGrainChangeDialog(false); setGrainChangeDialog(false);
@ -1321,13 +1325,20 @@ export default function BinVisualizer(props: Props) {
} }
} }
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && bin.bushelsPerTonne() > 1) { if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1) {
diffDisplay = diffDisplay / bin.bushelsPerTonne(); diffDisplay = diffDisplay / bin.bushelsPerTonne();
if (pendingDisplay) { if (pendingDisplay) {
pendingDisplay = pendingDisplay / bin.bushelsPerTonne(); pendingDisplay = pendingDisplay / bin.bushelsPerTonne();
} }
} }
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTon() > 1) {
diffDisplay = diffDisplay / bin.bushelsPerTon();
if (pendingDisplay) {
pendingDisplay = pendingDisplay / bin.bushelsPerTon();
}
}
return ( return (
<Box display="flex" width={1} justifyContent="flex-end"> <Box display="flex" width={1} justifyContent="flex-end">
<FullScreen handle={fullScreenHandler}> <FullScreen handle={fullScreenHandler}>
@ -1987,9 +1998,11 @@ export default function BinVisualizer(props: Props) {
//update all the grain stuff //update all the grain stuff
b.settings.inventory.grainType = grainType; b.settings.inventory.grainType = grainType;
b.settings.inventory.customTypeName = customTypeName; b.settings.inventory.customTypeName = customTypeName;
b.settings.inventory.bushelsPerTonne = isNaN(parseFloat(bushPerTonne)) b.settings.inventory.bushelsPerTonne = GrainDescriber(grainType).bushelsPerTonne
? 0 b.settings.inventory.bushelsPerTon = GrainDescriber(grainType).bushelsPerTon
: parseFloat(bushPerTonne); // b.settings.inventory.bushelsPerTonne = isNaN(parseFloat(bushPerTonne))
// ? 0
// : parseFloat(bushPerTonne);
b.settings.inventory.grainSubtype = grainSubtype; b.settings.inventory.grainSubtype = grainSubtype;
b.settings.inventory.customGrain = newGrainSettings b.settings.inventory.customGrain = newGrainSettings
} }
@ -2010,7 +2023,6 @@ export default function BinVisualizer(props: Props) {
} }
b.settings.mode = newBinMode; b.settings.mode = newBinMode;
} }
console.log(b.settings)
binAPI.updateBin(bin.key(), b.settings, as).then(resp => { binAPI.updateBin(bin.key(), b.settings, as).then(resp => {
refresh(); refresh();
}); });

View file

@ -652,8 +652,29 @@ export default function BinyardDisplay(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 grainQuantityDisplay = (custom?: pond.CustomInventory) => {
}
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; const useWeight = getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT;
return ( return (
<Accordion <Accordion
@ -695,7 +716,7 @@ export default function BinyardDisplay(props: Props) {
<GridListTile key={key}> <GridListTile key={key}>
<BinUtilizationChart <BinUtilizationChart
grain={inv.grainType} grain={inv.grainType}
customUnit={useWeight ? " mT" : " bu"} customUnit={grainUnitDisplay()}
bushelAmount={ bushelAmount={
useWeight useWeight
? inv.bushelAmount / GrainDescriber(inv.grainType).bushelsPerTonne ? inv.bushelAmount / GrainDescriber(inv.grainType).bushelsPerTonne
@ -724,11 +745,8 @@ export default function BinyardDisplay(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) { unit = grainUnitDisplay(inv)
amount = amount / inv.bushelsPerTonne;
cap = cap / inv.bushelsPerTonne;
unit = " mT";
} }
return ( return (

View file

@ -69,9 +69,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);
binAPI binAPI
.listHistoryBetween(bin.key(), 500, startDate.toISOString(), endDate.toISOString()) .listHistoryBetween(bin.key(), 500, startDate.toISOString(), endDate.toISOString())
@ -85,13 +88,18 @@ export default function BinLevelOverTime(props: Props) {
if (hist.settings?.inventory) { if (hist.settings?.inventory) {
let bushels = hist.settings.inventory.grainBushels ?? 0; let bushels = hist.settings.inventory.grainBushels ?? 0;
if (bushels !== lastBushels) { if (bushels !== lastBushels) {
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;
}
let newData: InventoryAt = { let newData: InventoryAt = {
timestamp: moment(hist.timestamp).valueOf(), timestamp: moment(hist.timestamp).valueOf(),
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
}; };
data.push(newData); data.push(newData);
lastBushels = bushels; lastBushels = bushels;
@ -163,8 +171,15 @@ export default function BinLevelOverTime(props: Props) {
m.values.forEach((val, i) => { m.values.forEach((val, i) => {
if (val.values[0] && m.timestamps[i]) { if (val.values[0] && m.timestamps[i]) {
if (lastBushels !== val.values[0]) { if (lastBushels !== val.values[0]) {
let grainDisplay = val.values[0]
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
grainDisplay = Math.round((grainDisplay / bin.bushelsPerTonne()) * 100) / 100;
}
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTon() > 1){
grainDisplay = Math.round((grainDisplay / bin.bushelsPerTon()) * 100) / 100;
}
autoBarData.push({ autoBarData.push({
value: val.values[0], value: grainDisplay,
timestamp: moment(m.timestamps[i]).valueOf(), timestamp: moment(m.timestamps[i]).valueOf(),
}); });
lastBushels = val.values[0]; lastBushels = val.values[0];

View file

@ -88,6 +88,7 @@ export default function FieldSettings(props: Props) {
settings.grainSubtype = grainSubtype; settings.grainSubtype = grainSubtype;
settings.landLocation = landLocation; settings.landLocation = landLocation;
settings.acres = acres; settings.acres = acres;
settings.bushelsPerTonne = isNaN(parseFloat(bushelsPerTonne)) ? 1 : parseFloat(bushelsPerTonne);
fieldAPI fieldAPI
.updateField(selectedField.key(), settings, undefined, as) .updateField(selectedField.key(), settings, undefined, as)
@ -121,6 +122,7 @@ export default function FieldSettings(props: Props) {
geo.shapes = borders; geo.shapes = borders;
} }
settings.fieldGeoData = geo; settings.fieldGeoData = geo;
settings.bushelsPerTonne = isNaN(parseFloat(bushelsPerTonne)) ? 1 : parseFloat(bushelsPerTonne);
fieldAPI fieldAPI
.addField(settings, as) .addField(settings, as)
.then(resp => { .then(resp => {
@ -226,6 +228,7 @@ export default function FieldSettings(props: Props) {
if (option) { if (option) {
let grainType = pond.Grain[option.value as keyof typeof pond.Grain]; let grainType = pond.Grain[option.value as keyof typeof pond.Grain];
setCropType(grainType); setCropType(grainType);
console.log("set bpt here")
setBushelsPerTonne(GrainDescriber(grainType).bushelsPerTonne.toString()); setBushelsPerTonne(GrainDescriber(grainType).bushelsPerTonne.toString());
} }
}} }}

View file

@ -20,7 +20,7 @@ export default function CustomGrainForm(props: Props) {
const [kgPerBushel, setKgPerBushel] = useState("0") const [kgPerBushel, setKgPerBushel] = useState("0")
const [bushelsPerTonne, setBushelsPerTonne] = useState("0")//this is metric const [bushelsPerTonne, setBushelsPerTonne] = useState("0")//this is metric
const [lbPerBushel, setLbPerBushel] = useState("0") const [lbPerBushel, setLbPerBushel] = useState("0")
const [bushelsPerTon, setBushelsPerTon] = useState("0")//this is imperial const [bushelsPerTon, setBushelsPerTon] = useState("0")//this is US ton
const valid = useRef(false) const valid = useRef(false)
useEffect(()=>{ useEffect(()=>{
@ -33,6 +33,8 @@ export default function CustomGrainForm(props: Props) {
setConstantC(grainSettings.c.toString()) setConstantC(grainSettings.c.toString())
setKgPerBushel(grainSettings.kgPerBushel.toString()) setKgPerBushel(grainSettings.kgPerBushel.toString())
setBushelsPerTonne(grainSettings.bushelsPerTonne.toString()) setBushelsPerTonne(grainSettings.bushelsPerTonne.toString())
setLbPerBushel(grainSettings.poundsPerBushel.toString())
setBushelsPerTon(grainSettings.bushelsPerTon.toString())
setNewGrainSettings(grainSettings) setNewGrainSettings(grainSettings)
} }
},[grainSettings]) },[grainSettings])
@ -236,7 +238,7 @@ export default function CustomGrainForm(props: Props) {
let settings = cloneDeep(newGrainSettings) let settings = cloneDeep(newGrainSettings)
if(!isNaN(parseFloat(val))){ if(!isNaN(parseFloat(val))){
settings.bushelsPerTonne = parseFloat(val) settings.bushelsPerTonne = parseFloat(val)
let newTon = Math.round((parseFloat(val)*1.102)*100)/100 let newTon = Math.round((parseFloat(val)*0.907)*100)/100
settings.bushelsPerTon = newTon settings.bushelsPerTon = newTon
setBushelsPerTon(newTon.toString()) setBushelsPerTon(newTon.toString())
} }
@ -257,7 +259,7 @@ export default function CustomGrainForm(props: Props) {
let settings = cloneDeep(newGrainSettings) let settings = cloneDeep(newGrainSettings)
if(!isNaN(parseFloat(val))){ if(!isNaN(parseFloat(val))){
settings.bushelsPerTon = parseFloat(val) settings.bushelsPerTon = parseFloat(val)
let newTonne = Math.round((parseFloat(val)/1.102)*100)/100 let newTonne = Math.round((parseFloat(val)/0.907)*100)/100
settings.bushelsPerTonne = newTonne settings.bushelsPerTonne = newTonne
setBushelsPerTonne(newTonne.toString()) setBushelsPerTonne(newTonne.toString())
} }

View file

@ -30,6 +30,7 @@ export interface GrainExtension {
colour: string; colour: string;
weightConversionKg: number; weightConversionKg: number;
bushelsPerTonne: number; bushelsPerTonne: number;
bushelsPerTon: number; //NOTE: this is US tons (2000lB/t)
} }
const defaultSetTemp = 30.0; const defaultSetTemp = 30.0;
@ -45,7 +46,8 @@ const defaultGrain: GrainExtension = {
targetMC: 15.0, targetMC: 15.0,
colour: "#424242", colour: "#424242",
weightConversionKg: 0, weightConversionKg: 0,
bushelsPerTonne: 0 bushelsPerTonne: 0,
bushelsPerTon: 0
}; };
export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
@ -64,7 +66,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
targetMC: 15.0, targetMC: 15.0,
colour: "yellow", colour: "yellow",
weightConversionKg: 0, weightConversionKg: 0,
bushelsPerTonne: 0 bushelsPerTonne: 0,
bushelsPerTon: 0
} }
], ],
[ [
@ -81,7 +84,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: BarleyImg, img: BarleyImg,
colour: "#27632a", colour: "#27632a",
weightConversionKg: 21.772657171369, weightConversionKg: 21.772657171369,
bushelsPerTonne: 45.93 bushelsPerTonne: 45.93,
bushelsPerTon: 41.66
} }
], ],
[ [
@ -98,7 +102,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
targetMC: 16.1, targetMC: 16.1,
colour: "#46b298", colour: "#46b298",
weightConversionKg: 1, weightConversionKg: 1,
bushelsPerTonne: 45.93 bushelsPerTonne: 45.93,
bushelsPerTon: 50.63
} }
], ],
[ [
@ -116,7 +121,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
// colour: "#cddc39", // colour: "#cddc39",
colour: "#ffff00", colour: "#ffff00",
weightConversionKg: 22.67961461, weightConversionKg: 22.67961461,
bushelsPerTonne: 44.092 bushelsPerTonne: 44.092,
bushelsPerTon: 39.99
} }
], ],
[ [
@ -133,7 +139,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: CanolaImg, img: CanolaImg,
colour: "#cddc39", colour: "#cddc39",
weightConversionKg: 27.215537532, weightConversionKg: 27.215537532,
bushelsPerTonne: 44.092 bushelsPerTonne: 44.092,
bushelsPerTon: 39.9
} }
], ],
[ [
@ -150,7 +157,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: CornImg, img: CornImg,
colour: "#ffef62", colour: "#ffef62",
weightConversionKg: 25.4014333665971, weightConversionKg: 25.4014333665971,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
} }
], ],
[ [
@ -167,7 +175,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: CornImg, img: CornImg,
colour: "#ffef62", colour: "#ffef62",
weightConversionKg: 25.4014333665971, weightConversionKg: 25.4014333665971,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
} }
], ],
[ [
@ -184,7 +193,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: CornImg, img: CornImg,
colour: "#ffef62", colour: "#ffef62",
weightConversionKg: 25.4014333665971, weightConversionKg: 25.4014333665971,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
} }
], ],
[ [
@ -201,7 +211,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: CornImg, img: CornImg,
colour: "#ffef62", colour: "#ffef62",
weightConversionKg: 25.4014333665971, weightConversionKg: 25.4014333665971,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
} }
], ],
[ [
@ -218,7 +229,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: CornImg, img: CornImg,
colour: "#ffef62", colour: "#ffef62",
weightConversionKg: 25.4014333665971, weightConversionKg: 25.4014333665971,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
} }
], ],
[ [
@ -235,7 +247,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: OatImg, img: OatImg,
colour: "#79955a", colour: "#79955a",
weightConversionKg: 15.4222988297197, weightConversionKg: 15.4222988297197,
bushelsPerTonne: 64.842 bushelsPerTonne: 64.842,
bushelsPerTon: 58.81
} }
], ],
[ [
@ -252,7 +265,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: OatImg, img: OatImg,
colour: "#79955a", colour: "#79955a",
weightConversionKg: 15.4222988297197, weightConversionKg: 15.4222988297197,
bushelsPerTonne: 64.842 bushelsPerTonne: 64.842,
bushelsPerTon: 58.81
} }
], ],
[ [
@ -269,7 +283,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: OatImg, img: OatImg,
colour: "#79955a", colour: "#79955a",
weightConversionKg: 15.4222988297197, weightConversionKg: 15.4222988297197,
bushelsPerTonne: 64.842 bushelsPerTonne: 64.842,
bushelsPerTon: 58.81
} }
], ],
[ [
@ -286,7 +301,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: PeanutImg, img: PeanutImg,
colour: "#b2a058", colour: "#b2a058",
weightConversionKg: 23.3124, weightConversionKg: 23.3124,
bushelsPerTonne: 105.263 bushelsPerTonne: 105.263,
bushelsPerTon: 95.47
} }
], ],
[ [
@ -303,7 +319,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: RiceImg, img: RiceImg,
colour: "#7c9c99", colour: "#7c9c99",
weightConversionKg: 28.439, weightConversionKg: 28.439,
bushelsPerTonne: 49.02 bushelsPerTonne: 49.02,
bushelsPerTon: 44.46
} }
], ],
[ [
@ -320,7 +337,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: RiceImg, img: RiceImg,
colour: "#7c9c99", colour: "#7c9c99",
weightConversionKg: 29.979, weightConversionKg: 29.979,
bushelsPerTonne: 49.02 bushelsPerTonne: 49.02,
bushelsPerTon: 44.46
} }
], ],
[ [
@ -337,7 +355,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: RiceImg, img: RiceImg,
colour: "#7c9c99", colour: "#7c9c99",
weightConversionKg: 30.744, weightConversionKg: 30.744,
bushelsPerTonne: 49.02 bushelsPerTonne: 49.02,
bushelsPerTon: 44.46
} }
], ],
[ [
@ -354,7 +373,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: SorghumImg, img: SorghumImg,
colour: "#829baf", colour: "#829baf",
weightConversionKg: 25.4014333665971, weightConversionKg: 25.4014333665971,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
} }
], ],
[ [
@ -371,7 +391,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: SoybeanImg, img: SoybeanImg,
colour: "#7d6d99", colour: "#7d6d99",
weightConversionKg: 27.2158214642112, weightConversionKg: 27.2158214642112,
bushelsPerTonne: 36.744 bushelsPerTonne: 36.744,
bushelsPerTon: 33.33
} }
], ],
[ [
@ -388,7 +409,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: SunflowerImg, img: SunflowerImg,
colour: "#ffab40", colour: "#ffab40",
weightConversionKg: 13.6079107321056, weightConversionKg: 13.6079107321056,
bushelsPerTonne: 73.487 bushelsPerTonne: 73.487,
bushelsPerTon: 66.65
} }
], ],
[ [
@ -405,7 +427,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: WheatImg, img: WheatImg,
colour: "#46b298", colour: "#46b298",
weightConversionKg: 27.2158214642112, weightConversionKg: 27.2158214642112,
bushelsPerTonne: 36.744 bushelsPerTonne: 36.744,
bushelsPerTon: 33.33
} }
], ],
[ [
@ -422,7 +445,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: WheatImg, img: WheatImg,
colour: "#46b298", colour: "#46b298",
weightConversionKg: 27.2158214642112, weightConversionKg: 27.2158214642112,
bushelsPerTonne: 36.744 bushelsPerTonne: 36.744,
bushelsPerTon: 33.33
} }
], ],
[ [
@ -439,7 +463,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: WheatImg, img: WheatImg,
colour: "#46b298", colour: "#46b298",
weightConversionKg: 27.2158214642112, weightConversionKg: 27.2158214642112,
bushelsPerTonne: 36.744 bushelsPerTonne: 36.744,
bushelsPerTon: 33.33
} }
], ],
[ [
@ -456,7 +481,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: FlaxImg, img: FlaxImg,
colour: "#6e6d19", colour: "#6e6d19",
weightConversionKg: 25.4014333665971, weightConversionKg: 25.4014333665971,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
} }
], ],
[ [
@ -473,7 +499,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: FlaxImg, img: FlaxImg,
colour: "#6e6d19", colour: "#6e6d19",
weightConversionKg: 25.4014333665971, weightConversionKg: 25.4014333665971,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
} }
], ],
[ [
@ -490,7 +517,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: PeaImg, img: PeaImg,
colour: "#ffe100", colour: "#ffe100",
weightConversionKg: 27.2158214642112, weightConversionKg: 27.2158214642112,
bushelsPerTonne: 36.744 bushelsPerTonne: 36.744,
bushelsPerTon: 33.33
} }
], ],
[ [
@ -507,7 +535,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: LentilImg, img: LentilImg,
colour: "#cb5e3c", colour: "#cb5e3c",
weightConversionKg: 27.2158214642112, weightConversionKg: 27.2158214642112,
bushelsPerTonne: 36.744 bushelsPerTonne: 36.744,
bushelsPerTon: 33.33
} }
], ],
[ [
@ -524,7 +553,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: LentilImg, img: LentilImg,
colour: "#cb5e3c", colour: "#cb5e3c",
weightConversionKg: 27.2158214642112, weightConversionKg: 27.2158214642112,
bushelsPerTonne: 36.744 bushelsPerTonne: 36.744,
bushelsPerTon: 33.33
} }
], ],
[ [
@ -541,7 +571,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
img: LentilImg, img: LentilImg,
colour: "#cb5e3c", colour: "#cb5e3c",
weightConversionKg: 27.2158214642112, weightConversionKg: 27.2158214642112,
bushelsPerTonne: 36.744 bushelsPerTonne: 36.744,
bushelsPerTon: 33.33
} }
], ],
[ [
@ -557,7 +588,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
targetMC: 15.0, targetMC: 15.0,
colour: "red", colour: "red",
weightConversionKg: 27.2155, weightConversionKg: 27.2155,
bushelsPerTonne: 36.744 bushelsPerTonne: 36.744,
bushelsPerTon: 33.33
} }
],[ ],[
pond.Grain.GRAIN_DRY_BEANS_BLACK, pond.Grain.GRAIN_DRY_BEANS_BLACK,
@ -572,7 +604,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
targetMC: 15.0, targetMC: 15.0,
colour: "grey", colour: "grey",
weightConversionKg: 27.2155, weightConversionKg: 27.2155,
bushelsPerTonne: 36.744 bushelsPerTonne: 36.744,
bushelsPerTon: 33.33
} }
],[ ],[
pond.Grain.GRAIN_RYE_A, pond.Grain.GRAIN_RYE_A,
@ -587,7 +620,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
targetMC: 15.0, targetMC: 15.0,
colour: "grey", colour: "grey",
weightConversionKg: 25.4, weightConversionKg: 25.4,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
} }
],[ ],[
pond.Grain.GRAIN_RYE_B, pond.Grain.GRAIN_RYE_B,
@ -602,7 +636,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
targetMC: 15.0, targetMC: 15.0,
colour: "grey", colour: "grey",
weightConversionKg: 25.4, weightConversionKg: 25.4,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
}, },
],[ ],[
pond.Grain.GRAIN_RYE_C, pond.Grain.GRAIN_RYE_C,
@ -617,7 +652,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
targetMC: 15.0, targetMC: 15.0,
colour: "grey", colour: "grey",
weightConversionKg: 25.4, weightConversionKg: 25.4,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
}, },
],[ ],[
pond.Grain.GRAIN_RYE_D, pond.Grain.GRAIN_RYE_D,
@ -632,7 +668,8 @@ export const GrainExtensions: Map<pond.Grain, GrainExtension> = new Map([
targetMC: 15.0, targetMC: 15.0,
colour: "grey", colour: "grey",
weightConversionKg: 25.4, weightConversionKg: 25.4,
bushelsPerTonne: 39.368 bushelsPerTonne: 39.368,
bushelsPerTon: 35.71
} }
] ]
]); ]);

View file

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

View file

@ -161,6 +161,7 @@ export default function GrainBagSettings(props: Props) {
settings.currentBushels = grainBushels; settings.currentBushels = grainBushels;
settings.grainSubtype = grainSubtype; settings.grainSubtype = grainSubtype;
settings.fillDate = fillDate; settings.fillDate = fillDate;
settings.bushelsPerTonne = bushelsPerTonne;
settings.storageType = isCustom settings.storageType = isCustom
? pond.BinStorage.BIN_STORAGE_UNSUPPORTED_GRAIN ? pond.BinStorage.BIN_STORAGE_UNSUPPORTED_GRAIN
: pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN; : pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN;

View file

@ -236,7 +236,23 @@ export class Bin {
} }
/** /**
* gets the weight in tonnes for the grain inventory provided the bushels per tonne is set * returns the bushels per ton set in the bins settings, if not set will return 1
* @returns 1 or bushels per tonne
*/
public bushelsPerTon(): number {
//trying to avoid a divide by 0 error by only returning a value greater than 0
//since to get the weight you divide the current bushels by the bushels per tonne
let bpt = 1;
if (this.settings.inventory) {
if (this.settings.inventory.bushelsPerTon > 0) {
bpt = this.settings.inventory.bushelsPerTon;
}
}
return bpt;
}
/**
* gets the weight in tonnes (metric) for the grain inventory provided the bushels per tonne is set
* if it is not set it will divide by 1 effectively returning the bushels * if it is not set it will divide by 1 effectively returning the bushels
* @returns grain weight * @returns grain weight
*/ */
@ -248,6 +264,19 @@ export class Bin {
return Math.round(weight * 100) / 100; return Math.round(weight * 100) / 100;
} }
/**
* gets the weight in tons (imperial) for the grain inventory provided the bushels per ton is set
* if it is not set it will divide by 1 effectively returning the bushels
* @returns grain weight
*/
public grainTons(): number {
let weight = 0;
if (this.settings.inventory) {
weight = this.settings.inventory.grainBushels / this.bushelsPerTon();
}
return Math.round(weight * 100) / 100;
}
/** /**
* gets the enum value for the inventory control in the bins inventory * gets the enum value for the inventory control in the bins inventory
*/ */

View file

@ -59,7 +59,6 @@ export default function GrainBag(props: Props) {
} }
console.log console.log
userAPI.getUser(user.id(), { key: key, kind: kind } as Scope).then(resp => { userAPI.getUser(user.id(), { key: key, kind: kind } as Scope).then(resp => {
console.log(resp)
setPermissions(resp.permissions); setPermissions(resp.permissions);
}); });
}, [as, bagID, userAPI, user]); }, [as, bagID, userAPI, user]);

View file

@ -147,7 +147,7 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
(end && "&end=" + end) (end && "&end=" + end)
) )
if (view) { if (view) {
url = url + "?as=" + view url = url + "&as=" + view
} }
return get<pond.ListGrainBagHistoryResponse>(url); return get<pond.ListGrainBagHistoryResponse>(url);
}; };

View file

@ -11,6 +11,7 @@ interface Props {
export default function TransactionDataDisplay(props: Props) { export default function TransactionDataDisplay(props: Props) {
const { transaction } = props; const { transaction } = props;
console.log(transaction)
const display = () => { const display = () => {
let transactionData = transaction.transaction.transaction; let transactionData = transaction.transaction.transaction;

View file

@ -455,8 +455,11 @@ export default function UserSettings(props: Props) {
case 1: case 1:
grainUnit = pond.GrainUnit.GRAIN_UNIT_BUSHELS; grainUnit = pond.GrainUnit.GRAIN_UNIT_BUSHELS;
break; break;
case 2: case 3:
grainUnit = pond.GrainUnit.GRAIN_UNIT_WEIGHT; grainUnit = pond.GrainUnit.GRAIN_UNIT_TONNE;
break;
case 4:
grainUnit = pond.GrainUnit.GRAIN_UNIT_TON;
break; break;
default: default:
grainUnit = pond.GrainUnit.GRAIN_UNIT_UNKNOWN; grainUnit = pond.GrainUnit.GRAIN_UNIT_UNKNOWN;
@ -540,7 +543,8 @@ export default function UserSettings(props: Props) {
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

@ -55,13 +55,33 @@ export function setDistanceUnit(unit: pond.DistanceUnit) {
} }
export function getGrainUnit(): pond.GrainUnit { export function getGrainUnit(): pond.GrainUnit {
return localStorage.getItem("grainUnit") === "mT" switch(localStorage.getItem("grainUnit")){
? pond.GrainUnit.GRAIN_UNIT_WEIGHT case "mT":
: pond.GrainUnit.GRAIN_UNIT_BUSHELS; return pond.GrainUnit.GRAIN_UNIT_TONNE
case "t":
return pond.GrainUnit.GRAIN_UNIT_TON
default:
return pond.GrainUnit.GRAIN_UNIT_BUSHELS
}
// return localStorage.getItem("grainUnit") === "mT"
// ? pond.GrainUnit.GRAIN_UNIT_WEIGHT
// : pond.GrainUnit.GRAIN_UNIT_BUSHELS;
} }
export function setGrainUnit(unit: pond.GrainUnit) { export function setGrainUnit(unit: pond.GrainUnit) {
localStorage.setItem("grainUnit", unit === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? "mT" : "bu"); switch(unit){
case pond.GrainUnit.GRAIN_UNIT_WEIGHT:
case pond.GrainUnit.GRAIN_UNIT_TONNE:
localStorage.setItem("grainUnit", "mT")
break;
case pond.GrainUnit.GRAIN_UNIT_TON:
localStorage.setItem("grainUnit", "t")
break;
default:
localStorage.setItem("grainUnit", "bu")
}
// localStorage.setItem("grainUnit", unit === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? "mT" : "bu");
} }
export const distanceConversion = (val: number) => { export const distanceConversion = (val: number) => {