|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Year |
|
4
|
|
|
* |
|
5
|
|
|
* @package Intraface_Accounting |
|
6
|
|
|
* @author Lars Olesen |
|
7
|
|
|
* @since 1.0 |
|
8
|
|
|
* @version 1.0 |
|
9
|
|
|
*/ |
|
10
|
|
|
require_once 'Intraface/modules/accounting/Account.php'; |
|
11
|
|
|
|
|
12
|
|
|
class Year extends Intraface_Standard |
|
13
|
|
|
{ |
|
14
|
|
|
public $id; // årsid |
|
15
|
|
|
public $kernel; // object |
|
16
|
|
|
public $value; // array |
|
17
|
|
|
public $error; // error object |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Constructor |
|
21
|
|
|
* |
|
22
|
|
|
* @param object $kernel |
|
23
|
|
|
* @param integer $year_id |
|
24
|
|
|
* @param boolean $load_active used when a new year is created |
|
25
|
|
|
* |
|
26
|
|
|
* @return void |
|
|
|
|
|
|
27
|
|
|
*/ |
|
28
|
36 |
|
function __construct($kernel, $year_id = 0, $load_active = true) |
|
29
|
|
|
{ |
|
30
|
36 |
|
$this->error = new Intraface_Error; |
|
31
|
36 |
|
$this->kernel = $kernel; |
|
32
|
36 |
|
$this->id = (int)$year_id; |
|
33
|
|
|
|
|
34
|
36 |
|
if ($this->id > 0) { |
|
35
|
1 |
|
$this->load(); |
|
36
|
36 |
|
} elseif ($load_active) { |
|
37
|
36 |
|
if ($this->loadActiveyear() > 0) { |
|
38
|
19 |
|
$this->load(); |
|
39
|
19 |
|
} |
|
40
|
36 |
|
} |
|
41
|
36 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Funktion til at sætte et regnskabsår, som brugeren redigerer i. |
|
45
|
|
|
* |
|
46
|
|
|
* @return true |
|
47
|
|
|
*/ |
|
48
|
4 |
|
function setYear() |
|
49
|
|
|
{ |
|
50
|
4 |
|
if ($this->id == 0) { |
|
51
|
1 |
|
return false; |
|
52
|
|
|
} |
|
53
|
3 |
|
$this->reset(); |
|
54
|
|
|
|
|
55
|
3 |
|
$this->kernel->getSetting()->set('user', 'accounting.active_year', $this->id); |
|
56
|
|
|
|
|
57
|
3 |
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Finder det aktive år. |
|
62
|
|
|
* |
|
63
|
|
|
* @todo should be deprecated in favor of getActiveYear |
|
64
|
|
|
* |
|
65
|
|
|
* @return year / false |
|
66
|
|
|
*/ |
|
67
|
36 |
|
public function loadActiveYear() |
|
68
|
|
|
{ |
|
69
|
36 |
|
$this->id = $this->kernel->getSetting()->get('user', 'accounting.active_year'); |
|
70
|
36 |
|
return $this->id; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Finds the ative year |
|
75
|
|
|
* |
|
76
|
|
|
* @return integer |
|
77
|
|
|
*/ |
|
78
|
3 |
|
function getActiveYear() |
|
79
|
|
|
{ |
|
80
|
3 |
|
return $this->kernel->getSetting()->get('user', 'accounting.active_year'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Checks whether a year isset. |
|
85
|
|
|
* |
|
86
|
|
|
* @param boolean $redirect Set to true if a redirect should occur if no year isset |
|
87
|
|
|
* |
|
88
|
|
|
* @return boolean |
|
89
|
|
|
*/ |
|
90
|
20 |
|
function checkYear($redirect = true) |
|
91
|
|
|
{ |
|
92
|
|
|
// hvis ikke der er sat noget aktivt år, skal det sættes |
|
93
|
2 |
|
$active_year = $this->getActiveYear(); |
|
94
|
2 |
|
if (!$this->_isValid()) { |
|
95
|
20 |
|
$active_year = 0; |
|
96
|
20 |
|
} |
|
97
|
|
|
|
|
98
|
2 |
|
if (!$active_year) { |
|
99
|
1 |
|
if ($redirect) { |
|
100
|
|
|
header('Location: years.php'); |
|
101
|
|
|
exit; |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
1 |
|
return false; |
|
104
|
|
|
} |
|
105
|
1 |
|
return true; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
1 |
|
function isYearSet() |
|
109
|
|
|
{ |
|
110
|
|
|
// if no active year isset, it has to be done |
|
111
|
1 |
|
$active_year = $this->loadActiveYear(); |
|
|
|
|
|
|
112
|
1 |
|
if (!$this->_isValid()) { |
|
113
|
|
|
return false; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
1 |
|
return true; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Resets active year |
|
121
|
|
|
* |
|
122
|
|
|
* @return boolean |
|
123
|
|
|
*/ |
|
124
|
3 |
|
private function reset() |
|
125
|
|
|
{ |
|
126
|
3 |
|
$this->kernel->getSetting()->set('user', 'accounting.active_year', 0); |
|
127
|
3 |
|
return true; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/******************************************************************************* |
|
131
|
|
|
OPDATERING OG LOAD |
|
132
|
|
|
*******************************************************************************/ |
|
133
|
|
|
|
|
134
|
30 |
|
private function load() |
|
135
|
|
|
{ |
|
136
|
30 |
|
if ($this->id == 0) { |
|
137
|
|
|
$this->value['id'] = 0; |
|
138
|
|
|
return; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
$sql = "SELECT id, |
|
142
|
|
|
DATE_FORMAT(from_date, '%Y') AS year, |
|
143
|
|
|
DATE_FORMAT(from_date, '%d-%m-%Y') AS from_date_dk, |
|
144
|
|
|
DATE_FORMAT(to_date, '%d-%m-%Y') AS to_date_dk, |
|
145
|
|
|
last_year_id, from_date, to_date, locked, label, vat |
|
146
|
|
|
FROM accounting_year |
|
147
|
30 |
|
WHERE id = '" . $this->id . "' |
|
148
|
30 |
|
AND intranet_id = ".$this->kernel->intranet->get('id')." |
|
149
|
30 |
|
LIMIT 1"; |
|
150
|
|
|
|
|
151
|
30 |
|
$db = new DB_Sql; |
|
152
|
30 |
|
$db->query($sql); |
|
153
|
|
|
|
|
154
|
30 |
|
if ($db->nextRecord()) { |
|
155
|
30 |
|
$this->id = $db->f('id'); |
|
156
|
30 |
|
$this->value['id'] = $db->f('id'); |
|
157
|
30 |
|
$this->value['year'] = $db->f('year'); |
|
158
|
30 |
|
$this->value['label'] = $db->f('label'); |
|
159
|
30 |
|
$this->value['last_year_id'] = $db->f('last_year_id'); |
|
160
|
30 |
|
$this->value['from_date'] = $db->f('from_date'); |
|
161
|
30 |
|
$this->value['from_date_dk'] = $db->f('from_date_dk'); |
|
162
|
30 |
|
$this->value['to_date'] = $db->f('to_date'); |
|
163
|
30 |
|
$this->value['to_date_dk'] = $db->f('to_date_dk'); |
|
164
|
30 |
|
$this->value['locked'] = $db->f('locked'); |
|
165
|
30 |
|
$this->value['vat'] = $db->f('vat'); |
|
166
|
30 |
|
} else { |
|
167
|
19 |
|
$this->id = 0; |
|
168
|
19 |
|
$this->value['id'] = 0; |
|
169
|
|
|
} |
|
170
|
30 |
|
} |
|
171
|
|
|
|
|
172
|
30 |
|
private function validate(&$var) |
|
173
|
|
|
{ |
|
174
|
30 |
|
$validator = new Intraface_Validator($this->error); |
|
175
|
|
|
// I could not find any use of the following, so i commented it out /SJ (22-01-2007) |
|
176
|
|
|
// $validator->isNumeric($var['year'], "year", "allow_empty"); |
|
|
|
|
|
|
177
|
30 |
|
$validator->isNumeric($var['last_year_id'], "last_year_id", "allow_empty"); |
|
178
|
30 |
|
$validator->isString($var['label'], "Du skal skrive et navn til året"); |
|
179
|
30 |
|
$validator->isNumeric($var['locked'], "locked"); |
|
180
|
30 |
|
settype($var['vat'], 'integer'); |
|
181
|
30 |
|
$validator->isNumeric($var['vat'], "vat", 'allow_empty'); |
|
182
|
|
|
|
|
183
|
30 |
|
if ($this->error->isError()) { |
|
184
|
|
|
return false; |
|
185
|
|
|
} |
|
186
|
30 |
|
return true; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Updates year |
|
191
|
|
|
* |
|
192
|
|
|
* @param array $var Information about the year |
|
193
|
|
|
* |
|
194
|
|
|
* @return integer |
|
195
|
|
|
*/ |
|
196
|
30 |
|
public function save($var) |
|
197
|
|
|
{ |
|
198
|
30 |
|
$var = safeToDb($var); |
|
199
|
|
|
|
|
200
|
30 |
|
$post_date_from = new Intraface_Date($var['from_date']); |
|
201
|
30 |
|
$post_date_from->convert2db(); |
|
202
|
|
|
|
|
203
|
30 |
|
$post_date_to = new Intraface_Date($var['to_date']); |
|
204
|
30 |
|
$post_date_to->convert2db(); |
|
205
|
|
|
|
|
206
|
30 |
|
if (!isset($var['last_year_id'])) { |
|
207
|
19 |
|
$var['last_year_id'] = 0; |
|
208
|
19 |
|
} |
|
209
|
|
|
|
|
210
|
30 |
|
if (!$this->validate($var)) { |
|
211
|
|
|
return false; |
|
|
|
|
|
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
30 |
|
if ($this->id > 0) { |
|
215
|
2 |
|
$sql="UPDATE accounting_year "; |
|
216
|
2 |
|
$sql_after=" WHERE id='".$this->id."' AND intranet_id = ".$this->kernel->intranet->get('id').""; |
|
217
|
2 |
|
} else { |
|
218
|
30 |
|
$sql="INSERT INTO accounting_year "; |
|
219
|
30 |
|
$sql_after = ', date_created = NOW()'; |
|
220
|
|
|
} |
|
221
|
|
|
$sql.=" SET |
|
222
|
30 |
|
intranet_id='".$this->kernel->intranet->get('id')."', |
|
223
|
30 |
|
user_id='".$this->kernel->user->get('id')."', |
|
224
|
30 |
|
last_year_id='".$var['last_year_id']."', |
|
225
|
30 |
|
label='".$var['label']."', |
|
226
|
30 |
|
from_date='".$post_date_from->get()."', |
|
227
|
30 |
|
to_date = '".$post_date_to->get()."', |
|
228
|
30 |
|
locked='".$var['locked']."', |
|
229
|
|
|
date_changed = NOW(), |
|
230
|
30 |
|
vat = '".(int)$var['vat']."' |
|
231
|
30 |
|
$sql_after"; |
|
232
|
|
|
|
|
233
|
30 |
|
$db = new DB_Sql; |
|
234
|
30 |
|
$db->query($sql); |
|
235
|
|
|
|
|
236
|
30 |
|
if ($this->id == 0) { |
|
237
|
30 |
|
$this->id = $db->insertedId(); |
|
238
|
30 |
|
} |
|
239
|
|
|
|
|
240
|
30 |
|
$this->load(); |
|
241
|
|
|
|
|
242
|
30 |
|
return $this->id; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/**************************************************************************** |
|
246
|
|
|
VALIDERINGSFUNKTIONER |
|
247
|
|
|
****************************************************************************/ |
|
248
|
|
|
public function isValid() |
|
249
|
|
|
{ |
|
250
|
|
|
return $this->_isValid(); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Checks whether year is valid |
|
255
|
|
|
* |
|
256
|
|
|
* @return 1 = year set; 0 = year NOT set |
|
|
|
|
|
|
257
|
|
|
*/ |
|
258
|
3 |
View Code Duplication |
private function _isValid() |
|
|
|
|
|
|
259
|
|
|
{ |
|
260
|
|
|
$sql = "SELECT id FROM accounting_year |
|
261
|
3 |
|
WHERE id = ".$this->id." |
|
262
|
3 |
|
AND intranet_id = ". $this->kernel->intranet->get('id') . " AND active = 1"; |
|
263
|
|
|
|
|
264
|
3 |
|
$db = new DB_Sql; |
|
265
|
3 |
|
$db->query($sql); |
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
3 |
|
if (!$db->nextRecord()) { |
|
269
|
|
|
return false; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
3 |
|
return true; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
1 |
|
function vatAccountIsSet() |
|
276
|
|
|
{ |
|
277
|
1 |
|
if ($this->get('vat') == 0) { |
|
278
|
1 |
|
return true; // pretend it is set, when no vat on the year |
|
279
|
|
|
} |
|
280
|
|
|
if ($this->getSetting('vat_in_account_id') > 0 and $this->getSetting('vat_out_account_id') > 0 and $this->getSetting('vat_balance_account_id') > 0) { |
|
|
|
|
|
|
281
|
|
|
return true; |
|
282
|
|
|
} |
|
283
|
|
|
return false; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* Checks whether the year is open for stating |
|
288
|
|
|
* |
|
289
|
|
|
* @return boolean |
|
290
|
|
|
*/ |
|
291
|
10 |
View Code Duplication |
public function isYearOpen() |
|
|
|
|
|
|
292
|
|
|
{ |
|
293
|
10 |
|
$db = new Db_Sql; |
|
294
|
10 |
|
$db->query("SELECT locked FROM accounting_year WHERE id = " . $this->id . " AND intranet_id = ".$this->kernel->intranet->get('id')); |
|
295
|
10 |
|
if ($db->nextRecord()) { |
|
296
|
10 |
|
if ($db->f('locked') == 1) { |
|
297
|
|
|
return false; |
|
298
|
|
|
} |
|
299
|
10 |
|
} |
|
300
|
10 |
|
return true; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* is the date in the current year |
|
305
|
|
|
* |
|
306
|
|
|
* @param date $date Format: 0000-00-00 |
|
307
|
|
|
* |
|
308
|
|
|
* @return boolean |
|
309
|
|
|
*/ |
|
310
|
17 |
|
public function isDateInYear($date) |
|
311
|
|
|
{ |
|
312
|
17 |
|
if ($this->getId() == 0) { |
|
313
|
|
|
throw new Exception('Year has not been loaded yet - maybe not saved'); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
17 |
|
$date = safeToDb($date); |
|
317
|
|
|
|
|
318
|
17 |
|
$db = new Db_Sql; |
|
319
|
17 |
|
$db->query("SELECT from_date, to_date FROM accounting_year WHERE id= " . $this->id . " AND intranet_id = " . $this->kernel->intranet->get('id') . " LIMIT 1"); |
|
320
|
17 |
|
if ($db->nextRecord()) { |
|
321
|
17 |
|
if ($db->f('from_date') <= $date and $date <= $db->f('to_date')) { |
|
|
|
|
|
|
322
|
15 |
|
return true; |
|
323
|
|
|
} |
|
324
|
2 |
|
} |
|
325
|
2 |
|
return false; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* Checks whether the year is ready to use for stating |
|
330
|
|
|
* |
|
331
|
|
|
* @return boolean |
|
332
|
|
|
*/ |
|
333
|
17 |
|
public function readyForState($date = null) |
|
334
|
|
|
{ |
|
335
|
17 |
|
if ($date === null) { |
|
336
|
3 |
|
$date = date('Y-m-d'); |
|
337
|
3 |
|
} |
|
338
|
|
|
|
|
339
|
17 |
|
$return = true; |
|
340
|
|
|
|
|
341
|
17 |
|
if (!$this->get('id')) { |
|
342
|
1 |
|
$this->error->set('Der er ikke sat noget år.'); |
|
343
|
1 |
|
$return = false; |
|
344
|
17 |
|
} elseif (!$this->isDateInYear($date)) { |
|
345
|
1 |
|
$this->error->set('Datoen er ikke i det år, der er sat i regnskabsmodulet.'); |
|
346
|
1 |
|
$return = false; |
|
347
|
16 |
|
} elseif ($this->get('locked') == 1) { |
|
348
|
|
|
$this->error->set('Året er ikke åbent for bogføring.'); |
|
349
|
|
|
$return = false; |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
17 |
|
return $return; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/************************************************************************** |
|
356
|
|
|
�VRIGE METODER |
|
357
|
|
|
**************************************************************************/ |
|
358
|
|
|
|
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* Gets a list |
|
362
|
|
|
* |
|
363
|
|
|
* @return array |
|
364
|
|
|
*/ |
|
365
|
1 |
|
function getList() |
|
366
|
|
|
{ |
|
367
|
1 |
|
$gateway = new Intraface_modules_accounting_YearGateway($this->kernel); |
|
368
|
1 |
|
return $gateway->getList(); |
|
369
|
|
|
/* |
|
|
|
|
|
|
370
|
|
|
if (!is_object($this->kernel)) { |
|
371
|
|
|
throw new Exception('Du kan ikke k�re Year::getList() uden at have instatieret klassen', FATAL); |
|
372
|
|
|
} |
|
373
|
|
|
$sql = "SELECT id, label FROM accounting_year |
|
374
|
|
|
WHERE intranet_id = ".$this->kernel->intranet->get('id')." |
|
375
|
|
|
ORDER BY from_date ASC"; |
|
376
|
|
|
|
|
377
|
|
|
$db = new DB_Sql; |
|
378
|
|
|
$db->query($sql); |
|
379
|
|
|
|
|
380
|
|
|
if ($db->numRows() == 0) { |
|
381
|
|
|
return array(); |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
while ($db->nextRecord()) { |
|
385
|
|
|
$account_years[$db->f("id")]['id'] = $db->f("id"); |
|
386
|
|
|
$account_years[$db->f("id")]['label'] = $db->f("label"); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
return $account_years; |
|
390
|
|
|
*/ |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
1 |
|
function getBalanceAccounts() |
|
394
|
|
|
{ |
|
395
|
|
|
// afstemningskonti |
|
396
|
1 |
|
$balance_accounts = unserialize($this->getSetting('balance_accounts')); |
|
397
|
|
|
|
|
398
|
1 |
|
if (!is_array($balance_accounts)) { |
|
399
|
|
|
throw new Exception('Balance accounts are not an array'); |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
1 |
|
$sql_where = ""; |
|
403
|
|
|
|
|
404
|
1 |
|
if (!empty($balance_accounts) and count($balance_accounts) > 0) { |
|
|
|
|
|
|
405
|
|
|
foreach ($balance_accounts as $account) { |
|
406
|
|
|
$sql_where .= "id = " . $account . " OR "; |
|
407
|
|
|
} |
|
408
|
|
|
} |
|
409
|
|
|
// hvis der ikke er nogen balance_accounts skal den ikke v�lge nogen poster |
|
410
|
1 |
|
$sql_where .= "id=0"; |
|
411
|
|
|
|
|
412
|
1 |
|
$db = new DB_Sql; |
|
413
|
1 |
|
$db->query("SELECT id FROM accounting_account |
|
414
|
1 |
|
WHERE (".$sql_where.") |
|
415
|
1 |
|
AND intranet_id = " . $this->kernel->intranet->get('id') . " |
|
416
|
1 |
|
AND year_id = " . $this->get('id')); |
|
417
|
|
|
|
|
418
|
1 |
|
$accounts = array(); // afstemningskonti |
|
419
|
1 |
|
$i = 0; |
|
420
|
1 |
|
while ($db->nextRecord()) { |
|
421
|
|
|
$oAccount = new Account($this, $db->f('id')); |
|
422
|
|
|
$oAccount->getSaldo('stated'); |
|
423
|
|
|
$saldo = $oAccount->get('saldo'); |
|
424
|
|
|
$oAccount->getSaldo('draft'); // f�r et array |
|
425
|
|
|
|
|
426
|
|
|
$accounts[$i]['id'] = $oAccount->get('id'); |
|
427
|
|
|
$accounts[$i]['name'] = $oAccount->get('name'); |
|
428
|
|
|
$accounts[$i]['number'] = $oAccount->get('number'); |
|
429
|
|
|
$accounts[$i]['saldo_primo'] = $saldo; |
|
430
|
|
|
$accounts[$i]['saldo_draft'] = (float)$oAccount->get('saldo_draft'); |
|
431
|
|
|
$accounts[$i]['saldo_ultimo'] = $saldo + $oAccount->get('saldo_draft'); |
|
432
|
|
|
$i++; |
|
433
|
|
|
} |
|
434
|
1 |
|
return $accounts; |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
21 |
|
function setSetting($setting, $value) |
|
438
|
|
|
{ |
|
439
|
21 |
|
return $this->kernel->getSetting()->set('intranet', 'accounting.'.$setting, $value, $this->get('id')); |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
17 |
|
function getSetting($setting) |
|
443
|
|
|
{ |
|
444
|
17 |
|
return $this->kernel->getSetting()->get('intranet', 'accounting.' . $setting, $this->get('id')); |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
20 |
|
function createAccounts($type, $last_year_id = 0) |
|
448
|
|
|
{ |
|
449
|
20 |
|
if ($this->getId() == 0) { |
|
450
|
|
|
throw new Exception('Year has no id'); |
|
451
|
|
|
} |
|
452
|
|
|
|
|
453
|
20 |
|
$last_year_id = (int)$last_year_id; |
|
454
|
|
|
switch ($type) { |
|
455
|
20 |
|
case 'standard': |
|
456
|
20 |
|
$standardaccounts = array(); |
|
457
|
|
|
/* |
|
|
|
|
|
|
458
|
|
|
// HACK |
|
459
|
|
|
include(ROOT_PATH . 'intraface_modules/accounting/standardaccounts.php'); |
|
460
|
|
|
// HACK |
|
461
|
|
|
|
|
462
|
|
|
if (empty($standardaccounts)) { |
|
463
|
|
|
return 0; |
|
464
|
|
|
} |
|
465
|
|
|
*/ |
|
466
|
|
|
|
|
467
|
|
|
// $module_accounting = $this->kernel->useModule('accounting'); |
|
|
|
|
|
|
468
|
|
|
// $module_accounting->includeFile('standardaccounts.php'); |
|
|
|
|
|
|
469
|
|
|
// HACK |
|
470
|
|
|
// include($module_accounting->includeFile('standardaccounts.php')); // 'intraface_modules/accounting/standardaccounts.php'); |
|
|
|
|
|
|
471
|
|
|
// HACK |
|
472
|
|
|
|
|
473
|
20 |
|
include('Intraface/modules/accounting/standardaccounts.php'); |
|
474
|
|
|
|
|
475
|
20 |
|
if (empty($standardaccounts)) { |
|
476
|
|
|
return false; |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
20 |
|
$balance_accounts = array(); |
|
480
|
20 |
|
$buy_abroad = array(); |
|
481
|
20 |
|
$buy_eu = array(); |
|
482
|
|
|
|
|
483
|
20 |
|
foreach ($standardaccounts as $input) { |
|
484
|
20 |
|
require_once 'Intraface/modules/accounting/Account.php'; |
|
485
|
20 |
|
$account = new Account($this); |
|
486
|
20 |
|
$input['vat_percent'] = $this->kernel->getSetting()->get('intranet', 'vatpercent'); |
|
487
|
20 |
|
$id = $account->save($input); |
|
488
|
|
|
|
|
489
|
|
|
// settings |
|
490
|
20 |
|
if (!empty($input['setting'])) { |
|
491
|
20 |
|
$this->setSetting($input['setting'] . '_account_id', $id); |
|
492
|
20 |
|
} |
|
493
|
20 |
|
if (!empty($input['balance_account']) and $input['balance_account'] == 1) { |
|
|
|
|
|
|
494
|
20 |
|
$balance_accounts[] = $id; |
|
495
|
20 |
|
} |
|
496
|
20 |
|
if (!empty($input['result_account_id_start']) and $input['result_account_id_start']) { |
|
|
|
|
|
|
497
|
20 |
|
$this->setSetting('result_account_id_start', $id); |
|
498
|
20 |
|
} |
|
499
|
|
|
|
|
500
|
20 |
|
if (!empty($input['result_account_id_end']) and $input['result_account_id_end']) { |
|
|
|
|
|
|
501
|
20 |
|
$this->setSetting('result_account_id_end', $id); |
|
502
|
20 |
|
} |
|
503
|
|
|
|
|
504
|
20 |
|
if (!empty($input['balance_account_id_start']) and $input['balance_account_id_start']) { |
|
|
|
|
|
|
505
|
20 |
|
$this->setSetting('balance_account_id_start', $id); |
|
506
|
20 |
|
} |
|
507
|
20 |
|
if (!empty($input['capital_account']) and $input['capital_account']) { |
|
|
|
|
|
|
508
|
20 |
|
$this->setSetting('capital_account_id', $id); |
|
509
|
20 |
|
} |
|
510
|
20 |
|
if (!empty($input['balance_account_id_end']) and $input['balance_account_id_end']) { |
|
|
|
|
|
|
511
|
20 |
|
$this->setSetting('balance_account_id_end', $id); |
|
512
|
20 |
|
} |
|
513
|
|
|
|
|
514
|
20 |
|
if (!empty($input['buy_eu']) and $input['buy_eu'] == 1) { |
|
|
|
|
|
|
515
|
20 |
|
$buy_eu[] = $id; |
|
516
|
20 |
|
} |
|
517
|
20 |
|
if (!empty($input['buy_abroad']) and $input['buy_abroad'] == 1) { |
|
|
|
|
|
|
518
|
20 |
|
$buy_abroad[] = $id; |
|
519
|
20 |
|
} |
|
520
|
20 |
|
} |
|
521
|
|
|
|
|
522
|
20 |
|
$this->setSetting('balance_accounts', serialize($balance_accounts)); |
|
523
|
20 |
|
$this->setSetting('buy_abroad_accounts', serialize($buy_abroad)); |
|
524
|
20 |
|
$this->setSetting('buy_eu_accounts', serialize($buy_eu)); |
|
525
|
|
|
|
|
526
|
20 |
|
break; |
|
527
|
|
|
case 'transfer_from_last_year': |
|
528
|
|
|
// oprette konti |
|
529
|
|
|
if ($last_year_id == 0) { |
|
530
|
|
|
return false; |
|
531
|
|
|
} |
|
532
|
|
|
$last_year = new Year($this->kernel, $last_year_id); |
|
533
|
|
|
$account = new Account($last_year); |
|
534
|
|
|
$accounts = $account->getList(); |
|
535
|
|
|
|
|
536
|
|
|
foreach ($accounts as $a) { |
|
537
|
|
|
$old_account = new Account($last_year, $a['id']); |
|
538
|
|
|
$input = $old_account->get(); |
|
539
|
|
|
$input['created_from_id'] = $old_account->get('id'); |
|
540
|
|
|
$new_account = new Account($this); |
|
541
|
|
|
$new_account->save($input); |
|
542
|
|
|
} |
|
543
|
|
|
// transfer setttings |
|
544
|
|
|
// old account id will be connected to the new account |
|
545
|
|
|
if ($this->get('vat') > 0) { |
|
546
|
|
|
$this->transferAccountSetting($last_year, 'vat_in_account_id'); |
|
547
|
|
|
$this->transferAccountSetting($last_year, 'vat_abroad_account_id'); |
|
548
|
|
|
$this->transferAccountSetting($last_year, 'vat_out_account_id'); |
|
549
|
|
|
$this->transferAccountSetting($last_year, 'vat_balance_account_id'); |
|
550
|
|
|
$this->transferAccountSetting($last_year, 'vat_free_account_id'); |
|
551
|
|
|
$this->transferAccountSetting($last_year, 'eu_sale_account_id'); |
|
552
|
|
|
//$this->transferAccountSetting($last_year, 'eu_buy_account_id'); |
|
|
|
|
|
|
553
|
|
|
//$this->transferAccountSetting($last_year, 'abroad_buy_account_id'); |
|
|
|
|
|
|
554
|
|
|
} |
|
555
|
|
|
$this->transferAccountSetting($last_year, 'result_account_id'); |
|
556
|
|
|
$this->transferAccountSetting($last_year, 'debtor_account_id'); |
|
557
|
|
|
$this->transferAccountSetting($last_year, 'credit_account_id'); |
|
558
|
|
|
|
|
559
|
|
|
$this->transferAccountSetting($last_year, 'result_account_id_start'); |
|
560
|
|
|
$this->transferAccountSetting($last_year, 'result_account_id_end'); |
|
561
|
|
|
$this->transferAccountSetting($last_year, 'balance_account_id_start'); |
|
562
|
|
|
$this->transferAccountSetting($last_year, 'balance_account_id_end'); |
|
563
|
|
|
$this->transferAccountSetting($last_year, 'capital_account_id'); |
|
564
|
|
|
|
|
565
|
|
|
$balance_accounts = unserialize($last_year->getSetting('balance_accounts')); |
|
566
|
|
|
|
|
567
|
|
|
$db = new DB_Sql; |
|
568
|
|
|
$new_balance_accounts = array(); |
|
569
|
|
|
|
|
570
|
|
View Code Duplication |
if (is_array($balance_accounts)) { |
|
571
|
|
|
foreach ($balance_accounts as $key => $id) { |
|
572
|
|
|
$db->query("SELECT id FROM accounting_account WHERE year_id = ".$this->get('id')." AND intranet_id = ".$this->kernel->intranet->get('id')." AND created_from_id = " . (int)$id); |
|
573
|
|
|
while ($db->nextRecord()) { |
|
574
|
|
|
$new_balance_accounts[] = $db->f('id'); |
|
575
|
|
|
} |
|
576
|
|
|
} |
|
577
|
|
|
} |
|
578
|
|
|
$this->setSetting('balance_accounts', serialize($new_balance_accounts)); |
|
579
|
|
|
|
|
580
|
|
|
$buy_eu_accounts = unserialize($last_year->getSetting('buy_eu_accounts')); |
|
581
|
|
|
|
|
582
|
|
|
$db = new DB_Sql; |
|
583
|
|
|
$new_buy_eu_accounts = array(); |
|
584
|
|
|
|
|
585
|
|
View Code Duplication |
if (is_array($buy_eu_accounts)) { |
|
586
|
|
|
foreach ($buy_eu_accounts as $key => $id) { |
|
587
|
|
|
$db->query("SELECT id FROM accounting_account WHERE year_id = ".$this->get('id')." AND intranet_id = ".$this->kernel->intranet->get('id')." AND created_from_id = " . (int)$id); |
|
588
|
|
|
while ($db->nextRecord()) { |
|
589
|
|
|
$new_buy_eu_accounts[] = $db->f('id'); |
|
590
|
|
|
} |
|
591
|
|
|
} |
|
592
|
|
|
} |
|
593
|
|
|
$this->setSetting('buy_eu_accounts', serialize($new_buy_eu_accounts)); |
|
594
|
|
|
|
|
595
|
|
|
$buy_abroad_accounts = unserialize($last_year->getSetting('buy_abroad_accounts')); |
|
596
|
|
|
|
|
597
|
|
|
$db = new DB_Sql; |
|
598
|
|
|
$new_buy_abroad_accounts = array(); |
|
599
|
|
|
|
|
600
|
|
View Code Duplication |
if (is_array($buy_abroad_accounts)) { |
|
601
|
|
|
foreach ($buy_abroad_accounts as $key => $id) { |
|
602
|
|
|
$db->query("SELECT id FROM accounting_account WHERE year_id = ".$this->get('id')." AND intranet_id = ".$this->kernel->intranet->get('id')." AND created_from_id = " . (int)$id); |
|
603
|
|
|
while ($db->nextRecord()) { |
|
604
|
|
|
$new_buy_abroad_accounts[] = $db->f('id'); |
|
605
|
|
|
} |
|
606
|
|
|
} |
|
607
|
|
|
} |
|
608
|
|
|
$this->setSetting('buy_abroad_accounts', serialize($new_buy_abroad_accounts)); |
|
609
|
|
|
|
|
610
|
|
|
|
|
611
|
|
|
break; |
|
612
|
|
|
default: |
|
613
|
|
|
throw new Exception('A method to create the accounts must be chosen'); |
|
614
|
|
|
break; |
|
|
|
|
|
|
615
|
|
|
} |
|
616
|
20 |
|
return true; |
|
617
|
|
|
} |
|
618
|
|
|
|
|
619
|
1 |
|
function setSettings($input) |
|
620
|
|
|
{ |
|
621
|
1 |
|
if ($this->get('vat') > 0) { |
|
622
|
|
|
if (empty($input['vat_in_account_id'])) { |
|
623
|
|
|
$input['vat_in_account_id'] = 0; |
|
624
|
|
|
} |
|
625
|
|
|
$this->setSetting('vat_in_account_id', (int)$input['vat_in_account_id']); |
|
626
|
|
|
|
|
627
|
|
|
if (empty($input['vat_out_account_id'])) { |
|
628
|
|
|
$input['vat_out_account_id'] = 0; |
|
629
|
|
|
} |
|
630
|
|
|
$this->setSetting('vat_out_account_id', (int)$input['vat_out_account_id']); |
|
631
|
|
|
|
|
632
|
|
|
if (empty($input['vat_abroad_account_id'])) { |
|
633
|
|
|
$input['vat_abroad_account_id'] = 0; |
|
634
|
|
|
} |
|
635
|
|
|
$this->setSetting('vat_abroad_account_id', (int)$input['vat_abroad_account_id']); |
|
636
|
|
|
|
|
637
|
|
|
if (empty($input['vat_balance_account_id'])) { |
|
638
|
|
|
$input['vat_balance_account_id'] = 0; |
|
639
|
|
|
} |
|
640
|
|
|
$this->setSetting('vat_balance_account_id', (int)$input['vat_balance_account_id']); |
|
641
|
|
|
|
|
642
|
|
|
if (empty($input['vat_free_account_id'])) { |
|
643
|
|
|
$input['vat_free_account_id'] = 0; |
|
644
|
|
|
} |
|
645
|
|
|
$this->setSetting('vat_free_account_id', (int)$input['vat_free_account_id']); |
|
646
|
|
|
|
|
647
|
|
|
if (empty($input['eu_sale_account_id'])) { |
|
648
|
|
|
$input['eu_sale_account_id'] = 0; |
|
649
|
|
|
} |
|
650
|
|
|
$this->setSetting('eu_sale_account_id', (int)$input['eu_sale_account_id']); |
|
651
|
|
|
//$this->setSetting('eu_buy_account_id', (int)$input['eu_buy_account_id']); |
|
|
|
|
|
|
652
|
|
|
//$this->setSetting('abroad_buy_account_id', (int)$input['abroad_buy_account_id']); |
|
|
|
|
|
|
653
|
|
|
} |
|
654
|
1 |
|
if (empty($input['result_account_id'])) { |
|
655
|
1 |
|
$input['result_account_id'] = 0; |
|
656
|
1 |
|
} |
|
657
|
1 |
|
$this->setSetting('result_account_id', (int)$input['result_account_id']); |
|
658
|
|
|
|
|
659
|
1 |
|
if (empty($input['debtor_account_id'])) { |
|
660
|
1 |
|
$input['debtor_account_id'] = 0; |
|
661
|
1 |
|
} |
|
662
|
1 |
|
$this->setSetting('debtor_account_id', (int)$input['debtor_account_id']); |
|
663
|
|
|
|
|
664
|
1 |
|
if (empty($input['credit_account_id'])) { |
|
665
|
1 |
|
$input['credit_account_id'] = 0; |
|
666
|
1 |
|
} |
|
667
|
1 |
|
$this->setSetting('credit_account_id', (int)$input['credit_account_id']); |
|
668
|
|
|
|
|
669
|
1 |
|
if (empty($input['balance_accounts'])) { |
|
670
|
1 |
|
$input['balance_accounts'] = array(); |
|
671
|
1 |
|
} |
|
672
|
1 |
|
$this->setSetting('balance_accounts', serialize($input['balance_accounts'])); |
|
673
|
|
|
|
|
674
|
1 |
|
if (empty($input['buy_abroad_accounts'])) { |
|
675
|
1 |
|
$input['buy_abroad_accounts'] = array(); |
|
676
|
1 |
|
} |
|
677
|
1 |
|
$this->setSetting('buy_abroad_accounts', serialize($input['buy_abroad_accounts'])); |
|
678
|
|
|
|
|
679
|
1 |
|
if (empty($input['buy_eu_accounts'])) { |
|
680
|
1 |
|
$input['buy_eu_accounts'] = array(); |
|
681
|
1 |
|
} |
|
682
|
1 |
|
$this->setSetting('buy_eu_accounts', serialize($input['buy_eu_accounts'])); |
|
683
|
|
|
|
|
684
|
|
|
|
|
685
|
1 |
|
if (empty($input['result_account_id_start'])) { |
|
686
|
1 |
|
$input['result_account_id_start'] = 0; |
|
687
|
1 |
|
} |
|
688
|
1 |
|
$this->setSetting('result_account_id_start', $input['result_account_id_start']); |
|
689
|
|
|
|
|
690
|
1 |
|
if (empty($input['result_account_id_end'])) { |
|
691
|
1 |
|
$input['result_account_id_end'] = 0; |
|
692
|
1 |
|
} |
|
693
|
1 |
|
$this->setSetting('result_account_id_end', $input['result_account_id_end']); |
|
694
|
|
|
|
|
695
|
1 |
|
if (empty($input['balance_account_id_start'])) { |
|
696
|
1 |
|
$input['balance_account_id_start'] = 0; |
|
697
|
1 |
|
} |
|
698
|
1 |
|
$this->setSetting('balance_account_id_start', $input['balance_account_id_start']); |
|
699
|
|
|
|
|
700
|
1 |
|
if (empty($input['balance_account_id_end'])) { |
|
701
|
1 |
|
$input['balance_account_id_end'] = 0; |
|
702
|
1 |
|
} |
|
703
|
1 |
|
$this->setSetting('balance_account_id_end', $input['balance_account_id_end']); |
|
704
|
|
|
|
|
705
|
1 |
|
if (empty($input['capital_account_id'])) { |
|
706
|
1 |
|
$input['capital_account_id'] = 0; |
|
707
|
1 |
|
} |
|
708
|
1 |
|
$this->setSetting('capital_account_id', $input['capital_account_id']); |
|
709
|
|
|
|
|
710
|
1 |
|
return true; |
|
711
|
|
|
} |
|
712
|
|
|
|
|
713
|
1 |
|
function getSettings() |
|
714
|
|
|
{ |
|
715
|
1 |
|
if ($this->get('vat') > 0) { |
|
716
|
|
|
$setting['vat_in_account_id'] = $this->getSetting('vat_in_account_id'); |
|
|
|
|
|
|
717
|
|
|
$setting['vat_out_account_id'] = $this->getSetting('vat_out_account_id'); |
|
718
|
|
|
$setting['vat_abroad_account_id'] = $this->getSetting('vat_abroad_account_id'); |
|
719
|
|
|
$setting['vat_balance_account_id'] = $this->getSetting('vat_balance_account_id'); |
|
720
|
|
|
$setting['vat_free_account_id'] = $this->getSetting('vat_free_account_id'); |
|
721
|
|
|
$setting['eu_sale_account_id'] = $this->getSetting('eu_sale_account_id'); |
|
722
|
|
|
//$setting['eu_buy_account_id'] = $this->getSetting('eu_buy_account_id'); |
|
|
|
|
|
|
723
|
|
|
//$setting['abroad_buy_account_id'] = $this->getSetting('abroad_buy_account_id'); |
|
|
|
|
|
|
724
|
|
|
} |
|
725
|
1 |
|
$setting['result_account_id'] = $this->getSetting('result_account_id'); |
|
|
|
|
|
|
726
|
1 |
|
$setting['debtor_account_id'] = $this->getSetting('debtor_account_id'); |
|
727
|
1 |
|
$setting['credit_account_id'] = $this->getSetting('credit_account_id'); |
|
728
|
1 |
|
$setting['balance_accounts'] = unserialize($this->getSetting('balance_accounts')); |
|
729
|
1 |
|
$setting['buy_eu_accounts'] = unserialize($this->getSetting('buy_eu_accounts')); |
|
730
|
1 |
|
$setting['buy_abroad_accounts'] = unserialize($this->getSetting('buy_abroad_accounts')); |
|
731
|
|
|
|
|
732
|
1 |
|
$setting['result_account_id_start'] = $this->getSetting('result_account_id_start'); |
|
733
|
1 |
|
$setting['result_account_id_end'] = $this->getSetting('result_account_id_end'); |
|
734
|
1 |
|
$setting['balance_account_id_start'] = $this->getSetting('balance_account_id_start'); |
|
735
|
1 |
|
$setting['balance_account_id_end'] = $this->getSetting('balance_account_id_end'); |
|
736
|
|
|
|
|
737
|
1 |
|
$setting['capital_account_id'] = $this->getSetting('capital_account_id'); |
|
738
|
|
|
|
|
739
|
1 |
|
return $setting; |
|
740
|
|
|
} |
|
741
|
|
|
|
|
742
|
|
|
/** |
|
743
|
|
|
* @param $from->year (object) |
|
744
|
|
|
* @param $setting (string) |
|
745
|
|
|
*/ |
|
746
|
|
|
function transferAccountSetting($from_year, $setting) |
|
747
|
|
|
{ |
|
748
|
|
|
$account_id = $from_year->getSetting($setting); |
|
749
|
|
|
$db = new DB_Sql; |
|
750
|
|
|
$db->query("SELECT id FROM accounting_account WHERE year_id = ".$this->get('id')." AND intranet_id = ".$this->kernel->intranet->get('id')." AND created_from_id = " . $account_id); |
|
751
|
|
|
if ($db->nextRecord()) { |
|
752
|
|
|
$this->setSetting($setting, $db->f('id')); |
|
753
|
|
|
} |
|
754
|
|
|
} |
|
755
|
|
|
|
|
756
|
1 |
|
function isSettingsSet() |
|
757
|
|
|
{ |
|
758
|
1 |
|
if (!$this->getSetting('result_account_id_start') or !$this->getSetting('result_account_id_end') or !$this->getSetting('balance_account_id_start') or !$this->getSetting('balance_account_id_end') or !$this->getSetting('capital_account_id')) { |
|
|
|
|
|
|
759
|
1 |
|
return false; |
|
760
|
|
|
} |
|
761
|
|
|
return true; |
|
762
|
|
|
} |
|
763
|
|
|
|
|
764
|
|
|
/** |
|
765
|
|
|
* |
|
766
|
|
|
*/ |
|
767
|
1 |
|
function isBalanced() |
|
768
|
|
|
{ |
|
769
|
1 |
|
$this->value['year_saldo'] = 0; |
|
770
|
|
|
|
|
771
|
1 |
|
$db = new DB_Sql; |
|
772
|
1 |
|
$db2 = new Db_Sql; |
|
|
|
|
|
|
773
|
|
|
|
|
774
|
1 |
|
$db->query("SELECT distinct(account.id) |
|
775
|
|
|
FROM accounting_account account |
|
776
|
|
|
LEFT JOIN accounting_post post |
|
777
|
|
|
ON account.id = post.account_id |
|
778
|
|
|
WHERE |
|
779
|
1 |
|
account.intranet_id = ".$this->kernel->intranet->get('id')." |
|
780
|
|
|
AND account.active = 1 |
|
781
|
1 |
|
AND account.year_id = ".$this->get('id')." |
|
782
|
1 |
|
ORDER BY account.number ASC"); |
|
783
|
1 |
|
$i = 0; |
|
784
|
1 |
View Code Duplication |
while ($db->nextRecord()) { |
|
785
|
|
|
$account = new Account($this, $db->f('id')); |
|
786
|
|
|
|
|
787
|
|
|
# ikke sum konti |
|
788
|
|
|
if ($account->get('type_key') == array_search('sum', $account->types)) { |
|
789
|
|
|
continue; |
|
790
|
|
|
} |
|
791
|
|
|
|
|
792
|
|
|
$account->getSaldo(); |
|
793
|
|
|
|
|
794
|
|
|
$i++; |
|
795
|
|
|
} |
|
796
|
|
|
|
|
797
|
|
|
// HACK midlertidigt hack round() indtil alle beløb er integers i stedet for floats |
|
798
|
1 |
|
if (round($this->value['year_saldo']) == 0) { |
|
799
|
1 |
|
return true; |
|
800
|
|
|
} else { |
|
801
|
|
|
return false; |
|
802
|
|
|
} |
|
803
|
|
|
} |
|
804
|
|
|
|
|
805
|
|
|
/************************************************************************** |
|
806
|
|
|
* VALIDATE FUNCTIONS - IKKE EGENTLIG ÅRSRELATEREDE |
|
807
|
|
|
**************************************************************************/ |
|
808
|
|
|
|
|
809
|
|
|
/** |
|
810
|
|
|
* Bruges i momsafregning og Årsafslutning |
|
811
|
|
|
* |
|
812
|
|
|
* @return boolean |
|
813
|
|
|
*/ |
|
814
|
|
|
function isStated($type, $date_start, $date_end) |
|
815
|
|
|
{ |
|
816
|
|
|
if (!$this->kernel->user->hasModuleAccess('debtor')) { |
|
817
|
|
|
return true; |
|
818
|
|
|
} |
|
819
|
|
|
|
|
820
|
|
|
require_once 'Intraface/modules/debtor/Debtor.php'; |
|
821
|
|
|
$types = Debtor::getDebtorTypes(); |
|
822
|
|
|
$type_key = array_search($type, $types); |
|
823
|
|
|
if (empty($type_key)) { |
|
824
|
|
|
throw new Exception('Ugyldig type'); |
|
825
|
|
|
} |
|
826
|
|
|
$db = new DB_Sql; |
|
827
|
|
|
$sql = "SELECT id FROM debtor |
|
828
|
|
|
WHERE type= " . $type_key . " |
|
829
|
|
|
AND intranet_id = " .$this->kernel->intranet->get('id') . " |
|
830
|
|
|
AND (this_date BETWEEN '" . $date_start . "' AND '" .$date_end . "') |
|
831
|
|
|
AND voucher_id = 0 |
|
832
|
|
|
AND active = 1"; |
|
833
|
|
|
$db->query($sql); |
|
834
|
|
|
if ($db->numRows() == 0) { |
|
835
|
|
|
return true; |
|
836
|
|
|
} |
|
837
|
|
|
return false; |
|
838
|
|
|
} |
|
839
|
|
|
|
|
840
|
|
|
function isPaymentsStated($date_start, $date_end) |
|
841
|
|
|
{ |
|
842
|
|
|
$db = new DB_Sql; |
|
843
|
|
|
$sql = "SELECT id FROM invoice_payment |
|
844
|
|
|
WHERE intranet_id = " .$this->kernel->intranet->get('id') . " |
|
845
|
|
|
AND (payment_date BETWEEN '" . $date_start . "' AND '" .$date_end . "') |
|
846
|
|
|
AND voucher_id = 0"; |
|
847
|
|
|
$db->query($sql); |
|
848
|
|
|
if ($db->numRows() == 0) { |
|
849
|
|
|
return true; |
|
850
|
|
|
} |
|
851
|
|
|
return false; |
|
852
|
|
|
} |
|
853
|
|
|
|
|
854
|
|
|
function isProcurementsStated($date_start, $date_end) |
|
855
|
|
|
{ |
|
856
|
|
|
$db = new DB_Sql; |
|
857
|
|
|
$sql = "SELECT id FROM procurement |
|
858
|
|
|
WHERE intranet_id = " .$this->kernel->intranet->get('id') . " |
|
859
|
|
|
AND (invoice_date BETWEEN '" . $date_start . "' AND '" .$date_end . "') |
|
860
|
|
|
AND voucher_id = 0 |
|
861
|
|
|
AND active = 1"; |
|
862
|
|
|
$db->query($sql); |
|
863
|
|
|
if ($db->numRows() == 0) { |
|
864
|
|
|
return true; |
|
865
|
|
|
} |
|
866
|
|
|
return false; |
|
867
|
|
|
} |
|
868
|
|
|
|
|
869
|
|
|
function lock() |
|
870
|
|
|
{ |
|
871
|
|
|
$db = new DB_Sql; |
|
872
|
|
|
$db->query("UPDATE accounting_year SET locked = 1 WHERE id = " . $this->id); |
|
873
|
|
|
return true; |
|
874
|
|
|
} |
|
875
|
|
|
|
|
876
|
21 |
|
public function getId() |
|
877
|
|
|
{ |
|
878
|
21 |
|
return $this->get('id'); |
|
879
|
|
|
} |
|
880
|
|
|
} |
|
881
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.