Skip to content

Commit

Permalink
more oconus updates for gbloc
Browse files Browse the repository at this point in the history
  • Loading branch information
pambecker committed Jan 20, 2025
1 parent db3f97b commit 3ead62a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 86 deletions.
27 changes: 0 additions & 27 deletions pkg/models/mto_shipments.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,33 +277,6 @@ func GetCustomerFromShipment(db *pop.Connection, shipmentID uuid.UUID) (*Service
return &serviceMember, nil
}

func (m *MTOShipment) UpdateOrdersDestinationGBLOC(db *pop.Connection) error {
// Since this requires looking up the order in the DB, the order must have an ID. This means, the order has to have been created first.
if uuid.UUID.IsNil(m.ID) {
return fmt.Errorf("error updating orders destination GBLOC for shipment due to no shipment ID provided")
}

var err error
var order Order

err = db.Load(&m, "MoveTaskOrder.OrdersID")
if err != nil {
return fmt.Errorf("error loading orders for shipment ID: %s with error %w", m.ID, err)
}

order, err = FetchOrder(db, m.MoveTaskOrder.OrdersID)
if err != nil {
return fmt.Errorf("error fetching order for shipment ID: %s with error %w", m.ID, err)
}

err = order.UpdateDestinationGBLOC(db)
if err != nil {
return fmt.Errorf("error fetching GBLOC for postal code with error %w", err)
}

return nil
}

// Helper function to check that an MTO Shipment contains a PPM Shipment
func (m MTOShipment) ContainsAPPMShipment() bool {
return m.PPMShipment != nil
Expand Down
40 changes: 0 additions & 40 deletions pkg/models/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,46 +492,6 @@ func (o Order) GetDestinationAddressForAssociatedMoves(db *pop.Connection) (*Add
return &destinationAddress, nil
}

// UpdateDestinationGBLOC updates the destination GBLOC for the associated Order in the DB
func (o Order) UpdateDestinationGBLOC(db *pop.Connection) error {
// Since this requires looking up the order in the DB, the order must have an ID. This means, the order has to have been created first.
if uuid.UUID.IsNil(o.ID) {
return errors.WithMessage(ErrInvalidOrderID, "You must created the order in the DB before updating the destination GBLOC.")
}

var dbOrder Order
err := db.Find(&dbOrder, o.ID)
if err != nil {
if err.Error() == RecordNotFoundErrorString {
return errors.WithMessage(err, "No Order was found for the order ID "+o.ID.String())
}
return err
}

err = db.Load(&o, "NewDutyLocation.Address.PostalCode")
if err != nil {
if err.Error() == RecordNotFoundErrorString {
return errors.WithMessage(err, "No New Duty Location Address Postal Code was found for the order ID "+o.ID.String())
}
return err
}

var gblocResult PostalCodeToGBLOC
gblocResult, err = FetchGBLOCForPostalCode(db, o.NewDutyLocation.Address.PostalCode)
if err != nil {
return errors.WithMessage(err, "Could not get GBLOC for postal code "+o.NewDutyLocation.Address.PostalCode)
}

dbOrder.DestinationGBLOC = &gblocResult.GBLOC

err = db.Save(&dbOrder)
if err != nil {
return errors.WithMessage(err, "Could not save the updated destination GBLOC for order ID "+o.ID.String())
}

return nil
}

// IsCompleteForGBL checks if orders have all fields necessary to generate a GBL
func (o *Order) IsCompleteForGBL() bool {

Expand Down
18 changes: 14 additions & 4 deletions pkg/services/invoice/ghc_payment_request_invoice_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,16 +447,26 @@ func (g ghcPaymentRequestInvoiceGenerator) createBuyerAndSellerOrganizationNames
return apperror.NewQueryError("MTOShipments", err, fmt.Sprintf("error querying for shipments pickup address gbloc to use in N1*BY segments in PaymentRequest %s: %s", paymentRequestID, err))
}
}
pickupPostalCodeToGbloc, gblocErr := models.FetchGBLOCForPostalCode(appCtx.DB(), address.PostalCode)
if gblocErr != nil {
return apperror.NewInvalidInputError(pickupPostalCodeToGbloc.ID, gblocErr, nil, "unable to determine GBLOC for pickup postal code")
var pickupPostalCodeToGbloc *string
if *address.IsOconus {
originDutyLocationGBLOCOconus, gblocErr := models.FetchAddressGbloc(appCtx.DB(), address, orders.ServiceMember)
if gblocErr != nil {
return apperror.NewInvalidInputError(address.ID, gblocErr, nil, "unable to determine GBLOC for Oconus pickup postal code")
}
pickupPostalCodeToGbloc = originDutyLocationGBLOCOconus
} else {
originDutyLocationGBLOCConus, gblocErr := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode)
if gblocErr != nil {
return apperror.NewInvalidInputError(address.ID, gblocErr, nil, "unable to determine GBLOC for pickup postal code")
}
pickupPostalCodeToGbloc = &originDutyLocationGBLOCConus.GBLOC
}

