From 5b983059bbca7e9e2600b44c198eb3434580b39f Mon Sep 17 00:00:00 2001 From: Daniel Jordan Date: Tue, 27 Aug 2024 14:57:41 +0000 Subject: [PATCH 1/3] initial commit, lemon squeezy --- .../shipment_summary_worksheet.go | 2 +- .../shipment_summary_worksheet_test.go | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet.go b/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet.go index 99896b0a136..9da6840e211 100644 --- a/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet.go +++ b/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet.go @@ -258,7 +258,7 @@ func FormatValuesShipmentSummaryWorksheetFormPage1(data services.ShipmentSummary page1.ActualObligationGCC100 = formattedShipment.ShipmentWeightForObligation + " - Estimated lbs; " + formattedShipment.FinalIncentive page1.PreparationDate1 = formatAOADate(data.SignedCertifications, data.PPMShipment.ID) } - page1.MaxObligationGCC100 = FormatWeights(data.WeightAllotment.TotalWeight) + " lbs; " + formattedShipment.EstimatedIncentive + page1.MaxObligationGCC100 = FormatWeights(data.WeightAllotment.Entitlement) + " lbs; " + formattedShipment.EstimatedIncentive page1.MaxObligationGCCMaxAdvance = formattedShipment.MaxAdvance page1.ActualObligationAdvance = formattedShipment.AdvanceAmountReceived page1.MaxObligationSIT = fmt.Sprintf("%02d Days in SIT", data.MaxSITStorageEntitlement) diff --git a/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet_test.go b/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet_test.go index 8664db3e334..c80452add73 100644 --- a/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet_test.go +++ b/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet_test.go @@ -102,7 +102,6 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFetchDataShipmentSummaryW suite.Equal(ppmShipment.EstimatedWeight, ssd.PPMShipments[0].EstimatedWeight) suite.Require().NotNil(ssd.PPMShipments[0].AdvanceAmountRequested) suite.Equal(ppmShipment.AdvanceAmountRequested, ssd.PPMShipments[0].AdvanceAmountRequested) - // suite.Equal(signedCertification.ID, ssd.SignedCertification.ID) } func (suite *ShipmentSummaryWorksheetServiceSuite) TestFetchDataShipmentSummaryWorksheetWithErrorNoMove() { @@ -272,7 +271,6 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFetchDataShipmentSummaryW suite.Equal(ppmShipment.EstimatedWeight, ssd.PPMShipments[0].EstimatedWeight) suite.Require().NotNil(ssd.PPMShipments[0].AdvanceAmountRequested) suite.Equal(ppmShipment.AdvanceAmountRequested, ssd.PPMShipments[0].AdvanceAmountRequested) - // suite.Equal(signedCertification.ID, ssd.SignedCertification.ID) suite.Require().Len(ssd.MovingExpenses, 0) } @@ -318,12 +316,14 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma netWeight := unit.Pound(4000) cents := unit.Cents(1000) locator := "ABCDEF-01" - PPMShipment := models.PPMShipment{ + estIncentive := unit.Cents(1000000) + PPMShipments := models.PPMShipment{ ExpectedDepartureDate: expectedPickupDate, ActualMoveDate: &actualPickupDate, Status: models.PPMShipmentStatusWaitingOnCustomer, EstimatedWeight: &netWeight, AdvanceAmountRequested: ¢s, + EstimatedIncentive: &estIncentive, Shipment: models.MTOShipment{ ShipmentLocator: &locator, }, @@ -336,7 +336,7 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma PPMRemainingEntitlement: 3000, WeightAllotment: wtgEntitlements, PreparationDate: time.Date(2019, 1, 1, 1, 1, 1, 1, time.UTC), - PPMShipment: PPMShipment, + PPMShipment: PPMShipments, } sswPage1, err := FormatValuesShipmentSummaryWorksheetFormPage1(ssd, false) suite.NoError(err) @@ -351,13 +351,10 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma suite.Equal("444-555-8888", sswPage1.PreferredPhoneNumber) suite.Equal("michael+ppm-expansion_1@truss.works", sswPage1.PreferredEmail) suite.Equal("1234567890", sswPage1.DODId) - suite.Equal("Air Force", sswPage1.IssuingBranchOrAgency) suite.Equal("21-Dec-2018", sswPage1.OrdersIssueDate) suite.Equal("PCS/012345", sswPage1.OrdersTypeAndOrdersNumber) - suite.Equal("Fort Eisenhower, GA 30813", sswPage1.NewDutyAssignment) - suite.Equal("15,000", sswPage1.WeightAllotment) suite.Equal("2,000", sswPage1.WeightAllotmentProGear) suite.Equal("500", sswPage1.WeightAllotmentProgearSpouse) @@ -367,9 +364,8 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma suite.Equal("11-Jan-2019", sswPage1.ShipmentPickUpDates) suite.Equal("4,000 lbs - Estimated", sswPage1.ShipmentWeights) suite.Equal("Waiting On Customer", sswPage1.ShipmentCurrentShipmentStatuses) - suite.Equal("17,500", sswPage1.TotalWeightAllotmentRepeat) - + suite.Equal("15,000 lbs; $10,000.00", sswPage1.MaxObligationGCC100) suite.Equal("3,000", sswPage1.PPMRemainingEntitlement) // quick test when there is no PPM actual move date From 593d00897a9d4d3744ed6da1f5672fee1c8782a8 Mon Sep 17 00:00:00 2001 From: Daniel Jordan Date: Tue, 27 Aug 2024 17:40:03 +0000 Subject: [PATCH 2/3] replaced estimated weight with customers entitlement from orders when calculating estimated incentive of a PPM --- pkg/services/ppm_closeout/ppm_closeout.go | 6 ++++- pkg/services/ppmshipment/ppm_estimator.go | 24 +++++++++++++++---- .../ppmshipment/ppm_estimator_test.go | 21 ++++++++++++++-- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/pkg/services/ppm_closeout/ppm_closeout.go b/pkg/services/ppm_closeout/ppm_closeout.go index edf301bf0b1..f10ea7373e9 100644 --- a/pkg/services/ppm_closeout/ppm_closeout.go +++ b/pkg/services/ppm_closeout/ppm_closeout.go @@ -361,7 +361,11 @@ func (p *ppmCloseoutFetcher) getServiceItemPrices(appCtx appcontext.AppContext, ppmToMtoShipment = ppmshipment.MapPPMShipmentFinalFields(ppmShipment, totalWeight) } else { // Reassign ppm shipment fields to their expected location on the mto shipment for dates, addresses, weights ... - ppmToMtoShipment = ppmshipment.MapPPMShipmentEstimatedFields(ppmShipment) + ppmToMtoShipment, err = ppmshipment.MapPPMShipmentEstimatedFields(appCtx, ppmShipment) + if err != nil { + logger.Error("unable to map PPM estimated fields", zap.Error(err)) + return serviceItemPrices{}, err + } } sitCosts, err := p.GetExpenseStoragePrice(appCtx, ppmShipment.ID) diff --git a/pkg/services/ppmshipment/ppm_estimator.go b/pkg/services/ppmshipment/ppm_estimator.go index 39087237f93..bd47f53d935 100644 --- a/pkg/services/ppmshipment/ppm_estimator.go +++ b/pkg/services/ppmshipment/ppm_estimator.go @@ -349,7 +349,11 @@ func (f estimatePPM) calculatePrice(appCtx appcontext.AppContext, ppmShipment *m mtoShipment = MapPPMShipmentFinalFields(*ppmShipment, totalWeightFromWeightTickets) } else { // Reassign ppm shipment fields to their expected location on the mto shipment for dates, addresses, weights ... - mtoShipment = MapPPMShipmentEstimatedFields(*ppmShipment) + mtoShipment, err = MapPPMShipmentEstimatedFields(appCtx, *ppmShipment) + if err != nil { + logger.Error("unable to map PPM estimated fields", zap.Error(err)) + return nil, err + } } totalPrice := unit.Cents(0) @@ -674,15 +678,27 @@ func priceAdditionalDaySIT(appCtx appcontext.AppContext, pricer services.ParamsP // mapPPMShipmentEstimatedFields remaps our PPMShipment specific information into the fields where the service param lookups // expect to find them on the MTOShipment model. This is only in-memory and shouldn't get saved to the database. -func MapPPMShipmentEstimatedFields(ppmShipment models.PPMShipment) models.MTOShipment { +func MapPPMShipmentEstimatedFields(appCtx appcontext.AppContext, ppmShipment models.PPMShipment) (models.MTOShipment, error) { + // we have access to the MoveTaskOrderID in the ppmShipment object so we can use that to get the customer's maximum weight entitlement + var move models.Move + err := appCtx.DB().Q().Eager( + "Orders.Entitlement", + ).Where("show = TRUE").Find(&move, ppmShipment.Shipment.MoveTaskOrderID) + if err != nil { + return models.MTOShipment{}, apperror.NewNotFoundError(ppmShipment.ID, " error querying move") + } + orders := move.Orders + if orders.Entitlement.DBAuthorizedWeight == nil { + return models.MTOShipment{}, apperror.NewNotFoundError(ppmShipment.ID, " DB authorized weight cannot be nil") + } ppmShipment.Shipment.ActualPickupDate = &ppmShipment.ExpectedDepartureDate ppmShipment.Shipment.RequestedPickupDate = &ppmShipment.ExpectedDepartureDate ppmShipment.Shipment.PickupAddress = &models.Address{PostalCode: ppmShipment.PickupAddress.PostalCode} ppmShipment.Shipment.DestinationAddress = &models.Address{PostalCode: ppmShipment.DestinationAddress.PostalCode} - ppmShipment.Shipment.PrimeActualWeight = ppmShipment.EstimatedWeight + ppmShipment.Shipment.PrimeActualWeight = (*unit.Pound)(orders.Entitlement.DBAuthorizedWeight) - return ppmShipment.Shipment + return ppmShipment.Shipment, nil } // mapPPMShipmentFinalFields remaps our PPMShipment specific information into the fields where the service param lookups diff --git a/pkg/services/ppmshipment/ppm_estimator_test.go b/pkg/services/ppmshipment/ppm_estimator_test.go index 9089a340e57..ac982bb33cb 100644 --- a/pkg/services/ppmshipment/ppm_estimator_test.go +++ b/pkg/services/ppmshipment/ppm_estimator_test.go @@ -509,7 +509,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() { suite.Equal(oldPPMShipment.PickupAddress.PostalCode, newPPM.PickupAddress.PostalCode) suite.Equal(unit.Pound(5000), *newPPM.EstimatedWeight) - suite.Equal(unit.Cents(70064364), *ppmEstimate) + suite.Equal(unit.Cents(112102682), *ppmEstimate) }) suite.Run("Estimated Incentive - Success - clears advance and advance requested values", func() { @@ -540,7 +540,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() { suite.NilOrNoVerrs(err) suite.Nil(newPPM.HasRequestedAdvance) suite.Nil(newPPM.AdvanceAmountRequested) - suite.Equal(unit.Cents(38213948), *ppmEstimate) + suite.Equal(unit.Cents(112102682), *ppmEstimate) }) suite.Run("Estimated Incentive - does not change when required fields are the same", func() { @@ -1637,7 +1637,24 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() { setupPricerData() destinationLocation := models.SITLocationTypeDestination + move := factory.BuildMove(suite.DB(), []factory.Customization{ + { + Model: models.Order{ + ID: uuid.Must(uuid.NewV4()), + }, + }, + { + Model: models.Entitlement{ + ID: uuid.Must(uuid.NewV4()), + DBAuthorizedWeight: models.IntPointer(2000), + }, + }, + }, nil) originalShipment := factory.BuildPPMShipment(suite.DB(), []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, { Model: models.PPMShipment{ SITExpected: models.BoolPointer(true), From 524e112b57f0a7e3aed88e48e014e3d9f6e47943 Mon Sep 17 00:00:00 2001 From: Daniel Jordan Date: Tue, 27 Aug 2024 18:04:24 +0000 Subject: [PATCH 3/3] updated playwright after changed incentive calculation --- playwright/tests/office/ppms/happyPathFlows.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright/tests/office/ppms/happyPathFlows.spec.js b/playwright/tests/office/ppms/happyPathFlows.spec.js index 975301d990e..010a1d8e4a4 100644 --- a/playwright/tests/office/ppms/happyPathFlows.spec.js +++ b/playwright/tests/office/ppms/happyPathFlows.spec.js @@ -117,7 +117,7 @@ test.describe('Services counselor user', () => { await expect(shipmentContainer.locator('[data-testid="estimatedWeight"]')).toContainText('4,000 lbs'); await expect(shipmentContainer.locator('[data-testid="proGearWeight"]')).toContainText('Yes, 1,000 lbs'); await expect(shipmentContainer.locator('[data-testid="spouseProGear"]')).toContainText('Yes, 500 lbs'); - await expect(shipmentContainer.locator('[data-testid="estimatedIncentive"]')).toContainText('$67,689'); + await expect(shipmentContainer.locator('[data-testid="estimatedIncentive"]')).toContainText('$223,235'); await expect(shipmentContainer.locator('[data-testid="hasRequestedAdvance"]')).toContainText('Yes, $10,000'); await expect(shipmentContainer.locator('[data-testid="counselorRemarks"]')).toContainText( 'Added correct incentive',