paperwork

package
v0.0.0-...-c407d37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PdfOrientation string  = "P"
	PdfUnit        string  = "pt"
	PdfPageWidth   float64 = 612.0
	PdfPageHeight  float64 = 792.0
	PdfPageSize    string  = "Letter"
	PdfFontDir     string  = ""
)

Default values for PDF generation

Variables

View Source
var HHGShipmentCardLayout = []TableRow{
	{
		LeftFieldName:  "ScheduledPickupDate",
		LeftLabel:      "Scheduled pickup date",
		RightFieldName: "ScheduledDeliveryDate",
		RightLabel:     "Scheduled delivery date",
	},
	{
		LeftFieldName:  "RequestedPickupDate",
		LeftLabel:      "Requested pickup date",
		RightFieldName: "RequiredDeliveryDate",
		RightLabel:     "Required delivery date",
	},
	{
		LeftFieldName:  "ActualPickupDate",
		LeftLabel:      "Actual pickup date",
		RightFieldName: "ActualDeliveryDate",
		RightLabel:     "Actual delivery date",
	},
	{
		LeftFieldName:  "ReleasingAgent",
		LeftLabel:      "Releasing agent",
		RightFieldName: "ReceivingAgent",
		RightLabel:     "Receiving agent",
	},
}
View Source
var InspectionInformationFieldLabels = map[string]string{
	"ObservedShipmentPhysicalPickupDate": "Observed pickup date",
	"ObservedShipmentDeliveryDate":       "Observed delivery date",
	"DateOfInspection":                   "Date of inspection",
	"ReportSubmission":                   "Report submission",
	"EvaluationType":                     "Evaluation type",
	"TimeDepart":                         "Time departed for evaluation",
	"EvalStart":                          "Time evaluation started",
	"EvalEnd":                            "Time evaluation ended",
	"EvaluationLocation":                 "Evaluation location",
	"ObservedPickupDate":                 "Observed pickup date",
	"ObservedDeliveryDate":               "Observed delivery date",
}
View Source
var InspectionInformationFields = []string{
	"DateOfInspection",
	"ReportSubmission",
	"EvaluationType",
	"ObservedShipmentDeliveryDate",
	"ObservedShipmentPhysicalPickupDate",
	"TimeDepart",
	"EvalStart",
	"EvalEnd",
	"EvaluationLocation",
}
View Source
var KPIFieldLabels = map[string]string{
	"ObservedPickupSpreadStartDate": "Observed pickup spread start date",
	"ObservedPickupSpreadEndDate":   "Observed pickup spread end date",
	"ObservedClaimDate":             "Observed claims response date",
	"ObservedPickupDate":            "Observed pickup date",
	"ObservedDeliveryDate":          "Observed delivery date",
}
View Source
var NTSRShipmentCardLayout = []TableRow{
	{
		LeftFieldName:  "ScheduledPickupDate",
		LeftLabel:      "Scheduled pickup date",
		RightFieldName: "ScheduledDeliveryDate",
		RightLabel:     "Scheduled delivery date",
	},
	{
		LeftFieldName:  "RequestedPickupDate",
		LeftLabel:      "Requested pickup date",
		RightFieldName: "RequiredDeliveryDate",
		RightLabel:     "Required delivery date",
	},
	{
		LeftFieldName:  "ActualPickupDate",
		LeftLabel:      "Actual pickup date",
		RightFieldName: "ActualDeliveryDate",
		RightLabel:     "Actual delivery date",
	},
	{
		LeftFieldName:  "StorageFacility",
		LeftLabel:      "Storage information",
		RightFieldName: "ReceivingAgent",
		RightLabel:     "Receiving agent",
	},
}
View Source
var NTSShipmentCardLayout = []TableRow{
	{
		LeftFieldName:  "ScheduledPickupDate",
		LeftLabel:      "Scheduled pickup date",
		RightFieldName: "ScheduledDeliveryDate",
		RightLabel:     "Scheduled delivery date",
	},
	{
		LeftFieldName:  "RequestedPickupDate",
		LeftLabel:      "Requested pickup date",
		RightFieldName: "RequiredDeliveryDate",
		RightLabel:     "Required delivery date",
	},
	{
		LeftFieldName:  "ActualPickupDate",
		LeftLabel:      "Actual pickup date",
		RightFieldName: "ActualDeliveryDate",
		RightLabel:     "Actual delivery date",
	},
	{
		LeftFieldName:  "ReleasingAgent",
		LeftLabel:      "Releasing agent",
		RightFieldName: "StorageFacility",
		RightLabel:     "Storage information",
	},
}
View Source
var PPMShipmentCardLayout = []TableRow{
	{
		LeftFieldName:  "PPMOriginZIP",
		LeftLabel:      "Origin zip",
		RightFieldName: "PPMDestinationZIP",
		RightLabel:     "Destination zip",
	},
	{
		LeftFieldName:  "PPMDepartureDate",
		LeftLabel:      "Departure date",
		RightFieldName: "",
		RightLabel:     "",
	},
}
View Source
var QAERemarksFieldLabels = map[string]string{"QAERemarks": "Evaluation remarks"}
View Source
var QAERemarksFields = []string{"QAERemarks"}
View Source
var ShipmentSummaryPage1Layout = FormLayout{
	TemplateImagePath: "paperwork/formtemplates/ssw1.png",

	FieldsLayout: map[string]FieldPos{
		"CUIBanner":                       FormField(0, 1.6, 216, floatPtr(10), nil, stringPtr("CM")),
		"PreparationDate":                 FormField(155.5, 23, 46, floatPtr(10), nil, nil),
		"ServiceMemberName":               FormField(5, 50, 153, floatPtr(10), nil, nil),
		"DODId":                           FormField(153.5, 43, 60, floatPtr(10), nil, nil),
		"ServiceBranch":                   FormField(10, 54, 40, floatPtr(10), nil, nil),
		"RankGrade":                       FormField(54, 54, 44, floatPtr(10), nil, nil),
		"PreferredEmail":                  FormField(102.5, 54, 47, floatPtr(10), nil, nil),
		"PreferredPhoneNumber":            FormField(153.5, 54, 60, floatPtr(10), nil, nil),
		"WeightAllotment":                 FormField(73.5, 96, 16, floatPtr(10), nil, stringPtr("RM")),
		"WeightAllotmentProgear":          FormField(73.5, 103, 16, floatPtr(10), nil, stringPtr("RM")),
		"WeightAllotmentProgearSpouse":    FormField(73.5, 110, 16, floatPtr(10), nil, stringPtr("RM")),
		"TotalWeightAllotment":            FormField(73.5, 116.5, 16, floatPtr(10), nil, stringPtr("RM")),
		"POVAuthorized":                   FormField(102.25, 91, 45, floatPtr(10), nil, nil),
		"AuthorizedOrigin":                FormField(153.5, 91, 49, floatPtr(10), nil, nil),
		"MaxSITStorageEntitlement":        FormField(102.25, 104, 45, floatPtr(10), nil, nil),
		"AuthorizedDestination":           FormField(153.5, 104, 49, floatPtr(10), nil, nil),
		"MileageTotal":                    FormField(153.5, 116.5, 49, floatPtr(10), nil, nil),
		"OrdersIssueDate":                 FormField(9.5, 73, 40, floatPtr(10), nil, nil),
		"OrdersTypeAndOrdersNumber":       FormField(54, 73, 44, floatPtr(10), nil, nil),
		"IssuingBranchOrAgency":           FormField(102.5, 73, 47, floatPtr(10), nil, nil),
		"NewDutyAssignment":               FormField(153, 73, 60, floatPtr(10), nil, nil),
		"ShipmentNumberAndTypes":          FormField(9.5, 141, 41, floatPtr(10), nil, nil),
		"ShipmentPickUpDates":             FormField(54, 141, 46, floatPtr(10), nil, nil),
		"ShipmentWeights":                 FormField(103, 141, 41, floatPtr(10), nil, nil),
		"ShipmentCurrentShipmentStatuses": FormField(153.5, 141, 41, floatPtr(10), nil, nil),
		"SITNumberAndTypes":               FormField(9.5, 180, 41, floatPtr(10), nil, nil),
		"SITEntryDates":                   FormField(54, 180, 46, floatPtr(10), nil, nil),
		"SITEndDates":                     FormField(103, 180, 41, floatPtr(10), nil, nil),
		"SITDaysInStorage":                FormField(153.5, 180, 41, floatPtr(10), nil, nil),
		"MaxObligationGCC100":             FormField(39, 225.5, 22, floatPtr(10), nil, stringPtr("RM")),
		"TotalWeightAllotmentRepeat":      FormField(73, 225.5, 16, floatPtr(10), nil, stringPtr("RM")),
		"MaxObligationGCC95":              FormField(39, 233, 22, floatPtr(10), nil, stringPtr("RM")),
		"MaxObligationSIT":                FormField(39, 240, 22, floatPtr(10), nil, stringPtr("RM")),
		"MaxObligationGCCMaxAdvance":      FormField(39, 247, 22, floatPtr(10), nil, stringPtr("RM")),
		"ActualObligationGCC100":          FormField(133, 225.5, 22, floatPtr(10), nil, stringPtr("RM")),
		"PPMRemainingEntitlement":         FormField(167, 225.5, 16, floatPtr(10), nil, stringPtr("RM")),
		"ActualObligationGCC95":           FormField(133, 233, 22, floatPtr(10), nil, stringPtr("RM")),
		"ActualObligationSIT":             FormField(133, 240, 22, floatPtr(10), nil, stringPtr("RM")),
		"ActualObligationAdvance":         FormField(133, 247, 22, floatPtr(10), nil, stringPtr("RM")),
	},
}

