-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.js
More file actions
114 lines (106 loc) · 4.13 KB
/
report.js
File metadata and controls
114 lines (106 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
function copyTableDataToArray() {
let table = document.getElementById("CustomerDetailsReport").getElementsByTagName('tbody')[0];
let rows = table.getElementsByTagName('tr');
let dataArray = [];
for (let i = 0; i < rows.length; i++) {
let cells = rows[i].getElementsByTagName('td');
let rowData = {
orderID: cells[0].textContent,
total: cells[3].textContent,
date: cells[4].textContent
};
dataArray.push(rowData);
}
return dataArray;
}
// Define the Monthly object
let currentMonthValue = new Date().getMonth() + 1; // Months are zero-indexed
let currentYear = new Date().getFullYear();
let currentdate = new Date().getDate();
function generateReport() {
let dataArray = copyTableDataToArray();
var Monthly = {
outputType: jsPDFInvoiceTemplate.OutputType.Save, // Use OutputType from jsPDFInvoiceTemplate
returnJsPDFDocObject: true,
fileName: "Monthly Sales Report",
orientationLandscape: false,
compress: true,
logo: {
src: "img/logo.png",
type: 'PNG', // Optional, when src = data:uri (nodejs case)
width: 40, // Aspect ratio = width/height
height: 40,
margin: {
top: -10, // Negative or positive num, from the current position
left: 0 // Negative or positive num, from the current position
}
},
stamp: {
inAllPages: true, // By default = false, just in the last page
src: "https://raw.githubusercontent.com/edisonneza/jspdf-invoice-template/demo/images/qr_code.jpg",
type: 'JPG', // Optional, when src = data:uri (nodejs case)
width: 20, // Aspect ratio = width/height
height: 20,
margin: {
top: 0, // Negative or positive num, from the current position
left: 0 // Negative or positive num, from the current position
}
},
business: {
name: "J&K Burgers",
address: "No 115,New City,Halphathota,Baddegama",
phone: "(+94) 0740726297",
email: "JKBurgers@gmail.com",
website: "www.S&DBurgers.com",
},
invoice: {
label: "Monthly Sales Report: ",
num:1,// Ensure this variable is defined elsewhere in your code
invDate: `From: 1/${currentMonthValue}/${currentYear}`, // Template literals for dynamic values
invGenDate: `To: ${currentdate}/${currentMonthValue}/${currentYear}`, // Template literals for dynamic values
headerBorder: true,
tableBodyBorder: true,
header: [
{ title: "#" },
{ title: "Order ID" },
{ title: "Order Date" },
{ title: "Total" }
],
table: dataArray.map((rowData, index) => ([
index + 1, // Index for row number
rowData.orderID,
rowData.date, // Using the 'date' property from dataArray
rowData.total // Using the 'total' property from dataArray
])),
additionalRows: [
{
col1: 'Total:',
col2: '145,250.50',
col3: 'ALL',
style: { fontSize: 14 } // Optional, default 12
},
{
col1: 'VAT:',
col2: '20',
col3: '%',
style: { fontSize: 10 } // Optional, default 12
},
{
col1: 'SubTotal:',
col2: '116,199.90',
col3: 'ALL',
style: { fontSize: 10 } // Optional, default 12
}
],
},
footer: {
text: "The invoice is created on a computer and is valid without the signature and stamp.",
},
pageEnable: true,
pageLabel: "Page ",
};
// Create the PDF
jsPDFInvoiceTemplate.default(Monthly);
// Log the object for debugging
console.log("PDF Object created");
}