-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathabstract_report.php
233 lines (220 loc) · 7.56 KB
/
abstract_report.php
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
<?php
/**
* Reports base class
*
* PHP version 8
*
* Copyright (C) Ere Maijala 2010-2021
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category MLInvoice
* @package MLInvoice\Reports
* @author Ere Maijala <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://labs.fi/mlinvoice.eng.php
*/
require_once 'sqlfuncs.php';
require_once 'translator.php';
require_once 'pdf.php';
/**
* Reports base class
*
* @category MLInvoice
* @package MLInvoice\Reports
* @author Ere Maijala <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://labs.fi/mlinvoice.eng.php
*/
abstract class AbstractReport
{
protected $pdf = null;
/**
* Create the report form
*
* @return void
*/
abstract public function createReport();
/**
* Create a limit query
*
* @return array
*/
protected function createLimitQuery()
{
$strQuery = '';
$arrParams = [];
$intBaseId = getPostOrQuery('base', false);
if ($intBaseId) {
$strQuery .= ' AND i.base_id = ?';
$arrParams[] = $intBaseId;
}
$intCompanyId = getPostOrQuery('company', false);
if ($intCompanyId) {
$strQuery .= ' AND i.company_id = ?';
$arrParams[] = $intCompanyId;
}
$dateRange = explode(' - ', getPostOrQuery('date', ''));
$startDate = $dateRange[0];
$endDate = $dateRange[1] ?? $startDate;
if ($startDate) {
$strQuery .= ' AND i.invoice_date >= ?';
$arrParams[] = dateConvDate2DBDate($startDate);
}
if ($endDate) {
$strQuery .= ' AND i.invoice_date <= ?';
$arrParams[] = dateConvDate2DBDate($endDate);
}
if ($tags = getPostOrQuery('tags')) {
$tagsQuery = [];
foreach (explode(',', $tags) as $tag) {
$tag = trim($tag);
$tagsQuery[] = <<<EOT
c.id IN (
SELECT ctl.company_id FROM {prefix}company_tag_link ctl WHERE ctl.tag_id=(
SELECT ct.id FROM {prefix}company_tag ct WHERE ct.tag=?
)
)
EOT;
$arrParams[] = $tag;
}
$strQuery .= ' AND (' . implode(' OR ', $tagsQuery) . ')';
}
return [$strQuery, $arrParams];
}
/**
* Get a string with the selected parameters
*
* @param bool $html Whether to return the parameters as HTML
*
* @return string
*/
protected function getParamsStr($html)
{
$mappings = [
'date' => ['name' => 'InvoiceDateInterval'],
'accounting_date' => ['name' => 'DateInterval'],
'row_date' => ['name' => 'InvoiceRowDateInterval'],
'payment_date' => ['name' => 'PaymentDateInterval'],
'tags' => ['name' => 'Tags'],
'base' => [
'name' => 'Biller',
'sql' => 'SELECT name as v FROM {prefix}base WHERE id = ?'
],
'company' => [
'name' => 'Client',
'sql' => 'SELECT company_name as v FROM {prefix}company WHERE id = ?'
],
'product' => [
'name' => 'Product',
'sql' => 'SELECT product_name as v FROM {prefix}product WHERE id = ?'
],
'row_types' => [
'name' => 'InvoiceRowTypes',
'values' => [
'all' => 'PrintInvoiceRowTypeAll',
'normal' => 'PrintInvoiceRowTypeNormal',
'reminder' => 'PrintInvoiceRowTypeReminder'
]
],
'grouping' => [
'name' => 'PrintGrouping',
'values' => [
'state' => 'PrintGroupingState',
'month' => 'PrintGroupingMonth',
'client' => 'PrintGroupingClient',
'vat' => 'PrintGroupingVAT',
'product' => 'PrintGroupingProduct'
]
],
];
$params = [];
foreach (array_merge($_GET, $_POST) as $key => $value) {
if (empty($value)
|| in_array($key, ['func', 'form', 'report', 'format', 'fields'])
|| strncmp($key, 'stateid_', 8) == 0
) {
continue;
}
if (!isset($mappings[$key])) {
$params[] = "$key: $value";
continue;
}
$mapping = $mappings[$key];
$param = Translator::translate($mapping['name']) . ': ';
if (isset($mapping['values'])) {
$param .= isset($mapping['values'][$value])
? Translator::translate($mapping['values'][$value]) : $value;
} elseif (isset($mapping['sql'])) {
$rows = dbParamQuery($mapping['sql'], [$value]);
$param .= $rows ? $rows[0]['v'] : '';
} else {
$param .= $value;
}
$params[] = $param;
}
$res = dbQueryCheck(
'SELECT id, name FROM {prefix}invoice_state WHERE deleted=0'
. ' ORDER BY order_no'
);
$states = [];
while ($row = mysqli_fetch_assoc($res)) {
$stateId = $row['id'];
if (getPostOrQuery("stateid_$stateId", false)) {
$states[] = Translator::translate($row['name'] ?? '-');
}
}
if ($states) {
$params[] = Translator::translate('PrintReportStates') . ': '
. implode(', ', $states);
}
return implode($html ? '<br/>' : "\n", $params);
}
/**
* Add invoice states to the form
*
* @return void
*/
protected function addInvoiceStateSelection()
{
?>
<div class="selection-list invoice-states">
<div class="medium_label"><?php echo Translator::translate('PrintReportStates')?></div>
<?php
$strQuery = 'SELECT id, name, invoice_offer FROM {prefix}invoice_state WHERE deleted=0'
. ' ORDER BY order_no';
$intRes = dbQueryCheck($strQuery);
$first = true;
while ($row = mysqli_fetch_assoc($intRes)) {
$intStateId = $row['id'];
$strStateName = Translator::translate($row['name'] ?? '-');
$strChecked = getPostOrQuery("stateid_$intStateId", $row['invoice_offer'] ? false : true) ? ' checked' : '';
if (!$first) {
echo " <div class=\"medium_label\"></div>\n";
}
$first = false;
?>
<div class="field">
<label>
<input type="checkbox" id="state-<?php echo $intStateId?>" name="stateid_<?php echo $intStateId?>" value="1"<?php echo $strChecked?>>
<?php echo htmlspecialchars($strStateName)?>
</label>
</div>
<?php
}
?>
</div>
<?php
}
}