Skip to content

Commit

Permalink
Merge branch 'main' into INT-amw-B19763-Linehaul-FSC-Payment-When-Des…
Browse files Browse the repository at this point in the history
…tination-SIT-TOO-Work
  • Loading branch information
WeatherfordAaron committed May 10, 2024
2 parents 825f61f + 29fc583 commit c70fcb3
Showing 1 changed file with 9 additions and 43 deletions.
52 changes: 9 additions & 43 deletions pkg/services/mto_shipment/mto_shipment_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mtoshipment
import (
"database/sql"
"fmt"
"math"
"time"

"github.com/gobuffalo/validate/v3"
Expand Down Expand Up @@ -609,26 +608,18 @@ func (f *mtoShipmentUpdater) updateShipmentRecord(appCtx appcontext.AppContext,
}
}

// If the estimated weight was updated on an approved shipment then it would mean the move could qualify for
// excess weight risk depending on the weight allowance and other shipment estimated weights
if newShipment.PrimeEstimatedWeight != nil {
move, verrs, err := f.moveWeights.CheckExcessWeight(txnAppCtx, dbShipment.MoveTaskOrderID, *newShipment)
if verrs != nil && verrs.HasAny() {
return errors.New(verrs.Error())
}
if err != nil {
return err
}

// updates to prime estimated weight should change the authorized weight of the entitlement
// which can be manually adjusted by an office user if needed
err = updateAuthorizedWeight(appCtx, newShipment, move)
if err != nil {
return err
}

// If the estimated weight was updated on an approved shipment then it would mean the move could qualify for
// excess weight risk depending on the weight allowance and other shipment estimated weights
if dbShipment.PrimeEstimatedWeight == nil || *newShipment.PrimeEstimatedWeight != *dbShipment.PrimeEstimatedWeight {
// checking if the total of shipment weight & new prime estimated weight is 90% or more of allowed weight
move, verrs, err := f.moveWeights.CheckExcessWeight(txnAppCtx, dbShipment.MoveTaskOrderID, *newShipment)
if verrs != nil && verrs.HasAny() {
return errors.New(verrs.Error())
}
if err != nil {
return err
}

existingMoveStatus := move.Status
// if the move is in excess weight risk and the TOO has not acknowledge that, need to change move status to "Approvals Requested"
Expand Down Expand Up @@ -1216,28 +1207,3 @@ func UpdateDestinationSITServiceItemsSITDeliveryMiles(planner route.Planner, app

return nil
}

func updateAuthorizedWeight(appCtx appcontext.AppContext, shipment *models.MTOShipment, move *models.Move) error {
dBAuthorizedWeight := int(*shipment.PrimeEstimatedWeight)
if len(move.MTOShipments) != 0 {
for _, mtoShipment := range move.MTOShipments {
if mtoShipment.PrimeEstimatedWeight != nil && mtoShipment.Status == models.MTOShipmentStatusApproved {
dBAuthorizedWeight += int(*mtoShipment.PrimeEstimatedWeight)
}
}
}
dBAuthorizedWeight = int(math.Round(float64(dBAuthorizedWeight) * 1.10))
entitlement := move.Orders.Entitlement
entitlement.DBAuthorizedWeight = &dBAuthorizedWeight
verrs, err := appCtx.DB().ValidateAndUpdate(entitlement)

if verrs != nil && verrs.HasAny() {
invalidInputError := apperror.NewInvalidInputError(shipment.ID, nil, verrs, "There was an issue with validating the updates")
return invalidInputError
}
if err != nil {
return err
}

return nil
}

0 comments on commit c70fcb3

Please sign in to comment.