From 279890e922dd3ba4cd669740e289c1175337c6a0 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Thu, 17 Oct 2024 15:58:19 +0200 Subject: [PATCH 1/2] feat: Add qty column to preview pdf templates: --- .../CreditNotePaperTemplate.tsx | 34 +++++++++++++++-- .../EstimatePaperTemplate.tsx | 36 ++++++++++++++++-- .../InvoiceCustomize/InvoicePaperTemplate.tsx | 25 ++++++++++--- .../InvoiceCustomize/PaperTemplate.tsx | 13 ++++--- .../ReceiptCustomize/ReceiptPaperTemplate.tsx | 37 +++++++++++++++++-- 5 files changed, 122 insertions(+), 23 deletions(-) diff --git a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/CreditNotePaperTemplate.tsx b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/CreditNotePaperTemplate.tsx index 54d0eba59..aed120527 100644 --- a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/CreditNotePaperTemplate.tsx +++ b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/CreditNotePaperTemplate.tsx @@ -1,3 +1,4 @@ +import { Classes, Text } from '@blueprintjs/core'; import { Box, Group, Stack } from '@/components'; import { PaperTemplate, @@ -67,6 +68,12 @@ export interface CreditNotePaperTemplateProps extends PaperTemplateProps { creditNoteNumebr?: string; creditNoteNumberLabel?: string; showCreditNoteNumber?: boolean; + + // Entries + lineItemLabel?: string; + lineQuantityLabel?: string; + lineRateLabel?: string; + lineTotalLabel?: string; } export function CreditNotePaperTemplate({ @@ -127,6 +134,12 @@ export function CreditNotePaperTemplate({ creditNoteDate = 'September 3, 2024', showCreditNoteDate = true, creditNoteDateLabel = 'Credit Note Date', + + // Entries + lineItemLabel = 'Item', + lineQuantityLabel = 'Qty', + lineRateLabel = 'Rate', + lineTotalLabel = 'Total', }: CreditNotePaperTemplateProps) { return ( @@ -172,10 +185,23 @@ export function CreditNotePaperTemplate({ ( + + {data.item} + + {data.description} + + + ), + }, + { label: lineQuantityLabel, accessor: 'quantity' }, + { label: lineRateLabel, accessor: 'rate', align: 'right' }, + { label: lineTotalLabel, accessor: 'total', align: 'right' }, ]} data={lines} /> diff --git a/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/EstimatePaperTemplate.tsx b/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/EstimatePaperTemplate.tsx index adfda72c3..6a04a94e5 100644 --- a/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/EstimatePaperTemplate.tsx +++ b/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/EstimatePaperTemplate.tsx @@ -1,3 +1,4 @@ +import { Classes, Text } from '@blueprintjs/core'; import { Box, Group, Stack } from '@/components'; import { PaperTemplate, @@ -69,6 +70,13 @@ export interface EstimatePaperTemplateProps extends PaperTemplateProps { quantity: string; total: string; }>; + + // Lines + lineItemLabel?: string, + lineQuantityLabel?: string, + lineRateLabel?: string, + lineTotalLabel?: string, + } export function EstimatePaperTemplate({ @@ -134,6 +142,13 @@ export function EstimatePaperTemplate({ expirationDateLabel = 'Expiration Date', showExpirationDate = true, expirationDate = 'September 3, 2024', + + // Entries + lineItemLabel = 'Item', + lineQuantityLabel = 'Qty', + lineRateLabel = 'Rate', + lineTotalLabel = 'Total', + }: EstimatePaperTemplateProps) { return ( @@ -183,10 +198,23 @@ export function EstimatePaperTemplate({ ( + + {data.item} + + {data.description} + + + ), + }, + { label: lineQuantityLabel, accessor: 'quantity' }, + { label: lineRateLabel, accessor: 'rate', align: 'right' }, + { label: lineTotalLabel, accessor: 'total', align: 'right' }, ]} data={lines} /> diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/InvoicePaperTemplate.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/InvoicePaperTemplate.tsx index 3e646f0a9..ea2883658 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/InvoicePaperTemplate.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/InvoicePaperTemplate.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import { Classes, Text } from '@blueprintjs/core'; import { PaperTemplate, PaperTemplateTotalBorder } from './PaperTemplate'; import { Box, Group, Stack } from '@/components'; import { @@ -9,6 +9,7 @@ import { DefaultPdfTemplateAddressBilledTo, DefaultPdfTemplateAddressBilledFrom, } from '@/constants/PdfTemplates'; + interface PapaerLine { item?: string; description?: string; @@ -55,7 +56,7 @@ export interface InvoicePaperTemplateProps { // Entries lineItemLabel?: string; - lineDescriptionLabel?: string; + lineQuantityLabel?: string; lineRateLabel?: string; lineTotalLabel?: string; @@ -129,7 +130,7 @@ export function InvoicePaperTemplate({ // Entries lineItemLabel = 'Item', - lineDescriptionLabel = 'Description', + lineQuantityLabel = 'Qty', lineRateLabel = 'Rate', lineTotalLabel = 'Total', @@ -214,7 +215,6 @@ export function InvoicePaperTemplate({ )} - {showCustomerAddress && ( {billedToLabel} @@ -226,8 +226,21 @@ export function InvoicePaperTemplate({ ( + + {data.item} + + {data.description} + + + ), + }, + { label: lineQuantityLabel, accessor: 'quantity' }, { label: lineRateLabel, accessor: 'rate', align: 'right' }, { label: lineTotalLabel, accessor: 'total', align: 'right' }, ]} diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/PaperTemplate.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/PaperTemplate.tsx index 9d7d6e306..3e6465851 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/PaperTemplate.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/PaperTemplate.tsx @@ -1,6 +1,6 @@ import React from 'react'; import clsx from 'classnames'; -import { get } from 'lodash'; +import { get, isFunction } from 'lodash'; import { Box, Group, GroupProps } from '@/components'; import styles from './InvoicePaperTemplate.module.scss'; @@ -26,8 +26,9 @@ export function PaperTemplate({ interface PaperTemplateTableProps { columns: Array<{ - accessor: string; + accessor: string | ((data: Record) => JSX.Element); label: string; + value?: JSX.Element; align?: 'left' | 'center' | 'right'; }>; data: Array>; @@ -71,7 +72,9 @@ PaperTemplate.Table = ({ columns, data }: PaperTemplateTableProps) => { {columns.map((column, index) => ( - {get(_data, column.accessor)} + {isFunction(column?.accessor) + ? column?.accessor(_data) + : get(_data, column.accessor)} ))} @@ -115,9 +118,9 @@ PaperTemplate.TotalLine = ({ ); }; -PaperTemplate.MutedText = () => {}; +PaperTemplate.MutedText = () => { }; -PaperTemplate.Text = () => {}; +PaperTemplate.Text = () => { }; PaperTemplate.AddressesGroup = (props: GroupProps) => { return ( diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptPaperTemplate.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptPaperTemplate.tsx index 9dd66180c..8169db451 100644 --- a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptPaperTemplate.tsx +++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptPaperTemplate.tsx @@ -1,3 +1,4 @@ +import { Classes, Text } from '@blueprintjs/core'; import { Box, Group, Stack } from '@/components'; import { PaperTemplate, @@ -67,6 +68,12 @@ export interface ReceiptPaperTemplateProps extends PaperTemplateProps { receiptNumebr?: string; receiptNumberLabel?: string; showReceiptNumber?: boolean; + + // Entries + lineItemLabel?: string; + lineQuantityLabel?: string; + lineRateLabel?: string; + lineTotalLabel?: string; } export function ReceiptPaperTemplate({ @@ -115,13 +122,22 @@ export function ReceiptPaperTemplate({ total: '$1000.00', }, ], + + // Receipt Number showReceiptNumber = true, receiptNumberLabel = 'Receipt Number', receiptNumebr = '346D3D40-0001', + // Receipt Date receiptDate = 'September 3, 2024', showReceiptDate = true, receiptDateLabel = 'Receipt Date', + + // Entries + lineItemLabel = 'Item', + lineQuantityLabel = 'Qty', + lineRateLabel = 'Rate', + lineTotalLabel = 'Total', }: ReceiptPaperTemplateProps) { return ( @@ -167,10 +183,23 @@ export function ReceiptPaperTemplate({ ( + + {data.item} + + {data.description} + + + ), + }, + { label: lineQuantityLabel, accessor: 'quantity' }, + { label: lineRateLabel, accessor: 'rate', align: 'right' }, + { label: lineTotalLabel, accessor: 'total', align: 'right' }, ]} data={lines} /> From 758ebbe261737f92a83a7f2a2ada2ee05d488f29 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Thu, 17 Oct 2024 16:00:19 +0200 Subject: [PATCH 2/2] feat: Add qty column to server-side pdf templates --- .../views/modules/credit-note-standard.pug | 26 +++++++++++++------ .../views/modules/estimate-regular.pug | 17 +++++++++--- .../views/modules/invoice-standard.pug | 17 +++++++++--- .../views/modules/receipt-regular.pug | 21 +++++++++++---- .../src/services/Sales/Invoices/constants.ts | 2 +- 5 files changed, 63 insertions(+), 20 deletions(-) diff --git a/packages/server/resources/views/modules/credit-note-standard.pug b/packages/server/resources/views/modules/credit-note-standard.pug index 193e46251..bb1fc86f3 100644 --- a/packages/server/resources/views/modules/credit-note-standard.pug +++ b/packages/server/resources/views/modules/credit-note-standard.pug @@ -108,7 +108,14 @@ block head .#{prefix}-table__cell--right { text-align: right; } - + .#{prefix}-table__cell--item .item { + display: flex; + flex-direction: column; + gap: 2px; + } + .#{prefix}-table__cell--item .item .item__description{ + color: #5f6b7c; + } .#{prefix}-totals { display: flex; flex-direction: column; @@ -184,16 +191,19 @@ block content thead tr th(class=`${prefix}-table__header`) #{'Item'} - th(class=`${prefix}-table__header`) #{'Description'} - th(class=`${prefix}-table__header`) #{'Rate'} - th(class=`${prefix}-table__header`) #{'Total'} + th(class=`${prefix}-table__header ${prefix}-table__header--right`) #{'Quantity'} + th(class=`${prefix}-table__header ${prefix}-table__header--right`) #{'Rate'} + th(class=`${prefix}-table__header ${prefix}-table__header--right`) #{'Total'} tbody each line in lines tr(class=`${prefix}-table__row`) - td(class=`${prefix}-table__cell`) #{line.item} - td(class=`${prefix}-table__cell`) #{line.description} - td(class=`${prefix}-table__cell--right`) #{line.rate} - td(class=`${prefix}-table__cell--right`) #{line.total} + td(class=`${prefix}-table__cell ${prefix}-table__cell--item`) + div.item + div.item__label #{line.item} + div.item__description #{line.description} + td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.quantity} + td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.rate} + td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.total} div(class=`${prefix}-totals`) if showSubtotal diff --git a/packages/server/resources/views/modules/estimate-regular.pug b/packages/server/resources/views/modules/estimate-regular.pug index f086f29df..92eab0b9d 100644 --- a/packages/server/resources/views/modules/estimate-regular.pug +++ b/packages/server/resources/views/modules/estimate-regular.pug @@ -109,6 +109,14 @@ block head .#{prefix}-table__cell:last-of-type { padding-right: 0; } + .#{prefix}-table__cell--item .item { + display: flex; + flex-direction: column; + gap: 2px; + } + .#{prefix}-table__cell--item .item .item__description{ + color: #5f6b7c; + } .#{prefix}-totals { display: flex; flex-direction: column; @@ -193,14 +201,17 @@ block content thead tr th(class=`${prefix}-table__header`) Item - th(class=`${prefix}-table__header`) Description + th(class=`${prefix}-table__header ${prefix}-table__header--right`) Qty th(class=`${prefix}-table__header ${prefix}-table__header--right`) Rate th(class=`${prefix}-table__header ${prefix}-table__header--right`) Total tbody each line in lines tr - td(class=`${prefix}-table__cell`) #{line.item} - td(class=`${prefix}-table__cell`) #{line.description} + td(class=`${prefix}-table__cell ${prefix}-table__cell--item`) + div.item + div.item__label #{line.item} + div.item__description #{line.description} + td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.quantity} td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.rate} td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.total} diff --git a/packages/server/resources/views/modules/invoice-standard.pug b/packages/server/resources/views/modules/invoice-standard.pug index b24af4e5e..ad4f0881c 100644 --- a/packages/server/resources/views/modules/invoice-standard.pug +++ b/packages/server/resources/views/modules/invoice-standard.pug @@ -115,6 +115,14 @@ block head .#{prefix}-table__cell--right { text-align: right; } + .#{prefix}-table__cell--item .item { + display: flex; + flex-direction: column; + gap: 2px; + } + .#{prefix}-table__cell--item .item__description { + color: #5f6b7c; + } .#{prefix}-totals { display: flex; flex-direction: column; @@ -200,14 +208,17 @@ block content thead tr th(class=`${prefix}-table__header`) #{lineItemLabel} - th(class=`${prefix}-table__header`) #{lineDescriptionLabel} + th(class=`${prefix}-table__header ${prefix}-table__header--right`) #{lineQuantityLabel} th(class=`${prefix}-table__header ${prefix}-table__header--right`) #{lineRateLabel} th(class=`${prefix}-table__header ${prefix}-table__header--right`) #{lineTotalLabel} tbody each line in lines tr - td(class=`${prefix}-table__cell`) #{line.item} - td(class=`${prefix}-table__cell`) #{line.description} + td(class=`${prefix}-table__cell ${prefix}-table__cell--item`) + div.item + div.item__label #{line.item} + div.item__description #{line.description} + td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.quantity} td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.rate} td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.total} diff --git a/packages/server/resources/views/modules/receipt-regular.pug b/packages/server/resources/views/modules/receipt-regular.pug index 11351c2da..cd6432a59 100644 --- a/packages/server/resources/views/modules/receipt-regular.pug +++ b/packages/server/resources/views/modules/receipt-regular.pug @@ -105,6 +105,14 @@ block head .#{prefix}-table__cell--right { text-align: right; } + .#{prefix}-table__cell--item .item { + display: flex; + flex-direction: column; + gap: 2px; + } + .#{prefix}-table__cell--item .item .item__description{ + color: #5f6b7c; + } .#{prefix}-totals { display: flex; flex-direction: column; @@ -179,16 +187,19 @@ block content thead(class=`${prefix}-table__header`) tr th(class=`${prefix}-table__header`) Item - th(class=`${prefix}-table__header`) Description + th(class=`${prefix}-table__header ${prefix}-table__header--right`) Qty th(class=`${prefix}-table__header ${prefix}-table__header--right`) Rate th(class=`${prefix}-table__header ${prefix}-table__header--right`) Total tbody each line in lines tr(class=`${prefix}-table__row`) - td(class=`${prefix}-table__cell`)= line.item - td(class=`${prefix}-table__cell`)= line.description - td(class=`${prefix}-table__cell${prefix}-table__cell--right`)= line.rate - td(class=`${prefix}-table__cell${prefix}-table__cell--right`)= line.total + td(class=`${prefix}-table__cell ${prefix}-table__cell--item`) + div.item + div.item__label #{line.item} + div.item__description #{line.description} + td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.quantity} + td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.rate} + td(class=`${prefix}-table__cell ${prefix}-table__cell--right`) #{line.total} //- Totals Section div(class=`${prefix}-totals`) diff --git a/packages/server/src/services/Sales/Invoices/constants.ts b/packages/server/src/services/Sales/Invoices/constants.ts index becd1ebcf..4a67b6780 100644 --- a/packages/server/src/services/Sales/Invoices/constants.ts +++ b/packages/server/src/services/Sales/Invoices/constants.ts @@ -194,7 +194,7 @@ export const defaultInvoicePdfTemplateAttributes = { // Entries lineItemLabel: 'Item', - lineDescriptionLabel: 'Description', + lineQuantityLabel: 'Qty', lineRateLabel: 'Rate', lineTotalLabel: 'Total',