From 9d3c89742fcffda6286407784eba648ad8b482fe Mon Sep 17 00:00:00 2001 From: Alex Lusk Date: Fri, 15 Nov 2024 15:31:55 +0000 Subject: [PATCH 1/5] ppm closeout incentives and costs use allowable weight if it is less than net weight --- pkg/factory/ppm_shipment_factory.go | 10 ++++++++++ pkg/handlers/ghcapi/ppm_closeout.go | 14 +++++++------- pkg/services/ppm_closeout/ppm_closeout.go | 6 +++++- pkg/services/ppmshipment/ppm_estimator.go | 4 ++++ pkg/testdatagen/scenario/shared.go | 8 ++++++++ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/pkg/factory/ppm_shipment_factory.go b/pkg/factory/ppm_shipment_factory.go index f6a43ab95f2..5c0fa338e8e 100644 --- a/pkg/factory/ppm_shipment_factory.go +++ b/pkg/factory/ppm_shipment_factory.go @@ -344,6 +344,16 @@ func AddWeightTicketToPPMShipment(db *pop.Connection, ppmShipment *models.PPMShi weightTicket.UpdatedAt = ppmShipment.UpdatedAt } ppmShipment.WeightTickets = append(ppmShipment.WeightTickets, weightTicket) + + // if ppmShipment.Status == models.PPMShipmentStatusNeedsCloseout { + // var allowableWeight = unit.Pound(0) + // if len(ppmShipment.WeightTickets) >= 1 { + // for _, weightTicket := range ppmShipment.WeightTickets { + // allowableWeight += *weightTicket.FullWeight - *weightTicket.EmptyWeight + // } + // } + // ppmShipment.AllowableWeight = &allowableWeight + // } } // AddProgearWeightTicketToPPMShipment adds a progear weight ticket to diff --git a/pkg/handlers/ghcapi/ppm_closeout.go b/pkg/handlers/ghcapi/ppm_closeout.go index 43b46cf42d4..d3fa3d7f9fe 100644 --- a/pkg/handlers/ghcapi/ppm_closeout.go +++ b/pkg/handlers/ghcapi/ppm_closeout.go @@ -69,7 +69,7 @@ type GetPPMActualWeightHandler struct { ppmShipmentFetcher services.PPMShipmentFetcher } -// Handle retrieves all calcuations for a PPM closeout +// Handle retrieves actual weight for a PPM pending closeout func (h GetPPMActualWeightHandler) Handle(params ppmcloseoutops.GetPPMActualWeightParams) middleware.Responder { return h.AuditableAppContextFromRequestWithErrors(params.HTTPRequest, func(appCtx appcontext.AppContext) (middleware.Responder, error) { @@ -79,15 +79,15 @@ func (h GetPPMActualWeightHandler) Handle(params ppmcloseoutops.GetPPMActualWeig payload := &ghcmessages.Error{Message: handlers.FmtString(err.Error())} switch err.(type) { case apperror.NotFoundError: - return ppmcloseoutops.NewGetPPMCloseoutNotFound().WithPayload(payload), err + return ppmcloseoutops.NewGetPPMActualWeightNotFound().WithPayload(payload), err case apperror.PPMNotReadyForCloseoutError: - return ppmcloseoutops.NewGetPPMCloseoutNotFound().WithPayload(payload), err + return ppmcloseoutops.NewGetPPMActualWeightNotFound().WithPayload(payload), err case apperror.ForbiddenError: - return ppmcloseoutops.NewGetPPMCloseoutForbidden().WithPayload(payload), err + return ppmcloseoutops.NewGetPPMActualWeightForbidden().WithPayload(payload), err case apperror.QueryError: - return ppmcloseoutops.NewGetPPMCloseoutInternalServerError().WithPayload(payload), err + return ppmcloseoutops.NewGetPPMActualWeightInternalServerError().WithPayload(payload), err default: - return ppmcloseoutops.NewGetPPMCloseoutInternalServerError().WithPayload(payload), err + return ppmcloseoutops.NewGetPPMActualWeightInternalServerError().WithPayload(payload), err } } errInstance := fmt.Sprintf("Instance: %s", h.GetTraceIDFromRequest(params.HTTPRequest)) @@ -95,7 +95,7 @@ func (h GetPPMActualWeightHandler) Handle(params ppmcloseoutops.GetPPMActualWeig errPayload := &ghcmessages.Error{Message: &errInstance} if !appCtx.Session().IsOfficeApp() { - return ppmcloseoutops.NewGetPPMCloseoutForbidden().WithPayload(errPayload), apperror.NewSessionError("Request should come from the office app.") + return ppmcloseoutops.NewGetPPMActualWeightForbidden().WithPayload(errPayload), apperror.NewSessionError("Request should come from the office app.") } ppmShipmentID := uuid.FromStringOrNil(params.PpmShipmentID.String()) diff --git a/pkg/services/ppm_closeout/ppm_closeout.go b/pkg/services/ppm_closeout/ppm_closeout.go index 2ac5ea8a46f..925385d079b 100644 --- a/pkg/services/ppm_closeout/ppm_closeout.go +++ b/pkg/services/ppm_closeout/ppm_closeout.go @@ -92,7 +92,7 @@ func (p *ppmCloseoutFetcher) GetPPMCloseout(appCtx appcontext.AppContext, ppmShi fullWeightGCCShipment := ppmShipment - // Set pro gear werights for the GCC calculation to the max allowed before calculating GCC price + // Set pro gear weights for the GCC calculation to the max allowed before calculating GCC price fullWeightGCCShipment.ProGearWeight = &proGearCustomerMax fullWeightGCCShipment.SpouseProGearWeight = &proGearSpouseMax gcc, _ := p.calculateGCC(appCtx, *fullWeightGCCShipment, fullAllowableWeight) @@ -351,6 +351,10 @@ func (p *ppmCloseoutFetcher) getServiceItemPrices(appCtx appcontext.AppContext, } } + if ppmShipment.AllowableWeight != nil && *ppmShipment.AllowableWeight < totalWeight { + totalWeight = *ppmShipment.AllowableWeight + } + if totalWeight > 0 { // Reassign ppm shipment fields to their expected location on the mto shipment for dates, addresses, weights ... ppmToMtoShipment = ppmshipment.MapPPMShipmentFinalFields(ppmShipment, totalWeight) diff --git a/pkg/services/ppmshipment/ppm_estimator.go b/pkg/services/ppmshipment/ppm_estimator.go index ebec38a8848..16782fe024c 100644 --- a/pkg/services/ppmshipment/ppm_estimator.go +++ b/pkg/services/ppmshipment/ppm_estimator.go @@ -254,6 +254,10 @@ func (f *estimatePPM) finalIncentive(appCtx appcontext.AppContext, oldPPMShipmen } originalTotalWeight, newTotalWeight := SumWeightTickets(oldPPMShipment, *newPPMShipment) + if newPPMShipment.AllowableWeight != nil && *newPPMShipment.AllowableWeight < newTotalWeight { + newTotalWeight = *newPPMShipment.AllowableWeight + } + isMissingInfo := shouldSetFinalIncentiveToNil(newPPMShipment, newTotalWeight) var skipCalculateFinalIncentive bool finalIncentive := oldPPMShipment.FinalIncentive diff --git a/pkg/testdatagen/scenario/shared.go b/pkg/testdatagen/scenario/shared.go index 525f8ec7dd0..f92ea47dd1e 100644 --- a/pkg/testdatagen/scenario/shared.go +++ b/pkg/testdatagen/scenario/shared.go @@ -1366,6 +1366,7 @@ func createApprovedMoveWithPPMCloseoutComplete(appCtx appcontext.AppContext, use approvedAt := time.Date(2022, 4, 15, 12, 30, 0, 0, time.UTC) address := factory.BuildAddress(appCtx.DB(), nil, nil) approvedAdvanceStatus := models.PPMAdvanceStatusApproved + allowableWeight := unit.Pound(4000) assertions := testdatagen.Assertions{ UserUploader: userUploader, @@ -1388,6 +1389,7 @@ func createApprovedMoveWithPPMCloseoutComplete(appCtx appcontext.AppContext, use HasReceivedAdvance: models.BoolPointer(true), AdvanceAmountReceived: models.CentPointer(unit.Cents(340000)), W2Address: &address, + AllowableWeight: &allowableWeight, }, } @@ -1426,6 +1428,7 @@ func createApprovedMoveWithPPMCloseoutCompleteMultipleWeightTickets(appCtx appco approvedAt := time.Date(2022, 4, 15, 12, 30, 0, 0, time.UTC) address := factory.BuildAddress(appCtx.DB(), nil, nil) approvedAdvanceStatus := models.PPMAdvanceStatusApproved + allowableWeight := unit.Pound(8000) assertions := testdatagen.Assertions{ UserUploader: userUploader, @@ -1448,6 +1451,7 @@ func createApprovedMoveWithPPMCloseoutCompleteMultipleWeightTickets(appCtx appco HasReceivedAdvance: models.BoolPointer(true), AdvanceAmountReceived: models.CentPointer(unit.Cents(340000)), W2Address: &address, + AllowableWeight: &allowableWeight, }, } @@ -1504,6 +1508,7 @@ func createApprovedMoveWithPPMCloseoutCompleteWithExpenses(appCtx appcontext.App approvedAt := time.Date(2022, 4, 15, 12, 30, 0, 0, time.UTC) address := factory.BuildAddress(appCtx.DB(), nil, nil) approvedAdvanceStatus := models.PPMAdvanceStatusApproved + allowableWeight := unit.Pound(4000) assertions := testdatagen.Assertions{ UserUploader: userUploader, @@ -1526,6 +1531,7 @@ func createApprovedMoveWithPPMCloseoutCompleteWithExpenses(appCtx appcontext.App HasReceivedAdvance: models.BoolPointer(true), AdvanceAmountReceived: models.CentPointer(unit.Cents(340000)), W2Address: &address, + AllowableWeight: &allowableWeight, }, } @@ -1595,6 +1601,7 @@ func createApprovedMoveWithPPMCloseoutCompleteWithAllDocTypes(appCtx appcontext. approvedAt := time.Date(2022, 4, 15, 12, 30, 0, 0, time.UTC) address := factory.BuildAddress(appCtx.DB(), nil, nil) approvedAdvanceStatus := models.PPMAdvanceStatusApproved + allowableWeight := unit.Pound(4000) assertions := testdatagen.Assertions{ UserUploader: userUploader, @@ -1617,6 +1624,7 @@ func createApprovedMoveWithPPMCloseoutCompleteWithAllDocTypes(appCtx appcontext. HasReceivedAdvance: models.BoolPointer(true), AdvanceAmountReceived: models.CentPointer(unit.Cents(340000)), W2Address: &address, + AllowableWeight: &allowableWeight, }, } From ba3a8a49dda245115381f1a4c7cc737ecbf337e3 Mon Sep 17 00:00:00 2001 From: Alex Lusk Date: Fri, 15 Nov 2024 15:34:17 +0000 Subject: [PATCH 2/5] removed unused and no longer tested edit net weight form --- .../PPM/EditNetWeights/EditPPMNetWeight.jsx | 163 ++---------------- 1 file changed, 11 insertions(+), 152 deletions(-) diff --git a/src/components/Office/PPM/EditNetWeights/EditPPMNetWeight.jsx b/src/components/Office/PPM/EditNetWeights/EditPPMNetWeight.jsx index f930c8e2acc..8cd593f73cb 100644 --- a/src/components/Office/PPM/EditNetWeights/EditPPMNetWeight.jsx +++ b/src/components/Office/PPM/EditNetWeights/EditPPMNetWeight.jsx @@ -1,23 +1,14 @@ -import React, { useState } from 'react'; -import { Formik } from 'formik'; -import { useMutation, useQueryClient } from '@tanstack/react-query'; -import * as Yup from 'yup'; +import React from 'react'; import { PropTypes, number } from 'prop-types'; -import { Button, Fieldset, Label, Textarea } from '@trussworks/react-uswds'; import styles from './EditPPMNetWeight.module.scss'; -import MaskedTextField from 'components/form/fields/MaskedTextField/MaskedTextField'; -import { ErrorMessage } from 'components/form/ErrorMessage'; import { formatWeight } from 'utils/formatters'; import { calculateWeightTicketWeightDifference, getWeightTicketNetWeight } from 'utils/shipmentWeights'; import { calculateWeightRequested } from 'hooks/custom'; -import { patchWeightTicket } from 'services/ghcApi'; import { ShipmentShape, WeightTicketShape } from 'types/shipment'; -import { DOCUMENTS } from 'constants/queryKeys'; // Labels & constants - const CALCULATION_TYPE = { NET_WEIGHT: 'NET_WEIGHT', EXCESS_WEIGHT: 'EXCESS_WEIGHT', @@ -48,15 +39,6 @@ const FlexContainer = ({ children, className }) => { ); }; -// Form Error Indicator -const ErrorIndicator = ({ children, hasErrors }) => { - return ( -
- {children} -
- ); -}; - const WeightCalculationHint = ({ type, firstValue, secondValue, thirdValue }) => { const { firstLabel, secondLabel, thirdLabel } = weightLabels[type]; return ( @@ -91,111 +73,7 @@ const WeightCalculationHint = ({ type, firstValue, secondValue, thirdValue }) => ); }; -const EditPPMNetWeightForm = ({ onCancel, initialValues, weightTicket }) => { - const validationSchema = Yup.object({ - adjustedNetWeight: Yup.number() - .min(0, 'Net weight must be 0 lbs or greater') - .lessThan(weightTicket.fullWeight, 'Net weight must be less than or equal to the full weight') - .required('Required'), - netWeightRemarks: Yup.string().nullable().required('Required'), - }); - const queryClient = useQueryClient(); - - const { mutate: patchWeightTicketMutation } = useMutation({ - mutationFn: patchWeightTicket, - onSuccess: () => { - queryClient.invalidateQueries({ - queryKey: [DOCUMENTS], - }); - }, - }); - - /** - * @const onSubmit - * @description This function is used to submit the mini form represented by the EditPPMNetWeightForm. - * @param {Object} formValues - The values that are returned from the EditPPMNetWeightForm component on click. - * @param {string} formValues.adjustedNetWeight - The adjusted net weight as a string. This value needs to be parsed into an integer before mutation. - * @param {string} formValues.netWeightRemarks - The net weight remarks. - * */ - const onSubmit = (formValues /* , actions */) => { - const payload = { - adjustedNetWeight: parseInt(formValues.adjustedNetWeight, 10), - netWeightRemarks: formValues.netWeightRemarks, - }; - patchWeightTicketMutation( - { - ppmShipmentId: weightTicket.ppmShipmentId, - weightTicketId: weightTicket.id, - payload, - eTag: weightTicket.eTag, - }, - { - onSuccess: () => { - onCancel(); - }, - }, - ); - }; - - return ( - - {({ handleChange, handleSubmit, values, isValid, errors, touched, setTouched }) => ( -
-
- - - - {errors.netWeightRemarks} - - -