header.BuyerOrganizationName = edisegment.N1{
EntityIdentifierCode: "BY",
Name: truncateStr(originDutyLocation.Name, maxLocationlength),
IdentificationCodeQualifier: "92",
IdentificationCode: modifyGblocIfMarines(*orders.ServiceMember.Affiliation, pickupPostalCodeToGbloc.GBLOC),
IdentificationCode: modifyGblocIfMarines(*orders.ServiceMember.Affiliation, *pickupPostalCodeToGbloc),
}

// seller organization name
Expand Down
22 changes: 16 additions & 6 deletions pkg/services/move_task_order/move_task_order_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,23 @@ func (f moveTaskOrderFetcher) FetchMoveTaskOrder(appCtx appcontext.AppContext, s
mto.MTOServiceItems = loadedServiceItems

if mto.Orders.DestinationGBLOC == nil {
newDutyLocationGBLOC, err := models.FetchGBLOCForPostalCode(appCtx.DB(), mto.Orders.NewDutyLocation.Address.PostalCode)
if err != nil {
err = apperror.NewBadDataError("New duty location GBLOC cannot be verified")
appCtx.Logger().Error(err.Error())
return &models.Move{}, apperror.NewQueryError("DestinationGBLOC", err, "")
var newDutyLocationGBLOC *string
if *mto.Orders.NewDutyLocation.Address.IsOconus {
newDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), mto.Orders.NewDutyLocation.Address, mto.Orders.ServiceMember)
if err != nil {
return nil, apperror.NewNotFoundError(mto.Orders.NewDutyLocation.ID, "while looking for Duty Location Oconus GBLOC")
}
newDutyLocationGBLOC = newDutyLocationGBLOCOconus
} else {
newDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), mto.Orders.NewDutyLocation.Address.PostalCode)
if err != nil {
err = apperror.NewBadDataError("New duty location GBLOC cannot be verified")
appCtx.Logger().Error(err.Error())
return &models.Move{}, apperror.NewQueryError("DestinationGBLOC", err, "")
}
newDutyLocationGBLOC = &newDutyLocationGBLOCConus.GBLOC
}
mto.Orders.DestinationGBLOC = &newDutyLocationGBLOC.GBLOC
mto.Orders.DestinationGBLOC = newDutyLocationGBLOC
}

return mto, nil
Expand Down
28 changes: 19 additions & 9 deletions pkg/services/support/move_task_order/move_task_order_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,27 @@ func createOrder(appCtx appcontext.AppContext, customer *models.ServiceMember, o
order.OriginDutyLocation = originDutyLocation
order.OriginDutyLocationID = &originDutyLocationID

var originDutyLocationGBLOC models.PostalCodeToGBLOC
originDutyLocationGBLOC, err = models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode)
if err != nil {
switch err {
case sql.ErrNoRows:
return nil, apperror.NewNotFoundError(originDutyLocationID, "while looking for Duty Location PostalCodeToGBLOC")
default:
return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "")
var originDutyLocationGBLOC *string
if *originDutyLocation.Address.IsOconus {
originDutyLocationGBLOCOconus, err := models.FetchAddressGbloc(appCtx.DB(), originDutyLocation.Address, order.ServiceMember)
if err != nil {
return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location Oconus GBLOC")
}
originDutyLocationGBLOC = originDutyLocationGBLOCOconus
} else {
originDutyLocationGBLOCConus, err := models.FetchGBLOCForPostalCode(appCtx.DB(), originDutyLocation.Address.PostalCode)
if err != nil {
switch err {
case sql.ErrNoRows:
return nil, apperror.NewNotFoundError(originDutyLocation.ID, "while looking for Duty Location PostalCodeToGBLOC")
default:
return nil, apperror.NewQueryError("PostalCodeToGBLOC", err, "")
}
}
originDutyLocationGBLOC = &originDutyLocationGBLOCConus.GBLOC
}
order.OriginDutyLocationGBLOC = &originDutyLocationGBLOC.GBLOC

order.OriginDutyLocationGBLOC = originDutyLocationGBLOC
}
// Check that the uploaded orders document exists
var uploadedOrders *models.Document
Expand Down

0 comments on commit 3ead62a

Please sign in to comment.