Skip to content

Commit

Permalink
Merge pull request #716 from bigcapitalhq/add-quantity-column-pdf-tem…
Browse files Browse the repository at this point in the history
…plates

feat: Add quantity column to pdf templates
  • Loading branch information
abouolia authored Oct 17, 2024
2 parents 44fae36 + 758ebbe commit 4d6f65b
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 43 deletions.
26 changes: 18 additions & 8 deletions packages/server/resources/views/modules/credit-note-standard.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions packages/server/resources/views/modules/estimate-regular.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}

Expand Down
17 changes: 14 additions & 3 deletions packages/server/resources/views/modules/invoice-standard.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}

Expand Down
21 changes: 16 additions & 5 deletions packages/server/resources/views/modules/receipt-regular.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/services/Sales/Invoices/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const defaultInvoicePdfTemplateAttributes = {

// Entries
lineItemLabel: 'Item',
lineDescriptionLabel: 'Description',
lineQuantityLabel: 'Qty',
lineRateLabel: 'Rate',
lineTotalLabel: 'Total',

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Classes, Text } from '@blueprintjs/core';
import { Box, Group, Stack } from '@/components';
import {
PaperTemplate,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 (
<PaperTemplate primaryColor={primaryColor} secondaryColor={secondaryColor}>
Expand Down Expand Up @@ -172,10 +185,23 @@ export function CreditNotePaperTemplate({
<Stack spacing={0}>
<PaperTemplate.Table
columns={[
{ label: 'Item', accessor: 'item' },
{ label: 'Description', accessor: 'description' },
{ label: 'Rate', accessor: 'rate', align: 'right' },
{ label: 'Total', accessor: 'total', align: 'right' },
{
label: lineItemLabel,
accessor: (data) => (
<Stack spacing={2}>
<Text>{data.item}</Text>
<Text
className={Classes.TEXT_MUTED}
style={{ fontSize: 12 }}
>
{data.description}
</Text>
</Stack>
),
},
{ label: lineQuantityLabel, accessor: 'quantity' },
{ label: lineRateLabel, accessor: 'rate', align: 'right' },
{ label: lineTotalLabel, accessor: 'total', align: 'right' },
]}
data={lines}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Classes, Text } from '@blueprintjs/core';
import { Box, Group, Stack } from '@/components';
import {
PaperTemplate,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 (
<PaperTemplate primaryColor={primaryColor} secondaryColor={secondaryColor}>
Expand Down Expand Up @@ -183,10 +198,23 @@ export function EstimatePaperTemplate({
<Stack spacing={0}>
<PaperTemplate.Table
columns={[
{ label: 'Item', accessor: 'item' },
{ label: 'Description', accessor: 'description' },
{ label: 'Rate', accessor: 'rate', align: 'right' },
{ label: 'Total', accessor: 'total', align: 'right' },
{
label: lineItemLabel,
accessor: (data) => (
<Stack spacing={2}>
<Text>{data.item}</Text>
<Text
className={Classes.TEXT_MUTED}
style={{ fontSize: 12 }}
>
{data.description}
</Text>
</Stack>
),
},
{ label: lineQuantityLabel, accessor: 'quantity' },
{ label: lineRateLabel, accessor: 'rate', align: 'right' },
{ label: lineTotalLabel, accessor: 'total', align: 'right' },
]}
data={lines}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -9,6 +9,7 @@ import {
DefaultPdfTemplateAddressBilledTo,
DefaultPdfTemplateAddressBilledFrom,
} from '@/constants/PdfTemplates';

interface PapaerLine {
item?: string;
description?: string;
Expand Down Expand Up @@ -55,7 +56,7 @@ export interface InvoicePaperTemplateProps {

// Entries
lineItemLabel?: string;
lineDescriptionLabel?: string;
lineQuantityLabel?: string;
lineRateLabel?: string;
lineTotalLabel?: string;

Expand Down Expand Up @@ -129,7 +130,7 @@ export function InvoicePaperTemplate({

// Entries
lineItemLabel = 'Item',
lineDescriptionLabel = 'Description',
lineQuantityLabel = 'Qty',
lineRateLabel = 'Rate',
lineTotalLabel = 'Total',

Expand Down Expand Up @@ -214,7 +215,6 @@ export function InvoicePaperTemplate({
<Box dangerouslySetInnerHTML={{ __html: companyAddress }} />
</PaperTemplate.Address>
)}

{showCustomerAddress && (
<PaperTemplate.Address>
<strong>{billedToLabel}</strong>
Expand All @@ -226,8 +226,21 @@ export function InvoicePaperTemplate({
<Stack spacing={0}>
<PaperTemplate.Table
columns={[
{ label: lineItemLabel, accessor: 'item' },
{ label: lineDescriptionLabel, accessor: 'description' },
{
label: lineItemLabel,
accessor: (data) => (
<Stack spacing={2}>
<Text>{data.item}</Text>
<Text
className={Classes.TEXT_MUTED}
style={{ fontSize: 12 }}
>
{data.description}
</Text>
</Stack>
),
},
{ label: lineQuantityLabel, accessor: 'quantity' },
{ label: lineRateLabel, accessor: 'rate', align: 'right' },
{ label: lineTotalLabel, accessor: 'total', align: 'right' },
]}
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -26,8 +26,9 @@ export function PaperTemplate({

interface PaperTemplateTableProps {
columns: Array<{
accessor: string;
accessor: string | ((data: Record<string, any>) => JSX.Element);
label: string;
value?: JSX.Element;
align?: 'left' | 'center' | 'right';
}>;
data: Array<Record<string, any>>;
Expand Down Expand Up @@ -71,7 +72,9 @@ PaperTemplate.Table = ({ columns, data }: PaperTemplateTableProps) => {
<tr>
{columns.map((column, index) => (
<td align={column.align} key={index}>
{get(_data, column.accessor)}
{isFunction(column?.accessor)
? column?.accessor(_data)
: get(_data, column.accessor)}
</td>
))}
</tr>
Expand Down Expand Up @@ -115,9 +118,9 @@ PaperTemplate.TotalLine = ({
);
};

PaperTemplate.MutedText = () => {};
PaperTemplate.MutedText = () => { };

PaperTemplate.Text = () => {};
PaperTemplate.Text = () => { };

PaperTemplate.AddressesGroup = (props: GroupProps) => {
return (
Expand Down
Loading

0 comments on commit 4d6f65b

Please sign in to comment.