Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INT-B-21698 PPM Clouseout Calculation Improvement #14627

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
46f65c8
B-21698 exclude rejected progear tickets from total weight calculation
brianmanley-caci Jan 17, 2025
b0ab007
Merge remote-tracking branch 'origin/main' into MAIN-B-21698
brianmanley-caci Jan 20, 2025
9bd9aa4
B-21698 don't included rejected or excluded expenses in the total
brianmanley-caci Jan 20, 2025
49c9440
Merge remote-tracking branch 'origin/main' into MAIN-B-21698
brianmanley-caci Jan 20, 2025
2bfe4fb
Merge B-21698 into INT-B-21698
brianmanley-caci Jan 20, 2025
64e32c4
Merge branch 'integrationTesting' into INT-B-21698-PPM-Clouseout-Calc…
brianmanley-caci Jan 21, 2025
6fdcebc
B-21698 fix spelling
brianmanley-caci Jan 22, 2025
1906867
B-21698 add constants for ppm doc status
brianmanley-caci Jan 22, 2025
af69542
Merge remote-tracking branch 'origin/main' into MAIN-B-21698
brianmanley-caci Jan 22, 2025
1fc9581
Merge B-21698 into INT-B-21698
brianmanley-caci Jan 22, 2025
99eeac9
B-21698 use existing ppm document status constants
brianmanley-caci Jan 22, 2025
d966642
Merge remote-tracking branch 'origin/MAIN-B-21698' into INT-B-21698-P…
brianmanley-caci Jan 22, 2025
8e2333f
Merge branch 'integrationTesting' into INT-B-21698-PPM-Clouseout-Calc…
brianmanley-caci Jan 22, 2025
9503d89
Merge branch 'integrationTesting' into INT-B-21698-PPM-Clouseout-Calc…
brianmanley-caci Jan 22, 2025
a26e1b2
Merge branch 'integrationTesting' into INT-B-21698-PPM-Clouseout-Calc…
brianmanley-caci Jan 22, 2025
4336e05
Merge branch 'integrationTesting' into INT-B-21698-PPM-Clouseout-Calc…
brianmanley-caci Jan 23, 2025
4df3462
Merge branch 'integrationTesting' into INT-B-21698-PPM-Clouseout-Calc…
brianmanley-caci Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/services/mto_shipment/mto_shipment_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,6 @@ func reServiceCodesForShipment(shipment models.MTOShipment) []models.ReServiceCo
models.ReServiceCodeDPK,
models.ReServiceCodeDUPK,
}

