create-dfactory 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +37 -0
- package/package.json +50 -0
- package/templates/base/dfactory.config.ts +34 -0
- package/templates/react/src/templates/invoice/template.tsx +154 -0
- package/templates/react/src/templates/invoice-reference/components/InvoiceReferenceDocument.tsx +309 -0
- package/templates/react/src/templates/invoice-reference/components/InvoiceReferenceFooter.tsx +26 -0
- package/templates/react/src/templates/invoice-reference/components/InvoiceReferenceHeader.tsx +23 -0
- package/templates/react/src/templates/invoice-reference/components/InvoiceReferencePagination.tsx +24 -0
- package/templates/react/src/templates/invoice-reference/components/InvoiceReferenceToc.tsx +30 -0
- package/templates/react/src/templates/invoice-reference/components/InvoiceReferenceWatermark.tsx +16 -0
- package/templates/react/src/templates/invoice-reference/components/types.ts +65 -0
- package/templates/react/src/templates/invoice-reference/template.tsx +307 -0
- package/templates/vue/src/templates/invoice/InvoiceTemplate.vue +96 -0
- package/templates/vue/src/templates/invoice/template.ts +85 -0
- package/templates/vue/src/templates/invoice-reference/components/InvoiceReferenceDocument.vue +241 -0
- package/templates/vue/src/templates/invoice-reference/components/InvoiceReferenceFooter.vue +26 -0
- package/templates/vue/src/templates/invoice-reference/components/InvoiceReferenceHeader.vue +25 -0
- package/templates/vue/src/templates/invoice-reference/components/InvoiceReferencePagination.vue +24 -0
- package/templates/vue/src/templates/invoice-reference/components/InvoiceReferenceToc.vue +34 -0
- package/templates/vue/src/templates/invoice-reference/components/InvoiceReferenceWatermark.vue +20 -0
- package/templates/vue/src/templates/invoice-reference/components/types.ts +65 -0
- package/templates/vue/src/templates/invoice-reference/template.ts +300 -0
- package/templates/vue/src/vue-shims.d.ts +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 chiploopman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# create-dfactory
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Project bootstrap generator for adding dFactory into existing React/Vue projects.
|
|
6
|
+
|
|
7
|
+
It detects framework dependencies, updates package scripts/dependencies, and copies starter templates.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm create dfactory@latest
|
|
13
|
+
# or
|
|
14
|
+
pnpm create dfactory@latest
|
|
15
|
+
# or
|
|
16
|
+
yarn create dfactory
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Development
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm --filter create-dfactory typecheck
|
|
23
|
+
pnpm --filter create-dfactory test
|
|
24
|
+
pnpm --filter create-dfactory build
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
When changing generation behavior, add unit coverage under `tests/unit/create-dfactory*.test.ts`.
|
|
28
|
+
|
|
29
|
+
## Troubleshooting
|
|
30
|
+
|
|
31
|
+
- Wrong framework selected: verify target project dependencies before running initializer.
|
|
32
|
+
- Missing scripts/deps: rerun generator and inspect resulting `package.json` merge behavior.
|
|
33
|
+
|
|
34
|
+
## Related Documentation
|
|
35
|
+
|
|
36
|
+
- [Installation](/docs/installation)
|
|
37
|
+
- [Contributing](/docs/contributing)
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-dfactory",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/chiploopman/dfactory.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/chiploopman/dfactory#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/chiploopman/dfactory/issues"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"dfactory",
|
|
15
|
+
"pdf",
|
|
16
|
+
"templates",
|
|
17
|
+
"scaffold"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=20"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"bin": {
|
|
24
|
+
"create-dfactory": "dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"main": "dist/index.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"templates"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"picocolors": "^1.1.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"tsup": "^8.3.5",
|
|
40
|
+
"tsx": "^4.20.5"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
44
|
+
"dev": "tsx src/index.ts",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
46
|
+
"lint": "eslint .",
|
|
47
|
+
"test": "vitest run --passWithNoTests",
|
|
48
|
+
"clean": "rm -rf dist"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DFactoryConfig } from "@dfactory/core";
|
|
2
|
+
|
|
3
|
+
const config: DFactoryConfig = {
|
|
4
|
+
templates: {
|
|
5
|
+
globs: ["src/templates/*/template.{ts,tsx,js,jsx,mts,mtsx}"],
|
|
6
|
+
compatibilityGlobEnabled: false
|
|
7
|
+
},
|
|
8
|
+
plugins: ["{{frameworkPluginPackage}}"],
|
|
9
|
+
moduleLoader: "{{moduleLoaderPackage}}",
|
|
10
|
+
auth: {
|
|
11
|
+
mode: "apiKey",
|
|
12
|
+
apiKeys: []
|
|
13
|
+
},
|
|
14
|
+
ui: {
|
|
15
|
+
exposeInProd: true,
|
|
16
|
+
sourceInProd: false,
|
|
17
|
+
playgroundInProd: false
|
|
18
|
+
},
|
|
19
|
+
renderer: {
|
|
20
|
+
engine: "playwright",
|
|
21
|
+
poolSize: 4,
|
|
22
|
+
timeoutMs: 30000,
|
|
23
|
+
pdfPlugins: ["@dfactory/pdf-feature-standard"],
|
|
24
|
+
defaults: {
|
|
25
|
+
format: "A4",
|
|
26
|
+
printBackground: true,
|
|
27
|
+
preferCSSPageSize: true,
|
|
28
|
+
tagged: true,
|
|
29
|
+
outline: true
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default config;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AvoidBreakInside,
|
|
5
|
+
Document,
|
|
6
|
+
Heading,
|
|
7
|
+
KeepWithNext,
|
|
8
|
+
NumericCell,
|
|
9
|
+
Page,
|
|
10
|
+
PageBreakBefore,
|
|
11
|
+
Paragraph,
|
|
12
|
+
Section,
|
|
13
|
+
Table,
|
|
14
|
+
TableBody,
|
|
15
|
+
TableCell,
|
|
16
|
+
TableHead,
|
|
17
|
+
TableHeaderCell,
|
|
18
|
+
TableRow
|
|
19
|
+
} from "@dfactory/pdf-primitives-react";
|
|
20
|
+
import { defineTemplate } from "@dfactory/template-kit";
|
|
21
|
+
|
|
22
|
+
const template = defineTemplate({
|
|
23
|
+
meta: {
|
|
24
|
+
id: "invoice",
|
|
25
|
+
title: "Invoice",
|
|
26
|
+
description: "Default starter invoice template",
|
|
27
|
+
framework: "react",
|
|
28
|
+
version: "1.0.0",
|
|
29
|
+
tags: ["billing", "starter"]
|
|
30
|
+
},
|
|
31
|
+
schema: z.object({
|
|
32
|
+
invoiceNumber: z.string(),
|
|
33
|
+
customerName: z.string(),
|
|
34
|
+
issuedAt: z.string(),
|
|
35
|
+
items: z.array(
|
|
36
|
+
z.object({
|
|
37
|
+
name: z.string(),
|
|
38
|
+
qty: z.number(),
|
|
39
|
+
price: z.number()
|
|
40
|
+
})
|
|
41
|
+
)
|
|
42
|
+
}),
|
|
43
|
+
pdf: {
|
|
44
|
+
page: {
|
|
45
|
+
size: "A4",
|
|
46
|
+
marginsMm: { top: 12, right: 12, bottom: 14, left: 12 }
|
|
47
|
+
},
|
|
48
|
+
toc: {
|
|
49
|
+
enabled: true,
|
|
50
|
+
maxDepth: 2,
|
|
51
|
+
title: "Invoice Overview"
|
|
52
|
+
},
|
|
53
|
+
pagination: {
|
|
54
|
+
mode: "css"
|
|
55
|
+
},
|
|
56
|
+
headerFooter: {
|
|
57
|
+
enabled: true,
|
|
58
|
+
footerTemplate:
|
|
59
|
+
"<div style=\"width:100%;font-size:9px;padding:0 12px;color:#64748b;display:flex;justify-content:space-between;\"><span>{{title}}</span><span>{{pageXofY}}</span></div>"
|
|
60
|
+
},
|
|
61
|
+
metadata: {
|
|
62
|
+
title: "Invoice Document",
|
|
63
|
+
keywords: ["invoice", "billing", "starter"]
|
|
64
|
+
},
|
|
65
|
+
theme: {
|
|
66
|
+
font: {
|
|
67
|
+
family: "Inter, 'Segoe UI', sans-serif"
|
|
68
|
+
},
|
|
69
|
+
color: {
|
|
70
|
+
accent: "#1d4ed8"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
examples: [
|
|
75
|
+
{
|
|
76
|
+
name: "default",
|
|
77
|
+
payload: {
|
|
78
|
+
invoiceNumber: "INV-1001",
|
|
79
|
+
customerName: "Northwind Trading",
|
|
80
|
+
issuedAt: "2026-03-27",
|
|
81
|
+
items: [
|
|
82
|
+
{ name: "Consulting", qty: 2, price: 420 },
|
|
83
|
+
{ name: "Support", qty: 1, price: 180 }
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
render(payload) {
|
|
89
|
+
const total = payload.items.reduce((sum, item) => sum + item.qty * item.price, 0);
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<Document>
|
|
93
|
+
<Page>
|
|
94
|
+
<Section style={{ padding: "24px" }}>
|
|
95
|
+
<KeepWithNext>
|
|
96
|
+
<Heading as="h1" style={{ marginBottom: "8px", color: "var(--df-pdf-color-accent)" }}>
|
|
97
|
+
Invoice {payload.invoiceNumber}
|
|
98
|
+
</Heading>
|
|
99
|
+
<Paragraph style={{ color: "var(--df-pdf-color-muted)", marginTop: 0 }}>
|
|
100
|
+
Customer: {payload.customerName}
|
|
101
|
+
</Paragraph>
|
|
102
|
+
<Paragraph style={{ color: "var(--df-pdf-color-muted)", marginTop: "4px" }}>
|
|
103
|
+
Issued: {payload.issuedAt}
|
|
104
|
+
</Paragraph>
|
|
105
|
+
</KeepWithNext>
|
|
106
|
+
|
|
107
|
+
<AvoidBreakInside>
|
|
108
|
+
<Heading as="h2" style={{ marginTop: "20px", marginBottom: "8px", fontSize: "16px" }}>
|
|
109
|
+
Line Items
|
|
110
|
+
</Heading>
|
|
111
|
+
<Table style={{ marginTop: "10px" }}>
|
|
112
|
+
<TableHead>
|
|
113
|
+
<TableRow>
|
|
114
|
+
<TableHeaderCell style={{ textAlign: "left" }}>Item</TableHeaderCell>
|
|
115
|
+
<TableHeaderCell style={{ textAlign: "right" }}>Qty</TableHeaderCell>
|
|
116
|
+
<TableHeaderCell style={{ textAlign: "right" }}>Price</TableHeaderCell>
|
|
117
|
+
</TableRow>
|
|
118
|
+
</TableHead>
|
|
119
|
+
<TableBody>
|
|
120
|
+
{payload.items.map((item) => (
|
|
121
|
+
<TableRow key={item.name}>
|
|
122
|
+
<TableCell>{item.name}</TableCell>
|
|
123
|
+
<NumericCell>{item.qty}</NumericCell>
|
|
124
|
+
<NumericCell>${(item.price * item.qty).toFixed(2)}</NumericCell>
|
|
125
|
+
</TableRow>
|
|
126
|
+
))}
|
|
127
|
+
</TableBody>
|
|
128
|
+
</Table>
|
|
129
|
+
<Paragraph style={{ textAlign: "right", marginTop: "16px", fontWeight: 700 }}>
|
|
130
|
+
Total: ${total.toFixed(2)}
|
|
131
|
+
</Paragraph>
|
|
132
|
+
</AvoidBreakInside>
|
|
133
|
+
|
|
134
|
+
<PageBreakBefore>
|
|
135
|
+
<Heading as="h2" style={{ marginTop: "24px", fontSize: "16px" }}>
|
|
136
|
+
Payment Terms
|
|
137
|
+
</Heading>
|
|
138
|
+
<Paragraph style={{ color: "var(--df-pdf-color-text)", lineHeight: 1.6 }}>
|
|
139
|
+
Payment due within 14 calendar days from invoice date. Late payments may incur
|
|
140
|
+
additional charges.
|
|
141
|
+
</Paragraph>
|
|
142
|
+
</PageBreakBefore>
|
|
143
|
+
</Section>
|
|
144
|
+
</Page>
|
|
145
|
+
</Document>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
export const meta = template.meta;
|
|
151
|
+
export const schema = template.schema;
|
|
152
|
+
export const pdf = template.pdf;
|
|
153
|
+
export const examples = template.examples;
|
|
154
|
+
export const render = template.render;
|
package/templates/react/src/templates/invoice-reference/components/InvoiceReferenceDocument.tsx
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AvoidBreakInside,
|
|
3
|
+
Divider,
|
|
4
|
+
Document,
|
|
5
|
+
KeepWithNext,
|
|
6
|
+
Page,
|
|
7
|
+
PageBreakBefore
|
|
8
|
+
} from "@dfactory/pdf-primitives-react";
|
|
9
|
+
|
|
10
|
+
import type { InvoiceReferencePayload } from "./types";
|
|
11
|
+
|
|
12
|
+
function formatMoney(value: number, currency: string): string {
|
|
13
|
+
return new Intl.NumberFormat("en-US", {
|
|
14
|
+
style: "currency",
|
|
15
|
+
currency
|
|
16
|
+
}).format(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function calculateLineTotal(options: {
|
|
20
|
+
qty: number;
|
|
21
|
+
unitPrice: number;
|
|
22
|
+
discount?: number;
|
|
23
|
+
taxRate?: number;
|
|
24
|
+
}): number {
|
|
25
|
+
const gross = options.qty * options.unitPrice;
|
|
26
|
+
const discount = options.discount ?? 0;
|
|
27
|
+
const discounted = gross - gross * (discount / 100);
|
|
28
|
+
const taxRate = options.taxRate ?? 0;
|
|
29
|
+
return discounted + discounted * (taxRate / 100);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function InvoiceReferenceDocument(props: {
|
|
33
|
+
payload: InvoiceReferencePayload;
|
|
34
|
+
}) {
|
|
35
|
+
const accent = props.payload.brand?.accentColor ?? "#4f46e5";
|
|
36
|
+
const subtotal = props.payload.items.reduce(
|
|
37
|
+
(sum, item) => sum + item.qty * item.unitPrice,
|
|
38
|
+
0
|
|
39
|
+
);
|
|
40
|
+
const total = props.payload.items.reduce(
|
|
41
|
+
(sum, item) =>
|
|
42
|
+
sum +
|
|
43
|
+
calculateLineTotal({
|
|
44
|
+
qty: item.qty,
|
|
45
|
+
unitPrice: item.unitPrice,
|
|
46
|
+
discount: item.discount,
|
|
47
|
+
taxRate: item.taxRate
|
|
48
|
+
}),
|
|
49
|
+
0
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Document>
|
|
54
|
+
<Page>
|
|
55
|
+
<KeepWithNext
|
|
56
|
+
as="header"
|
|
57
|
+
style={{
|
|
58
|
+
borderBottom: "2px solid #e2e8f0",
|
|
59
|
+
paddingBottom: "16px",
|
|
60
|
+
marginBottom: "18px"
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
<h1 style={{ margin: 0, color: accent }}>Invoice {props.payload.invoiceNumber}</h1>
|
|
64
|
+
<p style={{ margin: "6px 0 0", color: "#475569" }}>
|
|
65
|
+
Issued {props.payload.issuedAt} • Due {props.payload.dueAt}
|
|
66
|
+
</p>
|
|
67
|
+
{props.payload.purchaseOrder ? (
|
|
68
|
+
<p style={{ margin: "4px 0 0", color: "#64748b" }}>
|
|
69
|
+
Purchase Order: {props.payload.purchaseOrder}
|
|
70
|
+
</p>
|
|
71
|
+
) : null}
|
|
72
|
+
</KeepWithNext>
|
|
73
|
+
|
|
74
|
+
<section
|
|
75
|
+
style={{
|
|
76
|
+
display: "grid",
|
|
77
|
+
gridTemplateColumns: "1fr 1fr",
|
|
78
|
+
gap: "18px",
|
|
79
|
+
marginBottom: "16px"
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
<AvoidBreakInside as="article">
|
|
83
|
+
<h2 style={{ fontSize: "16px", marginBottom: "8px" }}>Bill From</h2>
|
|
84
|
+
<p style={{ margin: 0, fontWeight: 600 }}>{props.payload.company.name}</p>
|
|
85
|
+
<p style={{ margin: "4px 0 0", color: "#475569", whiteSpace: "pre-line" }}>
|
|
86
|
+
{props.payload.company.address}
|
|
87
|
+
</p>
|
|
88
|
+
<p style={{ margin: "8px 0 0", color: "#334155" }}>
|
|
89
|
+
{props.payload.company.email} • {props.payload.company.phone}
|
|
90
|
+
</p>
|
|
91
|
+
<p style={{ margin: "4px 0 0", color: "#64748b" }}>
|
|
92
|
+
{props.payload.company.website} • Tax ID {props.payload.company.taxId}
|
|
93
|
+
</p>
|
|
94
|
+
</AvoidBreakInside>
|
|
95
|
+
|
|
96
|
+
<AvoidBreakInside as="article">
|
|
97
|
+
<h2 style={{ fontSize: "16px", marginBottom: "8px" }}>Bill To</h2>
|
|
98
|
+
<p style={{ margin: 0, fontWeight: 600 }}>{props.payload.customer.name}</p>
|
|
99
|
+
<p style={{ margin: "4px 0 0", color: "#475569" }}>
|
|
100
|
+
Contact: {props.payload.customer.contact}
|
|
101
|
+
</p>
|
|
102
|
+
<p style={{ margin: "4px 0 0", color: "#334155" }}>{props.payload.customer.email}</p>
|
|
103
|
+
<p style={{ margin: "4px 0 0", color: "#64748b", whiteSpace: "pre-line" }}>
|
|
104
|
+
{props.payload.customer.address}
|
|
105
|
+
</p>
|
|
106
|
+
</AvoidBreakInside>
|
|
107
|
+
</section>
|
|
108
|
+
|
|
109
|
+
<AvoidBreakInside as="section">
|
|
110
|
+
<h2 style={{ fontSize: "16px", margin: "20px 0 8px" }}>Services & Deliverables</h2>
|
|
111
|
+
<table
|
|
112
|
+
style={{
|
|
113
|
+
width: "100%",
|
|
114
|
+
borderCollapse: "collapse",
|
|
115
|
+
border: "1px solid #e2e8f0",
|
|
116
|
+
borderRadius: "8px",
|
|
117
|
+
overflow: "hidden"
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
<thead style={{ backgroundColor: "#eef2ff" }}>
|
|
121
|
+
<tr>
|
|
122
|
+
<th style={{ textAlign: "left", padding: "10px 12px" }}>Description</th>
|
|
123
|
+
<th style={{ textAlign: "right", padding: "10px 12px" }}>Qty</th>
|
|
124
|
+
<th style={{ textAlign: "right", padding: "10px 12px" }}>Unit</th>
|
|
125
|
+
<th style={{ textAlign: "right", padding: "10px 12px" }}>Discount</th>
|
|
126
|
+
<th style={{ textAlign: "right", padding: "10px 12px" }}>Tax</th>
|
|
127
|
+
<th style={{ textAlign: "right", padding: "10px 12px" }}>Line Total</th>
|
|
128
|
+
</tr>
|
|
129
|
+
</thead>
|
|
130
|
+
<tbody>
|
|
131
|
+
{props.payload.items.map((item) => (
|
|
132
|
+
<tr key={item.id}>
|
|
133
|
+
<td style={{ padding: "10px 12px", borderTop: "1px solid #e2e8f0" }}>
|
|
134
|
+
<p style={{ margin: 0, fontWeight: 600 }}>{item.name}</p>
|
|
135
|
+
{item.description ? (
|
|
136
|
+
<p style={{ margin: "4px 0 0", color: "#64748b" }}>{item.description}</p>
|
|
137
|
+
) : null}
|
|
138
|
+
</td>
|
|
139
|
+
<td
|
|
140
|
+
style={{
|
|
141
|
+
textAlign: "right",
|
|
142
|
+
padding: "10px 12px",
|
|
143
|
+
borderTop: "1px solid #e2e8f0"
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
{item.qty}
|
|
147
|
+
</td>
|
|
148
|
+
<td
|
|
149
|
+
style={{
|
|
150
|
+
textAlign: "right",
|
|
151
|
+
padding: "10px 12px",
|
|
152
|
+
borderTop: "1px solid #e2e8f0"
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
{formatMoney(item.unitPrice, props.payload.currency)}
|
|
156
|
+
</td>
|
|
157
|
+
<td
|
|
158
|
+
style={{
|
|
159
|
+
textAlign: "right",
|
|
160
|
+
padding: "10px 12px",
|
|
161
|
+
borderTop: "1px solid #e2e8f0"
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
{(item.discount ?? 0).toFixed(1)}%
|
|
165
|
+
</td>
|
|
166
|
+
<td
|
|
167
|
+
style={{
|
|
168
|
+
textAlign: "right",
|
|
169
|
+
padding: "10px 12px",
|
|
170
|
+
borderTop: "1px solid #e2e8f0"
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
{(item.taxRate ?? 0).toFixed(1)}%
|
|
174
|
+
</td>
|
|
175
|
+
<td
|
|
176
|
+
style={{
|
|
177
|
+
textAlign: "right",
|
|
178
|
+
padding: "10px 12px",
|
|
179
|
+
borderTop: "1px solid #e2e8f0",
|
|
180
|
+
fontWeight: 600
|
|
181
|
+
}}
|
|
182
|
+
>
|
|
183
|
+
{formatMoney(
|
|
184
|
+
calculateLineTotal({
|
|
185
|
+
qty: item.qty,
|
|
186
|
+
unitPrice: item.unitPrice,
|
|
187
|
+
discount: item.discount,
|
|
188
|
+
taxRate: item.taxRate
|
|
189
|
+
}),
|
|
190
|
+
props.payload.currency
|
|
191
|
+
)}
|
|
192
|
+
</td>
|
|
193
|
+
</tr>
|
|
194
|
+
))}
|
|
195
|
+
</tbody>
|
|
196
|
+
</table>
|
|
197
|
+
</AvoidBreakInside>
|
|
198
|
+
|
|
199
|
+
<section
|
|
200
|
+
style={{
|
|
201
|
+
marginTop: "16px",
|
|
202
|
+
display: "grid",
|
|
203
|
+
gridTemplateColumns: "1fr 280px",
|
|
204
|
+
gap: "24px"
|
|
205
|
+
}}
|
|
206
|
+
>
|
|
207
|
+
<article>
|
|
208
|
+
<h2 style={{ fontSize: "16px", marginBottom: "8px" }}>Summary Notes</h2>
|
|
209
|
+
<p style={{ color: "#475569", marginTop: 0 }}>
|
|
210
|
+
The sections below intentionally include long-form text to provide a strong
|
|
211
|
+
multi-page reference for TOC, pagination, and marker helpers.
|
|
212
|
+
</p>
|
|
213
|
+
{props.payload.sections.map((section, index) => {
|
|
214
|
+
const sectionStyle = {
|
|
215
|
+
marginTop: "14px",
|
|
216
|
+
padding: "12px",
|
|
217
|
+
border: "1px solid #e2e8f0",
|
|
218
|
+
borderRadius: "8px",
|
|
219
|
+
background: "#f8fafc"
|
|
220
|
+
} as const;
|
|
221
|
+
|
|
222
|
+
if (index === 2) {
|
|
223
|
+
return (
|
|
224
|
+
<PageBreakBefore key={`${section.title}-${index}`} as="section" style={sectionStyle}>
|
|
225
|
+
<h3 style={{ marginTop: 0, marginBottom: "8px", color: "#1e293b" }}>
|
|
226
|
+
{section.title}
|
|
227
|
+
</h3>
|
|
228
|
+
<p style={{ margin: 0, color: "#334155" }}>{section.description}</p>
|
|
229
|
+
{section.notes ? (
|
|
230
|
+
<p style={{ margin: "8px 0 0", color: "#64748b" }}>{section.notes}</p>
|
|
231
|
+
) : null}
|
|
232
|
+
</PageBreakBefore>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<section key={`${section.title}-${index}`} style={sectionStyle}>
|
|
238
|
+
<h3 style={{ marginTop: 0, marginBottom: "8px", color: "#1e293b" }}>
|
|
239
|
+
{section.title}
|
|
240
|
+
</h3>
|
|
241
|
+
<p style={{ margin: 0, color: "#334155" }}>{section.description}</p>
|
|
242
|
+
{section.notes ? (
|
|
243
|
+
<p style={{ margin: "8px 0 0", color: "#64748b" }}>{section.notes}</p>
|
|
244
|
+
) : null}
|
|
245
|
+
</section>
|
|
246
|
+
);
|
|
247
|
+
})}
|
|
248
|
+
</article>
|
|
249
|
+
|
|
250
|
+
<KeepWithNext
|
|
251
|
+
as="aside"
|
|
252
|
+
style={{
|
|
253
|
+
border: "1px solid #dbeafe",
|
|
254
|
+
background: "#eff6ff",
|
|
255
|
+
borderRadius: "10px",
|
|
256
|
+
padding: "14px"
|
|
257
|
+
}}
|
|
258
|
+
>
|
|
259
|
+
<h2 style={{ margin: 0, fontSize: "15px" }}>Totals</h2>
|
|
260
|
+
<p style={{ margin: "10px 0 0", color: "#475569" }}>
|
|
261
|
+
Subtotal: <strong>{formatMoney(subtotal, props.payload.currency)}</strong>
|
|
262
|
+
</p>
|
|
263
|
+
<p style={{ margin: "6px 0 0", color: "#475569" }}>
|
|
264
|
+
Grand Total: <strong>{formatMoney(total, props.payload.currency)}</strong>
|
|
265
|
+
</p>
|
|
266
|
+
<Divider
|
|
267
|
+
style={{
|
|
268
|
+
borderTopColor: "rgba(71, 85, 105, 0.2)",
|
|
269
|
+
marginTop: "10px",
|
|
270
|
+
marginBottom: "8px"
|
|
271
|
+
}}
|
|
272
|
+
/>
|
|
273
|
+
<p style={{ margin: "10px 0 0", color: "#1e293b", fontWeight: 600 }}>
|
|
274
|
+
Payment via {props.payload.payment.bankName}
|
|
275
|
+
</p>
|
|
276
|
+
<p style={{ margin: "4px 0 0", color: "#475569" }}>
|
|
277
|
+
IBAN: {props.payload.payment.iban}
|
|
278
|
+
</p>
|
|
279
|
+
<p style={{ margin: "4px 0 0", color: "#475569" }}>
|
|
280
|
+
SWIFT: {props.payload.payment.swift}
|
|
281
|
+
</p>
|
|
282
|
+
{props.payload.payment.instructions ? (
|
|
283
|
+
<p style={{ margin: "8px 0 0", color: "#64748b" }}>
|
|
284
|
+
{props.payload.payment.instructions}
|
|
285
|
+
</p>
|
|
286
|
+
) : null}
|
|
287
|
+
</KeepWithNext>
|
|
288
|
+
</section>
|
|
289
|
+
|
|
290
|
+
{props.payload.notes ? (
|
|
291
|
+
<PageBreakBefore
|
|
292
|
+
as="section"
|
|
293
|
+
style={{
|
|
294
|
+
marginTop: "20px",
|
|
295
|
+
padding: "16px",
|
|
296
|
+
border: "1px dashed #cbd5e1",
|
|
297
|
+
borderRadius: "10px"
|
|
298
|
+
}}
|
|
299
|
+
>
|
|
300
|
+
<h2 style={{ marginTop: 0, fontSize: "16px" }}>Additional Terms</h2>
|
|
301
|
+
<p style={{ marginBottom: 0, color: "#334155", whiteSpace: "pre-line" }}>
|
|
302
|
+
{props.payload.notes}
|
|
303
|
+
</p>
|
|
304
|
+
</PageBreakBefore>
|
|
305
|
+
) : null}
|
|
306
|
+
</Page>
|
|
307
|
+
</Document>
|
|
308
|
+
);
|
|
309
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function InvoiceReferenceFooter(props: {
|
|
2
|
+
templateId: string;
|
|
3
|
+
pageNumberToken: string;
|
|
4
|
+
totalPagesToken: string;
|
|
5
|
+
supportEmail?: string;
|
|
6
|
+
}) {
|
|
7
|
+
return (
|
|
8
|
+
<div
|
|
9
|
+
style={{
|
|
10
|
+
width: "100%",
|
|
11
|
+
padding: "0 14px",
|
|
12
|
+
fontSize: "9px",
|
|
13
|
+
color: "#475569",
|
|
14
|
+
display: "flex",
|
|
15
|
+
justifyContent: "space-between",
|
|
16
|
+
alignItems: "center"
|
|
17
|
+
}}
|
|
18
|
+
>
|
|
19
|
+
<span>{props.supportEmail ?? "billing@dfactory.dev"}</span>
|
|
20
|
+
<span>{props.templateId}</span>
|
|
21
|
+
<span>
|
|
22
|
+
{props.pageNumberToken} / {props.totalPagesToken}
|
|
23
|
+
</span>
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function InvoiceReferenceHeader(props: {
|
|
2
|
+
title: string;
|
|
3
|
+
invoiceNumber: string;
|
|
4
|
+
generatedAtToken: string;
|
|
5
|
+
}) {
|
|
6
|
+
return (
|
|
7
|
+
<div
|
|
8
|
+
style={{
|
|
9
|
+
width: "100%",
|
|
10
|
+
padding: "0 14px",
|
|
11
|
+
fontSize: "9px",
|
|
12
|
+
color: "#475569",
|
|
13
|
+
display: "flex",
|
|
14
|
+
justifyContent: "space-between",
|
|
15
|
+
alignItems: "center"
|
|
16
|
+
}}
|
|
17
|
+
>
|
|
18
|
+
<span>{props.title}</span>
|
|
19
|
+
<span>{props.invoiceNumber}</span>
|
|
20
|
+
<span>{props.generatedAtToken}</span>
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
}
|
package/templates/react/src/templates/invoice-reference/components/InvoiceReferencePagination.tsx
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AvoidBreakInside } from "@dfactory/pdf-primitives-react";
|
|
2
|
+
|
|
3
|
+
export function InvoiceReferencePagination(props: {
|
|
4
|
+
pageNumberToken: string;
|
|
5
|
+
totalPagesToken: string;
|
|
6
|
+
}) {
|
|
7
|
+
return (
|
|
8
|
+
<AvoidBreakInside
|
|
9
|
+
style={{
|
|
10
|
+
width: "100%",
|
|
11
|
+
padding: "4px 16px 8px",
|
|
12
|
+
fontSize: "9px",
|
|
13
|
+
color: "#64748b",
|
|
14
|
+
display: "flex",
|
|
15
|
+
justifyContent: "space-between"
|
|
16
|
+
}}
|
|
17
|
+
>
|
|
18
|
+
<span>DFactory Reference Pagination Layer</span>
|
|
19
|
+
<span>
|
|
20
|
+
Page {props.pageNumberToken} of {props.totalPagesToken}
|
|
21
|
+
</span>
|
|
22
|
+
</AvoidBreakInside>
|
|
23
|
+
);
|
|
24
|
+
}
|