diff --git a/packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte b/packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte index 510f2239..eefc3663 100644 --- a/packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte +++ b/packages/invoice-dashboard/src/lib/dashboard/invoice-view.svelte @@ -20,13 +20,14 @@ // Utils import { formatDate } from "@requestnetwork/shared-utils/formatDate"; import { calculateItemTotal } from "@requestnetwork/shared-utils/invoiceTotals"; + import { exportToPDF } from "@requestnetwork/shared-utils/generateInvoice"; + import { getCurrencyFromManager } from "@requestnetwork/shared-utils/getCurrency"; // Types import type { WalletState } from "@requestnetwork/shared-types/web3Onboard"; import { onMount } from "svelte"; import { formatUnits } from "viem"; - import { exportToPDF, walletClientToSigner } from "../../utils"; - import { getCurrencyFromManager } from "../../utils/getCurrency"; + import { walletClientToSigner } from "../../utils"; export let config; export let wallet: WalletState | undefined; diff --git a/packages/invoice-dashboard/src/lib/view-requests.svelte b/packages/invoice-dashboard/src/lib/view-requests.svelte index bb5e9ef5..d043b57f 100644 --- a/packages/invoice-dashboard/src/lib/view-requests.svelte +++ b/packages/invoice-dashboard/src/lib/view-requests.svelte @@ -25,14 +25,16 @@ // Utils import { config as defaultConfig } from "@requestnetwork/shared-utils/config"; import { initializeCurrencyManager } from "@requestnetwork/shared-utils/initCurrencyManager"; + import { exportToPDF } from "@requestnetwork/shared-utils/generateInvoice"; + import { getCurrencyFromManager } from "@requestnetwork/shared-utils/getCurrency"; import { CurrencyManager } from "@requestnetwork/currency"; import type { RequestNetwork } from "@requestnetwork/request-client.js"; import { Types } from "@requestnetwork/request-client.js"; import { onMount } from "svelte"; import { formatUnits } from "viem"; - import { capitalize, debounce, exportToPDF, formatAddress } from "../utils"; - import { getCurrencyFromManager } from "../utils/getCurrency"; + import { capitalize, debounce, formatAddress } from "../utils"; + import { Drawer, InvoiceView } from "./dashboard"; export let config: IConfig; @@ -515,8 +517,8 @@ {formatAddress( currentTab === "Pay" - ? (request.payee?.value ?? "") - : (request.payer?.value ?? "") + ? request.payee?.value ?? "" + : request.payer?.value ?? "" )} import { fade } from "svelte/transition"; + import { exportToPDF } from "@requestnetwork/shared-utils/generateInvoice"; + import { getCurrencyFromManager } from "@requestnetwork/shared-utils/getCurrency"; + import { initializeCurrencyManager } from "@requestnetwork/shared-utils/initCurrencyManager"; + import Toaster from "@requestnetwork/shared-components/sonner.svelte"; + import { toast } from "svelte-sonner"; + + export let createdRequest: any; + export let enablePdfReceipt: boolean = true; + export let enableRequestScanLink: boolean = true; + export let sellerLogo: string = ""; + + async function handleDownloadReceipt() { + if (createdRequest) { + try { + const currencyManager = initializeCurrencyManager([]); + + const currencyData = createdRequest?.inMemoryInfo?.requestData; + + await exportToPDF( + currencyData, + getCurrencyFromManager(currencyData.currencyInfo, currencyManager), + sellerLogo + ); + } catch (error) { + toast.error(`Failed to export PDF`, { + description: `${error}`, + action: { + label: "X", + onClick: () => console.info("Close"), + }, + }); + } + } + } +

Payment Complete

Thank you for your payment. Your transaction was successful.

+ + {#if enablePdfReceipt || (enableRequestScanLink && createdRequest)} +
+ {#if enablePdfReceipt} + + {/if} + {#if enableRequestScanLink && createdRequest} + + View on Request Scan + + {/if} +
+ {/if}
- -
+
- ${logo ? `Logo` : ""} + ${logo && logo.length > 0 ? `Logo` : ""}

Issued on ${formatDate(invoice.contentData?.creationDate)}

Payment due by ${formatDate(invoice.contentData?.paymentTerms?.dueDate)}

-

INVOICE #${ +

INVOICE #${ invoice.contentData?.invoiceNumber || "-" }

-
+
From:
-

${invoice.payee?.value || "-"}

- ${invoice.contentData?.sellerInfo?.firstName || ""} ${invoice.contentData?.sellerInfo?.lastName || ""}
- ${renderAddress(invoice.contentData?.sellerInfo)}
- ${invoice.contentData?.sellerInfo?.taxRegistration ? `VAT: ${invoice.contentData.sellerInfo.taxRegistration}` : ""} +

${invoice.payee?.value || "-"}

+

${invoice.contentData?.sellerInfo?.firstName || ""} ${invoice.contentData?.sellerInfo?.lastName || ""}

+

${renderAddress(invoice.contentData?.sellerInfo)}

+ ${invoice.contentData?.sellerInfo?.taxRegistration ? `

VAT: ${invoice.contentData.sellerInfo.taxRegistration}

` : ""}
-
+
To:
-

${invoice.payer?.value || "-"}

- ${invoice.contentData?.buyerInfo?.firstName || ""} ${invoice.contentData?.buyerInfo?.lastName || ""}
- ${renderAddress(invoice.contentData?.buyerInfo)}
- ${invoice.contentData?.buyerInfo?.taxRegistration ? `VAT: ${invoice.contentData.buyerInfo.taxRegistration}` : ""} +

${invoice.payer?.value || "-"}

+

${invoice.contentData?.buyerInfo?.firstName || ""} ${invoice.contentData?.buyerInfo?.lastName || ""}

+

${renderAddress(invoice.contentData?.buyerInfo)}

+ ${invoice.contentData?.buyerInfo?.taxRegistration ? `

VAT: ${invoice.contentData.buyerInfo.taxRegistration}

` : ""}
-
+
Payment Chain: ${invoice.currencyInfo?.network || "-"}
Invoice Currency: ${invoice.currency || "-"}
Invoice Type: Regular Invoice
- +
- - - - - - - + + + + + + + @@ -101,22 +126,22 @@ export const exportToPDF = async ( .map( (item: any) => ` - - - + + - - - - - +
DescriptionQuantityUnit PriceDiscountTaxAmount
DescriptionQuantityUnit PriceDiscountTaxAmount
${item.name || "-"}${item.quantity || "-"}${ + ${item.name || "-"}${item.quantity || "-"}${ item.unitPrice ? formatUnits(BigInt(item.unitPrice), currency?.decimals || 0) : "-" }${ + ${ item.discount ? formatUnits(BigInt(item.discount), currency?.decimals || 0) : "-" }${ + ${ item.tax?.amount ? `${item.tax.amount}%` : "-" }${ + ${ item ? formatUnits( BigInt(calculateItemTotal(item)), @@ -131,8 +156,8 @@ export const exportToPDF = async (
Due:${ + Due:${ invoice.expectedAmount ? `${formatUnits(BigInt(invoice.expectedAmount), currency?.decimals || 0)} ${invoice.currency || ""}` : "-" @@ -143,7 +168,7 @@ export const exportToPDF = async ( ${ invoice.contentData?.note - ? `
+ ? `

Note:

${invoice.contentData.note}

` diff --git a/packages/invoice-dashboard/src/utils/getCurrency.ts b/shared/utils/getCurrency.ts similarity index 100% rename from packages/invoice-dashboard/src/utils/getCurrency.ts rename to shared/utils/getCurrency.ts