Skip to content

Commit

Permalink
Merge pull request #12796 from transcom/B-20164
Browse files Browse the repository at this point in the history
B 20164
  • Loading branch information
r-mettler authored Jun 7, 2024
2 parents af398d6 + 30dd913 commit b2dcb60
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 63 deletions.
2 changes: 1 addition & 1 deletion migrations/app/migrations_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,10 @@
20240515164336_ignore_locked_columns_in_moves_table_for_history_log.up.sql
20240516143952_add_pricing_estimate_to_mto_service_items.up.sql
20240516184021_import_pricing_data_ghc.up.sql
20240524214247_add_sit_location_moving_expenses.up.sql
20240521160335_backfill_LOA_FY_TX.up.sql
20240521184834_add_standalone_field_to_service_items.up.sql
20240522124339_add_csr_to_roles.up.sql
20240524214247_add_sit_location_moving_expenses.up.sql
20240530020648_adding_standalone_crate_service_param.up.sql
20240531050324_adding_standalone_crate_cap.up.sql
20240531152430_migrate_data_to_new_ppm_statuses.up.sql
Expand Down
2 changes: 2 additions & 0 deletions pkg/services/ppm_closeout/ppm_closeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ func (p *ppmCloseoutFetcher) GetPPMShipment(appCtx appcontext.AppContext, ppmShi
"FinalIncentive",
"AdvanceAmountReceived",
"Shipment.Distance",
"PickupAddress",
"DestinationAddress",
).
Find(&ppmShipment, ppmShipmentID)

Expand Down
9 changes: 9 additions & 0 deletions pkg/services/ppm_closeout/ppm_closeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ func (suite *PPMCloseoutSuite) TestPPMShipmentCreator() {
},
})

testdatagen.FetchOrMakeReZip3(suite.AppContextForTest().DB(), testdatagen.Assertions{
ReZip3: models.ReZip3{
Contract: originDomesticServiceArea.Contract,
ContractID: originDomesticServiceArea.ContractID,
DomesticServiceArea: originDomesticServiceArea,
Zip3: "503",
},
})

