updated the yard with the new ton stuff working through contracts
This commit is contained in:
parent
dd6a842fda
commit
9414e30cea
7 changed files with 126 additions and 57 deletions
|
|
@ -668,25 +668,31 @@ export default function BinyardDisplay(props: Props) {
|
|||
}
|
||||
};
|
||||
|
||||
const grainQuantityDisplay = (bushels: number, custom?: pond.CustomInventory) => {
|
||||
if (custom && custom.bushelsPerTonne <= 1) {
|
||||
return bushels;
|
||||
const customQuantityDisplay = (customInventory: pond.CustomInventory, bushels: number) => {
|
||||
let amount = bushels
|
||||
if(customInventory.bushelsPerTonne > 1){
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||
amount = bushels/customInventory.bushelsPerTonne
|
||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||
amount = bushels/(customInventory.bushelsPerTonne*0.907)
|
||||
}
|
||||
}
|
||||
|
||||
switch (getGrainUnit()) {
|
||||
case pond.GrainUnit.GRAIN_UNIT_TONNE:
|
||||
return " mT";
|
||||
case pond.GrainUnit.GRAIN_UNIT_TON:
|
||||
return " t";
|
||||
default:
|
||||
return bushels;
|
||||
return Math.round(amount*100)/100
|
||||
}
|
||||
|
||||
const supportedGrainDisplay = (grain: pond.Grain, bushels: number) => {
|
||||
const describer = GrainDescriber(grain)
|
||||
let amount = bushels
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||
amount = bushels/describer.bushelsPerTonne
|
||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||
amount = bushels/describer.bushelsPerTon
|
||||
}
|
||||
return Math.round(amount*100)/100
|
||||
}
|
||||
|
||||
const binUtilizationList = () => {
|
||||
const hasInventory = binMetrics && binMetrics.grainInventory.length > 0;
|
||||
console.log(binMetrics)
|
||||
const useWeight = getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT;
|
||||
return (
|
||||
<Accordion
|
||||
className={classes.accordion}
|
||||
|
|
@ -728,16 +734,8 @@ export default function BinyardDisplay(props: Props) {
|
|||
<BinUtilizationChart
|
||||
grain={inv.grainType}
|
||||
customUnit={grainUnitDisplay()}
|
||||
bushelAmount={
|
||||
useWeight
|
||||
? inv.bushelAmount / GrainDescriber(inv.grainType).bushelsPerTonne
|
||||
: inv.bushelAmount
|
||||
}
|
||||
bushelCapacity={
|
||||
useWeight
|
||||
? inv.bushelCapacity / GrainDescriber(inv.grainType).bushelsPerTonne
|
||||
: inv.bushelCapacity
|
||||
}
|
||||
bushelAmount={supportedGrainDisplay(inv.grainType, inv.bushelAmount)}
|
||||
bushelCapacity={supportedGrainDisplay(inv.grainType, inv.bushelCapacity)}
|
||||
onClick={() => {
|
||||
setContentFilter(pond.Grain[inv.grainType]);
|
||||
loadMoreBins(pond.Grain[inv.grainType]);
|
||||
|
|
@ -757,8 +755,8 @@ export default function BinyardDisplay(props: Props) {
|
|||
cap = cap * 35.239;
|
||||
unit = " L";
|
||||
}else{
|
||||
amount
|
||||
cap
|
||||
amount = customQuantityDisplay(inv, amount)
|
||||
cap = customQuantityDisplay(inv, cap)
|
||||
unit = grainUnitDisplay(inv)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -120,12 +120,17 @@ export default function BinLevelOverTime(props: Props) {
|
|||
let currentTime = moment().valueOf();
|
||||
if (data.length === 0) {
|
||||
let bushels = bin.bushels();
|
||||
let grainDisplay = bushels
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
|
||||
grainDisplay = Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100;
|
||||
}
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTon() > 1){
|
||||
grainDisplay = Math.round((bushels / bin.bushelsPerTon()) * 100) / 100;
|
||||
}
|
||||
data.push({
|
||||
value: fertilizerBin
|
||||
? Math.round(bushels * 35.239)
|
||||
: getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT
|
||||
? Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100
|
||||
: bushels,
|
||||
: grainDisplay,
|
||||
timestamp: currentTime
|
||||
});
|
||||
}
|
||||
|
|
@ -151,9 +156,12 @@ export default function BinLevelOverTime(props: Props) {
|
|||
if (fertilizerBin && cap) {
|
||||
cap = cap * 35.239;
|
||||
}
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && cap) {
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && cap) {
|
||||
cap = cap / bin.bushelsPerTonne();
|
||||
}
|
||||
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && cap) {
|
||||
cap = cap / bin.bushelsPerTon();
|
||||
}
|
||||
setCapacity(cap);
|
||||
let autoBarData: BarData[] = [];
|
||||
|
||||
|
|
@ -190,12 +198,17 @@ export default function BinLevelOverTime(props: Props) {
|
|||
if (autoBarData.length === 0) {
|
||||
let bushels = bin.bushels();
|
||||
let currentTime = moment().valueOf();
|
||||
let grainDisplay = bushels
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && bin.bushelsPerTonne() > 1){
|
||||
grainDisplay = Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100;
|
||||
}
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && bin.bushelsPerTon() > 1){
|
||||
grainDisplay = Math.round((bushels / bin.bushelsPerTon()) * 100) / 100;
|
||||
}
|
||||
autoBarData.push({
|
||||
value: fertilizerBin
|
||||
? Math.round(bushels * 35.239)
|
||||
: getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT
|
||||
? Math.round((bushels / bin.bushelsPerTonne()) * 100) / 100
|
||||
: bushels,
|
||||
: grainDisplay,
|
||||
timestamp: currentTime
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,12 +102,21 @@ export default function ContractSettings(props: Props) {
|
|||
useEffect(() => {
|
||||
switch (contractType) {
|
||||
case pond.ContractType.CONTRACT_TYPE_GRAIN:
|
||||
let conversionLabel = "Bushels Per Tonne"
|
||||
let adornment = "bu"
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||
adornment = "mT"
|
||||
}
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||
conversionLabel = "Bushels Per Ton"
|
||||
adornment = "t"
|
||||
}
|
||||
setLabels({
|
||||
sizeLabel: "Total Grain on Contract",
|
||||
commodityLabel: "Select Grain Type",
|
||||
conversionLabel: "Bushels Per Tonne",
|
||||
conversionLabel: conversionLabel,
|
||||
deliveryLabel: "Grain Delivered",
|
||||
adornment: getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? "mT" : "bu"
|
||||
adornment: adornment
|
||||
});
|
||||
break;
|
||||
default:
|
||||
|
|
@ -148,7 +157,12 @@ export default function ContractSettings(props: Props) {
|
|||
};
|
||||
|
||||
const submit = () => {
|
||||
const conVal = isNaN(parseFloat(conversionValue)) ? 1 : parseFloat(conversionValue);
|
||||
let conVal = isNaN(parseFloat(conversionValue)) ? 1 : parseFloat(conversionValue);
|
||||
if(contractType === pond.ContractType.CONTRACT_TYPE_GRAIN){
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||
conVal = conVal/1.102 //convert the ton they entered to mT to be sotred in the contract
|
||||
}
|
||||
}
|
||||
const deliveredVal = isNaN(parseFloat(deliveredAmount))
|
||||
? 0
|
||||
: Math.round(Contract.toStoredUnit(parseFloat(deliveredAmount), contractType, conVal));
|
||||
|
|
@ -490,7 +504,9 @@ export default function ContractSettings(props: Props) {
|
|||
InputLabelProps={{ shrink: true }}
|
||||
error={isNaN(parseFloat(conversionValue))}
|
||||
helperText={isNaN(parseFloat(conversionValue)) ? "Must be a valid number" : ""}
|
||||
onChange={e => setConversionValue(e.target.value)}
|
||||
onChange={e => {
|
||||
setConversionValue(e.target.value)
|
||||
}}
|
||||
/>
|
||||
</React.Fragment>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -278,6 +278,10 @@ export default function Router() {
|
|||
path="/:groupID/devices/:deviceID"
|
||||
element={<DevicePage />}
|
||||
/>
|
||||
<Route
|
||||
path="/:groupID/devices/:deviceID/components/:componentID"
|
||||
element={<DeviceComponent />}
|
||||
/>
|
||||
<Route
|
||||
path="/:groupID/devices/:deviceID/*"
|
||||
element={<RelativeRoutes />}
|
||||
|
|
|
|||
|
|
@ -928,9 +928,47 @@ export default function Bins(props: Props) {
|
|||
);
|
||||
};
|
||||
|
||||
const grainUnitDisplay = (custom?: pond.CustomInventory) => {
|
||||
// If custom and not convertible, always bushels
|
||||
if (custom && custom.bushelsPerTonne <= 1) {
|
||||
return " bu";
|
||||
}
|
||||
|
||||
switch (getGrainUnit()) {
|
||||
case pond.GrainUnit.GRAIN_UNIT_TONNE:
|
||||
return " mT";
|
||||
case pond.GrainUnit.GRAIN_UNIT_TON:
|
||||
return " t";
|
||||
default:
|
||||
return " bu";
|
||||
}
|
||||
};
|
||||
|
||||
const customQuantityDisplay = (customInventory: pond.CustomInventory, bushels: number) => {
|
||||
let amount = bushels
|
||||
if(customInventory.bushelsPerTonne > 1){
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||
amount = bushels/customInventory.bushelsPerTonne
|
||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||
amount = bushels/(customInventory.bushelsPerTonne*0.907)
|
||||
}
|
||||
}
|
||||
return Math.round(amount*100)/100
|
||||
}
|
||||
|
||||
const supportedGrainDisplay = (grain: pond.Grain, bushels: number) => {
|
||||
const describer = GrainDescriber(grain)
|
||||
let amount = bushels
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
|
||||
amount = bushels/describer.bushelsPerTonne
|
||||
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
|
||||
amount = bushels/describer.bushelsPerTon
|
||||
}
|
||||
return Math.round(amount*100)/100
|
||||
}
|
||||
|
||||
const binUtilizationList = () => {
|
||||
const hasInventory = binMetrics && binMetrics.grainInventory.length > 0;
|
||||
const useWeight = getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT;
|
||||
return (
|
||||
<Accordion
|
||||
className={classes.accordion}
|
||||
|
|
@ -972,17 +1010,9 @@ export default function Bins(props: Props) {
|
|||
<ImageListItem key={key}>
|
||||
<BinUtilizationChart
|
||||
grain={inv.grainType}
|
||||
customUnit={useWeight ? " mT" : " bu"}
|
||||
bushelAmount={
|
||||
useWeight
|
||||
? inv.bushelAmount / GrainDescriber(inv.grainType).bushelsPerTonne
|
||||
: inv.bushelAmount
|
||||
}
|
||||
bushelCapacity={
|
||||
useWeight
|
||||
? inv.bushelCapacity / GrainDescriber(inv.grainType).bushelsPerTonne
|
||||
: inv.bushelCapacity
|
||||
}
|
||||
customUnit={grainUnitDisplay()}
|
||||
bushelAmount={supportedGrainDisplay(inv.grainType, inv.bushelAmount)}
|
||||
bushelCapacity={supportedGrainDisplay(inv.grainType, inv.bushelCapacity)}
|
||||
onClick={() => {
|
||||
setContentFilter(pond.Grain[inv.grainType]);
|
||||
loadMoreBins(pond.Grain[inv.grainType]);
|
||||
|
|
@ -1001,11 +1031,10 @@ export default function Bins(props: Props) {
|
|||
amount = amount * 35.239;
|
||||
cap = cap * 35.239;
|
||||
unit = " L";
|
||||
}
|
||||
if (useWeight && inv.bushelsPerTonne > 1) {
|
||||
amount = amount / inv.bushelsPerTonne;
|
||||
cap = cap / inv.bushelsPerTonne;
|
||||
unit = " mT";
|
||||
} else {
|
||||
amount = customQuantityDisplay(inv, amount)
|
||||
cap = customQuantityDisplay(inv, cap)
|
||||
unit = grainUnitDisplay(inv);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -168,7 +168,8 @@ export default function SignupCallback () {
|
|||
variant="outlined"
|
||||
InputLabelProps={{ shrink: true }}>
|
||||
<MenuItem value={pond.GrainUnit.GRAIN_UNIT_BUSHELS}>Bushels (bu)</MenuItem>
|
||||
<MenuItem value={pond.GrainUnit.GRAIN_UNIT_WEIGHT}>Tonnes (mT)</MenuItem>
|
||||
<MenuItem value={pond.GrainUnit.GRAIN_UNIT_TONNE}>Tonnes (mT)</MenuItem>
|
||||
<MenuItem value={pond.GrainUnit.GRAIN_UNIT_TON}>US Tons (t)</MenuItem>
|
||||
</TextField>
|
||||
</Grid2>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,16 @@ export default function TransactionDataDisplay(props: Props) {
|
|||
const { transaction } = props;
|
||||
console.log(transaction)
|
||||
|
||||
const grainDisplay = (gt: pond.GrainTransaction) => {
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && gt.bushelsPerTonne > 1){
|
||||
return "Weight: " + Math.round(gt.bushels / gt.bushelsPerTonne*100)/100 + " mT"
|
||||
}
|
||||
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && gt.bushelsPerTon > 1){
|
||||
return "Weight: " + Math.round(gt.bushels / gt.bushelsPerTon*100)/100 + " t"
|
||||
}
|
||||
return "Bushels: " + gt.bushels
|
||||
}
|
||||
|
||||
const display = () => {
|
||||
let transactionData = transaction.transaction.transaction;
|
||||
if (transactionData) {
|
||||
|
|
@ -28,9 +38,7 @@ export default function TransactionDataDisplay(props: Props) {
|
|||
</Typography>
|
||||
<Typography>Variant: {gt.subtype}</Typography>
|
||||
<Typography>
|
||||
{getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT && gt.bushelsPerTonne > 1
|
||||
? "Weight: " + gt.bushels / gt.bushelsPerTonne + " mT"
|
||||
: "Bushels: " + gt.bushels}
|
||||
{grainDisplay(gt)}
|
||||
</Typography>
|
||||
<Typography>Message: {gt.message}</Typography>
|
||||
</Box>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue