Skip to content

Commit

Permalink
Merge pull request #12160 from transcom/B-17960-integrate-calc-displa…
Browse files Browse the repository at this point in the history
…y-main

B 17960 PPM Closeout Calculations Breakout Display Main
  • Loading branch information
JamesHawks224 authored Mar 7, 2024
2 parents fae01b2 + 4a0f6a2 commit d74ae89
Show file tree
Hide file tree
Showing 50 changed files with 2,105 additions and 383 deletions.
17 changes: 17 additions & 0 deletions pkg/apperror/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ func (e *NotFoundError) Unwrap() error {
return e.err
}

type PPMNotReadyForCloseoutError struct {
id uuid.UUID
message string
}

// NewNotFoundError returns an error for when a struct can not be found
func NewPPMNotReadyForCloseoutError(id uuid.UUID, message string) PPMNotReadyForCloseoutError {
return PPMNotReadyForCloseoutError{
id: id,
message: message,
}
}

func (e PPMNotReadyForCloseoutError) Error() string {
return fmt.Sprintf("ID: %s - PPM Shipment is not ready for closeout. Customer must upload PPM documents. %s", e.id.String(), e.message)
}

// ErrorCode contains error codes for the route package
type ErrorCode string

Expand Down
22 changes: 14 additions & 8 deletions pkg/gen/ghcapi/embedded_spec.go

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

4 changes: 4 additions & 0 deletions pkg/gen/ghcmessages/m_t_o_shipment.go

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

4 changes: 2 additions & 2 deletions pkg/gen/ghcmessages/p_p_m_closeout.go

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

2 changes: 1 addition & 1 deletion pkg/handlers/ghcapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func NewGhcAPIHandler(handlerConfig handlers.HandlerConfig) *ghcops.MymoveAPI {
ppmDocumentsFetcher,
}

ppmCloseoutFetcher := ppmcloseout.NewPPMCloseoutFetcher()
ppmCloseoutFetcher := ppmcloseout.NewPPMCloseoutFetcher(handlerConfig.DTODPlanner(), &paymentrequesthelper.RequestPaymentHelper{}, ppmEstimator)

