finished updating for US tons

This commit is contained in:
csawatzky 2026-03-06 10:24:12 -06:00
parent 9414e30cea
commit 62c2f6a63c
16 changed files with 180 additions and 211 deletions

View file

@ -92,9 +92,14 @@ export default function ContractSettings(props: Props) {
setContractValue(contract.settings.totalValue.toString());
setCommodity(contract.settings.commodity);
setContractDate(contract.settings.contractDate);
setConversionValue(
contract.settings.conversionValue > 0 ? contract.settings.conversionValue.toString() : "1"
);
let conv = 1
if(contract.settings.conversionValue > 1){
conv = contract.settings.conversionValue
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
conv = conv * 0.907
}
}
setConversionValue(conv.toFixed(2));
setUseCustom(contract.isCustom());
}
}, [contract]);
@ -158,17 +163,21 @@ export default function ContractSettings(props: Props) {
const submit = () => {
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
}
}
//the toStoredUnit will convert what they entered for amount and size using the conversion that they entered
//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))
? 0
: Math.round(Contract.toStoredUnit(parseFloat(deliveredAmount), contractType, conVal));
const sizeVal = isNaN(parseFloat(contractSize))
? 0
: Math.round(Contract.toStoredUnit(parseFloat(contractSize), contractType, conVal));
//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(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
conVal = conVal / 0.907 //convert the ton they entered to mT to be stored in the contracts conversion value
}
}
if (contract) {
let settings: pond.ContractSettings = contract.settings;
settings.commodity = commodity;
@ -215,7 +224,6 @@ export default function ContractSettings(props: Props) {
settings.type = contractType;
settings.conversionValue = conVal;
settings.contractDate = contractDate;
contractAPI
.addContract(name, settings, as)
.then(resp => {

View file

@ -27,11 +27,17 @@ export default function ContractTransactionGraph(props: Props) {
if (transaction?.grainTransaction) {
value = transaction.grainTransaction.bushels;
if (
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_WEIGHT &&
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE &&
transaction.grainTransaction.bushelsPerTonne > 1
) {
value = value / transaction.grainTransaction.bushelsPerTonne;
}
if (
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON &&
transaction.grainTransaction.bushelsPerTonne > 1
) {
value = value / (transaction.grainTransaction.bushelsPerTonne * 0.907);
}
}
d.push({
timestamp: time.valueOf(),