dveldhoen / easyinvoice

MIT License
165 stars 31 forks source link

500 error #125

Closed mario8754 closed 7 months ago

mario8754 commented 7 months ago

Im getting an error when tryning to create an invoice

[Node] { result: { statusCode: 500, message: 'Internal server error' } } [Node] node:internal/process/promises:279 [Node] triggerUncaughtException(err, true / fromPromise /); [Node] ^ [Node] [Node] [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#".] { [Node] code: 'ERR_UNHANDLED_REJECTION' [Node] }

dveldhoen commented 7 months ago

Hi, what config are you using?

mario8754 commented 7 months ago

im using nodejs ts en then version [3.0.47] of easy invoice

mario8754 commented 7 months ago

import easyinvoice, { InvoiceData } from "easyinvoice"; import path from "path"; import fs from "fs";

interface InvoiceProduct { description?: string; price?: number;

orderNumber?: string; adres?: string; postCode?: string; city?: string; land?: string; date?: string; name?: string; } export const data: InvoiceData = { // Customize enables ydou to provide your own templates // Please review the documentation for instructions and examples customize: { // "template": fs.readFileSync('template.html', 'base64') // Must be base64 encoded html }, // apiKey: process.env.APIKEY, images: { logo: "https://public.budgetinvoice.com/img/logo_en_original.png", background: "https://public.budgetinvoice.com/img/watermark_draft.jpg", //logo: "https:/.nl/img/logo.a6e4aac4.png",

}, sender: { company: " ", address: " ", zip: " ", city: " ", country: " ", }, client: { company: "", address: "", zip: "", city: "", country: "", }, information: { number: "", date: "", // "due-date": "31-12-2021", }, products: [ // { // quantity: 1, // description: " ", // "tax-rate": 21, // price: 0, // }, ], bottomNotice: "test",

// Settings to customize your invoice settings: { currency: "EUR", // See documentation 'Locales and Currency' for more info. Leave empty for no currency. locale: "nl-NL", // Defaults to en-US, used for number formatting (See documentation 'Locales and Currency') marginTop: 25, // Defaults to '25' marginRight: 25, // Defaults to '25' marginLeft: 25, // Defaults to '25' marginBottom: 25, // Defaults to '25' format: "A4", // Defaults to A4, options: A3, A4, A5, Legal, Letter, Tabloid // height: "1000px", // width: "500px", // orientation: "landscape", // portrait or landscape, defaults to portrait }, // Translate your invoice to your preferred language translate: { invoice: "Factuur", // Default to 'INVOICE' number: "Nummer", // Defaults to 'Number' date: "Datum", // Default to 'Date' dueDate: "Betaaldatum", // Defaults to 'Due Date' subtotal: "Subtotaal", // Defaults to 'Subtotal' products: "kavelnummers", // Defaults to 'Products' quantity: "Aantal", // Default to 'Quantity' price: "Prijs", // Defaults to 'Price' productTotal: "Totaal", // Defaults to 'Total' total: "Totaal", // Defaults to 'Total' vat: "btw", // Defaults to 'vat' }, };

export function generateInvoice(data: InvoiceData, fileName: string) { const invoicesDirectory = path.join( __dirname, "..", "..", "folders/facturen" ); console.log({ invoicesDirectory }); if (!fs.existsSync(invoicesDirectory)) { fs.mkdirSync(invoicesDirectory); } const filePath = path.join(invoicesDirectory, fileName); console.log(filePath); return new Promise((resolve, reject) => { easyinvoice.createInvoice(data, async function (result: { pdf: string }) { console.log({ result }); fs.writeFile(filePath, result.pdf, { encoding: "base64" }, (err) => { if (err) { console.error( "Er is een fout opgetreden bij het opslaan van de PDF:", err ); reject(err); } else { console.log("PDF succesvol opgeslagen op de server."); resolve(result.pdf); } }); }); }); }

mario8754 commented 7 months ago

is there something change or just the apikey that needs to be added

dveldhoen commented 7 months ago

Hi, sorry, we didn't get a chance to respond yet. Had your issue been fixed?