ghcAPI.PpmGetPPMCloseoutHandler = GetPPMCloseoutHandler{
handlerConfig,
Expand Down
43 changes: 24 additions & 19 deletions pkg/handlers/ghcapi/internal/payloads/model_to_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ func WeightTicket(storer storage.FileStorer, weightTicket *models.WeightTicket)
ProofOfTrailerOwnershipDocumentID: *handlers.FmtUUID(weightTicket.ProofOfTrailerOwnershipDocumentID),
ProofOfTrailerOwnershipDocument: proofOfTrailerOwnershipDocument,
AdjustedNetWeight: handlers.FmtPoundPtr(weightTicket.AdjustedNetWeight),
AllowableWeight: handlers.FmtPoundPtr(weightTicket.AllowableWeight),
NetWeightRemarks: weightTicket.NetWeightRemarks,
ETag: etag.GenerateEtag(weightTicket.UpdatedAt),
}
Expand Down Expand Up @@ -997,25 +998,25 @@ func PPMCloseout(ppmCloseout *models.PPMCloseout) *ghcmessages.PPMCloseout {
return nil
}
payload := &ghcmessages.PPMCloseout{
ID: strfmt.UUID(ppmCloseout.ID.String()),
PlannedMoveDate: handlers.FmtDatePtr(ppmCloseout.PlannedMoveDate),
ActualMoveDate: handlers.FmtDatePtr(ppmCloseout.ActualMoveDate),
Miles: handlers.FmtIntPtrToInt64(ppmCloseout.Miles),
EstimatedWeight: handlers.FmtPoundPtr(ppmCloseout.EstimatedWeight),
ActualWeight: handlers.FmtPoundPtr(ppmCloseout.ActualWeight),
ProGearWeightCustomer: handlers.FmtPoundPtr(ppmCloseout.ProGearWeightCustomer),
ProGearWeightSpouse: handlers.FmtPoundPtr(ppmCloseout.ProGearWeightSpouse),
GrossIncentive: handlers.FmtCost(ppmCloseout.GrossIncentive),
Gcc: handlers.FmtCost(ppmCloseout.GCC),
Aoa: handlers.FmtCost(ppmCloseout.AOA),
RemainingReimbursementOwed: handlers.FmtCost(ppmCloseout.RemainingReimbursementOwed),
HaulPrice: handlers.FmtCost(ppmCloseout.HaulPrice),
HaulFSC: handlers.FmtCost(ppmCloseout.HaulFSC),
Dop: handlers.FmtCost(ppmCloseout.DOP),
Ddp: handlers.FmtCost(ppmCloseout.DDP),
PackPrice: handlers.FmtCost(ppmCloseout.PackPrice),
UnpackPrice: handlers.FmtCost(ppmCloseout.UnpackPrice),
SITReimbursement: handlers.FmtCost(ppmCloseout.SITReimbursement),
ID: strfmt.UUID(ppmCloseout.ID.String()),
PlannedMoveDate: handlers.FmtDatePtr(ppmCloseout.PlannedMoveDate),
ActualMoveDate: handlers.FmtDatePtr(ppmCloseout.ActualMoveDate),
Miles: handlers.FmtIntPtrToInt64(ppmCloseout.Miles),
EstimatedWeight: handlers.FmtPoundPtr(ppmCloseout.EstimatedWeight),
ActualWeight: handlers.FmtPoundPtr(ppmCloseout.ActualWeight),
ProGearWeightCustomer: handlers.FmtPoundPtr(ppmCloseout.ProGearWeightCustomer),
ProGearWeightSpouse: handlers.FmtPoundPtr(ppmCloseout.ProGearWeightSpouse),
GrossIncentive: handlers.FmtCost(ppmCloseout.GrossIncentive),
Gcc: handlers.FmtCost(ppmCloseout.GCC),
Aoa: handlers.FmtCost(ppmCloseout.AOA),
RemainingIncentive: handlers.FmtCost(ppmCloseout.RemainingIncentive),
HaulPrice: handlers.FmtCost(ppmCloseout.HaulPrice),
HaulFSC: handlers.FmtCost(ppmCloseout.HaulFSC),
Dop: handlers.FmtCost(ppmCloseout.DOP),
Ddp: handlers.FmtCost(ppmCloseout.DDP),
PackPrice: handlers.FmtCost(ppmCloseout.PackPrice),
UnpackPrice: handlers.FmtCost(ppmCloseout.UnpackPrice),
SITReimbursement: handlers.FmtCost(ppmCloseout.SITReimbursement),
}

return payload
Expand Down Expand Up @@ -1083,6 +1084,10 @@ func MTOShipment(storer storage.FileStorer, mtoShipment *models.MTOShipment, sit
DeliveryAddressUpdate: ShipmentAddressUpdate(mtoShipment.DeliveryAddressUpdate),
}

if mtoShipment.Distance != nil {
payload.Distance = handlers.FmtInt64(int64(*mtoShipment.Distance))
}

if sitStatusPayload != nil {
// If we have a sitStatusPayload, overwrite SitDaysAllowance from the shipment model.
totalSITAllowance := 0
Expand Down
3 changes: 2 additions & 1 deletion pkg/handlers/ghcapi/mto_shipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ func (h GetMTOShipmentHandler) Handle(params mtoshipmentops.GetShipmentParams) m
"SecondaryDeliveryAddress",
"MTOServiceItems.CustomerContacts",
"StorageFacility.Address",
"PPMShipment"}
"PPMShipment",
"Distance"}

shipmentID := uuid.FromStringOrNil(params.ShipmentID.String())

