Skip to content

Commit

Permalink
Merge pull request #14829 from transcom/MAIN-B-21698
Browse files Browse the repository at this point in the history
Main b 21698
  • Loading branch information
brianmanley-caci authored Feb 20, 2025
2 parents e8ccbce + ec423a2 commit 9daddb7
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
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,
};

0 comments on commit 9daddb7

Please # to comment.