Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B 20967 sit panel main #13754

Merged
merged 17 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/handlers/ghcapi/mto_shipment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ func (suite *HandlerSuite) TestListMTOShipmentsHandler() {
suite.Equal(int64(190), *payloadShipment.SitDaysAllowance)
suite.Equal(sitstatus.OriginSITLocation, payloadShipment.SitStatus.CurrentSIT.Location)
suite.Equal(int64(8), *payloadShipment.SitStatus.CurrentSIT.DaysInSIT)
suite.Equal(int64(175), *payloadShipment.SitStatus.TotalDaysRemaining)
suite.Equal(int64(15), *payloadShipment.SitStatus.TotalSITDaysUsed) // 7 from the previous SIT and 7 from the current
suite.Equal(int64(15), *payloadShipment.SitStatus.CalculatedTotalDaysInSIT)
suite.Equal(int64(174), *payloadShipment.SitStatus.TotalDaysRemaining)
suite.Equal(int64(16), *payloadShipment.SitStatus.TotalSITDaysUsed) // 7 from the previous SIT and 7 from the current (+2 for including last days)
suite.Equal(int64(16), *payloadShipment.SitStatus.CalculatedTotalDaysInSIT)
suite.Equal(subtestData.sit.SITEntryDate.Format("2006-01-02"), payloadShipment.SitStatus.CurrentSIT.SitEntryDate.String())
suite.Equal(subtestData.sit.SITDepartureDate.Format("2006-01-02"), payloadShipment.SitStatus.CurrentSIT.SitDepartureDate.String())

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/ghcapi/payment_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ func (suite *HandlerSuite) TestShipmentsSITBalanceHandler() {
suite.Equal(int64(120), shipmentSITBalance.TotalSITDaysAuthorized)
suite.Equal(int64(60), shipmentSITBalance.PendingSITDaysInvoiced)
// Since there is no departure date on one of the SITs, +1 is added to the count to count the last day
suite.Equal(int64(-61), shipmentSITBalance.TotalSITDaysRemaining) // Well over entitlement
suite.Equal(int64(-62), shipmentSITBalance.TotalSITDaysRemaining) // Well over entitlement
suite.Equal(destinationPaymentEndDate.Format("2006-01-02"), shipmentSITBalance.PendingBilledEndDate.String())
suite.Equal(int64(30), *shipmentSITBalance.PreviouslyBilledDays)
})
Expand Down
14 changes: 12 additions & 2 deletions pkg/services/mocks/ShipmentSITStatus.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ func (suite *MTOServiceItemServiceSuite) TestMTOServiceItemUpdater() {
var postUpdatedServiceItemShipment models.MTOShipment
suite.DB().Q().Find(&postUpdatedServiceItemShipment, shipment.ID)
suite.NotNil(postUpdatedServiceItemShipment)
// Verify the departure date is before the original shipment authorized end date
suite.True(updatedServiceItem.SITDepartureDate.Before(*shipmentWithCalculatedStatus.DestinationSITAuthEndDate))
// Verify the departure date is equal to the shipment SIT status departure date (Previously shipment SIT status would have an improper end date due to calc issues. This was fixed in B-20967)
suite.True(updatedServiceItem.SITDepartureDate.Equal(*shipmentWithCalculatedStatus.DestinationSITAuthEndDate))
// Verify the updated shipment authorized end date is equal to the departure date
// Truncate to the nearest day. This is because the shipment only inherits the day, month, year from the service item, not the hour, minute, or second
suite.True(updatedServiceItem.SITDepartureDate.Truncate(24 * time.Hour).Equal(postUpdatedServiceItemShipment.DestinationSITAuthEndDate.Truncate(24 * time.Hour)))
Expand Down Expand Up @@ -605,8 +605,8 @@ func (suite *MTOServiceItemServiceSuite) TestMTOServiceItemUpdater() {
var postUpdatedServiceItemShipment models.MTOShipment
suite.DB().Q().Find(&postUpdatedServiceItemShipment, shipment.ID)
suite.NotNil(postUpdatedServiceItemShipment)
// Verify the departure date is before the original shipment authorized end date
suite.True(updatedServiceItem.SITDepartureDate.Before(*shipmentWithCalculatedStatus.OriginSITAuthEndDate))
// Verify the departure date is equal to the shipment SIT status departure date (Previously shipment SIT status would have an improper end date due to calc issues. This was fixed in B-20967)
suite.True(updatedServiceItem.SITDepartureDate.Equal(*shipmentWithCalculatedStatus.OriginSITAuthEndDate))
// Verify the updated shipment authorized end date is equal to the departure date
// Truncate to the nearest day. This is because the shipment only inherits the day, month, year from the service item, not the hour, minute, or second
suite.True(updatedServiceItem.SITDepartureDate.Truncate(24 * time.Hour).Equal(postUpdatedServiceItemShipment.OriginSITAuthEndDate.Truncate(24 * time.Hour)))
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/mto_shipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,5 @@ type ShipmentSITStatus interface {
CalculateShipmentsSITStatuses(appCtx appcontext.AppContext, shipments []models.MTOShipment) map[string]SITStatus
CalculateShipmentSITStatus(appCtx appcontext.AppContext, shipment models.MTOShipment) (*SITStatus, models.MTOShipment, error)
CalculateShipmentSITAllowance(appCtx appcontext.AppContext, shipment models.MTOShipment) (int, error)
RetrieveShipmentSIT(appCtx appcontext.AppContext, shipment models.MTOShipment) models.SITServiceItemGroupings
RetrieveShipmentSIT(appCtx appcontext.AppContext, shipment models.MTOShipment) (models.SITServiceItemGroupings, error)
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ func calculateReviewedSITBalance(appCtx appcontext.AppContext, paymentServiceIte
}

// sort the SIT service items into past, current and future to aid in the upcoming calculations
shipmentSIT := sitstatus.NewShipmentSITStatus().RetrieveShipmentSIT(appCtx, shipment)
shipmentSIT, err := sitstatus.NewShipmentSITStatus().RetrieveShipmentSIT(appCtx, shipment)
if err != nil {
return err
}
sortedShipmentSIT := sitstatus.SortShipmentSITs(shipmentSIT, today)

totalSITDaysAuthorized, err := sitstatus.NewShipmentSITStatus().CalculateShipmentSITAllowance(appCtx, shipment)
Expand Down Expand Up @@ -155,7 +158,10 @@ func calculatePendingSITBalance(appCtx appcontext.AppContext, paymentServiceItem
return err
}
// sort the SIT service items into past, current and future to aid in the upcoming calculations
shipmentSIT := sitstatus.NewShipmentSITStatus().RetrieveShipmentSIT(appCtx, shipment)
shipmentSIT, err := sitstatus.NewShipmentSITStatus().RetrieveShipmentSIT(appCtx, shipment)
if err != nil {
return err
}
sortedShipmentSIT := sitstatus.SortShipmentSITs(shipmentSIT, today)
totalSITAllowance, err := sitstatus.NewShipmentSITStatus().CalculateShipmentSITAllowance(appCtx, shipment)
if err != nil {
Expand All @@ -173,7 +179,9 @@ func calculatePendingSITBalance(appCtx appcontext.AppContext, paymentServiceItem

// Even though these have been set before, we should do these calculations again in order to recalculate the
// totalSITEndDate using this service item's entry date.
totalSITEndDate := sitstatus.CalculateSITAuthorizedEndDate(totalSITAllowance, daysInSIT, *paymentServiceItem.MTOServiceItem.SITEntryDate, calculateTotalDaysInSIT)
// Additionally retrieve the latest SIT Departure date from the current SIT if it exists. The first current SIT is chosen as there is not currently support for more than one SIT
// Per AC under B-20899
totalSITEndDate := sitstatus.CalculateSITAuthorizedEndDate(totalSITAllowance, daysInSIT, *paymentServiceItem.MTOServiceItem.SITEntryDate, calculateTotalDaysInSIT, sortedShipmentSIT.CurrentSITs[0].Summary.SITDepartureDate)

shipmentSITBalance.TotalSITEndDate = totalSITEndDate
shipmentsSITBalances[shipment.ID.String()] = shipmentSITBalance
Expand All @@ -191,7 +199,9 @@ func calculatePendingSITBalance(appCtx appcontext.AppContext, paymentServiceItem
totalSITDaysUsed := sitstatus.CalculateTotalDaysInSIT(sortedShipmentSIT, today)
totalSITDaysRemaining := totalSITDaysAuthorized - totalSITDaysUsed

totalSITEndDate := sitstatus.CalculateSITAuthorizedEndDate(totalSITAllowance, daysInSIT, *paymentServiceItem.MTOServiceItem.SITEntryDate, calculateTotalDaysInSIT)
// Retrieve the latest SIT Departure date from the current SIT if it exists. The first current SIT is chosen as there is not currently support for more than one SIT
// Per AC under B-20899
totalSITEndDate := sitstatus.CalculateSITAuthorizedEndDate(totalSITAllowance, daysInSIT, *paymentServiceItem.MTOServiceItem.SITEntryDate, calculateTotalDaysInSIT, sortedShipmentSIT.CurrentSITs[0].Summary.SITDepartureDate)

shipmentSITBalance.TotalSITDaysAuthorized = totalSITDaysAuthorized
shipmentSITBalance.TotalSITDaysRemaining = totalSITDaysRemaining
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (suite *PaymentRequestServiceSuite) TestListShipmentPaymentSITBalance() {
suite.Equal(paymentEndDate.String(), pendingSITBalance.PendingBilledEndDate.String())
suite.Equal(120, pendingSITBalance.TotalSITDaysAuthorized)
suite.Equal(89, pendingSITBalance.TotalSITDaysRemaining)
suite.Equal(doasit.SITEntryDate.AddDate(0, 0, 119).String(), pendingSITBalance.TotalSITEndDate.UTC().String())
suite.Equal(doasit.SITEntryDate.AddDate(0, 0, 118).String(), pendingSITBalance.TotalSITEndDate.UTC().String())
})

suite.Run("calculates pending destination SIT balance when origin was invoiced previously", func() {
Expand Down Expand Up @@ -528,9 +528,9 @@ func (suite *PaymentRequestServiceSuite) TestListShipmentPaymentSITBalance() {

suite.Equal(120, pendingSITBalance.TotalSITDaysAuthorized)
// 120 total authorized - 30 from origin SIT - 60 from destination SIT = 30 SIT days remaining
suite.Equal(29, pendingSITBalance.TotalSITDaysRemaining)
suite.Equal(28, pendingSITBalance.TotalSITDaysRemaining)

suite.Equal(ddasit.SITEntryDate.AddDate(0, 0, 89).String(), pendingSITBalance.TotalSITEndDate.UTC().String())
suite.Equal(ddasit.SITEntryDate.AddDate(0, 0, 87).String(), pendingSITBalance.TotalSITEndDate.UTC().String())
})

suite.Run("ignores including previously denied service items in SIT balance", func() {
Expand Down Expand Up @@ -842,7 +842,7 @@ func (suite *PaymentRequestServiceSuite) TestListShipmentPaymentSITBalance() {
suite.Equal(shipment.ID.String(), pendingSITBalance.ShipmentID.String())
suite.Equal(120, pendingSITBalance.TotalSITDaysAuthorized)
suite.Equal(60, pendingSITBalance.PendingSITDaysInvoiced)
suite.Equal(44, pendingSITBalance.TotalSITDaysRemaining)
suite.Equal(43, pendingSITBalance.TotalSITDaysRemaining)
suite.Equal(destinationPaymentEndDate.String(), pendingSITBalance.PendingBilledEndDate.String())
suite.Nil(pendingSITBalance.PreviouslyBilledDays)
})
Expand Down
Loading
Loading