-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.php
More file actions
78 lines (57 loc) · 2.45 KB
/
new.php
File metadata and controls
78 lines (57 loc) · 2.45 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
<?php
// FI Card reader
// This particular file simply parses data posted to it. Post data from an HTML file to this one.
function init(){
parseFile();
}
function parseFile()
{
echo "Læser overførsler...<br/><br/>";
$file = $_FILES['file'];
// Loop over all lines in the files
if ($file['error'] !== 0) {
return false;
}
$fh = fopen($file['tmp_name'], 'r');
if ($fh === false) {
return false;
}
$count = 0;
$total_sum = 0;
$payment_dataz = array();
while ($line = fgets($fh))
{
if (substr($line, 0, 2) == 'FI') {
// FI Line
if($fi_parsed = parseFILine($line))
{
echo "Overførsel " . (string)($count + 1) . "<br/>";
echo 'FI nummer: ' . '+71<' . $fi_parsed['fi_number'] . "<br/>";
echo 'Beløb: ' . number_format((double)$fi_parsed['amount'], 2, ',', '.') . " kr.<br/>";
echo 'Betalingsdato: ' . $fi_parsed['payment_date'] . "<br/>";
echo 'Bank dato: ' . $fi_parsed['payment_date2'] . "<br/>";
echo '<br/>';
$total_sum = $total_sum + (double)$fi_parsed['amount'];
$count = $count + 1;
}
}
}
echo "Der var i alt " . $count . " overførsler, med et total beløb på " . number_format($total_sum, 2, ',', '.') . " kr. <br/>";
echo "Husk at tjekke om beløbet stemmer med banken!";
}
function parseFILine ($line) {
$regex = '/^(FI)(030)([0-9]{8})([0-9]{2})([0-9]{19})(.{22})([0-9]{8})([0-9]{15})(.{22})(.{2})([0-9]{9})(.)/m';
$matches = array();
if (preg_match($regex, $line, $matches)) {
if ($matches[12] !== 'N') {
return false;
}
$fi_number = substr($line, 19, 15);
$paymentdate = substr($matches[3],0, 4) . '-' . substr($matches[3], 4, 2) . '-' . substr($matches[3], 6, 2);
$paymentdate2 = substr($line,56, 4) . '-' . substr($line, 60, 2) . '-' . substr($line, 62, 2);
return array('fi_number' => $fi_number, 'amount' => $matches[8] / 100, 'payment_date' => $paymentdate, 'payment_date2' => $paymentdate2, 'note' => $line);
}
return false;
}
init();
?>