Expand Down
10 changes: 6 additions & 4 deletions pkg/handlers/ghcapi/ppm_closeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// GetPPMCloseoutHandler is the handler that fetches all of the calculations for a PPM closeout for the office api
type GetPPMCloseoutHandler struct {
handlers.HandlerConfig
ppmCloseoutFetcher services.PPMCloseoutFetcher
services.PPMCloseoutFetcher
}

// Handle retrieves all calcuations for a PPM closeout
Expand All @@ -33,12 +33,14 @@ func (h GetPPMCloseoutHandler) Handle(params ppmcloseoutops.GetPPMCloseoutParams
switch err.(type) {
case apperror.NotFoundError:
return ppmcloseoutops.NewGetPPMCloseoutNotFound().WithPayload(payload), err
case apperror.PPMNotReadyForCloseoutError:
return ppmcloseoutops.NewGetPPMCloseoutNotFound().WithPayload(payload), err
case apperror.ForbiddenError:
return ppmcloseoutops.NewGetPPMCloseoutForbidden().WithPayload(payload), err
case apperror.QueryError:
return ppmcloseoutops.NewGetPPMCloseoutInternalServerError(), err
return ppmcloseoutops.NewGetPPMCloseoutInternalServerError().WithPayload(payload), err
default:
return ppmcloseoutops.NewGetPPMCloseoutInternalServerError(), err
return ppmcloseoutops.NewGetPPMCloseoutInternalServerError().WithPayload(payload), err
}
}
errInstance := fmt.Sprintf("Instance: %s", h.GetTraceIDFromRequest(params.HTTPRequest))
Expand All @@ -50,7 +52,7 @@ func (h GetPPMCloseoutHandler) Handle(params ppmcloseoutops.GetPPMCloseoutParams
}
ppmShipmentID := uuid.FromStringOrNil(params.PpmShipmentID.String())

ppmCloseout, err := h.ppmCloseoutFetcher.GetPPMCloseout(appCtx, ppmShipmentID)
ppmCloseout, err := h.PPMCloseoutFetcher.GetPPMCloseout(appCtx, ppmShipmentID)
if err != nil {
return handleError(err)
}
Expand Down
84 changes: 72 additions & 12 deletions pkg/handlers/ghcapi/ppm_closeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,88 @@ package ghcapi
import (
"fmt"
"net/http/httptest"
"time"

"github.com/go-openapi/strfmt"
"github.com/gofrs/uuid"
"github.com/stretchr/testify/mock"

"github.com/transcom/mymove/pkg/factory"
ppmcloseoutops "github.com/transcom/mymove/pkg/gen/ghcapi/ghcoperations/ppm"
"github.com/transcom/mymove/pkg/models"
paymentrequest "github.com/transcom/mymove/pkg/payment_request"
"github.com/transcom/mymove/pkg/services"
"github.com/transcom/mymove/pkg/services/mocks"
ppmcloseout "github.com/transcom/mymove/pkg/services/ppm_closeout"
"github.com/transcom/mymove/pkg/unit"
)

