Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue where item descriptions would overlap #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified examples/example.pdf
Binary file not shown.
25 changes: 4 additions & 21 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let myInvoice = new MicroInvoice({
value : 1
}, {
label : "Status",
value : "Paid"
value : "Paid afsdf asfdasd asf asdf as asdfasdf asd asd fasf"
}, {
label : "Date",
value : "22/10/21"
Expand Down Expand Up @@ -78,13 +78,11 @@ let myInvoice = new MicroInvoice({
value : "Description"
}, {
value : "Quantity"
}, {
value : "Subtotal"
}],

parts : [
[{
value : "Nike Air Max"
value : "Nike Air Max Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit"
}, {
value : 1
}, {
Expand All @@ -102,29 +100,14 @@ let myInvoice = new MicroInvoice({
}]
],

total : [{
label : "Total without VAT",
value : "43",
price : true
}, {
label : "VAT Rate",
value : "20%"
}, {
label : "VAT Paid",
value : "8.6",
price : true
}, {
label : "Total paid with VAT",
value : "51.6",
price : true
}]
total : []
}
}
}
});

// Render invoice as PDF
myInvoice.generate("example.pdf").then(() => {
myInvoice.generate("examples/example.pdf").then(() => {
console.log("Invoice saved");
}).catch((error) => {
console.error(error);
Expand Down
61 changes: 31 additions & 30 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = class Microinvoice {
},
header : {
backgroundColor : "#F8F8FA",
height : 150,
height : 120,
image : null,
textPosition : 330
},
Expand Down Expand Up @@ -88,12 +88,12 @@ module.exports = class Microinvoice {
}, {
value : "Quantity"
}, {
value : "Subtotal"
value : ""
}],
parts : [],
total : [{
label : "Total",
value : 0
label : "",
value : ""
}]
},
legal : []
Expand Down Expand Up @@ -246,41 +246,46 @@ module.exports = class Microinvoice {
);
}

let _fontMargin = 4;
let _fontMargin = 2;

// Write header details
this.setCursor("x", this.options.style.header.textPosition);
this.setCursor("y", this.options.style.document.marginTop);


this.setText(this.options.data.invoice.name, {
fontSize : "heading",
fontWeight : "bold",
color : this.options.style.header.regularColor
});

let currentY = this.storage.cursor.y
const currentX = this.storage.cursor.x

this.options.data.invoice.header.forEach(line => {
currentY = this.storage.cursor.y
this.setText(`${line.label}:`, {
fontWeight : "bold",
color : this.options.style.header.regularColor,
marginTop : _fontMargin
marginTop : _fontMargin,
skipDown: true
});

let _values = [];
this.setCursor('x', currentX + 100)
this.setCursor('y', currentY)


if (Array.isArray(line.value)) {
_values = line.value;
} else {
_values = [line.value];
}
this.setText(line.value, {
colorCode : "secondary",
color : this.options.style.header.secondaryColor,
marginTop : _fontMargin,
maxWidth : 145,
})

_values.forEach((value) => {
this.setText(value, {
colorCode : "secondary",
color : this.options.style.header.secondaryColor,
marginTop : _fontMargin
});
});
this.setCursor('x', currentX)

});

}

/**
Expand Down Expand Up @@ -341,10 +346,6 @@ module.exports = class Microinvoice {
generateTableRow(type, columns) {
let _fontWeight = "normal", _colorCode = "secondary";

this.storage.cursor.y = this.document.y;

this.storage.cursor.y += 17;

if (type === "header") {
_fontWeight = "bold";
_colorCode = "primary";
Expand Down Expand Up @@ -397,12 +398,10 @@ module.exports = class Microinvoice {
}
});

// Set y to the max y position
this.setCursor("y", _maxY);

if (type === "header") {
this.generateLine();
}
this.generateLine();

}

/**
Expand All @@ -412,7 +411,6 @@ module.exports = class Microinvoice {
* @return void
*/
generateLine() {
this.storage.cursor.y += this.options.style.text.regularSize + 2;

this.document
.strokeColor("#F0F0F0")
Expand All @@ -426,6 +424,9 @@ module.exports = class Microinvoice {
this.storage.cursor.y
)
.stroke();

this.setCursor("y", this.storage.cursor.y + 5);

}

/**
Expand All @@ -452,7 +453,7 @@ module.exports = class Microinvoice {
this.generateTableRow("row", part);
});

this.storage.cursor.y += 50;
this.storage.cursor.y += 10;

(this.options.data.invoice.details.total || []).forEach(total => {
let _mainRatio = 0.6, _secondaryRatio = 0.3;
Expand Down Expand Up @@ -488,7 +489,7 @@ module.exports = class Microinvoice {
* @return void
*/
generateLegal() {
this.storage.cursor.y += 60;
this.storage.cursor.y += 15;

(this.options.data.invoice.legal || []).forEach(legal => {
this.setCursor("x", this.options.style.document.marginLeft * 2);
Expand Down