ShipmentSummaryPage1Layout specifies the layout and template of a Shipment Summary Worksheet

View Source
var ShipmentSummaryPage2Layout = FormLayout{

	TemplateImagePath: "paperwork/formtemplates/ssw2.png",

	FieldsLayout: map[string]FieldPos{
		"CUIBanner":                   FormField(0, 2, 216, floatPtr(10), nil, stringPtr("CM")),
		"PreparationDate":             FormField(155.5, 23, 46, floatPtr(10), nil, nil),
		"SAC":                         FormField(10, 43, 45, floatPtr(10), nil, nil),
		"TAC":                         FormField(10, 54, 45, floatPtr(10), nil, nil),
		"ContractedExpenseMemberPaid": FormField(55, 98, 20, floatPtr(10), nil, stringPtr("RM")),
		"RentalEquipmentMemberPaid":   FormField(55, 104, 20, floatPtr(10), nil, stringPtr("RM")),
		"PackingMaterialsMemberPaid":  FormField(55, 110.5, 20, floatPtr(10), nil, stringPtr("RM")),
		"WeighingFeesMemberPaid":      FormField(55, 117, 20, floatPtr(10), nil, stringPtr("RM")),
		"GasMemberPaid":               FormField(55, 123, 20, floatPtr(10), nil, stringPtr("RM")),
		"TollsMemberPaid":             FormField(55, 129, 20, floatPtr(10), nil, stringPtr("RM")),
		"OilMemberPaid":               FormField(55, 135.5, 20, floatPtr(10), nil, stringPtr("RM")),
		"OtherMemberPaid":             FormField(55, 142, 20, floatPtr(10), nil, stringPtr("RM")),
		"TotalMemberPaid":             FormField(55, 148, 20, floatPtr(10), nil, stringPtr("RM")),
		"ContractedExpenseGTCCPaid":   FormField(82.5, 98, 20, floatPtr(10), nil, stringPtr("RM")),
		"RentalEquipmentGTCCPaid":     FormField(82.5, 104, 20, floatPtr(10), nil, stringPtr("RM")),
		"PackingMaterialsGTCCPaid":    FormField(82.5, 110.5, 20, floatPtr(10), nil, stringPtr("RM")),
		"WeighingFeesGTCCPaid":        FormField(82.5, 117, 20, floatPtr(10), nil, stringPtr("RM")),
		"GasGTCCPaid":                 FormField(82.5, 123, 20, floatPtr(10), nil, stringPtr("RM")),
		"TollsGTCCPaid":               FormField(82.5, 129, 20, floatPtr(10), nil, stringPtr("RM")),
		"OilGTCCPaid":                 FormField(82.5, 135.5, 20, floatPtr(10), nil, stringPtr("RM")),
		"OtherGTCCPaid":               FormField(82.5, 142, 20, floatPtr(10), nil, stringPtr("RM")),
		"TotalGTCCPaid":               FormField(82.5, 148, 20, floatPtr(10), nil, stringPtr("RM")),
		"TotalMemberPaidRepeated":     FormField(169.5, 98, 30, floatPtr(10), nil, stringPtr("RM")),
		"TotalGTCCPaidRepeated":       FormField(169.5, 104.5, 30, floatPtr(10), nil, stringPtr("RM")),
		"TotalMemberPaidSIT":          FormField(169.5, 135.5, 30, floatPtr(10), nil, stringPtr("RM")),
		"TotalGTCCPaidSIT":            FormField(169.5, 142, 30, floatPtr(10), nil, stringPtr("RM")),
		"TotalPaidNonSIT":             FormField(169.5, 111, 30, floatPtr(10), nil, stringPtr("RM")),
		"TotalPaidSIT":                FormField(169.5, 148.5, 30, floatPtr(10), nil, stringPtr("RM")),
	},
}

