working on US ton stuff
This commit is contained in:
parent
3401cc7c15
commit
29d9e7377c
18 changed files with 474 additions and 117 deletions
|
|
@ -126,14 +126,13 @@ interface BinFormExtension {
|
|||
hopperHeight: string;
|
||||
diameter: string;
|
||||
grainBushels: string;
|
||||
grainTonnes: string;
|
||||
grainWeight: string;
|
||||
grainType: Option | null;
|
||||
grainUse: Option | null;
|
||||
grainSubtype: string;
|
||||
customTypeName: string;
|
||||
highTemp: number;
|
||||
lowTemp: number;
|
||||
bushelsPerTonne: string;
|
||||
tempTarget: number;
|
||||
}
|
||||
|
||||
|
|
@ -160,14 +159,13 @@ export default function BinSettings(props: Props) {
|
|||
hopperHeight: "",
|
||||
diameter: "",
|
||||
grainBushels: "",
|
||||
grainTonnes: "",
|
||||
grainWeight: "",
|
||||
grainType: null,
|
||||
grainUse: null,
|
||||
grainSubtype: "",
|
||||
customTypeName: "",
|
||||
highTemp: 20,
|
||||
lowTemp: 10,
|
||||
bushelsPerTonne: "",
|
||||
tempTarget: 15
|
||||
});
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
|
|
@ -194,6 +192,7 @@ export default function BinSettings(props: Props) {
|
|||
const [isCustomBin, setIsCustomBin] = useState(false);
|
||||
const [binModelOps, setBinModelOptions] = useState<Option[]>([]);
|
||||
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 [autoTopNode, setAutoTopNode] = useState(false);
|
||||
const [inventoryControl, setInventoryControl] = useState<pond.BinInventoryControl>(
|
||||
|
|
@ -232,14 +231,30 @@ export default function BinSettings(props: Props) {
|
|||
|
||||
if (initForm.inventory) {
|
||||
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
|
||||
if (!initForm.inventory.bushelsPerTonne) {
|
||||
initForm.inventory.bushelsPerTonne = GrainDescriber(
|
||||
//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
|
||||
const grain = GrainDescriber(
|
||||
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){
|
||||
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 (!initForm.inventory.targetTemperature || initForm.inventory.targetTemperature) {
|
||||
|
|
@ -290,6 +305,21 @@ export default function BinSettings(props: Props) {
|
|||
? initForm.inventory.grainBushels * 35.239
|
||||
: 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);
|
||||
setHighTempC(initForm.highTemp ?? 20);
|
||||
|
|
@ -299,9 +329,10 @@ export default function BinSettings(props: Props) {
|
|||
height: h,
|
||||
diameter: d,
|
||||
grainBushels: gb.toFixed(2),
|
||||
grainTonnes: initForm.inventory?.bushelsPerTonne
|
||||
? (gb / initForm.inventory.bushelsPerTonne).toFixed(2)
|
||||
: "",
|
||||
grainWeight: weight,
|
||||
// grainTons: initForm.inventory?.bushelsPerTon
|
||||
// ? (gb / initForm.inventory.bushelsPerTon).toFixed(2)
|
||||
// : "",
|
||||
grainType: initForm.inventory?.grainType
|
||||
? ToGrainOption(initForm.inventory.grainType)
|
||||
: null,
|
||||
|
|
@ -315,8 +346,7 @@ export default function BinSettings(props: Props) {
|
|||
tempTarget: target,
|
||||
hopperHeight: hopperHeight,
|
||||
topConeHeight: topconeHeight,
|
||||
sidewallHeight: sidewallHeight,
|
||||
bushelsPerTonne: initForm.inventory?.bushelsPerTonne.toString() ?? "0"
|
||||
sidewallHeight: sidewallHeight
|
||||
});
|
||||
setInMoistureString(initForm.inventory?.initialMoisture.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 inventory = form.inventory;
|
||||
const empty = inventory ? inventory.empty : false;
|
||||
const bushPerTonne = formExtension.bushelsPerTonne;
|
||||
const binQuantity = formExtension.grainBushels;
|
||||
const grainTonnes = formExtension.grainTonnes;
|
||||
const grainType = formExtension.grainType;
|
||||
const grainSubtype = formExtension.grainSubtype;
|
||||
const grainUse = formExtension.grainUse;
|
||||
|
|
@ -805,11 +926,12 @@ export default function BinSettings(props: Props) {
|
|||
pond.BinInventory.create({
|
||||
...form.inventory,
|
||||
grainType: pond.Grain.GRAIN_CUSTOM,
|
||||
bushelsPerTonne: 0
|
||||
bushelsPerTonne: 0,
|
||||
bushelsPerTon: 0
|
||||
})
|
||||
);
|
||||
updateFormExtension("grainType", null);
|
||||
updateFormExtension("bushelsPerTonne", "");
|
||||
setBushelConversion(0)
|
||||
} else {
|
||||
setStorageType(pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN);
|
||||
updateForm(
|
||||
|
|
@ -859,7 +981,8 @@ export default function BinSettings(props: Props) {
|
|||
let storageType = parseFloat(value) as pond.BinStorage;
|
||||
setStorageType(storageType);
|
||||
if (storageType === pond.BinStorage.BIN_STORAGE_FERTILIZER) {
|
||||
formExtension.bushelsPerTonne = "";
|
||||
// formExtension.bushelsPerTonne = "";
|
||||
setBushelConversion(0)
|
||||
formExtension.grainBushels = (
|
||||
parseFloat(formExtension.grainBushels) * 35.239
|
||||
).toFixed(0);
|
||||
|
|
@ -1054,7 +1177,30 @@ export default function BinSettings(props: Props) {
|
|||
</React.Fragment>
|
||||
:
|
||||
<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>
|
||||
}
|
||||
</React.Fragment>
|
||||
|
|
@ -1073,11 +1219,22 @@ export default function BinSettings(props: Props) {
|
|||
pond.BinInventory.create({
|
||||
...form.inventory,
|
||||
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
|
||||
//and is reset whenever the user switches between custom or not
|
||||
let conversion = 0
|
||||
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);
|
||||
}}
|
||||
group
|
||||
|
|
@ -1106,7 +1263,8 @@ export default function BinSettings(props: Props) {
|
|||
/>
|
||||
</React.Fragment>
|
||||
}
|
||||
{getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_BUSHELS ||
|
||||
{inventoryAmount()}
|
||||
{/* {getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_BUSHELS ||
|
||||
storageType === pond.BinStorage.BIN_STORAGE_FERTILIZER ||
|
||||
formExtension.bushelsPerTonne === "0" ||
|
||||
formExtension.bushelsPerTonne === "" ? (
|
||||
|
|
@ -1163,7 +1321,7 @@ export default function BinSettings(props: Props) {
|
|||
) : (
|
||||
<TextField
|
||||
label="Amount"
|
||||
value={grainTonnes}
|
||||
value={grainWeight}
|
||||
type="number"
|
||||
onChange={event => {
|
||||
let newWeight = event.target.value;
|
||||
|
|
@ -1180,7 +1338,7 @@ export default function BinSettings(props: Props) {
|
|||
})
|
||||
);
|
||||
//updateFormExtension("grainBushels", newBushels.toString())
|
||||
updateFormExtension("grainTonnes", newWeight);
|
||||
updateFormExtension("grainWeight", newWeight);
|
||||
}
|
||||
}}
|
||||
fullWidth
|
||||
|
|
@ -1191,7 +1349,7 @@ export default function BinSettings(props: Props) {
|
|||
}}
|
||||
className={classes.bottomSpacing}
|
||||
/>
|
||||
)}
|
||||
)} */}
|
||||
{!isCustomInventory && (
|
||||
<SearchSelect
|
||||
label="Use"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue