diff --git a/README.md b/README.md
index 2179431..0a90440 100644
--- a/README.md
+++ b/README.md
@@ -122,7 +122,7 @@ This is the information about your company. It is an object with the following s
```js
const company = {
logo: "... ", // Optional. SVG logo of your company.
- name: "Festrol Corp.", // Required.
+ name: "Festrol Corp.", // Optional or required if logo is not supplied.
address: "1711 W. El Segundo Blvd, Hawthorne, \n Canada - 90250", // Optional.
phone: "Tel: (+11) 245 543 903", // Optional.
email: "hello@company.com", // Optional.
@@ -131,7 +131,9 @@ const company = {
}
```
-For now, only **SVG logo** can be used. The name of the company is required. Rest of the fields are optional.
+For now, only **svg logo** can be used. If you wish to use logo & do not want the company name, then do not pass the `name` field. Rest of the fields are optional.
+
+```js
### Invoice
@@ -285,4 +287,3 @@ Refer to [releases](https://github.com/h1dd3nsn1p3r/pdf-invoice/releases) sectio
- [ ] Add design/style options.
- [ ] Add configuration options.
- [ ] Add support for multi-language.
-- [ ] Better error handling.
diff --git a/dist/class/invoice.js b/dist/class/invoice.js
index 0ccb3e5..c83a753 100644
--- a/dist/class/invoice.js
+++ b/dist/class/invoice.js
@@ -1,16 +1,16 @@
'use strict';
-var l=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var y=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var h=y((b,r)=>{var p={calcItemTotal:function(s){let t=s.price||0,e=s.quantity||1;return (t*e).toFixed(2)},calcSubTotal:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{t+=Number(this.calcItemTotal(e));}),t.toFixed(2)},calcTax:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{let n=e.price,c=e.quantity,i=e.tax||0;t+=n*c*i/100;}),t.toFixed(2)},calcFinalTotal:function(s){if(s.length===0)return 0;let t=Number(this.calcSubTotal(s)),e=Number(this.calcTax(s));return (t+e).toFixed(2)}};r.exports=p;});var f=l("fs"),d=l("path"),x=l("pdfmake"),a=h(),u=class{payload;company;invoice;customer;items;currency;path;qr;note;date;constructor(t){this.payload=t,this.company=t.company,this.customer=t.customer,this.invoice=t.invoice,this.items=t.items,this.qr=t.qr,this.note=t.note,this.currency=this.invoice.currency||"$",this.path=d.resolve(this.invoice.path)||"./invoice.pdf",this.date=new Date().toLocaleDateString("en-US",{year:"numeric",month:"numeric",day:"numeric"});}async create(){let t=new x(this.fonts()),e={pageSize:"A4",orientation:"portrait",pageMargins:[40,40,40,40],info:this.meta(),content:this.content(),defaultStyle:this.defaultStyle(),styles:this.styles()};return new Promise((n,c)=>{let i=t.createPdfKitDocument(e);i.pipe(f.createWriteStream(this.path)),i.end(),i.on("end",()=>{n(this.path);}),i.on("error",o=>{c(o);});})}fonts(){return {Helvetica:{normal:"Helvetica",bold:"Helvetica-Bold",italics:"Helvetica-Oblique",bolditalics:"Helvetica-BoldOblique"}}}meta(){return {title:"Invoice - #"+this.invoice.number,author:this.company.name,subject:"Invoice - "+this.customer.name,keywords:"invoice"}}defaultStyle(){return {fontSize:10,lineHeight:1.8,bold:!1,font:"Helvetica",color:"#222222",columnGap:30}}styles(){return {h1:{fontSize:18,bold:!0},h2:{fontSize:16,bold:!0},h3:{fontSize:14,bold:!0},text:{fontSize:10,bold:!1},textBold:{fontSize:10,bold:!0}}}content(){let t=[],e={columns:[{width:"70%",stack:[],style:"text"},{width:"30%",stack:[],style:"text"}]};if(this.company.logo){if(!this.company.logo.startsWith("typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var y=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var u=y((b,h)=>{var p={calcItemTotal:function(s){let t=s.price||0,e=s.quantity||1;return (t*e).toFixed(2)},calcSubTotal:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{t+=Number(this.calcItemTotal(e));}),t.toFixed(2)},calcTax:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{let n=e.price,c=e.quantity,i=e.tax||0;t+=n*c*i/100;}),t.toFixed(2)},calcFinalTotal:function(s){if(s.length===0)return 0;let t=Number(this.calcSubTotal(s)),e=Number(this.calcTax(s));return (t+e).toFixed(2)}};h.exports=p;});var f=r("fs"),d=r("path"),x=r("pdfmake"),a=u(),m=class{payload;company;invoice;customer;items;currency;path;qr;note;date;constructor(t){this.payload=t,this.company=t.company,this.customer=t.customer,this.invoice=t.invoice,this.items=t.items,this.qr=t.qr,this.note=t.note,this.currency=this.invoice.currency||"$",this.path=d.resolve(this.invoice.path)||"./invoice.pdf",this.date=new Date().toLocaleDateString("en-US",{year:"numeric",month:"numeric",day:"numeric"});}async create(){let t=new x(this.fonts()),e={pageSize:"A4",orientation:"portrait",pageMargins:[40,40,40,40],info:this.meta(),content:this.content(),defaultStyle:this.defaultStyle(),styles:this.styles()};return new Promise((n,c)=>{let i=t.createPdfKitDocument(e),o=f.createWriteStream(this.path);i.pipe(o),i.on("end",()=>{n(this.path);}),i.on("error",l=>{c(l);}),i.end();})}fonts(){return {Helvetica:{normal:"Helvetica",bold:"Helvetica-Bold",italics:"Helvetica-Oblique",bolditalics:"Helvetica-BoldOblique"}}}meta(){return {title:"Invoice - #"+this.invoice.number,author:this.company.name,subject:"Invoice - "+this.customer.name,keywords:"invoice"}}defaultStyle(){return {fontSize:10,lineHeight:1.8,bold:!1,font:"Helvetica",color:"#222222",columnGap:30}}styles(){return {h1:{fontSize:18,bold:!0},h2:{fontSize:16,bold:!0},h3:{fontSize:14,bold:!0},text:{fontSize:10,bold:!1},textBold:{fontSize:10,bold:!0}}}content(){let t=[],e={columns:[{width:"70%",stack:[],style:"text"},{width:"30%",stack:[],style:"text"}]};if(this.company.logo){if(!this.company.logo.startsWith("0&&this.items.forEach(o=>{let m=a.calcItemTotal(o);c.table.body.push([`
+ Total`]]}};this.items.length>0&&this.items.forEach(o=>{let l=a.calcItemTotal(o);c.table.body.push([`
${o.name}`,`
${o.quantity}`,`
${this.currency}${o.price}`,`
${o.tax||0}%`,`
- ${this.currency}${m}`]);}),t.push(c);let i={margin:[0,20,0,0],columns:[{width:"*",stack:[" "],style:"text"},{width:200,lineHeight:1.5,style:"textBold",table:{widths:[80,"*"],headerRows:1,lineHeight:1.5,body:[[`
+ ${this.currency}${l}`]);}),t.push(c);let i={margin:[0,20,0,0],columns:[{width:"*",stack:[" "],style:"text"},{width:200,lineHeight:1.5,style:"textBold",table:{widths:[80,"*"],headerRows:1,lineHeight:1.5,body:[[`
Subtotal`,`
${this.currency}${a.calcSubTotal(this.items)}`],[`
Total Tax`,`
@@ -18,6 +18,6 @@ var l=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(t
Total`,`
${this.currency}${a.calcFinalTotal(this.items)}`]]}}]};if(t.push(i),this.payload.qr){let o={margin:[0,50,0,0],qr:this.payload.qr.data,fit:this.payload.qr.width||"50"};t.push(o);}if(this.payload.note){let o={margin:[0,this.payload.qr?20:50,0,0],text:this.payload.note,italics:!0};t.push(o);}return t}};
-exports.PDFInvoice = u;
+exports.PDFInvoice = m;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=invoice.js.map
\ No newline at end of file
diff --git a/dist/class/invoice.js.map b/dist/class/invoice.js.map
index 74f3ebd..6dda140 100644
--- a/dist/class/invoice.js.map
+++ b/dist/class/invoice.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../../src/utils/helper.ts","../../src/class/invoice.ts"],"names":["require_helper","__commonJSMin","exports","module","helper","item","price","quantity","items","total","tax","subTotal","fs","path","invoiceMaker","PDFInvoice","payload","printer","docDefinition","resolve","reject","doc","e","sections","sectionCompany","sectionCustomer","sectionItems","totalPrice","sectionTotal","sectionQR","sectionNote"],"mappings":"uTAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cASA,IAAMC,EAAkB,CAQvB,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AAGxB,EAAO,aAC5B,KAAK,KACN,CAAC,EACF,EACA,CACC;AAAA,YACA;AAAA,GAAM,KAAK,QAAQ,GAAGA,EAAO,QAC5B,KAAK,KACN,CAAC,EACF,EACA,CACC;AAAA,QACA;AAAA,GAAM,KAAK,QAAQ,GAAGA,EAAO,eAC5B,KAAK,KACN,CAAC,EACF,CACD,CACD,CACD,CACD,CACD,EASA,GAPAmB,EAAS,KAAKK,CAAY,EAOtB,KAAK,QAAQ,GAAI,CACpB,IAAMC,EAAY,CACjB,OAAQ,CAAC,EAAG,GAAI,EAAG,CAAC,EACpB,GAAI,KAAK,QAAQ,GAAG,KACpB,IAAK,KAAK,QAAQ,GAAG,OAAS,IAC/B,EAEAN,EAAS,KAAKM,CAAS,CACxB,CAOA,GAAI,KAAK,QAAQ,KAAM,CACtB,IAAMC,EAAc,CACnB,OAAQ,CAAC,EAAG,KAAK,QAAQ,GAAK,GAAK,GAAI,EAAG,CAAC,EAC3C,KAAM,KAAK,QAAQ,KACnB,QAAS,EACV,EAEAP,EAAS,KAAKO,CAAW,CAC1B,CAOA,OAAOP,CACR,CACD","sourcesContent":["import type { ItemInfo } from \"../../global\";\r\n\r\ninterface Helpers {\r\n\tcalcItemTotal(item: ItemInfo): number | string;\r\n\tcalcTax(items: ItemInfo[]): number | string;\r\n\tcalcSubTotal(items: ItemInfo[]): number | string;\r\n\tcalcFinalTotal(items: ItemInfo[]): number | string;\r\n}\r\n\r\nconst helper: Helpers = {\r\n\t/**\r\n\t * Item total price calculation.\r\n\t *\r\n\t * @param {Object} item.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcItemTotal: function (item: ItemInfo): string {\r\n\t\tconst price = item.price || 0;\r\n\t\tconst quantity = item.quantity || 1;\r\n\t\treturn (price * quantity).toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate subtotal.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcSubTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\ttotal += Number(this.calcItemTotal(item));\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate tax.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcTax: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\tconst price = item.price;\r\n\t\t\tconst quantity = item.quantity;\r\n\t\t\tconst tax = item.tax || 0;\r\n\r\n\t\t\ttotal += (price * quantity * tax) / 100;\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate total final price.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcFinalTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tconst subTotal = Number(this.calcSubTotal(items));\r\n\t\tconst tax = Number(this.calcTax(items));\r\n\r\n\t\treturn (subTotal + tax).toFixed(2);\r\n\t},\r\n};\r\n\r\nmodule.exports = helper;\r\n","const fs = require(\"fs\");\r\nconst path = require(\"path\");\r\nconst invoiceMaker = require(\"pdfmake\");\r\nconst helper = require(\"../utils/helper\");\r\nimport type {\r\n\tCompanyInfo,\r\n\tCustomerInfo,\r\n\tInvoiceInfo,\r\n\tItemInfo,\r\n\tQRInfo,\r\n\tNotes,\r\n\tInvoicePayLoad,\r\n\tSimplePDFInvoice,\r\n} from \"../../global\";\r\n\r\nexport class PDFInvoice implements SimplePDFInvoice {\r\n\tpayload: InvoicePayLoad;\r\n\tcompany: CompanyInfo;\r\n\tinvoice: InvoiceInfo;\r\n\tcustomer: CustomerInfo;\r\n\titems: ItemInfo[];\r\n\tcurrency: string;\r\n\tpath: string;\r\n\tqr: QRInfo;\r\n\tnote: Notes;\r\n\tdate: string;\r\n\tconstructor(payload: InvoicePayLoad) {\r\n\t\tthis.payload = payload;\r\n\r\n\t\t// Invoice content section.\r\n\t\tthis.company = payload.company;\r\n\t\tthis.customer = payload.customer;\r\n\t\tthis.invoice = payload.invoice;\r\n\t\tthis.items = payload.items;\r\n\t\tthis.qr = payload.qr;\r\n\t\tthis.note = payload.note;\r\n\r\n\t\t// Invoice currency.\r\n\t\tthis.currency = this.invoice.currency || \"$\";\r\n\r\n\t\t// Path.\r\n\t\tthis.path = path.resolve(this.invoice.path) || \"./invoice.pdf\";\r\n\r\n\t\t// Invoice information.\r\n\t\tthis.date = new Date().toLocaleDateString(\"en-US\", {\r\n\t\t\tyear: \"numeric\",\r\n\t\t\tmonth: \"numeric\",\r\n\t\t\tday: \"numeric\",\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Create a PDF invoice.\r\n\t *\r\n\t * @returns {void}\r\n\t * @since 1.0.0\r\n\t */\r\n\tasync create(): Promise {\r\n\t\tconst printer = new invoiceMaker(this.fonts());\r\n\r\n\t\tconst docDefinition = {\r\n\t\t\tpageSize: \"A4\",\r\n\t\t\torientation: \"portrait\",\r\n\t\t\tpageMargins: [40, 40, 40, 40],\r\n\t\t\tinfo: this.meta(),\r\n\t\t\tcontent: this.content(),\r\n\t\t\tdefaultStyle: this.defaultStyle(),\r\n\t\t\tstyles: this.styles(),\r\n\t\t};\r\n\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst doc = printer.createPdfKitDocument(docDefinition);\r\n\r\n\t\t\tdoc.pipe(fs.createWriteStream(this.path));\r\n\r\n\t\t\tdoc.end();\r\n\r\n\t\t\tdoc.on(\"end\", () => {\r\n\t\t\t\tresolve(this.path);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.on(\"error\", (e: any) => {\r\n\t\t\t\treject(e);\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Fonts.\r\n\t *\r\n\t * @returns {Object} font.\r\n\t * @since 1.0.0\r\n\t */\r\n\tfonts(): any {\r\n\t\tconst fonts = {\r\n\t\t\tHelvetica: {\r\n\t\t\t\tnormal: \"Helvetica\",\r\n\t\t\t\tbold: \"Helvetica-Bold\",\r\n\t\t\t\titalics: \"Helvetica-Oblique\",\r\n\t\t\t\tbolditalics: \"Helvetica-BoldOblique\",\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\treturn fonts;\r\n\t}\r\n\r\n\t/**\r\n\t * Doc meta.\r\n\t *\r\n\t * @returns {Object} meta.\r\n\t * @since 1.0.0\r\n\t */\r\n\tmeta(): any {\r\n\t\tconst meta = {\r\n\t\t\ttitle: \"Invoice - #\" + this.invoice.number,\r\n\t\t\tauthor: this.company.name,\r\n\t\t\tsubject: \"Invoice - \" + this.customer.name,\r\n\t\t\tkeywords: \"invoice\",\r\n\t\t};\r\n\r\n\t\treturn meta;\r\n\t}\r\n\r\n\t/**\r\n\t * Default invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tdefaultStyle(): any {\r\n\t\tconst defaults = {\r\n\t\t\tfontSize: 10,\r\n\t\t\tlineHeight: 1.8,\r\n\t\t\tbold: false,\r\n\t\t\tfont: \"Helvetica\",\r\n\t\t\tcolor: \"#222222\",\r\n\t\t\tcolumnGap: 30,\r\n\t\t};\r\n\t\treturn defaults;\r\n\t}\r\n\r\n\t/**\r\n\t * Invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tstyles(): any {\r\n\t\tconst styles = {\r\n\t\t\th1: {\r\n\t\t\t\tfontSize: 18,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th2: {\r\n\t\t\t\tfontSize: 16,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th3: {\r\n\t\t\t\tfontSize: 14,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\ttext: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: false,\r\n\t\t\t},\r\n\t\t\ttextBold: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t};\r\n\t\treturn styles;\r\n\t}\r\n\r\n\t/**\r\n\t * Return the invoice layout.\r\n\t *\r\n\t * @returns {Object} layout.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcontent(): any {\r\n\t\tconst sections = [];\r\n\r\n\t\t/**\r\n\t\t * Left: Company section.\r\n\t\t * Right: Invoice section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionCompany = {\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"70%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"30%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tif (this.company.logo) {\r\n\t\t\tif (!this.company.logo.startsWith(\" 0) {\r\n\t\t\tthis.items.forEach((item) => {\r\n\t\t\t\tconst totalPrice = helper.calcItemTotal(item);\r\n\r\n\t\t\t\tsectionItems.table.body.push([\r\n\t\t\t\t\t`\\n ${item.name}`,\r\n\t\t\t\t\t`\\n ${item.quantity}`,\r\n\t\t\t\t\t`\\n ${this.currency}${item.price}`,\r\n\t\t\t\t\t`\\n ${item.tax || 0}%`,\r\n\t\t\t\t\t`\\n ${this.currency}${totalPrice}`,\r\n\t\t\t\t]);\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tsections.push(sectionItems);\r\n\r\n\t\t/**\r\n\t\t * Right: Total section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionTotal = {\r\n\t\t\tmargin: [0, 20, 0, 0],\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"*\",\r\n\t\t\t\t\tstack: [\" \"],\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: 200,\r\n\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\tstyle: \"textBold\",\r\n\t\t\t\t\ttable: {\r\n\t\t\t\t\t\twidths: [80, \"*\"],\r\n\t\t\t\t\t\theaderRows: 1,\r\n\t\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\t\tbody: [\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Subtotal\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcSubTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total Tax\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcTax(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcFinalTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t},\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tsections.push(sectionTotal);\r\n\r\n\t\t/**\r\n\t\t * Left: QR section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.qr) {\r\n\t\t\tconst sectionQR = {\r\n\t\t\t\tmargin: [0, 50, 0, 0],\r\n\t\t\t\tqr: this.payload.qr.data,\r\n\t\t\t\tfit: this.payload.qr.width || \"50\",\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionQR);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Left: Notes section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.note) {\r\n\t\t\tconst sectionNote = {\r\n\t\t\t\tmargin: [0, this.payload.qr ? 20 : 50, 0, 0],\r\n\t\t\t\ttext: this.payload.note,\r\n\t\t\t\titalics: true,\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionNote);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Return the invoice sections.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\treturn sections;\r\n\t}\r\n}\r\n"]}
\ No newline at end of file
+{"version":3,"sources":["../../src/utils/helper.ts","../../src/class/invoice.ts"],"names":["require_helper","__commonJSMin","exports","module","helper","item","price","quantity","items","total","tax","subTotal","fs","path","invoiceMaker","PDFInvoice","payload","printer","docDefinition","resolve","reject","doc","stream","err","sections","sectionCompany","sectionCustomer","sectionItems","totalPrice","sectionTotal","sectionQR","sectionNote"],"mappings":"uTAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cASA,IAAMC,EAAkB,CAQvB,cAAe,SAAUC,EAAwB,CAChD,IAAMC,EAAQD,EAAK,OAAS,EACtBE,EAAWF,EAAK,UAAY,EAClC,OAAQC,EAAQC,GAAU,QAAQ,CAAC,CACpC,EASA,aAAc,SAAUC,EAAoC,CAC3D,GAAIA,EAAM,SAAW,EACpB,MAAO,GAGR,IAAIC,EAAQ,EAEZ,OAAAD,EAAM,QAASH,GAAS,CAC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ACD,CACD,CACD,EASA,GAPAoB,EAAS,KAAKK,CAAY,EAOtB,KAAK,QAAQ,GAAI,CACpB,IAAMC,EAAY,CACjB,OAAQ,CAAC,EAAG,GAAI,EAAG,CAAC,EACpB,GAAI,KAAK,QAAQ,GAAG,KACpB,IAAK,KAAK,QAAQ,GAAG,OAAS,IAC/B,EAEAN,EAAS,KAAKM,CAAS,CACxB,CAOA,GAAI,KAAK,QAAQ,KAAM,CACtB,IAAMC,EAAc,CACnB,OAAQ,CAAC,EAAG,KAAK,QAAQ,GAAK,GAAK,GAAI,EAAG,CAAC,EAC3C,KAAM,KAAK,QAAQ,KACnB,QAAS,EACV,EAEAP,EAAS,KAAKO,CAAW,CAC1B,CAOA,OAAOP,CACR,CACD","sourcesContent":["import type { ItemInfo } from \"../../global\";\r\n\r\ninterface Helpers {\r\n\tcalcItemTotal(item: ItemInfo): number | string;\r\n\tcalcTax(items: ItemInfo[]): number | string;\r\n\tcalcSubTotal(items: ItemInfo[]): number | string;\r\n\tcalcFinalTotal(items: ItemInfo[]): number | string;\r\n}\r\n\r\nconst helper: Helpers = {\r\n\t/**\r\n\t * Item total price calculation.\r\n\t *\r\n\t * @param {Object} item.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcItemTotal: function (item: ItemInfo): string {\r\n\t\tconst price = item.price || 0;\r\n\t\tconst quantity = item.quantity || 1;\r\n\t\treturn (price * quantity).toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate subtotal.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcSubTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\ttotal += Number(this.calcItemTotal(item));\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate tax.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcTax: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\tconst price = item.price;\r\n\t\t\tconst quantity = item.quantity;\r\n\t\t\tconst tax = item.tax || 0;\r\n\r\n\t\t\ttotal += (price * quantity * tax) / 100;\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate total final price.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcFinalTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tconst subTotal = Number(this.calcSubTotal(items));\r\n\t\tconst tax = Number(this.calcTax(items));\r\n\r\n\t\treturn (subTotal + tax).toFixed(2);\r\n\t},\r\n};\r\n\r\nmodule.exports = helper;\r\n","const fs = require(\"fs\");\r\nconst path = require(\"path\");\r\nconst invoiceMaker = require(\"pdfmake\");\r\nconst helper = require(\"../utils/helper\");\r\nimport type {\r\n\tCompanyInfo,\r\n\tCustomerInfo,\r\n\tInvoiceInfo,\r\n\tItemInfo,\r\n\tQRInfo,\r\n\tNotes,\r\n\tInvoicePayLoad,\r\n\tSimplePDFInvoice,\r\n} from \"../../global\";\r\n\r\nexport class PDFInvoice implements SimplePDFInvoice {\r\n\tpayload: InvoicePayLoad;\r\n\tcompany: CompanyInfo;\r\n\tinvoice: InvoiceInfo;\r\n\tcustomer: CustomerInfo;\r\n\titems: ItemInfo[];\r\n\tcurrency: string;\r\n\tpath: string;\r\n\tqr: QRInfo;\r\n\tnote: Notes;\r\n\tdate: string;\r\n\tconstructor(payload: InvoicePayLoad) {\r\n\t\tthis.payload = payload;\r\n\r\n\t\t// Invoice content section.\r\n\t\tthis.company = payload.company;\r\n\t\tthis.customer = payload.customer;\r\n\t\tthis.invoice = payload.invoice;\r\n\t\tthis.items = payload.items;\r\n\t\tthis.qr = payload.qr;\r\n\t\tthis.note = payload.note;\r\n\r\n\t\t// Invoice currency.\r\n\t\tthis.currency = this.invoice.currency || \"$\";\r\n\r\n\t\t// Path.\r\n\t\tthis.path = path.resolve(this.invoice.path) || \"./invoice.pdf\";\r\n\r\n\t\t// Invoice information.\r\n\t\tthis.date = new Date().toLocaleDateString(\"en-US\", {\r\n\t\t\tyear: \"numeric\",\r\n\t\t\tmonth: \"numeric\",\r\n\t\t\tday: \"numeric\",\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Create a PDF invoice.\r\n\t *\r\n\t * @returns {void}\r\n\t * @since 1.0.0\r\n\t */\r\n\tasync create(): Promise {\r\n\t\tconst printer = new invoiceMaker(this.fonts());\r\n\r\n\t\tconst docDefinition = {\r\n\t\t\tpageSize: \"A4\",\r\n\t\t\torientation: \"portrait\",\r\n\t\t\tpageMargins: [40, 40, 40, 40],\r\n\t\t\tinfo: this.meta(),\r\n\t\t\tcontent: this.content(),\r\n\t\t\tdefaultStyle: this.defaultStyle(),\r\n\t\t\tstyles: this.styles(),\r\n\t\t};\r\n\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst doc = printer.createPdfKitDocument(docDefinition);\r\n\t\t\tconst stream = fs.createWriteStream(this.path);\r\n\r\n\t\t\tdoc.pipe(stream);\r\n\r\n\t\t\tdoc.on(\"end\", () => {\r\n\t\t\t\tresolve(this.path);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.on(\"error\", (err: any) => {\r\n\t\t\t\treject(err);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.end();\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Fonts.\r\n\t *\r\n\t * @returns {Object} font.\r\n\t * @since 1.0.0\r\n\t */\r\n\tfonts(): any {\r\n\t\tconst fonts = {\r\n\t\t\tHelvetica: {\r\n\t\t\t\tnormal: \"Helvetica\",\r\n\t\t\t\tbold: \"Helvetica-Bold\",\r\n\t\t\t\titalics: \"Helvetica-Oblique\",\r\n\t\t\t\tbolditalics: \"Helvetica-BoldOblique\",\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\treturn fonts;\r\n\t}\r\n\r\n\t/**\r\n\t * Doc meta.\r\n\t *\r\n\t * @returns {Object} meta.\r\n\t * @since 1.0.0\r\n\t */\r\n\tmeta(): any {\r\n\t\tconst meta = {\r\n\t\t\ttitle: \"Invoice - #\" + this.invoice.number,\r\n\t\t\tauthor: this.company.name,\r\n\t\t\tsubject: \"Invoice - \" + this.customer.name,\r\n\t\t\tkeywords: \"invoice\",\r\n\t\t};\r\n\r\n\t\treturn meta;\r\n\t}\r\n\r\n\t/**\r\n\t * Default invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tdefaultStyle(): any {\r\n\t\tconst defaults = {\r\n\t\t\tfontSize: 10,\r\n\t\t\tlineHeight: 1.8,\r\n\t\t\tbold: false,\r\n\t\t\tfont: \"Helvetica\",\r\n\t\t\tcolor: \"#222222\",\r\n\t\t\tcolumnGap: 30,\r\n\t\t};\r\n\t\treturn defaults;\r\n\t}\r\n\r\n\t/**\r\n\t * Invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tstyles(): any {\r\n\t\tconst styles = {\r\n\t\t\th1: {\r\n\t\t\t\tfontSize: 18,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th2: {\r\n\t\t\t\tfontSize: 16,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th3: {\r\n\t\t\t\tfontSize: 14,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\ttext: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: false,\r\n\t\t\t},\r\n\t\t\ttextBold: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t};\r\n\t\treturn styles;\r\n\t}\r\n\r\n\t/**\r\n\t * Return the invoice layout.\r\n\t *\r\n\t * @returns {Object} layout.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcontent(): any {\r\n\t\tconst sections = [];\r\n\r\n\t\t/**\r\n\t\t * Left: Company section.\r\n\t\t * Right: Invoice section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionCompany = {\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"70%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"30%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tif (this.company.logo) {\r\n\t\t\tif (!this.company.logo.startsWith(\" 0) {\r\n\t\t\tthis.items.forEach((item) => {\r\n\t\t\t\tconst totalPrice = helper.calcItemTotal(item);\r\n\r\n\t\t\t\tsectionItems.table.body.push([\r\n\t\t\t\t\t`\\n ${item.name}`,\r\n\t\t\t\t\t`\\n ${item.quantity}`,\r\n\t\t\t\t\t`\\n ${this.currency}${item.price}`,\r\n\t\t\t\t\t`\\n ${item.tax || 0}%`,\r\n\t\t\t\t\t`\\n ${this.currency}${totalPrice}`,\r\n\t\t\t\t]);\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tsections.push(sectionItems);\r\n\r\n\t\t/**\r\n\t\t * Right: Total section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionTotal = {\r\n\t\t\tmargin: [0, 20, 0, 0],\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"*\",\r\n\t\t\t\t\tstack: [\" \"],\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: 200,\r\n\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\tstyle: \"textBold\",\r\n\t\t\t\t\ttable: {\r\n\t\t\t\t\t\twidths: [80, \"*\"],\r\n\t\t\t\t\t\theaderRows: 1,\r\n\t\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\t\tbody: [\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Subtotal\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcSubTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total Tax\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcTax(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcFinalTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t},\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tsections.push(sectionTotal);\r\n\r\n\t\t/**\r\n\t\t * Left: QR section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.qr) {\r\n\t\t\tconst sectionQR = {\r\n\t\t\t\tmargin: [0, 50, 0, 0],\r\n\t\t\t\tqr: this.payload.qr.data,\r\n\t\t\t\tfit: this.payload.qr.width || \"50\",\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionQR);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Left: Notes section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.note) {\r\n\t\t\tconst sectionNote = {\r\n\t\t\t\tmargin: [0, this.payload.qr ? 20 : 50, 0, 0],\r\n\t\t\t\ttext: this.payload.note,\r\n\t\t\t\titalics: true,\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionNote);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Return the invoice sections.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\treturn sections;\r\n\t}\r\n}\r\n"]}
\ No newline at end of file
diff --git a/dist/class/invoice.mjs b/dist/class/invoice.mjs
index 88103dd..bb104a0 100644
--- a/dist/class/invoice.mjs
+++ b/dist/class/invoice.mjs
@@ -1,14 +1,14 @@
-var l=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var y=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var h=y((b,r)=>{var p={calcItemTotal:function(s){let t=s.price||0,e=s.quantity||1;return (t*e).toFixed(2)},calcSubTotal:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{t+=Number(this.calcItemTotal(e));}),t.toFixed(2)},calcTax:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{let n=e.price,c=e.quantity,i=e.tax||0;t+=n*c*i/100;}),t.toFixed(2)},calcFinalTotal:function(s){if(s.length===0)return 0;let t=Number(this.calcSubTotal(s)),e=Number(this.calcTax(s));return (t+e).toFixed(2)}};r.exports=p;});var f=l("fs"),d=l("path"),x=l("pdfmake"),a=h(),u=class{payload;company;invoice;customer;items;currency;path;qr;note;date;constructor(t){this.payload=t,this.company=t.company,this.customer=t.customer,this.invoice=t.invoice,this.items=t.items,this.qr=t.qr,this.note=t.note,this.currency=this.invoice.currency||"$",this.path=d.resolve(this.invoice.path)||"./invoice.pdf",this.date=new Date().toLocaleDateString("en-US",{year:"numeric",month:"numeric",day:"numeric"});}async create(){let t=new x(this.fonts()),e={pageSize:"A4",orientation:"portrait",pageMargins:[40,40,40,40],info:this.meta(),content:this.content(),defaultStyle:this.defaultStyle(),styles:this.styles()};return new Promise((n,c)=>{let i=t.createPdfKitDocument(e);i.pipe(f.createWriteStream(this.path)),i.end(),i.on("end",()=>{n(this.path);}),i.on("error",o=>{c(o);});})}fonts(){return {Helvetica:{normal:"Helvetica",bold:"Helvetica-Bold",italics:"Helvetica-Oblique",bolditalics:"Helvetica-BoldOblique"}}}meta(){return {title:"Invoice - #"+this.invoice.number,author:this.company.name,subject:"Invoice - "+this.customer.name,keywords:"invoice"}}defaultStyle(){return {fontSize:10,lineHeight:1.8,bold:!1,font:"Helvetica",color:"#222222",columnGap:30}}styles(){return {h1:{fontSize:18,bold:!0},h2:{fontSize:16,bold:!0},h3:{fontSize:14,bold:!0},text:{fontSize:10,bold:!1},textBold:{fontSize:10,bold:!0}}}content(){let t=[],e={columns:[{width:"70%",stack:[],style:"text"},{width:"30%",stack:[],style:"text"}]};if(this.company.logo){if(!this.company.logo.startsWith("typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var y=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var u=y((b,h)=>{var p={calcItemTotal:function(s){let t=s.price||0,e=s.quantity||1;return (t*e).toFixed(2)},calcSubTotal:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{t+=Number(this.calcItemTotal(e));}),t.toFixed(2)},calcTax:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{let n=e.price,c=e.quantity,i=e.tax||0;t+=n*c*i/100;}),t.toFixed(2)},calcFinalTotal:function(s){if(s.length===0)return 0;let t=Number(this.calcSubTotal(s)),e=Number(this.calcTax(s));return (t+e).toFixed(2)}};h.exports=p;});var f=r("fs"),d=r("path"),x=r("pdfmake"),a=u(),m=class{payload;company;invoice;customer;items;currency;path;qr;note;date;constructor(t){this.payload=t,this.company=t.company,this.customer=t.customer,this.invoice=t.invoice,this.items=t.items,this.qr=t.qr,this.note=t.note,this.currency=this.invoice.currency||"$",this.path=d.resolve(this.invoice.path)||"./invoice.pdf",this.date=new Date().toLocaleDateString("en-US",{year:"numeric",month:"numeric",day:"numeric"});}async create(){let t=new x(this.fonts()),e={pageSize:"A4",orientation:"portrait",pageMargins:[40,40,40,40],info:this.meta(),content:this.content(),defaultStyle:this.defaultStyle(),styles:this.styles()};return new Promise((n,c)=>{let i=t.createPdfKitDocument(e),o=f.createWriteStream(this.path);i.pipe(o),i.on("end",()=>{n(this.path);}),i.on("error",l=>{c(l);}),i.end();})}fonts(){return {Helvetica:{normal:"Helvetica",bold:"Helvetica-Bold",italics:"Helvetica-Oblique",bolditalics:"Helvetica-BoldOblique"}}}meta(){return {title:"Invoice - #"+this.invoice.number,author:this.company.name,subject:"Invoice - "+this.customer.name,keywords:"invoice"}}defaultStyle(){return {fontSize:10,lineHeight:1.8,bold:!1,font:"Helvetica",color:"#222222",columnGap:30}}styles(){return {h1:{fontSize:18,bold:!0},h2:{fontSize:16,bold:!0},h3:{fontSize:14,bold:!0},text:{fontSize:10,bold:!1},textBold:{fontSize:10,bold:!0}}}content(){let t=[],e={columns:[{width:"70%",stack:[],style:"text"},{width:"30%",stack:[],style:"text"}]};if(this.company.logo){if(!this.company.logo.startsWith("0&&this.items.forEach(o=>{let m=a.calcItemTotal(o);c.table.body.push([`
+ Total`]]}};this.items.length>0&&this.items.forEach(o=>{let l=a.calcItemTotal(o);c.table.body.push([`
${o.name}`,`
${o.quantity}`,`
${this.currency}${o.price}`,`
${o.tax||0}%`,`
- ${this.currency}${m}`]);}),t.push(c);let i={margin:[0,20,0,0],columns:[{width:"*",stack:[" "],style:"text"},{width:200,lineHeight:1.5,style:"textBold",table:{widths:[80,"*"],headerRows:1,lineHeight:1.5,body:[[`
+ ${this.currency}${l}`]);}),t.push(c);let i={margin:[0,20,0,0],columns:[{width:"*",stack:[" "],style:"text"},{width:200,lineHeight:1.5,style:"textBold",table:{widths:[80,"*"],headerRows:1,lineHeight:1.5,body:[[`
Subtotal`,`
${this.currency}${a.calcSubTotal(this.items)}`],[`
Total Tax`,`
@@ -16,6 +16,6 @@ var l=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(t
Total`,`
${this.currency}${a.calcFinalTotal(this.items)}`]]}}]};if(t.push(i),this.payload.qr){let o={margin:[0,50,0,0],qr:this.payload.qr.data,fit:this.payload.qr.width||"50"};t.push(o);}if(this.payload.note){let o={margin:[0,this.payload.qr?20:50,0,0],text:this.payload.note,italics:!0};t.push(o);}return t}};
-export { u as PDFInvoice };
+export { m as PDFInvoice };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=invoice.mjs.map
\ No newline at end of file
diff --git a/dist/class/invoice.mjs.map b/dist/class/invoice.mjs.map
index 74f3ebd..6dda140 100644
--- a/dist/class/invoice.mjs.map
+++ b/dist/class/invoice.mjs.map
@@ -1 +1 @@
-{"version":3,"sources":["../../src/utils/helper.ts","../../src/class/invoice.ts"],"names":["require_helper","__commonJSMin","exports","module","helper","item","price","quantity","items","total","tax","subTotal","fs","path","invoiceMaker","PDFInvoice","payload","printer","docDefinition","resolve","reject","doc","e","sections","sectionCompany","sectionCustomer","sectionItems","totalPrice","sectionTotal","sectionQR","sectionNote"],"mappings":"uTAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cASA,IAAMC,EAAkB,CAQvB,cAAe,SAAUC,EAAwB,CAChD,IAAMC,EAAQD,EAAK,OAAS,EACtBE,EAAWF,EAAK,UAAY,EAClC,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,GAAGA,EAAO,QAC5B,KAAK,KACN,CAAC,EACF,EACA,CACC;AAAA,QACA;AAAA,GAAM,KAAK,QAAQ,GAAGA,EAAO,eAC5B,KAAK,KACN,CAAC,EACF,CACD,CACD,CACD,CACD,CACD,EASA,GAPAmB,EAAS,KAAKK,CAAY,EAOtB,KAAK,QAAQ,GAAI,CACpB,IAAMC,EAAY,CACjB,OAAQ,CAAC,EAAG,GAAI,EAAG,CAAC,EACpB,GAAI,KAAK,QAAQ,GAAG,KACpB,IAAK,KAAK,QAAQ,GAAG,OAAS,IAC/B,EAEAN,EAAS,KAAKM,CAAS,CACxB,CAOA,GAAI,KAAK,QAAQ,KAAM,CACtB,IAAMC,EAAc,CACnB,OAAQ,CAAC,EAAG,KAAK,QAAQ,GAAK,GAAK,GAAI,EAAG,CAAC,EAC3C,KAAM,KAAK,QAAQ,KACnB,QAAS,EACV,EAEAP,EAAS,KAAKO,CAAW,CAC1B,CAOA,OAAOP,CACR,CACD","sourcesContent":["import type { ItemInfo } from \"../../global\";\r\n\r\ninterface Helpers {\r\n\tcalcItemTotal(item: ItemInfo): number | string;\r\n\tcalcTax(items: ItemInfo[]): number | string;\r\n\tcalcSubTotal(items: ItemInfo[]): number | string;\r\n\tcalcFinalTotal(items: ItemInfo[]): number | string;\r\n}\r\n\r\nconst helper: Helpers = {\r\n\t/**\r\n\t * Item total price calculation.\r\n\t *\r\n\t * @param {Object} item.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcItemTotal: function (item: ItemInfo): string {\r\n\t\tconst price = item.price || 0;\r\n\t\tconst quantity = item.quantity || 1;\r\n\t\treturn (price * quantity).toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate subtotal.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcSubTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\ttotal += Number(this.calcItemTotal(item));\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate tax.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcTax: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\tconst price = item.price;\r\n\t\t\tconst quantity = item.quantity;\r\n\t\t\tconst tax = item.tax || 0;\r\n\r\n\t\t\ttotal += (price * quantity * tax) / 100;\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate total final price.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcFinalTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tconst subTotal = Number(this.calcSubTotal(items));\r\n\t\tconst tax = Number(this.calcTax(items));\r\n\r\n\t\treturn (subTotal + tax).toFixed(2);\r\n\t},\r\n};\r\n\r\nmodule.exports = helper;\r\n","const fs = require(\"fs\");\r\nconst path = require(\"path\");\r\nconst invoiceMaker = require(\"pdfmake\");\r\nconst helper = require(\"../utils/helper\");\r\nimport type {\r\n\tCompanyInfo,\r\n\tCustomerInfo,\r\n\tInvoiceInfo,\r\n\tItemInfo,\r\n\tQRInfo,\r\n\tNotes,\r\n\tInvoicePayLoad,\r\n\tSimplePDFInvoice,\r\n} from \"../../global\";\r\n\r\nexport class PDFInvoice implements SimplePDFInvoice {\r\n\tpayload: InvoicePayLoad;\r\n\tcompany: CompanyInfo;\r\n\tinvoice: InvoiceInfo;\r\n\tcustomer: CustomerInfo;\r\n\titems: ItemInfo[];\r\n\tcurrency: string;\r\n\tpath: string;\r\n\tqr: QRInfo;\r\n\tnote: Notes;\r\n\tdate: string;\r\n\tconstructor(payload: InvoicePayLoad) {\r\n\t\tthis.payload = payload;\r\n\r\n\t\t// Invoice content section.\r\n\t\tthis.company = payload.company;\r\n\t\tthis.customer = payload.customer;\r\n\t\tthis.invoice = payload.invoice;\r\n\t\tthis.items = payload.items;\r\n\t\tthis.qr = payload.qr;\r\n\t\tthis.note = payload.note;\r\n\r\n\t\t// Invoice currency.\r\n\t\tthis.currency = this.invoice.currency || \"$\";\r\n\r\n\t\t// Path.\r\n\t\tthis.path = path.resolve(this.invoice.path) || \"./invoice.pdf\";\r\n\r\n\t\t// Invoice information.\r\n\t\tthis.date = new Date().toLocaleDateString(\"en-US\", {\r\n\t\t\tyear: \"numeric\",\r\n\t\t\tmonth: \"numeric\",\r\n\t\t\tday: \"numeric\",\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Create a PDF invoice.\r\n\t *\r\n\t * @returns {void}\r\n\t * @since 1.0.0\r\n\t */\r\n\tasync create(): Promise {\r\n\t\tconst printer = new invoiceMaker(this.fonts());\r\n\r\n\t\tconst docDefinition = {\r\n\t\t\tpageSize: \"A4\",\r\n\t\t\torientation: \"portrait\",\r\n\t\t\tpageMargins: [40, 40, 40, 40],\r\n\t\t\tinfo: this.meta(),\r\n\t\t\tcontent: this.content(),\r\n\t\t\tdefaultStyle: this.defaultStyle(),\r\n\t\t\tstyles: this.styles(),\r\n\t\t};\r\n\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst doc = printer.createPdfKitDocument(docDefinition);\r\n\r\n\t\t\tdoc.pipe(fs.createWriteStream(this.path));\r\n\r\n\t\t\tdoc.end();\r\n\r\n\t\t\tdoc.on(\"end\", () => {\r\n\t\t\t\tresolve(this.path);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.on(\"error\", (e: any) => {\r\n\t\t\t\treject(e);\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Fonts.\r\n\t *\r\n\t * @returns {Object} font.\r\n\t * @since 1.0.0\r\n\t */\r\n\tfonts(): any {\r\n\t\tconst fonts = {\r\n\t\t\tHelvetica: {\r\n\t\t\t\tnormal: \"Helvetica\",\r\n\t\t\t\tbold: \"Helvetica-Bold\",\r\n\t\t\t\titalics: \"Helvetica-Oblique\",\r\n\t\t\t\tbolditalics: \"Helvetica-BoldOblique\",\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\treturn fonts;\r\n\t}\r\n\r\n\t/**\r\n\t * Doc meta.\r\n\t *\r\n\t * @returns {Object} meta.\r\n\t * @since 1.0.0\r\n\t */\r\n\tmeta(): any {\r\n\t\tconst meta = {\r\n\t\t\ttitle: \"Invoice - #\" + this.invoice.number,\r\n\t\t\tauthor: this.company.name,\r\n\t\t\tsubject: \"Invoice - \" + this.customer.name,\r\n\t\t\tkeywords: \"invoice\",\r\n\t\t};\r\n\r\n\t\treturn meta;\r\n\t}\r\n\r\n\t/**\r\n\t * Default invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tdefaultStyle(): any {\r\n\t\tconst defaults = {\r\n\t\t\tfontSize: 10,\r\n\t\t\tlineHeight: 1.8,\r\n\t\t\tbold: false,\r\n\t\t\tfont: \"Helvetica\",\r\n\t\t\tcolor: \"#222222\",\r\n\t\t\tcolumnGap: 30,\r\n\t\t};\r\n\t\treturn defaults;\r\n\t}\r\n\r\n\t/**\r\n\t * Invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tstyles(): any {\r\n\t\tconst styles = {\r\n\t\t\th1: {\r\n\t\t\t\tfontSize: 18,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th2: {\r\n\t\t\t\tfontSize: 16,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th3: {\r\n\t\t\t\tfontSize: 14,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\ttext: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: false,\r\n\t\t\t},\r\n\t\t\ttextBold: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t};\r\n\t\treturn styles;\r\n\t}\r\n\r\n\t/**\r\n\t * Return the invoice layout.\r\n\t *\r\n\t * @returns {Object} layout.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcontent(): any {\r\n\t\tconst sections = [];\r\n\r\n\t\t/**\r\n\t\t * Left: Company section.\r\n\t\t * Right: Invoice section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionCompany = {\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"70%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"30%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tif (this.company.logo) {\r\n\t\t\tif (!this.company.logo.startsWith(\" 0) {\r\n\t\t\tthis.items.forEach((item) => {\r\n\t\t\t\tconst totalPrice = helper.calcItemTotal(item);\r\n\r\n\t\t\t\tsectionItems.table.body.push([\r\n\t\t\t\t\t`\\n ${item.name}`,\r\n\t\t\t\t\t`\\n ${item.quantity}`,\r\n\t\t\t\t\t`\\n ${this.currency}${item.price}`,\r\n\t\t\t\t\t`\\n ${item.tax || 0}%`,\r\n\t\t\t\t\t`\\n ${this.currency}${totalPrice}`,\r\n\t\t\t\t]);\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tsections.push(sectionItems);\r\n\r\n\t\t/**\r\n\t\t * Right: Total section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionTotal = {\r\n\t\t\tmargin: [0, 20, 0, 0],\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"*\",\r\n\t\t\t\t\tstack: [\" \"],\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: 200,\r\n\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\tstyle: \"textBold\",\r\n\t\t\t\t\ttable: {\r\n\t\t\t\t\t\twidths: [80, \"*\"],\r\n\t\t\t\t\t\theaderRows: 1,\r\n\t\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\t\tbody: [\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Subtotal\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcSubTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total Tax\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcTax(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcFinalTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t},\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tsections.push(sectionTotal);\r\n\r\n\t\t/**\r\n\t\t * Left: QR section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.qr) {\r\n\t\t\tconst sectionQR = {\r\n\t\t\t\tmargin: [0, 50, 0, 0],\r\n\t\t\t\tqr: this.payload.qr.data,\r\n\t\t\t\tfit: this.payload.qr.width || \"50\",\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionQR);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Left: Notes section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.note) {\r\n\t\t\tconst sectionNote = {\r\n\t\t\t\tmargin: [0, this.payload.qr ? 20 : 50, 0, 0],\r\n\t\t\t\ttext: this.payload.note,\r\n\t\t\t\titalics: true,\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionNote);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Return the invoice sections.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\treturn sections;\r\n\t}\r\n}\r\n"]}
\ No newline at end of file
+{"version":3,"sources":["../../src/utils/helper.ts","../../src/class/invoice.ts"],"names":["require_helper","__commonJSMin","exports","module","helper","item","price","quantity","items","total","tax","subTotal","fs","path","invoiceMaker","PDFInvoice","payload","printer","docDefinition","resolve","reject","doc","stream","err","sections","sectionCompany","sectionCustomer","sectionItems","totalPrice","sectionTotal","sectionQR","sectionNote"],"mappings":"uTAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cASA,IAAMC,EAAkB,CAQvB,cAAe,SAAUC,EAAwB,CAChD,IAAMC,EAAQD,EAAK,OAAS,EACtBE,EAAWF,EAAK,UAAY,EAClC,OAAQC,EAAQC,GAAU,QAAQ,CAAC,CACpC,EASA,aAAc,SAAUC,EAAoC,CAC3D,GAAIA,EAAM,SAAW,EACpB,MAAO,GAGR,IAAIC,EAAQ,EAEZ,OAAAD,EAAM,QAASH,GAAS,CACvBI,GAAS,OAAO,KAAK,cAAcJ,CAAI,CAAC,CACzC,CAAC,EAEMI,EAAM,QAAQ,CAAC,CACv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EAAY,CACjB,OAAQ,CAAC,EAAG,GAAI,EAAG,CAAC,EACpB,GAAI,KAAK,QAAQ,GAAG,KACpB,IAAK,KAAK,QAAQ,GAAG,OAAS,IAC/B,EAEAN,EAAS,KAAKM,CAAS,CACxB,CAOA,GAAI,KAAK,QAAQ,KAAM,CACtB,IAAMC,EAAc,CACnB,OAAQ,CAAC,EAAG,KAAK,QAAQ,GAAK,GAAK,GAAI,EAAG,CAAC,EAC3C,KAAM,KAAK,QAAQ,KACnB,QAAS,EACV,EAEAP,EAAS,KAAKO,CAAW,CAC1B,CAOA,OAAOP,CACR,CACD","sourcesContent":["import type { ItemInfo } from \"../../global\";\r\n\r\ninterface Helpers {\r\n\tcalcItemTotal(item: ItemInfo): number | string;\r\n\tcalcTax(items: ItemInfo[]): number | string;\r\n\tcalcSubTotal(items: ItemInfo[]): number | string;\r\n\tcalcFinalTotal(items: ItemInfo[]): number | string;\r\n}\r\n\r\nconst helper: Helpers = {\r\n\t/**\r\n\t * Item total price calculation.\r\n\t *\r\n\t * @param {Object} item.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcItemTotal: function (item: ItemInfo): string {\r\n\t\tconst price = item.price || 0;\r\n\t\tconst quantity = item.quantity || 1;\r\n\t\treturn (price * quantity).toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate subtotal.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcSubTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\ttotal += Number(this.calcItemTotal(item));\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate tax.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcTax: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\tconst price = item.price;\r\n\t\t\tconst quantity = item.quantity;\r\n\t\t\tconst tax = item.tax || 0;\r\n\r\n\t\t\ttotal += (price * quantity * tax) / 100;\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate total final price.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcFinalTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tconst subTotal = Number(this.calcSubTotal(items));\r\n\t\tconst tax = Number(this.calcTax(items));\r\n\r\n\t\treturn (subTotal + tax).toFixed(2);\r\n\t},\r\n};\r\n\r\nmodule.exports = helper;\r\n","const fs = require(\"fs\");\r\nconst path = require(\"path\");\r\nconst invoiceMaker = require(\"pdfmake\");\r\nconst helper = require(\"../utils/helper\");\r\nimport type {\r\n\tCompanyInfo,\r\n\tCustomerInfo,\r\n\tInvoiceInfo,\r\n\tItemInfo,\r\n\tQRInfo,\r\n\tNotes,\r\n\tInvoicePayLoad,\r\n\tSimplePDFInvoice,\r\n} from \"../../global\";\r\n\r\nexport class PDFInvoice implements SimplePDFInvoice {\r\n\tpayload: InvoicePayLoad;\r\n\tcompany: CompanyInfo;\r\n\tinvoice: InvoiceInfo;\r\n\tcustomer: CustomerInfo;\r\n\titems: ItemInfo[];\r\n\tcurrency: string;\r\n\tpath: string;\r\n\tqr: QRInfo;\r\n\tnote: Notes;\r\n\tdate: string;\r\n\tconstructor(payload: InvoicePayLoad) {\r\n\t\tthis.payload = payload;\r\n\r\n\t\t// Invoice content section.\r\n\t\tthis.company = payload.company;\r\n\t\tthis.customer = payload.customer;\r\n\t\tthis.invoice = payload.invoice;\r\n\t\tthis.items = payload.items;\r\n\t\tthis.qr = payload.qr;\r\n\t\tthis.note = payload.note;\r\n\r\n\t\t// Invoice currency.\r\n\t\tthis.currency = this.invoice.currency || \"$\";\r\n\r\n\t\t// Path.\r\n\t\tthis.path = path.resolve(this.invoice.path) || \"./invoice.pdf\";\r\n\r\n\t\t// Invoice information.\r\n\t\tthis.date = new Date().toLocaleDateString(\"en-US\", {\r\n\t\t\tyear: \"numeric\",\r\n\t\t\tmonth: \"numeric\",\r\n\t\t\tday: \"numeric\",\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Create a PDF invoice.\r\n\t *\r\n\t * @returns {void}\r\n\t * @since 1.0.0\r\n\t */\r\n\tasync create(): Promise {\r\n\t\tconst printer = new invoiceMaker(this.fonts());\r\n\r\n\t\tconst docDefinition = {\r\n\t\t\tpageSize: \"A4\",\r\n\t\t\torientation: \"portrait\",\r\n\t\t\tpageMargins: [40, 40, 40, 40],\r\n\t\t\tinfo: this.meta(),\r\n\t\t\tcontent: this.content(),\r\n\t\t\tdefaultStyle: this.defaultStyle(),\r\n\t\t\tstyles: this.styles(),\r\n\t\t};\r\n\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst doc = printer.createPdfKitDocument(docDefinition);\r\n\t\t\tconst stream = fs.createWriteStream(this.path);\r\n\r\n\t\t\tdoc.pipe(stream);\r\n\r\n\t\t\tdoc.on(\"end\", () => {\r\n\t\t\t\tresolve(this.path);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.on(\"error\", (err: any) => {\r\n\t\t\t\treject(err);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.end();\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Fonts.\r\n\t *\r\n\t * @returns {Object} font.\r\n\t * @since 1.0.0\r\n\t */\r\n\tfonts(): any {\r\n\t\tconst fonts = {\r\n\t\t\tHelvetica: {\r\n\t\t\t\tnormal: \"Helvetica\",\r\n\t\t\t\tbold: \"Helvetica-Bold\",\r\n\t\t\t\titalics: \"Helvetica-Oblique\",\r\n\t\t\t\tbolditalics: \"Helvetica-BoldOblique\",\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\treturn fonts;\r\n\t}\r\n\r\n\t/**\r\n\t * Doc meta.\r\n\t *\r\n\t * @returns {Object} meta.\r\n\t * @since 1.0.0\r\n\t */\r\n\tmeta(): any {\r\n\t\tconst meta = {\r\n\t\t\ttitle: \"Invoice - #\" + this.invoice.number,\r\n\t\t\tauthor: this.company.name,\r\n\t\t\tsubject: \"Invoice - \" + this.customer.name,\r\n\t\t\tkeywords: \"invoice\",\r\n\t\t};\r\n\r\n\t\treturn meta;\r\n\t}\r\n\r\n\t/**\r\n\t * Default invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tdefaultStyle(): any {\r\n\t\tconst defaults = {\r\n\t\t\tfontSize: 10,\r\n\t\t\tlineHeight: 1.8,\r\n\t\t\tbold: false,\r\n\t\t\tfont: \"Helvetica\",\r\n\t\t\tcolor: \"#222222\",\r\n\t\t\tcolumnGap: 30,\r\n\t\t};\r\n\t\treturn defaults;\r\n\t}\r\n\r\n\t/**\r\n\t * Invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tstyles(): any {\r\n\t\tconst styles = {\r\n\t\t\th1: {\r\n\t\t\t\tfontSize: 18,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th2: {\r\n\t\t\t\tfontSize: 16,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th3: {\r\n\t\t\t\tfontSize: 14,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\ttext: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: false,\r\n\t\t\t},\r\n\t\t\ttextBold: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t};\r\n\t\treturn styles;\r\n\t}\r\n\r\n\t/**\r\n\t * Return the invoice layout.\r\n\t *\r\n\t * @returns {Object} layout.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcontent(): any {\r\n\t\tconst sections = [];\r\n\r\n\t\t/**\r\n\t\t * Left: Company section.\r\n\t\t * Right: Invoice section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionCompany = {\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"70%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"30%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tif (this.company.logo) {\r\n\t\t\tif (!this.company.logo.startsWith(\" 0) {\r\n\t\t\tthis.items.forEach((item) => {\r\n\t\t\t\tconst totalPrice = helper.calcItemTotal(item);\r\n\r\n\t\t\t\tsectionItems.table.body.push([\r\n\t\t\t\t\t`\\n ${item.name}`,\r\n\t\t\t\t\t`\\n ${item.quantity}`,\r\n\t\t\t\t\t`\\n ${this.currency}${item.price}`,\r\n\t\t\t\t\t`\\n ${item.tax || 0}%`,\r\n\t\t\t\t\t`\\n ${this.currency}${totalPrice}`,\r\n\t\t\t\t]);\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tsections.push(sectionItems);\r\n\r\n\t\t/**\r\n\t\t * Right: Total section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionTotal = {\r\n\t\t\tmargin: [0, 20, 0, 0],\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"*\",\r\n\t\t\t\t\tstack: [\" \"],\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: 200,\r\n\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\tstyle: \"textBold\",\r\n\t\t\t\t\ttable: {\r\n\t\t\t\t\t\twidths: [80, \"*\"],\r\n\t\t\t\t\t\theaderRows: 1,\r\n\t\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\t\tbody: [\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Subtotal\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcSubTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total Tax\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcTax(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcFinalTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t},\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tsections.push(sectionTotal);\r\n\r\n\t\t/**\r\n\t\t * Left: QR section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.qr) {\r\n\t\t\tconst sectionQR = {\r\n\t\t\t\tmargin: [0, 50, 0, 0],\r\n\t\t\t\tqr: this.payload.qr.data,\r\n\t\t\t\tfit: this.payload.qr.width || \"50\",\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionQR);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Left: Notes section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.note) {\r\n\t\t\tconst sectionNote = {\r\n\t\t\t\tmargin: [0, this.payload.qr ? 20 : 50, 0, 0],\r\n\t\t\t\ttext: this.payload.note,\r\n\t\t\t\titalics: true,\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionNote);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Return the invoice sections.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\treturn sections;\r\n\t}\r\n}\r\n"]}
\ No newline at end of file
diff --git a/dist/index.js b/dist/index.js
index eec4880..cdba7cb 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1,16 +1,16 @@
'use strict';
-var l=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var y=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var u=y((b,h)=>{var p={calcItemTotal:function(s){let t=s.price||0,e=s.quantity||1;return (t*e).toFixed(2)},calcSubTotal:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{t+=Number(this.calcItemTotal(e));}),t.toFixed(2)},calcTax:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{let n=e.price,c=e.quantity,i=e.tax||0;t+=n*c*i/100;}),t.toFixed(2)},calcFinalTotal:function(s){if(s.length===0)return 0;let t=Number(this.calcSubTotal(s)),e=Number(this.calcTax(s));return (t+e).toFixed(2)}};h.exports=p;});var f=l("fs"),d=l("path"),x=l("pdfmake"),a=u(),r=class{payload;company;invoice;customer;items;currency;path;qr;note;date;constructor(t){this.payload=t,this.company=t.company,this.customer=t.customer,this.invoice=t.invoice,this.items=t.items,this.qr=t.qr,this.note=t.note,this.currency=this.invoice.currency||"$",this.path=d.resolve(this.invoice.path)||"./invoice.pdf",this.date=new Date().toLocaleDateString("en-US",{year:"numeric",month:"numeric",day:"numeric"});}async create(){let t=new x(this.fonts()),e={pageSize:"A4",orientation:"portrait",pageMargins:[40,40,40,40],info:this.meta(),content:this.content(),defaultStyle:this.defaultStyle(),styles:this.styles()};return new Promise((n,c)=>{let i=t.createPdfKitDocument(e);i.pipe(f.createWriteStream(this.path)),i.end(),i.on("end",()=>{n(this.path);}),i.on("error",o=>{c(o);});})}fonts(){return {Helvetica:{normal:"Helvetica",bold:"Helvetica-Bold",italics:"Helvetica-Oblique",bolditalics:"Helvetica-BoldOblique"}}}meta(){return {title:"Invoice - #"+this.invoice.number,author:this.company.name,subject:"Invoice - "+this.customer.name,keywords:"invoice"}}defaultStyle(){return {fontSize:10,lineHeight:1.8,bold:!1,font:"Helvetica",color:"#222222",columnGap:30}}styles(){return {h1:{fontSize:18,bold:!0},h2:{fontSize:16,bold:!0},h3:{fontSize:14,bold:!0},text:{fontSize:10,bold:!1},textBold:{fontSize:10,bold:!0}}}content(){let t=[],e={columns:[{width:"70%",stack:[],style:"text"},{width:"30%",stack:[],style:"text"}]};if(this.company.logo){if(!this.company.logo.startsWith("typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var y=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var m=y((b,u)=>{var p={calcItemTotal:function(s){let t=s.price||0,e=s.quantity||1;return (t*e).toFixed(2)},calcSubTotal:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{t+=Number(this.calcItemTotal(e));}),t.toFixed(2)},calcTax:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{let n=e.price,c=e.quantity,i=e.tax||0;t+=n*c*i/100;}),t.toFixed(2)},calcFinalTotal:function(s){if(s.length===0)return 0;let t=Number(this.calcSubTotal(s)),e=Number(this.calcTax(s));return (t+e).toFixed(2)}};u.exports=p;});var f=r("fs"),d=r("path"),x=r("pdfmake"),a=m(),h=class{payload;company;invoice;customer;items;currency;path;qr;note;date;constructor(t){this.payload=t,this.company=t.company,this.customer=t.customer,this.invoice=t.invoice,this.items=t.items,this.qr=t.qr,this.note=t.note,this.currency=this.invoice.currency||"$",this.path=d.resolve(this.invoice.path)||"./invoice.pdf",this.date=new Date().toLocaleDateString("en-US",{year:"numeric",month:"numeric",day:"numeric"});}async create(){let t=new x(this.fonts()),e={pageSize:"A4",orientation:"portrait",pageMargins:[40,40,40,40],info:this.meta(),content:this.content(),defaultStyle:this.defaultStyle(),styles:this.styles()};return new Promise((n,c)=>{let i=t.createPdfKitDocument(e),o=f.createWriteStream(this.path);i.pipe(o),i.on("end",()=>{n(this.path);}),i.on("error",l=>{c(l);}),i.end();})}fonts(){return {Helvetica:{normal:"Helvetica",bold:"Helvetica-Bold",italics:"Helvetica-Oblique",bolditalics:"Helvetica-BoldOblique"}}}meta(){return {title:"Invoice - #"+this.invoice.number,author:this.company.name,subject:"Invoice - "+this.customer.name,keywords:"invoice"}}defaultStyle(){return {fontSize:10,lineHeight:1.8,bold:!1,font:"Helvetica",color:"#222222",columnGap:30}}styles(){return {h1:{fontSize:18,bold:!0},h2:{fontSize:16,bold:!0},h3:{fontSize:14,bold:!0},text:{fontSize:10,bold:!1},textBold:{fontSize:10,bold:!0}}}content(){let t=[],e={columns:[{width:"70%",stack:[],style:"text"},{width:"30%",stack:[],style:"text"}]};if(this.company.logo){if(!this.company.logo.startsWith("0&&this.items.forEach(o=>{let m=a.calcItemTotal(o);c.table.body.push([`
+ Total`]]}};this.items.length>0&&this.items.forEach(o=>{let l=a.calcItemTotal(o);c.table.body.push([`
${o.name}`,`
${o.quantity}`,`
${this.currency}${o.price}`,`
${o.tax||0}%`,`
- ${this.currency}${m}`]);}),t.push(c);let i={margin:[0,20,0,0],columns:[{width:"*",stack:[" "],style:"text"},{width:200,lineHeight:1.5,style:"textBold",table:{widths:[80,"*"],headerRows:1,lineHeight:1.5,body:[[`
+ ${this.currency}${l}`]);}),t.push(c);let i={margin:[0,20,0,0],columns:[{width:"*",stack:[" "],style:"text"},{width:200,lineHeight:1.5,style:"textBold",table:{widths:[80,"*"],headerRows:1,lineHeight:1.5,body:[[`
Subtotal`,`
${this.currency}${a.calcSubTotal(this.items)}`],[`
Total Tax`,`
@@ -18,6 +18,6 @@ var l=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(t
Total`,`
${this.currency}${a.calcFinalTotal(this.items)}`]]}}]};if(t.push(i),this.payload.qr){let o={margin:[0,50,0,0],qr:this.payload.qr.data,fit:this.payload.qr.width||"50"};t.push(o);}if(this.payload.note){let o={margin:[0,this.payload.qr?20:50,0,0],text:this.payload.note,italics:!0};t.push(o);}return t}};
-exports.PDFInvoice = r;
+exports.PDFInvoice = h;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/dist/index.js.map b/dist/index.js.map
index 8deddae..402462e 100644
--- a/dist/index.js.map
+++ b/dist/index.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/utils/helper.ts","../src/class/invoice.ts"],"names":["require_helper","__commonJSMin","exports","module","helper","item","price","quantity","items","total","tax","subTotal","fs","path","invoiceMaker","PDFInvoice","payload","printer","docDefinition","resolve","reject","doc","e","sections","sectionCompany","sectionCustomer","sectionItems","totalPrice","sectionTotal","sectionQR","sectionNote"],"mappings":"uTAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cASA,IAAMC,EAAkB,CAQvB,cAAe,SAAUC,EAAwB,CAChD,IAAMC,EAAQD,EAAK,OAAS,EACtBE,EAAWF,EAAK,UAAY,EAClC,OAAQC,EAAQC,GAAU,QAAQ,CAAC,CACpC,EASA,aAAc,SAAUC,EAAoC,CAC3D,GAAIA,EAAM,SAAW,EACpB,MAAO,GAGR,IAAIC,EAAQ,EAEZ,OAAAD,EAAM,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D,CACD,CACD,EASA,GAPAmB,EAAS,KAAKK,CAAY,EAOtB,KAAK,QAAQ,GAAI,CACpB,IAAMC,EAAY,CACjB,OAAQ,CAAC,EAAG,GAAI,EAAG,CAAC,EACpB,GAAI,KAAK,QAAQ,GAAG,KACpB,IAAK,KAAK,QAAQ,GAAG,OAAS,IAC/B,EAEAN,EAAS,KAAKM,CAAS,CACxB,CAOA,GAAI,KAAK,QAAQ,KAAM,CACtB,IAAMC,EAAc,CACnB,OAAQ,CAAC,EAAG,KAAK,QAAQ,GAAK,GAAK,GAAI,EAAG,CAAC,EAC3C,KAAM,KAAK,QAAQ,KACnB,QAAS,EACV,EAEAP,EAAS,KAAKO,CAAW,CAC1B,CAOA,OAAOP,CACR,CACD","sourcesContent":["import type { ItemInfo } from \"../../global\";\r\n\r\ninterface Helpers {\r\n\tcalcItemTotal(item: ItemInfo): number | string;\r\n\tcalcTax(items: ItemInfo[]): number | string;\r\n\tcalcSubTotal(items: ItemInfo[]): number | string;\r\n\tcalcFinalTotal(items: ItemInfo[]): number | string;\r\n}\r\n\r\nconst helper: Helpers = {\r\n\t/**\r\n\t * Item total price calculation.\r\n\t *\r\n\t * @param {Object} item.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcItemTotal: function (item: ItemInfo): string {\r\n\t\tconst price = item.price || 0;\r\n\t\tconst quantity = item.quantity || 1;\r\n\t\treturn (price * quantity).toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate subtotal.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcSubTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\ttotal += Number(this.calcItemTotal(item));\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate tax.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcTax: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\tconst price = item.price;\r\n\t\t\tconst quantity = item.quantity;\r\n\t\t\tconst tax = item.tax || 0;\r\n\r\n\t\t\ttotal += (price * quantity * tax) / 100;\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate total final price.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcFinalTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tconst subTotal = Number(this.calcSubTotal(items));\r\n\t\tconst tax = Number(this.calcTax(items));\r\n\r\n\t\treturn (subTotal + tax).toFixed(2);\r\n\t},\r\n};\r\n\r\nmodule.exports = helper;\r\n","const fs = require(\"fs\");\r\nconst path = require(\"path\");\r\nconst invoiceMaker = require(\"pdfmake\");\r\nconst helper = require(\"../utils/helper\");\r\nimport type {\r\n\tCompanyInfo,\r\n\tCustomerInfo,\r\n\tInvoiceInfo,\r\n\tItemInfo,\r\n\tQRInfo,\r\n\tNotes,\r\n\tInvoicePayLoad,\r\n\tSimplePDFInvoice,\r\n} from \"../../global\";\r\n\r\nexport class PDFInvoice implements SimplePDFInvoice {\r\n\tpayload: InvoicePayLoad;\r\n\tcompany: CompanyInfo;\r\n\tinvoice: InvoiceInfo;\r\n\tcustomer: CustomerInfo;\r\n\titems: ItemInfo[];\r\n\tcurrency: string;\r\n\tpath: string;\r\n\tqr: QRInfo;\r\n\tnote: Notes;\r\n\tdate: string;\r\n\tconstructor(payload: InvoicePayLoad) {\r\n\t\tthis.payload = payload;\r\n\r\n\t\t// Invoice content section.\r\n\t\tthis.company = payload.company;\r\n\t\tthis.customer = payload.customer;\r\n\t\tthis.invoice = payload.invoice;\r\n\t\tthis.items = payload.items;\r\n\t\tthis.qr = payload.qr;\r\n\t\tthis.note = payload.note;\r\n\r\n\t\t// Invoice currency.\r\n\t\tthis.currency = this.invoice.currency || \"$\";\r\n\r\n\t\t// Path.\r\n\t\tthis.path = path.resolve(this.invoice.path) || \"./invoice.pdf\";\r\n\r\n\t\t// Invoice information.\r\n\t\tthis.date = new Date().toLocaleDateString(\"en-US\", {\r\n\t\t\tyear: \"numeric\",\r\n\t\t\tmonth: \"numeric\",\r\n\t\t\tday: \"numeric\",\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Create a PDF invoice.\r\n\t *\r\n\t * @returns {void}\r\n\t * @since 1.0.0\r\n\t */\r\n\tasync create(): Promise {\r\n\t\tconst printer = new invoiceMaker(this.fonts());\r\n\r\n\t\tconst docDefinition = {\r\n\t\t\tpageSize: \"A4\",\r\n\t\t\torientation: \"portrait\",\r\n\t\t\tpageMargins: [40, 40, 40, 40],\r\n\t\t\tinfo: this.meta(),\r\n\t\t\tcontent: this.content(),\r\n\t\t\tdefaultStyle: this.defaultStyle(),\r\n\t\t\tstyles: this.styles(),\r\n\t\t};\r\n\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst doc = printer.createPdfKitDocument(docDefinition);\r\n\r\n\t\t\tdoc.pipe(fs.createWriteStream(this.path));\r\n\r\n\t\t\tdoc.end();\r\n\r\n\t\t\tdoc.on(\"end\", () => {\r\n\t\t\t\tresolve(this.path);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.on(\"error\", (e: any) => {\r\n\t\t\t\treject(e);\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Fonts.\r\n\t *\r\n\t * @returns {Object} font.\r\n\t * @since 1.0.0\r\n\t */\r\n\tfonts(): any {\r\n\t\tconst fonts = {\r\n\t\t\tHelvetica: {\r\n\t\t\t\tnormal: \"Helvetica\",\r\n\t\t\t\tbold: \"Helvetica-Bold\",\r\n\t\t\t\titalics: \"Helvetica-Oblique\",\r\n\t\t\t\tbolditalics: \"Helvetica-BoldOblique\",\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\treturn fonts;\r\n\t}\r\n\r\n\t/**\r\n\t * Doc meta.\r\n\t *\r\n\t * @returns {Object} meta.\r\n\t * @since 1.0.0\r\n\t */\r\n\tmeta(): any {\r\n\t\tconst meta = {\r\n\t\t\ttitle: \"Invoice - #\" + this.invoice.number,\r\n\t\t\tauthor: this.company.name,\r\n\t\t\tsubject: \"Invoice - \" + this.customer.name,\r\n\t\t\tkeywords: \"invoice\",\r\n\t\t};\r\n\r\n\t\treturn meta;\r\n\t}\r\n\r\n\t/**\r\n\t * Default invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tdefaultStyle(): any {\r\n\t\tconst defaults = {\r\n\t\t\tfontSize: 10,\r\n\t\t\tlineHeight: 1.8,\r\n\t\t\tbold: false,\r\n\t\t\tfont: \"Helvetica\",\r\n\t\t\tcolor: \"#222222\",\r\n\t\t\tcolumnGap: 30,\r\n\t\t};\r\n\t\treturn defaults;\r\n\t}\r\n\r\n\t/**\r\n\t * Invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tstyles(): any {\r\n\t\tconst styles = {\r\n\t\t\th1: {\r\n\t\t\t\tfontSize: 18,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th2: {\r\n\t\t\t\tfontSize: 16,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th3: {\r\n\t\t\t\tfontSize: 14,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\ttext: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: false,\r\n\t\t\t},\r\n\t\t\ttextBold: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t};\r\n\t\treturn styles;\r\n\t}\r\n\r\n\t/**\r\n\t * Return the invoice layout.\r\n\t *\r\n\t * @returns {Object} layout.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcontent(): any {\r\n\t\tconst sections = [];\r\n\r\n\t\t/**\r\n\t\t * Left: Company section.\r\n\t\t * Right: Invoice section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionCompany = {\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"70%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"30%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tif (this.company.logo) {\r\n\t\t\tif (!this.company.logo.startsWith(\" 0) {\r\n\t\t\tthis.items.forEach((item) => {\r\n\t\t\t\tconst totalPrice = helper.calcItemTotal(item);\r\n\r\n\t\t\t\tsectionItems.table.body.push([\r\n\t\t\t\t\t`\\n ${item.name}`,\r\n\t\t\t\t\t`\\n ${item.quantity}`,\r\n\t\t\t\t\t`\\n ${this.currency}${item.price}`,\r\n\t\t\t\t\t`\\n ${item.tax || 0}%`,\r\n\t\t\t\t\t`\\n ${this.currency}${totalPrice}`,\r\n\t\t\t\t]);\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tsections.push(sectionItems);\r\n\r\n\t\t/**\r\n\t\t * Right: Total section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionTotal = {\r\n\t\t\tmargin: [0, 20, 0, 0],\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"*\",\r\n\t\t\t\t\tstack: [\" \"],\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: 200,\r\n\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\tstyle: \"textBold\",\r\n\t\t\t\t\ttable: {\r\n\t\t\t\t\t\twidths: [80, \"*\"],\r\n\t\t\t\t\t\theaderRows: 1,\r\n\t\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\t\tbody: [\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Subtotal\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcSubTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total Tax\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcTax(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcFinalTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t},\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tsections.push(sectionTotal);\r\n\r\n\t\t/**\r\n\t\t * Left: QR section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.qr) {\r\n\t\t\tconst sectionQR = {\r\n\t\t\t\tmargin: [0, 50, 0, 0],\r\n\t\t\t\tqr: this.payload.qr.data,\r\n\t\t\t\tfit: this.payload.qr.width || \"50\",\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionQR);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Left: Notes section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.note) {\r\n\t\t\tconst sectionNote = {\r\n\t\t\t\tmargin: [0, this.payload.qr ? 20 : 50, 0, 0],\r\n\t\t\t\ttext: this.payload.note,\r\n\t\t\t\titalics: true,\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionNote);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Return the invoice sections.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\treturn sections;\r\n\t}\r\n}\r\n"]}
\ No newline at end of file
+{"version":3,"sources":["../src/utils/helper.ts","../src/class/invoice.ts"],"names":["require_helper","__commonJSMin","exports","module","helper","item","price","quantity","items","total","tax","subTotal","fs","path","invoiceMaker","PDFInvoice","payload","printer","docDefinition","resolve","reject","doc","stream","err","sections","sectionCompany","sectionCustomer","sectionItems","totalPrice","sectionTotal","sectionQR","sectionNote"],"mappings":"uTAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cASA,IAAMC,EAAkB,CAQvB,cAAe,SAAUC,EAAwB,CAChD,IAAMC,EAAQD,EAAK,OAAS,EACtBE,EAAWF,EAAK,UAAY,EAClC,OAAQC,EAAQC,GAAU,QAAQ,CAAC,CACpC,EASA,aAAc,SAAUC,EAAoC,CAC3D,GAAIA,EAAM,SAAW,EACpB,MAAO,GAGR,IAAIC,EAAQ,EAEZ,OAAAD,EAAM,QAASH,GAAS,CACvBI,GAAS,OAAO,KAAK,cAAcJ,CAAI,CAAC,CACzC,CAAC,EAEMI,EAAM,QAAQ,CAAC,CACvB,EASA,QAAS,SAAUD,EAAoC,CACtD,GAAIA,EAAM,SAAW,EACpB,MAAO,GAGR,IAAIC,EAAQ,EAEZ,OAAAD,EAAM,QAASH,GAAS,CACvB,IAAMC,EAAQD,EAAK,MAC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AAS,CACxB,CAOA,GAAI,KAAK,QAAQ,KAAM,CACtB,IAAMC,EAAc,CACnB,OAAQ,CAAC,EAAG,KAAK,QAAQ,GAAK,GAAK,GAAI,EAAG,CAAC,EAC3C,KAAM,KAAK,QAAQ,KACnB,QAAS,EACV,EAEAP,EAAS,KAAKO,CAAW,CAC1B,CAOA,OAAOP,CACR,CACD","sourcesContent":["import type { ItemInfo } from \"../../global\";\r\n\r\ninterface Helpers {\r\n\tcalcItemTotal(item: ItemInfo): number | string;\r\n\tcalcTax(items: ItemInfo[]): number | string;\r\n\tcalcSubTotal(items: ItemInfo[]): number | string;\r\n\tcalcFinalTotal(items: ItemInfo[]): number | string;\r\n}\r\n\r\nconst helper: Helpers = {\r\n\t/**\r\n\t * Item total price calculation.\r\n\t *\r\n\t * @param {Object} item.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcItemTotal: function (item: ItemInfo): string {\r\n\t\tconst price = item.price || 0;\r\n\t\tconst quantity = item.quantity || 1;\r\n\t\treturn (price * quantity).toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate subtotal.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcSubTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\ttotal += Number(this.calcItemTotal(item));\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate tax.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcTax: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\tconst price = item.price;\r\n\t\t\tconst quantity = item.quantity;\r\n\t\t\tconst tax = item.tax || 0;\r\n\r\n\t\t\ttotal += (price * quantity * tax) / 100;\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate total final price.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcFinalTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tconst subTotal = Number(this.calcSubTotal(items));\r\n\t\tconst tax = Number(this.calcTax(items));\r\n\r\n\t\treturn (subTotal + tax).toFixed(2);\r\n\t},\r\n};\r\n\r\nmodule.exports = helper;\r\n","const fs = require(\"fs\");\r\nconst path = require(\"path\");\r\nconst invoiceMaker = require(\"pdfmake\");\r\nconst helper = require(\"../utils/helper\");\r\nimport type {\r\n\tCompanyInfo,\r\n\tCustomerInfo,\r\n\tInvoiceInfo,\r\n\tItemInfo,\r\n\tQRInfo,\r\n\tNotes,\r\n\tInvoicePayLoad,\r\n\tSimplePDFInvoice,\r\n} from \"../../global\";\r\n\r\nexport class PDFInvoice implements SimplePDFInvoice {\r\n\tpayload: InvoicePayLoad;\r\n\tcompany: CompanyInfo;\r\n\tinvoice: InvoiceInfo;\r\n\tcustomer: CustomerInfo;\r\n\titems: ItemInfo[];\r\n\tcurrency: string;\r\n\tpath: string;\r\n\tqr: QRInfo;\r\n\tnote: Notes;\r\n\tdate: string;\r\n\tconstructor(payload: InvoicePayLoad) {\r\n\t\tthis.payload = payload;\r\n\r\n\t\t// Invoice content section.\r\n\t\tthis.company = payload.company;\r\n\t\tthis.customer = payload.customer;\r\n\t\tthis.invoice = payload.invoice;\r\n\t\tthis.items = payload.items;\r\n\t\tthis.qr = payload.qr;\r\n\t\tthis.note = payload.note;\r\n\r\n\t\t// Invoice currency.\r\n\t\tthis.currency = this.invoice.currency || \"$\";\r\n\r\n\t\t// Path.\r\n\t\tthis.path = path.resolve(this.invoice.path) || \"./invoice.pdf\";\r\n\r\n\t\t// Invoice information.\r\n\t\tthis.date = new Date().toLocaleDateString(\"en-US\", {\r\n\t\t\tyear: \"numeric\",\r\n\t\t\tmonth: \"numeric\",\r\n\t\t\tday: \"numeric\",\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Create a PDF invoice.\r\n\t *\r\n\t * @returns {void}\r\n\t * @since 1.0.0\r\n\t */\r\n\tasync create(): Promise {\r\n\t\tconst printer = new invoiceMaker(this.fonts());\r\n\r\n\t\tconst docDefinition = {\r\n\t\t\tpageSize: \"A4\",\r\n\t\t\torientation: \"portrait\",\r\n\t\t\tpageMargins: [40, 40, 40, 40],\r\n\t\t\tinfo: this.meta(),\r\n\t\t\tcontent: this.content(),\r\n\t\t\tdefaultStyle: this.defaultStyle(),\r\n\t\t\tstyles: this.styles(),\r\n\t\t};\r\n\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst doc = printer.createPdfKitDocument(docDefinition);\r\n\t\t\tconst stream = fs.createWriteStream(this.path);\r\n\r\n\t\t\tdoc.pipe(stream);\r\n\r\n\t\t\tdoc.on(\"end\", () => {\r\n\t\t\t\tresolve(this.path);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.on(\"error\", (err: any) => {\r\n\t\t\t\treject(err);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.end();\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Fonts.\r\n\t *\r\n\t * @returns {Object} font.\r\n\t * @since 1.0.0\r\n\t */\r\n\tfonts(): any {\r\n\t\tconst fonts = {\r\n\t\t\tHelvetica: {\r\n\t\t\t\tnormal: \"Helvetica\",\r\n\t\t\t\tbold: \"Helvetica-Bold\",\r\n\t\t\t\titalics: \"Helvetica-Oblique\",\r\n\t\t\t\tbolditalics: \"Helvetica-BoldOblique\",\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\treturn fonts;\r\n\t}\r\n\r\n\t/**\r\n\t * Doc meta.\r\n\t *\r\n\t * @returns {Object} meta.\r\n\t * @since 1.0.0\r\n\t */\r\n\tmeta(): any {\r\n\t\tconst meta = {\r\n\t\t\ttitle: \"Invoice - #\" + this.invoice.number,\r\n\t\t\tauthor: this.company.name,\r\n\t\t\tsubject: \"Invoice - \" + this.customer.name,\r\n\t\t\tkeywords: \"invoice\",\r\n\t\t};\r\n\r\n\t\treturn meta;\r\n\t}\r\n\r\n\t/**\r\n\t * Default invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tdefaultStyle(): any {\r\n\t\tconst defaults = {\r\n\t\t\tfontSize: 10,\r\n\t\t\tlineHeight: 1.8,\r\n\t\t\tbold: false,\r\n\t\t\tfont: \"Helvetica\",\r\n\t\t\tcolor: \"#222222\",\r\n\t\t\tcolumnGap: 30,\r\n\t\t};\r\n\t\treturn defaults;\r\n\t}\r\n\r\n\t/**\r\n\t * Invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tstyles(): any {\r\n\t\tconst styles = {\r\n\t\t\th1: {\r\n\t\t\t\tfontSize: 18,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th2: {\r\n\t\t\t\tfontSize: 16,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th3: {\r\n\t\t\t\tfontSize: 14,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\ttext: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: false,\r\n\t\t\t},\r\n\t\t\ttextBold: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t};\r\n\t\treturn styles;\r\n\t}\r\n\r\n\t/**\r\n\t * Return the invoice layout.\r\n\t *\r\n\t * @returns {Object} layout.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcontent(): any {\r\n\t\tconst sections = [];\r\n\r\n\t\t/**\r\n\t\t * Left: Company section.\r\n\t\t * Right: Invoice section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionCompany = {\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"70%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"30%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tif (this.company.logo) {\r\n\t\t\tif (!this.company.logo.startsWith(\" 0) {\r\n\t\t\tthis.items.forEach((item) => {\r\n\t\t\t\tconst totalPrice = helper.calcItemTotal(item);\r\n\r\n\t\t\t\tsectionItems.table.body.push([\r\n\t\t\t\t\t`\\n ${item.name}`,\r\n\t\t\t\t\t`\\n ${item.quantity}`,\r\n\t\t\t\t\t`\\n ${this.currency}${item.price}`,\r\n\t\t\t\t\t`\\n ${item.tax || 0}%`,\r\n\t\t\t\t\t`\\n ${this.currency}${totalPrice}`,\r\n\t\t\t\t]);\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tsections.push(sectionItems);\r\n\r\n\t\t/**\r\n\t\t * Right: Total section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionTotal = {\r\n\t\t\tmargin: [0, 20, 0, 0],\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"*\",\r\n\t\t\t\t\tstack: [\" \"],\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: 200,\r\n\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\tstyle: \"textBold\",\r\n\t\t\t\t\ttable: {\r\n\t\t\t\t\t\twidths: [80, \"*\"],\r\n\t\t\t\t\t\theaderRows: 1,\r\n\t\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\t\tbody: [\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Subtotal\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcSubTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total Tax\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcTax(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcFinalTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t},\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tsections.push(sectionTotal);\r\n\r\n\t\t/**\r\n\t\t * Left: QR section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.qr) {\r\n\t\t\tconst sectionQR = {\r\n\t\t\t\tmargin: [0, 50, 0, 0],\r\n\t\t\t\tqr: this.payload.qr.data,\r\n\t\t\t\tfit: this.payload.qr.width || \"50\",\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionQR);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Left: Notes section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.note) {\r\n\t\t\tconst sectionNote = {\r\n\t\t\t\tmargin: [0, this.payload.qr ? 20 : 50, 0, 0],\r\n\t\t\t\ttext: this.payload.note,\r\n\t\t\t\titalics: true,\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionNote);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Return the invoice sections.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\treturn sections;\r\n\t}\r\n}\r\n"]}
\ No newline at end of file
diff --git a/dist/index.mjs b/dist/index.mjs
index cd9e8cb..5069798 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -1,14 +1,14 @@
-var l=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var y=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var u=y((b,h)=>{var p={calcItemTotal:function(s){let t=s.price||0,e=s.quantity||1;return (t*e).toFixed(2)},calcSubTotal:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{t+=Number(this.calcItemTotal(e));}),t.toFixed(2)},calcTax:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{let n=e.price,c=e.quantity,i=e.tax||0;t+=n*c*i/100;}),t.toFixed(2)},calcFinalTotal:function(s){if(s.length===0)return 0;let t=Number(this.calcSubTotal(s)),e=Number(this.calcTax(s));return (t+e).toFixed(2)}};h.exports=p;});var f=l("fs"),d=l("path"),x=l("pdfmake"),a=u(),r=class{payload;company;invoice;customer;items;currency;path;qr;note;date;constructor(t){this.payload=t,this.company=t.company,this.customer=t.customer,this.invoice=t.invoice,this.items=t.items,this.qr=t.qr,this.note=t.note,this.currency=this.invoice.currency||"$",this.path=d.resolve(this.invoice.path)||"./invoice.pdf",this.date=new Date().toLocaleDateString("en-US",{year:"numeric",month:"numeric",day:"numeric"});}async create(){let t=new x(this.fonts()),e={pageSize:"A4",orientation:"portrait",pageMargins:[40,40,40,40],info:this.meta(),content:this.content(),defaultStyle:this.defaultStyle(),styles:this.styles()};return new Promise((n,c)=>{let i=t.createPdfKitDocument(e);i.pipe(f.createWriteStream(this.path)),i.end(),i.on("end",()=>{n(this.path);}),i.on("error",o=>{c(o);});})}fonts(){return {Helvetica:{normal:"Helvetica",bold:"Helvetica-Bold",italics:"Helvetica-Oblique",bolditalics:"Helvetica-BoldOblique"}}}meta(){return {title:"Invoice - #"+this.invoice.number,author:this.company.name,subject:"Invoice - "+this.customer.name,keywords:"invoice"}}defaultStyle(){return {fontSize:10,lineHeight:1.8,bold:!1,font:"Helvetica",color:"#222222",columnGap:30}}styles(){return {h1:{fontSize:18,bold:!0},h2:{fontSize:16,bold:!0},h3:{fontSize:14,bold:!0},text:{fontSize:10,bold:!1},textBold:{fontSize:10,bold:!0}}}content(){let t=[],e={columns:[{width:"70%",stack:[],style:"text"},{width:"30%",stack:[],style:"text"}]};if(this.company.logo){if(!this.company.logo.startsWith("typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var y=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var m=y((b,u)=>{var p={calcItemTotal:function(s){let t=s.price||0,e=s.quantity||1;return (t*e).toFixed(2)},calcSubTotal:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{t+=Number(this.calcItemTotal(e));}),t.toFixed(2)},calcTax:function(s){if(s.length===0)return 0;let t=0;return s.forEach(e=>{let n=e.price,c=e.quantity,i=e.tax||0;t+=n*c*i/100;}),t.toFixed(2)},calcFinalTotal:function(s){if(s.length===0)return 0;let t=Number(this.calcSubTotal(s)),e=Number(this.calcTax(s));return (t+e).toFixed(2)}};u.exports=p;});var f=r("fs"),d=r("path"),x=r("pdfmake"),a=m(),h=class{payload;company;invoice;customer;items;currency;path;qr;note;date;constructor(t){this.payload=t,this.company=t.company,this.customer=t.customer,this.invoice=t.invoice,this.items=t.items,this.qr=t.qr,this.note=t.note,this.currency=this.invoice.currency||"$",this.path=d.resolve(this.invoice.path)||"./invoice.pdf",this.date=new Date().toLocaleDateString("en-US",{year:"numeric",month:"numeric",day:"numeric"});}async create(){let t=new x(this.fonts()),e={pageSize:"A4",orientation:"portrait",pageMargins:[40,40,40,40],info:this.meta(),content:this.content(),defaultStyle:this.defaultStyle(),styles:this.styles()};return new Promise((n,c)=>{let i=t.createPdfKitDocument(e),o=f.createWriteStream(this.path);i.pipe(o),i.on("end",()=>{n(this.path);}),i.on("error",l=>{c(l);}),i.end();})}fonts(){return {Helvetica:{normal:"Helvetica",bold:"Helvetica-Bold",italics:"Helvetica-Oblique",bolditalics:"Helvetica-BoldOblique"}}}meta(){return {title:"Invoice - #"+this.invoice.number,author:this.company.name,subject:"Invoice - "+this.customer.name,keywords:"invoice"}}defaultStyle(){return {fontSize:10,lineHeight:1.8,bold:!1,font:"Helvetica",color:"#222222",columnGap:30}}styles(){return {h1:{fontSize:18,bold:!0},h2:{fontSize:16,bold:!0},h3:{fontSize:14,bold:!0},text:{fontSize:10,bold:!1},textBold:{fontSize:10,bold:!0}}}content(){let t=[],e={columns:[{width:"70%",stack:[],style:"text"},{width:"30%",stack:[],style:"text"}]};if(this.company.logo){if(!this.company.logo.startsWith("0&&this.items.forEach(o=>{let m=a.calcItemTotal(o);c.table.body.push([`
+ Total`]]}};this.items.length>0&&this.items.forEach(o=>{let l=a.calcItemTotal(o);c.table.body.push([`
${o.name}`,`
${o.quantity}`,`
${this.currency}${o.price}`,`
${o.tax||0}%`,`
- ${this.currency}${m}`]);}),t.push(c);let i={margin:[0,20,0,0],columns:[{width:"*",stack:[" "],style:"text"},{width:200,lineHeight:1.5,style:"textBold",table:{widths:[80,"*"],headerRows:1,lineHeight:1.5,body:[[`
+ ${this.currency}${l}`]);}),t.push(c);let i={margin:[0,20,0,0],columns:[{width:"*",stack:[" "],style:"text"},{width:200,lineHeight:1.5,style:"textBold",table:{widths:[80,"*"],headerRows:1,lineHeight:1.5,body:[[`
Subtotal`,`
${this.currency}${a.calcSubTotal(this.items)}`],[`
Total Tax`,`
@@ -16,6 +16,6 @@ var l=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(t
Total`,`
${this.currency}${a.calcFinalTotal(this.items)}`]]}}]};if(t.push(i),this.payload.qr){let o={margin:[0,50,0,0],qr:this.payload.qr.data,fit:this.payload.qr.width||"50"};t.push(o);}if(this.payload.note){let o={margin:[0,this.payload.qr?20:50,0,0],text:this.payload.note,italics:!0};t.push(o);}return t}};
-export { r as PDFInvoice };
+export { h as PDFInvoice };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.mjs.map
\ No newline at end of file
diff --git a/dist/index.mjs.map b/dist/index.mjs.map
index 8deddae..402462e 100644
--- a/dist/index.mjs.map
+++ b/dist/index.mjs.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/utils/helper.ts","../src/class/invoice.ts"],"names":["require_helper","__commonJSMin","exports","module","helper","item","price","quantity","items","total","tax","subTotal","fs","path","invoiceMaker","PDFInvoice","payload","printer","docDefinition","resolve","reject","doc","e","sections","sectionCompany","sectionCustomer","sectionItems","totalPrice","sectionTotal","sectionQR","sectionNote"],"mappings":"uTAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cASA,IAAMC,EAAkB,CAQvB,cAAe,SAAUC,EAAwB,CAChD,IAAMC,EAAQD,EAAK,OAAS,EACtBE,EAAWF,EAAK,UAAY,EAClC,OAAQC,EAAQC,GAAU,QAAQ,CAAC,CACpC,EASA,aAAc,SAAUC,EAAoC,CAC3D,GAAIA,EAAM,SAAW,EACpB,MAAO,GAGR,IAAIC,EAAQ,EAEZ,OAAAD,EAAM,QAASH,GAAS,CACvBI,GAAS,OAAO,KAAK,cAAcJ,CAAI,CAAC,CACzC,CAAC,EAEMI,EAAM,QAAQ,CAAC,CACvB,EASA,QAAS,SAAUD,EAAoC,CACtD,G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ACpB,GAAI,KAAK,QAAQ,GAAG,KACpB,IAAK,KAAK,QAAQ,GAAG,OAAS,IAC/B,EAEAN,EAAS,KAAKM,CAAS,CACxB,CAOA,GAAI,KAAK,QAAQ,KAAM,CACtB,IAAMC,EAAc,CACnB,OAAQ,CAAC,EAAG,KAAK,QAAQ,GAAK,GAAK,GAAI,EAAG,CAAC,EAC3C,KAAM,KAAK,QAAQ,KACnB,QAAS,EACV,EAEAP,EAAS,KAAKO,CAAW,CAC1B,CAOA,OAAOP,CACR,CACD","sourcesContent":["import type { ItemInfo } from \"../../global\";\r\n\r\ninterface Helpers {\r\n\tcalcItemTotal(item: ItemInfo): number | string;\r\n\tcalcTax(items: ItemInfo[]): number | string;\r\n\tcalcSubTotal(items: ItemInfo[]): number | string;\r\n\tcalcFinalTotal(items: ItemInfo[]): number | string;\r\n}\r\n\r\nconst helper: Helpers = {\r\n\t/**\r\n\t * Item total price calculation.\r\n\t *\r\n\t * @param {Object} item.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcItemTotal: function (item: ItemInfo): string {\r\n\t\tconst price = item.price || 0;\r\n\t\tconst quantity = item.quantity || 1;\r\n\t\treturn (price * quantity).toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate subtotal.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcSubTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\ttotal += Number(this.calcItemTotal(item));\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate tax.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcTax: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\tconst price = item.price;\r\n\t\t\tconst quantity = item.quantity;\r\n\t\t\tconst tax = item.tax || 0;\r\n\r\n\t\t\ttotal += (price * quantity * tax) / 100;\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate total final price.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcFinalTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tconst subTotal = Number(this.calcSubTotal(items));\r\n\t\tconst tax = Number(this.calcTax(items));\r\n\r\n\t\treturn (subTotal + tax).toFixed(2);\r\n\t},\r\n};\r\n\r\nmodule.exports = helper;\r\n","const fs = require(\"fs\");\r\nconst path = require(\"path\");\r\nconst invoiceMaker = require(\"pdfmake\");\r\nconst helper = require(\"../utils/helper\");\r\nimport type {\r\n\tCompanyInfo,\r\n\tCustomerInfo,\r\n\tInvoiceInfo,\r\n\tItemInfo,\r\n\tQRInfo,\r\n\tNotes,\r\n\tInvoicePayLoad,\r\n\tSimplePDFInvoice,\r\n} from \"../../global\";\r\n\r\nexport class PDFInvoice implements SimplePDFInvoice {\r\n\tpayload: InvoicePayLoad;\r\n\tcompany: CompanyInfo;\r\n\tinvoice: InvoiceInfo;\r\n\tcustomer: CustomerInfo;\r\n\titems: ItemInfo[];\r\n\tcurrency: string;\r\n\tpath: string;\r\n\tqr: QRInfo;\r\n\tnote: Notes;\r\n\tdate: string;\r\n\tconstructor(payload: InvoicePayLoad) {\r\n\t\tthis.payload = payload;\r\n\r\n\t\t// Invoice content section.\r\n\t\tthis.company = payload.company;\r\n\t\tthis.customer = payload.customer;\r\n\t\tthis.invoice = payload.invoice;\r\n\t\tthis.items = payload.items;\r\n\t\tthis.qr = payload.qr;\r\n\t\tthis.note = payload.note;\r\n\r\n\t\t// Invoice currency.\r\n\t\tthis.currency = this.invoice.currency || \"$\";\r\n\r\n\t\t// Path.\r\n\t\tthis.path = path.resolve(this.invoice.path) || \"./invoice.pdf\";\r\n\r\n\t\t// Invoice information.\r\n\t\tthis.date = new Date().toLocaleDateString(\"en-US\", {\r\n\t\t\tyear: \"numeric\",\r\n\t\t\tmonth: \"numeric\",\r\n\t\t\tday: \"numeric\",\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Create a PDF invoice.\r\n\t *\r\n\t * @returns {void}\r\n\t * @since 1.0.0\r\n\t */\r\n\tasync create(): Promise {\r\n\t\tconst printer = new invoiceMaker(this.fonts());\r\n\r\n\t\tconst docDefinition = {\r\n\t\t\tpageSize: \"A4\",\r\n\t\t\torientation: \"portrait\",\r\n\t\t\tpageMargins: [40, 40, 40, 40],\r\n\t\t\tinfo: this.meta(),\r\n\t\t\tcontent: this.content(),\r\n\t\t\tdefaultStyle: this.defaultStyle(),\r\n\t\t\tstyles: this.styles(),\r\n\t\t};\r\n\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst doc = printer.createPdfKitDocument(docDefinition);\r\n\r\n\t\t\tdoc.pipe(fs.createWriteStream(this.path));\r\n\r\n\t\t\tdoc.end();\r\n\r\n\t\t\tdoc.on(\"end\", () => {\r\n\t\t\t\tresolve(this.path);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.on(\"error\", (e: any) => {\r\n\t\t\t\treject(e);\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Fonts.\r\n\t *\r\n\t * @returns {Object} font.\r\n\t * @since 1.0.0\r\n\t */\r\n\tfonts(): any {\r\n\t\tconst fonts = {\r\n\t\t\tHelvetica: {\r\n\t\t\t\tnormal: \"Helvetica\",\r\n\t\t\t\tbold: \"Helvetica-Bold\",\r\n\t\t\t\titalics: \"Helvetica-Oblique\",\r\n\t\t\t\tbolditalics: \"Helvetica-BoldOblique\",\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\treturn fonts;\r\n\t}\r\n\r\n\t/**\r\n\t * Doc meta.\r\n\t *\r\n\t * @returns {Object} meta.\r\n\t * @since 1.0.0\r\n\t */\r\n\tmeta(): any {\r\n\t\tconst meta = {\r\n\t\t\ttitle: \"Invoice - #\" + this.invoice.number,\r\n\t\t\tauthor: this.company.name,\r\n\t\t\tsubject: \"Invoice - \" + this.customer.name,\r\n\t\t\tkeywords: \"invoice\",\r\n\t\t};\r\n\r\n\t\treturn meta;\r\n\t}\r\n\r\n\t/**\r\n\t * Default invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tdefaultStyle(): any {\r\n\t\tconst defaults = {\r\n\t\t\tfontSize: 10,\r\n\t\t\tlineHeight: 1.8,\r\n\t\t\tbold: false,\r\n\t\t\tfont: \"Helvetica\",\r\n\t\t\tcolor: \"#222222\",\r\n\t\t\tcolumnGap: 30,\r\n\t\t};\r\n\t\treturn defaults;\r\n\t}\r\n\r\n\t/**\r\n\t * Invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tstyles(): any {\r\n\t\tconst styles = {\r\n\t\t\th1: {\r\n\t\t\t\tfontSize: 18,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th2: {\r\n\t\t\t\tfontSize: 16,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th3: {\r\n\t\t\t\tfontSize: 14,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\ttext: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: false,\r\n\t\t\t},\r\n\t\t\ttextBold: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t};\r\n\t\treturn styles;\r\n\t}\r\n\r\n\t/**\r\n\t * Return the invoice layout.\r\n\t *\r\n\t * @returns {Object} layout.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcontent(): any {\r\n\t\tconst sections = [];\r\n\r\n\t\t/**\r\n\t\t * Left: Company section.\r\n\t\t * Right: Invoice section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionCompany = {\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"70%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"30%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tif (this.company.logo) {\r\n\t\t\tif (!this.company.logo.startsWith(\" 0) {\r\n\t\t\tthis.items.forEach((item) => {\r\n\t\t\t\tconst totalPrice = helper.calcItemTotal(item);\r\n\r\n\t\t\t\tsectionItems.table.body.push([\r\n\t\t\t\t\t`\\n ${item.name}`,\r\n\t\t\t\t\t`\\n ${item.quantity}`,\r\n\t\t\t\t\t`\\n ${this.currency}${item.price}`,\r\n\t\t\t\t\t`\\n ${item.tax || 0}%`,\r\n\t\t\t\t\t`\\n ${this.currency}${totalPrice}`,\r\n\t\t\t\t]);\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tsections.push(sectionItems);\r\n\r\n\t\t/**\r\n\t\t * Right: Total section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionTotal = {\r\n\t\t\tmargin: [0, 20, 0, 0],\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"*\",\r\n\t\t\t\t\tstack: [\" \"],\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: 200,\r\n\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\tstyle: \"textBold\",\r\n\t\t\t\t\ttable: {\r\n\t\t\t\t\t\twidths: [80, \"*\"],\r\n\t\t\t\t\t\theaderRows: 1,\r\n\t\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\t\tbody: [\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Subtotal\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcSubTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total Tax\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcTax(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcFinalTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t},\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tsections.push(sectionTotal);\r\n\r\n\t\t/**\r\n\t\t * Left: QR section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.qr) {\r\n\t\t\tconst sectionQR = {\r\n\t\t\t\tmargin: [0, 50, 0, 0],\r\n\t\t\t\tqr: this.payload.qr.data,\r\n\t\t\t\tfit: this.payload.qr.width || \"50\",\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionQR);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Left: Notes section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.note) {\r\n\t\t\tconst sectionNote = {\r\n\t\t\t\tmargin: [0, this.payload.qr ? 20 : 50, 0, 0],\r\n\t\t\t\ttext: this.payload.note,\r\n\t\t\t\titalics: true,\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionNote);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Return the invoice sections.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\treturn sections;\r\n\t}\r\n}\r\n"]}
\ No newline at end of file
+{"version":3,"sources":["../src/utils/helper.ts","../src/class/invoice.ts"],"names":["require_helper","__commonJSMin","exports","module","helper","item","price","quantity","items","total","tax","subTotal","fs","path","invoiceMaker","PDFInvoice","payload","printer","docDefinition","resolve","reject","doc","stream","err","sections","sectionCompany","sectionCustomer","sectionItems","totalPrice","sectionTotal","sectionQR","sectionNote"],"mappings":"uTAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cASA,IAAMC,EAAkB,CAQvB,cAAe,SAAUC,EAAwB,CAChD,IAAMC,EAAQD,EAAK,OAAS,EACtBE,EAAWF,EAAK,UAAY,EAClC,OAAQC,EAAQC,GAAU,QAAQ,CAAC,CACpC,EASA,aAAc,SAAUC,EAAoC,CAC3D,GAAIA,EAAM,SAAW,EACpB,MAAO,GAGR,IAAIC,EAAQ,EAEZ,OAAAD,EAAM,QAASH,GAAS,CACvBI,GAAS,OAAO,KAAK,cAAcJ,CAAI,CAAC,CACzC,CAAC,EAEMI,EAAM,QAAQ,CAAC,CACvB,EASA,QAAS,SAAUD,EAAoC,CACtD,GAAIA,EAAM,SAAW,EACpB,MAAO,GAGR,IAAIC,EAAQ,EAEZ,OAAAD,EAAM,QAASH,GAAS,CACvB,IAAMC,EAAQD,EAAK,MACbE,EAAWF,EAAK,SAChBK,EAAML,EAAK,KAAO,EAExBI,GAAUH,EAAQC,EAAWG,EAAO,GACrC,CAAC,EAEMD,EAAM,QAAQ,CAAC,CACvB,EASA,eAAgB,S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C,KAAM,KAAK,QAAQ,KACnB,QAAS,EACV,EAEAP,EAAS,KAAKO,CAAW,CAC1B,CAOA,OAAOP,CACR,CACD","sourcesContent":["import type { ItemInfo } from \"../../global\";\r\n\r\ninterface Helpers {\r\n\tcalcItemTotal(item: ItemInfo): number | string;\r\n\tcalcTax(items: ItemInfo[]): number | string;\r\n\tcalcSubTotal(items: ItemInfo[]): number | string;\r\n\tcalcFinalTotal(items: ItemInfo[]): number | string;\r\n}\r\n\r\nconst helper: Helpers = {\r\n\t/**\r\n\t * Item total price calculation.\r\n\t *\r\n\t * @param {Object} item.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcItemTotal: function (item: ItemInfo): string {\r\n\t\tconst price = item.price || 0;\r\n\t\tconst quantity = item.quantity || 1;\r\n\t\treturn (price * quantity).toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate subtotal.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcSubTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\ttotal += Number(this.calcItemTotal(item));\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate tax.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcTax: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tlet total = 0;\r\n\r\n\t\titems.forEach((item) => {\r\n\t\t\tconst price = item.price;\r\n\t\t\tconst quantity = item.quantity;\r\n\t\t\tconst tax = item.tax || 0;\r\n\r\n\t\t\ttotal += (price * quantity * tax) / 100;\r\n\t\t});\r\n\r\n\t\treturn total.toFixed(2);\r\n\t},\r\n\r\n\t/**\r\n\t * Calculate total final price.\r\n\t *\r\n\t * @param {Object} items.\r\n\t * @returns {number} total.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcalcFinalTotal: function (items: ItemInfo[]): number | string {\r\n\t\tif (items.length === 0) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tconst subTotal = Number(this.calcSubTotal(items));\r\n\t\tconst tax = Number(this.calcTax(items));\r\n\r\n\t\treturn (subTotal + tax).toFixed(2);\r\n\t},\r\n};\r\n\r\nmodule.exports = helper;\r\n","const fs = require(\"fs\");\r\nconst path = require(\"path\");\r\nconst invoiceMaker = require(\"pdfmake\");\r\nconst helper = require(\"../utils/helper\");\r\nimport type {\r\n\tCompanyInfo,\r\n\tCustomerInfo,\r\n\tInvoiceInfo,\r\n\tItemInfo,\r\n\tQRInfo,\r\n\tNotes,\r\n\tInvoicePayLoad,\r\n\tSimplePDFInvoice,\r\n} from \"../../global\";\r\n\r\nexport class PDFInvoice implements SimplePDFInvoice {\r\n\tpayload: InvoicePayLoad;\r\n\tcompany: CompanyInfo;\r\n\tinvoice: InvoiceInfo;\r\n\tcustomer: CustomerInfo;\r\n\titems: ItemInfo[];\r\n\tcurrency: string;\r\n\tpath: string;\r\n\tqr: QRInfo;\r\n\tnote: Notes;\r\n\tdate: string;\r\n\tconstructor(payload: InvoicePayLoad) {\r\n\t\tthis.payload = payload;\r\n\r\n\t\t// Invoice content section.\r\n\t\tthis.company = payload.company;\r\n\t\tthis.customer = payload.customer;\r\n\t\tthis.invoice = payload.invoice;\r\n\t\tthis.items = payload.items;\r\n\t\tthis.qr = payload.qr;\r\n\t\tthis.note = payload.note;\r\n\r\n\t\t// Invoice currency.\r\n\t\tthis.currency = this.invoice.currency || \"$\";\r\n\r\n\t\t// Path.\r\n\t\tthis.path = path.resolve(this.invoice.path) || \"./invoice.pdf\";\r\n\r\n\t\t// Invoice information.\r\n\t\tthis.date = new Date().toLocaleDateString(\"en-US\", {\r\n\t\t\tyear: \"numeric\",\r\n\t\t\tmonth: \"numeric\",\r\n\t\t\tday: \"numeric\",\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Create a PDF invoice.\r\n\t *\r\n\t * @returns {void}\r\n\t * @since 1.0.0\r\n\t */\r\n\tasync create(): Promise {\r\n\t\tconst printer = new invoiceMaker(this.fonts());\r\n\r\n\t\tconst docDefinition = {\r\n\t\t\tpageSize: \"A4\",\r\n\t\t\torientation: \"portrait\",\r\n\t\t\tpageMargins: [40, 40, 40, 40],\r\n\t\t\tinfo: this.meta(),\r\n\t\t\tcontent: this.content(),\r\n\t\t\tdefaultStyle: this.defaultStyle(),\r\n\t\t\tstyles: this.styles(),\r\n\t\t};\r\n\r\n\t\treturn new Promise((resolve, reject) => {\r\n\t\t\tconst doc = printer.createPdfKitDocument(docDefinition);\r\n\t\t\tconst stream = fs.createWriteStream(this.path);\r\n\r\n\t\t\tdoc.pipe(stream);\r\n\r\n\t\t\tdoc.on(\"end\", () => {\r\n\t\t\t\tresolve(this.path);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.on(\"error\", (err: any) => {\r\n\t\t\t\treject(err);\r\n\t\t\t});\r\n\r\n\t\t\tdoc.end();\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Fonts.\r\n\t *\r\n\t * @returns {Object} font.\r\n\t * @since 1.0.0\r\n\t */\r\n\tfonts(): any {\r\n\t\tconst fonts = {\r\n\t\t\tHelvetica: {\r\n\t\t\t\tnormal: \"Helvetica\",\r\n\t\t\t\tbold: \"Helvetica-Bold\",\r\n\t\t\t\titalics: \"Helvetica-Oblique\",\r\n\t\t\t\tbolditalics: \"Helvetica-BoldOblique\",\r\n\t\t\t},\r\n\t\t};\r\n\r\n\t\treturn fonts;\r\n\t}\r\n\r\n\t/**\r\n\t * Doc meta.\r\n\t *\r\n\t * @returns {Object} meta.\r\n\t * @since 1.0.0\r\n\t */\r\n\tmeta(): any {\r\n\t\tconst meta = {\r\n\t\t\ttitle: \"Invoice - #\" + this.invoice.number,\r\n\t\t\tauthor: this.company.name,\r\n\t\t\tsubject: \"Invoice - \" + this.customer.name,\r\n\t\t\tkeywords: \"invoice\",\r\n\t\t};\r\n\r\n\t\treturn meta;\r\n\t}\r\n\r\n\t/**\r\n\t * Default invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tdefaultStyle(): any {\r\n\t\tconst defaults = {\r\n\t\t\tfontSize: 10,\r\n\t\t\tlineHeight: 1.8,\r\n\t\t\tbold: false,\r\n\t\t\tfont: \"Helvetica\",\r\n\t\t\tcolor: \"#222222\",\r\n\t\t\tcolumnGap: 30,\r\n\t\t};\r\n\t\treturn defaults;\r\n\t}\r\n\r\n\t/**\r\n\t * Invoice styles.\r\n\t *\r\n\t * @returns {Object} defaults.\r\n\t * @since 1.0.0\r\n\t */\r\n\tstyles(): any {\r\n\t\tconst styles = {\r\n\t\t\th1: {\r\n\t\t\t\tfontSize: 18,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th2: {\r\n\t\t\t\tfontSize: 16,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\th3: {\r\n\t\t\t\tfontSize: 14,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t\ttext: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: false,\r\n\t\t\t},\r\n\t\t\ttextBold: {\r\n\t\t\t\tfontSize: 10,\r\n\t\t\t\tbold: true,\r\n\t\t\t},\r\n\t\t};\r\n\t\treturn styles;\r\n\t}\r\n\r\n\t/**\r\n\t * Return the invoice layout.\r\n\t *\r\n\t * @returns {Object} layout.\r\n\t * @since 1.0.0\r\n\t */\r\n\tcontent(): any {\r\n\t\tconst sections = [];\r\n\r\n\t\t/**\r\n\t\t * Left: Company section.\r\n\t\t * Right: Invoice section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionCompany = {\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"70%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"30%\",\r\n\t\t\t\t\tstack: [] as any,\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tif (this.company.logo) {\r\n\t\t\tif (!this.company.logo.startsWith(\" 0) {\r\n\t\t\tthis.items.forEach((item) => {\r\n\t\t\t\tconst totalPrice = helper.calcItemTotal(item);\r\n\r\n\t\t\t\tsectionItems.table.body.push([\r\n\t\t\t\t\t`\\n ${item.name}`,\r\n\t\t\t\t\t`\\n ${item.quantity}`,\r\n\t\t\t\t\t`\\n ${this.currency}${item.price}`,\r\n\t\t\t\t\t`\\n ${item.tax || 0}%`,\r\n\t\t\t\t\t`\\n ${this.currency}${totalPrice}`,\r\n\t\t\t\t]);\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tsections.push(sectionItems);\r\n\r\n\t\t/**\r\n\t\t * Right: Total section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tconst sectionTotal = {\r\n\t\t\tmargin: [0, 20, 0, 0],\r\n\t\t\tcolumns: [\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: \"*\",\r\n\t\t\t\t\tstack: [\" \"],\r\n\t\t\t\t\tstyle: \"text\",\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\twidth: 200,\r\n\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\tstyle: \"textBold\",\r\n\t\t\t\t\ttable: {\r\n\t\t\t\t\t\twidths: [80, \"*\"],\r\n\t\t\t\t\t\theaderRows: 1,\r\n\t\t\t\t\t\tlineHeight: 1.5,\r\n\t\t\t\t\t\tbody: [\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Subtotal\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcSubTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total Tax\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcTax(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\t\"\\n Total\",\r\n\t\t\t\t\t\t\t\t`\\n ${this.currency}${helper.calcFinalTotal(\r\n\t\t\t\t\t\t\t\t\tthis.items\r\n\t\t\t\t\t\t\t\t)}`,\r\n\t\t\t\t\t\t\t],\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t},\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t};\r\n\r\n\t\tsections.push(sectionTotal);\r\n\r\n\t\t/**\r\n\t\t * Left: QR section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.qr) {\r\n\t\t\tconst sectionQR = {\r\n\t\t\t\tmargin: [0, 50, 0, 0],\r\n\t\t\t\tqr: this.payload.qr.data,\r\n\t\t\t\tfit: this.payload.qr.width || \"50\",\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionQR);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Left: Notes section.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\tif (this.payload.note) {\r\n\t\t\tconst sectionNote = {\r\n\t\t\t\tmargin: [0, this.payload.qr ? 20 : 50, 0, 0],\r\n\t\t\t\ttext: this.payload.note,\r\n\t\t\t\titalics: true,\r\n\t\t\t};\r\n\r\n\t\t\tsections.push(sectionNote);\r\n\t\t}\r\n\r\n\t\t/**\r\n\t\t * Return the invoice sections.\r\n\t\t *\r\n\t\t * @since 1.0.0\r\n\t\t */\r\n\t\treturn sections;\r\n\t}\r\n}\r\n"]}
\ No newline at end of file
diff --git a/examples/example.ts b/examples/example.ts
index 4de6216..8418747 100644
--- a/examples/example.ts
+++ b/examples/example.ts
@@ -22,7 +22,7 @@ const payload = {
dueDate: "25/12/2023",
status: "Paid!",
currency: "£",
- path: "./invoice.pdf", // path needs to be relative to current working directory.
+ path: path.join(__dirname, "invoice.pdf"),
},
items: [
{
@@ -55,10 +55,13 @@ const payload = {
* Generate PDF invoice.
*/
const createPDF = async () => {
- const invoice = new PDFInvoice(payload);
- const pdf = await invoice.create();
-
- console.log(pdf);
+ try {
+ const invoice = new PDFInvoice(payload);
+ const result = await invoice.create();
+ console.log("✨ [Success] Invoice created : " + result + "\n");
+ } catch (err) {
+ console.log(err);
+ }
};
createPDF();
diff --git a/examples/invoice.pdf b/examples/invoice.pdf
index 96fb5bb..a3fcef2 100644
Binary files a/examples/invoice.pdf and b/examples/invoice.pdf differ
diff --git a/global.d.ts b/global.d.ts
index 5eb3336..a5bd6c9 100644
--- a/global.d.ts
+++ b/global.d.ts
@@ -1,6 +1,6 @@
export interface CompanyInfo {
logo?: string;
- name: string;
+ name?: string;
address?: string;
phone?: string;
email?: string;
diff --git a/package.json b/package.json
index 581c847..4551f90 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@h1dd3nsn1p3r/pdf-invoice",
- "version": "1.0.5",
+ "version": "1.0.6",
"author": "h1dd3nsn1p3r",
"description": "Simple yet powerful node JS library that generates PDF invoice on the fly.",
"license": "MIT",
diff --git a/src/class/invoice.ts b/src/class/invoice.ts
index 104cf0b..61970ff 100644
--- a/src/class/invoice.ts
+++ b/src/class/invoice.ts
@@ -70,18 +70,19 @@ export class PDFInvoice implements SimplePDFInvoice {
return new Promise((resolve, reject) => {
const doc = printer.createPdfKitDocument(docDefinition);
+ const stream = fs.createWriteStream(this.path);
- doc.pipe(fs.createWriteStream(this.path));
-
- doc.end();
+ doc.pipe(stream);
doc.on("end", () => {
resolve(this.path);
});
- doc.on("error", (e: any) => {
- reject(e);
+ doc.on("error", (err: any) => {
+ reject(err);
});
+
+ doc.end();
});
}