ShipmentSummaryPage2Layout specifies the layout and template of a Shipment Summary Worksheet

View Source
var ShipmentSummaryPage3Layout = FormLayout{

	TemplateImagePath: "paperwork/formtemplates/shipment_summary_worksheet_page3.png",

	FieldsLayout: map[string]FieldPos{
		"CUIBanner":              FormField(0, 2, 216, floatPtr(10), nil, stringPtr("CM")),
		"PreparationDate":        FormField(155.5, 23, 46, floatPtr(10), nil, nil),
		"Descriptions":           FormField(10, 64, 135, floatPtr(10), nil, nil),
		"AmountsPaid":            FormField(155.5, 64, 46, floatPtr(10), nil, stringPtr("RM")),
		"ServiceMemberSignature": FormField(10, 125, 200, floatPtr(10), nil, nil),
		"SignatureDate":          FormField(10, 136, 200, floatPtr(10), nil, nil),
	},
}

ShipmentSummaryPage3Layout specifies the layout and template of a Shipment Summary Worksheet

View Source
var ViolationsFieldLabels = map[string]string{
	"ViolationsObserved":         "Violations observed",
	"SeriousIncident":            "Serious incident",
	"SeriousIncidentDescription": "Serious incident description",
}
View Source
var ViolationsFields = []string{
	"ViolationsObserved",
	"SeriousIncident",
	"SeriousIncidentDescription",
}

