medusajs-documents-plugin 1.1.13 → 1.1.14
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/.medusa/server/src/admin/index.js +53 -29
- package/.medusa/server/src/admin/index.mjs +54 -30
- package/.medusa/server/src/api/admin/documents/[id]/sync-zoho/route.js +21 -4
- package/.medusa/server/src/api/admin/documents/custom/route.js +6 -4
- package/.medusa/server/src/api/admin/documents/manual/route.js +6 -4
- package/.medusa/server/src/api/admin/documents/templates/preview/route.js +1 -1
- package/.medusa/server/src/api/admin/documents/zoho/list/route.js +18 -7
- package/.medusa/server/src/api/api/store/documents/r/[code]/route.js +3 -42
- package/.medusa/server/src/api/documents/r/[code]/route.js +3 -37
- package/.medusa/server/src/api/documents/templates/preview/route.js +1 -1
- package/.medusa/server/src/api/r/[code]/route.js +3 -55
- package/.medusa/server/src/api/store/documents/r/[code]/route.js +4 -31
- package/.medusa/server/src/modules/documents/service.js +23 -7
- package/.medusa/server/src/services/notification-sender.js +5 -5
- package/.medusa/server/src/services/pdfkit-generator.js +58 -20
- package/.medusa/server/src/services/zoho-books.js +6 -4
- package/.medusa/server/src/subscribers/order-documents.js +17 -6
- package/.medusa/server/src/subscribers/repair-documents.js +45 -7
- package/.medusa/server/src/utils/shortlink-resolver.js +168 -0
- package/CHANGELOG.md +39 -0
- package/package.json +1 -1
|
@@ -163,12 +163,13 @@ const DocumentsPage = () => {
|
|
|
163
163
|
const [manualForm, setManualForm] = react.useState({
|
|
164
164
|
title: "Tax Invoice",
|
|
165
165
|
type: "invoice",
|
|
166
|
+
company_name: "",
|
|
166
167
|
customer_name: "",
|
|
167
168
|
customer_email: "",
|
|
168
169
|
customer_phone: "",
|
|
169
170
|
customer_address: "",
|
|
170
171
|
items: [{ title: "", description: "", quantity: 1, unit_price: 0 }],
|
|
171
|
-
currency_code: "
|
|
172
|
+
currency_code: "kes",
|
|
172
173
|
notes: "",
|
|
173
174
|
force_source: "auto",
|
|
174
175
|
auto_send: false
|
|
@@ -176,6 +177,7 @@ const DocumentsPage = () => {
|
|
|
176
177
|
const [customDocForm, setCustomDocForm] = react.useState({
|
|
177
178
|
preset_id: "warranty",
|
|
178
179
|
title: "Warranty Certificate",
|
|
180
|
+
company_name: "",
|
|
179
181
|
customer_name: "",
|
|
180
182
|
customer_email: "",
|
|
181
183
|
customer_phone: "",
|
|
@@ -184,7 +186,7 @@ const DocumentsPage = () => {
|
|
|
184
186
|
{ title: "OEM Component & Hardware Warranty", description: "90-Day Coverage from Date of Collection", quantity: 1, unit_price: 0 },
|
|
185
187
|
{ title: "Workshop Diagnostic & Quality Clearance", description: "Multi-Point Hardware & Bench Testing", quantity: 1, unit_price: 0 }
|
|
186
188
|
],
|
|
187
|
-
currency_code: "
|
|
189
|
+
currency_code: "kes",
|
|
188
190
|
send_email_now: true,
|
|
189
191
|
email_subject: "Your Official Warranty Certificate - Urban Device Care"
|
|
190
192
|
});
|
|
@@ -282,6 +284,7 @@ const DocumentsPage = () => {
|
|
|
282
284
|
type: manualForm.type,
|
|
283
285
|
customer: {
|
|
284
286
|
name: manualForm.customer_name,
|
|
287
|
+
company_name: manualForm.company_name || void 0,
|
|
285
288
|
email: manualForm.customer_email,
|
|
286
289
|
phone: manualForm.customer_phone,
|
|
287
290
|
address: manualForm.customer_address
|
|
@@ -300,12 +303,13 @@ const DocumentsPage = () => {
|
|
|
300
303
|
setManualForm({
|
|
301
304
|
title: "Tax Invoice",
|
|
302
305
|
type: "invoice",
|
|
306
|
+
company_name: "",
|
|
303
307
|
customer_name: "",
|
|
304
308
|
customer_email: "",
|
|
305
309
|
customer_phone: "",
|
|
306
310
|
customer_address: "",
|
|
307
311
|
items: [{ title: "", description: "", quantity: 1, unit_price: 0 }],
|
|
308
|
-
currency_code: "
|
|
312
|
+
currency_code: "kes",
|
|
309
313
|
notes: "",
|
|
310
314
|
force_source: "auto",
|
|
311
315
|
auto_send: false
|
|
@@ -340,6 +344,7 @@ const DocumentsPage = () => {
|
|
|
340
344
|
title: customDocForm.title,
|
|
341
345
|
customer: {
|
|
342
346
|
name: customDocForm.customer_name,
|
|
347
|
+
company_name: customDocForm.company_name || void 0,
|
|
343
348
|
email: customDocForm.customer_email,
|
|
344
349
|
phone: customDocForm.customer_phone
|
|
345
350
|
},
|
|
@@ -567,8 +572,8 @@ const DocumentsPage = () => {
|
|
|
567
572
|
children: [
|
|
568
573
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { size: "small", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Document Type" }) }),
|
|
569
574
|
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
575
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "invoice", children: "Invoices (Default)" }),
|
|
570
576
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "all", children: "All Types" }),
|
|
571
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "invoice", children: "Invoices" }),
|
|
572
577
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "receipt", children: "Receipts" }),
|
|
573
578
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "estimate", children: "Estimates / Quotes" }),
|
|
574
579
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "job_card", children: "Job Cards" }),
|
|
@@ -586,19 +591,17 @@ const DocumentsPage = () => {
|
|
|
586
591
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "pdfkit", children: "PDFKit Local" })
|
|
587
592
|
] })
|
|
588
593
|
] }),
|
|
589
|
-
/* @__PURE__ */ jsxRuntime.
|
|
590
|
-
ui.
|
|
594
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: "Refresh Live Zoho Books Invoices", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
595
|
+
ui.IconButton,
|
|
591
596
|
{
|
|
592
597
|
variant: "secondary",
|
|
593
598
|
size: "small",
|
|
594
599
|
onClick: () => loadZohoLiveDocs(),
|
|
595
600
|
isLoading: loadingZoho,
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
" Refresh Live Zoho"
|
|
599
|
-
]
|
|
601
|
+
title: "Refresh Live Zoho Books Invoices",
|
|
602
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowPath, { className: `w-4 h-4 ${loadingZoho ? "animate-spin" : ""}` })
|
|
600
603
|
}
|
|
601
|
-
)
|
|
604
|
+
) })
|
|
602
605
|
] })
|
|
603
606
|
] }),
|
|
604
607
|
loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-12 text-center text-ui-fg-muted text-sm", children: "Loading documents..." }) : filteredDocs.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-12 text-center text-ui-fg-muted border border-dashed border-ui-border-base rounded-lg", children: [
|
|
@@ -635,7 +638,7 @@ const DocumentsPage = () => {
|
|
|
635
638
|
] }) }),
|
|
636
639
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-semibold", children: new Intl.NumberFormat("en-US", {
|
|
637
640
|
style: "currency",
|
|
638
|
-
currency: (doc.currency_code || "
|
|
641
|
+
currency: (doc.currency_code || "KES").toUpperCase()
|
|
639
642
|
}).format(Number(doc.total_amount || 0)) }) }),
|
|
640
643
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: isPaid ? "green" : doc.payment_status === "unpaid" ? "red" : "blue", size: "small", children: doc.payment_status || doc.status }) }),
|
|
641
644
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: isZoho ? "purple" : "grey", size: "small", children: isZoho ? "Zoho Books" : "PDFKit" }) }),
|
|
@@ -668,7 +671,7 @@ const DocumentsPage = () => {
|
|
|
668
671
|
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Envelope, { className: "w-4 h-4" })
|
|
669
672
|
}
|
|
670
673
|
),
|
|
671
|
-
!isZoho && settings.zoho_books_enabled && /* @__PURE__ */ jsxRuntime.jsx(
|
|
674
|
+
!isZoho && settings.zoho_books_enabled && (doc.type === "invoice" || doc.type === "estimate") && Number(doc.total_amount || 0) > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
672
675
|
ui.Button,
|
|
673
676
|
{
|
|
674
677
|
variant: "transparent",
|
|
@@ -703,20 +706,17 @@ const DocumentsPage = () => {
|
|
|
703
706
|
] }),
|
|
704
707
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: "purple", size: "small", children: "Live Cloud Sync" })
|
|
705
708
|
] }),
|
|
706
|
-
/* @__PURE__ */ jsxRuntime.
|
|
707
|
-
ui.
|
|
709
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: "Refresh Live Zoho Books Invoices", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
710
|
+
ui.IconButton,
|
|
708
711
|
{
|
|
709
712
|
variant: "transparent",
|
|
710
713
|
size: "small",
|
|
711
714
|
onClick: () => loadZohoLiveDocs(),
|
|
712
715
|
isLoading: loadingZoho,
|
|
713
|
-
|
|
714
|
-
children:
|
|
715
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowPath, { className: `w-3.5 h-3.5 ${loadingZoho ? "animate-spin" : ""}` }),
|
|
716
|
-
" Refresh Zoho"
|
|
717
|
-
]
|
|
716
|
+
title: "Refresh Live Zoho Books Invoices",
|
|
717
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowPath, { className: `w-4 h-4 ${loadingZoho ? "animate-spin" : ""}` })
|
|
718
718
|
}
|
|
719
|
-
)
|
|
719
|
+
) })
|
|
720
720
|
] }),
|
|
721
721
|
loadingZoho && zohoLiveDocs.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-8 text-center text-ui-fg-muted text-sm", children: "Fetching live documents from Zoho Books..." }) : zohoLiveDocs.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-8 text-center text-ui-fg-muted text-sm border border-dashed border-ui-border-base rounded-lg", children: [
|
|
722
722
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-sm font-medium", children: "No live Zoho documents found" }),
|
|
@@ -732,7 +732,7 @@ const DocumentsPage = () => {
|
|
|
732
732
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: zohoLiveDocs.map((zi) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
733
733
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { className: "font-medium", children: zi.invoice_number || zi.estimate_number || zi.payment_number || "—" }),
|
|
734
734
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: zi.customer_name || "—" }),
|
|
735
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: zi.total != null ? `${zi.currency_symbol || ""}${zi.total}` : zi.amount != null ? `${zi.currency_symbol || ""}${zi.amount}` : "—" }),
|
|
735
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: zi.total != null ? `${zi.currency_symbol || "KES "}${zi.total}` : zi.amount != null ? `${zi.currency_symbol || "KES "}${zi.amount}` : "—" }),
|
|
736
736
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: zi.status === "paid" ? "green" : zi.status === "overdue" ? "red" : "blue", size: "small", children: zi.status || "draft" }) }),
|
|
737
737
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: zi.date || "—" })
|
|
738
738
|
] }, zi.invoice_id || zi.estimate_id || zi.payment_id || `${zi.invoice_number}-${zi.date}`)) })
|
|
@@ -1717,6 +1717,18 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
1717
1717
|
}
|
|
1718
1718
|
)
|
|
1719
1719
|
] }),
|
|
1720
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1721
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { className: "text-xs", children: "Company Name (Optional)" }),
|
|
1722
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1723
|
+
ui.Input,
|
|
1724
|
+
{
|
|
1725
|
+
value: manualForm.company_name,
|
|
1726
|
+
onChange: (e) => setManualForm({ ...manualForm, company_name: e.target.value }),
|
|
1727
|
+
placeholder: "Company / Organization Name",
|
|
1728
|
+
size: "small"
|
|
1729
|
+
}
|
|
1730
|
+
)
|
|
1731
|
+
] }),
|
|
1720
1732
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1721
1733
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { className: "text-xs", children: "Customer Name" }),
|
|
1722
1734
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1785,10 +1797,10 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
1785
1797
|
children: [
|
|
1786
1798
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { size: "small", className: "w-24", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
|
|
1787
1799
|
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
1800
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "kes", children: "KES (KSh)" }),
|
|
1788
1801
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "usd", children: "USD ($)" }),
|
|
1789
1802
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "gbp", children: "GBP (£)" }),
|
|
1790
1803
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "eur", children: "EUR (€)" }),
|
|
1791
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "kes", children: "KES (KSh)" }),
|
|
1792
1804
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "cad", children: "CAD ($)" }),
|
|
1793
1805
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "aud", children: "AUD ($)" })
|
|
1794
1806
|
] })
|
|
@@ -1886,7 +1898,7 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
1886
1898
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { className: "text-[11px] text-ui-fg-subtle mb-0.5", children: "Row Total" }),
|
|
1887
1899
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-semibold text-ui-fg-base py-1", children: new Intl.NumberFormat("en-US", {
|
|
1888
1900
|
style: "currency",
|
|
1889
|
-
currency: (manualForm.currency_code || "
|
|
1901
|
+
currency: (manualForm.currency_code || "KES").toUpperCase()
|
|
1890
1902
|
}).format(lineTotal) }),
|
|
1891
1903
|
manualForm.items.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1892
1904
|
"button",
|
|
@@ -1931,7 +1943,7 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
1931
1943
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-ui-fg-subtle font-medium", children: "Document Total:" }),
|
|
1932
1944
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-bold text-ui-fg-base", children: new Intl.NumberFormat("en-US", {
|
|
1933
1945
|
style: "currency",
|
|
1934
|
-
currency: (manualForm.currency_code || "
|
|
1946
|
+
currency: (manualForm.currency_code || "KES").toUpperCase()
|
|
1935
1947
|
}).format(
|
|
1936
1948
|
manualForm.items.reduce(
|
|
1937
1949
|
(sum, it) => sum + (Number(it.quantity) || 0) * (Number(it.unit_price) || 0),
|
|
@@ -2012,6 +2024,18 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
2012
2024
|
}
|
|
2013
2025
|
)
|
|
2014
2026
|
] }),
|
|
2027
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2028
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { className: "text-xs", children: "Company Name (Optional)" }),
|
|
2029
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2030
|
+
ui.Input,
|
|
2031
|
+
{
|
|
2032
|
+
value: customDocForm.company_name,
|
|
2033
|
+
onChange: (e) => setCustomDocForm({ ...customDocForm, company_name: e.target.value }),
|
|
2034
|
+
placeholder: "Company / Organization Name",
|
|
2035
|
+
size: "small"
|
|
2036
|
+
}
|
|
2037
|
+
)
|
|
2038
|
+
] }),
|
|
2015
2039
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2016
2040
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { className: "text-xs", children: "Customer Name *" }),
|
|
2017
2041
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2036,7 +2060,7 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
2036
2060
|
}
|
|
2037
2061
|
)
|
|
2038
2062
|
] }),
|
|
2039
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
2063
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2040
2064
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { className: "text-xs", children: "Customer Phone (Optional)" }),
|
|
2041
2065
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2042
2066
|
ui.Input,
|
|
@@ -2074,10 +2098,10 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
2074
2098
|
children: [
|
|
2075
2099
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { size: "small", className: "w-24", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
|
|
2076
2100
|
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
2101
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "kes", children: "KES (KSh)" }),
|
|
2077
2102
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "usd", children: "USD ($)" }),
|
|
2078
2103
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "gbp", children: "GBP (£)" }),
|
|
2079
2104
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "eur", children: "EUR (€)" }),
|
|
2080
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "kes", children: "KES (KSh)" }),
|
|
2081
2105
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "cad", children: "CAD ($)" }),
|
|
2082
2106
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "aud", children: "AUD ($)" })
|
|
2083
2107
|
] })
|
|
@@ -2175,7 +2199,7 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
2175
2199
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { className: "text-[11px] text-ui-fg-subtle mb-0.5", children: "Row Total" }),
|
|
2176
2200
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-semibold text-ui-fg-base py-1", children: new Intl.NumberFormat("en-US", {
|
|
2177
2201
|
style: "currency",
|
|
2178
|
-
currency: (customDocForm.currency_code || "
|
|
2202
|
+
currency: (customDocForm.currency_code || "KES").toUpperCase()
|
|
2179
2203
|
}).format(lineTotal) }),
|
|
2180
2204
|
customDocForm.items.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2181
2205
|
"button",
|
|
@@ -2220,7 +2244,7 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
2220
2244
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-ui-fg-subtle font-medium", children: "Document Total:" }),
|
|
2221
2245
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-bold text-ui-fg-base", children: new Intl.NumberFormat("en-US", {
|
|
2222
2246
|
style: "currency",
|
|
2223
|
-
currency: (customDocForm.currency_code || "
|
|
2247
|
+
currency: (customDocForm.currency_code || "KES").toUpperCase()
|
|
2224
2248
|
}).format(
|
|
2225
2249
|
customDocForm.items.reduce(
|
|
2226
2250
|
(sum, it) => sum + (Number(it.quantity) || 0) * (Number(it.unit_price) || 0),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { defineRouteConfig } from "@medusajs/admin-sdk";
|
|
3
|
-
import { Container, Heading, Text, Button, Input, Select, Table, Badge, Label, Switch, Textarea, FocusModal } from "@medusajs/ui";
|
|
3
|
+
import { Container, Heading, Text, Button, Input, Select, Tooltip, IconButton, Table, Badge, Label, Switch, Textarea, FocusModal } from "@medusajs/ui";
|
|
4
4
|
import { useState, useEffect } from "react";
|
|
5
5
|
import { DocumentText, Plus, Sparkles, ArrowPath, ArrowDownTray, Envelope, Trash } from "@medusajs/icons";
|
|
6
6
|
const CUSTOM_DOC_PRESETS = [
|
|
@@ -162,12 +162,13 @@ const DocumentsPage = () => {
|
|
|
162
162
|
const [manualForm, setManualForm] = useState({
|
|
163
163
|
title: "Tax Invoice",
|
|
164
164
|
type: "invoice",
|
|
165
|
+
company_name: "",
|
|
165
166
|
customer_name: "",
|
|
166
167
|
customer_email: "",
|
|
167
168
|
customer_phone: "",
|
|
168
169
|
customer_address: "",
|
|
169
170
|
items: [{ title: "", description: "", quantity: 1, unit_price: 0 }],
|
|
170
|
-
currency_code: "
|
|
171
|
+
currency_code: "kes",
|
|
171
172
|
notes: "",
|
|
172
173
|
force_source: "auto",
|
|
173
174
|
auto_send: false
|
|
@@ -175,6 +176,7 @@ const DocumentsPage = () => {
|
|
|
175
176
|
const [customDocForm, setCustomDocForm] = useState({
|
|
176
177
|
preset_id: "warranty",
|
|
177
178
|
title: "Warranty Certificate",
|
|
179
|
+
company_name: "",
|
|
178
180
|
customer_name: "",
|
|
179
181
|
customer_email: "",
|
|
180
182
|
customer_phone: "",
|
|
@@ -183,7 +185,7 @@ const DocumentsPage = () => {
|
|
|
183
185
|
{ title: "OEM Component & Hardware Warranty", description: "90-Day Coverage from Date of Collection", quantity: 1, unit_price: 0 },
|
|
184
186
|
{ title: "Workshop Diagnostic & Quality Clearance", description: "Multi-Point Hardware & Bench Testing", quantity: 1, unit_price: 0 }
|
|
185
187
|
],
|
|
186
|
-
currency_code: "
|
|
188
|
+
currency_code: "kes",
|
|
187
189
|
send_email_now: true,
|
|
188
190
|
email_subject: "Your Official Warranty Certificate - Urban Device Care"
|
|
189
191
|
});
|
|
@@ -281,6 +283,7 @@ const DocumentsPage = () => {
|
|
|
281
283
|
type: manualForm.type,
|
|
282
284
|
customer: {
|
|
283
285
|
name: manualForm.customer_name,
|
|
286
|
+
company_name: manualForm.company_name || void 0,
|
|
284
287
|
email: manualForm.customer_email,
|
|
285
288
|
phone: manualForm.customer_phone,
|
|
286
289
|
address: manualForm.customer_address
|
|
@@ -299,12 +302,13 @@ const DocumentsPage = () => {
|
|
|
299
302
|
setManualForm({
|
|
300
303
|
title: "Tax Invoice",
|
|
301
304
|
type: "invoice",
|
|
305
|
+
company_name: "",
|
|
302
306
|
customer_name: "",
|
|
303
307
|
customer_email: "",
|
|
304
308
|
customer_phone: "",
|
|
305
309
|
customer_address: "",
|
|
306
310
|
items: [{ title: "", description: "", quantity: 1, unit_price: 0 }],
|
|
307
|
-
currency_code: "
|
|
311
|
+
currency_code: "kes",
|
|
308
312
|
notes: "",
|
|
309
313
|
force_source: "auto",
|
|
310
314
|
auto_send: false
|
|
@@ -339,6 +343,7 @@ const DocumentsPage = () => {
|
|
|
339
343
|
title: customDocForm.title,
|
|
340
344
|
customer: {
|
|
341
345
|
name: customDocForm.customer_name,
|
|
346
|
+
company_name: customDocForm.company_name || void 0,
|
|
342
347
|
email: customDocForm.customer_email,
|
|
343
348
|
phone: customDocForm.customer_phone
|
|
344
349
|
},
|
|
@@ -566,8 +571,8 @@ const DocumentsPage = () => {
|
|
|
566
571
|
children: [
|
|
567
572
|
/* @__PURE__ */ jsx(Select.Trigger, { size: "small", children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Document Type" }) }),
|
|
568
573
|
/* @__PURE__ */ jsxs(Select.Content, { children: [
|
|
574
|
+
/* @__PURE__ */ jsx(Select.Item, { value: "invoice", children: "Invoices (Default)" }),
|
|
569
575
|
/* @__PURE__ */ jsx(Select.Item, { value: "all", children: "All Types" }),
|
|
570
|
-
/* @__PURE__ */ jsx(Select.Item, { value: "invoice", children: "Invoices" }),
|
|
571
576
|
/* @__PURE__ */ jsx(Select.Item, { value: "receipt", children: "Receipts" }),
|
|
572
577
|
/* @__PURE__ */ jsx(Select.Item, { value: "estimate", children: "Estimates / Quotes" }),
|
|
573
578
|
/* @__PURE__ */ jsx(Select.Item, { value: "job_card", children: "Job Cards" }),
|
|
@@ -585,19 +590,17 @@ const DocumentsPage = () => {
|
|
|
585
590
|
/* @__PURE__ */ jsx(Select.Item, { value: "pdfkit", children: "PDFKit Local" })
|
|
586
591
|
] })
|
|
587
592
|
] }),
|
|
588
|
-
/* @__PURE__ */
|
|
589
|
-
|
|
593
|
+
/* @__PURE__ */ jsx(Tooltip, { content: "Refresh Live Zoho Books Invoices", children: /* @__PURE__ */ jsx(
|
|
594
|
+
IconButton,
|
|
590
595
|
{
|
|
591
596
|
variant: "secondary",
|
|
592
597
|
size: "small",
|
|
593
598
|
onClick: () => loadZohoLiveDocs(),
|
|
594
599
|
isLoading: loadingZoho,
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
" Refresh Live Zoho"
|
|
598
|
-
]
|
|
600
|
+
title: "Refresh Live Zoho Books Invoices",
|
|
601
|
+
children: /* @__PURE__ */ jsx(ArrowPath, { className: `w-4 h-4 ${loadingZoho ? "animate-spin" : ""}` })
|
|
599
602
|
}
|
|
600
|
-
)
|
|
603
|
+
) })
|
|
601
604
|
] })
|
|
602
605
|
] }),
|
|
603
606
|
loading ? /* @__PURE__ */ jsx("div", { className: "py-12 text-center text-ui-fg-muted text-sm", children: "Loading documents..." }) : filteredDocs.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "py-12 text-center text-ui-fg-muted border border-dashed border-ui-border-base rounded-lg", children: [
|
|
@@ -634,7 +637,7 @@ const DocumentsPage = () => {
|
|
|
634
637
|
] }) }),
|
|
635
638
|
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx("span", { className: "text-xs font-semibold", children: new Intl.NumberFormat("en-US", {
|
|
636
639
|
style: "currency",
|
|
637
|
-
currency: (doc.currency_code || "
|
|
640
|
+
currency: (doc.currency_code || "KES").toUpperCase()
|
|
638
641
|
}).format(Number(doc.total_amount || 0)) }) }),
|
|
639
642
|
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Badge, { color: isPaid ? "green" : doc.payment_status === "unpaid" ? "red" : "blue", size: "small", children: doc.payment_status || doc.status }) }),
|
|
640
643
|
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Badge, { color: isZoho ? "purple" : "grey", size: "small", children: isZoho ? "Zoho Books" : "PDFKit" }) }),
|
|
@@ -667,7 +670,7 @@ const DocumentsPage = () => {
|
|
|
667
670
|
children: /* @__PURE__ */ jsx(Envelope, { className: "w-4 h-4" })
|
|
668
671
|
}
|
|
669
672
|
),
|
|
670
|
-
!isZoho && settings.zoho_books_enabled && /* @__PURE__ */ jsx(
|
|
673
|
+
!isZoho && settings.zoho_books_enabled && (doc.type === "invoice" || doc.type === "estimate") && Number(doc.total_amount || 0) > 0 && /* @__PURE__ */ jsx(
|
|
671
674
|
Button,
|
|
672
675
|
{
|
|
673
676
|
variant: "transparent",
|
|
@@ -702,20 +705,17 @@ const DocumentsPage = () => {
|
|
|
702
705
|
] }),
|
|
703
706
|
/* @__PURE__ */ jsx(Badge, { color: "purple", size: "small", children: "Live Cloud Sync" })
|
|
704
707
|
] }),
|
|
705
|
-
/* @__PURE__ */
|
|
706
|
-
|
|
708
|
+
/* @__PURE__ */ jsx(Tooltip, { content: "Refresh Live Zoho Books Invoices", children: /* @__PURE__ */ jsx(
|
|
709
|
+
IconButton,
|
|
707
710
|
{
|
|
708
711
|
variant: "transparent",
|
|
709
712
|
size: "small",
|
|
710
713
|
onClick: () => loadZohoLiveDocs(),
|
|
711
714
|
isLoading: loadingZoho,
|
|
712
|
-
|
|
713
|
-
children:
|
|
714
|
-
/* @__PURE__ */ jsx(ArrowPath, { className: `w-3.5 h-3.5 ${loadingZoho ? "animate-spin" : ""}` }),
|
|
715
|
-
" Refresh Zoho"
|
|
716
|
-
]
|
|
715
|
+
title: "Refresh Live Zoho Books Invoices",
|
|
716
|
+
children: /* @__PURE__ */ jsx(ArrowPath, { className: `w-4 h-4 ${loadingZoho ? "animate-spin" : ""}` })
|
|
717
717
|
}
|
|
718
|
-
)
|
|
718
|
+
) })
|
|
719
719
|
] }),
|
|
720
720
|
loadingZoho && zohoLiveDocs.length === 0 ? /* @__PURE__ */ jsx("div", { className: "py-8 text-center text-ui-fg-muted text-sm", children: "Fetching live documents from Zoho Books..." }) : zohoLiveDocs.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "py-8 text-center text-ui-fg-muted text-sm border border-dashed border-ui-border-base rounded-lg", children: [
|
|
721
721
|
/* @__PURE__ */ jsx(Text, { className: "text-sm font-medium", children: "No live Zoho documents found" }),
|
|
@@ -731,7 +731,7 @@ const DocumentsPage = () => {
|
|
|
731
731
|
/* @__PURE__ */ jsx(Table.Body, { children: zohoLiveDocs.map((zi) => /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
732
732
|
/* @__PURE__ */ jsx(Table.Cell, { className: "font-medium", children: zi.invoice_number || zi.estimate_number || zi.payment_number || "—" }),
|
|
733
733
|
/* @__PURE__ */ jsx(Table.Cell, { children: zi.customer_name || "—" }),
|
|
734
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: zi.total != null ? `${zi.currency_symbol || ""}${zi.total}` : zi.amount != null ? `${zi.currency_symbol || ""}${zi.amount}` : "—" }),
|
|
734
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: zi.total != null ? `${zi.currency_symbol || "KES "}${zi.total}` : zi.amount != null ? `${zi.currency_symbol || "KES "}${zi.amount}` : "—" }),
|
|
735
735
|
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Badge, { color: zi.status === "paid" ? "green" : zi.status === "overdue" ? "red" : "blue", size: "small", children: zi.status || "draft" }) }),
|
|
736
736
|
/* @__PURE__ */ jsx(Table.Cell, { children: zi.date || "—" })
|
|
737
737
|
] }, zi.invoice_id || zi.estimate_id || zi.payment_id || `${zi.invoice_number}-${zi.date}`)) })
|
|
@@ -1716,6 +1716,18 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
1716
1716
|
}
|
|
1717
1717
|
)
|
|
1718
1718
|
] }),
|
|
1719
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1720
|
+
/* @__PURE__ */ jsx(Label, { className: "text-xs", children: "Company Name (Optional)" }),
|
|
1721
|
+
/* @__PURE__ */ jsx(
|
|
1722
|
+
Input,
|
|
1723
|
+
{
|
|
1724
|
+
value: manualForm.company_name,
|
|
1725
|
+
onChange: (e) => setManualForm({ ...manualForm, company_name: e.target.value }),
|
|
1726
|
+
placeholder: "Company / Organization Name",
|
|
1727
|
+
size: "small"
|
|
1728
|
+
}
|
|
1729
|
+
)
|
|
1730
|
+
] }),
|
|
1719
1731
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
1720
1732
|
/* @__PURE__ */ jsx(Label, { className: "text-xs", children: "Customer Name" }),
|
|
1721
1733
|
/* @__PURE__ */ jsx(
|
|
@@ -1784,10 +1796,10 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
1784
1796
|
children: [
|
|
1785
1797
|
/* @__PURE__ */ jsx(Select.Trigger, { size: "small", className: "w-24", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
|
|
1786
1798
|
/* @__PURE__ */ jsxs(Select.Content, { children: [
|
|
1799
|
+
/* @__PURE__ */ jsx(Select.Item, { value: "kes", children: "KES (KSh)" }),
|
|
1787
1800
|
/* @__PURE__ */ jsx(Select.Item, { value: "usd", children: "USD ($)" }),
|
|
1788
1801
|
/* @__PURE__ */ jsx(Select.Item, { value: "gbp", children: "GBP (£)" }),
|
|
1789
1802
|
/* @__PURE__ */ jsx(Select.Item, { value: "eur", children: "EUR (€)" }),
|
|
1790
|
-
/* @__PURE__ */ jsx(Select.Item, { value: "kes", children: "KES (KSh)" }),
|
|
1791
1803
|
/* @__PURE__ */ jsx(Select.Item, { value: "cad", children: "CAD ($)" }),
|
|
1792
1804
|
/* @__PURE__ */ jsx(Select.Item, { value: "aud", children: "AUD ($)" })
|
|
1793
1805
|
] })
|
|
@@ -1885,7 +1897,7 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
1885
1897
|
/* @__PURE__ */ jsx(Label, { className: "text-[11px] text-ui-fg-subtle mb-0.5", children: "Row Total" }),
|
|
1886
1898
|
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-ui-fg-base py-1", children: new Intl.NumberFormat("en-US", {
|
|
1887
1899
|
style: "currency",
|
|
1888
|
-
currency: (manualForm.currency_code || "
|
|
1900
|
+
currency: (manualForm.currency_code || "KES").toUpperCase()
|
|
1889
1901
|
}).format(lineTotal) }),
|
|
1890
1902
|
manualForm.items.length > 1 && /* @__PURE__ */ jsx(
|
|
1891
1903
|
"button",
|
|
@@ -1930,7 +1942,7 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
1930
1942
|
/* @__PURE__ */ jsx("span", { className: "text-xs text-ui-fg-subtle font-medium", children: "Document Total:" }),
|
|
1931
1943
|
/* @__PURE__ */ jsx("span", { className: "text-sm font-bold text-ui-fg-base", children: new Intl.NumberFormat("en-US", {
|
|
1932
1944
|
style: "currency",
|
|
1933
|
-
currency: (manualForm.currency_code || "
|
|
1945
|
+
currency: (manualForm.currency_code || "KES").toUpperCase()
|
|
1934
1946
|
}).format(
|
|
1935
1947
|
manualForm.items.reduce(
|
|
1936
1948
|
(sum, it) => sum + (Number(it.quantity) || 0) * (Number(it.unit_price) || 0),
|
|
@@ -2011,6 +2023,18 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
2011
2023
|
}
|
|
2012
2024
|
)
|
|
2013
2025
|
] }),
|
|
2026
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2027
|
+
/* @__PURE__ */ jsx(Label, { className: "text-xs", children: "Company Name (Optional)" }),
|
|
2028
|
+
/* @__PURE__ */ jsx(
|
|
2029
|
+
Input,
|
|
2030
|
+
{
|
|
2031
|
+
value: customDocForm.company_name,
|
|
2032
|
+
onChange: (e) => setCustomDocForm({ ...customDocForm, company_name: e.target.value }),
|
|
2033
|
+
placeholder: "Company / Organization Name",
|
|
2034
|
+
size: "small"
|
|
2035
|
+
}
|
|
2036
|
+
)
|
|
2037
|
+
] }),
|
|
2014
2038
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
2015
2039
|
/* @__PURE__ */ jsx(Label, { className: "text-xs", children: "Customer Name *" }),
|
|
2016
2040
|
/* @__PURE__ */ jsx(
|
|
@@ -2035,7 +2059,7 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
2035
2059
|
}
|
|
2036
2060
|
)
|
|
2037
2061
|
] }),
|
|
2038
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2062
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2039
2063
|
/* @__PURE__ */ jsx(Label, { className: "text-xs", children: "Customer Phone (Optional)" }),
|
|
2040
2064
|
/* @__PURE__ */ jsx(
|
|
2041
2065
|
Input,
|
|
@@ -2073,10 +2097,10 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
2073
2097
|
children: [
|
|
2074
2098
|
/* @__PURE__ */ jsx(Select.Trigger, { size: "small", className: "w-24", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
|
|
2075
2099
|
/* @__PURE__ */ jsxs(Select.Content, { children: [
|
|
2100
|
+
/* @__PURE__ */ jsx(Select.Item, { value: "kes", children: "KES (KSh)" }),
|
|
2076
2101
|
/* @__PURE__ */ jsx(Select.Item, { value: "usd", children: "USD ($)" }),
|
|
2077
2102
|
/* @__PURE__ */ jsx(Select.Item, { value: "gbp", children: "GBP (£)" }),
|
|
2078
2103
|
/* @__PURE__ */ jsx(Select.Item, { value: "eur", children: "EUR (€)" }),
|
|
2079
|
-
/* @__PURE__ */ jsx(Select.Item, { value: "kes", children: "KES (KSh)" }),
|
|
2080
2104
|
/* @__PURE__ */ jsx(Select.Item, { value: "cad", children: "CAD ($)" }),
|
|
2081
2105
|
/* @__PURE__ */ jsx(Select.Item, { value: "aud", children: "AUD ($)" })
|
|
2082
2106
|
] })
|
|
@@ -2174,7 +2198,7 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
2174
2198
|
/* @__PURE__ */ jsx(Label, { className: "text-[11px] text-ui-fg-subtle mb-0.5", children: "Row Total" }),
|
|
2175
2199
|
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-ui-fg-base py-1", children: new Intl.NumberFormat("en-US", {
|
|
2176
2200
|
style: "currency",
|
|
2177
|
-
currency: (customDocForm.currency_code || "
|
|
2201
|
+
currency: (customDocForm.currency_code || "KES").toUpperCase()
|
|
2178
2202
|
}).format(lineTotal) }),
|
|
2179
2203
|
customDocForm.items.length > 1 && /* @__PURE__ */ jsx(
|
|
2180
2204
|
"button",
|
|
@@ -2219,7 +2243,7 @@ Your *{document_title} #{display_id}* has been generated.
|
|
|
2219
2243
|
/* @__PURE__ */ jsx("span", { className: "text-xs text-ui-fg-subtle font-medium", children: "Document Total:" }),
|
|
2220
2244
|
/* @__PURE__ */ jsx("span", { className: "text-sm font-bold text-ui-fg-base", children: new Intl.NumberFormat("en-US", {
|
|
2221
2245
|
style: "currency",
|
|
2222
|
-
currency: (customDocForm.currency_code || "
|
|
2246
|
+
currency: (customDocForm.currency_code || "KES").toUpperCase()
|
|
2223
2247
|
}).format(
|
|
2224
2248
|
customDocForm.items.reduce(
|
|
2225
2249
|
(sum, it) => sum + (Number(it.quantity) || 0) * (Number(it.unit_price) || 0),
|
|
@@ -12,6 +12,21 @@ async function POST(req, res) {
|
|
|
12
12
|
if (!settings.zoho_books_enabled || !settings.zoho_client_id) {
|
|
13
13
|
return res.status(400).json({
|
|
14
14
|
message: "Zoho Books integration is not enabled or credentials are missing.",
|
|
15
|
+
success: false,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
// Reject non-Zoho document types (e.g. job_card, packing_slip, custom)
|
|
19
|
+
if (record.type === "job_card" || record.type === "packing_slip" || record.type === "custom") {
|
|
20
|
+
return res.status(400).json({
|
|
21
|
+
message: `Cannot push ${record.type} documents to Zoho Books. Only invoice and estimate documents are supported.`,
|
|
22
|
+
success: false,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
// Reject documents with zero or negative total amount
|
|
26
|
+
if (Number(record.total_amount || 0) <= 0) {
|
|
27
|
+
return res.status(400).json({
|
|
28
|
+
message: "Cannot push documents with zero total amount to Zoho Books.",
|
|
29
|
+
success: false,
|
|
15
30
|
});
|
|
16
31
|
}
|
|
17
32
|
const zoho = new zoho_books_1.ZohoBooksService({
|
|
@@ -20,14 +35,16 @@ async function POST(req, res) {
|
|
|
20
35
|
refresh_token: settings.zoho_refresh_token,
|
|
21
36
|
organization_id: settings.zoho_organization_id,
|
|
22
37
|
domain: settings.zoho_domain || "com",
|
|
23
|
-
}, req.scope.resolve("logger"));
|
|
24
|
-
|
|
38
|
+
}, req.scope.resolve("logger", { allowUnregistered: true }));
|
|
39
|
+
const meta = (record.metadata || {});
|
|
40
|
+
const companyName = meta.customer_company_name || meta.company_name;
|
|
41
|
+
// 1. Sync contact (prioritize company name)
|
|
25
42
|
const contactId = await zoho.syncContact({
|
|
26
43
|
first_name: record.customer_name || "Customer",
|
|
44
|
+
company_name: companyName || undefined,
|
|
27
45
|
email: record.customer_email || undefined,
|
|
28
46
|
phone: record.customer_phone || undefined,
|
|
29
47
|
});
|
|
30
|
-
const meta = (record.metadata || {});
|
|
31
48
|
const items = (meta.items || []).map((it) => ({
|
|
32
49
|
name: it.title,
|
|
33
50
|
description: it.description || "",
|
|
@@ -65,4 +82,4 @@ async function POST(req, res) {
|
|
|
65
82
|
success: true,
|
|
66
83
|
});
|
|
67
84
|
}
|
|
68
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
85
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvYXBpL2FkbWluL2RvY3VtZW50cy9baWRdL3N5bmMtem9oby9yb3V0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQU1BLG9CQTBGQztBQS9GRCxnRUFBb0U7QUFFcEUsbUVBQXNFO0FBRXRFLHNDQUFzQztBQUMvQixLQUFLLFVBQVUsSUFBSSxDQUFDLEdBQWtDLEVBQUUsR0FBbUI7SUFDaEYsTUFBTSxlQUFlLEdBQTBCLEdBQUcsQ0FBQyxLQUFLLENBQUMsT0FBTyxDQUFDLDRCQUFnQixDQUFDLENBQUM7SUFDbkYsTUFBTSxFQUFFLEdBQUcsR0FBRyxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUM7SUFFekIsTUFBTSxNQUFNLEdBQUcsTUFBTSxlQUFlLENBQUMsc0JBQXNCLENBQUMsRUFBRSxDQUFDLENBQUM7SUFDaEUsTUFBTSxRQUFRLEdBQUcsTUFBTSxlQUFlLENBQUMsV0FBVyxFQUFFLENBQUM7SUFFckQsSUFBSSxDQUFDLFFBQVEsQ0FBQyxrQkFBa0IsSUFBSSxDQUFDLFFBQVEsQ0FBQyxjQUFjLEVBQUUsQ0FBQztRQUM3RCxPQUFPLEdBQUcsQ0FBQyxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUMsSUFBSSxDQUFDO1lBQzFCLE9BQU8sRUFBRSxtRUFBbUU7WUFDNUUsT0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TCxDQUFDIn0=
|
|
@@ -6,25 +6,27 @@ const documents_1 = require("../../../../modules/documents");
|
|
|
6
6
|
async function POST(req, res) {
|
|
7
7
|
try {
|
|
8
8
|
const documentService = req.scope.resolve(documents_1.DOCUMENTS_MODULE);
|
|
9
|
-
const { title = "Custom Document", customer, body_text, items = [], total = 0, currency_code = "
|
|
9
|
+
const { title = "Custom Document", customer, body_text, items = [], total = 0, currency_code = "kes", notes, custom_fields, send_email_now = true, email_subject, custom_email_message, } = req.body || {};
|
|
10
10
|
let computedTotal = Number(total || 0);
|
|
11
11
|
if (items.length > 0 && computedTotal === 0) {
|
|
12
12
|
for (const item of items) {
|
|
13
13
|
computedTotal += Number(item.quantity || 1) * Number(item.unit_price || 0);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
const companyName = customer?.company_name || req.body?.company_name;
|
|
16
17
|
const result = await documentService.generateDocument({
|
|
17
18
|
title: title,
|
|
18
19
|
type: "custom",
|
|
19
20
|
customer: {
|
|
20
|
-
name: customer?.name || "Customer",
|
|
21
|
+
name: companyName || customer?.name || "Customer",
|
|
22
|
+
company_name: companyName || undefined,
|
|
21
23
|
email: customer?.email,
|
|
22
24
|
phone: customer?.phone,
|
|
23
25
|
address: customer?.address,
|
|
24
26
|
},
|
|
25
27
|
items,
|
|
26
28
|
total: computedTotal,
|
|
27
|
-
currency_code,
|
|
29
|
+
currency_code: currency_code || "kes",
|
|
28
30
|
body_text,
|
|
29
31
|
notes,
|
|
30
32
|
custom_fields,
|
|
@@ -45,4 +47,4 @@ async function POST(req, res) {
|
|
|
45
47
|
return res.status(500).json({ message: err.message, success: false });
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
50
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9z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