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

fix: [M3-7008] - Invoice and Payment id wrapping in generated PDFs #9702

Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ const addTitle = (doc: jsPDF, y: number, ...textStrings: Title[]) => {
textStrings.forEach((eachString) => {
doc.text(eachString.text, eachString.leftMargin || pageMargin, y, {
charSpace: 0.75,
maxWidth: 100,
});
y += 12;
});
// reset text format
doc.setFont(baseFont, 'normal');

return y;
};

// M3-6177 only make one request to get the logo
Expand Down Expand Up @@ -273,15 +275,20 @@ export const printInvoice = async (
);
const rightHeaderYPosition = addRightHeader(doc, account);

addTitle(doc, Math.max(leftHeaderYPosition, rightHeaderYPosition) + 4, {
text: `Invoice: #${invoiceId}`,
});
const titlePosition = addTitle(
doc,
Math.max(leftHeaderYPosition, rightHeaderYPosition) + 12,
Copy link
Member Author

@bnussman-akamai bnussman-akamai Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed 4 to 12 to match the payment PDFs. It helps make the PDF a bit more readable (see before and after photos above).

{
text: `Invoice: #${invoiceId}`,
}
);

createInvoiceItemsTable({
doc,
flags,
items: itemsChunk,
regions,
startY: titlePosition,
timezone,
});

Expand Down Expand Up @@ -336,11 +343,16 @@ export const printPayment = (
countryTax
);
const rightHeaderYPosition = addRightHeader(doc, account);
addTitle(doc, Math.max(leftHeaderYPosition, rightHeaderYPosition) + 12, {
text: `Receipt for Payment #${payment.id}`,
});

createPaymentsTable(doc, payment, timezone);
const titleYPosition = addTitle(
doc,
Math.max(leftHeaderYPosition, rightHeaderYPosition) + 12,
{
text: `Receipt for Payment #${payment.id}`,
}
);

createPaymentsTable(doc, payment, titleYPosition, timezone);
createFooter(doc, baseFont, account.country, payment.date);
createPaymentsTotalsTable(doc, payment);

Expand Down
11 changes: 8 additions & 3 deletions packages/manager/src/features/Billing/PdfGenerator/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const formatDateForTable = (
export const createPaymentsTable = (
doc: JSPDF,
payment: Payment,
startY: number,
timezone?: string
) => {
autoTable(doc, {
Expand All @@ -63,7 +64,7 @@ export const createPaymentsTable = (
headStyles: {
fillColor: '#444444',
},
startY: 165,
startY,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startY is now dynamic instead of hard-coded. This allows the table to be dynamically positioned so that the header text will not overlap with the table.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good choice, the dynamic value definitely improves the table's aesthetic.

styles: {
lineWidth: 1,
},
Expand Down Expand Up @@ -95,6 +96,10 @@ interface CreateInvoiceItemsTableOptions {
* Used to add Region labels to the `Region` column
*/
regions: Region[];
/**
* The start position of the table on the Y axis
*/
startY: number;
timezone?: string;
}

Expand All @@ -104,7 +109,7 @@ interface CreateInvoiceItemsTableOptions {
export const createInvoiceItemsTable = (
options: CreateInvoiceItemsTableOptions
) => {
const { doc, flags, items, regions, timezone } = options;
const { doc, flags, items, regions, timezone, startY } = options;

autoTable(doc, {
body: items.map((item) => {
Expand Down Expand Up @@ -182,7 +187,7 @@ export const createInvoiceItemsTable = (
headStyles: {
fillColor: '#444444',
},
startY: 165,
startY,
styles: {
lineWidth: 1,
},
Expand Down
15 changes: 13 additions & 2 deletions packages/manager/src/mocks/serverHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,11 @@ export const handlers = [
return res(ctx.delay(5000), ctx.json(transfer));
}),
rest.get('*/account/payments', (req, res, ctx) => {
const paymentWithLargeId = paymentFactory.build({
id: 123_456_789_123_456,
});
const payments = paymentFactory.buildList(5);
return res(ctx.json(makeResourcePage(payments)));
return res(ctx.json(makeResourcePage([paymentWithLargeId, ...payments])));
}),
rest.get('*/account/invoices', (req, res, ctx) => {
const linodeInvoice = invoiceFactory.build({
Expand All @@ -989,7 +992,15 @@ export const handlers = [
date: '2022-12-16T18:04:01',
label: 'AkamaiInvoice',
});
return res(ctx.json(makeResourcePage([linodeInvoice, akamaiInvoice])));
const invoiceWithLargerId = invoiceFactory.build({
id: 123_456_789_123_456,
label: 'Invoice with Large ID',
});
return res(
ctx.json(
makeResourcePage([linodeInvoice, akamaiInvoice, invoiceWithLargerId])
)
);
}),
rest.get('*/account/invoices/:invoiceId', (req, res, ctx) => {
const linodeInvoice = invoiceFactory.build({
Expand Down