Functions

func ReduceUnusedSpace

func ReduceUnusedSpace(_ appcontext.AppContext, file afero.File, g *Generator, contentType string) (imgFile afero.File, width float64, height float64, err error)

ReduceUnusedSpace reduces unused space

Types

type AdditionalKPIData

type AdditionalKPIData struct {
	ObservedPickupSpreadStartDate string
	ObservedPickupSpreadEndDate   string
	ObservedClaimDate             string
	ObservedPickupDate            string
	ObservedDeliveryDate          string
}

func FormatAdditionalKPIValues

func FormatAdditionalKPIValues(report models.EvaluationReport) AdditionalKPIData

type ContactInformationValues

type ContactInformationValues struct {
	CustomerFullName    string
	CustomerPhone       string
	CustomerRank        string
	CustomerAffiliation string
	QAEFullName         string
	QAEPhone            string
	QAEEmail            string
}

ContactInformationValues holds formatted customer and QAE contact information

func FormatContactInformationValues

func FormatContactInformationValues(customer models.ServiceMember, qae models.OfficeUser) ContactInformationValues

TODO we might be able to change the returns here to strings TODO the function that uses this doesnt care about any of the individual fields, it just joins them

type EvaluationReportFormFiller

type EvaluationReportFormFiller struct {
	// contains filtered or unexported fields
}

EvaluationReportFormFiller is used to create counseling and shipment evaluation reports

func NewEvaluationReportFormFiller