testdatagen.FetchOrMakeReDomesticLinehaulPrice(suite.AppContextForTest().DB(), testdatagen.Assertions{
ReDomesticLinehaulPrice: models.ReDomesticLinehaulPrice{
Contract: originDomesticServiceArea.Contract,
Expand Down
20 changes: 10 additions & 10 deletions pkg/services/ppmshipment/ppm_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (f *estimatePPM) FinalIncentiveWithDefaultChecks(appCtx appcontext.AppConte

func shouldSkipEstimatingIncentive(newPPMShipment *models.PPMShipment, oldPPMShipment *models.PPMShipment) bool {
return oldPPMShipment.ExpectedDepartureDate.Equal(newPPMShipment.ExpectedDepartureDate) &&
newPPMShipment.PickupPostalCode == oldPPMShipment.PickupPostalCode &&
newPPMShipment.DestinationPostalCode == oldPPMShipment.DestinationPostalCode &&
newPPMShipment.PickupAddress.PostalCode == oldPPMShipment.PickupAddress.PostalCode &&
newPPMShipment.DestinationAddress.PostalCode == oldPPMShipment.DestinationAddress.PostalCode &&
((newPPMShipment.EstimatedWeight == nil && oldPPMShipment.EstimatedWeight == nil) || (oldPPMShipment.EstimatedWeight != nil && newPPMShipment.EstimatedWeight.Int() == oldPPMShipment.EstimatedWeight.Int()))
}

Expand Down Expand Up @@ -97,8 +97,8 @@ func shouldCalculateSITCost(newPPMShipment *models.PPMShipment, oldPPMShipment *
*newPPMShipment.SITEstimatedWeight != *oldPPMShipment.SITEstimatedWeight ||
*newPPMShipment.SITEstimatedEntryDate != *oldPPMShipment.SITEstimatedEntryDate ||
*newPPMShipment.SITEstimatedDepartureDate != *oldPPMShipment.SITEstimatedDepartureDate ||
newPPMShipment.PickupPostalCode != oldPPMShipment.PickupPostalCode ||
newPPMShipment.DestinationPostalCode != oldPPMShipment.DestinationPostalCode ||
newPPMShipment.PickupAddress.PostalCode != oldPPMShipment.PickupAddress.PostalCode ||
newPPMShipment.DestinationAddress.PostalCode != oldPPMShipment.DestinationAddress.PostalCode ||
newPPMShipment.ExpectedDepartureDate != oldPPMShipment.ExpectedDepartureDate
}

Expand Down Expand Up @@ -394,9 +394,9 @@ func priceFirstDaySIT(appCtx appcontext.AppContext, pricer services.ParamsPricer
return nil, errors.New("ppm estimate pricer for SIT service item does not implement the first day pricer interface")
}

serviceAreaPostalCode := ppmShipment.PickupPostalCode
serviceAreaPostalCode := ppmShipment.PickupAddress.PostalCode
if serviceItem.ReService.Code == models.ReServiceCodeDDFSIT {
serviceAreaPostalCode = ppmShipment.DestinationPostalCode
serviceAreaPostalCode = ppmShipment.DestinationAddress.PostalCode
}

serviceAreaLookup := serviceparamvaluelookups.ServiceAreaLookup{
Expand Down Expand Up @@ -433,9 +433,9 @@ func priceAdditionalDaySIT(appCtx appcontext.AppContext, pricer services.ParamsP
return nil, errors.New("ppm estimate pricer for SIT service item does not implement the additional days pricer interface")
}

serviceAreaPostalCode := ppmShipment.PickupPostalCode
serviceAreaPostalCode := ppmShipment.PickupAddress.PostalCode
if serviceItem.ReService.Code == models.ReServiceCodeDDASIT {
serviceAreaPostalCode = ppmShipment.DestinationPostalCode
serviceAreaPostalCode = ppmShipment.DestinationAddress.PostalCode
}
serviceAreaLookup := serviceparamvaluelookups.ServiceAreaLookup{
Address: models.Address{PostalCode: serviceAreaPostalCode},
Expand All @@ -462,8 +462,8 @@ func MapPPMShipmentEstimatedFields(ppmShipment models.PPMShipment) models.MTOShi

ppmShipment.Shipment.ActualPickupDate = &ppmShipment.ExpectedDepartureDate
ppmShipment.Shipment.RequestedPickupDate = &ppmShipment.ExpectedDepartureDate
ppmShipment.Shipment.PickupAddress = &models.Address{PostalCode: ppmShipment.PickupPostalCode}
ppmShipment.Shipment.DestinationAddress = &models.Address{PostalCode: ppmShipment.DestinationPostalCode}
ppmShipment.Shipment.PickupAddress = &models.Address{PostalCode: ppmShipment.PickupAddress.PostalCode}
ppmShipment.Shipment.DestinationAddress = &models.Address{PostalCode: ppmShipment.DestinationAddress.PostalCode}
ppmShipment.Shipment.PrimeActualWeight = ppmShipment.EstimatedWeight

return ppmShipment.Shipment
Expand Down
78 changes: 54 additions & 24 deletions pkg/services/ppmshipment/ppm_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
},
})

testdatagen.FetchOrMakeReZip3(suite.DB(), testdatagen.Assertions{
ReZip3: models.ReZip3{
Contract: originDomesticServiceArea.Contract,
ContractID: originDomesticServiceArea.ContractID,
DomesticServiceArea: originDomesticServiceArea,
Zip3: "503",
},
})

testdatagen.FetchOrMakeReZip3(suite.DB(), testdatagen.Assertions{
ReZip3: models.ReZip3{
Contract: originDomesticServiceArea.Contract,
Expand Down Expand Up @@ -488,16 +497,16 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {

// DTOD distance is going to be less than the HHG Rand McNally distance of 2361 miles
mockedPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813").Return(2294, nil)
"50309", "30813").Return(2294, nil)

ppmEstimate, _, err := ppmEstimator.EstimateIncentiveWithDefaultChecks(suite.AppContextForTest(), oldPPMShipment, &newPPM)
suite.NilOrNoVerrs(err)

mockedPlanner.AssertCalled(suite.T(), "ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813")
"50309", "30813")
mockedPaymentRequestHelper.AssertCalled(suite.T(), "FetchServiceParamsForServiceItems", mock.AnythingOfType("*appcontext.appContext"), mock.AnythingOfType("[]models.MTOServiceItem"))

suite.Equal(oldPPMShipment.PickupPostalCode, newPPM.PickupPostalCode)
suite.Equal(oldPPMShipment.PickupAddress.PostalCode, newPPM.PickupAddress.PostalCode)
suite.Equal(unit.Pound(5000), *newPPM.EstimatedWeight)
suite.Equal(unit.Cents(70064364), *ppmEstimate)
})
Expand All @@ -524,7 +533,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {

// DTOD distance is going to be less than the HHG Rand McNally distance of 2361 miles
mockedPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813").Return(2294, nil).Once()
"50309", "30813").Return(2294, nil).Once()

ppmEstimate, _, err := ppmEstimator.EstimateIncentiveWithDefaultChecks(suite.AppContextForTest(), oldPPMShipment, &newPPM)
suite.NilOrNoVerrs(err)
Expand All @@ -547,9 +556,9 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {

estimatedIncentive, _, err := ppmEstimator.EstimateIncentiveWithDefaultChecks(suite.AppContextForTest(), oldPPMShipment, &newPPM)
suite.NilOrNoVerrs(err)
suite.Equal(oldPPMShipment.PickupPostalCode, newPPM.PickupPostalCode)
suite.Equal(oldPPMShipment.PickupAddress.PostalCode, newPPM.PickupAddress.PostalCode)
suite.Equal(*oldPPMShipment.EstimatedWeight, *newPPM.EstimatedWeight)
suite.Equal(oldPPMShipment.DestinationPostalCode, newPPM.DestinationPostalCode)
suite.Equal(oldPPMShipment.DestinationAddress.PostalCode, newPPM.DestinationAddress.PostalCode)
suite.True(oldPPMShipment.ExpectedDepartureDate.Equal(newPPM.ExpectedDepartureDate))
suite.Equal(*oldPPMShipment.EstimatedIncentive, *estimatedIncentive)
suite.Equal(models.BoolPointer(true), newPPM.HasRequestedAdvance)
Expand All @@ -564,13 +573,16 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
},
},
}, nil)

pickupAddress := models.Address{PostalCode: oldPPMShipment.PickupAddress.PostalCode}
destinationAddress := models.Address{PostalCode: "94040"}
newPPM := models.PPMShipment{
ID: uuid.FromStringOrNil("575c25aa-b4eb-4024-9597-43483003c773"),
ShipmentID: oldPPMShipment.ShipmentID,
Status: models.PPMShipmentStatusCloseoutComplete,
ExpectedDepartureDate: oldPPMShipment.ExpectedDepartureDate,
PickupPostalCode: oldPPMShipment.PickupPostalCode,
DestinationPostalCode: "94040",
PickupAddress: &pickupAddress,
DestinationAddress: &destinationAddress,
EstimatedWeight: oldPPMShipment.EstimatedWeight,
SITExpected: oldPPMShipment.SITExpected,
EstimatedIncentive: models.CentPointer(unit.Cents(600000)),
Expand All @@ -585,7 +597,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
oldPPMShipment := factory.BuildMinimalPPMShipment(suite.DB(), nil, nil)

newPPM := oldPPMShipment
newPPM.DestinationPostalCode = "94040"
newPPM.DestinationAddress.PostalCode = "94040"
_, _, err := ppmEstimator.EstimateIncentiveWithDefaultChecks(suite.AppContextForTest(), oldPPMShipment, &newPPM)
suite.NoError(err)
suite.Nil(newPPM.EstimatedIncentive)
Expand All @@ -600,7 +612,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
oldPPMShipment := factory.BuildPPMShipment(suite.DB(), []factory.Customization{
{
Model: models.PPMShipment{
ActualPickupPostalCode: models.StringPointer("90210"),
ActualPickupPostalCode: models.StringPointer("50309"),
ActualDestinationPostalCode: models.StringPointer("30813"),
ActualMoveDate: models.TimePointer(actualMoveDate),
Status: models.PPMShipmentStatusWaitingOnCustomer,
Expand Down Expand Up @@ -629,13 +641,13 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {

// DTOD distance is going to be less than the HHG Rand McNally distance of 2361 miles
mockedPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813").Return(2294, nil)
"50309", "30813").Return(2294, nil)

ppmFinal, err := ppmEstimator.FinalIncentiveWithDefaultChecks(suite.AppContextForTest(), oldPPMShipment, &newPPM)
suite.NilOrNoVerrs(err)

mockedPlanner.AssertCalled(suite.T(), "ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813")
"50309", "30813")
mockedPaymentRequestHelper.AssertCalled(suite.T(), "FetchServiceParamsForServiceItems", mock.AnythingOfType("*appcontext.appContext"), mock.AnythingOfType("[]models.MTOServiceItem"))

suite.Equal(oldPPMShipment.ActualPickupPostalCode, newPPM.ActualPickupPostalCode)
Expand All @@ -652,7 +664,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
oldPPMShipment := factory.BuildPPMShipment(suite.DB(), []factory.Customization{
{
Model: models.PPMShipment{
ActualPickupPostalCode: models.StringPointer("90210"),
ActualPickupPostalCode: models.StringPointer("50309"),
ActualDestinationPostalCode: models.StringPointer("30813"),
ActualMoveDate: models.TimePointer(moveDate),
Status: models.PPMShipmentStatusWaitingOnCustomer,
Expand Down Expand Up @@ -683,13 +695,13 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {

// DTOD distance is going to be less than the HHG Rand McNally distance of 2361 miles
mockedPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813").Return(2294, nil)
"50309", "30813").Return(2294, nil)

ppmFinal, err := ppmEstimator.FinalIncentiveWithDefaultChecks(suite.AppContextForTest(), oldPPMShipment, &newPPM)
suite.NilOrNoVerrs(err)

mockedPlanner.AssertCalled(suite.T(), "ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813")
"50309", "30813")
mockedPaymentRequestHelper.AssertCalled(suite.T(), "FetchServiceParamsForServiceItems", mock.AnythingOfType("*appcontext.appContext"), mock.AnythingOfType("[]models.MTOServiceItem"))

suite.Equal(oldPPMShipment.ActualPickupPostalCode, newPPM.ActualPickupPostalCode)
Expand All @@ -708,7 +720,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
oldPPMShipment := factory.BuildPPMShipmentThatNeedsCloseout(suite.DB(), nil, []factory.Customization{
{
Model: models.PPMShipment{
ActualPickupPostalCode: models.StringPointer("90210"),
ActualPickupPostalCode: models.StringPointer("50309"),
ActualDestinationPostalCode: models.StringPointer("30813"),
ActualMoveDate: models.TimePointer(moveDate),
},
Expand Down Expand Up @@ -740,13 +752,13 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {

// DTOD distance is going to be less than the HHG Rand McNally distance of 2361 miles
mockedPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813").Return(2294, nil)
"50309", "30813").Return(2294, nil)

ppmFinal, err := ppmEstimator.FinalIncentiveWithDefaultChecks(suite.AppContextForTest(), oldPPMShipment, &newPPM)
suite.NilOrNoVerrs(err)

mockedPlanner.AssertCalled(suite.T(), "ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813")
"50309", "30813")
mockedPaymentRequestHelper.AssertCalled(suite.T(), "FetchServiceParamsForServiceItems", mock.AnythingOfType("*appcontext.appContext"), mock.AnythingOfType("[]models.MTOServiceItem"))

originalWeight, newWeight := SumWeightTickets(oldPPMShipment, newPPM)
Expand Down Expand Up @@ -1349,6 +1361,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
},
},
}, nil)

shipmentOriginSIT := factory.BuildPPMShipment(nil, []factory.Customization{
{
Model: models.PPMShipment{
Expand All @@ -1367,7 +1380,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
}, nil)

mockedPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813").Return(2294, nil)
"50309", "30813").Return(2294, nil)

_, estimatedSITCost, err := ppmEstimator.EstimateIncentiveWithDefaultChecks(suite.AppContextForTest(), models.PPMShipment{}, &shipmentOriginSIT)

Expand Down Expand Up @@ -1406,7 +1419,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
}, nil)

mockedPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813").Return(2294, nil)
"50309", "30813").Return(2294, nil)

_, estimatedSITCost, err := ppmEstimator.EstimateIncentiveWithDefaultChecks(suite.AppContextForTest(), models.PPMShipment{}, &shipmentOriginSIT)

Expand All @@ -1427,6 +1440,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
},
},
}, nil)

shipmentOriginSIT := factory.BuildPPMShipment(nil, []factory.Customization{
{
Model: models.PPMShipment{
Expand All @@ -1444,7 +1458,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
},
}, nil)
mockedPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30813").Return(2294, nil)
"50309", "30813").Return(2294, nil)

_, estimatedSITCost, err := ppmEstimator.EstimateIncentiveWithDefaultChecks(suite.AppContextForTest(), models.PPMShipment{}, &shipmentOriginSIT)

Expand Down Expand Up @@ -1591,10 +1605,26 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
}, nil)
// PPM base shipment field changes will affect SIT pricing
shipmentDifferentPickup := originalShipment
shipmentDifferentPickup.PickupPostalCode = "90211"
pickupAddress := models.Address{
StreetAddress1: originalShipment.PickupAddress.StreetAddress1,
StreetAddress2: originalShipment.PickupAddress.StreetAddress2,
StreetAddress3: originalShipment.PickupAddress.StreetAddress3,
City: originalShipment.PickupAddress.City,
State: originalShipment.PickupAddress.State,
PostalCode: "90211",
}
shipmentDifferentPickup.PickupAddress = &pickupAddress

shipmentDifferentDestination := originalShipment
shipmentDifferentDestination.DestinationPostalCode = "30814"
destinationAddress := models.Address{
StreetAddress1: originalShipment.PickupAddress.StreetAddress1,
StreetAddress2: originalShipment.PickupAddress.StreetAddress2,
StreetAddress3: originalShipment.PickupAddress.StreetAddress3,
City: originalShipment.PickupAddress.City,
State: originalShipment.PickupAddress.State,
PostalCode: "30814",
}
shipmentDifferentDestination.DestinationAddress = &destinationAddress

shipmentDifferentDeparture := originalShipment
// original date was Mar 15th so adding 3 months should affect the date peak period pricing
Expand All @@ -1604,7 +1634,7 @@ func (suite *PPMShipmentSuite) TestPPMEstimator() {
"90211", "30813").Return(2294, nil)

mockedPlanner.On("ZipTransitDistance", mock.AnythingOfType("*appcontext.appContext"),
"90210", "30814").Return(2290, nil)
"50309", "30814").Return(2290, nil)

// SIT specific field changes will likely cause the price to change, although adjusting dates may not change
// the total number of days in SIT.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import React from 'react';

import styles from 'components/Customer/PPM/Booking/EstimatedIncentiveDetails/EstimatedIncentiveDetails.module.scss';
import { ShipmentShape } from 'types/shipment';
import { formatAddress } from 'utils/shipmentDisplay';
import { formatCentsTruncateWhole, formatCustomerDate, formatWeight } from 'utils/formatters';

const EstimatedIncentiveDetails = ({ shipment }) => {
const {
estimatedWeight,
pickupPostalCode,
secondaryPickupPostalCode,
destinationPostalCode,
secondaryDestinationPostalCode,
pickupAddress,
hasSecondaryPickupAddress,
secondaryPickupAddress,
destinationAddress,
hasSecondaryDestinationAddress,
secondaryDestinationAddress,
expectedDepartureDate,
estimatedIncentive,
} = shipment?.ppmShipment || {};
Expand All @@ -23,10 +26,12 @@ const EstimatedIncentiveDetails = ({ shipment }) => {
<p>This is an estimate of how much you could earn by moving your PPM, based on what you have entered:</p>
<ul>
<li>{formatWeight(estimatedWeight)} estimated weight</li>
<li>Starting from {pickupPostalCode}</li>
{secondaryPickupPostalCode && <li>Picking up things in {secondaryPickupPostalCode}</li>}
{secondaryDestinationPostalCode && <li>Dropping off things in {secondaryDestinationPostalCode}</li>}
<li>Ending in {destinationPostalCode}</li>
<li>Starting from {formatAddress(pickupAddress)}</li>
{hasSecondaryPickupAddress && <li>Picking up things at {formatAddress(secondaryPickupAddress)}</li>}
{hasSecondaryDestinationAddress && (
<li>Dropping off things at {formatAddress(secondaryDestinationAddress)}</li>
)}
<li>Ending at {formatAddress(destinationAddress)}</li>
<li>Starting your PPM on {formatCustomerDate(expectedDepartureDate)}</li>
</ul>
</div>
Expand Down
Loading

0 comments on commit b2dcb60

Please sign in to comment.