diff --git a/pkg/services/mto_shipment/mto_shipment_updater.go b/pkg/services/mto_shipment/mto_shipment_updater.go index a4ec081df2a..1f3696da161 100644 --- a/pkg/services/mto_shipment/mto_shipment_updater.go +++ b/pkg/services/mto_shipment/mto_shipment_updater.go @@ -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{ diff --git a/src/utils/ppmCloseout.jsx b/src/utils/ppmCloseout.jsx index 6ee33434c7b..2a2a121107f 100644 --- a/src/utils/ppmCloseout.jsx +++ b/src/utils/ppmCloseout.jsx @@ -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 @@ -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); }; diff --git a/src/utils/ppmCloseout.test.jsx b/src/utils/ppmCloseout.test.jsx index 4c8df5e07d5..b168a896eaf 100644 --- a/src/utils/ppmCloseout.test.jsx +++ b/src/utils/ppmCloseout.test.jsx @@ -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([ @@ -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); + }); +}); diff --git a/src/utils/shipmentWeights.js b/src/utils/shipmentWeights.js index 08d57c8130d..58cd6e8ab73 100644 --- a/src/utils/shipmentWeights.js +++ b/src/utils/shipmentWeights.js @@ -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) { @@ -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; } @@ -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; }; diff --git a/src/utils/shipmentWeights.test.js b/src/utils/shipmentWeights.test.js index a3ec57823e4..4f4e7616358 100644 --- a/src/utils/shipmentWeights.test.js +++ b/src/utils/shipmentWeights.test.js @@ -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', () => { @@ -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', () => { @@ -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 = [ { diff --git a/src/utils/test/factories/proGearWeightTicket.js b/src/utils/test/factories/proGearWeightTicket.js index 767dbe667a6..1935bc1b4a8 100644 --- a/src/utils/test/factories/proGearWeightTicket.js +++ b/src/utils/test/factories/proGearWeightTicket.js @@ -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(); @@ -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, };