|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) 2011-2019 Alexandre Spangaro <[email protected]> |
|
3
|
|
|
* Copyright (C) 2014 Juanjo Menent <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU General Public License as published by |
|
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
8
|
|
|
* (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU General Public License |
|
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* \file htdocs/salaries/class/paymentsalary.class.php |
|
21
|
|
|
* \ingroup salaries |
|
22
|
|
|
* \brief Class for salaries module payment |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
// Put here all includes required by your class file |
|
26
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class to manage salary payments |
|
31
|
|
|
*/ |
|
32
|
|
|
class PaymentSalary extends CommonObject |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var string ID to identify managed object |
|
36
|
|
|
*/ |
|
37
|
|
|
public $element = 'payment_salary'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string Name of table without prefix where object is stored |
|
41
|
|
|
*/ |
|
42
|
|
|
public $table_element = 'payment_salary'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png |
|
46
|
|
|
*/ |
|
47
|
|
|
public $picto = 'payment'; |
|
48
|
|
|
|
|
49
|
|
|
public $tms; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var int User ID |
|
53
|
|
|
*/ |
|
54
|
|
|
public $fk_user; |
|
55
|
|
|
|
|
56
|
|
|
public $datep; |
|
57
|
|
|
public $datev; |
|
58
|
|
|
public $amount; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var int ID |
|
62
|
|
|
*/ |
|
63
|
|
|
public $fk_project; |
|
64
|
|
|
|
|
65
|
|
|
public $type_payment; |
|
66
|
|
|
public $num_payment; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @var string salary payments label |
|
70
|
|
|
*/ |
|
71
|
|
|
public $label; |
|
72
|
|
|
|
|
73
|
|
|
public $datesp; |
|
74
|
|
|
public $dateep; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @var int ID |
|
78
|
|
|
*/ |
|
79
|
|
|
public $fk_bank; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @var int ID |
|
83
|
|
|
*/ |
|
84
|
|
|
public $fk_user_author; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @var int ID |
|
88
|
|
|
*/ |
|
89
|
|
|
public $fk_user_modif; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. |
|
93
|
|
|
*/ |
|
94
|
|
|
public $fields = array(); |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Constructor |
|
99
|
|
|
* |
|
100
|
|
|
* @param DoliDB $db Database handler |
|
101
|
|
|
*/ |
|
102
|
|
|
public function __construct($db) |
|
103
|
|
|
{ |
|
104
|
|
|
$this->db = $db; |
|
105
|
|
|
$this->element = 'payment_salary'; |
|
106
|
|
|
$this->table_element = 'payment_salary'; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Update database |
|
111
|
|
|
* |
|
112
|
|
|
* @param User $user User that modify |
|
113
|
|
|
* @param int $notrigger 0=no, 1=yes (no update trigger) |
|
114
|
|
|
* @return int <0 if KO, >0 if OK |
|
115
|
|
|
*/ |
|
116
|
|
|
public function update($user = null, $notrigger = 0) |
|
117
|
|
|
{ |
|
118
|
|
|
global $conf, $langs; |
|
119
|
|
|
|
|
120
|
|
|
$error = 0; |
|
121
|
|
|
|
|
122
|
|
|
// Clean parameters |
|
123
|
|
|
$this->amount = trim($this->amount); |
|
124
|
|
|
$this->label = trim($this->label); |
|
125
|
|
|
$this->note = trim($this->note); |
|
126
|
|
|
|
|
127
|
|
|
// Check parameters |
|
128
|
|
|
if (empty($this->fk_user) || $this->fk_user < 0) { |
|
129
|
|
|
$this->error = 'ErrorBadParameter'; |
|
130
|
|
|
return -1; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
$this->db->begin(); |
|
134
|
|
|
|
|
135
|
|
|
// Update request |
|
136
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET"; |
|
137
|
|
|
|
|
138
|
|
|
$sql .= " tms='".$this->db->idate($this->tms)."',"; |
|
139
|
|
|
$sql .= " fk_user=".$this->fk_user.","; |
|
140
|
|
|
$sql .= " datep='".$this->db->idate($this->datep)."',"; |
|
141
|
|
|
$sql .= " datev='".$this->db->idate($this->datev)."',"; |
|
142
|
|
|
$sql .= " amount=".price2num($this->amount).","; |
|
143
|
|
|
$sql .= " fk_projet=".((int) $this->fk_project).","; |
|
144
|
|
|
$sql .= " fk_typepayment=".$this->fk_typepayment."',"; |
|
|
|
|
|
|
145
|
|
|
$sql .= " num_payment='".$this->db->escape($this->num_payment)."',"; |
|
146
|
|
|
$sql .= " label='".$this->db->escape($this->label)."',"; |
|
147
|
|
|
$sql .= " datesp='".$this->db->idate($this->datesp)."',"; |
|
148
|
|
|
$sql .= " dateep='".$this->db->idate($this->dateep)."',"; |
|
149
|
|
|
$sql .= " note='".$this->db->escape($this->note)."',"; |
|
150
|
|
|
$sql .= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").","; |
|
151
|
|
|
$sql .= " fk_user_author=".((int) $this->fk_user_author).","; |
|
152
|
|
|
$sql .= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : 'null'); |
|
153
|
|
|
|
|
154
|
|
|
$sql .= " WHERE rowid=".$this->id; |
|
155
|
|
|
|
|
156
|
|
|
dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
157
|
|
|
$resql = $this->db->query($sql); |
|
158
|
|
|
if (!$resql) { |
|
159
|
|
|
$this->error = "Error ".$this->db->lasterror(); |
|
160
|
|
|
return -1; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
// Update extrafield |
|
164
|
|
|
if (!$error) { |
|
165
|
|
|
$result = $this->insertExtraFields(); |
|
166
|
|
|
if ($result < 0) { |
|
167
|
|
|
$error++; |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
if (!$notrigger) { |
|
172
|
|
|
// Call trigger |
|
173
|
|
|
$result = $this->call_trigger('PAYMENT_SALARY_MODIFY', $user); |
|
174
|
|
|
if ($result < 0) { |
|
175
|
|
|
$error++; |
|
176
|
|
|
} |
|
177
|
|
|
// End call triggers |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
if (!$error) { |
|
181
|
|
|
$this->db->commit(); |
|
182
|
|
|
return 1; |
|
183
|
|
|
} else { |
|
184
|
|
|
$this->db->rollback(); |
|
185
|
|
|
return -1; |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Load object in memory from database |
|
192
|
|
|
* |
|
193
|
|
|
* @param int $id id object |
|
194
|
|
|
* @param User $user User that load |
|
195
|
|
|
* @return int <0 if KO, >0 if OK |
|
196
|
|
|
*/ |
|
197
|
|
|
public function fetch($id, $user = null) |
|
198
|
|
|
{ |
|
199
|
|
|
global $langs; |
|
200
|
|
|
|
|
201
|
|
|
$sql = "SELECT"; |
|
202
|
|
|
$sql .= " s.rowid,"; |
|
203
|
|
|
|
|
204
|
|
|
$sql .= " s.tms,"; |
|
205
|
|
|
$sql .= " s.fk_user,"; |
|
206
|
|
|
$sql .= " s.datep,"; |
|
207
|
|
|
$sql .= " s.datev,"; |
|
208
|
|
|
$sql .= " s.amount,"; |
|
209
|
|
|
$sql .= " s.fk_projet as fk_project,"; |
|
210
|
|
|
$sql .= " s.fk_typepayment,"; |
|
211
|
|
|
$sql .= " s.num_payment,"; |
|
212
|
|
|
$sql .= " s.label,"; |
|
213
|
|
|
$sql .= " s.datesp,"; |
|
214
|
|
|
$sql .= " s.dateep,"; |
|
215
|
|
|
$sql .= " s.note,"; |
|
216
|
|
|
$sql .= " s.fk_bank,"; |
|
217
|
|
|
$sql .= " s.fk_user_author,"; |
|
218
|
|
|
$sql .= " s.fk_user_modif,"; |
|
219
|
|
|
$sql .= " b.fk_account,"; |
|
220
|
|
|
$sql .= " b.fk_type,"; |
|
221
|
|
|
$sql .= " b.rappro"; |
|
222
|
|
|
|
|
223
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as s"; |
|
224
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid"; |
|
225
|
|
|
$sql .= " WHERE s.rowid = ".$id; |
|
226
|
|
|
|
|
227
|
|
|
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
228
|
|
|
$resql = $this->db->query($sql); |
|
229
|
|
|
if ($resql) { |
|
230
|
|
|
if ($this->db->num_rows($resql)) { |
|
231
|
|
|
$obj = $this->db->fetch_object($resql); |
|
232
|
|
|
|
|
233
|
|
|
$this->id = $obj->rowid; |
|
234
|
|
|
$this->ref = $obj->rowid; |
|
235
|
|
|
$this->tms = $this->db->jdate($obj->tms); |
|
236
|
|
|
$this->fk_user = $obj->fk_user; |
|
237
|
|
|
$this->datep = $this->db->jdate($obj->datep); |
|
238
|
|
|
$this->datev = $this->db->jdate($obj->datev); |
|
239
|
|
|
$this->amount = $obj->amount; |
|
240
|
|
|
$this->fk_project = $obj->fk_project; |
|
241
|
|
|
$this->type_payement = $obj->fk_typepayment; |
|
242
|
|
|
$this->num_payment = $obj->num_payment; |
|
243
|
|
|
$this->label = $obj->label; |
|
244
|
|
|
$this->datesp = $this->db->jdate($obj->datesp); |
|
245
|
|
|
$this->dateep = $this->db->jdate($obj->dateep); |
|
246
|
|
|
$this->note = $obj->note; |
|
247
|
|
|
$this->fk_bank = $obj->fk_bank; |
|
248
|
|
|
$this->fk_user_author = $obj->fk_user_author; |
|
249
|
|
|
$this->fk_user_modif = $obj->fk_user_modif; |
|
250
|
|
|
$this->fk_account = $obj->fk_account; |
|
251
|
|
|
$this->fk_type = $obj->fk_type; |
|
252
|
|
|
$this->rappro = $obj->rappro; |
|
253
|
|
|
|
|
254
|
|
|
// Retrieve all extrafield |
|
255
|
|
|
// fetch optionals attributes and labels |
|
256
|
|
|
$this->fetch_optionals(); |
|
257
|
|
|
} |
|
258
|
|
|
$this->db->free($resql); |
|
259
|
|
|
|
|
260
|
|
|
return 1; |
|
261
|
|
|
} else { |
|
262
|
|
|
$this->error = "Error ".$this->db->lasterror(); |
|
263
|
|
|
return -1; |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* Delete object in database |
|
270
|
|
|
* |
|
271
|
|
|
* @param User $user User that delete |
|
272
|
|
|
* @return int <0 if KO, >0 if OK |
|
273
|
|
|
*/ |
|
274
|
|
|
public function delete($user) |
|
275
|
|
|
{ |
|
276
|
|
|
global $conf, $langs; |
|
277
|
|
|
|
|
278
|
|
|
$error = 0; |
|
279
|
|
|
|
|
280
|
|
|
// Call trigger |
|
281
|
|
|
$result = $this->call_trigger('PAYMENT_SALARY_DELETE', $user); |
|
282
|
|
|
if ($result < 0) { |
|
283
|
|
|
return -1; |
|
284
|
|
|
} |
|
285
|
|
|
// End call triggers |
|
286
|
|
|
|
|
287
|
|
|
// Delete donation |
|
288
|
|
|
if (!$error) { |
|
289
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary_extrafields"; |
|
290
|
|
|
$sql .= " WHERE fk_object=".$this->id; |
|
291
|
|
|
|
|
292
|
|
|
$resql = $this->db->query($sql); |
|
293
|
|
|
if (!$resql) { |
|
294
|
|
|
$this->errors[] = $this->db->lasterror(); |
|
295
|
|
|
$error++; |
|
296
|
|
|
} |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary"; |
|
300
|
|
|
$sql .= " WHERE rowid=".$this->id; |
|
301
|
|
|
|
|
302
|
|
|
dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
303
|
|
|
$resql = $this->db->query($sql); |
|
304
|
|
|
if (!$resql) { |
|
305
|
|
|
$this->error = "Error ".$this->db->lasterror(); |
|
306
|
|
|
return -1; |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
return 1; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* Initialise an instance with random values. |
|
315
|
|
|
* Used to build previews or test instances. |
|
316
|
|
|
* id must be 0 if object instance is a specimen. |
|
317
|
|
|
* |
|
318
|
|
|
* @return void |
|
319
|
|
|
*/ |
|
320
|
|
|
public function initAsSpecimen() |
|
321
|
|
|
{ |
|
322
|
|
|
$this->id = 0; |
|
323
|
|
|
|
|
324
|
|
|
$this->tms = ''; |
|
325
|
|
|
$this->fk_user = 1; |
|
326
|
|
|
$this->datep = ''; |
|
327
|
|
|
$this->datev = ''; |
|
328
|
|
|
$this->amount = ''; |
|
329
|
|
|
$this->label = ''; |
|
330
|
|
|
$this->datesp = ''; |
|
331
|
|
|
$this->dateep = ''; |
|
332
|
|
|
$this->note = ''; |
|
333
|
|
|
$this->fk_bank = ''; |
|
334
|
|
|
$this->fk_user_author = 1; |
|
335
|
|
|
$this->fk_user_modif = 1; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* Create in database |
|
340
|
|
|
* |
|
341
|
|
|
* @param User $user User that create |
|
342
|
|
|
* @return int <0 if KO, >0 if OK |
|
343
|
|
|
*/ |
|
344
|
|
|
public function create($user) |
|
345
|
|
|
{ |
|
346
|
|
|
global $conf, $langs; |
|
347
|
|
|
|
|
348
|
|
|
$error = 0; |
|
349
|
|
|
$now = dol_now(); |
|
350
|
|
|
|
|
351
|
|
|
// Clean parameters |
|
352
|
|
|
$this->amount = price2num(trim($this->amount)); |
|
353
|
|
|
$this->label = trim($this->label); |
|
354
|
|
|
$this->note = trim($this->note); |
|
355
|
|
|
$this->fk_bank = (int) $this->fk_bank; |
|
356
|
|
|
$this->fk_user_author = (int) $this->fk_user_author; |
|
357
|
|
|
$this->fk_user_modif = (int) $this->fk_user_modif; |
|
358
|
|
|
|
|
359
|
|
|
// Check parameters |
|
360
|
|
|
if (!$this->label) { |
|
361
|
|
|
$this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")); |
|
362
|
|
|
return -3; |
|
363
|
|
|
} |
|
364
|
|
|
if ($this->fk_user <= 0 || $this->fk_user == '') { |
|
365
|
|
|
$this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee")); |
|
366
|
|
|
return -4; |
|
367
|
|
|
} |
|
368
|
|
|
if ($this->amount < 0 || $this->amount == '') { |
|
369
|
|
|
$this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")); |
|
370
|
|
|
return -5; |
|
371
|
|
|
} |
|
372
|
|
|
if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0)) { |
|
|
|
|
|
|
373
|
|
|
$this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account")); |
|
374
|
|
|
return -6; |
|
375
|
|
|
} |
|
376
|
|
|
if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0)) { |
|
377
|
|
|
$this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")); |
|
378
|
|
|
return -7; |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
$this->db->begin(); |
|
382
|
|
|
|
|
383
|
|
|
// Insert into llx_payment_salary |
|
384
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (fk_user"; |
|
385
|
|
|
$sql .= ", datep"; |
|
386
|
|
|
$sql .= ", datev"; |
|
387
|
|
|
$sql .= ", amount"; |
|
388
|
|
|
$sql .= ", fk_projet"; |
|
389
|
|
|
$sql .= ", salary"; |
|
390
|
|
|
$sql .= ", fk_typepayment"; |
|
391
|
|
|
$sql .= ", num_payment"; |
|
392
|
|
|
if ($this->note) { |
|
393
|
|
|
$sql .= ", note"; |
|
394
|
|
|
} |
|
395
|
|
|
$sql .= ", label"; |
|
396
|
|
|
$sql .= ", datesp"; |
|
397
|
|
|
$sql .= ", dateep"; |
|
398
|
|
|
$sql .= ", fk_user_author"; |
|
399
|
|
|
$sql .= ", datec"; |
|
400
|
|
|
$sql .= ", fk_bank"; |
|
401
|
|
|
$sql .= ", entity"; |
|
402
|
|
|
$sql .= ") "; |
|
403
|
|
|
$sql .= " VALUES ("; |
|
404
|
|
|
$sql .= "'".$this->db->escape($this->fk_user)."'"; |
|
405
|
|
|
$sql .= ", '".$this->db->idate($this->datep)."'"; |
|
406
|
|
|
$sql .= ", '".$this->db->idate($this->datev)."'"; |
|
407
|
|
|
$sql .= ", ".$this->amount; |
|
408
|
|
|
$sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 0); |
|
409
|
|
|
$sql .= ", ".($this->salary > 0 ? $this->salary : "null"); |
|
|
|
|
|
|
410
|
|
|
$sql .= ", ".$this->db->escape($this->type_payment); |
|
411
|
|
|
$sql .= ", '".$this->db->escape($this->num_payment)."'"; |
|
412
|
|
|
if ($this->note) { |
|
413
|
|
|
$sql .= ", '".$this->db->escape($this->note)."'"; |
|
414
|
|
|
} |
|
415
|
|
|
$sql .= ", '".$this->db->escape($this->label)."'"; |
|
416
|
|
|
$sql .= ", '".$this->db->idate($this->datesp)."'"; |
|
417
|
|
|
$sql .= ", '".$this->db->idate($this->dateep)."'"; |
|
418
|
|
|
$sql .= ", '".$this->db->escape($user->id)."'"; |
|
419
|
|
|
$sql .= ", '".$this->db->idate($now)."'"; |
|
420
|
|
|
$sql .= ", NULL"; |
|
421
|
|
|
$sql .= ", ".$conf->entity; |
|
422
|
|
|
$sql .= ")"; |
|
423
|
|
|
|
|
424
|
|
|
dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
425
|
|
|
$result = $this->db->query($sql); |
|
426
|
|
|
if ($result) { |
|
427
|
|
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary"); |
|
428
|
|
|
|
|
429
|
|
|
if ($this->id > 0) { |
|
430
|
|
|
if (!empty($conf->banque->enabled) && !empty($this->amount)) { |
|
431
|
|
|
// Insert into llx_bank |
|
432
|
|
|
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; |
|
433
|
|
|
|
|
434
|
|
|
$acc = new Account($this->db); |
|
435
|
|
|
$result = $acc->fetch($this->accountid); |
|
436
|
|
|
if ($result <= 0) { |
|
437
|
|
|
dol_print_error($this->db); |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
// Update extrafield |
|
441
|
|
|
if (!$error) { |
|
442
|
|
|
$result = $this->insertExtraFields(); |
|
443
|
|
|
if ($result < 0) { |
|
444
|
|
|
$error++; |
|
445
|
|
|
} |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
// Insert payment into llx_bank |
|
449
|
|
|
// Add link 'payment_salary' in bank_url between payment and bank transaction |
|
450
|
|
|
$bank_line_id = $acc->addline( |
|
451
|
|
|
$this->datep, |
|
452
|
|
|
$this->type_payment, |
|
453
|
|
|
$this->label, |
|
454
|
|
|
-abs($this->amount), |
|
455
|
|
|
$this->num_payment, |
|
456
|
|
|
'', |
|
457
|
|
|
$user, |
|
458
|
|
|
'', |
|
459
|
|
|
'', |
|
460
|
|
|
'', |
|
461
|
|
|
$this->datev |
|
462
|
|
|
); |
|
463
|
|
|
|
|
464
|
|
|
// Update fk_bank into llx_paiement. |
|
465
|
|
|
// So we know the payment which has generate the banking ecriture |
|
466
|
|
|
if ($bank_line_id > 0) { |
|
467
|
|
|
$this->update_fk_bank($bank_line_id); |
|
468
|
|
|
} else { |
|
469
|
|
|
$this->error = $acc->error; |
|
470
|
|
|
$error++; |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
if (!$error) { |
|
474
|
|
|
// Add link 'payment_salary' in bank_url between payment and bank transaction |
|
475
|
|
|
$url = DOL_URL_ROOT.'/salaries/card.php?id='; |
|
476
|
|
|
|
|
477
|
|
|
$result = $acc->add_url_line($bank_line_id, $this->id, $url, "(SalaryPayment)", "payment_salary"); |
|
478
|
|
|
if ($result <= 0) { |
|
479
|
|
|
$this->error = $acc->error; |
|
480
|
|
|
$error++; |
|
481
|
|
|
} |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
$fuser = new User($this->db); |
|
485
|
|
|
$fuser->fetch($this->fk_user); |
|
486
|
|
|
|
|
487
|
|
|
// Add link 'user' in bank_url between operation and bank transaction |
|
488
|
|
|
$result = $acc->add_url_line( |
|
489
|
|
|
$bank_line_id, |
|
490
|
|
|
$this->fk_user, |
|
491
|
|
|
DOL_URL_ROOT.'/user/card.php?id=', |
|
492
|
|
|
$fuser->getFullName($langs), |
|
493
|
|
|
// $langs->trans("SalaryPayment").' '.$fuser->getFullName($langs).' '.dol_print_date($this->datesp,'dayrfc').' '.dol_print_date($this->dateep,'dayrfc'), |
|
494
|
|
|
'user' |
|
495
|
|
|
); |
|
496
|
|
|
|
|
497
|
|
|
if ($result <= 0) { |
|
498
|
|
|
$this->error = $acc->error; |
|
499
|
|
|
$error++; |
|
500
|
|
|
} |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
// Call trigger |
|
504
|
|
|
$result = $this->call_trigger('PAYMENT_SALARY_CREATE', $user); |
|
505
|
|
|
if ($result < 0) { |
|
506
|
|
|
$error++; |
|
507
|
|
|
} |
|
508
|
|
|
// End call triggers |
|
509
|
|
|
} else { |
|
510
|
|
|
$error++; |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
if (!$error) { |
|
514
|
|
|
$this->db->commit(); |
|
515
|
|
|
return $this->id; |
|
516
|
|
|
} else { |
|
517
|
|
|
$this->db->rollback(); |
|
518
|
|
|
return -2; |
|
519
|
|
|
} |
|
520
|
|
|
} else { |
|
521
|
|
|
$this->error = $this->db->error(); |
|
522
|
|
|
$this->db->rollback(); |
|
523
|
|
|
return -1; |
|
524
|
|
|
} |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
|
528
|
|
|
/** |
|
529
|
|
|
* Update link between payment salary and line generate into llx_bank |
|
530
|
|
|
* |
|
531
|
|
|
* @param int $id_bank Id bank account |
|
532
|
|
|
* @return int <0 if KO, >0 if OK |
|
533
|
|
|
*/ |
|
534
|
|
|
public function update_fk_bank($id_bank) |
|
535
|
|
|
{ |
|
536
|
|
|
// phpcs:enable |
|
537
|
|
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_salary SET fk_bank = '.$id_bank; |
|
538
|
|
|
$sql .= ' WHERE rowid = '.$this->id; |
|
539
|
|
|
$result = $this->db->query($sql); |
|
540
|
|
|
if ($result) { |
|
541
|
|
|
return 1; |
|
542
|
|
|
} else { |
|
543
|
|
|
dol_print_error($this->db); |
|
544
|
|
|
return -1; |
|
545
|
|
|
} |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
|
|
549
|
|
|
/** |
|
550
|
|
|
* Send name clicable (with possibly the picto) |
|
551
|
|
|
* |
|
552
|
|
|
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
|
553
|
|
|
* @param string $option link option |
|
554
|
|
|
* @param int $notooltip 1=Disable tooltip |
|
555
|
|
|
* @param string $morecss Add more css on link |
|
556
|
|
|
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
|
557
|
|
|
* @return string Chaine with URL |
|
558
|
|
|
*/ |
|
559
|
|
|
public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) |
|
560
|
|
|
{ |
|
561
|
|
|
global $db, $conf, $langs, $hookmanager; |
|
562
|
|
|
|
|
563
|
|
|
if (!empty($conf->dol_no_mouse_hover)) { |
|
564
|
|
|
$notooltip = 1; // Force disable tooltips |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
$result = ''; |
|
568
|
|
|
|
|
569
|
|
|
$label = img_picto('', $this->picto).' <u>'.$langs->trans("SalaryPayment").'</u>'; |
|
570
|
|
|
$label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref; |
|
571
|
|
|
if (!empty($this->label)) { |
|
572
|
|
|
$labeltoshow = $this->label; |
|
573
|
|
|
$reg = array(); |
|
574
|
|
|
if (preg_match('/^\((.*)\)$/i', $this->label, $reg)) { |
|
575
|
|
|
// Label generique car entre parentheses. On l'affiche en le traduisant |
|
576
|
|
|
if ($reg[1] == 'paiement') { |
|
577
|
|
|
$reg[1] = 'Payment'; |
|
578
|
|
|
} |
|
579
|
|
|
$labeltoshow = $langs->trans($reg[1]); |
|
580
|
|
|
} |
|
581
|
|
|
$label .= '<br><b>'.$langs->trans('Label').':</b> '.$labeltoshow; |
|
582
|
|
|
} |
|
583
|
|
|
|
|
584
|
|
|
$url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id; |
|
585
|
|
|
|
|
586
|
|
|
if ($option != 'nolink') { |
|
587
|
|
|
// Add param to save lastsearch_values or not |
|
588
|
|
|
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
|
589
|
|
|
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { |
|
590
|
|
|
$add_save_lastsearch_values = 1; |
|
591
|
|
|
} |
|
592
|
|
|
if ($add_save_lastsearch_values) { |
|
593
|
|
|
$url .= '&save_lastsearch_values=1'; |
|
594
|
|
|
} |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
$linkclose = ''; |
|
598
|
|
|
if (empty($notooltip)) { |
|
599
|
|
|
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { |
|
600
|
|
|
$label = $langs->trans("ShowMyObject"); |
|
601
|
|
|
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
602
|
|
|
} |
|
603
|
|
|
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; |
|
604
|
|
|
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; |
|
605
|
|
|
|
|
606
|
|
|
/* |
|
607
|
|
|
$hookmanager->initHooks(array('myobjectdao')); |
|
608
|
|
|
$parameters=array('id'=>$this->id); |
|
609
|
|
|
$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
610
|
|
|
if ($reshook > 0) $linkclose = $hookmanager->resPrint; |
|
611
|
|
|
*/ |
|
612
|
|
|
} else { |
|
613
|
|
|
$linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); |
|
614
|
|
|
} |
|
615
|
|
|
|
|
616
|
|
|
$linkstart = '<a href="'.$url.'"'; |
|
617
|
|
|
$linkstart .= $linkclose.'>'; |
|
618
|
|
|
$linkend = '</a>'; |
|
619
|
|
|
|
|
620
|
|
|
$result .= $linkstart; |
|
621
|
|
|
if ($withpicto) { |
|
622
|
|
|
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); |
|
623
|
|
|
} |
|
624
|
|
|
if ($withpicto != 2) { |
|
625
|
|
|
$result .= $this->ref; |
|
626
|
|
|
} |
|
627
|
|
|
$result .= $linkend; |
|
628
|
|
|
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); |
|
629
|
|
|
|
|
630
|
|
|
global $action, $hookmanager; |
|
631
|
|
|
$hookmanager->initHooks(array('salarypayment')); |
|
632
|
|
|
$parameters = array('id'=>$this->id, 'getnomurl'=>$result); |
|
633
|
|
|
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
634
|
|
|
if ($reshook > 0) { |
|
635
|
|
|
$result = $hookmanager->resPrint; |
|
636
|
|
|
} else { |
|
637
|
|
|
$result .= $hookmanager->resPrint; |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
return $result; |
|
641
|
|
|
} |
|
642
|
|
|
|
|
643
|
|
|
/** |
|
644
|
|
|
* Information on record |
|
645
|
|
|
* |
|
646
|
|
|
* @param int $id Id of record |
|
647
|
|
|
* @return void |
|
648
|
|
|
*/ |
|
649
|
|
|
public function info($id) |
|
650
|
|
|
{ |
|
651
|
|
|
$sql = 'SELECT ps.rowid, ps.datec, ps.fk_user_author'; |
|
652
|
|
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps'; |
|
653
|
|
|
$sql .= ' WHERE ps.rowid = '.$id; |
|
654
|
|
|
|
|
655
|
|
|
dol_syslog(get_class($this).'::info', LOG_DEBUG); |
|
656
|
|
|
$result = $this->db->query($sql); |
|
657
|
|
|
|
|
658
|
|
|
if ($result) { |
|
659
|
|
|
if ($this->db->num_rows($result)) { |
|
660
|
|
|
$obj = $this->db->fetch_object($result); |
|
661
|
|
|
$this->id = $obj->rowid; |
|
662
|
|
|
if ($obj->fk_user_author) { |
|
663
|
|
|
$cuser = new User($this->db); |
|
664
|
|
|
$cuser->fetch($obj->fk_user_author); |
|
665
|
|
|
$this->user_creation = $cuser; |
|
666
|
|
|
} |
|
667
|
|
|
$this->date_creation = $this->db->jdate($obj->datec); |
|
668
|
|
|
} |
|
669
|
|
|
$this->db->free($result); |
|
670
|
|
|
} else { |
|
671
|
|
|
dol_print_error($this->db); |
|
672
|
|
|
} |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
|
|
676
|
|
|
/** |
|
677
|
|
|
* Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) |
|
678
|
|
|
* |
|
679
|
|
|
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
|
680
|
|
|
* @return string Libelle |
|
681
|
|
|
*/ |
|
682
|
|
|
public function getLibStatut($mode = 0) |
|
683
|
|
|
{ |
|
684
|
|
|
return $this->LibStatut($this->statut, $mode); |
|
685
|
|
|
} |
|
686
|
|
|
|
|
687
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
|
688
|
|
|
/** |
|
689
|
|
|
* Renvoi le libelle d'un statut donne |
|
690
|
|
|
* |
|
691
|
|
|
* @param int $status Statut |
|
692
|
|
|
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
|
693
|
|
|
* @return string Libelle du statut |
|
694
|
|
|
*/ |
|
695
|
|
|
public function LibStatut($status, $mode = 0) |
|
696
|
|
|
{ |
|
697
|
|
|
// phpcs:enable |
|
698
|
|
|
global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage |
|
699
|
|
|
|
|
700
|
|
|
$langs->load('compta'); |
|
701
|
|
|
/*if ($mode == 0) |
|
702
|
|
|
{ |
|
703
|
|
|
if ($status == 0) return $langs->trans('ToValidate'); |
|
704
|
|
|
if ($status == 1) return $langs->trans('Validated'); |
|
705
|
|
|
} |
|
706
|
|
|
if ($mode == 1) |
|
707
|
|
|
{ |
|
708
|
|
|
if ($status == 0) return $langs->trans('ToValidate'); |
|
709
|
|
|
if ($status == 1) return $langs->trans('Validated'); |
|
710
|
|
|
} |
|
711
|
|
|
if ($mode == 2) |
|
712
|
|
|
{ |
|
713
|
|
|
if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate'); |
|
714
|
|
|
if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated'); |
|
715
|
|
|
} |
|
716
|
|
|
if ($mode == 3) |
|
717
|
|
|
{ |
|
718
|
|
|
if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1'); |
|
719
|
|
|
if ($status == 1) return img_picto($langs->trans('Validated'),'statut4'); |
|
720
|
|
|
} |
|
721
|
|
|
if ($mode == 4) |
|
722
|
|
|
{ |
|
723
|
|
|
if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate'); |
|
724
|
|
|
if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated'); |
|
725
|
|
|
} |
|
726
|
|
|
if ($mode == 5) |
|
727
|
|
|
{ |
|
728
|
|
|
if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1'); |
|
729
|
|
|
if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4'); |
|
730
|
|
|
} |
|
731
|
|
|
if ($mode == 6) |
|
732
|
|
|
{ |
|
733
|
|
|
if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1'); |
|
734
|
|
|
if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4'); |
|
735
|
|
|
}*/ |
|
736
|
|
|
return ''; |
|
737
|
|
|
} |
|
738
|
|
|
} |
|
739
|
|
|
|