func NewEvaluationReportFormFiller() (*EvaluationReportFormFiller, error)

func (*EvaluationReportFormFiller) CreateCounselingReport

func (f *EvaluationReportFormFiller) CreateCounselingReport(report models.EvaluationReport, violations models.ReportViolations, shipments models.MTOShipments, customer models.ServiceMember) error

func (*EvaluationReportFormFiller) CreateShipmentReport

func (f *EvaluationReportFormFiller) CreateShipmentReport(report models.EvaluationReport, violations models.ReportViolations, shipment models.MTOShipment, customer models.ServiceMember) error

func (*EvaluationReportFormFiller) Output

func (f *EvaluationReportFormFiller) Output(output io.Writer) error

Output outputs the form to the provided file

type FieldPos

type FieldPos struct {
	// contains filtered or unexported fields
}

FieldPos encapsulates the starting position and width of a form field

func FormField

func FormField(xPos, yPos, width float64, fontSize, lineHeight *float64, alignStr *string) FieldPos

FormField returns a new field position

type FormFiller

type FormFiller struct {
	// contains filtered or unexported fields
}

FormFiller is a fillable pdf form

func NewFormFiller

func NewFormFiller() *FormFiller

NewFormFiller turns a template image and fields mapping into a FormFiller instance

func (*FormFiller) AppendPage

func (f *FormFiller) AppendPage(templateImage io.ReadSeeker, fields map[string]FieldPos, data interface{}) error

AppendPage adds a page to a PDF

func (*FormFiller) Debug

func (f *FormFiller) Debug()

Debug draws boxes around each form field and overlays the fields name on the right.

func (*FormFiller) Output

func (f *FormFiller) Output(output io.Writer) error

Output outputs the form to the provided file

func (*FormFiller) ScaleText

func (f *FormFiller) ScaleText(displayValue string, _ float64, width float64)

ScaleText scales the text down to fit the cell if it is too long to fit in one line

type FormLayout

type FormLayout struct {
	TemplateImagePath string
	FieldsLayout      map[string]FieldPos
}

FormLayout houses both a background image form template and the layout of individual fields

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator encapsulates the prerequisites for PDF generation.

func NewGenerator

func NewGenerator(uploader *uploader.Uploader) (*Generator, error)

NewGenerator creates a new Generator.

func (*Generator) AddPdfBookmarks

func (g *Generator) AddPdfBookmarks(inputFile afero.File, bookmarks []pdfcpu.Bookmark) (afero.File, error)

Add bookmarks into a single PDF

func (*Generator) AddWatermarks

func (g *Generator) AddWatermarks(inputFile afero.File, m map[int][]*model.Watermark) (afero.File, error)

func (*Generator) Cleanup

func (g *Generator) Cleanup(_ appcontext.AppContext) error

Cleanup removes filesystem working dir

func (*Generator) ConvertUploadToPDF

func (g *Generator) ConvertUploadToPDF(appCtx appcontext.AppContext, upload models.Upload) (string, error)

func (*Generator) ConvertUploadsToPDF

func (g *Generator) ConvertUploadsToPDF(appCtx appcontext.AppContext, uploads models.Uploads) ([]string, error)

ConvertUploadsToPDF turns a slice of Uploads into a slice of paths to converted PDF files

func (*Generator) CreateMergedPDFUpload

func (g *Generator) CreateMergedPDFUpload(appCtx appcontext.AppContext, uploads models.Uploads) (afero.File, error)

CreateMergedPDFUpload converts Uploads to PDF and merges them into a single PDF

func (*Generator) CreateTextWatermark

func (g *Generator) CreateTextWatermark(text, desc string, onTop, update bool, u types.DisplayUnit) (*model.Watermark, error)

func (*Generator) FileSystem

func (g *Generator) FileSystem() *afero.Afero

Get PDF Configuration (For Testing)

func (*Generator) FillPDFForm

func (g *Generator) FillPDFForm(jsonData []byte, templateReader io.ReadSeeker) (SSWWorksheet afero.File, err error)

func (*Generator) GetPdfFileInfo

func (g *Generator) GetPdfFileInfo(fileName string) (*pdfcpu.PDFInfo, error)

