-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmyDATA.html
664 lines (563 loc) · 20.2 KB
/
myDATA.html
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
<!DOCTYPE html>
<html>
<!--
ATTENTION: CHECK isTesting operation BEFORE USE!!
=============================================
Εφαρμογή για αποστολή ιατρικών ΑΠΥ στο MYDATA
=============================================
Υποστηρίζει:
1) αποστολή ΑΠΥ
2) κατέβασμα ΑΠΥ από MyDATA (>MARK_MIN)
2) αναζήτηση με βάση ΑΑ, ημερoμηνία, όνομα/αιτία
4) ακύρωση ΑΠΥ βάση ΜΑΡΚ
5) εκτύπωση ΑΠΥ βάση ΜΑΡΚ (online) ή entries (offline)
Hardcoded User info:
1) isTesting operation
2) Username and Keys
3) Branches (όπως φαίνονται στο Taxis)
4) Paymethods
5) Minimum MARK to download invoices
Invoice columns: Υποκ, ΑΑ, Ημ/νία, Ποσό, Πληρωμή, Σχόλιο, ΜΑΡΚ
Comment format = Patient Name, Address - Visit reason
-->
<head>
<meta charset="UTF-8">
<title>ΕΦΑΡΜΟΓΗ ΠΑΡΑΣΤΑΤΙΚΩΝ MYDATA ΓΙΑ ΓΙΑΤΡΟΥΣ</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<big><label id='title' for="title"></label></big>
<!-- SEND -->
<p> ΑΠΟΣΤΟΛΗ ΑΠΥ </p>
<label for="aa">Εδρα:</label>
<select id="dd_branch" onchange="AdjustForBranch()"></select><br><br>
<label for="aa">ΑΑ:</label>
<input type="text" id="aa" name="aa" value="" size="5">
<label for="Date">ΗΜΕΡ:</label>
<input type="text" id="date" name="date" value="" size="10"><br><br>
<label for="Amount">ΠΟΣΟ (Ε):</label>
<input type="text" id="amount" name="amount" value="5.00" size="5">
<select id="dd_paymethod"></select><br><br>
<label for="Name">ΟΝ/ΜΟ:</label>
<input type="text" id="name" name="name" value=""><br><br>
<label for="Address">ΔΙΕΥΘ:</label>
<input type="text" id="address" name="address" value="ΦΛΩΡΙΝΑ"><br><br>
<label for="reason">ΑΙΤΙΑ:</label>
<input type="text" id="reason" name="reason" value="ΣΥΝΤΑΓΟΓΡΑΦΗΣΗ"><br><br>
<button onclick="SendInvoice()">ΑΠΟΣΤΟΛΗ</button><br><br>
<!-- RETRIEVE AND SEARCH -->
<p> ΑΝΑΖΗΤΗΣΗ ΑΠΥ </p>
<select id="dd_range"></select><br><br>
<input type="text" id="from" name="from" value="">
<input type="text" id="until" name="until" value=""><br><br>
<select onchange="setMark()" id="dd_invoice"></select><br><br>
<button onclick="SearchInvoices()">ΑΝΑΖΗΤΗΣΗ</button>
<button onclick="RequestTransmittedDocs()">Sync MyDATA</button><br><br>
<!-- MANAGE -->
<p> ΔΙΑΧΕΙΡΙΣΗ ΑΠΥ </p>
<label for="Mark">ΜΑΡΚ:</label>
<input type="text" id="mark" name="mark" value=""><br><br>
<button onclick="Cancel()">ΑΚΥΡΩΣΗ</button><br><br>
<button onclick="PrintInvoice('online')">ΕΚΤΥΠΩΣΗ</button><br><br>
<button onclick="PrintInvoice('offline')">ΕΚΤΥΠΩΣΗ offline</button><br><br>
<script type="text/javascript">
// START OF JS ##################################
// GLOBALS ##############################
var user = "MYUSERNAME";
var isTesting = 1;
if (isTesting == 1) {
var MARK_MIN = 0
var key = "MYKEY-testing";
var url = "https://mydata-dev.azure-api.net";
document.getElementById("title").innerHTML =
"ΕΦΑΡΜΟΓΗ ΠΑΡΑΣΤΑΤΙΚΩΝ MYDATA ΓΙΑ ΓΙΑΤΡΟΥΣ - TESTING"
}
else {
var MARK_MIN = 0; // change as neededLast of Jul 22
var key = "MYKEY-production";
var url = "https://mydatapi.aade.gr/myDATA";
var url = "https://cors-anywhere.herokuapp.com/" + url; // bypass CORS!!
document.getElementById("title").innerHTML =
"ΕΦΑΡΜΟΓΗ ΠΑΡΑΣΤΑΤΙΚΩΝ MYDATA ΓΙΑ ΓΙΑΤΡΟΥΣ - PRODUCTION"
}
// Υποκαταστήματα με κωδικό από TAXIS
BRANCHES = {
'CITY1': [
'1', 'ADRESS1, TK1, CITY1<br />τηλ LAND, MOBILE'],
'CITY2': [
'2', 'ADRESS2, TK2, CITY2<br />τηλ LAND, MOBILE']
};
// TODO: Missing Διεθνές POS
PAYMETHODS = {
'Μετρητά': '3',
'POS': '1'
};
// POPULATE GUI ##############################
var INVOICES = [];
var INVOICE_HEAD = 'ΥΠΟΚ; ΑΑ; ΗΜ/ΝΙΑ; ΠΟΣΟ; ΠΛΗΡ; ΟΝ/ΜΟ-ΑΙΤΙΑ; ΜΑΡΚ';
var D = ";" // delimiter
// populate Branches
for (let i = 0; i < Object.keys(BRANCHES).length; i++) {
let opt_branch = document.createElement("option");
opt_branch.text = Object.keys(BRANCHES)[i]
dd_branch.options.add(opt_branch);
}
// populate Paymethods
for (let i = 0; i < Object.keys(PAYMETHODS).length; i++) {
let opt_paymethod = document.createElement("option");
opt_paymethod.text = Object.keys(PAYMETHODS)[i]
dd_paymethod.options.add(opt_paymethod);
}
// populate Search Categories
searchTerms = [
"1. Αριθμός ΑΠΥ [από] ... [έως]",
"2. Ημερομηνία [από] ... [έως]",
"5. Στοιχεία [Όνομα] και [Αιτία]"
]
for (let i = 0; i < searchTerms.length; i++) {
let opt_range = document.createElement("option");
opt_range.text = searchTerms[i]
dd_range.options.add(opt_range);
}
dd_range.value = searchTerms[1];
// Set today's date
let today = new Date().toISOString().slice(0, 10)
document.getElementById("date").value = today;
document.getElementById("until").value = today;
RequestTransmittedDocs();
// =====================================================
// Large methods
// =====================================================
// SEND invoice to MyDATA
function SendInvoice() {
let branchID = BRANCHES[document.getElementById("dd_branch").value][0];
let aa = document.getElementById("aa").value;
let date = document.getElementById("date").value;
let amount = document.getElementById("amount").value;
let paymethod = PAYMETHODS[document.getElementById("dd_paymethod").value][0];
let comment = document.getElementById("name").value + ',' +
document.getElementById("address").value + '-' +
document.getElementById("reason").value;
xml_payload = `
<InvoicesDoc xmlns="http://www.aade.gr/myDATA/invoice/v1.0" xmlns:icls="https://www.aade.gr/myDATA/incomeClassificaton/v1.0" xmlns:ecls="https://www.aade.gr/myDATA/expensesClassificaton/v1.0">
<invoice>
<issuer>
<vatNumber>062725970</vatNumber>
<country>GR</country>
<branch>${branchID}</branch>
</issuer>
<invoiceHeader>
<series>A</series>
<aa>${aa}</aa>
<issueDate>${date}</issueDate>
<invoiceType>11.2</invoiceType>
<currency>EUR</currency>
</invoiceHeader>
<paymentMethods>
<paymentMethodDetails>
<type>${paymethod}</type>
<amount>${amount}</amount>
<paymentMethodInfo>${comment}</paymentMethodInfo>
</paymentMethodDetails>
</paymentMethods>
<invoiceDetails>
<lineNumber>1</lineNumber>
<netValue>${amount}</netValue>
<vatCategory>7</vatCategory>
<vatAmount>0</vatAmount>
<vatExemptionCategory>7</vatExemptionCategory>
<incomeClassification>
<icls:classificationType>E3_561_003</icls:classificationType>
<icls:classificationCategory>category1_3</icls:classificationCategory>
<icls:amount>${amount}</icls:amount>
<icls:id>1</icls:id>
</incomeClassification>
</invoiceDetails>
<invoiceSummary>
<totalNetValue>${amount}</totalNetValue>
<totalVatAmount>0</totalVatAmount>
<totalWithheldAmount>0.00</totalWithheldAmount>
<totalFeesAmount>0.00</totalFeesAmount>
<totalStampDutyAmount>0.00</totalStampDutyAmount>
<totalOtherTaxesAmount>0.00</totalOtherTaxesAmount>
<totalDeductionsAmount>0.00</totalDeductionsAmount>
<totalGrossValue>${amount}</totalGrossValue>
<incomeClassification>
<icls:classificationType>E3_561_003</icls:classificationType>
<icls:classificationCategory>category1_3</icls:classificationCategory>
<icls:amount>${amount}</icls:amount>
</incomeClassification>
</invoiceSummary>
</invoice>
</InvoicesDoc>
`
$.ajax({
url: url + "/SendInvoices?",
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("aade-user-id", user);
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", key);
},
type: "POST",
data: xml_payload,
})
.done(function(data) {
xmlDoc = parser.parseFromString(data, "text/xml");
let mark = xmlDoc.getElementsByTagName("invoiceMark")[0].textContent;
alert("Success! Mark = " + mark);
l = ([
branchID
+ D + aa
+ D + date
+ D + amount
+ D + paymethod
+ D + comment
+ D + mark
]);
INVOICES.push(l);
let opt_invoice = document.createElement("option");
opt_invoice.text = l;
dd_invoice.options.add(opt_invoice);
})
.fail(function() {
alert("Request failed. Please see console for error");
});
};
// REQUEST invoices from MyDATA and call SearchInvoices() + AdjustForBranch()
function RequestTransmittedDocs() {
let params = {"mark": MARK_MIN};
$.ajax({
url: url + "/RequestTransmittedDocs?" + $.param(params),
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("aade-user-id", user);
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", key);
},
type: "GET",
})
.done(function(data) {
parser = new DOMParser();
xmlDoc = parser.parseFromString(data, "text/xml");
let inv = xmlDoc.getElementsByTagName("invoice");
INVOICES = [];
for (let i = 0; i < inv.length; i++) {
// Check if not Cancelled
if (typeof inv[i].getElementsByTagName("cancelledByMark") == "undefined" ||
inv[i].getElementsByTagName("cancelledByMark").length == 0) {
l =
inv[i].getElementsByTagName("branch")[0].textContent
+ D + inv[i].getElementsByTagName("aa")[0].textContent
+ D + inv[i].getElementsByTagName("issueDate")[0].textContent
+ D + inv[i].getElementsByTagName("amount")[0].textContent
+ D + inv[i].getElementsByTagName("type")[0].textContent
+ D + inv[i].getElementsByTagName("paymentMethodInfo")[0].textContent
+ D + inv[i].getElementsByTagName("mark")[0].textContent;
INVOICES.push(l);
};
};
SearchInvoices();
AdjustForBranch();
})
.fail(function() {
alert("Request failed. Please see console for error");
});
};
// SEARCH based on AA-range and populates invoice DropDown
function SearchInvoices() {
// empties the DD and adds HEAD
for (let i = document.getElementById('dd_invoice').options.length - 1; i >= 0; i--) {
document.getElementById('dd_invoice').remove(i);
};
let opt_invoice = document.createElement("option");
opt_invoice.text = INVOICE_HEAD;
dd_invoice.options.add(opt_invoice);
setRange();
let from = document.getElementById("from").value;
let until = document.getElementById("until").value;
let i = document.getElementById('dd_range').value.charAt(0); // TODO: get by index
// AA search
if (i === '1') {
for (let i = 0; i < INVOICES.length; i++) {
t = Number(INVOICES[i].split(D)[1]);
if ( t >= Number(from) && t <= Number(until)) {
opt_invoice = document.createElement("option");
opt_invoice.text = INVOICES[i];
dd_invoice.options.add(opt_invoice);
}
}
// Date search
} else if (i === '2') {
for (let i = 0; i < INVOICES.length; i++) {
t = INVOICES[i].split(D)[2];
if (t >= from && t <= until) {
opt_invoice = document.createElement("option");
opt_invoice.text = INVOICES[i];
dd_invoice.options.add(opt_invoice); //
};
};
// Name-Visit search
} else {
for (let i = 0; i < INVOICES.length; i++) {
t = INVOICES[i].split(D)[5].split('-');
if ( (t[0].includes(from) || t[1].includes(from))
&& t[2].includes(until) ) {
opt_invoice = document.createElement("option");
opt_invoice.text = INVOICES[i];
dd_invoice.options.add(opt_invoice); //
};
};
};
};
// CANCEL invoice based on MARK
function Cancel() {
// Get and check mark
let mark = document.getElementById("mark").value;
if (mark.length != 15) {
alert('Error: Invalid Mark length');
return;
};
let params = {
"mark": document.getElementById("mark").value
};
$.ajax({
url: url + "/CancelInvoice?" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("aade-user-id",user);
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key",key);
},
type: "POST",
data: "",
})
.done(function(data) {
parser = new DOMParser();
xmlDoc = parser.parseFromString(data, "text/xml");
if (typeof xmlDoc.getElementsByTagName("cancellationMark") != "undefined") {
alert("Cancel successful!");
document.getElementById("mark").value = "";
// TODO: instead, remove one line from INVOICES and populate DD
RequestTransmittedDocs();
} else {
alert("Error: " + xmlDoc.getElementsByTagName("message")[0].textContent);
};
})
.fail(function() {
alert("Request failed. Please see console for error");
});
};
// PRINT online -> an already valid APY, retreived from INVOICES
// PRINT offline -> a nonexistend APY, retreived from GUI entries
function PrintInvoice(mode) {
if (mode === 'online') {
let mark = document.getElementById("mark").value;
if (mark.length != 15) {
alert('Error: Ακυρο μήκος ΜΑΡΚ');
return;
};
for (let i = 0; i < INVOICES.length; i++) {
if (INVOICES[i].includes(mark)) {
invoice_info = INVOICES[i].split(D);
// Convert: branch Code -> City -> Address
// (works provided the BRANCHES are numbered 1,2...)
invoice_info[0] = Object.keys(BRANCHES)[invoice_info[0]-1];
patient_info = invoice_info[5].split('-');
};
};
if (typeof invoice_info == 'undefined') {
alert('Error: Δεν βρέθηκε ο ΜΑΡΚ');
return;
};
} else { // 'offline'
invoice_info = [
document.getElementById("dd_branch").value
, document.getElementById("aa").value
, document.getElementById("date").value
, document.getElementById("amount").value
]
patient_info = [
document.getElementById("name").value
, document.getElementById("address").value
, document.getElementById("reason").value
]
};
// empty Name and Address entries
if (patient_info.length == 2) {
patient_info[2] = 'ΣΥΝΤΑΓΟΓΡΑΦΗΣΗ'
}
// empty Visit entry
if (patient_info[2] === '') {
patient_info[2] = 'ΣΥΝΤΑΓΟΓΡΑΦΗΣΗ'
}
apy_html = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>ΑΠΥ Ιατρικών Υπηρεσιών</title>
<style>
.invoice-box {
max-width: 800px;
margin: auto;
padding: 30px;
border: 1px solid #eee;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.15);
font-size: 16px;
line-height: 24px;
font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;
color: #555;
}
.invoice-box table {
width: 100%%;
line-height: inherit;
text-align: left;
}
.invoice-box table td {
padding: 5px;
vertical-align: top;
}
.invoice-box table tr td:nth-child(2) {
text-align: right;
}
.invoice-box table tr.top table td {
padding-bottom: 20px;
}
.invoice-box table tr.top table td.title {
font-size: 45px;
line-height: 45px;
color: #333;
}
.invoice-box table tr.information table td {
padding-bottom: 40px;
}
.invoice-box table tr.heading td {
background: #eee;
border-bottom: 1px solid #ddd;
font-weight: bold;
}
.invoice-box table tr.details td {
padding-bottom: 20px;
}
.invoice-box table tr.item td {
border-bottom: 1px solid #eee;
}
.invoice-box table tr.item.last td {
border-bottom: none;
}
.invoice-box table tr.total td:nth-child(2) {
border-top: 2px solid #eee;
font-weight: bold;
}
@media only screen and (max-width: 600px) {
.invoice-box table tr.top table td {
width: 100%%;
display: block;
text-align: center;
}
.invoice-box table tr.information table td {
width: 100%%;
display: block;
text-align: center;
}
}
/** RTL **/
.invoice-box.rtl {
direction: rtl;
font-family: Tahoma, 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;
}
.invoice-box.rtl table {
text-align: right;
}
.invoice-box.rtl table tr td:nth-child(2) {
text-align: left;
}
</style>
</head>
<body>
<div class="invoice-box">
<table cellpadding="0" cellspacing="0">
<tr class="top">
<td colspan="2">
<table>
<tr class="heading">
<td>
ΕΥΑΓΓΕΛΟΣ Δ. ΤΣΟΥΚΑΣ<br />
Ιατρικές Υπηρεσίες Νευρολογίας<br />
ΑΦΜ: 062725970, ΔΟΥ: ΦΛΩΡΙΝΑΣ
</td>
<td>
Απόδειξη Λιανικών Συναλλαγών (ΑΠΥ)<br />
Αριθμός: ${invoice_info[1]}<br />
Ημερομηνία: ${invoice_info[2]}
</td>
</tr>
</table>
</td>
</tr>
<tr class="information">
<td colspan="2">
<table>
<tr>
<td>
Διεύθυνση:<br />
${BRANCHES[invoice_info[0]][1]}
</td>
<td>
ΠΑΡΑΛΗΠΤΗΣ:<br />
${patient_info[0]}<br />
${patient_info[1]}
</td>
</tr>
</table>
</td>
</tr>
<tr class="heading">
<td>Υπηρεσία</td>
<td>Αξία σε Ευρώ [Εξόφληση]</td>
</tr>
<tr class="item">
<td>${patient_info[2]}<br />
(χωρίς ΦΠΑ, άρθρο 22 Κώδικα)
</td>
<td>${invoice_info[3]}
</td>
</tr>
<tr class="heading">
<td></td>
<td>ΠΑΡΑΛΑΒΗ         ΕΚΔΟΣΗ      </td>
</tr>
</table>
</div>
</body>
</html>
`
var newWindow = window.open();
newWindow.document.write(apy_html);
}
// =====================================================
// Small methods
// =====================================================
// Adds mark to entry for the selected invoice
function setMark() {
document.getElementById("mark").value =
document.getElementById("dd_invoice").value.split(D)[6];
};
// Sets default or validates given range
function setRange() {
let from = document.getElementById("from").value;
let until = document.getElementById("until").value;
// TODO set default ranges
};
// Find and set max AA for specified branch
function AdjustForBranch() {
let max_aa = 0;
for (let i = 0; i < INVOICES.length; i++) {
if ( INVOICES[i].split(D)[0] === BRANCHES[document.getElementById("dd_branch").value][0] &&
Number(INVOICES[i].split(D)[1]) > max_aa ) {
max_aa = Number(INVOICES[i].split(D)[1]);
}
}
document.getElementById("aa").value = (max_aa+1).toString();
document.getElementById("address").value = document.getElementById("dd_branch").value;
}
// END OF JS ##################################
</script>
</body>
</html>