-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
971 lines (873 loc) · 37.7 KB
/
Copy pathindex.html
File metadata and controls
971 lines (873 loc) · 37.7 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
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dammam Airport Company (DACO) - Invoice System</title>
<link
href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"
rel="stylesheet"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.3.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.13/jspdf.plugin.autotable.min.js"></script>
</head>
<body class="bg-gray-100 font-serif">
<div class="container mx-auto p-4">
<header
class="flex justify-between items-center bg-white shadow p-4 rounded mb-4"
>
<div>
<h1 class="text-2xl font-bold">Dammam Airport Company (DACO)</h1>
<p class="text-gray-600">
Supply Chain Department - Commercial Comparison
</p>
</div>
<div>
<label for="supplier1" class="block text-gray-600">Supplier 1:</label>
<input
type="text"
id="supplier1"
class="border rounded px-2 py-1 mb-2"
oninput="saveSupplierNames()"
/>
<label for="supplier2" class="block text-gray-600">Supplier 2:</label>
<input
type="text"
id="supplier2"
class="border rounded px-2 py-1 mb-2"
oninput="saveSupplierNames()"
/>
<label for="supplier3" class="block text-gray-600">Supplier 3:</label>
<input
type="text"
id="supplier3"
class="border rounded px-2 py-1"
oninput="saveSupplierNames()"
/>
</div>
</header>
<!-- Invoice Table -->
<div class="bg-white shadow rounded p-4 mb-4">
<table id="comparisonTable" class="min-w-full border-collapse w-full">
<thead class="bg-gray-200">
<tr>
<th class="border px-4 py-2" colspan="5"></th>
<th class="border px-4 py-2" colspan="2" id="supplierHeader1">
AL Yaseen Agricultar
</th>
<th class="border px-4 py-2" colspan="2" id="supplierHeader2">
Al Taleb Group
</th>
<th class="border px-4 py-2" colspan="2" id="supplierHeader3">
Alam Albiad
</th>
<th class="border px-4 py-2"></th>
</tr>
<tr>
<th class="border px-4 py-2">S.N</th>
<th class="border px-4 py-2">Services No</th>
<th class="border px-4 py-2">Description</th>
<th class="border px-4 py-2">Unit</th>
<th class="border px-4 py-2">Qty</th>
<th class="border px-4 py-2">Unit Price</th>
<th class="border px-4 py-2">Total Price</th>
<th class="border px-4 py-2">Unit Price</th>
<th class="border px-4 py-2">Total Price</th>
<th class="border px-4 py-2">Unit Price</th>
<th class="border px-4 py-2">Total Price</th>
<th class="border px-4 py-2">Actions</th>
</tr>
</thead>
<tbody>
<!-- Sample data row -->
</tbody>
<tfoot class="bg-gray-200">
<tr class="font-bold">
<td class="border px-4 py-2" colspan="6">Subtotal</td>
<td class="border px-4 py-2" colspan="2" id="subtotal">0.00</td>
<td class="border px-4 py-2" colspan="2" id="subtotal2">0.00</td>
<td class="border px-4 py-2" colspan="2" id="subtotal3">0.00</td>
</tr>
<tr class="font-bold">
<td class="border px-4 py-2" colspan="6">VAT (15%)</td>
<td class="border px-4 py-2" colspan="2" id="vat">0.00</td>
<td class="border px-4 py-2" colspan="2" id="vat2">0.00</td>
<td class="border px-4 py-2" colspan="2" id="vat3">0.00</td>
</tr>
<tr class="font-bold">
<td class="border px-4 py-2" colspan="6">Total (with VAT)</td>
<td class="border px-4 py-2" colspan="2" id="total1">0.00</td>
<td class="border px-4 py-2" colspan="2" id="total2">0.00</td>
<td class="border px-4 py-2" colspan="2" id="total3">0.00</td>
</tr>
</tfoot>
</table>
</div>
<!-- Buttons for actions -->
<div class="flex justify-end mb-4">
<!-- <button class=" bg-indigo-500 px-4 py-2 rounded mr-2 text-white hover:bg-slate-900"> <a href="#">Check_Lowprice</a></button> -->
<!-- <button
class="bg-green-500 text-white px-4 py-2 rounded"
onclick="saveHistory()"
>
Save History
</button>
<button
class="bg-indigo-500 px-4 py-2 rounded mr-2 text-white hover:bg-slate-900"
>
<a href="./history.html">History</a>
</button> -->
<!-- histoy btn -->
<button
class="bg-green-500 text-white px-4 py-2 rounded"
onclick="saveHistory()"
>
Save History
</button>
<button
class="bg-indigo-500 px-4 py-2 rounded mr-2 text-white hover:bg-slate-900"
>
<a href="./history.html">History</a>
</button>
<!-- Assuming you have input fields for subtotal, VAT, and total -->
<input type="text" id="subtotal" placeholder="Subtotal" />
<input type="text" id="vat" placeholder="VAT" />
<input type="text" id="total" placeholder="Total" />
<!-- histoy btn -->
<button
class="bg-blue-500 text-white px-4 py-2 rounded mr-2"
onclick="addRow()"
>
Add Row
</button>
<button
class="bg-red-500 text-white px-4 py-2 rounded mr-2"
onclick="removeAllRows()"
>
Remove All Rows
</button>
<button
class="bg-green-500 text-white px-4 py-2 rounded mr-2"
onclick="downloadExcel()"
>
Download as Excel
</button>
<button
class="bg-purple-500 text-white px-4 py-2 rounded mr-2"
onclick="downloadPDF()"
>
Download as PDF
</button>
<input
type="file"
id="uploadPdfInput"
accept="application/pdf"
onchange="uploadPDF(event)"
style="display: none"
multiple
/>
<button
class="bg-indigo-500 text-white px-4 py-2 rounded"
onclick="document.getElementById('uploadPdfInput').click()"
>
Upload PDF
</button>
<button
class="bg-indigo-500 text-white p-4 ml-5 py-2 rounded"
onclick="document.getElementById('').click()"
>
Send to email
</button>
</div>
<!-- Uploaded PDF Section -->
<div id="uploadedPdfContainer" class="flex flex-wrap mb-4"></div>
<!-- Comments Section -->
<div class="bg-white shadow rounded p-4">
<h2 class="text-xl font-bold mb-2">Comments</h2>
<div class="flex mb-4">
<input
type="text"
id="commentInput"
class="flex-grow border rounded px-4 py-2 mr-2"
placeholder="Enter your comment"
/>
<button
class="bg-blue-500 text-white px-4 py-2 rounded"
onclick="submitComment()"
>
Submit
</button>
<button
class="bg-gray-500 text-white px-4 py-2 rounded ml-2"
onclick="clearComment()"
>
Clear
</button>
</div>
<div class="comments" id="comments"></div>
</div>
</div>
<script>
// Save supplier names to localStorage
function saveSupplierNames() {
const supplier1 = document.getElementById("supplier1").value;
const supplier2 = document.getElementById("supplier2").value;
const supplier3 = document.getElementById("supplier3").value;
localStorage.setItem("supplier1", supplier1);
localStorage.setItem("supplier2", supplier2);
localStorage.setItem("supplier3", supplier3);
// Update the table headers dynamically
document.getElementById("supplierHeader1").innerText =
supplier1 || "AL Yaseen Agricultar";
document.getElementById("supplierHeader2").innerText =
supplier2 || "Al Taleb Group";
document.getElementById("supplierHeader3").innerText =
supplier3 || "Alam Albiad";
}
// Load supplier names from localStorage
function loadSupplierNames() {
const supplier1 =
localStorage.getItem("supplier1") || "AL Yaseen Agricultar";
const supplier2 = localStorage.getItem("supplier2") || "Al Taleb Group";
const supplier3 = localStorage.getItem("supplier3") || "Alam Albiad";
document.getElementById("supplier1").value = supplier1;
document.getElementById("supplier2").value = supplier2;
document.getElementById("supplier3").value = supplier3;
document.getElementById("supplierHeader1").innerText = supplier1;
document.getElementById("supplierHeader2").innerText = supplier2;
document.getElementById("supplierHeader3").innerText = supplier3;
}
// Load supplier names on page load
window.onload = loadSupplierNames;
// // Save the table state to localStorage
function saveTableState() {
const tableData = [];
document
.querySelectorAll("#comparisonTable tbody tr")
.forEach((row) => {
const rowData = [];
row.querySelectorAll("td").forEach((cell) => {
if (
cell.children.length > 0 &&
cell.children[0].tagName === "SELECT"
) {
// If it's a select dropdown, save the selected value
rowData.push(cell.children[0].value);
} else {
rowData.push(cell.innerHTML);
}
});
tableData.push(rowData);
});
localStorage.setItem("tableState", JSON.stringify(tableData));
}
// Load the table state from localStorage
function loadTableState() {
const tableData = JSON.parse(localStorage.getItem("tableState"));
if (tableData) {
document.querySelector("#comparisonTable tbody").innerHTML = ""; // Clear existing rows
tableData.forEach((rowData, index) => {
addRow(false); // Add a new row but don't update totals yet
const row = document.querySelector(
"#comparisonTable tbody tr:last-child"
);
row.querySelectorAll("td").forEach((cell, i) => {
if (
cell.children.length > 0 &&
cell.children[0].tagName === "SELECT"
) {
// If it's a select dropdown, set the selected value
cell.children[0].value = rowData[i];
} else {
cell.innerHTML = rowData[i];
}
});
});
updateTotals();
}
}
// Function to save supplier names to localStorage
function saveSupplierNames() {
const supplier1 = document.getElementById("supplier1").value;
const supplier2 = document.getElementById("supplier2").value;
const supplier3 = document.getElementById("supplier3").value;
localStorage.setItem("supplier1", supplier1);
localStorage.setItem("supplier2", supplier2);
localStorage.setItem("supplier3", supplier3);
document.getElementById("supplierHeader1").innerText =
supplier1 || "AL Yaseen Agricultar";
document.getElementById("supplierHeader2").innerText =
supplier2 || "Al Taleb Group";
document.getElementById("supplierHeader3").innerText =
supplier3 || "Alam Albiad";
}
// Function to load supplier names from localStorage
function loadSupplierNames() {
const supplier1 =
localStorage.getItem("supplier1") || "AL Yaseen Agricultar";
const supplier2 = localStorage.getItem("supplier2") || "Al Taleb Group";
const supplier3 = localStorage.getItem("supplier3") || "Alam Albiad";
document.getElementById("supplier1").value = supplier1;
document.getElementById("supplier2").value = supplier2;
document.getElementById("supplier3").value = supplier3;
document.getElementById("supplierHeader1").innerText = supplier1;
document.getElementById("supplierHeader2").innerText = supplier2;
document.getElementById("supplierHeader3").innerText = supplier3;
}
// Function to save the current state of the table to localStorage
function saveTableState() {
const tableRows = document.querySelectorAll(
"#comparisonTable tbody tr"
);
const tableData = Array.from(tableRows).map((row) => {
return Array.from(row.cells).map((cell) => {
if (cell.querySelector("select")) {
return cell.querySelector("select").value;
} else if (cell.querySelector("input")) {
return cell.querySelector("input").value;
} else {
return cell.innerText.trim();
}
});
});
localStorage.setItem("tableData", JSON.stringify(tableData));
}
function loadTableState() {
const tableData = JSON.parse(localStorage.getItem("tableData") || "[]");
const tbody = document.querySelector("#comparisonTable tbody");
tbody.innerHTML = ""; // Clear existing rows
tableData.forEach((rowData, rowIndex) => {
const row = document.createElement("tr");
row.innerHTML = `
<td class="border px-4 py-2">${rowIndex + 1}</td>
<td class="border px-4 py-2">
<select class="w-full" onchange="updateCol3Options(this)">
<option value="6840l352683" ${
rowData[1] === "6840l352683" ? "selected" : ""
}>6840l352683</option>
<option value="6840L413853" ${
rowData[1] === "6840L413853" ? "selected" : ""
}>6840L413853</option>
<option value="8720L107601" ${
rowData[1] === "8720L107601" ? "selected" : ""
}>8720L107601</option>
<option value="8720L107602" ${
rowData[1] === "8720L107602" ? "selected" : ""
}>8720L107602</option>
</select>
</td>
<td class="border px-4 py-2">
<select class="w-full" onchange="saveTableState()">
<!-- Options will be dynamically populated based on col2 selection -->
</select>
</td>
<td class="border px-4 py-2" contenteditable="true" oninput="updateRow(this)">${
rowData[3] || ""
}</td>
<td class="border px-4 py-2" contenteditable="true" oninput="updateRow(this)">${
rowData[4] || "0"
}</td>
<td class="border px-4 py-2" contenteditable="true" oninput="updateRow(this)">${
rowData[5] || "0"
}</td>
<td class="border px-4 py-2 total-price">${
rowData[6] || "0.00"
}</td>
<td class="border px-4 py-2" contenteditable="true" oninput="updateRow(this)">${
rowData[7] || "0"
}</td>
<td class="border px-4 py-2 total-price">${
rowData[8] || "0.00"
}</td>
<td class="border px-4 py-2" contenteditable="true" oninput="updateRow(this)">${
rowData[9] || "0"
}</td>
<td class="border px-4 py-2 total-price">${
rowData[10] || "0.00"
}</td>
<td class="border px-4 py-2"><button class="text-red-500" onclick="removeRow(this)">Remove</button></td>
`;
tbody.appendChild(row);
updateCol3Options(row.querySelector("select")); // Initialize col3 based on loaded data
});
}
// Function to update options in col3 based on selection in col2
function updateCol3Options(selectElement) {
const selectedValue = selectElement.value;
const col3Select =
selectElement.parentElement.nextElementSibling.querySelector(
"select"
);
col3Select.innerHTML = ""; // Clear existing options
const descriptions = descriptionOptions[selectedValue] || [];
descriptions.forEach((description) => {
col3Select.innerHTML += `<option value="${description}">${description}</option>`;
});
saveTableState(); // Save state after updating col3 options
}
// Function to update row (triggered on input change)
function updateRow(cell) {
saveTableState(); // Save state whenever a cell is updated
}
// Function to remove a row from the table
function removeRow(button) {
button.closest("tr").remove();
saveTableState(); // Save state after removing a row
updateTotals(); // Recalculate totals after row removal
}
// Function to calculate totals (not fully implemented in the provided code)
function updateTotals() {
// Add your logic to update totals here if required
}
// Function to add a new row to the table
function addRow(updateTotalsFlag = true) {
const row = document.createElement("tr");
row.innerHTML = `
<td class="border px-4 py-2">${
document.querySelectorAll("#comparisonTable tbody tr")
.length + 1
}</td>
<td class="border px-4 py-2">
<select class="w-full" onchange="updateCol3Options(this)">
<option value="6840l352683">6840l352683</option>
<option value="6840L413853">6840L413853</option>
<option value="8720L107601">8720L107601</option>
<option value="8720L107602">8720L107602</option>
<option value="8720L158245">8720L158245</option>
<option value="8720L158736">8720L158736</option>
<option value="8720L267035">8720L267035</option>
<option value="8720L281984">8720L281984</option>
<option value="8720l298434">8720l298434</option>
<option value="8720L298533">8720L298533</option>
<option value="8720L298566">8720L298566</option>
<option value="8720L298567">8720L298567</option>
<option value="8720L298568">8720L298568</option>
<option value="8720L298570">8720L298570</option>
<option value="8720L352423">8720L352423</option>
<option value="8720L355889">8720L355889</option>
<option value="8720L355904">8720L355904</option>
<option value="8720L360048">8720L360048</option>
<option value="8720L368838">8720L368838</option>
<option value="8720L384282">8720L384282</option>
<option value="8720L392458">8720L392458</option>
<option value="8720L421026">8720L421026</option>
<option value="8720L413799">8720L413799</option>
<option value="8720L413798">8720L413798</option>
<option value="8720L403745">8720L403745</option>
<option value="8720L393565">8720L403745</option>
</select>
</td>
<td class="border px-4 py-2">
<select class="w-full" onchange="saveTableState()">
<!-- Options will be dynamically populated based on col2 selection -->
</select>
</td>
<td class="border px-4 py-2" contenteditable="true" oninput="updateRow(this)">IT</td>
<td class="border px-4 py-2" contenteditable="true" oninput="updateRow(this)">0</td>
<td class="border px-4 py-2" contenteditable="true" oninput="updateRow(this)">0</td>
<td class="border px-4 py-2 total-price">0.00</td>
<td class="border px-4 py-2" contenteditable="true" oninput="updateRow(this)">0</td>
<td class="border px-4 py-2 total-price">0.00</td>
<td class="border px-4 py-2" contenteditable="true" oninput="updateRow(this)">0</td>
<td class="border px-4 py-2 total-price">0.00</td>
<td class="border px-4 py-2"><button class="text-red-500" onclick="removeRow(this)">Remove</button></td>
`;
document.querySelector("#comparisonTable tbody").appendChild(row);
updateCol3Options(row.querySelector("select")); // Initialize col3 options
if (updateTotalsFlag) updateTotals();
saveTableState(); // Save state after adding a row
}
// Predefined options for col3 based on col2 selections (server numbers mapped to descriptions)
const descriptionOptions = {
"6840l352683": ["B-Nine dose SB plant growth reg."],
"6840L413853": ["B-Nine plant growth reg. SWG 1KG"],
"8720L107601": ["CALCIUM NITRATE 50KG/BG"],
"8720L107602": ["COPPER CHELATE 12%"],
"8720L107605": ["IRON CHELATE 11%"],
"8720L107607": ["MANGANESE CHELATE 12%"],
"8720L107615": ["ZINC CHELATE 12%"],
"8720L125863": ["CALCIUM NITRATE 100LB/BG"],
"8720L158238": ["Osmocote 14-14-14 50LB/BG"],
"8720L158245": ["Peters 20-10-20"],
"8720L158736": ["Soil vermiculite conditioner 85L"],
"8720L267035": ["Albustan organic 25 KG"],
"8720L281984": ["Soil perlite crum condr. 4cuft/bag"],
"8720l298434": ["Peat-lite special"],
"8720L298533": ["Soil orchid conditioner"],
"8720L298566": ["Osmocote 13-13-13"],
"8720L298567": ["Osmocote 17-7-12"],
"8720L298568": ["Super PO4 triple 0-46-0 50LB/BG"],
"8720L298570": ["Urea formaldehyde 38-0-0"],
"8720L352420": ["DAP 25-53-0 100LB/BG"],
"8720L352423": ["MANGANESE CHELATE 13%"],
"8720L355889": ["IRON CHELATE 13.2%"],
"8720L355904": ["ZINC CHELATE 15%"],
"8720L360048": ["Potassium NO3 13-0-44"],
"8720L368838": ["Urea 46-0-0"],
"8720L384282": ["Potassium nitrate 13-0-45+Te1.2%"],
"8720L392458": ["COPPER CHELATE 14%"],
"8720L393565": ["Diammonium phosphate 18-46-0"],
"8720L403745": ["Soil Charcoal"],
"8720L413798": ["Peters peat-lite"],
"8720L413799": ["Micromax 25lb/bag"],
"8720L421026": ["Sangral 20-20-20 + T/E 25KG/BG"],
};
// Load supplier names and table state on page load
window.onload = () => {
loadSupplierNames();
loadTableState();
};
// Remove a specific row
function removeRow(button) {
button.closest("tr").remove();
updateTotals();
}
// Remove all rows
function removeAllRows() {
document.querySelector("#comparisonTable tbody").innerHTML = "";
updateTotals();
}
// Update row calculations and totals
function updateRow(cell) {
const row = cell.closest("tr");
const qty = parseFloat(row.cells[4].innerText) || 0;
const unitPrice1 = parseFloat(row.cells[5].innerText) || 0;
const totalPrice1 = qty * unitPrice1;
row.cells[6].innerText = totalPrice1.toFixed(2);
const unitPrice2 = parseFloat(row.cells[7].innerText) || 0;
const totalPrice2 = qty * unitPrice2;
row.cells[8].innerText = totalPrice2.toFixed(2);
const unitPrice3 = parseFloat(row.cells[9].innerText) || 0;
const totalPrice3 = qty * unitPrice3;
row.cells[10].innerText = totalPrice3.toFixed(2);
updateTotals();
}
// Update all totals
function updateTotals() {
let subtotal = 0;
let subtotal2 = 0;
let subtotal3 = 0;
document
.querySelectorAll("#comparisonTable tbody tr")
.forEach((row) => {
subtotal += parseFloat(row.cells[6].innerText) || 0;
subtotal2 += parseFloat(row.cells[8].innerText) || 0;
subtotal3 += parseFloat(row.cells[10].innerText) || 0;
});
const vat = subtotal * 0.15;
const total = subtotal + vat;
const vat2 = subtotal2 * 0.15;
const total2 = subtotal2 + vat2;
const vat3 = subtotal3 * 0.15;
const total3 = subtotal3 + vat3;
document.getElementById("subtotal").innerText = subtotal.toFixed(2);
document.getElementById("vat").innerText = vat.toFixed(2);
document.getElementById("total").innerText = total.toFixed(2);
document.getElementById("subtotal2").innerText = subtotal2.toFixed(2);
document.getElementById("vat2").innerText = vat2.toFixed(2);
document.getElementById("total2").innerText = total2.toFixed(2);
document.getElementById("subtotal3").innerText = subtotal3.toFixed(2);
document.getElementById("vat3").innerText = vat3.toFixed(2);
document.getElementById("total3").innerText = total3.toFixed(2);
saveTableState();
}
// Download table as Excel
function downloadExcel() {
const table = document.getElementById("comparisonTable");
const workbook = XLSX.utils.table_to_book(table);
XLSX.writeFile(workbook, "comparison_table.xlsx");
}
function downloadExcel() {
const table = document.getElementById("comparisonTable");
const workbook = XLSX.utils.table_to_book(table);
XLSX.writeFile(workbook, "comparison_table.xlsx");
}
function downloadPDF() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF("l", "pt", "a4");
doc.text("Dammam Airport Company (DACO)", 40, 40);
doc.text("Supply Chain Department - Commercial Comparison", 40, 60);
const table = document.getElementById("comparisonTable");
const data = [];
const rows = table.getElementsByTagName("tr");
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const rowData = [];
const cells = row.getElementsByTagName("td");
for (let j = 0; j < cells.length; j++) {
if (
cells[j].children.length > 0 &&
cells[j].children[0].tagName === "SELECT"
) {
rowData.push(
cells[j].children[0].options[cells[j].children[0].selectedIndex]
.text
);
} else {
rowData.push(cells[j].innerText);
}
}
data.push(rowData);
}
doc.autoTable({
head: [
[
"S.N",
"Services No",
"Description",
"Unit",
"Qty",
"Unit Price",
"Total Price",
"Unit Price",
"Total Price",
"Unit Price",
"Total Price",
],
],
body: data,
startY: 80,
});
doc.save("comparison.pdf");
}
function downloadPDF() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF("landscape", "pt", "a4");
// Adding header
doc.setFontSize(18);
doc.text("Dammam Airport Company (DACO)", 40, 40);
doc.setFontSize(12);
doc.text("Supply Chain Department - Commercial Comparison", 40, 60);
// Clone the table
const table = document
.getElementById("comparisonTable")
.cloneNode(true);
// Replace dropdowns with selected values in the cloned table
const rows = table.querySelectorAll("tbody tr");
rows.forEach((row) => {
row.querySelectorAll("td").forEach((cell) => {
if (
cell.children.length > 0 &&
cell.children[0].tagName === "SELECT"
) {
const select = cell.children[0];
const selectedValue = select.value;
cell.innerHTML = selectedValue; // Replace the cell content with the selected value
}
});
});
// Adding table to the PDF
doc.autoTable({
html: table,
startY: 80,
theme: "grid",
styles: { cellPadding: 3, fontSize: 10 },
headStyles: { fillColor: [0, 0, 0] },
didDrawCell: function (data) {
if (
data.column.index === 6 ||
data.column.index === 8 ||
data.column.index === 10
) {
// Highlight the lowest price among the suppliers
const cellValue = parseFloat(data.cell.text[0]) || 0;
const row = data.row.index;
const cell6 = parseFloat(rows[row].cells[6].innerText) || 0;
const cell8 = parseFloat(rows[row].cells[8].innerText) || 0;
const cell10 = parseFloat(rows[row].cells[10].innerText) || 0;
const minValue = Math.min(cell6, cell8, cell10);
if (cellValue === minValue) {
data.cell.styles.fillColor = [0, 255, 0]; // Highlight the lowest price cells
}
}
},
});
// Adding comments to the PDF
const commentsDiv = document.getElementById("comments");
const comments = commentsDiv.querySelectorAll("div");
if (comments.length > 0) {
doc.setFontSize(14);
doc.text("Comments:", 40, doc.lastAutoTable.finalY + 40);
doc.setFontSize(12);
comments.forEach((comment, index) => {
const commentText = comment.querySelector("span").innerText;
doc.text(
`${index + 1}. ${commentText}`,
40,
doc.lastAutoTable.finalY + 60 + index * 20
);
});
}
// Save the generated PDF
doc.save("comparison.pdf");
}
function uploadPDF(event) {
const files = event.target.files;
const uploadedPdfs =
JSON.parse(localStorage.getItem("uploadedPdfs")) || [];
for (let i = 0; i < files.length; i++) {
const file = files[i];
const reader = new FileReader();
reader.onload = function (e) {
const pdfContainer = document.createElement("div");
pdfContainer.className =
"flex items-center m-2 p-2 border border-gray-300 rounded";
// Create the PDF icon
const pdfIcon = document.createElement("img");
pdfIcon.src = "https://img.icons8.com/ios-filled/50/000000/pdf.png"; // PDF icon
pdfIcon.alt = "PDF";
pdfIcon.className = "w-8 h-8 cursor-pointer";
pdfIcon.onclick = function () {
const newTab = window.open();
newTab.document.body.innerHTML = `<iframe src="${e.target.result}" class="w-full h-full" style="height: 100vh;"></iframe>`;
};
// Create the remove button
const removeBtn = document.createElement("button");
removeBtn.className =
"ml-2 bg-red-500 text-white px-2 py-1 rounded";
removeBtn.innerText = "Remove";
removeBtn.onclick = function () {
pdfContainer.remove();
// Remove from localStorage
const index = uploadedPdfs.indexOf(e.target.result);
if (index !== -1) {
uploadedPdfs.splice(index, 1);
saveUploadedPdfs(uploadedPdfs);
}
};
// Append the icon and remove button to the container
pdfContainer.appendChild(pdfIcon);
pdfContainer.appendChild(removeBtn);
document
.getElementById("uploadedPdfContainer")
.appendChild(pdfContainer);
uploadedPdfs.push(e.target.result);
saveUploadedPdfs(uploadedPdfs);
};
reader.readAsDataURL(file);
}
}
function saveUploadedPdfs(pdfs) {
localStorage.setItem("uploadedPdfs", JSON.stringify(pdfs));
}
function loadUploadedPdfs() {
const uploadedPdfs = JSON.parse(localStorage.getItem("uploadedPdfs"));
if (uploadedPdfs) {
const container = document.getElementById("uploadedPdfContainer");
container.innerHTML = "";
uploadedPdfs.forEach((pdf) => {
const pdfContainer = document.createElement("div");
pdfContainer.className =
"flex items-center m-2 p-2 border border-gray-300 rounded";
// Create the PDF icon
const pdfIcon = document.createElement("img");
pdfIcon.src = "https://img.icons8.com/ios-filled/50/000000/pdf.png"; // PDF icon
pdfIcon.alt = "PDF";
pdfIcon.className = "w-8 h-8 cursor-pointer";
pdfIcon.onclick = function () {
const newTab = window.open();
newTab.document.body.innerHTML = `<iframe src="${pdf}" class="w-full h-full" style="height: 100vh;"></iframe>`;
};
// Create the remove button
const removeBtn = document.createElement("button");
removeBtn.className =
"ml-2 bg-red-500 text-white px-2 py-1 rounded";
removeBtn.innerText = "Remove";
removeBtn.onclick = function () {
pdfContainer.remove();
// Remove from localStorage
const index = uploadedPdfs.indexOf(pdf);
if (index !== -1) {
uploadedPdfs.splice(index, 1);
saveUploadedPdfs(uploadedPdfs);
}
};
// Append the icon and remove button to the container
pdfContainer.appendChild(pdfIcon);
pdfContainer.appendChild(removeBtn);
container.appendChild(pdfContainer);
});
}
}
document.addEventListener("DOMContentLoaded", () => {
loadUploadedPdfs();
});
// Download table data as PDF file
// Submit a comment with edit and delete functionalities
function submitComment() {
const commentInput = document.getElementById("commentInput");
const commentText = commentInput.value.trim();
if (commentText) {
addComment(commentText);
commentInput.value = "";
saveComments();
}
}
function addComment(commentText, load = false) {
const commentDiv = document.createElement("div");
commentDiv.className =
"bg-gray-100 border border-gray-300 p-2 mb-2 rounded flex justify-between items-center";
const commentTextNode = document.createElement("span");
commentTextNode.contentEditable = true;
commentTextNode.innerText = commentText;
commentTextNode.className = "flex-grow mr-4";
commentTextNode.oninput = saveComments; // Save comments on edit
const editButton = document.createElement("button");
editButton.className =
"bg-yellow-500 text-white px-2 py-1 rounded mr-2";
editButton.innerText = "Edit";
editButton.onclick = () => {
commentTextNode.focus();
document.execCommand("selectAll", false, null);
};
const deleteButton = document.createElement("button");
deleteButton.className = "bg-red-500 text-white px-2 py-1 rounded";
deleteButton.innerText = "Delete";
deleteButton.onclick = () => {
commentDiv.remove();
saveComments();
};
commentDiv.appendChild(commentTextNode);
commentDiv.appendChild(editButton);
commentDiv.appendChild(deleteButton);
document.getElementById("comments").appendChild(commentDiv);
if (!load) {
saveComments();
}
}
function saveComments() {
const comments = [];
document.querySelectorAll("#comments > div").forEach((commentDiv) => {
const commentText = commentDiv.querySelector("span").innerText;
comments.push(commentText);
});
localStorage.setItem("comments", JSON.stringify(comments));
}
function loadComments() {
const savedComments =
JSON.parse(localStorage.getItem("comments")) || [];
savedComments.forEach((comment) => addComment(comment, true));
}
// Load comments on page load
document.addEventListener("DOMContentLoaded", loadComments);
// history page
function saveHistory() {
const history = JSON.parse(
localStorage.getItem("invoiceHistory") || "[]"
);
const newEntry = {
date: new Date().toLocaleDateString(),
subtotal: document.getElementById("total").value, // assuming you have input with id subtotal
vat: document.getElementById("total2").value, // assuming input with id vat
total: document.getElementById("total3").value, // assuming input with id total
};
history.push(newEntry);
localStorage.setItem("invoiceHistory", JSON.stringify(history));
console.log("History Saved!");
}
</script>
<body />
<html />
</body>
</html>