Skip to content

Commit

Permalink
Merge pull request #23 from h1dd3nsn1p3r/development
Browse files Browse the repository at this point in the history
📦 Added: Config option.
  • Loading branch information
h1dd3nsn1p3r authored Jan 20, 2024
2 parents 1d1c622 + 60d907a commit e4380f9
Show file tree
Hide file tree
Showing 23 changed files with 342 additions and 93 deletions.
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,50 @@ handleInvoice();

Once you call the `create` method, it will return a promise. You can either use `async/await` or `.then()` to handle the promise. The `create` method will return the path to the PDF file if the PDF is generated successfully. Otherwise, it will throw an error.

## Configuration

If required you can change the configuration of the invoice. It is an object with the following structure:

```js
const { PDFInvoice } = require('@h1dd3nsn1p3r/pdf-invoice');
const create = async(): Promise<void> => {
const payload = {
// ....
};
const config = {
// Custom labels.
string: {
invoice: "F A C T U A",
refNumber: "Referencia",
date: "Fecha",
dueDate: "Fecha de vencimiento",
status: "Estado",
billTo: "Facturar a",
item: "Artículo",
quantity: "Cantidad",
price: "Precio",
tax: "Impuesto",
total: "Total",
subTotal: "Subtotal",
totalTax: "Total Impuesto",
},
};
// Create the invoice.
const invoice = new PDFInvoice(payload, config);
const pdf = await invoice.create();
console.log(pdf);
}
```

### Config limitations:

For now only `latin` characters are supported. It seems like a limitation of `Helvetica` font. I'll be adding support for other languages soon.
## Types
This library is written in TypeScript. If you need to import the types, then you can import them from `global.d.ts` file. Refer to [Global types](https://github.com/h1dd3nsn1p3r/pdf-invoice/blob/stable/global.d.ts) file for more information.
Expand All @@ -282,8 +326,12 @@ import type { CompanyInfo, CustomerInfo, InvoiceInfo, ItemInfo, QRInfo, InvoiceP
Refer to [releases](https://github.com/h1dd3nsn1p3r/pdf-invoice/releases) section for more information.
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
## Todo
- [ ] Add design/style options.
- [ ] Add configuration options.
- [ ] Add configuration options - (Strings, Fonts, Styles, etc.)
- [ ] Add support for multi-language.
37 changes: 35 additions & 2 deletions dist/class/invoice.d.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface CompanyInfo {
logo?: string;
name: string;
name?: string;
address?: string;
phone?: string;
email?: string;
Expand Down Expand Up @@ -59,6 +59,38 @@ interface SimplePDFInvoice {
styles(): any;
}

interface Configuration {
string: {
invoice?: string;
refNumber?: string;
date?: string;
dueDate?: string;
status?: string;
billTo?: string;
item?: string;
quantity?: string;
price?: string;
tax?: string;
total?: string;
subTotal?: string;
totalTax?: string;
};
font: [
helvetica?: {
normal?: string;
bold?: string;
italics?: string;
bolditalics?: string;
},
noto?: {
normal?: string;
bold?: string;
italics?: string;
bolditalics?: string;
}
];
}

declare class PDFInvoice implements SimplePDFInvoice {
payload: InvoicePayLoad;
company: CompanyInfo;
Expand All @@ -70,7 +102,8 @@ declare class PDFInvoice implements SimplePDFInvoice {
qr: QRInfo;
note: Notes;
date: string;
constructor(payload: InvoicePayLoad);
config: Configuration;
constructor(payload: InvoicePayLoad, config?: Configuration);
/**
* Create a PDF invoice.
*
Expand Down
37 changes: 35 additions & 2 deletions dist/class/invoice.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface CompanyInfo {
logo?: string;
name: string;
name?: string;
address?: string;
phone?: string;
email?: string;
Expand Down Expand Up @@ -59,6 +59,38 @@ interface SimplePDFInvoice {
styles(): any;
}

interface Configuration {
string: {
invoice?: string;
refNumber?: string;
date?: string;
dueDate?: string;
status?: string;
billTo?: string;
item?: string;
quantity?: string;
price?: string;
tax?: string;
total?: string;
subTotal?: string;
totalTax?: string;
};
font: [
helvetica?: {
normal?: string;
bold?: string;
italics?: string;
bolditalics?: string;
},
noto?: {
normal?: string;
bold?: string;
italics?: string;
bolditalics?: string;
}
];
}

declare class PDFInvoice implements SimplePDFInvoice {
payload: InvoicePayLoad;
company: CompanyInfo;
Expand All @@ -70,7 +102,8 @@ declare class PDFInvoice implements SimplePDFInvoice {
qr: QRInfo;
note: Notes;
date: string;
constructor(payload: InvoicePayLoad);
config: Configuration;
constructor(payload: InvoicePayLoad, config?: Configuration);
/**
* Create a PDF invoice.
*
Expand Down
36 changes: 18 additions & 18 deletions dist/class/invoice.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/class/invoice.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit e4380f9

Please sign in to comment.