Skip to content

Commit

Permalink
1160 - Allowable AUM & Total AUM comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Brijesh committed Nov 14, 2024
1 parent 4a0c07e commit a25cec0
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classnames from 'classnames';
import { Dropdown, Icon, Table, Confirm } from 'semantic-ui-react';
import * as _ from 'lodash/fp';
import GrazingScheduleEntryRow from './GrazingScheduleEntryRow';
import { roundTo1Decimal , isUserAgrologist } from '../../../utils';
import { roundTo1Decimal, isUserAgrologist } from '../../../utils';
import * as strings from '../../../constants/strings';
import { CollapsibleBox, PrimaryButton, ErrorMessage } from '../../common';
import { IMAGE_SRC } from '../../../constants/variables';
Expand Down Expand Up @@ -62,6 +62,32 @@ const GrazingScheduleBox = ({
type: 'error',
};
}
const aggregatedCrownAUMs = schedule.grazingScheduleEntries.reduce((acc, entry) => {
if (entry.pasture && entry.pasture.id !== undefined) {
const pastureId = entry.pasture.id;
acc[pastureId] = roundTo1Decimal((acc[pastureId] || 0) + entry.crownAUMs);
}
return acc;
}, {});
const warningEntries = schedule.grazingScheduleEntries.reduce((acc, entry) => {
if (entry.pasture && entry.pasture.id !== undefined) {
const pastureId = entry.pasture.id;
const pastureName = entry.pasture.name;
const allowableAum = entry.pasture.allowableAum;
if (allowableAum && aggregatedCrownAUMs[pastureId] > allowableAum) {
acc.push({
id: entry.id,
message: `Total Crown AUMs: ${aggregatedCrownAUMs[pastureId]} of schedule entries of pasture "${pastureName}" have exceeded allowable AUMs value: ${allowableAum}.`,
type: 'warning',
});
}
}
return acc;
}, []);
const uniqueWarnings = Array.from(new Set(warningEntries.map((w) => w.id))).map((id) =>
warningEntries.find((w) => w.id === id),
);
return uniqueWarnings[0];
};

const scheduleError = getScheduleError();
Expand Down

0 comments on commit a25cec0

Please sign in to comment.