case models.MTOShipmentTypeHHGIntoNTS:
// Need to create: Dom Linehaul, Fuel Surcharge, Dom Origin Price, Dom Destination Price, Dom NTS Packing
return []models.ReServiceCode{
Expand Down
6 changes: 5 additions & 1 deletion src/utils/ppmCloseout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import moment from 'moment';
import { formatCents, formatCentsTruncateWhole, formatCustomerDate, formatWeight } from 'utils/formatters';
import { expenseTypeLabels, expenseTypes } from 'constants/ppmExpenseTypes';
import { isExpenseComplete, isWeightTicketComplete, isProGearComplete } from 'utils/shipments';
import PPMDocumentsStatus from 'constants/ppms';

export const getW2Address = (address) => {
const addressLine1 = address?.streetAddress2
Expand Down Expand Up @@ -166,7 +167,10 @@ export const formatExpenseItems = (expenses, editPath, editParams, handleDelete)
};

export const calculateTotalMovingExpensesAmount = (movingExpenses = []) => {
const excludedExpenseStatuses = [PPMDocumentsStatus.EXCLUDED, PPMDocumentsStatus.REJECTED]; // EXCLUDED and REJECTED expenses aren't included in the total.
return movingExpenses.reduce((prev, curr) => {
return curr.amount && !Number.isNaN(Number(curr.amount)) ? prev + curr.amount : prev;
return curr.amount && !Number.isNaN(Number(curr.amount)) && !excludedExpenseStatuses.includes(curr.status)
? prev + curr.amount
: prev;
}, 0);
};
29 changes: 29 additions & 0 deletions src/utils/ppmCloseout.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { calculateTotalMovingExpensesAmount, formatExpenseItems } from 'utils/ppmCloseout';
import { createCompleteMovingExpense, createCompleteSITMovingExpense } from 'utils/test/factories/movingExpense';
import { expenseTypeLabels } from 'constants/ppmExpenseTypes';
import PPMDocumentsStatus from 'constants/ppms';

describe('formatExpenseItems', () => {
it.each([
Expand Down Expand Up @@ -50,3 +51,31 @@ describe('calculateTotalMovingExpensesAmount', () => {
expect(calculateTotalMovingExpensesAmount(expenses)).toEqual(expectedTotal);
});
});

describe('calculateTotalMovingExpensesAmount with rejected and excluded amount', () => {
it('rejected and excluded expenses are not included in total amount', () => {
const approvedMovingExpense1 = createCompleteMovingExpense(
{},
{ status: PPMDocumentsStatus.APPROVED, amount: 350 },
);
const approvedMovingExpense2 = createCompleteMovingExpense(
{},
{ status: PPMDocumentsStatus.APPROVED, amount: 650 },
);
const approveAmountTotal = approvedMovingExpense1.amount + approvedMovingExpense2.amount;
const rejectedMovingExpense = createCompleteMovingExpense({}, { status: PPMDocumentsStatus.REJECTED, amount: 123 });
const excludedMovingExpense = createCompleteMovingExpense({}, { status: PPMDocumentsStatus.EXCLUDED, amount: 456 });
expect(approvedMovingExpense1.amount).toBeGreaterThan(0);
expect(approvedMovingExpense2.amount).toBeGreaterThan(0);
expect(rejectedMovingExpense.amount).toBeGreaterThan(0);
expect(excludedMovingExpense.amount).toBeGreaterThan(0);
expect(
calculateTotalMovingExpensesAmount([
approvedMovingExpense1,
approvedMovingExpense2,
rejectedMovingExpense,
excludedMovingExpense,
]),
).toEqual(approveAmountTotal);
});
});
9 changes: 7 additions & 2 deletions src/utils/shipmentWeights.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import returnLowestValue from './returnLowestValue';

import { SHIPMENT_OPTIONS } from 'shared/constants';
import PPMDocumentsStatus from 'constants/ppms';

// eslint-disable-next-line import/prefer-default-export
export function shipmentIsOverweight(estimatedWeight, weightCap) {
Expand Down Expand Up @@ -34,7 +35,11 @@ export const getDisplayWeight = (shipment, weightAdjustment = 1.0) => {
};

export const calculateNetWeightForProGearWeightTicket = (weightTicket) => {
if (weightTicket.weight == null || Number.isNaN(Number(weightTicket.weight))) {
if (
weightTicket.weight == null ||
Number.isNaN(Number(weightTicket.weight)) ||
weightTicket.status === PPMDocumentsStatus.REJECTED
) {
return 0;
}

Expand All @@ -61,7 +66,7 @@ export const calculateWeightTicketWeightDifference = (weightTicket) => {
};

export const getWeightTicketNetWeight = (weightTicket) => {
if (weightTicket.status !== 'REJECTED')
if (weightTicket.status !== PPMDocumentsStatus.REJECTED)
return weightTicket.adjustedNetWeight ?? calculateWeightTicketWeightDifference(weightTicket);
return 0;
};
Expand Down
26 changes: 25 additions & 1 deletion src/utils/shipmentWeights.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
shipmentIsOverweight,
getWeightTicketNetWeight,
} from './shipmentWeights';
import { createCompleteProGearWeightTicket } from './test/factories/proGearWeightTicket';
import {
createCompleteProGearWeightTicket,
createRejectedProGearWeightTicket,
} from './test/factories/proGearWeightTicket';
import { createCompleteWeightTicket } from './test/factories/weightTicket';

describe('shipmentWeights utils', () => {
Expand Down Expand Up @@ -202,6 +205,13 @@ describe('calculateNetWeightForProGearWeightTicket', () => {
expect(calculateNetWeightForProGearWeightTicket(proGearWeightTicket)).toEqual(expectedNetWeight);
},
);

it('rejected weight ticket net weight is zero', () => {
const rejectedProGearWeightTicket = createRejectedProGearWeightTicket({}, { weight: 200 });
// The weight of the ticket should be greater than zero for this test to be valid.
expect(rejectedProGearWeightTicket.weight).toBeGreaterThan(0);
expect(calculateNetWeightForProGearWeightTicket(rejectedProGearWeightTicket)).toEqual(0);
});
});

describe('calculateTotalNetWeightForProGearWeightTickets', () => {
Expand All @@ -226,6 +236,20 @@ describe('calculateTotalNetWeightForProGearWeightTickets', () => {
});
});

describe('calculateTotalNetWeightForProGearWeightTickets with a rejected weight ticket', () => {
it('rejected weight ticket is not included in total net weight', () => {
const approvedWeight = 350;
const approvedProGearWeightTicket = createCompleteProGearWeightTicket({}, { weight: approvedWeight });
const rejectedProGearWeightTicket = createRejectedProGearWeightTicket({}, { weight: 200 });
// The weight of each ticket should be greater than zero for this test to be valid.
expect(approvedProGearWeightTicket.weight).toBeGreaterThan(0);
expect(rejectedProGearWeightTicket.weight).toBeGreaterThan(0);
expect(
calculateTotalNetWeightForProGearWeightTickets([approvedProGearWeightTicket, rejectedProGearWeightTicket]),
).toEqual(approvedWeight);
});
});

describe('Calculating shipment net weights', () => {
const ppmShipments = [
{
Expand Down
15 changes: 15 additions & 0 deletions src/utils/test/factories/proGearWeightTicket.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { v4 } from 'uuid';

import createUpload from 'utils/test/factories/upload';
import { createDocumentWithoutUploads } from 'utils/test/factories/document';
import PPMDocumentsStatus from 'constants/ppms';

const createBaseProGearWeightTicket = ({ serviceMemberId, creationDate = new Date() } = {}, fieldOverrides = {}) => {
const createdAt = creationDate.toISOString();
Expand Down Expand Up @@ -81,8 +82,22 @@ const createCompleteProGearWeightTicketWithConstructedWeight = (
return weightTicket;
};

const createRejectedProGearWeightTicket = ({ serviceMemberId, creationDate } = {}, fieldOverrides = {}) => {
const fullFieldOverrides = {
belongsToSelf: true,
description: 'Laptop',
hasWeightTickets: true,
weight: 150,
...fieldOverrides,
};
const weightTicket = createBaseProGearWeightTicket({ serviceMemberId, creationDate }, fullFieldOverrides);
weightTicket.status = PPMDocumentsStatus.REJECTED;
return weightTicket;
};

export {
createBaseProGearWeightTicket,
createCompleteProGearWeightTicket,
createCompleteProGearWeightTicketWithConstructedWeight,
createRejectedProGearWeightTicket,
};
Loading