forked from aaronpk/checks
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
112 lines (90 loc) · 3.52 KB
/
index.php
File metadata and controls
112 lines (90 loc) · 3.52 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
<?php
date_default_timezone_set('UTC');
include("lib/can-full-size.php");
$CHK = new CheckGenerator;
$defaultFileName = isset($_GET['config'])
? 'configs/accounts/' . $_GET['config']
: 'configs/accounts/config.json';
$overridesFileName = isset($_GET['overrides'])
? 'configs/overrides/' . $_GET['overrides']
: 'configs/overrides/sample.json';
// Ensure files exist before reading
if (!file_exists($defaultFileName)) {
die("Error: Default file '$defaultFileName' not found.");
}
if (!file_exists($overridesFileName)) {
die("Error: Overrides file '$overridesFileName' not found.");
}
$defaultCheckData = json_decode(file_get_contents($defaultFileName), true);
$checksData = json_decode(file_get_contents($overridesFileName), true);
foreach ($checksData as $customData) {
$check = new Check($customData, $defaultCheckData);
$CHK->AddCheck($check->getAll());
}
if (isset($_SERVER['REMOTE_ADDR'])) {
header('Content-Type: application/octet-stream', false);
header('Content-Type: application/pdf', false);
$CHK->PrintChecks($defaultCheckData);
} else {
ob_start();
$CHK->PrintChecks($defaultCheckData);
$pdf = ob_get_clean();
file_put_contents('checks.pdf', $pdf);
echo "Saved to file: checks.pdf\n";
}
/**
* Class Check
*/
class Check
{
private $checkData;
private $logoMap;
private $logoSizeMap;
private $micrMap;
public function __construct(array $data, array $defaultData = [])
{
$logoConfig = json_decode(file_get_contents('configs/banks.json'), true);
$this->logoMap = $logoConfig['logoMap'] ?? [];
$this->logoSizeMap = $logoConfig['logoSize'] ?? [];
$this->micrMap = $logoConfig['micr_spacing'] ?? [];
$this->checkData = array_merge($defaultData, $data);
$this->setBankInfo();
}
public function set(string $key, $value): void
{
$this->checkData[$key] = $value;
}
public function get(string $key)
{
return $this->checkData[$key] ?? null;
}
public function getAll(): array
{
return $this->checkData;
}
private function setBankInfo(): void
{
$instNumber = $this->checkData['inst_number'] ?? null;
error_log('Setting bank info for instNumber: ' . var_export($instNumber, true));
$this->checkData['micr_spacing'] = $this->micrMap[$this->checkData['inst_number']] ?? 3;
if ($instNumber === null) {
error_log("Error: inst_number is not set in checkData!");
return;
}
$custom_logo = isset($this->logoSizeMap[$instNumber]) ? $this->logoSizeMap[$instNumber] : null;
error_log("Setting logo: " . var_export($instNumber, true) .
" custom_logo: " . var_export($custom_logo, true));
if ($instNumber === '010' && stripos($this->checkData['bank_1'], 'simplii') !== false) {
error_log("Simplii detected");
$this->checkData['bank_logo'] = $this->logoMap['simplii'] ?? "";
$this->checkData['bank_logo_size'] = $this->logoSizeMap['simplii'] ?? null;
} elseif ($custom_logo !== null) {
$this->checkData['bank_logo'] = $this->logoMap[$instNumber] ?? "";
$this->checkData['bank_logo_size'] = $custom_logo;
error_log("Bank logo size: " . var_export($this->checkData['bank_logo_size'], true));
} else {
$this->checkData['bank_logo'] = $this->logoMap[$instNumber] ?? "";
error_log("Warning: No custom logo found for instNumber: " . var_export($instNumber, true));
}
}
}