Skip to content

Commit

Permalink
Merge pull request #13972 from transcom/B-21522-MAIN
Browse files Browse the repository at this point in the history
B 21522 main
  • Loading branch information
deandreJones authored Oct 22, 2024
2 parents 36b5a8f + 8285f1a commit 7da3f7e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
28 changes: 26 additions & 2 deletions pkg/services/invoice/ghc_payment_request_invoice_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (g ghcPaymentRequestInvoiceGenerator) createG62Segments(appCtx appcontext.A
return nil
}

func (g ghcPaymentRequestInvoiceGenerator) createBuyerAndSellerOrganizationNamesSegments(appCtx appcontext.AppContext, _ uuid.UUID, orders models.Order, header *ediinvoice.InvoiceHeader) error {
func (g ghcPaymentRequestInvoiceGenerator) createBuyerAndSellerOrganizationNamesSegments(appCtx appcontext.AppContext, paymentRequestID uuid.UUID, orders models.Order, header *ediinvoice.InvoiceHeader) error {
var err error
var originDutyLocation models.DutyLocation
if orders.OriginDutyLocationID != nil && *orders.OriginDutyLocationID != uuid.Nil {
Expand All @@ -428,11 +428,35 @@ func (g ghcPaymentRequestInvoiceGenerator) createBuyerAndSellerOrganizationNames
return apperror.NewConflictError(orders.ID, "Invalid Order, must have OriginDutyLocation")
}

var address models.Address
err = appCtx.DB().Q().
Select("addresses.*").
Join("mto_shipments", "addresses.id = mto_shipments.pickup_address_id").
Join("moves", "mto_shipments.move_id = moves.id").
Join("mto_service_items", "mto_service_items.move_id = moves.id").
Join("payment_service_items", "payment_service_items.mto_service_item_id = mto_service_items.id").
Where("payment_service_items.payment_request_id = ?", paymentRequestID).
Order("mto_shipments.created_at").
First(&address)

if err != nil {
switch err {
case sql.ErrNoRows:
return apperror.NewNotFoundError(paymentRequestID, "for mto shipments associated with PaymentRequest")
default:
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")
}

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

// seller organization name
Expand Down
19 changes: 17 additions & 2 deletions pkg/services/invoice/ghc_payment_request_invoice_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,16 +874,31 @@ func (suite *GHCInvoiceSuite) TestAllGenerateEdi() {

suite.Run("adds buyer and seller organization name", func() {
setupTestData(nil, nil, nil, nil)
mtoShipment := factory.BuildMTOShipment(suite.DB(), []factory.Customization{
{
Model: mto,
LinkOnly: true,
},
{
Model: models.MTOShipment{
RequestedPickupDate: &requestedPickupDate,
ScheduledPickupDate: &scheduledPickupDate,
ActualPickupDate: &actualPickupDate,
},
},
}, nil)
// buyer name
pickupGbloc, err1 := models.FetchGBLOCForPostalCode(suite.DB(), mtoShipment.PickupAddress.PostalCode)

suite.FatalNoError(err1)
originDutyLocation := paymentRequest.MoveTaskOrder.Orders.OriginDutyLocation
buyerOrg := result.Header.BuyerOrganizationName
originDutyLocationGbloc := paymentRequest.MoveTaskOrder.Orders.OriginDutyLocationGBLOC
suite.IsType(edisegment.N1{}, buyerOrg)
suite.Equal("BY", buyerOrg.EntityIdentifierCode)
truncatedOriginDutyLocationName := truncateStr(*models.StringPointer(originDutyLocation.Name), 60)
suite.Equal(truncatedOriginDutyLocationName, buyerOrg.Name)
suite.Equal("92", buyerOrg.IdentificationCodeQualifier)
suite.Equal(*originDutyLocationGbloc, buyerOrg.IdentificationCode)
suite.Equal(pickupGbloc.GBLOC, buyerOrg.IdentificationCode)

sellerOrg := result.Header.SellerOrganizationName
suite.IsType(edisegment.N1{}, sellerOrg)
Expand Down

0 comments on commit 7da3f7e

Please sign in to comment.