-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathficard.php
More file actions
74 lines (57 loc) · 2.4 KB
/
ficard.php
File metadata and controls
74 lines (57 loc) · 2.4 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
<?php
// FI Card reader
// Opens all files in "fifiles" folder and iterates over them - calling the "parseFile" function with the contents of all files
// Call this function to get started
function init(){
echo 'Starting FI reader...<br/><br/>';
$files = scandir("fifiles");
$array = array();
foreach($files as $file)
{
if(!is_dir($dir.$file.'/')){
echo "Iterating over file '" . $file . "'...<br/>";
$file_contents = file_get_contents ("fifiles/" . $file, 'r');
parseFile($file_contents);
echo "<br/>";
}
}
echo 'FI reader finished.';
}
function parseFile($file_contents)
{
echo "Parsing file...<br/><br/>";
foreach(preg_split("/((\r?\n)|(\r\n?))/", $file_contents) as $line)
{
if (substr($line, 0, 2) == 'FI') {
// FI Line
if($fi_parsed = parseFILine($line))
{
echo "---- New line ----" . "<br/>";
echo 'FI number: ' . $fi_parsed['fi_number'] . "<br/>";
echo 'Amount: ' . $fi_parsed['amount'] . "<br/>";
echo 'Payment date:' . $fi_parsed['payment_date'] . "<br/>";
echo 'Bank date: ' . $fi_parsed['payment_date2'] . "<br/>";
echo 'Note: ' . $fi_parsed['note'] . "<br/>";
echo "---- Line end ----" . "<br/>";
echo '<br/>';
}
}
}
}
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') {
// Tilbagef¿rsel er ikke N
return false;
}
$fi_number = substr($matches[5], 0, -1);
$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' => (int)$fi_number, 'amount' => $matches[8] / 100, 'payment_date' => $paymentdate, 'payment_date2' => $paymentdate2, 'note' => $line);
}
return false;
}
init();
?>