replaced uses of getGrainUnit to the users grainUnit function to pull form logged in users settings rather than local storage
This commit is contained in:
parent
dc54f99abd
commit
cabc0146ed
22 changed files with 146 additions and 250 deletions
|
|
@ -17,7 +17,7 @@ import moment from "moment";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useGlobalState } from "providers";
|
import { useGlobalState } from "providers";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { celsiusToFahrenheit, getGrainUnit, or } from "utils";
|
import { celsiusToFahrenheit, or } from "utils";
|
||||||
//import { useHistory } from "react-router";
|
//import { useHistory } from "react-router";
|
||||||
//import BinModeDot from "./BinModeDot";
|
//import BinModeDot from "./BinModeDot";
|
||||||
import BinSVGV2 from "./BinSVGV2";
|
import BinSVGV2 from "./BinSVGV2";
|
||||||
|
|
@ -444,16 +444,16 @@ export default function BinCard(props: Props) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1) {
|
||||||
return (
|
return (
|
||||||
bin.grainInventory().toLocaleString() +
|
bin.grainInventory(user).toLocaleString() +
|
||||||
" mT " +
|
" mT " +
|
||||||
bin.fillPercent() +
|
bin.fillPercent() +
|
||||||
"%"
|
"%"
|
||||||
);
|
);
|
||||||
} else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1) {
|
} else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1) {
|
||||||
return (
|
return (
|
||||||
bin.grainInventory().toLocaleString() +
|
bin.grainInventory(user).toLocaleString() +
|
||||||
" t " +
|
" t " +
|
||||||
bin.fillPercent() +
|
bin.fillPercent() +
|
||||||
"%"
|
"%"
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ import { pond } from "protobuf-ts/pond";
|
||||||
import { useBinAPI, useBinYardAPI, useGlobalState, useLibraCartProxyAPI } from "providers";
|
import { useBinAPI, useBinYardAPI, useGlobalState, useLibraCartProxyAPI } from "providers";
|
||||||
import React, { useCallback, useEffect, useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
// import { useHistory } from "react-router";
|
// import { useHistory } from "react-router";
|
||||||
import { or, getGrainUnit } from "utils";
|
import { or } from "utils";
|
||||||
import { makeStyles } from "@mui/styles";
|
import { makeStyles } from "@mui/styles";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import BinSelector from "./BinSelector";
|
import BinSelector from "./BinSelector";
|
||||||
|
|
@ -240,16 +240,16 @@ export default function BinSettings(props: Props) {
|
||||||
initForm.inventory.bushelsPerTonne = grain.bushelsPerTonne;
|
initForm.inventory.bushelsPerTonne = grain.bushelsPerTonne;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
setBushelConversion(initForm.inventory.bushelsPerTonne)
|
setBushelConversion(initForm.inventory.bushelsPerTonne)
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
setBushelConversion(initForm.inventory.bushelsPerTonne * 0.907)
|
setBushelConversion(initForm.inventory.bushelsPerTonne * 0.907)
|
||||||
}
|
}
|
||||||
if (initForm.inventory.customGrain){
|
if (initForm.inventory.customGrain){
|
||||||
setCustomGrain(initForm.inventory.customGrain)
|
setCustomGrain(initForm.inventory.customGrain)
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
setBushelConversion(initForm.inventory.customGrain.bushelsPerTonne)
|
setBushelConversion(initForm.inventory.customGrain.bushelsPerTonne)
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
setBushelConversion(initForm.inventory.customGrain.bushelsPerTonne * 0.907)
|
setBushelConversion(initForm.inventory.customGrain.bushelsPerTonne * 0.907)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -304,15 +304,15 @@ export default function BinSettings(props: Props) {
|
||||||
: initForm.inventory?.grainBushels ?? 0;
|
: initForm.inventory?.grainBushels ?? 0;
|
||||||
let weight = ""
|
let weight = ""
|
||||||
if(initForm.inventory){
|
if(initForm.inventory){
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
weight = (gb/initForm.inventory.bushelsPerTonne).toFixed(2)
|
weight = (gb/initForm.inventory.bushelsPerTonne).toFixed(2)
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
weight = (gb/(initForm.inventory.bushelsPerTonne * 0.907)).toFixed(2)
|
weight = (gb/(initForm.inventory.bushelsPerTonne * 0.907)).toFixed(2)
|
||||||
}
|
}
|
||||||
if(initForm.inventory.customGrain){
|
if(initForm.inventory.customGrain){
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
weight = (gb/initForm.inventory.customGrain.bushelsPerTonne).toFixed(2)
|
weight = (gb/initForm.inventory.customGrain.bushelsPerTonne).toFixed(2)
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
weight = (gb/(initForm.inventory.customGrain.bushelsPerTonne * 0.907)).toFixed(2)
|
weight = (gb/(initForm.inventory.customGrain.bushelsPerTonne * 0.907)).toFixed(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -804,7 +804,7 @@ export default function BinSettings(props: Props) {
|
||||||
const binQuantity = formExtension.grainBushels;
|
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
|
//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 !== "")){
|
if(storageType !== pond.BinStorage.BIN_STORAGE_FERTILIZER && ((user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE || user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) && bushelConversion !== 0 && grainWeight !== "")){
|
||||||
return (
|
return (
|
||||||
<TextField
|
<TextField
|
||||||
label="Amount"
|
label="Amount"
|
||||||
|
|
@ -830,7 +830,7 @@ export default function BinSettings(props: Props) {
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
disabled={!canEdit}
|
disabled={!canEdit}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
endAdornment: <InputAdornment position="end">{getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE ? "mT" : "t"}</InputAdornment>
|
endAdornment: <InputAdornment position="end">{user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE ? "mT" : "t"}</InputAdornment>
|
||||||
}}
|
}}
|
||||||
className={classes.bottomSpacing}
|
className={classes.bottomSpacing}
|
||||||
/>
|
/>
|
||||||
|
|
@ -1179,9 +1179,9 @@ export default function BinSettings(props: Props) {
|
||||||
setCustomGrain(newGrainSettings)
|
setCustomGrain(newGrainSettings)
|
||||||
let conversion = 0
|
let conversion = 0
|
||||||
|
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
conversion = newGrainSettings.bushelsPerTonne
|
conversion = newGrainSettings.bushelsPerTonne
|
||||||
}else if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
conversion = newGrainSettings.bushelsPerTonne * 0.907
|
conversion = newGrainSettings.bushelsPerTonne * 0.907
|
||||||
}
|
}
|
||||||
updateForm(
|
updateForm(
|
||||||
|
|
@ -1218,9 +1218,9 @@ export default function BinSettings(props: Props) {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
let conversion = 0
|
let conversion = 0
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
conversion = GrainDescriber(newGrainType).bushelsPerTonne
|
conversion = GrainDescriber(newGrainType).bushelsPerTonne
|
||||||
}else if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
conversion = GrainDescriber(newGrainType).bushelsPerTon
|
conversion = GrainDescriber(newGrainType).bushelsPerTon
|
||||||
}
|
}
|
||||||
setBushelConversion(conversion)
|
setBushelConversion(conversion)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,10 @@ import { Transaction } from "models/Transaction";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import ObjectDescriber from "objects/ObjectDescriber";
|
import ObjectDescriber from "objects/ObjectDescriber";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useBinAPI, useContractAPI, useFieldAPI, useGrainBagAPI, useSnackbar, useTransactionAPI } from "providers";
|
import { useBinAPI, useContractAPI, useFieldAPI, useGlobalState, useGrainBagAPI, useSnackbar, useTransactionAPI } from "providers";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import TransactionDataDisplay from "transactions/transactionDataDisplay";
|
import TransactionDataDisplay from "transactions/transactionDataDisplay";
|
||||||
import { getGrainUnit } from "utils";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
bin: Bin
|
bin: Bin
|
||||||
|
|
@ -26,6 +25,7 @@ export default function BinTransactions(props: Props){
|
||||||
const { bin, permissions, refresh } = props
|
const { bin, permissions, refresh } = props
|
||||||
const [state, setState] = useState<pond.TransactionState>(pond.TransactionState.TRANSACTION_STATE_APPROVAL_REQUIRED)
|
const [state, setState] = useState<pond.TransactionState>(pond.TransactionState.TRANSACTION_STATE_APPROVAL_REQUIRED)
|
||||||
const transactionAPI = useTransactionAPI()
|
const transactionAPI = useTransactionAPI()
|
||||||
|
const [{user}] = useGlobalState()
|
||||||
const binAPI = useBinAPI()
|
const binAPI = useBinAPI()
|
||||||
const grainBagAPI = useGrainBagAPI()
|
const grainBagAPI = useGrainBagAPI()
|
||||||
const fieldAPI = useFieldAPI()
|
const fieldAPI = useFieldAPI()
|
||||||
|
|
@ -103,7 +103,7 @@ export default function BinTransactions(props: Props){
|
||||||
const loadContracts = useCallback(()=>{
|
const loadContracts = useCallback(()=>{
|
||||||
contractAPI.listContracts(0,0, "asc", "name").then(resp => {
|
contractAPI.listContracts(0,0, "asc", "name").then(resp => {
|
||||||
setContractOptions(resp.data.contracts.map(c => {
|
setContractOptions(resp.data.contracts.map(c => {
|
||||||
let contract = Contract.create(c)
|
let contract = Contract.create(c, user)
|
||||||
return {label: contract.name(), value: contract.key(), group: contract.grainName()}
|
return {label: contract.name(), value: contract.key(), group: contract.grainName()}
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
@ -198,11 +198,11 @@ export default function BinTransactions(props: Props){
|
||||||
|
|
||||||
const grainQuantityDisplay = (bushels: number) => {
|
const grainQuantityDisplay = (bushels: number) => {
|
||||||
const grainTransaction = selectedTransaction?.transaction.transaction?.grainTransaction ?? pond.GrainTransaction.create()
|
const grainTransaction = selectedTransaction?.transaction.transaction?.grainTransaction ?? pond.GrainTransaction.create()
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainTransaction.bushelsPerTonne > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainTransaction.bushelsPerTonne > 1){
|
||||||
let tonneWeight = bushels / grainTransaction.bushelsPerTonne
|
let tonneWeight = bushels / grainTransaction.bushelsPerTonne
|
||||||
return tonneWeight + " mT"
|
return tonneWeight + " mT"
|
||||||
}
|
}
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainTransaction.bushelsPerTonne > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainTransaction.bushelsPerTonne > 1){
|
||||||
let tonneWeight = bushels / (grainTransaction.bushelsPerTonne * 0.907)
|
let tonneWeight = bushels / (grainTransaction.bushelsPerTonne * 0.907)
|
||||||
return tonneWeight + " t"
|
return tonneWeight + " t"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ import { FullScreen, useFullScreenHandle } from "react-full-screen";
|
||||||
import moment, { Moment } from "moment";
|
import moment, { Moment } from "moment";
|
||||||
import ResponsiveDialog from "common/ResponsiveDialog";
|
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||||
import { getThemeType } from "theme";
|
import { getThemeType } from "theme";
|
||||||
import { getGrainUnit, or } from "utils";
|
import { or } from "utils";
|
||||||
import { useBinAPI } from "providers/pond/binAPI";
|
import { useBinAPI } from "providers/pond/binAPI";
|
||||||
import BindaptIcon from "products/Bindapt/BindaptIcon";
|
import BindaptIcon from "products/Bindapt/BindaptIcon";
|
||||||
import {
|
import {
|
||||||
|
|
@ -498,9 +498,9 @@ 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_TONNE && bin.bushelsPerTonne() > 1) {
|
if (user.grainUnit() === 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.bushelsPerTonne() > 1) {
|
} else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1) {
|
||||||
return Math.round((val / (bin.bushelsPerTonne()*0.907)) * 100) / 100;
|
return Math.round((val / (bin.bushelsPerTonne()*0.907)) * 100) / 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -516,9 +516,9 @@ 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_TONNE && bin.bushelsPerTonne() > 1) {
|
if (user.grainUnit() === 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.bushelsPerTonne() > 1) {
|
} else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1) {
|
||||||
return "t (" + bin.fillPercent() + "%)";
|
return "t (" + bin.fillPercent() + "%)";
|
||||||
} else {
|
} else {
|
||||||
return " / " + capacity.toLocaleString() + " bu";
|
return " / " + capacity.toLocaleString() + " bu";
|
||||||
|
|
@ -1328,14 +1328,14 @@ export default function BinVisualizer(props: Props) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1) {
|
if (user.grainUnit() === 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.bushelsPerTonne() > 1) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1) {
|
||||||
diffDisplay = diffDisplay / (bin.bushelsPerTonne()*0.907);
|
diffDisplay = diffDisplay / (bin.bushelsPerTonne()*0.907);
|
||||||
if (pendingDisplay) {
|
if (pendingDisplay) {
|
||||||
pendingDisplay = pendingDisplay / (bin.bushelsPerTonne()*0.907);
|
pendingDisplay = pendingDisplay / (bin.bushelsPerTonne()*0.907);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ import { Bin } from "models";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useBinAPI, useGlobalState } from "providers";
|
import { useBinAPI, useGlobalState } from "providers";
|
||||||
import React, { useEffect, useState, useCallback, SetStateAction } from "react";
|
import React, { useEffect, useState, useCallback, SetStateAction } from "react";
|
||||||
import { getGrainUnit, stringToMaterialColour } from "utils";
|
import { stringToMaterialColour } from "utils";
|
||||||
//import BinsFansStatusTable from "./BinFansStatusTable";
|
//import BinsFansStatusTable from "./BinFansStatusTable";
|
||||||
import BinsList from "./BinsList";
|
import BinsList from "./BinsList";
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@ export default function BinyardDisplay(props: Props) {
|
||||||
const isMobile = useMobile();
|
const isMobile = useMobile();
|
||||||
const [carouselIndex, setCarouselIndex] = useState(0);
|
const [carouselIndex, setCarouselIndex] = useState(0);
|
||||||
const [binMenuAnchorEl, setBinMenuAnchorEl] = useState<Element | null>(null);
|
const [binMenuAnchorEl, setBinMenuAnchorEl] = useState<Element | null>(null);
|
||||||
const [{ as }] = useGlobalState();
|
const [{ as, user }] = useGlobalState();
|
||||||
const maxBins = 40;
|
const maxBins = 40;
|
||||||
const [binsLoading, setBinsLoading] = useState(false);
|
const [binsLoading, setBinsLoading] = useState(false);
|
||||||
const [expandTotal, setExpandTotal] = useState(false);
|
const [expandTotal, setExpandTotal] = useState(false);
|
||||||
|
|
@ -658,7 +658,7 @@ export default function BinyardDisplay(props: Props) {
|
||||||
return " bu";
|
return " bu";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (getGrainUnit()) {
|
switch (user.grainUnit()) {
|
||||||
case pond.GrainUnit.GRAIN_UNIT_TONNE:
|
case pond.GrainUnit.GRAIN_UNIT_TONNE:
|
||||||
return " mT";
|
return " mT";
|
||||||
case pond.GrainUnit.GRAIN_UNIT_TON:
|
case pond.GrainUnit.GRAIN_UNIT_TON:
|
||||||
|
|
@ -671,9 +671,9 @@ export default function BinyardDisplay(props: Props) {
|
||||||
const customQuantityDisplay = (customInventory: pond.CustomInventory, bushels: number) => {
|
const customQuantityDisplay = (customInventory: pond.CustomInventory, bushels: number) => {
|
||||||
let amount = bushels
|
let amount = bushels
|
||||||
if(customInventory.bushelsPerTonne > 1){
|
if(customInventory.bushelsPerTonne > 1){
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
amount = bushels/customInventory.bushelsPerTonne
|
amount = bushels/customInventory.bushelsPerTonne
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
amount = bushels/(customInventory.bushelsPerTonne*0.907)
|
amount = bushels/(customInventory.bushelsPerTonne*0.907)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -683,9 +683,9 @@ export default function BinyardDisplay(props: Props) {
|
||||||
const supportedGrainDisplay = (grain: pond.Grain, bushels: number) => {
|
const supportedGrainDisplay = (grain: pond.Grain, bushels: number) => {
|
||||||
const describer = GrainDescriber(grain)
|
const describer = GrainDescriber(grain)
|
||||||
let amount = bushels
|
let amount = bushels
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
amount = bushels/describer.bushelsPerTonne
|
amount = bushels/describer.bushelsPerTonne
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
amount = bushels/describer.bushelsPerTon
|
amount = bushels/describer.bushelsPerTon
|
||||||
}
|
}
|
||||||
return Math.round(amount*100)/100
|
return Math.round(amount*100)/100
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import { pond } from "protobuf-ts/pond";
|
||||||
import { useBinAPI, useGlobalState } from "providers";
|
import { useBinAPI, useGlobalState } from "providers";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { Legend } from "recharts";
|
import { Legend } from "recharts";
|
||||||
import { getGrainUnit } from "utils";
|
|
||||||
import BinLevelAreaGraph from "./BinLevelAreaGraph";
|
import BinLevelAreaGraph from "./BinLevelAreaGraph";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -32,7 +31,7 @@ interface InventoryAt {
|
||||||
export default function BinLevelOverTime(props: Props) {
|
export default function BinLevelOverTime(props: Props) {
|
||||||
const { bin, fertilizerBin, colour, startDate, endDate, customHeight } = props;
|
const { bin, fertilizerBin, colour, startDate, endDate, customHeight } = props;
|
||||||
const binAPI = useBinAPI();
|
const binAPI = useBinAPI();
|
||||||
const [{as}] = useGlobalState();
|
const [{as, user}] = useGlobalState();
|
||||||
const [inventoryData, setInventoryData] = useState<InventoryAt[]>([]);
|
const [inventoryData, setInventoryData] = useState<InventoryAt[]>([]);
|
||||||
const [dataLoading, setDataLoading] = useState(false);
|
const [dataLoading, setDataLoading] = useState(false);
|
||||||
const [capacity, setCapacity] = useState<number | undefined>();
|
const [capacity, setCapacity] = useState<number | undefined>();
|
||||||
|
|
@ -69,10 +68,10 @@ 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_TONNE && cap) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && cap) {
|
||||||
cap = cap / bin.bushelsPerTonne();
|
cap = cap / bin.bushelsPerTonne();
|
||||||
}
|
}
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && cap) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && cap) {
|
||||||
cap = cap / (bin.bushelsPerTonne()*0.907);
|
cap = cap / (bin.bushelsPerTonne()*0.907);
|
||||||
}
|
}
|
||||||
setCapacity(cap);
|
setCapacity(cap);
|
||||||
|
|
@ -89,10 +88,10 @@ export default function BinLevelOverTime(props: Props) {
|
||||||
let bushels = hist.settings.inventory.grainBushels ?? 0;
|
let bushels = hist.settings.inventory.grainBushels ?? 0;
|
||||||
if (bushels !== lastBushels) {
|
if (bushels !== lastBushels) {
|
||||||
let grainDisplay = bushels
|
let grainDisplay = bushels
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
|
||||||
grainDisplay = Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100;
|
grainDisplay = Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100;
|
||||||
}
|
}
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1){
|
||||||
grainDisplay = Math.round((bushels / (bin.bushelsPerTonne()*0.907)) * 100) / 100;
|
grainDisplay = Math.round((bushels / (bin.bushelsPerTonne()*0.907)) * 100) / 100;
|
||||||
}
|
}
|
||||||
let newData: InventoryAt = {
|
let newData: InventoryAt = {
|
||||||
|
|
@ -121,10 +120,10 @@ export default function BinLevelOverTime(props: Props) {
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
let bushels = bin.bushels();
|
let bushels = bin.bushels();
|
||||||
let grainDisplay = bushels
|
let grainDisplay = bushels
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
|
||||||
grainDisplay = Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100;
|
grainDisplay = Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100;
|
||||||
}
|
}
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1){
|
||||||
grainDisplay = Math.round((bushels / (bin.bushelsPerTonne()*0.907)) * 100) / 100;
|
grainDisplay = Math.round((bushels / (bin.bushelsPerTonne()*0.907)) * 100) / 100;
|
||||||
}
|
}
|
||||||
data.push({
|
data.push({
|
||||||
|
|
@ -156,10 +155,10 @@ 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_TONNE && cap) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && cap) {
|
||||||
cap = cap / bin.bushelsPerTonne();
|
cap = cap / bin.bushelsPerTonne();
|
||||||
}
|
}
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && cap) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && cap) {
|
||||||
cap = cap / (bin.bushelsPerTonne()*0.907);
|
cap = cap / (bin.bushelsPerTonne()*0.907);
|
||||||
}
|
}
|
||||||
setCapacity(cap);
|
setCapacity(cap);
|
||||||
|
|
@ -180,10 +179,10 @@ export default function BinLevelOverTime(props: Props) {
|
||||||
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]
|
let grainDisplay = val.values[0]
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
|
||||||
grainDisplay = Math.round((grainDisplay / bin.bushelsPerTonne()) * 100) / 100;
|
grainDisplay = Math.round((grainDisplay / bin.bushelsPerTonne()) * 100) / 100;
|
||||||
}
|
}
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1){
|
||||||
grainDisplay = Math.round((grainDisplay / (bin.bushelsPerTonne()*0.907)) * 100) / 100;
|
grainDisplay = Math.round((grainDisplay / (bin.bushelsPerTonne()*0.907)) * 100) / 100;
|
||||||
}
|
}
|
||||||
autoBarData.push({
|
autoBarData.push({
|
||||||
|
|
@ -199,10 +198,10 @@ export default function BinLevelOverTime(props: Props) {
|
||||||
let bushels = bin.bushels();
|
let bushels = bin.bushels();
|
||||||
let currentTime = moment().valueOf();
|
let currentTime = moment().valueOf();
|
||||||
let grainDisplay = bushels
|
let grainDisplay = bushels
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
|
||||||
grainDisplay = Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100;
|
grainDisplay = Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100;
|
||||||
}
|
}
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTonne() > 1){
|
||||||
grainDisplay = Math.round((bushels / (bin.bushelsPerTonne()*0.907)) * 100) / 100;
|
grainDisplay = Math.round((bushels / (bin.bushelsPerTonne()*0.907)) * 100) / 100;
|
||||||
}
|
}
|
||||||
autoBarData.push({
|
autoBarData.push({
|
||||||
|
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
import { Box, Card, Typography, useTheme } from "@mui/material";
|
|
||||||
import GrainDescriber from "grain/GrainDescriber";
|
|
||||||
import { Contract } from "models/Contract";
|
|
||||||
import { Label, Pie, PieChart, ResponsiveContainer, Text } from "recharts";
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
contract: Contract;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ContractVisualizer(props: Props) {
|
|
||||||
const { contract } = props;
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card style={{ height: "100%", padding: 10 }}>
|
|
||||||
<Box height={"15%"}>
|
|
||||||
<Typography style={{ fontWeight: 650, fontSize: 20 }}>
|
|
||||||
{GrainDescriber(contract.grain()).name}
|
|
||||||
</Typography>
|
|
||||||
<Typography style={{ fontWeight: 650, fontSize: 15 }}>
|
|
||||||
{contract.deliveredInPreferredUnit().toFixed(2)}/
|
|
||||||
{contract.sizeInPreferredUnit().toFixed(2)} {contract.unit}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<ResponsiveContainer height={"85%"}>
|
|
||||||
<PieChart>
|
|
||||||
{/* <Legend
|
|
||||||
verticalAlign="bottom"
|
|
||||||
content={() => (
|
|
||||||
<Box textAlign="center" marginY={0.5}>
|
|
||||||
<Chip label={contract.commodityLabel()} />
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
/> */}
|
|
||||||
<Pie
|
|
||||||
outerRadius={"100%"}
|
|
||||||
innerRadius="70%"
|
|
||||||
stroke="transparent"
|
|
||||||
data={[
|
|
||||||
{
|
|
||||||
name: "",
|
|
||||||
value: contract.settings.delivered,
|
|
||||||
fill: contract.colour
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "",
|
|
||||||
value: contract.settings.size - contract.settings.delivered
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
dataKey="value"
|
|
||||||
cx="50%"
|
|
||||||
cy="50%">
|
|
||||||
<Label
|
|
||||||
position="center"
|
|
||||||
fill={theme.palette.text.secondary}
|
|
||||||
fontSize={"2rem"}
|
|
||||||
fontWeight={650}
|
|
||||||
content={props => {
|
|
||||||
const { cx, cy } = props.viewBox as any;
|
|
||||||
return (
|
|
||||||
<g>
|
|
||||||
<Text
|
|
||||||
x={cx}
|
|
||||||
y={cy}
|
|
||||||
dy={-15}
|
|
||||||
textAnchor="middle"
|
|
||||||
verticalAnchor="middle"
|
|
||||||
fill={props.fill}
|
|
||||||
fontWeight={props.fontWeight}
|
|
||||||
fontSize={props.fontSize}>
|
|
||||||
{((contract.settings.delivered / contract.settings.size) * 100).toFixed(1) +
|
|
||||||
"%"}
|
|
||||||
</Text>
|
|
||||||
</g>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Label
|
|
||||||
position="center"
|
|
||||||
fill={theme.palette.text.secondary}
|
|
||||||
fontSize={"1.5rem"}
|
|
||||||
fontWeight={650}
|
|
||||||
content={props => {
|
|
||||||
const { cx, cy } = props.viewBox as any;
|
|
||||||
return (
|
|
||||||
<g>
|
|
||||||
<Text
|
|
||||||
x={cx}
|
|
||||||
y={cy}
|
|
||||||
dy={15}
|
|
||||||
textAnchor="middle"
|
|
||||||
verticalAnchor="middle"
|
|
||||||
fill={props.fill}
|
|
||||||
fontWeight={props.fontWeight}
|
|
||||||
fontSize={props.fontSize}>
|
|
||||||
Delivered
|
|
||||||
</Text>
|
|
||||||
</g>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Pie>
|
|
||||||
</PieChart>
|
|
||||||
</ResponsiveContainer>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -60,7 +60,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
||||||
export default function ContractsList(props: Props) {
|
export default function ContractsList(props: Props) {
|
||||||
const { contracts, contractPermissions, updateList } = props;
|
const { contracts, contractPermissions, updateList } = props;
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [{as}] = useGlobalState();
|
const [{as, user}] = useGlobalState();
|
||||||
//will need map for contracts that have supported grain types
|
//will need map for contracts that have supported grain types
|
||||||
const [supportedTypes, setSupportedTypes] = useState<Map<pond.Grain, Contract[]>>(new Map());
|
const [supportedTypes, setSupportedTypes] = useState<Map<pond.Grain, Contract[]>>(new Map());
|
||||||
//will need need map for custom contracts
|
//will need need map for custom contracts
|
||||||
|
|
@ -173,16 +173,16 @@ export default function ContractsList(props: Props) {
|
||||||
<TableCell>{contract.name()}</TableCell>
|
<TableCell>{contract.name()}</TableCell>
|
||||||
<TableCell>{contract.settings.contractDate}</TableCell>
|
<TableCell>{contract.settings.contractDate}</TableCell>
|
||||||
<TableCell>{contract.settings.deliveryWindow?.endDate}</TableCell>
|
<TableCell>{contract.settings.deliveryWindow?.endDate}</TableCell>
|
||||||
<TableCell>{contract.sizeInPreferredUnit() + " " + contract.unit}</TableCell>
|
<TableCell>{contract.sizeInPreferredUnit(user) + " " + contract.unit}</TableCell>
|
||||||
<TableCell>{contract.deliveredInPreferredUnit() + " " + contract.unit}</TableCell>
|
<TableCell>{contract.deliveredInPreferredUnit(user) + " " + contract.unit}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{/* <progress value={contract.settings.delivered} max={contract.settings.size} style={{height: 10}}/> */}
|
{/* <progress value={contract.settings.delivered} max={contract.settings.size} style={{height: 10}}/> */}
|
||||||
<CustomProgressBar colour={colors.blue[500]} completed={fillPercent} />
|
<CustomProgressBar colour={colors.blue[500]} completed={fillPercent} />
|
||||||
{/* {((contract.settings.delivered/contract.settings.size)*100).toFixed(1) + "%"} */}
|
{/* {((contract.settings.delivered/contract.settings.size)*100).toFixed(1) + "%"} */}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{contract.sizeInPreferredUnit() -
|
{contract.sizeInPreferredUnit(user) -
|
||||||
contract.deliveredInPreferredUnit() +
|
contract.deliveredInPreferredUnit(user) +
|
||||||
" " +
|
" " +
|
||||||
contract.unit}
|
contract.unit}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import moment from "moment";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useGlobalState, useTaskAPI, useContractAPI, useSnackbar } from "providers";
|
import { useGlobalState, useTaskAPI, useContractAPI, useSnackbar } from "providers";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { getGrainUnit } from "utils";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
|
|
@ -45,7 +44,7 @@ export default function ContractSettings(props: Props) {
|
||||||
const { open, close, contract } = props;
|
const { open, close, contract } = props;
|
||||||
const contractAPI = useContractAPI();
|
const contractAPI = useContractAPI();
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [{as}] = useGlobalState();
|
const [{as, user}] = useGlobalState();
|
||||||
const [contractID, setContractID] = useState(""); //id
|
const [contractID, setContractID] = useState(""); //id
|
||||||
const [holder, setHolder] = useState(""); //holder
|
const [holder, setHolder] = useState(""); //holder
|
||||||
const [deliveryStart, setDeliveryStart] = useState(moment().format("YYYY-MM-DD")); //deliverystart
|
const [deliveryStart, setDeliveryStart] = useState(moment().format("YYYY-MM-DD")); //deliverystart
|
||||||
|
|
@ -72,7 +71,6 @@ export default function ContractSettings(props: Props) {
|
||||||
adornment: ""
|
adornment: ""
|
||||||
});
|
});
|
||||||
const taskAPI = useTaskAPI();
|
const taskAPI = useTaskAPI();
|
||||||
const [{ user }] = useGlobalState();
|
|
||||||
|
|
||||||
const closeSettings = () => {
|
const closeSettings = () => {
|
||||||
close();
|
close();
|
||||||
|
|
@ -87,32 +85,32 @@ export default function ContractSettings(props: Props) {
|
||||||
setDeliveryEnd(contract.settings.deliveryWindow?.endDate ?? "");
|
setDeliveryEnd(contract.settings.deliveryWindow?.endDate ?? "");
|
||||||
setContractType(contract.settings.type);
|
setContractType(contract.settings.type);
|
||||||
setCustomCommodity(contract.settings.customCommodity);
|
setCustomCommodity(contract.settings.customCommodity);
|
||||||
setContractSize(contract.sizeInPreferredUnit().toFixed(2));
|
setContractSize(contract.sizeInPreferredUnit(user).toFixed(2));
|
||||||
setDeliveredAmount(contract.deliveredInPreferredUnit().toFixed(2));
|
setDeliveredAmount(contract.deliveredInPreferredUnit(user).toFixed(2));
|
||||||
setContractValue(contract.settings.totalValue.toString());
|
setContractValue(contract.settings.totalValue.toString());
|
||||||
setCommodity(contract.settings.commodity);
|
setCommodity(contract.settings.commodity);
|
||||||
setContractDate(contract.settings.contractDate);
|
setContractDate(contract.settings.contractDate);
|
||||||
let conv = 1
|
let conv = 1
|
||||||
if(contract.settings.conversionValue > 1){
|
if(contract.settings.conversionValue > 1){
|
||||||
conv = contract.settings.conversionValue
|
conv = contract.settings.conversionValue
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
conv = conv * 0.907
|
conv = conv * 0.907
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setConversionValue(conv.toFixed(2));
|
setConversionValue(conv.toFixed(2));
|
||||||
setUseCustom(contract.isCustom());
|
setUseCustom(contract.isCustom());
|
||||||
}
|
}
|
||||||
}, [contract]);
|
}, [contract, user]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
switch (contractType) {
|
switch (contractType) {
|
||||||
case pond.ContractType.CONTRACT_TYPE_GRAIN:
|
case pond.ContractType.CONTRACT_TYPE_GRAIN:
|
||||||
let conversionLabel = "Bushels Per Tonne"
|
let conversionLabel = "Bushels Per Tonne"
|
||||||
let adornment = "bu"
|
let adornment = "bu"
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
adornment = "mT"
|
adornment = "mT"
|
||||||
}
|
}
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
conversionLabel = "Bushels Per Ton"
|
conversionLabel = "Bushels Per Ton"
|
||||||
adornment = "t"
|
adornment = "t"
|
||||||
}
|
}
|
||||||
|
|
@ -167,14 +165,14 @@ export default function ContractSettings(props: Props) {
|
||||||
//we will assume that both of those entries are using the same unit ie both US ton or both metric tonne
|
//we will assume that both of those entries are using the same unit ie both US ton or both metric tonne
|
||||||
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, user));
|
||||||
const sizeVal = isNaN(parseFloat(contractSize))
|
const sizeVal = isNaN(parseFloat(contractSize))
|
||||||
? 0
|
? 0
|
||||||
: Math.round(Contract.toStoredUnit(parseFloat(contractSize), contractType, conVal));
|
: Math.round(Contract.toStoredUnit(parseFloat(contractSize), contractType, conVal, user));
|
||||||
|
|
||||||
//then after the conversion to bushels change the conversion value to metric to be stored in the contract
|
//then after the conversion to bushels change the conversion value to metric to be stored in the contract
|
||||||
if(contractType === pond.ContractType.CONTRACT_TYPE_GRAIN){
|
if(contractType === pond.ContractType.CONTRACT_TYPE_GRAIN){
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
conVal = conVal / 0.907 //convert the ton they entered to mT to be stored in the contracts conversion value
|
conVal = conVal / 0.907 //convert the ton they entered to mT to be stored in the contracts conversion value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import { Transaction } from "models/Transaction";
|
||||||
import BarGraph, { BarData } from "charts/BarGraph";
|
import BarGraph, { BarData } from "charts/BarGraph";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import moment, { Moment } from "moment";
|
import moment, { Moment } from "moment";
|
||||||
import { getGrainUnit } from "utils";
|
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
contract: Contract;
|
contract: Contract;
|
||||||
|
|
@ -14,6 +14,7 @@ interface Props {
|
||||||
|
|
||||||
export default function ContractTransactionGraph(props: Props) {
|
export default function ContractTransactionGraph(props: Props) {
|
||||||
const { contract, transactions } = props;
|
const { contract, transactions } = props;
|
||||||
|
const [{ user }] = useGlobalState();
|
||||||
const [data, setData] = useState<BarData[]>([]);
|
const [data, setData] = useState<BarData[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -27,13 +28,13 @@ export default function ContractTransactionGraph(props: Props) {
|
||||||
if (transaction?.grainTransaction) {
|
if (transaction?.grainTransaction) {
|
||||||
value = transaction.grainTransaction.bushels;
|
value = transaction.grainTransaction.bushels;
|
||||||
if (
|
if (
|
||||||
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE &&
|
user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE &&
|
||||||
transaction.grainTransaction.bushelsPerTonne > 1
|
transaction.grainTransaction.bushelsPerTonne > 1
|
||||||
) {
|
) {
|
||||||
value = value / transaction.grainTransaction.bushelsPerTonne;
|
value = value / transaction.grainTransaction.bushelsPerTonne;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON &&
|
user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON &&
|
||||||
transaction.grainTransaction.bushelsPerTonne > 1
|
transaction.grainTransaction.bushelsPerTonne > 1
|
||||||
) {
|
) {
|
||||||
value = value / (transaction.grainTransaction.bushelsPerTonne * 0.907);
|
value = value / (transaction.grainTransaction.bushelsPerTonne * 0.907);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { Box, Card, Typography, useTheme } from "@mui/material";
|
import { Box, Card, Typography, useTheme } from "@mui/material";
|
||||||
import GrainDescriber from "grain/GrainDescriber";
|
import GrainDescriber from "grain/GrainDescriber";
|
||||||
import { Contract } from "models/Contract";
|
import { Contract } from "models/Contract";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
import { Label, Pie, PieChart, ResponsiveContainer, Text } from "recharts";
|
import { Label, Pie, PieChart, ResponsiveContainer, Text } from "recharts";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -9,6 +10,7 @@ interface Props {
|
||||||
|
|
||||||
export default function ContractVisualizer(props: Props) {
|
export default function ContractVisualizer(props: Props) {
|
||||||
const { contract } = props;
|
const { contract } = props;
|
||||||
|
const [{ user }] = useGlobalState();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -18,8 +20,8 @@ export default function ContractVisualizer(props: Props) {
|
||||||
{GrainDescriber(contract.grain()).name}
|
{GrainDescriber(contract.grain()).name}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography style={{ fontWeight: 650, fontSize: 15 }}>
|
<Typography style={{ fontWeight: 650, fontSize: 15 }}>
|
||||||
{contract.deliveredInPreferredUnit().toFixed(2)}/
|
{contract.deliveredInPreferredUnit(user).toFixed(2)}/
|
||||||
{contract.sizeInPreferredUnit().toFixed(2)} {contract.unit}
|
{contract.sizeInPreferredUnit(user).toFixed(2)} {contract.unit}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<ResponsiveContainer height={"85%"}>
|
<ResponsiveContainer height={"85%"}>
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ import {MenuItem, TextField } from "@mui/material"
|
||||||
import { cloneDeep } from "lodash"
|
import { cloneDeep } from "lodash"
|
||||||
import { pond } from "protobuf-ts/pond"
|
import { pond } from "protobuf-ts/pond"
|
||||||
import React, { useEffect, useRef, useState } from "react"
|
import React, { useEffect, useRef, useState } from "react"
|
||||||
import { getGrainUnit } from "utils"
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
grainSettings?: pond.GrainSettings
|
grainSettings?: pond.GrainSettings
|
||||||
onGrainSettingsChange: (settings: pond.GrainSettings, formValid: boolean) => void
|
onGrainSettingsChange: (settings: pond.GrainSettings, formValid: boolean) => void
|
||||||
|
|
@ -11,6 +10,7 @@ interface Props {
|
||||||
|
|
||||||
export default function CustomGrainForm(props: Props) {
|
export default function CustomGrainForm(props: Props) {
|
||||||
const {grainSettings, onGrainSettingsChange} = props
|
const {grainSettings, onGrainSettingsChange} = props
|
||||||
|
const [{ user }] = useGlobalState();
|
||||||
const [newGrainSettings, setNewGrainSettings] = useState(pond.GrainSettings.create())
|
const [newGrainSettings, setNewGrainSettings] = useState(pond.GrainSettings.create())
|
||||||
const [name, setName] = useState("")
|
const [name, setName] = useState("")
|
||||||
const [group, setGroup] = useState("")
|
const [group, setGroup] = useState("")
|
||||||
|
|
@ -204,7 +204,7 @@ export default function CustomGrainForm(props: Props) {
|
||||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, val)
|
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, val)
|
||||||
let settings = cloneDeep(newGrainSettings)
|
let settings = cloneDeep(newGrainSettings)
|
||||||
if(!isNaN(parseFloat(val))){
|
if(!isNaN(parseFloat(val))){
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
settings.bushelsPerTonne = parseFloat(val)/0.907
|
settings.bushelsPerTonne = parseFloat(val)/0.907
|
||||||
}else{
|
}else{
|
||||||
settings.bushelsPerTonne = parseFloat(val)
|
settings.bushelsPerTonne = parseFloat(val)
|
||||||
|
|
@ -212,7 +212,7 @@ export default function CustomGrainForm(props: Props) {
|
||||||
}
|
}
|
||||||
settingsChanged(settings)
|
settingsChanged(settings)
|
||||||
}}
|
}}
|
||||||
label={"Bushels per " + (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE ? " Tonne" : "Ton")}/>
|
label={"Bushels per " + (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE ? " Tonne" : "Ton")}/>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import {
|
||||||
useTransactionAPI
|
useTransactionAPI
|
||||||
} from "providers";
|
} from "providers";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { getGrainUnit } from "utils";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
mainObject: Bin | GrainBag | Field | Contract;
|
mainObject: Bin | GrainBag | Field | Contract;
|
||||||
|
|
@ -451,7 +450,7 @@ export default function GrainTransaction(props: Props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const grainUnitDisplay = () => {
|
const grainUnitDisplay = () => {
|
||||||
switch (getGrainUnit()){
|
switch (user.grainUnit()){
|
||||||
case pond.GrainUnit.GRAIN_UNIT_TONNE:
|
case pond.GrainUnit.GRAIN_UNIT_TONNE:
|
||||||
return "mT"
|
return "mT"
|
||||||
case pond.GrainUnit.GRAIN_UNIT_TON:
|
case pond.GrainUnit.GRAIN_UNIT_TON:
|
||||||
|
|
@ -525,7 +524,7 @@ export default function GrainTransaction(props: Props) {
|
||||||
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_TONNE) {
|
if (user.grainUnit() === 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))) {
|
||||||
|
|
@ -535,7 +534,7 @@ 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_TON) {
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
|
||||||
if (!isNaN(parseFloat(e.target.value))) {
|
if (!isNaN(parseFloat(e.target.value))) {
|
||||||
if (selectedSource) {
|
if (selectedSource) {
|
||||||
if(selectedSource.value.bushelsPerTonne){
|
if(selectedSource.value.bushelsPerTonne){
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import moment, { Moment } from "moment";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
|
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { getGrainUnit } from "utils";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
grainBag: GrainBag;
|
grainBag: GrainBag;
|
||||||
|
|
@ -21,7 +20,7 @@ export default function GrainBagInventoryGraph(props: Props) {
|
||||||
const [data, setData] = useState<BarData[]>([]);
|
const [data, setData] = useState<BarData[]>([]);
|
||||||
const [loadingData, setLoadingData] = useState<boolean>(false);
|
const [loadingData, setLoadingData] = useState<boolean>(false);
|
||||||
const { openSnack } = useSnackbar();
|
const { openSnack } = useSnackbar();
|
||||||
const [{as}] = useGlobalState();
|
const [{as, user}] = useGlobalState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (grainBag.key() && !loadingData) {
|
if (grainBag.key() && !loadingData) {
|
||||||
|
|
@ -36,12 +35,12 @@ export default function GrainBagInventoryGraph(props: Props) {
|
||||||
//let time = hist.timestamp;
|
//let time = hist.timestamp;
|
||||||
let val = hist.object.grainBagSettings.currentBushels ?? 0;
|
let val = hist.object.grainBagSettings.currentBushels ?? 0;
|
||||||
if (
|
if (
|
||||||
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE &&
|
user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE &&
|
||||||
grainBag.bushelsPerTonne() > 1
|
grainBag.bushelsPerTonne() > 1
|
||||||
) {
|
) {
|
||||||
val = Math.round((val / grainBag.bushelsPerTonne()) * 100) / 100;
|
val = Math.round((val / grainBag.bushelsPerTonne()) * 100) / 100;
|
||||||
}
|
}
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
|
||||||
val = Math.round((val / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
|
val = Math.round((val / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
|
||||||
}
|
}
|
||||||
if (val !== lastBushels) {
|
if (val !== lastBushels) {
|
||||||
|
|
@ -55,10 +54,10 @@ export default function GrainBagInventoryGraph(props: Props) {
|
||||||
});
|
});
|
||||||
if (barData.length === 0) {
|
if (barData.length === 0) {
|
||||||
let val = grainBag.bushels()
|
let val = grainBag.bushels()
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1){
|
||||||
val = grainBag.bushels() / grainBag.bushelsPerTonne()
|
val = grainBag.bushels() / grainBag.bushelsPerTonne()
|
||||||
}
|
}
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
|
||||||
val = grainBag.bushels() / (grainBag.bushelsPerTonne() * 0.907)
|
val = grainBag.bushels() / (grainBag.bushelsPerTonne() * 0.907)
|
||||||
}
|
}
|
||||||
barData.push({
|
barData.push({
|
||||||
|
|
@ -79,10 +78,10 @@ export default function GrainBagInventoryGraph(props: Props) {
|
||||||
|
|
||||||
const maxYAxis = () => {
|
const maxYAxis = () => {
|
||||||
let val = grainBag.capacity()
|
let val = grainBag.capacity()
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
val = Math.round((val / grainBag.bushelsPerTonne()) * 100) / 100;
|
val = Math.round((val / grainBag.bushelsPerTonne()) * 100) / 100;
|
||||||
}
|
}
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
|
||||||
val = Math.round((val / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
|
val = Math.round((val / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import { pond } from "protobuf-ts/pond";
|
||||||
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
|
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { getGrainUnit } from "utils";
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => {
|
const useStyles = makeStyles((theme: Theme) => {
|
||||||
return ({
|
return ({
|
||||||
|
|
@ -84,9 +83,9 @@ export default function GrainBagSettings(props: Props) {
|
||||||
: grainBag.settings.length
|
: grainBag.settings.length
|
||||||
);
|
);
|
||||||
let grainVal = grainBag.bushels();
|
let grainVal = grainBag.bushels();
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE) {
|
||||||
grainVal = grainBag.bushels() / grainBag.bushelsPerTonne();
|
grainVal = grainBag.bushels() / grainBag.bushelsPerTonne();
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
|
||||||
grainVal = grainBag.bushels() / (grainBag.bushelsPerTonne() * 0.907)
|
grainVal = grainBag.bushels() / (grainBag.bushelsPerTonne() * 0.907)
|
||||||
}
|
}
|
||||||
setGrainFill(grainVal.toFixed(2));
|
setGrainFill(grainVal.toFixed(2));
|
||||||
|
|
@ -120,7 +119,7 @@ export default function GrainBagSettings(props: Props) {
|
||||||
const submit = () => {
|
const submit = () => {
|
||||||
//if a bag was passed in do an update
|
//if a bag was passed in do an update
|
||||||
let tonneConversion = bushelConversion
|
let tonneConversion = bushelConversion
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
tonneConversion = bushelConversion / 0.907
|
tonneConversion = bushelConversion / 0.907
|
||||||
}
|
}
|
||||||
if (grainBag) {
|
if (grainBag) {
|
||||||
|
|
@ -255,9 +254,9 @@ export default function GrainBagSettings(props: Props) {
|
||||||
|
|
||||||
const grainUnitDisplay = () => {
|
const grainUnitDisplay = () => {
|
||||||
if(bushelConversion > 1){
|
if(bushelConversion > 1){
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
return "mT"
|
return "mT"
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
return "t"
|
return "t"
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -422,7 +421,7 @@ export default function GrainBagSettings(props: Props) {
|
||||||
value={grainFill}
|
value={grainFill}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
let bushelVal = +e.target.value;
|
let bushelVal = +e.target.value;
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE || getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE || user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
|
||||||
//convert the number as a weight into the bushel value, no changing or conversions necessary
|
//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)
|
// since these are both user entered fields and should be the same unit (ton or tonne)
|
||||||
bushelVal = +e.target.value * (bushelConversion > 0 ? bushelConversion : 1);
|
bushelVal = +e.target.value * (bushelConversion > 0 ? bushelConversion : 1);
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ import moment from "moment";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { getThemeType } from "theme";
|
import { getThemeType } from "theme";
|
||||||
import { getGrainUnit } from "utils";
|
|
||||||
import GrainBagSVG from "./grainBagSVG";
|
import GrainBagSVG from "./grainBagSVG";
|
||||||
import { makeStyles } from "@mui/styles";
|
import { makeStyles } from "@mui/styles";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
grainBag: GrainBag;
|
grainBag: GrainBag;
|
||||||
|
|
@ -68,6 +68,7 @@ export default function GrainBagVisualizer(props: Props) {
|
||||||
const [grainDiff, setGrainDiff] = useState<number | undefined>();
|
const [grainDiff, setGrainDiff] = useState<number | undefined>();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [openTransaction, setOpenTransaction] = useState(false);
|
const [openTransaction, setOpenTransaction] = useState(false);
|
||||||
|
const [{ user }] = useGlobalState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFillLevel((grainBag.bushels() / grainBag.capacity()) * 100);
|
setFillLevel((grainBag.bushels() / grainBag.capacity()) * 100);
|
||||||
|
|
@ -83,13 +84,13 @@ export default function GrainBagVisualizer(props: Props) {
|
||||||
const grainOverlay = () => {
|
const grainOverlay = () => {
|
||||||
let displayPending = pendingGrainAmount;
|
let displayPending = pendingGrainAmount;
|
||||||
let displayDiff = grainDiff;
|
let displayDiff = grainDiff;
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1) {
|
||||||
if (displayPending && displayDiff) {
|
if (displayPending && displayDiff) {
|
||||||
displayPending = Math.round((displayPending / grainBag.bushelsPerTonne()) * 100) / 100;
|
displayPending = Math.round((displayPending / grainBag.bushelsPerTonne()) * 100) / 100;
|
||||||
displayDiff = Math.round((displayDiff / grainBag.bushelsPerTonne()) * 100) / 100;
|
displayDiff = Math.round((displayDiff / grainBag.bushelsPerTonne()) * 100) / 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1) {
|
||||||
if (displayPending && displayDiff) {
|
if (displayPending && displayDiff) {
|
||||||
displayPending = Math.round((displayPending / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
|
displayPending = Math.round((displayPending / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
|
||||||
displayDiff = Math.round((displayDiff / (grainBag.bushelsPerTonne()* 0.907)) * 100) / 100;
|
displayDiff = Math.round((displayDiff / (grainBag.bushelsPerTonne()* 0.907)) * 100) / 100;
|
||||||
|
|
@ -148,7 +149,7 @@ export default function GrainBagVisualizer(props: Props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const grainAmountDisplay = () => {
|
const grainAmountDisplay = () => {
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1) {
|
||||||
return (
|
return (
|
||||||
<div style={{ display: "flex", flexDirection: "row" }}>
|
<div style={{ display: "flex", flexDirection: "row" }}>
|
||||||
<Typography variant="body2" style={{ fontWeight: "bold", marginRight: "4px" }}>
|
<Typography variant="body2" style={{ fontWeight: "bold", marginRight: "4px" }}>
|
||||||
|
|
@ -157,7 +158,7 @@ export default function GrainBagVisualizer(props: Props) {
|
||||||
<Typography variant="body2">({grainBag.fillPercent()}%)</Typography>
|
<Typography variant="body2">({grainBag.fillPercent()}%)</Typography>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1) {
|
} else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1) {
|
||||||
return (
|
return (
|
||||||
<div style={{ display: "flex", flexDirection: "row" }}>
|
<div style={{ display: "flex", flexDirection: "row" }}>
|
||||||
<Typography variant="body2" style={{ fontWeight: "bold", marginRight: "4px" }}>
|
<Typography variant="body2" style={{ fontWeight: "bold", marginRight: "4px" }}>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import GrainDescriber from "grain/GrainDescriber";
|
import GrainDescriber from "grain/GrainDescriber";
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
import { MarkerData } from "maps/mapMarkers/Markers";
|
import { MarkerData } from "maps/mapMarkers/Markers";
|
||||||
|
import { User } from "models";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { getGrainUnit } from "utils";
|
|
||||||
import { stringToMaterialColour } from "utils/strings";
|
import { stringToMaterialColour } from "utils/strings";
|
||||||
import { or } from "utils/types";
|
import { or } from "utils/types";
|
||||||
|
|
||||||
|
|
@ -236,11 +236,11 @@ export class Bin {
|
||||||
return bpt;
|
return bpt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public grainInventory(): number {
|
public grainInventory(user: User): number {
|
||||||
let grain = this.bushels()
|
let grain = this.bushels()
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && this.bushelsPerTonne() > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && this.bushelsPerTonne() > 1){
|
||||||
grain = this.bushels() / this.bushelsPerTonne()
|
grain = this.bushels() / this.bushelsPerTonne()
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && this.bushelsPerTonne() > 1){
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && this.bushelsPerTonne() > 1){
|
||||||
grain = this.bushels() / (this.bushelsPerTonne() * 0.907)
|
grain = this.bushels() / (this.bushelsPerTonne() * 0.907)
|
||||||
}
|
}
|
||||||
return Math.round(grain*100)/100
|
return Math.round(grain*100)/100
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@ import { Option } from "common/SearchSelect";
|
||||||
import { GrainOptions, ToGrainOption } from "grain";
|
import { GrainOptions, ToGrainOption } from "grain";
|
||||||
import GrainDescriber from "grain/GrainDescriber";
|
import GrainDescriber from "grain/GrainDescriber";
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
|
import { User } from "models";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { getGrainUnit, stringToMaterialColour } from "utils";
|
import { stringToMaterialColour } from "utils";
|
||||||
import { or } from "utils/types";
|
import { or } from "utils/types";
|
||||||
|
|
||||||
export class Contract {
|
export class Contract {
|
||||||
|
|
@ -14,26 +15,28 @@ export class Contract {
|
||||||
public label: string = "";
|
public label: string = "";
|
||||||
private objKey: string = "";
|
private objKey: string = "";
|
||||||
|
|
||||||
public static create(pb?: pond.Contract): Contract {
|
public static create(pb?: pond.Contract, user?: User): Contract {
|
||||||
let my = new Contract();
|
let my = new Contract();
|
||||||
if (pb) {
|
if (pb) {
|
||||||
my.settings = pond.ContractSettings.fromObject(cloneDeep(or(pb.settings, {})));
|
my.settings = pond.ContractSettings.fromObject(cloneDeep(or(pb.settings, {})));
|
||||||
my.title = pb.name;
|
my.title = pb.name;
|
||||||
my.objKey = pb.key;
|
my.objKey = pb.key;
|
||||||
my.unit = my.measurementUnit();
|
my.unit = my.measurementUnit(user);
|
||||||
my.colour = my.commodityColour();
|
my.colour = my.commodityColour();
|
||||||
my.label = my.commodityLabel();
|
my.label = my.commodityLabel();
|
||||||
}
|
}
|
||||||
return my;
|
return my;
|
||||||
}
|
}
|
||||||
|
|
||||||
private measurementUnit(): string {
|
private measurementUnit(user?: User): string {
|
||||||
if (this.settings.type === pond.ContractType.CONTRACT_TYPE_GRAIN) {
|
if (this.settings.type === pond.ContractType.CONTRACT_TYPE_GRAIN) {
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && this.conversionValue() > 1){
|
if( user ){
|
||||||
return "mT"
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && this.conversionValue() > 1){
|
||||||
}
|
return "mT"
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && this.conversionValue() > 1){
|
}
|
||||||
return "t"
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && this.conversionValue() > 1){
|
||||||
|
return "t"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "bu";
|
return "bu";
|
||||||
}
|
}
|
||||||
|
|
@ -63,21 +66,22 @@ export class Contract {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static clone(other?: Contract): Contract {
|
public static clone(other?: Contract, user?: User): Contract {
|
||||||
if (other) {
|
if (other) {
|
||||||
return Contract.create(
|
return Contract.create(
|
||||||
pond.Contract.fromObject({
|
pond.Contract.fromObject({
|
||||||
title: other.title,
|
title: other.title,
|
||||||
key: other.objKey,
|
key: other.objKey,
|
||||||
settings: cloneDeep(other.settings)
|
settings: cloneDeep(other.settings)
|
||||||
})
|
}),
|
||||||
|
user
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Contract.create();
|
return Contract.create(undefined, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static any(data: any): Contract {
|
public static any(data: any, user?: User): Contract {
|
||||||
return Contract.create(pond.Contract.fromObject(cloneDeep(data)));
|
return Contract.create(pond.Contract.fromObject(cloneDeep(data)), user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public key(): string {
|
public key(): string {
|
||||||
|
|
@ -204,28 +208,28 @@ export class Contract {
|
||||||
return this.conversionValue();
|
return this.conversionValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public sizeInPreferredUnit(): number {
|
public sizeInPreferredUnit(user: User): number {
|
||||||
let size = this.settings.size;
|
let size = this.settings.size;
|
||||||
switch (this.settings.type) {
|
switch (this.settings.type) {
|
||||||
case pond.ContractType.CONTRACT_TYPE_GRAIN:
|
case pond.ContractType.CONTRACT_TYPE_GRAIN:
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && this.conversionValue() > 1) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && this.conversionValue() > 1) {
|
||||||
size = size / this.conversionValue();
|
size = size / this.conversionValue();
|
||||||
}
|
}
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && this.conversionValue() > 1){
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && this.conversionValue() > 1){
|
||||||
size = size / (this.conversionValue() * 0.907); //the conversion for grain will be stored in metric tonnes, this will convert it to US tons
|
size = size / (this.conversionValue() * 0.907); //the conversion for grain will be stored in metric tonnes, this will convert it to US tons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Math.round(size * 100) / 100;
|
return Math.round(size * 100) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
public deliveredInPreferredUnit(): number {
|
public deliveredInPreferredUnit(user: User): number {
|
||||||
let del = this.settings.delivered;
|
let del = this.settings.delivered;
|
||||||
switch (this.settings.type) {
|
switch (this.settings.type) {
|
||||||
case pond.ContractType.CONTRACT_TYPE_GRAIN:
|
case pond.ContractType.CONTRACT_TYPE_GRAIN:
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && this.conversionValue() > 1) {
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && this.conversionValue() > 1) {
|
||||||
del = del / this.conversionValue();
|
del = del / this.conversionValue();
|
||||||
}
|
}
|
||||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && this.conversionValue() > 1){
|
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && this.conversionValue() > 1){
|
||||||
del = del / (this.conversionValue() * 0.907); //the conversion for grain will be stored in metric tonnes, this will convert it to US tons
|
del = del / (this.conversionValue() * 0.907); //the conversion for grain will be stored in metric tonnes, this will convert it to US tons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -237,14 +241,15 @@ export class Contract {
|
||||||
public static toStoredUnit(
|
public static toStoredUnit(
|
||||||
secondaryUnitVal: number,
|
secondaryUnitVal: number,
|
||||||
contractType: pond.ContractType,
|
contractType: pond.ContractType,
|
||||||
conversionValue: number
|
conversionValue: number,
|
||||||
|
user: User
|
||||||
): number {
|
): number {
|
||||||
let storedUnitVal = secondaryUnitVal;
|
let storedUnitVal = secondaryUnitVal;
|
||||||
switch (contractType) {
|
switch (contractType) {
|
||||||
//use the value and conversion they entered directly, it is safe to assume they are both the same unit (ton vs tonne) so dont need to convert anything
|
//use the value and conversion they entered directly, it is safe to assume they are both the same unit (ton vs tonne) so dont need to convert anything
|
||||||
//before converting to bushels
|
//before converting to bushels
|
||||||
case pond.ContractType.CONTRACT_TYPE_GRAIN:
|
case pond.ContractType.CONTRACT_TYPE_GRAIN:
|
||||||
if ((getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE || getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) && conversionValue > 1) {
|
if ((user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE || user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) && conversionValue > 1) {
|
||||||
storedUnitVal = secondaryUnitVal * conversionValue;
|
storedUnitVal = secondaryUnitVal * conversionValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ import {
|
||||||
} from "providers";
|
} from "providers";
|
||||||
import React, { SetStateAction, useCallback, useEffect, useState } from "react";
|
import React, { SetStateAction, useCallback, useEffect, useState } from "react";
|
||||||
// import { getThemeType } from "theme";
|
// import { getThemeType } from "theme";
|
||||||
import { getGrainUnit, stringToMaterialColour } from "utils";
|
import { stringToMaterialColour } from "utils";
|
||||||
//import InfiniteScroll from "react-infinite-scroller";
|
//import InfiniteScroll from "react-infinite-scroller";
|
||||||
import PageContainer from "./PageContainer";
|
import PageContainer from "./PageContainer";
|
||||||
import ObjectTable from "objects/ObjectTable";
|
import ObjectTable from "objects/ObjectTable";
|
||||||
|
|
@ -934,7 +934,7 @@ export default function Bins(props: Props) {
|
||||||
return " bu";
|
return " bu";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (getGrainUnit()) {
|
switch (user.grainUnit()) {
|
||||||
case pond.GrainUnit.GRAIN_UNIT_TONNE:
|
case pond.GrainUnit.GRAIN_UNIT_TONNE:
|
||||||
return " mT";
|
return " mT";
|
||||||
case pond.GrainUnit.GRAIN_UNIT_TON:
|
case pond.GrainUnit.GRAIN_UNIT_TON:
|
||||||
|
|
@ -947,9 +947,9 @@ export default function Bins(props: Props) {
|
||||||
const customQuantityDisplay = (customInventory: pond.CustomInventory, bushels: number) => {
|
const customQuantityDisplay = (customInventory: pond.CustomInventory, bushels: number) => {
|
||||||
let amount = bushels
|
let amount = bushels
|
||||||
if(customInventory.bushelsPerTonne > 1){
|
if(customInventory.bushelsPerTonne > 1){
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
amount = bushels/customInventory.bushelsPerTonne
|
amount = bushels/customInventory.bushelsPerTonne
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
amount = bushels/(customInventory.bushelsPerTonne*0.907)
|
amount = bushels/(customInventory.bushelsPerTonne*0.907)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -959,9 +959,9 @@ export default function Bins(props: Props) {
|
||||||
const supportedGrainDisplay = (grain: pond.Grain, bushels: number) => {
|
const supportedGrainDisplay = (grain: pond.Grain, bushels: number) => {
|
||||||
const describer = GrainDescriber(grain)
|
const describer = GrainDescriber(grain)
|
||||||
let amount = bushels
|
let amount = bushels
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||||
amount = bushels/describer.bushelsPerTonne
|
amount = bushels/describer.bushelsPerTonne
|
||||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||||
amount = bushels/describer.bushelsPerTon
|
amount = bushels/describer.bushelsPerTon
|
||||||
}
|
}
|
||||||
return Math.round(amount*100)/100
|
return Math.round(amount*100)/100
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import PageContainer from "./PageContainer";
|
||||||
|
|
||||||
export default function Contracts() {
|
export default function Contracts() {
|
||||||
const [openSettings, setOpenSettings] = useState(false);
|
const [openSettings, setOpenSettings] = useState(false);
|
||||||
const [{ as }] = useGlobalState()
|
const [{ as, user }] = useGlobalState()
|
||||||
const contractAPI = useContractAPI();
|
const contractAPI = useContractAPI();
|
||||||
const [contracts, setContracts] = useState<Contract[]>([]);
|
const [contracts, setContracts] = useState<Contract[]>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
@ -42,7 +42,7 @@ export default function Contracts() {
|
||||||
let contractPermissions: Map<string, pond.Permission[]> = new Map();
|
let contractPermissions: Map<string, pond.Permission[]> = new Map();
|
||||||
if (resp.data.contracts){
|
if (resp.data.contracts){
|
||||||
resp.data.contracts.forEach(contract => {
|
resp.data.contracts.forEach(contract => {
|
||||||
let c = Contract.create(contract);
|
let c = Contract.create(contract, user);
|
||||||
contracts.push(c);
|
contracts.push(c);
|
||||||
let p = pond.EvaluatePermissionsResponse.fromObject(
|
let p = pond.EvaluatePermissionsResponse.fromObject(
|
||||||
resp.data.contractPermissions[c.key()]
|
resp.data.contractPermissions[c.key()]
|
||||||
|
|
@ -56,7 +56,7 @@ export default function Contracts() {
|
||||||
})
|
})
|
||||||
.catch(err => {});
|
.catch(err => {});
|
||||||
}
|
}
|
||||||
}, [contractAPI, year, as]); // eslint-disable-line react-hooks/exhaustive-deps
|
}, [contractAPI, year, as, user]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer>
|
<PageContainer>
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ import { Box, Typography } from "@mui/material";
|
||||||
import GrainDescriber from "grain/GrainDescriber";
|
import GrainDescriber from "grain/GrainDescriber";
|
||||||
import { Transaction } from "models/Transaction";
|
import { Transaction } from "models/Transaction";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { getGrainUnit } from "utils";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
transaction: Transaction;
|
transaction: Transaction;
|
||||||
|
|
@ -11,13 +11,14 @@ interface Props {
|
||||||
|
|
||||||
export default function TransactionDataDisplay(props: Props) {
|
export default function TransactionDataDisplay(props: Props) {
|
||||||
const { transaction } = props;
|
const { transaction } = props;
|
||||||
|
const [{ user }] = useGlobalState();
|
||||||
console.log(transaction)
|
console.log(transaction)
|
||||||
|
|
||||||
const grainDisplay = (gt: pond.GrainTransaction) => {
|
const grainDisplay = (gt: pond.GrainTransaction) => {
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && gt.bushelsPerTonne > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && gt.bushelsPerTonne > 1){
|
||||||
return "Weight: " + Math.round(gt.bushels / gt.bushelsPerTonne*100)/100 + " mT"
|
return "Weight: " + Math.round(gt.bushels / gt.bushelsPerTonne*100)/100 + " mT"
|
||||||
}
|
}
|
||||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && gt.bushelsPerTonne > 1){
|
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && gt.bushelsPerTonne > 1){
|
||||||
return "Weight: " + Math.round(gt.bushels / (gt.bushelsPerTonne*0.907)*100)/100 + " t"
|
return "Weight: " + Math.round(gt.bushels / (gt.bushelsPerTonne*0.907)*100)/100 + " t"
|
||||||
}
|
}
|
||||||
return "Bushels: " + gt.bushels
|
return "Bushels: " + gt.bushels
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ export function setDistanceUnit(unit: pond.DistanceUnit) {
|
||||||
localStorage.setItem("distance", unit === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft");
|
localStorage.setItem("distance", unit === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function is deprecated, use User.grainUnit() instead
|
||||||
export function getGrainUnit(): pond.GrainUnit {
|
export function getGrainUnit(): pond.GrainUnit {
|
||||||
switch(localStorage.getItem("grainUnit")){
|
switch(localStorage.getItem("grainUnit")){
|
||||||
case "mT":
|
case "mT":
|
||||||
|
|
@ -84,12 +85,10 @@ export function setGrainUnit(unit: pond.GrainUnit) {
|
||||||
default:
|
default:
|
||||||
localStorage.setItem("grainUnit", "bu")
|
localStorage.setItem("grainUnit", "bu")
|
||||||
}
|
}
|
||||||
// localStorage.setItem("grainUnit", unit === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? "mT" : "bu");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const distanceConversion = (val: number, distanceUnit: pond.DistanceUnit) => {
|
export const distanceConversion = (val: number, distanceUnit: pond.DistanceUnit) => {
|
||||||
let converted = val;
|
let converted = val;
|
||||||
|
|
||||||
if (distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
if (distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||||
converted = val / 3.281;
|
converted = val / 3.281;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue