mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
fix: credit note printing
This commit is contained in:
257
shared/pdf-templates/src/components/CreditNotePaperTemplate.tsx
Normal file
257
shared/pdf-templates/src/components/CreditNotePaperTemplate.tsx
Normal file
@@ -0,0 +1,257 @@
|
||||
import {
|
||||
PaperTemplate,
|
||||
PaperTemplateProps,
|
||||
PaperTemplateTotalBorder,
|
||||
} from './PaperTemplate';
|
||||
import { Box } from '../lib/layout/Box';
|
||||
import { Text } from '../lib/text/Text';
|
||||
import { Stack } from '../lib/layout/Stack';
|
||||
import { Group } from '../lib/layout/Group';
|
||||
import {
|
||||
DefaultPdfTemplateTerms,
|
||||
DefaultPdfTemplateItemDescription,
|
||||
DefaultPdfTemplateItemName,
|
||||
DefaultPdfTemplateAddressBilledTo,
|
||||
DefaultPdfTemplateAddressBilledFrom,
|
||||
} from './_constants';
|
||||
|
||||
interface CreditNoteLine {
|
||||
item?: string;
|
||||
description?: string;
|
||||
quantity?: string;
|
||||
rate?: string;
|
||||
total?: string;
|
||||
}
|
||||
|
||||
export interface CreditNotePaperTemplateProps extends PaperTemplateProps {
|
||||
primaryColor?: string;
|
||||
secondaryColor?: string;
|
||||
|
||||
// Company
|
||||
showCompanyLogo?: boolean;
|
||||
companyLogoUri?: string;
|
||||
|
||||
companyName?: string;
|
||||
|
||||
// Credit Note number
|
||||
showCreditNoteNumber?: boolean;
|
||||
creditNoteNumebr?: string;
|
||||
creditNoteNumberLabel?: string;
|
||||
|
||||
// Credit Note date
|
||||
showCreditNoteDate?: boolean;
|
||||
creditNoteDate?: string;
|
||||
creditNoteDateLabel?: string;
|
||||
|
||||
// Address
|
||||
showCustomerAddress?: boolean;
|
||||
customerAddress?: string;
|
||||
|
||||
showCompanyAddress?: boolean;
|
||||
companyAddress?: string;
|
||||
|
||||
billedToLabel?: string;
|
||||
|
||||
// Entries
|
||||
lineItemLabel?: string;
|
||||
lineQuantityLabel?: string;
|
||||
lineRateLabel?: string;
|
||||
lineTotalLabel?: string;
|
||||
|
||||
// Subtotal
|
||||
showSubtotal?: boolean;
|
||||
subtotalLabel?: string;
|
||||
subtotal?: string;
|
||||
|
||||
// Total
|
||||
showTotal?: boolean;
|
||||
totalLabel?: string;
|
||||
total?: string;
|
||||
|
||||
// Customer Note
|
||||
showCustomerNote?: boolean;
|
||||
customerNote?: string;
|
||||
customerNoteLabel?: string;
|
||||
|
||||
// Terms & Conditions
|
||||
showTermsConditions?: boolean;
|
||||
termsConditions?: string;
|
||||
termsConditionsLabel?: string;
|
||||
|
||||
lines?: Array<CreditNoteLine>;
|
||||
}
|
||||
|
||||
export function CreditNotePaperTemplate({
|
||||
// # Colors
|
||||
primaryColor,
|
||||
secondaryColor,
|
||||
|
||||
// # Company
|
||||
companyName = 'Bigcapital Technology, Inc.',
|
||||
|
||||
showCompanyLogo = true,
|
||||
companyLogoUri = '',
|
||||
|
||||
// # Credit Note number
|
||||
creditNoteNumberLabel = 'Credit Note Number',
|
||||
creditNoteNumebr = '346D3D40-0001',
|
||||
showCreditNoteNumber = true,
|
||||
|
||||
// # Credit Note date
|
||||
creditNoteDate = 'September 3, 2024',
|
||||
creditNoteDateLabel = 'Credit Note Date',
|
||||
showCreditNoteDate = true,
|
||||
|
||||
// Address
|
||||
showCustomerAddress = true,
|
||||
customerAddress = DefaultPdfTemplateAddressBilledTo,
|
||||
|
||||
showCompanyAddress = true,
|
||||
companyAddress = DefaultPdfTemplateAddressBilledFrom,
|
||||
|
||||
billedToLabel = 'Billed To',
|
||||
|
||||
// Entries
|
||||
lineItemLabel = 'Item',
|
||||
lineQuantityLabel = 'Qty',
|
||||
lineRateLabel = 'Rate',
|
||||
lineTotalLabel = 'Total',
|
||||
|
||||
// Subtotal
|
||||
subtotalLabel = 'Subtotal',
|
||||
showSubtotal = true,
|
||||
subtotal = '1000.00',
|
||||
|
||||
// Total
|
||||
totalLabel = 'Total',
|
||||
showTotal = true,
|
||||
total = '$1000.00',
|
||||
|
||||
// Customer Note
|
||||
showCustomerNote = true,
|
||||
customerNote = '',
|
||||
customerNoteLabel = 'Customer Note',
|
||||
|
||||
// Terms & Conditions
|
||||
termsConditionsLabel = 'Terms & Conditions',
|
||||
showTermsConditions = true,
|
||||
termsConditions = DefaultPdfTemplateTerms,
|
||||
|
||||
lines = [
|
||||
{
|
||||
item: DefaultPdfTemplateItemName,
|
||||
description: DefaultPdfTemplateItemDescription,
|
||||
rate: '1',
|
||||
quantity: '1000',
|
||||
total: '$1000.00',
|
||||
},
|
||||
],
|
||||
...props
|
||||
}: CreditNotePaperTemplateProps) {
|
||||
return (
|
||||
<PaperTemplate
|
||||
primaryColor={primaryColor}
|
||||
secondaryColor={secondaryColor}
|
||||
{...props}
|
||||
>
|
||||
<Stack spacing={24}>
|
||||
<Group align="start" spacing={10}>
|
||||
<Stack flex={1}>
|
||||
<PaperTemplate.BigTitle title={'Credit Note'} />
|
||||
|
||||
<PaperTemplate.TermsList>
|
||||
{showCreditNoteNumber && (
|
||||
<PaperTemplate.TermsItem label={creditNoteNumberLabel}>
|
||||
{creditNoteNumebr}
|
||||
</PaperTemplate.TermsItem>
|
||||
)}
|
||||
{showCreditNoteDate && (
|
||||
<PaperTemplate.TermsItem label={creditNoteDateLabel}>
|
||||
{creditNoteDate}
|
||||
</PaperTemplate.TermsItem>
|
||||
)}
|
||||
</PaperTemplate.TermsList>
|
||||
</Stack>
|
||||
|
||||
{companyLogoUri && showCompanyLogo && (
|
||||
<PaperTemplate.Logo logoUri={companyLogoUri} />
|
||||
)}
|
||||
</Group>
|
||||
|
||||
<PaperTemplate.AddressesGroup>
|
||||
{showCompanyAddress && (
|
||||
<PaperTemplate.Address>
|
||||
<Box dangerouslySetInnerHTML={{ __html: companyAddress }} />
|
||||
</PaperTemplate.Address>
|
||||
)}
|
||||
{showCustomerAddress && (
|
||||
<PaperTemplate.Address>
|
||||
<strong>{billedToLabel}</strong>
|
||||
<Box dangerouslySetInnerHTML={{ __html: customerAddress }} />
|
||||
</PaperTemplate.Address>
|
||||
)}
|
||||
</PaperTemplate.AddressesGroup>
|
||||
|
||||
<Stack spacing={0}>
|
||||
<PaperTemplate.Table
|
||||
columns={[
|
||||
{
|
||||
label: lineItemLabel,
|
||||
accessor: (data) => (
|
||||
<Stack spacing={2}>
|
||||
<Text>{data.item}</Text>
|
||||
{data.description && (
|
||||
<Text color={'#5f6b7c'} fontSize={12}>
|
||||
{data.description}
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
),
|
||||
thStyle: { width: '60%' },
|
||||
},
|
||||
{
|
||||
label: lineQuantityLabel,
|
||||
accessor: 'quantity',
|
||||
align: 'right',
|
||||
},
|
||||
{ label: lineRateLabel, accessor: 'rate', align: 'right' },
|
||||
{ label: lineTotalLabel, accessor: 'total', align: 'right' },
|
||||
]}
|
||||
data={lines}
|
||||
/>
|
||||
<PaperTemplate.Totals>
|
||||
{showSubtotal && (
|
||||
<PaperTemplate.TotalLine
|
||||
label={subtotalLabel}
|
||||
amount={subtotal}
|
||||
border={PaperTemplateTotalBorder.Gray}
|
||||
/>
|
||||
)}
|
||||
{showTotal && (
|
||||
<PaperTemplate.TotalLine
|
||||
label={totalLabel}
|
||||
amount={total}
|
||||
border={PaperTemplateTotalBorder.Dark}
|
||||
style={{ fontWeight: 500 }}
|
||||
/>
|
||||
)}
|
||||
</PaperTemplate.Totals>
|
||||
</Stack>
|
||||
|
||||
<Stack spacing={0}>
|
||||
{showCustomerNote && customerNote && (
|
||||
<PaperTemplate.Statement label={customerNoteLabel}>
|
||||
{customerNote}
|
||||
</PaperTemplate.Statement>
|
||||
)}
|
||||
|
||||
{showTermsConditions && termsConditions && (
|
||||
<PaperTemplate.Statement label={termsConditionsLabel}>
|
||||
{termsConditions}
|
||||
</PaperTemplate.Statement>
|
||||
)}
|
||||
</Stack>
|
||||
</Stack>
|
||||
</PaperTemplate>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './components/PaperTemplate';
|
||||
export * from './components/InvoicePaperTemplate';
|
||||
export * from './components/CreditNotePaperTemplate';
|
||||
export * from './components/EstimatePaperTemplate';
|
||||
export * from './components/ReceiptPaperTemplate';
|
||||
export * from './components/PaymentReceivedPaperTemplate';
|
||||
@@ -7,6 +8,7 @@ export * from './components/FinancialSheetTemplate';
|
||||
export * from './components/ExportResourceTableTemplate';
|
||||
|
||||
export * from './renders/render-invoice-paper-template';
|
||||
export * from './renders/render-credit-note-paper-template';
|
||||
export * from './renders/render-estimate-paper-template';
|
||||
export * from './renders/render-receipt-paper-template';
|
||||
export * from './renders/render-payment-received-paper-template';
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
CreditNotePaperTemplate,
|
||||
CreditNotePaperTemplateProps,
|
||||
} from '../components/CreditNotePaperTemplate';
|
||||
import { renderSSR } from './render-ssr';
|
||||
|
||||
/**
|
||||
* Renders credit note paper template html.
|
||||
* @param {CreditNotePaperTemplateProps} props
|
||||
* @returns {string}
|
||||
*/
|
||||
export const renderCreditNotePaperTemplateHtml = (
|
||||
props: CreditNotePaperTemplateProps
|
||||
) => {
|
||||
return renderSSR(<CreditNotePaperTemplate {...props} />);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user