Get file information of a single PDF

func (*Generator) GetPdfFileInfoByContents

func (g *Generator) GetPdfFileInfoByContents(file afero.File) (*pdfcpu.PDFInfo, error)

Get file information of a single PDF

func (*Generator) GetPdfFileInfoForReadSeeker

func (g *Generator) GetPdfFileInfoForReadSeeker(rs io.ReadSeeker) (*pdfcpu.PDFInfo, error)

func (*Generator) MergeImagesToPDF

func (g *Generator) MergeImagesToPDF(appCtx appcontext.AppContext, paths []string) (string, error)

MergeImagesToPDF creates a PDF containing the images at the specified paths.

The content type of the image is inferred from its extension. If this proves to be insufficient, storage.DetectContentType and contentTypeToImageType above can be used.

func (*Generator) MergePDFFiles

func (g *Generator) MergePDFFiles(_ appcontext.AppContext, paths []string) (afero.File, error)

MergePDFFiles Merges a slice of paths to PDF files into a single PDF

func (*Generator) MergePDFFilesByContents

func (g *Generator) MergePDFFilesByContents(_ appcontext.AppContext, fileReaders []io.ReadSeeker) (afero.File, error)

MergePDFFiles Merges a slice of paths to PDF files into a single PDF

func (*Generator) PDFFromImages

func (g *Generator) PDFFromImages(appCtx appcontext.AppContext, images []inputFile) (string, error)

PDFFromImages returns the path to tempfile PDF containing all images included in urls.

Images will be rotated to have as little white space as possible.

The files at those paths will be tempfiles that will need to be cleaned up by the caller.

func (*Generator) PdfConfiguration

func (g *Generator) PdfConfiguration() *model.Configuration

Get PDF Configuration (For Testing)

type InspectionInformationValues

type InspectionInformationValues struct {
	DateOfInspection                   string
	ReportSubmission                   string
	EvaluationType                     string
	TimeDepart                         string
	EvalStart                          string
	EvalEnd                            string
	EvaluationLocation                 string
	ObservedShipmentDeliveryDate       string
	ObservedShipmentPhysicalPickupDate string
	ObservedPickupDate                 string
	ObservedDeliveryDate               string
	QAERemarks                         string
	ViolationsObserved                 string
	SeriousIncident                    string
	SeriousIncidentDescription         string
}

func FormatValuesInspectionInformation

func FormatValuesInspectionInformation(report models.EvaluationReport) InspectionInformationValues

type PDFLibrary

type PDFLibrary interface {
	Merge(rsc []io.ReadSeeker, w io.Writer) error
	Validate(rs io.ReadSeeker) error
}

PDFLibrary is the PDF library interface

type ShipmentValues

type ShipmentValues struct {
	ShipmentID            string
	ShipmentType          string
	PickupAddress         string
	ScheduledPickupDate   string
	RequestedPickupDate   string
	ActualPickupDate      string
	ReleasingAgentName    string
	ReleasingAgentPhone   string
	ReleasingAgentEmail   string
	DeliveryAddress       string
	ScheduledDeliveryDate string
	RequiredDeliveryDate  string
	ActualDeliveryDate    string
	ReceivingAgentName    string
	ReceivingAgentPhone   string
	ReceivingAgentEmail   string
	PPMOriginZIP          string
	PPMDestinationZIP     string
	PPMDepartureDate      string
	ReleasingAgent        string
	ReceivingAgent        string
	StorageFacility       string
	StorageFacilityName   string
	ExternalVendor        bool
}

ShipmentValues holds formatted values to put in a shipment card

func FormatValuesShipment

func FormatValuesShipment(shipment models.MTOShipment) ShipmentValues

type TableRow

type TableRow struct {
	LeftFieldName  string
	LeftLabel      string
	RightFieldName string
	RightLabel     string
}

TableRow is used to express the layout of one row of a shipment card Each row of the shipment card has two side by side key,value pairs The *FieldName properties are used to look up the values in a struct The *Label properties contain the label to display in the form

func PickShipmentCardLayout

func PickShipmentCardLayout(shipmentType models.MTOShipmentType) []TableRow

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL