Skip to content

Commit

Permalink
some minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljordan-caci committed Jan 20, 2025
1 parent 2d64f35 commit 4ef9c36
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ INSERT INTO service_params (id,service_id,service_item_param_key_id,created_at,u
DELETE FROM service_params
WHERE service_item_param_key_id = '6d44624c-b91b-4226-8fcd-98046e2f433d';

DELETE FROM service_item_param_keys
WHERE key = 'PriceAreaIntlOrigin';

-- remove PriceAreaIntlDest, we don't need it
DELETE FROM service_params
WHERE service_item_param_key_id = '4736f489-dfda-4df1-a303-8c434a120d5d';

DELETE FROM service_item_param_keys
WHERE key = 'PriceAreaIntlDest';

-- func to fetch a service id from re_services by providing the service code
CREATE OR REPLACE FUNCTION get_service_id(service_code TEXT) RETURNS UUID AS $$
DECLARE
Expand Down
6 changes: 3 additions & 3 deletions pkg/models/ppm_shipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func FetchPPMShipmentByPPMShipmentID(db *pop.Connection, ppmShipmentID uuid.UUID
return &ppmShipment, nil
}

type PPMIncentive struct {
type PPMIncentiveOCONUS struct {
TotalIncentive int `db:"total_incentive"`
PriceISLH int `db:"price_islh"`
PriceIHPK int `db:"price_ihpk"`
Expand All @@ -334,8 +334,8 @@ type PPMIncentive struct {

// a db function that will handle updating the estimated_incentive value
// this simulates pricing of a basic iHHG shipment with ISLH, IHPK, IHUPK, and the CONUS portion for a FSC
func CalculatePPMIncentive(db *pop.Connection, ppmID uuid.UUID, pickupAddressID uuid.UUID, destAddressID uuid.UUID, moveDate time.Time, mileage int, weight int, isEstimated bool, isActual bool, isMax bool) (*PPMIncentive, error) {
var incentive PPMIncentive
func CalculatePPMIncentive(db *pop.Connection, ppmID uuid.UUID, pickupAddressID uuid.UUID, destAddressID uuid.UUID, moveDate time.Time, mileage int, weight int, isEstimated bool, isActual bool, isMax bool) (*PPMIncentiveOCONUS, error) {
var incentive PPMIncentiveOCONUS

err := db.RawQuery("SELECT * FROM calculate_ppm_incentive($1, $2, $3, $4, $5, $6, $7, $8, $9)", ppmID, pickupAddressID, destAddressID, moveDate, mileage, weight, isEstimated, isActual, isMax).
First(&incentive)
Expand Down
63 changes: 7 additions & 56 deletions pkg/services/ppm_closeout/ppm_closeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,53 +255,6 @@ func (p *ppmCloseoutFetcher) GetExpenseStoragePrice(appCtx appcontext.AppContext
return storageExpensePrice, err
}

func (p *ppmCloseoutFetcher) GetEntitlement(appCtx appcontext.AppContext, moveID uuid.UUID) (*models.Entitlement, error) {
var moveModel models.Move
err := appCtx.DB().EagerPreload(
"OrdersID",
).Find(&moveModel, moveID)

if err != nil {
switch err {
case sql.ErrNoRows:
return nil, apperror.NewNotFoundError(moveID, "while looking for Move")
default:
return nil, apperror.NewQueryError("Move", err, "unable to find Move")
}
}

var order models.Order
orderID := &moveModel.OrdersID
errOrder := appCtx.DB().EagerPreload(
"EntitlementID",
).Find(&order, orderID)

if errOrder != nil {
switch errOrder {
case sql.ErrNoRows:
return nil, apperror.NewNotFoundError(*orderID, "while looking for Order")
default:
return nil, apperror.NewQueryError("Order", errOrder, "unable to find Order")
}
}

var entitlement models.Entitlement
entitlementID := order.EntitlementID
errEntitlement := appCtx.DB().EagerPreload(
"DBAuthorizedWeight",
).Find(&entitlement, entitlementID)

if errEntitlement != nil {
switch errEntitlement {
case sql.ErrNoRows:
return nil, apperror.NewNotFoundError(*entitlementID, "while looking for Entitlement")
default:
return nil, apperror.NewQueryError("Entitlement", errEntitlement, "unable to find Entitlement")
}
}
return &entitlement, nil
}

func paramsForServiceCode(code models.ReServiceCode, serviceParams models.ServiceParams) models.ServiceParams {
var serviceItemParams models.ServiceParams
for _, serviceParam := range serviceParams {
Expand All @@ -318,17 +271,12 @@ func (p *ppmCloseoutFetcher) getServiceItemPrices(appCtx appcontext.AppContext,
var returnPriceObj serviceItemPrices
logger := appCtx.Logger()

err := appCtx.DB().Where("mto_shipment_id = ?", ppmShipment.ShipmentID).All(&serviceItemsToPrice)
if err != nil {
return serviceItemPrices{}, err
}

isInternationalShipment := ppmShipment.Shipment.MarketCode == models.MarketCodeInternational
serviceItemsToPrice = ppmshipment.BaseServiceItems(ppmShipment)

actualPickupPostal := *ppmShipment.ActualPickupPostalCode
actualDestPostal := *ppmShipment.ActualDestinationPostalCode
// Change DLH to DSH if move within same Zip3
// Change DLH to DSH if move within same Zip3 (only for domestic shipments - intl uses ISLH)
if !isInternationalShipment && actualPickupPostal[0:3] == actualDestPostal[0:3] {
serviceItemsToPrice[0] = models.MTOServiceItem{ReService: models.ReService{Code: models.ReServiceCodeDSH}, MTOShipmentID: &ppmShipment.ShipmentID}
}
Expand All @@ -342,10 +290,12 @@ func (p *ppmCloseoutFetcher) getServiceItemPrices(appCtx appcontext.AppContext,
if paramErr != nil {
return serviceItemPrices{}, paramErr
}

var totalPrice, packPrice, unpackPrice, destinationPrice, originPrice, haulPrice, haulFSC, intlPackPrice, intlUnpackPrice, intlLinehaulPrice unit.Cents
var totalWeight unit.Pound
var ppmToMtoShipment models.MTOShipment

// adding all the weight tickets together to get the total weight of the moved PPM
if len(ppmShipment.WeightTickets) >= 1 {
for _, weightTicket := range ppmShipment.WeightTickets {
if weightTicket.Status != nil && *weightTicket.Status == models.PPMDocumentStatusRejected {
Expand Down Expand Up @@ -380,6 +330,7 @@ func (p *ppmCloseoutFetcher) getServiceItemPrices(appCtx appcontext.AppContext,
return serviceItemPrices{}, err
}

// combo of domestic & int'l service items
validCodes := map[models.ReServiceCode]string{
models.ReServiceCodeDPK: "DPK",
models.ReServiceCodeDUPK: "DUPK",
Expand Down Expand Up @@ -462,11 +413,11 @@ func (p *ppmCloseoutFetcher) getServiceItemPrices(appCtx appcontext.AppContext,
totalPrice = totalPrice.AddCents(centsValue)

switch serviceItem.ReService.Code {
case models.ReServiceCodeIHPK:
case models.ReServiceCodeIHPK: // Int'l pack
intlPackPrice += centsValue
case models.ReServiceCodeIHUPK:
case models.ReServiceCodeIHUPK: // Int'l unpack
intlUnpackPrice += centsValue
case models.ReServiceCodeISLH:
case models.ReServiceCodeISLH: // Int'l shipping & linehaul
intlLinehaulPrice += centsValue
case models.ReServiceCodeDPK:
packPrice += centsValue
Expand Down
12 changes: 6 additions & 6 deletions pkg/services/ppmshipment/ppm_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (f *estimatePPM) estimateIncentive(appCtx appcontext.AppContext, oldPPMShip
newPPMShipment.HasRequestedAdvance = nil
newPPMShipment.AdvanceAmountRequested = nil

estimatedIncentive, err = f.calculateOCONUSIncentive(appCtx, newPPMShipment.ID, *pickupAddress, *destinationAddress, contractDate, newPPMShipment.EstimatedWeight.Int(), false, false, true)
estimatedIncentive, err = f.CalculateOCONUSIncentive(appCtx, newPPMShipment.ID, *pickupAddress, *destinationAddress, contractDate, newPPMShipment.EstimatedWeight.Int(), false, false, true)
if err != nil {
return nil, nil, fmt.Errorf("failed to calculate estimated PPM incentive: %w", err)
}
Expand All @@ -274,7 +274,7 @@ func (f *estimatePPM) estimateIncentive(appCtx appcontext.AppContext, oldPPMShip
return estimatedIncentive, estimatedSITCost, nil
}
daysInSIT := additionalDaysInSIT(*newPPMShipment.SITEstimatedEntryDate, *newPPMShipment.SITEstimatedDepartureDate)
estimatedSITCost, err = f.calculateOCONUSSITCosts(appCtx, newPPMShipment.ID, sitAddress.ID, isOrigin, contractDate, newPPMShipment.EstimatedWeight.Int(), daysInSIT)
estimatedSITCost, err = f.CalculateOCONUSSITCosts(appCtx, newPPMShipment.ID, sitAddress.ID, isOrigin, contractDate, newPPMShipment.EstimatedWeight.Int(), daysInSIT)
if err != nil {
return nil, nil, fmt.Errorf("failed to calculate estimated PPM incentive: %w", err)
}
Expand Down Expand Up @@ -330,7 +330,7 @@ func (f *estimatePPM) maxIncentive(appCtx appcontext.AppContext, oldPPMShipment
pickupAddress := orders.OriginDutyLocation.Address
destinationAddress := orders.NewDutyLocation.Address

maxIncentive, err := f.calculateOCONUSIncentive(appCtx, newPPMShipment.ID, pickupAddress, destinationAddress, contractDate, *orders.Entitlement.DBAuthorizedWeight, false, false, true)
maxIncentive, err := f.CalculateOCONUSIncentive(appCtx, newPPMShipment.ID, pickupAddress, destinationAddress, contractDate, *orders.Entitlement.DBAuthorizedWeight, false, false, true)
if err != nil {
return nil, fmt.Errorf("failed to calculate estimated PPM incentive: %w", err)
}
Expand Down Expand Up @@ -395,7 +395,7 @@ func (f *estimatePPM) finalIncentive(appCtx appcontext.AppContext, oldPPMShipmen

// we can't calculate actual incentive without the weight
if newTotalWeight != 0 {
finalIncentive, err := f.calculateOCONUSIncentive(appCtx, newPPMShipment.ID, *pickupAddress, *destinationAddress, contractDate, newTotalWeight.Int(), false, true, false)
finalIncentive, err := f.CalculateOCONUSIncentive(appCtx, newPPMShipment.ID, *pickupAddress, *destinationAddress, contractDate, newTotalWeight.Int(), false, true, false)
if err != nil {
return nil, fmt.Errorf("failed to calculate estimated PPM incentive: %w", err)
}
Expand Down Expand Up @@ -767,7 +767,7 @@ func (f estimatePPM) priceBreakdown(appCtx appcontext.AppContext, ppmShipment *m
// function for calculating incentives for OCONUS PPM shipments
// this uses a db function that takes in values needed to come up with the estimated/actual/max incentives
// this simulates the reimbursement for an iHHG move with ISLH, IHPK, IHUPK, and CONUS portion of FSC
func (f *estimatePPM) calculateOCONUSIncentive(appCtx appcontext.AppContext, ppmShipmentID uuid.UUID, pickupAddress models.Address, destinationAddress models.Address, moveDate time.Time, weight int, isEstimated bool, isActual bool, isMax bool) (*unit.Cents, error) {
func (f *estimatePPM) CalculateOCONUSIncentive(appCtx appcontext.AppContext, ppmShipmentID uuid.UUID, pickupAddress models.Address, destinationAddress models.Address, moveDate time.Time, weight int, isEstimated bool, isActual bool, isMax bool) (*unit.Cents, error) {
var mileage int
ppmPort, err := models.FetchPortLocationByCode(appCtx.DB(), "3002") // Tacoma, WA port
if err != nil {
Expand Down Expand Up @@ -807,7 +807,7 @@ func (f *estimatePPM) calculateOCONUSIncentive(appCtx appcontext.AppContext, ppm
return (*unit.Cents)(&incentive.TotalIncentive), nil
}

func (f *estimatePPM) calculateOCONUSSITCosts(appCtx appcontext.AppContext, ppmID uuid.UUID, addressID uuid.UUID, isOrigin bool, moveDate time.Time, weight int, sitDays int) (*unit.Cents, error) {
func (f *estimatePPM) CalculateOCONUSSITCosts(appCtx appcontext.AppContext, ppmID uuid.UUID, addressID uuid.UUID, isOrigin bool, moveDate time.Time, weight int, sitDays int) (*unit.Cents, error) {
if sitDays <= 0 {
return nil, fmt.Errorf("SIT days must be greater than zero")
}
Expand Down

0 comments on commit 4ef9c36

Please sign in to comment.