diff --git a/cmd/generate-shipment-summary/main.go b/cmd/generate-shipment-summary/main.go index 0e929582f32..e920d423276 100644 --- a/cmd/generate-shipment-summary/main.go +++ b/cmd/generate-shipment-summary/main.go @@ -169,7 +169,7 @@ func main() { log.Fatal(err.Error()) } - page1Data, page2Data := ppmComputer.FormatValuesShipmentSummaryWorksheet(*ssfd, false) + page1Data, page2Data, err := ppmComputer.FormatValuesShipmentSummaryWorksheet(*ssfd, false) noErr(err) ppmGenerator, err := shipmentsummaryworksheet.NewSSWPPMGenerator(generator) noErr(err) diff --git a/pkg/assets/paperwork/formtemplates/SSWPDFTemplate.pdf b/pkg/assets/paperwork/formtemplates/SSWPDFTemplate.pdf index 96d3ef28a45..76cccff2025 100644 Binary files a/pkg/assets/paperwork/formtemplates/SSWPDFTemplate.pdf and b/pkg/assets/paperwork/formtemplates/SSWPDFTemplate.pdf differ diff --git a/pkg/services/mocks/SSWPPMComputer.go b/pkg/services/mocks/SSWPPMComputer.go index 6612f32620a..23372677ec1 100644 --- a/pkg/services/mocks/SSWPPMComputer.go +++ b/pkg/services/mocks/SSWPPMComputer.go @@ -71,12 +71,13 @@ func (_m *SSWPPMComputer) FetchDataShipmentSummaryWorksheetFormData(appCtx appco } // FormatValuesShipmentSummaryWorksheet provides a mock function with given fields: shipmentSummaryFormData, isPaymentPacket -func (_m *SSWPPMComputer) FormatValuesShipmentSummaryWorksheet(shipmentSummaryFormData services.ShipmentSummaryFormData, isPaymentPacket bool) (services.Page1Values, services.Page2Values) { +func (_m *SSWPPMComputer) FormatValuesShipmentSummaryWorksheet(shipmentSummaryFormData services.ShipmentSummaryFormData, isPaymentPacket bool) (services.Page1Values, services.Page2Values, error) { ret := _m.Called(shipmentSummaryFormData, isPaymentPacket) var r0 services.Page1Values var r1 services.Page2Values - if rf, ok := ret.Get(0).(func(services.ShipmentSummaryFormData, bool) (services.Page1Values, services.Page2Values)); ok { + var r2 error + if rf, ok := ret.Get(0).(func(services.ShipmentSummaryFormData, bool) (services.Page1Values, services.Page2Values, error)); ok { return rf(shipmentSummaryFormData, isPaymentPacket) } if rf, ok := ret.Get(0).(func(services.ShipmentSummaryFormData, bool) services.Page1Values); ok { @@ -91,7 +92,13 @@ func (_m *SSWPPMComputer) FormatValuesShipmentSummaryWorksheet(shipmentSummaryFo r1 = ret.Get(1).(services.Page2Values) } - return r0, r1 + if rf, ok := ret.Get(2).(func(services.ShipmentSummaryFormData, bool) error); ok { + r2 = rf(shipmentSummaryFormData, isPaymentPacket) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 } // NewSSWPPMComputer creates a new instance of SSWPPMComputer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. diff --git a/pkg/services/ppmshipment/aoa_packet_creator.go b/pkg/services/ppmshipment/aoa_packet_creator.go index 2bd2b495801..15777de292d 100644 --- a/pkg/services/ppmshipment/aoa_packet_creator.go +++ b/pkg/services/ppmshipment/aoa_packet_creator.go @@ -80,7 +80,10 @@ func (a *aoaPacketCreator) CreateAOAPacket(appCtx appcontext.AppContext, ppmShip return nil, fmt.Errorf("%s: %w", errMsgPrefix, err) } - page1Data, page2Data := a.SSWPPMComputer.FormatValuesShipmentSummaryWorksheet(*ssfd, isPaymentPacket) + page1Data, page2Data, err := a.SSWPPMComputer.FormatValuesShipmentSummaryWorksheet(*ssfd, isPaymentPacket) + if err != nil { + return nil, fmt.Errorf("%s: %w", errMsgPrefix, err) + } SSWPPMWorksheet, SSWPDFInfo, err := a.SSWPPMGenerator.FillSSWPDFForm(page1Data, page2Data) if err != nil { diff --git a/pkg/services/shipment_summary_worksheet.go b/pkg/services/shipment_summary_worksheet.go index d9c74b2ed4c..b56e9033dbd 100644 --- a/pkg/services/shipment_summary_worksheet.go +++ b/pkg/services/shipment_summary_worksheet.go @@ -46,7 +46,7 @@ type Page1Values struct { SITEntryDates string SITEndDates string SITDaysInStorage string - PreparationDate string + PreparationDate1 string MaxObligationGCC100 string TotalWeightAllotmentRepeat string MaxObligationGCC95 string @@ -64,7 +64,7 @@ type Page1Values struct { // Page2Values is an object representing a Shipment Summary Worksheet type Page2Values struct { CUIBanner string - PreparationDate string + PreparationDate2 string TAC string SAC string ContractedExpenseMemberPaid string @@ -181,7 +181,7 @@ type SSWMaxWeightEntitlement struct { type SSWPPMComputer interface { FetchDataShipmentSummaryWorksheetFormData(appCtx appcontext.AppContext, _ *auth.Session, ppmShipmentID uuid.UUID) (*ShipmentSummaryFormData, error) ComputeObligations(_ appcontext.AppContext, _ ShipmentSummaryFormData, _ route.Planner) (Obligations, error) - FormatValuesShipmentSummaryWorksheet(shipmentSummaryFormData ShipmentSummaryFormData, isPaymentPacket bool) (Page1Values, Page2Values) + FormatValuesShipmentSummaryWorksheet(shipmentSummaryFormData ShipmentSummaryFormData, isPaymentPacket bool) (Page1Values, Page2Values, error) } //go:generate mockery --name SSWPPMGenerator diff --git a/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet.go b/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet.go index 0a5c3109a63..03c9137db1a 100644 --- a/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet.go +++ b/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet.go @@ -56,11 +56,17 @@ func NewSSWPPMGenerator(pdfGenerator *paperwork.Generator) (services.SSWPPMGener } // FormatValuesShipmentSummaryWorksheet returns the formatted pages for the Shipment Summary Worksheet -func (SSWPPMComputer *SSWPPMComputer) FormatValuesShipmentSummaryWorksheet(shipmentSummaryFormData services.ShipmentSummaryFormData, isPaymentPacket bool) (services.Page1Values, services.Page2Values) { - page1 := FormatValuesShipmentSummaryWorksheetFormPage1(shipmentSummaryFormData, isPaymentPacket) - page2 := FormatValuesShipmentSummaryWorksheetFormPage2(shipmentSummaryFormData, isPaymentPacket) +func (SSWPPMComputer *SSWPPMComputer) FormatValuesShipmentSummaryWorksheet(shipmentSummaryFormData services.ShipmentSummaryFormData, isPaymentPacket bool) (services.Page1Values, services.Page2Values, error) { + page1, err := FormatValuesShipmentSummaryWorksheetFormPage1(shipmentSummaryFormData, isPaymentPacket) + if err != nil { + return page1, services.Page2Values{}, errors.WithStack(err) + } + page2, err := FormatValuesShipmentSummaryWorksheetFormPage2(shipmentSummaryFormData, isPaymentPacket) + if err != nil { + return page1, page2, errors.WithStack(err) + } - return page1, page2 + return page1, page2, nil } // textField represents a text field within a form. @@ -202,13 +208,13 @@ const ( ) // FormatValuesShipmentSummaryWorksheetFormPage1 formats the data for page 1 of the Shipment Summary Worksheet -func FormatValuesShipmentSummaryWorksheetFormPage1(data services.ShipmentSummaryFormData, isPaymentPacket bool) services.Page1Values { +func FormatValuesShipmentSummaryWorksheetFormPage1(data services.ShipmentSummaryFormData, isPaymentPacket bool) (services.Page1Values, error) { + var err error page1 := services.Page1Values{} page1.CUIBanner = controlledUnclassifiedInformationText page1.MaxSITStorageEntitlement = fmt.Sprintf("%02d Days in SIT", data.MaxSITStorageEntitlement) // We don't currently know what allows POV to be authorized, so we are hardcoding it to "No" to start page1.POVAuthorized = "No" - page1.PreparationDate = FormatDate(data.PreparationDate) sm := data.ServiceMember page1.ServiceMemberName = FormatServiceMemberFullName(sm) @@ -247,9 +253,14 @@ func FormatValuesShipmentSummaryWorksheetFormPage1(data services.ShipmentSummary finalPPMWeight := FormatPPMWeightFinal(data.PPMShipmentFinalWeight) page1.ShipmentWeights = finalPPMWeight page1.ActualObligationGCC100 = finalPPMWeight + "; " + formattedShipment.FinalIncentive + page1.PreparationDate1, err = formatSSWDate(data.SignedCertifications, data.PPMShipment.ID) + if err != nil { + return page1, err + } } else { page1.ShipmentWeights = formattedShipments.ShipmentWeights page1.ActualObligationGCC100 = formattedShipments.ShipmentWeightForObligation + " - Estimated lbs; " + formattedShipment.FinalIncentive + page1.PreparationDate1 = formatAOADate(data.SignedCertifications, data.PPMShipment.ID) } page1.MaxObligationGCC100 = FormatWeights(data.WeightAllotment.TotalWeight) + " lbs; " + formattedShipment.EstimatedIncentive page1.MaxObligationGCCMaxAdvance = formattedShipment.MaxAdvance @@ -258,7 +269,56 @@ func FormatValuesShipmentSummaryWorksheetFormPage1(data services.ShipmentSummary page1.ActualObligationSIT = formattedSIT.DaysInStorage page1.TotalWeightAllotmentRepeat = page1.TotalWeightAllotment page1.PPMRemainingEntitlement = FormatWeights(data.PPMRemainingEntitlement) - return page1 + return page1, nil +} + +// FormatValuesShipmentSummaryWorksheetFormPage2 formats the data for page 2 of the Shipment Summary Worksheet +func FormatValuesShipmentSummaryWorksheetFormPage2(data services.ShipmentSummaryFormData, isPaymentPacket bool) (services.Page2Values, error) { + var err error + expensesMap := SubTotalExpenses(data.MovingExpenses) + certificationInfo := formatSignedCertifications(data.SignedCertifications, data.PPMShipment.ID) + formattedShipments := FormatAllShipments(data.PPMShipments) + + page2 := services.Page2Values{} + page2.CUIBanner = controlledUnclassifiedInformationText + page2.TAC = derefStringTypes(data.Order.TAC) + page2.SAC = derefStringTypes(data.Order.SAC) + if isPaymentPacket { + page2.PreparationDate2, err = formatSSWDate(data.SignedCertifications, data.PPMShipment.ID) + if err != nil { + return page2, err + } + } else { + page2.PreparationDate2 = formatAOADate(data.SignedCertifications, data.PPMShipment.ID) + } + page2.ContractedExpenseMemberPaid = FormatDollars(expensesMap["ContractedExpenseMemberPaid"]) + page2.ContractedExpenseGTCCPaid = FormatDollars(expensesMap["ContractedExpenseGTCCPaid"]) + page2.PackingMaterialsMemberPaid = FormatDollars(expensesMap["PackingMaterialsMemberPaid"]) + page2.PackingMaterialsGTCCPaid = FormatDollars(expensesMap["PackingMaterialsGTCCPaid"]) + page2.WeighingFeesMemberPaid = FormatDollars(expensesMap["WeighingFeeMemberPaid"]) + page2.WeighingFeesGTCCPaid = FormatDollars(expensesMap["WeighingFeeGTCCPaid"]) + page2.RentalEquipmentMemberPaid = FormatDollars(expensesMap["RentalEquipmentMemberPaid"]) + page2.RentalEquipmentGTCCPaid = FormatDollars(expensesMap["RentalEquipmentGTCCPaid"]) + page2.TollsMemberPaid = FormatDollars(expensesMap["TollsMemberPaid"]) + page2.TollsGTCCPaid = FormatDollars(expensesMap["TollsGTCCPaid"]) + page2.OilMemberPaid = FormatDollars(expensesMap["OilMemberPaid"]) + page2.OilGTCCPaid = FormatDollars(expensesMap["OilGTCCPaid"]) + page2.OtherMemberPaid = FormatDollars(expensesMap["OtherMemberPaid"]) + page2.OtherGTCCPaid = FormatDollars(expensesMap["OtherGTCCPaid"]) + page2.TotalMemberPaid = FormatDollars(expensesMap["TotalMemberPaid"]) + page2.TotalGTCCPaid = FormatDollars(expensesMap["TotalGTCCPaid"]) + page2.TotalMemberPaidRepeated = FormatDollars(expensesMap["TotalMemberPaid"]) + page2.TotalGTCCPaidRepeated = FormatDollars(expensesMap["TotalGTCCPaid"]) + page2.TotalMemberPaidSIT = FormatDollars(expensesMap["StorageMemberPaid"]) + page2.TotalGTCCPaidSIT = FormatDollars(expensesMap["StorageGTCCPaid"]) + page2.TotalMemberPaidRepeated = page2.TotalMemberPaid + page2.TotalGTCCPaidRepeated = page2.TotalGTCCPaid + page2.ShipmentPickupDates = formattedShipments.PickUpDates + page2.TrustedAgentName = trustedAgentText + page2.ServiceMemberSignature = certificationInfo.CustomerField + page2.PPPOPPSORepresentative = certificationInfo.OfficeField + page2.SignatureDate = certificationInfo.DateField + return page2, nil } // FormatGrade formats the service member's rank for Shipment Summary Worksheet @@ -300,48 +360,6 @@ func FormatGrade(grade *internalmessages.OrderPayGrade) string { return "" } -// FormatValuesShipmentSummaryWorksheetFormPage2 formats the data for page 2 of the Shipment Summary Worksheet -func FormatValuesShipmentSummaryWorksheetFormPage2(data services.ShipmentSummaryFormData, isPaymentPacket bool) services.Page2Values { - - expensesMap := SubTotalExpenses(data.MovingExpenses) - certificationInfo := formatSignedCertifications(data.SignedCertifications, data.PPMShipment.ID) - formattedShipments := FormatAllShipments(data.PPMShipments) - - page2 := services.Page2Values{} - page2.CUIBanner = controlledUnclassifiedInformationText - page2.TAC = derefStringTypes(data.Order.TAC) - page2.SAC = derefStringTypes(data.Order.SAC) - page2.PreparationDate = FormatDate(data.PreparationDate) - page2.ContractedExpenseMemberPaid = FormatDollars(expensesMap["ContractedExpenseMemberPaid"]) - page2.ContractedExpenseGTCCPaid = FormatDollars(expensesMap["ContractedExpenseGTCCPaid"]) - page2.PackingMaterialsMemberPaid = FormatDollars(expensesMap["PackingMaterialsMemberPaid"]) - page2.PackingMaterialsGTCCPaid = FormatDollars(expensesMap["PackingMaterialsGTCCPaid"]) - page2.WeighingFeesMemberPaid = FormatDollars(expensesMap["WeighingFeeMemberPaid"]) - page2.WeighingFeesGTCCPaid = FormatDollars(expensesMap["WeighingFeeGTCCPaid"]) - page2.RentalEquipmentMemberPaid = FormatDollars(expensesMap["RentalEquipmentMemberPaid"]) - page2.RentalEquipmentGTCCPaid = FormatDollars(expensesMap["RentalEquipmentGTCCPaid"]) - page2.TollsMemberPaid = FormatDollars(expensesMap["TollsMemberPaid"]) - page2.TollsGTCCPaid = FormatDollars(expensesMap["TollsGTCCPaid"]) - page2.OilMemberPaid = FormatDollars(expensesMap["OilMemberPaid"]) - page2.OilGTCCPaid = FormatDollars(expensesMap["OilGTCCPaid"]) - page2.OtherMemberPaid = FormatDollars(expensesMap["OtherMemberPaid"]) - page2.OtherGTCCPaid = FormatDollars(expensesMap["OtherGTCCPaid"]) - page2.TotalMemberPaid = FormatDollars(expensesMap["TotalMemberPaid"]) - page2.TotalGTCCPaid = FormatDollars(expensesMap["TotalGTCCPaid"]) - page2.TotalMemberPaidRepeated = FormatDollars(expensesMap["TotalMemberPaid"]) - page2.TotalGTCCPaidRepeated = FormatDollars(expensesMap["TotalGTCCPaid"]) - page2.TotalMemberPaidSIT = FormatDollars(expensesMap["StorageMemberPaid"]) - page2.TotalGTCCPaidSIT = FormatDollars(expensesMap["StorageGTCCPaid"]) - page2.TotalMemberPaidRepeated = page2.TotalMemberPaid - page2.TotalGTCCPaidRepeated = page2.TotalGTCCPaid - page2.ShipmentPickupDates = formattedShipments.PickUpDates - page2.TrustedAgentName = trustedAgentText - page2.ServiceMemberSignature = certificationInfo.CustomerField - page2.PPPOPPSORepresentative = certificationInfo.OfficeField - page2.SignatureDate = certificationInfo.DateField - return page2 -} - func formatEmplid(serviceMember models.ServiceMember) (*string, error) { const prefix = "EMPLID:" const separator = " " @@ -383,10 +401,10 @@ func formatSignedCertifications(signedCertifications []*models.SignedCertificati switch { case *cert.CertificationType == models.SignedCertificationTypePreCloseoutReviewedPPMPAYMENT: aoaSignature = cert.Signature - aoaDate = FormatSignatureDate(cert.UpdatedAt) // We use updatedat to get the most recent signature dates + aoaDate = FormatDate(cert.UpdatedAt) // We use updatedat to get the most recent signature dates case *cert.CertificationType == models.SignedCertificationTypeCloseoutReviewedPPMPAYMENT: sswSignature = cert.Signature - sswDate = FormatSignatureDate(cert.UpdatedAt) // We use updatedat to get the most recent signature dates + sswDate = FormatDate(cert.UpdatedAt) // We use updatedat to get the most recent signature dates } } } @@ -397,11 +415,36 @@ func formatSignedCertifications(signedCertifications []*models.SignedCertificati return certifications } -// FormatSignatureDate formats the date the office members signed the SSW -func FormatSignatureDate(signature time.Time) string { - dateLayout := "02 Jan 2006" // Removed time to save space on template, per PO it's not needed - dt := signature.Format(dateLayout) - return dt +// The following formats the preparation date, as the preparation date for AOAs is the date the service counselor certifies the advance. +func formatAOADate(signedCertifications []*models.SignedCertification, ppmid uuid.UUID) string { + // This loop evaluates certs to find Office AOA Signature date + for _, cert := range signedCertifications { + if cert.PpmID != nil { // Required to avoid error, service members signatures have nil ppm ids + if *cert.PpmID == ppmid { // PPM ID needs to be checked to prevent signatures from other PPMs on the same move from populating + if *cert.CertificationType == models.SignedCertificationTypePreCloseoutReviewedPPMPAYMENT { + aoaDate := FormatDate(cert.UpdatedAt) // We use updatedat to get the most recent signature dates + return aoaDate + } + } + } + } + return FormatDate(time.Now()) +} + +// The following formats the preparation date, as the preparation date for SSWs is the date the closeout counselor certifies the closeout. +func formatSSWDate(signedCertifications []*models.SignedCertification, ppmid uuid.UUID) (string, error) { + // This loop evaluates certs to find Office SSW Signature date + for _, cert := range signedCertifications { + if cert.PpmID != nil { // Required to avoid error, service members signatures have nil ppm ids + if *cert.PpmID == ppmid { // PPM ID needs to be checked to prevent signatures from other PPMs on the same move from populating + if *cert.CertificationType == models.SignedCertificationTypeCloseoutReviewedPPMPAYMENT { + sswDate := FormatDate(cert.UpdatedAt) // We use updatedat to get the most recent signature dates + return sswDate, nil + } + } + } + } + return "", errors.New("Payment Packet is not certified") } // FormatLocation formats AuthorizedOrigin and AuthorizedDestination for Shipment Summary Worksheet @@ -874,7 +917,7 @@ func (SSWPPMGenerator *SSWPPMGenerator) FillSSWPDFForm(Page1Values services.Page var sswHeader = header{ Source: "SSWPDFTemplate.pdf", Version: "pdfcpu v0.8.0 dev", - Creation: "2024-07-19 18:07:42 UTC", + Creation: "2024-08-21 19:31:01 UTC", Producer: "macOS Version 13.5 (Build 22G74) Quartz PDFContext, AppendMode 1.1", } @@ -937,7 +980,7 @@ func createTextFields(data interface{}, pages ...int) []textField { ID: fmt.Sprintf("%d", len(textFields)+1), Name: field.Name, Value: fmt.Sprintf("%v", value), - Multiline: false, + Multiline: true, Locked: false, } diff --git a/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet_test.go b/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet_test.go index 705b0700d62..92cb2fc865a 100644 --- a/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet_test.go +++ b/pkg/services/shipment_summary_worksheet/shipment_summary_worksheet_test.go @@ -334,9 +334,8 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma PreparationDate: time.Date(2019, 1, 1, 1, 1, 1, 1, time.UTC), PPMShipments: PPMShipments, } - sswPage1 := FormatValuesShipmentSummaryWorksheetFormPage1(ssd, false) - - suite.Equal("01-Jan-2019", sswPage1.PreparationDate) + sswPage1, err := FormatValuesShipmentSummaryWorksheetFormPage1(ssd, false) + suite.NoError(err) suite.Equal("Jenkins Jr., Marcus Joseph", sswPage1.ServiceMemberName) suite.Equal("E-9", sswPage1.RankGrade) @@ -398,7 +397,8 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma PreparationDate: time.Date(2019, 1, 1, 1, 1, 1, 1, time.UTC), PPMShipments: PPMShipmentsWithoutActualMoveDate, } - sswPage1NoActualMoveDate := FormatValuesShipmentSummaryWorksheetFormPage1(ssdWithoutPPMActualMoveDate, false) + sswPage1NoActualMoveDate, err := FormatValuesShipmentSummaryWorksheetFormPage1(ssdWithoutPPMActualMoveDate, false) + suite.NoError(err) suite.Equal("N/A", sswPage1NoActualMoveDate.ShipmentPickUpDates) } @@ -464,7 +464,8 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatValuesShipmentSumma MovingExpenses: movingExpenses, } - sswPage2 := FormatValuesShipmentSummaryWorksheetFormPage2(ssd, false) + sswPage2, err := FormatValuesShipmentSummaryWorksheetFormPage2(ssd, false) + suite.NoError(err) suite.Equal("$200.00", sswPage2.TollsGTCCPaid) suite.Equal("$200.00", sswPage2.TollsMemberPaid) suite.Equal("$200.00", sswPage2.OilMemberPaid) @@ -654,17 +655,25 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatPPMWeightFinal() { suite.Equal("1,000 lbs - Actual", FormatPPMWeightFinal(pounds)) } -func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatSignedCertifications() { +func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatAOASignedCertifications() { + var err error move := factory.BuildMoveWithPPMShipment(suite.DB(), nil, nil) - testDate := time.Now() - certifications := Certifications{ + testDate := time.Now() // due to using updatedAt, time.Now() needs to be used to test cert times and dates + aoaCertifications := Certifications{ CustomerField: "", OfficeField: "AOA: Firstname Lastname\nSSW: ", - DateField: "AOA: " + FormatSignatureDate(testDate) + "\nSSW: ", + DateField: "AOA: " + FormatDate(testDate) + "\nSSW: ", } + sswCertifications := Certifications{ + CustomerField: "", + OfficeField: "AOA: Firstname Lastname\nSSW: Firstname Lastname", + DateField: "AOA: " + FormatDate(testDate) + "\nSSW: " + FormatDate(testDate), + } + prepAOADate := FormatDate(testDate) + prepSSWDate := FormatDate(testDate) signedCertType := models.SignedCertificationTypePreCloseoutReviewedPPMPAYMENT - ppmPaymentsignedCertification := factory.BuildSignedCertification(suite.DB(), []factory.Customization{ + aoaSignedCertification := factory.BuildSignedCertification(suite.DB(), []factory.Customization{ { Model: move, LinkOnly: true, @@ -680,23 +689,76 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatSignedCertification }, }, nil) var certs []*models.SignedCertification - certs = append(certs, &ppmPaymentsignedCertification) + certs = append(certs, &aoaSignedCertification) formattedSignature := formatSignedCertifications(certs, move.MTOShipments[0].PPMShipment.ID) + formattedDate := formatAOADate(certs, move.MTOShipments[0].PPMShipment.ID) + suite.Equal(prepAOADate, formattedDate) + suite.Equal(aoaCertifications, formattedSignature) - suite.Equal(certifications, formattedSignature) -} + signedCertType = models.SignedCertificationTypeCloseoutReviewedPPMPAYMENT + ppmPaymentsignedCertification := factory.BuildSignedCertification(suite.DB(), []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + { + Model: models.SignedCertification{ + CertificationType: &signedCertType, + CertificationText: "APPROVED", + Signature: "Firstname Lastname", + UpdatedAt: testDate, + PpmID: models.UUIDPointer(move.MTOShipments[0].PPMShipment.ID), + }, + }, + }, nil) + certs = append(certs, &ppmPaymentsignedCertification) + + formattedSignature = formatSignedCertifications(certs, move.MTOShipments[0].PPMShipment.ID) + formattedDate, err = formatSSWDate(certs, move.MTOShipments[0].PPMShipment.ID) + suite.NoError(err) + suite.Equal(prepSSWDate, formattedDate) + suite.Equal(sswCertifications, formattedSignature) -func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatSignatureDate() { - signatureDate := time.Date(2019, time.January, 26, 14, 40, 0, 0, time.UTC) +} - signature := models.SignedCertification{ - Date: signatureDate, +func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatSSWSignedCertifications() { + var err error + move := factory.BuildMoveWithPPMShipment(suite.DB(), nil, nil) + testDate := time.Now() // due to using updatedAt, time.Now() needs to be used to test cert times and dates + sswCertifications := Certifications{ + CustomerField: "", + OfficeField: "AOA: \nSSW: Firstname Lastname", + DateField: "AOA: " + "\nSSW: " + FormatDate(testDate), } + prepSSWDate := FormatDate(testDate) + + var certs []*models.SignedCertification + + signedCertType := models.SignedCertificationTypeCloseoutReviewedPPMPAYMENT + ppmPaymentsignedCertification := factory.BuildSignedCertification(suite.DB(), []factory.Customization{ + { + Model: move, + LinkOnly: true, + }, + { + Model: models.SignedCertification{ + CertificationType: &signedCertType, + CertificationText: "APPROVED", + Signature: "Firstname Lastname", + UpdatedAt: testDate, + PpmID: models.UUIDPointer(move.MTOShipments[0].PPMShipment.ID), + }, + }, + }, nil) + certs = append(certs, &ppmPaymentsignedCertification) - formattedDate := FormatSignatureDate(signature.Date) + formattedSignature := formatSignedCertifications(certs, move.MTOShipments[0].PPMShipment.ID) + formattedDate, err := formatSSWDate(certs, move.MTOShipments[0].PPMShipment.ID) + suite.NoError(err) + suite.Equal(prepSSWDate, formattedDate) + suite.Equal(sswCertifications, formattedSignature) - suite.Equal("26 Jan 2019", formattedDate) } func (suite *ShipmentSummaryWorksheetServiceSuite) TestFormatAddress() { @@ -788,9 +850,9 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestCreateTextFields() { result := createTextFields(testData, pages...) expectedResult := []textField{ - {Pages: pages, ID: "1", Name: "Field1", Value: "Value1", Multiline: false, Locked: false}, - {Pages: pages, ID: "2", Name: "Field2", Value: "42", Multiline: false, Locked: false}, - {Pages: pages, ID: "3", Name: "Field3", Value: "true", Multiline: false, Locked: false}, + {Pages: pages, ID: "1", Name: "Field1", Value: "Value1", Multiline: true, Locked: false}, + {Pages: pages, ID: "2", Name: "Field2", Value: "42", Multiline: true, Locked: false}, + {Pages: pages, ID: "3", Name: "Field3", Value: "true", Multiline: true, Locked: false}, } suite.Equal(result, expectedResult) @@ -853,7 +915,8 @@ func (suite *ShipmentSummaryWorksheetServiceSuite) TestFillSSWPDFForm() { ssd, err := SSWPPMComputer.FetchDataShipmentSummaryWorksheetFormData(suite.AppContextForTest(), &session, ppmShipmentID) suite.NoError(err) - page1Data, page2Data := SSWPPMComputer.FormatValuesShipmentSummaryWorksheet(*ssd, false) + page1Data, page2Data, err := SSWPPMComputer.FormatValuesShipmentSummaryWorksheet(*ssd, false) + suite.NoError(err) test, info, err := ppmGenerator.FillSSWPDFForm(page1Data, page2Data) suite.NoError(err) println(test.Name()) // ensures was generated with temp filesystem