func (suite *HandlerSuite) TestGetPPMCloseoutHandler() {

setUpMockCloseoutFetcher := func(returnValues ...interface{}) services.PPMCloseoutFetcher {
mockPPMCloseoutFetcher := &mocks.PPMCloseoutFetcher{}

mockPPMCloseoutFetcher.On("GetPPMCloseout",
mock.AnythingOfType("*appcontext.appContext"),
mock.AnythingOfType("uuid.UUID"),
).Return(returnValues...)

return mockPPMCloseoutFetcher
}

setUpHandler := func(ppmCloseoutFetcher services.PPMCloseoutFetcher) GetPPMCloseoutHandler {
return GetPPMCloseoutHandler{
suite.HandlerConfig(),
ppmCloseoutFetcher,
}
}

// Success integration test
suite.Run("Successful fetch (integration) test", func() {
// Create mock object for return from Handler
ppmShipment := factory.BuildPPMShipment(suite.DB(), nil, nil)
SITReimbursement := unit.Cents(100000)
ActualWeight := unit.Pound(980)
DDP := unit.Cents(33280)
DOP := unit.Cents(16160)
EstimatedWeight := unit.Pound(4000)
GrossIncentive := unit.Cents(5000000)
Miles := 2082
PackPrice := unit.Cents(295800)
ProGearWeightCustomer := unit.Pound(1978)
ProGearWeightSpouse := unit.Pound(280)
UnpackPrice := unit.Cents(23800)
aoa := unit.Cents(50)
remainingIncentive := GrossIncentive - aoa
haulPrice := unit.Cents(2300)
haulFSC := unit.Cents(23)
gcc := unit.Cents(500)
actualMoveDate := time.Now()
plannedMoveDate := time.Now()
ppmCloseoutObj := models.PPMCloseout{
ID: &ppmShipment.ID,
SITReimbursement: &SITReimbursement,
ActualMoveDate: &actualMoveDate,
ActualWeight: &ActualWeight,
AOA: &aoa,
DDP: &DDP,
DOP: &DOP,
EstimatedWeight: &EstimatedWeight,
GCC: &gcc,
GrossIncentive: &GrossIncentive,
HaulFSC: &haulFSC,
HaulPrice: &haulPrice,
Miles: &Miles,
PackPrice: &PackPrice,
PlannedMoveDate: &plannedMoveDate,
ProGearWeightCustomer: &ProGearWeightCustomer,
ProGearWeightSpouse: &ProGearWeightSpouse,
RemainingIncentive: &remainingIncentive,
UnpackPrice: &UnpackPrice,
}
officeUser := factory.BuildOfficeUser(nil, nil, nil)
handlerConfig := suite.HandlerConfig()
fetcher := ppmcloseout.NewPPMCloseoutFetcher()
fetcher := setUpMockCloseoutFetcher(&ppmCloseoutObj, nil)
handler := setUpHandler(fetcher)
request := httptest.NewRequest("GET", fmt.Sprintf("/ppm-shipments/%s/closeout", ppmShipment.ID.String()), nil)
request = suite.AuthenticateOfficeRequest(request, officeUser)

Expand All @@ -27,14 +93,8 @@ func (suite *HandlerSuite) TestGetPPMCloseoutHandler() {
PpmShipmentID: strfmt.UUID(ppmShipment.ID.String()),
}

handler := GetPPMCloseoutHandler{
HandlerConfig: handlerConfig,
ppmCloseoutFetcher: fetcher,
}

// Validate incoming payload: no body to validate

response := handler.Handle(params)

suite.IsType(&ppmcloseoutops.GetPPMCloseoutOK{}, response)
payload := response.(*ppmcloseoutops.GetPPMCloseoutOK).Payload

Expand All @@ -47,7 +107,7 @@ func (suite *HandlerSuite) TestGetPPMCloseoutHandler() {
uuidForShipment, _ := uuid.NewV4()
officeUser := factory.BuildOfficeUser(nil, nil, nil)
handlerConfig := suite.HandlerConfig()
fetcher := ppmcloseout.NewPPMCloseoutFetcher()
fetcher := ppmcloseout.NewPPMCloseoutFetcher(suite.HandlerConfig().DTODPlanner(), &paymentrequest.RequestPaymentHelper{}, &mocks.PPMEstimator{})
request := httptest.NewRequest("GET", fmt.Sprintf("/ppm-shipments/%s/closeout", uuidForShipment.String()), nil)
request = suite.AuthenticateOfficeRequest(request, officeUser)

Expand All @@ -57,8 +117,8 @@ func (suite *HandlerSuite) TestGetPPMCloseoutHandler() {
}

handler := GetPPMCloseoutHandler{
HandlerConfig: handlerConfig,
ppmCloseoutFetcher: fetcher,
handlerConfig,
fetcher,
}

// Validate incoming payload: no body to validate
Expand Down
Loading

0 comments on commit d74ae89

Please sign in to comment.