-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoice.php
503 lines (441 loc) · 19.5 KB
/
invoice.php
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
<?php
session_start();
include 'includes/dbConnection.php';
if (!$_SESSION["user_name_loggedIn_admin"]) {
$_SESSION["expired_session"] = "Your session has been expired, relog in!";
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="author" content="">
<title>AX GYM</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="js/scripts.js"></script>
<!-- Page level plugin CSS-->
<link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
<?php include 'globalExternals/components.php'; ?>
<style>
@page {
bleed: 1cm;
size: A4 portrait;
size: auto;
/* auto is the initial value */
margin-bottom: 50pt;
margin-top: 0cm;
font-size: 12pt;
#content,
#page {
width: 100%;
margin: 0;
float: none;
}
}
@media print {
.page {
border: initial;
border-radius: initial;
width: initial;
min-height: initial;
box-shadow: initial;
background: initial;
page-break-after: always;
}
table {
page-break-inside: auto;
}
tr.last-row {
background-color: #555 !important;
}
tr.last-row>th,
tr.last-row>td {
background-color: unset !important;
}
div.page-break {
page-break-before: auto;
}
}
.gray {
color: #333;
}
.gray-ish {
color: #666;
}
.almost-gray {
color: #999;
}
body {
background-color: #1DB198;
padding-top: 25px;
-webkit-print-color-adjust: exact !important;
height: 100%;
margin-top: 40px;
}
div.container {
background-color: white;
border-radius: 10px;
height: 100%;
position: relative;
margin-top: 50px;
}
div.invoice-header {
background-color: #444;
color: white;
border-bottom: 3px solid rgb(255, 77, 77);
}
div.invoice-header>div>p {
font-size: 1.2rem;
font-weight: 350;
}
div.invoice-header>div>h1 {
font-size: 4rem;
}
div.invoice-table {
border-top: 3px solid rgb(255, 77, 77);
}
div.invoice-table>table.table>thead,
div.invoice-table>table.table>thead.thead>tr,
div.invoice-table>table.table>thead.thead>tr>th {
border-top: none;
}
div.total-field {
position: relative;
}
h5.due-date {
position: absolute;
bottom: 10px;
right: 15px;
}
div.sub-table {
border-left: 3px solid rgb(255, 77, 77);
padding-left: 0;
}
div.sub-table>table {
padding-bottom: 0;
margin-bottom: 0;
}
tr.last-row {
margin-top: 25px;
background-color: #555;
color: white;
border-top: 3px solid rgb(255, 77, 77);
}
p.footer {
bottom: 0;
width: 100%;
background-color: #333;
color: white;
padding-top: 15px;
border-top: 3px solid red;
}
</style>
<script>
/**
* PDF page settings.
* Must have the correct values for the script to work.
* All numbers must be in inches (as floats)!
* '/25.4' part is a converstiom from mm to in.
*
* @type {Object}
*/
var pdfPage = {
width: 11.7, // inches
height: 8.3, // inches
};
/**
* The distance to bottom of which if the element is closer, it should moved on
* the next page. Should be at least the element (TR)'s height.
*
* @type {Number}
*/
var splitThreshold = 42;
/**
* Class name of the tables to automatically split.
* Should not contain any CSS definitions because it is automatically removed
* after the split.
*
* @type {String}
*/
var splitClassName = 'splitForPrint';
var debug = false;
var profile = false;
var startTime = 0;
var endTime = 0;
var tableProcessStart = 0;
var tableProcessEnd = 0;
var profileDivsList = [];
var profileDiv = $('<div>');
var dpi = 120;
var pageWidth = (pdfPage.width - pdfPage.margins.left - pdfPage.margins.right) * dpi;
// page height in pixels
var pageHeight = (pdfPage.height - pdfPage.margins.top - pdfPage.margins.bottom) * dpi;
// temporary set body's width and padding to match pdf's size
var $body = $('body .report_data'); //a single div should wrap whole pdf content
$body.css('width', pageWidth);
$body.css('margin-left', pdfPage.margins.left + 'in');
$body.css('margin-right', pdfPage.margins.right + 'in');
$body.css('margin-top', pdfPage.margins.top + 'in');
$body.css('margin-bottom', pdfPage.margins.bottom + 'in');
var currentPageZero = 0; //the offset for the currentPage. Will go with pageHeight increments page by page
var tablesModified = true;
/** div with page-break logic
* css should include
* page-break-before: always;
*/
var breaker = $('<div class="page-break"></div>');
var pageOffset = 0;
/**
* Table splitting logic lives in this method
* table - table to split, should be a jQuery object
* tableIndex - and index from original page where this table is sitting, allows to properly insert table back to where it belonged
* onTableSplittedCallback - a function that will be caleed when table will be splitted out - allows to do some post-processing if required
*/
function splitTable(table, tableIndex, onTableSplittedCallback) {
/**
* Logic of appending a new table
* container - jQuery object where we will append our table (NOTE: a collectable 'div' is used for each table in the script for memory optimization, it should be passed here)
* trs - array of <tr> objects (non jQuery) for our new table
* isLastBatch - passed as 'true' if we have tr's left over from processing and we don't want a page break because there still can be some place left on the page
*/
//The idea here is that we grab our header from original table, clone it, add some modifications and use it for all our future tables
//find our header
var originalHeader = table.find('tr.heading1');
var tableHeader;
var tableHeaderHeight;
if (originalHeader.length > 0) {
tableHeader = originalHeader.clone();
tableHeader.addClass('page-split'); //mark header so we could display that this one is splitted
/*
* In my project we had to add ellipsis before header on each new page
* Feel free to modify this part.
* Idea here is that first row of the table determines all column widths, and if it will not be exactly as our header row - table will be messed up significantly
* So, we have to make a copy of our header, clean it from the text and add some ellipsis
*/
var ellipsis = tableHeader.clone();
ellipsis.removeClass('heading1');
ellipsis.find('th,td').each(function(i, e) {
$(e).text("");
});
var ellipsisDiv = $('<div>').addClass('ellipsis').text("...");
ellipsis.find('th:eq(0),td:eq(0)').append(ellipsisDiv);
//!careful here. first row of table determines column widths!
tableHeader = tableHeader.before(ellipsis);
}
templateTable.append("<tr class='noborder'><td></td></tr>");
var tmpTables = []; //this array will store temporarry tables - we will append them after splitting logic is finished
var tmpTrs = []; //this array will store rows for each temporarry table
var collectableDiv = $('<div>'); //this div will collect our splitted table
$('tbody tr', table).each(function() {
var tr = $(this);
//get offset for current page, taking custom pageOffset into consideration
var trTop = tr.offset().top - currentPageZero - pageOffset;
if (debug) {
aa.text(aa.text() + "(o:" + tr.offset().top + " : t:" + trTop + " || ");
}
//if we fit the page with threshold - go ahead and push tr into tmpTrs array
if (trTop >= pageHeight - splitThreshold) { //else go to the next page
if (tmpTrs.length == 1 && $(tmpTrs[0]).hasClass('heading1')) {
tmpTables.push([]); //if the only row we have fit the page is a header - add a page split and move on - we don't need a single header left in the end of the page
} else {
//another special case. if we hit the page end and prev.row is 'heading2' - don't leave it last on the page
if ($(tmpTrs[tmpTrs.length - 1]).hasClass('heading2')) {
var heading2Row = tmpTrs.pop();
var heading1Row = null;
if ($(tmpTrs[tmpTrs.length - 1]).hasClass('heading1')) { //if it turnes out that heading1 is before - pop it also
heading1Row = tmpTrs.pop();
}
tmpTables.push(tmpTrs);
tmpTrs = [];
if (heading1Row) {
tmpTrs.push(heading1Row);
}
tmpTrs.push(heading2Row);
} else {
//save table and start new
tmpTables.push(tmpTrs);
tmpTrs = [];
}
}
currentPageZero += pageHeight;
}
tmpTrs.push(tr[0]);
});
//save leftower for the page and remove the original table away
tmpTables.push(tmpTrs);
tmpTrs = [];
var originalTableHeight = table.outerHeight();
collectableDiv.css('width', table.width());
table.remove();
//append each splitted table to a collectable div
$.each(tmpTables, function(i, trs) {
appendTable(collectableDiv, trs, i === tmpTables.length - 1);
})
//add that div to the page and particular index - this is where rendering will take place
var elementInParent = parent.children().eq(tableIndex);
if (elementInParent.length > 0) {
elementInParent.before(collectableDiv);
} else {
parent.children().eq(tableIndex - 1).after(collectableDiv);
}
pageOffset += (collectableDiv.outerHeight() - originalTableHeight); //new table can be greater then the original because we added some new headers
/*Feel free to strip out debuggin and profiling to minimize script size*/
if (profile) {
resultsApppendEnd = new Date().getTime();
profileDivsList.push("<div>== append results took:" + (resultsApppendEnd - resultsApppendStart) + "</div>")
}
if (profile) {
tableProcessEnd = new Date().getTime();
profileDivsList.push("<div>== process table at " + tableIndex + " took:" + (tableProcessEnd - tableProcessStart) + "</div>")
}
}
while (tablesModified) {
tablesModified = false;
while ($('table.' + splitClassName).length > 0) {
var table = $('table.' + splitClassName + ':eq(0)');
splitTable(table, table.index(), function(splittedTable) {
//some custom post-processing for each new table. This aslo was project-specific, feel free to modify
var headers = splittedTable.find('.heading1');
if (headers.length > 1) {
splittedTable.find('.ellipsis').addClass('hidden');
splittedTable.find('.heading1.page-split').addClass('hidden');
}
if (splittedTable.find('.page-split').length > 0) {
splittedTable.removeClass('new_section');
}
if (splittedTable.find('.page-split.hidden').length > 0) {
splittedTable.addClass('new_section');
}
return splittedTable;
});
}
}
// restore body's padding
$body.css('padding-left', 0);
$body.css('padding-right', 0);
</script>
</head>
<body id="page-top" class="fixed-nav">
<div class="container">
<div class="row invoice-header px-3 py-2">
<div class="col-4">
<p>AX Gym Management System</p>
<h2>INVOICE</h2>
</div>
<div class="col-4 text-right">
<p>03-123123</p>
<p>[email protected]</p>
<p>Member Payment Invoice</p>
</div>
</div>
<div class="invoice-content row px-5 pt-5">
<div class="col-3">
<h5 class="almost-gray mb-3">Invoiced to:</h5>
<p class="gray-ish">Client Name</p>
<p class="gray-ish">VAT ID: 12091803</p>
</div>
<div class="col-3">
<h5 class="almost-gray">Invoice number:</h5>
<p class="gray-ish"># 123456789</p>
<h5 class="almost-gray">Date of Issue:</h5>
<p class="gray-ish">01 / 01 / 20 20 </p>
</div>
<div class="col-6 text-right total-field">
<h4 class="almost-gray">Invoice Total</h4>
<h1 class="gray-ish">634,57 <span class="curency">$</span></h1>
</div>
</div>
<div class="row mt-5">
<div class="col-10 offset-1 invoice-table pt-1">
<table class="table table-hover">
<thead class="thead splitForPrint">
<tr>
<th scope="col gray-ish">NO.</th>
<th scope="col gray-ish">Item</th>
<th scope="col gray-ish">Qty.</th>
<th scope="col gray-ish">U. Price</th>
<th scope="col gray-ish">VAT %</th>
<th scope="col gray-ish">Discount</th>
<th class="text-right" scope="col gray-ish">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td class="item">Item 1</td>
<td>1</td>
<td>25 <span class="currency">$</span></td>
<td>5 %</td>
<td>5 %</td>
<td class="text-right">28,75 <span class="currency">$</span></td>
</tr>
<tr>
<th scope="row">2</th>
<td class="item">Item 2</td>
<td>1</td>
<td>25 <span class="currency">$</span> </td>
<td></td>
<td>5 %</td>
<td class="text-right">28,75 <span class="currency">$</span> </td>
</tr>
<tr>
<th scope="row">3</th>
<td class="item">Item 3</td>
<td>1</td>
<td>25 <span class="currency">$</span> </td>
<td>13 %</td>
<td>5 %</td>
<td class="text-right">28,75 <span class="currency">$</span> </td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row invoice_details">
<!-- invoiced to details -->
<div class="col-4 offset-1 pt-3">
<h4 class="gray-ish">Invoice Summary & Notes</h4>
<p class="pt-3 almost-gray">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras purus sapien, ullamcorper quis orci eu, consectetur congue nulla. In a fermentum est, ornare maximus neque. Phasellus metus risus, mattis ac sapien in, volutpat laoreet lectus. Maecenas tincidunt condimentum quam, ut porttitor dui ultricies nec.</p>
</div>
<!-- Invoice assets and total -->
<div class="offset-1 col-5 mb-3 pr-4 sub-table">
<table class="table table-borderless">
<tbody>
<tr>
<th scope="row gray-ish">Subtotal</th>
<td class="text-right">75 <span class="currency ">$</span></td>
</tr>
<tr>
<th scope="row gray-ish">VAT</th>
<td class="text-right">11,25 <span class="currency">$</span></td>
</tr>
<tr>
<th scope="row gray-ish">Taxes*</th>
<td class="text-right">11,25 <span class="currency">$</span></td>
</tr>
<tr>
<th scope="row gray-ish">Discounts</th>
<td class="text-right">7,5 <span class="currency">$</span></td>
</tr>
<tr class="last-row">
<th scope="row">
<h4>Total</h4>
</th>
<td class="text-right">
<h4><span class="currency">$</span> 90,25</h4>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p class="text-center pb-3"><em> Taxes will be calculated in $ regarding transport and other taxable services.</em></p>
</div>
</body>
</html>