Total Complexity | 120 |
Total Lines | 944 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Salary often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Salary, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | class Salary extends CommonObject |
||
38 | { |
||
39 | /** |
||
40 | * @var string ID to identify managed object |
||
41 | */ |
||
42 | public $element = 'salary'; |
||
43 | |||
44 | /** |
||
45 | * @var string Name of table without prefix where object is stored |
||
46 | */ |
||
47 | public $table_element = 'salary'; |
||
48 | |||
49 | /** |
||
50 | * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png |
||
51 | */ |
||
52 | public $picto = 'salary'; |
||
53 | |||
54 | /** |
||
55 | * @var array<string, array<string>> List of child tables. To test if we can delete object. |
||
56 | */ |
||
57 | protected $childtables = array('payment_salary' => array('name' => 'SalaryPayment', 'fk_element' => 'fk_salary')); |
||
58 | |||
59 | // /** |
||
60 | // * @var array List of child tables. To know object to delete on cascade. |
||
61 | // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will |
||
62 | // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object |
||
63 | // */ |
||
64 | //protected $childtablesoncascade = array('mymodule_myobjectdet'); |
||
65 | |||
66 | |||
67 | /** |
||
68 | * @var int User ID |
||
69 | */ |
||
70 | public $fk_user; |
||
71 | |||
72 | public $datep; |
||
73 | public $datev; |
||
74 | |||
75 | public $salary; |
||
76 | public $amount; |
||
77 | |||
78 | /** |
||
79 | * @var int ID |
||
80 | */ |
||
81 | public $fk_project; |
||
82 | |||
83 | public $type_payment; |
||
84 | |||
85 | /** |
||
86 | * @var string salary payments label |
||
87 | */ |
||
88 | public $label; |
||
89 | |||
90 | public $datesp; |
||
91 | public $dateep; |
||
92 | |||
93 | /** |
||
94 | * @var int ID |
||
95 | */ |
||
96 | public $fk_bank; |
||
97 | |||
98 | /** |
||
99 | * @var int |
||
100 | * @see $accountid |
||
101 | */ |
||
102 | public $fk_account; |
||
103 | |||
104 | /** |
||
105 | * @var int |
||
106 | */ |
||
107 | public $accountid; |
||
108 | |||
109 | /** |
||
110 | * @var int ID |
||
111 | */ |
||
112 | public $fk_user_author; |
||
113 | |||
114 | /** |
||
115 | * @var int ID |
||
116 | */ |
||
117 | public $fk_user_modif; |
||
118 | |||
119 | /** |
||
120 | * @var user User |
||
121 | */ |
||
122 | public $user; |
||
123 | |||
124 | /** |
||
125 | * @var int 1 if salary paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code) |
||
126 | * @deprecated |
||
127 | */ |
||
128 | public $paye; |
||
129 | |||
130 | const STATUS_UNPAID = 0; |
||
131 | const STATUS_PAID = 1; |
||
132 | |||
133 | public $resteapayer; |
||
134 | |||
135 | /** |
||
136 | * Constructor |
||
137 | * |
||
138 | * @param DoliDB $db Database handler |
||
|
|||
139 | */ |
||
140 | public function __construct($db) |
||
141 | { |
||
142 | $this->db = $db; |
||
143 | $this->element = 'salary'; |
||
144 | $this->table_element = 'salary'; |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * Update database |
||
149 | * |
||
150 | * @param User $user User that modify |
||
151 | * @param int $notrigger 0=no, 1=yes (no update trigger) |
||
152 | * @return int Return integer <0 if KO, >0 if OK |
||
153 | */ |
||
154 | public function update($user = null, $notrigger = 0) |
||
155 | { |
||
156 | $error = 0; |
||
157 | |||
158 | // Clean parameters |
||
159 | $this->amount = trim($this->amount); |
||
160 | $this->label = trim($this->label); |
||
161 | $this->note = trim($this->note); |
||
162 | |||
163 | // Check parameters |
||
164 | if (empty($this->fk_user) || $this->fk_user < 0) { |
||
165 | $this->error = 'ErrorBadParameter'; |
||
166 | return -1; |
||
167 | } |
||
168 | |||
169 | $this->db->begin(); |
||
170 | |||
171 | // Update request |
||
172 | $sql = "UPDATE " . MAIN_DB_PREFIX . "salary SET"; |
||
173 | $sql .= " tms='" . $this->db->idate(dol_now()) . "',"; |
||
174 | $sql .= " fk_user=" . ((int) $this->fk_user) . ","; |
||
175 | /*$sql .= " datep='".$this->db->idate($this->datep)."',"; |
||
176 | $sql .= " datev='".$this->db->idate($this->datev)."',";*/ |
||
177 | $sql .= " amount=" . price2num($this->amount) . ","; |
||
178 | $sql .= " fk_projet=" . ((int) $this->fk_project) . ","; |
||
179 | $sql .= " fk_typepayment=" . ((int) $this->type_payment) . ","; |
||
180 | $sql .= " label='" . $this->db->escape($this->label) . "',"; |
||
181 | $sql .= " datesp='" . $this->db->idate($this->datesp) . "',"; |
||
182 | $sql .= " dateep='" . $this->db->idate($this->dateep) . "',"; |
||
183 | $sql .= " note='" . $this->db->escape($this->note) . "',"; |
||
184 | $sql .= " fk_bank=" . ($this->fk_bank > 0 ? (int) $this->fk_bank : "null") . ","; |
||
185 | $sql .= " fk_user_author=" . ((int) $this->fk_user_author) . ","; |
||
186 | $sql .= " fk_user_modif=" . ($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id); |
||
187 | $sql .= " WHERE rowid=" . ((int) $this->id); |
||
188 | |||
189 | dol_syslog(get_class($this) . "::update", LOG_DEBUG); |
||
190 | $resql = $this->db->query($sql); |
||
191 | if (!$resql) { |
||
192 | $this->error = "Error " . $this->db->lasterror(); |
||
193 | return -1; |
||
194 | } |
||
195 | |||
196 | // Update extrafield |
||
197 | if (!$error) { |
||
198 | $result = $this->insertExtraFields(); |
||
199 | if ($result < 0) { |
||
200 | $error++; |
||
201 | } |
||
202 | } |
||
203 | |||
204 | if (!$notrigger) { |
||
205 | // Call trigger |
||
206 | $result = $this->call_trigger('SALARY_MODIFY', $user); |
||
207 | if ($result < 0) { |
||
208 | $error++; |
||
209 | } |
||
210 | // End call triggers |
||
211 | } |
||
212 | |||
213 | if (!$error) { |
||
214 | $this->db->commit(); |
||
215 | return 1; |
||
216 | } else { |
||
217 | $this->db->rollback(); |
||
218 | return -1; |
||
219 | } |
||
220 | } |
||
221 | |||
222 | |||
223 | /** |
||
224 | * Load object in memory from database |
||
225 | * |
||
226 | * @param int $id id object |
||
227 | * @param User $user User that load |
||
228 | * @return int Return integer <0 if KO, >0 if OK |
||
229 | */ |
||
230 | public function fetch($id, $user = null) |
||
231 | { |
||
232 | $sql = "SELECT"; |
||
233 | $sql .= " s.rowid,"; |
||
234 | $sql .= " s.tms,"; |
||
235 | $sql .= " s.fk_user,"; |
||
236 | $sql .= " s.datep,"; |
||
237 | $sql .= " s.datev,"; |
||
238 | $sql .= " s.amount,"; |
||
239 | $sql .= " s.fk_projet as fk_project,"; |
||
240 | $sql .= " s.fk_typepayment,"; |
||
241 | $sql .= " s.label,"; |
||
242 | $sql .= " s.datesp,"; |
||
243 | $sql .= " s.dateep,"; |
||
244 | $sql .= " s.note,"; |
||
245 | $sql .= " s.paye,"; |
||
246 | $sql .= " s.fk_bank,"; |
||
247 | $sql .= " s.fk_user_author,"; |
||
248 | $sql .= " s.fk_user_modif,"; |
||
249 | $sql .= " s.fk_account"; |
||
250 | $sql .= " FROM " . MAIN_DB_PREFIX . "salary as s"; |
||
251 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank as b ON s.fk_bank = b.rowid"; |
||
252 | $sql .= " WHERE s.rowid = " . ((int) $id); |
||
253 | |||
254 | dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); |
||
255 | $resql = $this->db->query($sql); |
||
256 | if ($resql) { |
||
257 | if ($this->db->num_rows($resql)) { |
||
258 | $obj = $this->db->fetch_object($resql); |
||
259 | |||
260 | $this->id = $obj->rowid; |
||
261 | $this->ref = $obj->rowid; |
||
262 | $this->tms = $this->db->jdate($obj->tms); |
||
263 | $this->fk_user = $obj->fk_user; |
||
264 | $this->datep = $this->db->jdate($obj->datep); |
||
265 | $this->datev = $this->db->jdate($obj->datev); |
||
266 | $this->amount = $obj->amount; |
||
267 | $this->fk_project = $obj->fk_project; |
||
268 | $this->type_payment = $obj->fk_typepayment; |
||
269 | $this->label = $obj->label; |
||
270 | $this->datesp = $this->db->jdate($obj->datesp); |
||
271 | $this->dateep = $this->db->jdate($obj->dateep); |
||
272 | $this->note = $obj->note; |
||
273 | $this->paye = $obj->paye; |
||
274 | $this->status = $obj->paye; |
||
275 | $this->fk_bank = $obj->fk_bank; |
||
276 | $this->fk_user_author = $obj->fk_user_author; |
||
277 | $this->fk_user_modif = $obj->fk_user_modif; |
||
278 | $this->fk_account = $obj->fk_account; |
||
279 | $this->accountid = $obj->fk_account; |
||
280 | |||
281 | // Retrieve all extrafield |
||
282 | // fetch optionals attributes and labels |
||
283 | $this->fetch_optionals(); |
||
284 | } |
||
285 | $this->db->free($resql); |
||
286 | |||
287 | return 1; |
||
288 | } else { |
||
289 | $this->error = "Error " . $this->db->lasterror(); |
||
290 | return -1; |
||
291 | } |
||
292 | } |
||
293 | |||
294 | |||
295 | /** |
||
296 | * Delete object in database |
||
297 | * |
||
298 | * @param User $user User that delete |
||
299 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
||
300 | * @return int Return integer <0 if KO, >0 if OK |
||
301 | */ |
||
302 | public function delete($user, $notrigger = 0) |
||
303 | { |
||
304 | return $this->deleteCommon($user, $notrigger); |
||
305 | } |
||
306 | |||
307 | |||
308 | /** |
||
309 | * Initialise an instance with random values. |
||
310 | * Used to build previews or test instances. |
||
311 | * id must be 0 if object instance is a specimen. |
||
312 | * |
||
313 | * @return int |
||
314 | */ |
||
315 | public function initAsSpecimen() |
||
333 | } |
||
334 | |||
335 | /** |
||
336 | * Create in database |
||
337 | * |
||
338 | * @param User $user User that create |
||
339 | * @return int Return integer <0 if KO, >0 if OK |
||
340 | */ |
||
341 | public function create($user) |
||
342 | { |
||
343 | global $conf, $langs; |
||
344 | |||
345 | $error = 0; |
||
346 | $now = dol_now(); |
||
347 | |||
348 | // Clean parameters |
||
349 | $this->amount = price2num(trim($this->amount)); |
||
350 | $this->label = trim($this->label); |
||
351 | $this->note = trim($this->note); |
||
352 | $this->fk_bank = (int) $this->fk_bank; |
||
353 | $this->fk_user_author = (int) $this->fk_user_author; |
||
354 | $this->fk_user_modif = (int) $this->fk_user_modif; |
||
355 | $this->accountid = (int) $this->accountid; |
||
356 | $this->paye = (int) $this->paye; |
||
357 | |||
358 | // Check parameters |
||
359 | if (!$this->label) { |
||
360 | $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")); |
||
361 | return -3; |
||
362 | } |
||
363 | if ($this->fk_user < 0 || $this->fk_user == '') { |
||
364 | $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee")); |
||
365 | return -4; |
||
366 | } |
||
367 | if ($this->amount == '') { |
||
368 | $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")); |
||
369 | return -5; |
||
370 | } |
||
371 | |||
372 | $this->db->begin(); |
||
373 | |||
374 | // Insert into llx_salary |
||
375 | $sql = "INSERT INTO " . MAIN_DB_PREFIX . "salary (fk_user"; |
||
376 | //$sql .= ", datep"; |
||
377 | //$sql .= ", datev"; |
||
378 | $sql .= ", amount"; |
||
379 | $sql .= ", fk_projet"; |
||
380 | $sql .= ", salary"; |
||
381 | $sql .= ", fk_typepayment"; |
||
382 | $sql .= ", fk_account"; |
||
383 | if ($this->note) { |
||
384 | $sql .= ", note"; |
||
385 | } |
||
386 | $sql .= ", label"; |
||
387 | $sql .= ", datesp"; |
||
388 | $sql .= ", dateep"; |
||
389 | $sql .= ", fk_user_author"; |
||
390 | $sql .= ", datec"; |
||
391 | $sql .= ", fk_bank"; |
||
392 | $sql .= ", entity"; |
||
393 | $sql .= ") "; |
||
394 | $sql .= " VALUES ("; |
||
395 | $sql .= "'" . $this->db->escape($this->fk_user) . "'"; |
||
396 | //$sql .= ", '".$this->db->idate($this->datep)."'"; |
||
397 | //$sql .= ", '".$this->db->idate($this->datev)."'"; |
||
398 | $sql .= ", " . ((float) $this->amount); |
||
399 | $sql .= ", " . ($this->fk_project > 0 ? ((int) $this->fk_project) : 0); |
||
400 | $sql .= ", " . ($this->salary > 0 ? ((float) $this->salary) : "null"); |
||
401 | $sql .= ", " . ($this->type_payment > 0 ? ((int) $this->type_payment) : 0); |
||
402 | $sql .= ", " . ($this->accountid > 0 ? ((int) $this->accountid) : "null"); |
||
403 | if ($this->note) { |
||
404 | $sql .= ", '" . $this->db->escape($this->note) . "'"; |
||
405 | } |
||
406 | $sql .= ", '" . $this->db->escape($this->label) . "'"; |
||
407 | $sql .= ", '" . $this->db->idate($this->datesp) . "'"; |
||
408 | $sql .= ", '" . $this->db->idate($this->dateep) . "'"; |
||
409 | $sql .= ", '" . $this->db->escape($user->id) . "'"; |
||
410 | $sql .= ", '" . $this->db->idate($now) . "'"; |
||
411 | $sql .= ", NULL"; |
||
412 | $sql .= ", " . ((int) $conf->entity); |
||
413 | $sql .= ")"; |
||
414 | |||
415 | dol_syslog(get_class($this) . "::create", LOG_DEBUG); |
||
416 | $result = $this->db->query($sql); |
||
417 | if ($result) { |
||
418 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "salary"); |
||
419 | |||
420 | if ($this->id > 0) { |
||
421 | // Update extrafield |
||
422 | if (!$error) { |
||
423 | $result = $this->insertExtraFields(); |
||
424 | if ($result < 0) { |
||
425 | $error++; |
||
426 | } |
||
427 | } |
||
428 | |||
429 | // Call trigger |
||
430 | $result = $this->call_trigger('SALARY_CREATE', $user); |
||
431 | if ($result < 0) { |
||
432 | $error++; |
||
433 | } |
||
434 | // End call triggers |
||
435 | } else { |
||
436 | $error++; |
||
437 | } |
||
438 | |||
439 | if (!$error) { |
||
440 | $this->db->commit(); |
||
441 | return $this->id; |
||
442 | } else { |
||
443 | $this->db->rollback(); |
||
444 | return -2; |
||
445 | } |
||
446 | } else { |
||
447 | $this->error = $this->db->error(); |
||
448 | $this->db->rollback(); |
||
449 | return -1; |
||
450 | } |
||
451 | } |
||
452 | |||
453 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
454 | /** |
||
455 | * Update link between payment salary and line generate into llx_bank |
||
456 | * |
||
457 | * @param int $id_bank Id bank account |
||
458 | * @return int Return integer <0 if KO, >0 if OK |
||
459 | */ |
||
460 | public function update_fk_bank($id_bank) |
||
461 | { |
||
462 | // phpcs:enable |
||
463 | $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'salary SET fk_bank = ' . ((int) $id_bank); |
||
464 | $sql .= " WHERE rowid = " . ((int) $this->id); |
||
465 | $result = $this->db->query($sql); |
||
466 | if ($result) { |
||
467 | return 1; |
||
468 | } else { |
||
469 | dol_print_error($this->db); |
||
470 | return -1; |
||
471 | } |
||
472 | } |
||
473 | |||
474 | /** |
||
475 | * getTooltipContentArray |
||
476 | * |
||
477 | * @param array $params params to construct tooltip data |
||
478 | * @since v18 |
||
479 | * @return array |
||
480 | */ |
||
481 | public function getTooltipContentArray($params) |
||
482 | { |
||
483 | global $langs; |
||
484 | |||
485 | $langs->loadLangs(['salaries']); |
||
486 | |||
487 | // Complete datas |
||
488 | if (!empty($params['fromajaxtooltip']) && !isset($this->alreadypaid)) { |
||
489 | // Load the alreadypaid field |
||
490 | $this->alreadypaid = $this->getSommePaiement(0); |
||
491 | } |
||
492 | |||
493 | $datas = []; |
||
494 | |||
495 | $datas['picto'] = '<u>' . $langs->trans("Salary") . '</u>'; |
||
496 | if (isset($this->status) && isset($this->alreadypaid)) { |
||
497 | $datas['picto'] .= ' ' . $this->getLibStatut(5, $this->alreadypaid); |
||
498 | } |
||
499 | $datas['ref'] = '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref; |
||
500 | |||
501 | return $datas; |
||
502 | } |
||
503 | |||
504 | /** |
||
505 | * Send name clicable (with possibly the picto) |
||
506 | * |
||
507 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
||
508 | * @param string $option link option |
||
509 | * @param int $notooltip 1=Disable tooltip |
||
510 | * @param string $morecss Add more css on link |
||
511 | * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
||
512 | * @return string Chaine with URL |
||
513 | */ |
||
514 | public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) |
||
515 | { |
||
516 | global $conf, $langs, $hookmanager; |
||
517 | |||
518 | if (!empty($conf->dol_no_mouse_hover)) { |
||
519 | $notooltip = 1; |
||
520 | } // Force disable tooltips |
||
521 | |||
522 | $result = ''; |
||
523 | $params = [ |
||
524 | 'id' => $this->id, |
||
525 | 'objecttype' => $this->element, |
||
526 | 'option' => $option, |
||
527 | ]; |
||
528 | $classfortooltip = 'classfortooltip'; |
||
529 | $dataparams = ''; |
||
530 | if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { |
||
531 | $classfortooltip = 'classforajaxtooltip'; |
||
532 | $dataparams = ' data-params="' . dol_escape_htmltag(json_encode($params)) . '"'; |
||
533 | $label = ''; |
||
534 | } else { |
||
535 | $label = implode($this->getTooltipContentArray($params)); |
||
536 | } |
||
537 | |||
538 | $url = constant('BASE_URL') . '/salaries/card.php?id=' . $this->id; |
||
539 | |||
540 | if ($option != 'nolink') { |
||
541 | // Add param to save lastsearch_values or not |
||
542 | $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
||
543 | if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { |
||
544 | $add_save_lastsearch_values = 1; |
||
545 | } |
||
546 | if ($add_save_lastsearch_values) { |
||
547 | $url .= '&save_lastsearch_values=1'; |
||
548 | } |
||
549 | } |
||
550 | |||
551 | $linkclose = ''; |
||
552 | if (empty($notooltip)) { |
||
553 | if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { |
||
554 | $label = $langs->trans("ShowMyObject"); |
||
555 | $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"'; |
||
556 | } |
||
557 | $linkclose .= ($label ? ' title="' . dol_escape_htmltag($label, 1) . '"' : ' title="tocomplete"'); |
||
558 | $linkclose .= $dataparams . ' class="' . $classfortooltip . ($morecss ? ' ' . $morecss : '') . '"'; |
||
559 | } else { |
||
560 | $linkclose = ($morecss ? ' class="' . $morecss . '"' : ''); |
||
561 | } |
||
562 | |||
563 | $linkstart = '<a href="' . $url . '"'; |
||
564 | $linkstart .= $linkclose . '>'; |
||
565 | $linkend = '</a>'; |
||
566 | |||
567 | $result .= $linkstart; |
||
568 | if ($withpicto) { |
||
569 | $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . '"'), 0, 0, $notooltip ? 0 : 1); |
||
570 | } |
||
571 | if ($withpicto != 2) { |
||
572 | $result .= $this->ref; |
||
573 | } |
||
574 | $result .= $linkend; |
||
575 | //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); |
||
576 | |||
577 | global $action, $hookmanager; |
||
578 | $hookmanager->initHooks(array('salarypayment')); |
||
579 | $parameters = array('id' => $this->id, 'getnomurl' => &$result); |
||
580 | $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
||
581 | if ($reshook > 0) { |
||
582 | $result = $hookmanager->resPrint; |
||
583 | } else { |
||
584 | $result .= $hookmanager->resPrint; |
||
585 | } |
||
586 | |||
587 | return $result; |
||
588 | } |
||
589 | |||
590 | /** |
||
591 | * Return amount of payments already done |
||
592 | * |
||
593 | * @param int $multicurrency Return multicurrency_amount instead of amount. -1=Return both. |
||
594 | * @return float|int|array Amount of payment already done, <0 and set ->error if KO |
||
595 | */ |
||
596 | public function getSommePaiement($multicurrency = 0) |
||
597 | { |
||
598 | $table = 'payment_salary'; |
||
599 | $field = 'fk_salary'; |
||
600 | |||
601 | $sql = "SELECT sum(amount) as amount"; |
||
602 | //sum(multicurrency_amount) as multicurrency_amount // Not yet supported |
||
603 | $sql .= " FROM " . MAIN_DB_PREFIX . $table; |
||
604 | $sql .= " WHERE " . $field . " = " . ((int) $this->id); |
||
605 | |||
606 | dol_syslog(get_class($this) . "::getSommePaiement", LOG_DEBUG); |
||
607 | |||
608 | $resql = $this->db->query($sql); |
||
609 | |||
610 | if ($resql) { |
||
611 | $obj = $this->db->fetch_object($resql); |
||
612 | |||
613 | $this->db->free($resql); |
||
614 | |||
615 | if ($obj) { |
||
616 | if ($multicurrency < 0) { |
||
617 | //$this->sumpayed = $obj->amount; |
||
618 | //$this->sumpayed_multicurrency = $obj->multicurrency_amount; |
||
619 | //return array('alreadypaid'=>(float) $obj->amount, 'alreadypaid_multicurrency'=>(float) $obj->multicurrency_amount); |
||
620 | return array(); // Not yet supported |
||
621 | } elseif ($multicurrency) { |
||
622 | //$this->sumpayed_multicurrency = $obj->multicurrency_amount; |
||
623 | //return (float) $obj->multicurrency_amount; |
||
624 | return -1; // Not yet supported |
||
625 | } else { |
||
626 | //$this->sumpayed = $obj->amount; |
||
627 | return (float) $obj->amount; |
||
628 | } |
||
629 | } else { |
||
630 | return 0; |
||
631 | } |
||
632 | } else { |
||
633 | $this->error = $this->db->lasterror(); |
||
634 | return -1; |
||
635 | } |
||
636 | } |
||
637 | |||
638 | /** |
||
639 | * Information on record |
||
640 | * |
||
641 | * @param int $id Id of record |
||
642 | * @return void |
||
643 | */ |
||
644 | public function info($id) |
||
645 | { |
||
646 | $sql = 'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif'; |
||
647 | $sql .= ' FROM ' . MAIN_DB_PREFIX . 'salary as ps'; |
||
648 | $sql .= ' WHERE ps.rowid = ' . ((int) $id); |
||
649 | |||
650 | dol_syslog(get_class($this) . '::info', LOG_DEBUG); |
||
651 | $result = $this->db->query($sql); |
||
652 | |||
653 | if ($result) { |
||
654 | if ($this->db->num_rows($result)) { |
||
655 | $obj = $this->db->fetch_object($result); |
||
656 | |||
657 | $this->id = $obj->rowid; |
||
658 | |||
659 | $this->user_creation_id = $obj->fk_user_author; |
||
660 | $this->user_modification_id = $obj->fk_user_modif; |
||
661 | $this->date_creation = $this->db->jdate($obj->datec); |
||
662 | $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem); |
||
663 | } |
||
664 | $this->db->free($result); |
||
665 | } else { |
||
666 | dol_print_error($this->db); |
||
667 | } |
||
668 | } |
||
669 | |||
670 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
671 | /** |
||
672 | * Tag social contribution as paid completely |
||
673 | * |
||
674 | * @deprecated |
||
675 | * @see setPaid() |
||
676 | * @param User $user Object user making change |
||
677 | * @return int Return integer <0 if KO, >0 if OK |
||
678 | */ |
||
679 | public function set_paid($user) |
||
680 | { |
||
681 | // phpcs:enable |
||
682 | dol_syslog(get_class($this) . "::set_paid is deprecated, use setPaid instead", LOG_NOTICE); |
||
683 | return $this->setPaid($user); |
||
684 | } |
||
685 | |||
686 | /** |
||
687 | * Tag social contribution as paid completely |
||
688 | * |
||
689 | * @param User $user Object user making change |
||
690 | * @return int Return integer <0 if KO, >0 if OK |
||
691 | */ |
||
692 | public function setPaid($user) |
||
693 | { |
||
694 | $sql = "UPDATE " . MAIN_DB_PREFIX . "salary SET"; |
||
695 | $sql .= " paye = 1"; |
||
696 | $sql .= " WHERE rowid = " . ((int) $this->id); |
||
697 | |||
698 | $return = $this->db->query($sql); |
||
699 | |||
700 | if ($return) { |
||
701 | $this->paye = 1; |
||
702 | return 1; |
||
703 | } else { |
||
704 | return -1; |
||
705 | } |
||
706 | } |
||
707 | |||
708 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
709 | /** |
||
710 | * Remove tag paid on social contribution |
||
711 | * |
||
712 | * @param User $user Object user making change |
||
713 | * @return int Return integer <0 if KO, >0 if OK |
||
714 | */ |
||
715 | public function set_unpaid($user) |
||
716 | { |
||
717 | // phpcs:enable |
||
718 | $sql = "UPDATE " . MAIN_DB_PREFIX . "salary SET"; |
||
719 | $sql .= " paye = 0"; |
||
720 | $sql .= " WHERE rowid = " . ((int) $this->id); |
||
721 | |||
722 | $return = $this->db->query($sql); |
||
723 | |||
724 | if ($return) { |
||
725 | $this->paye = 0; |
||
726 | return 1; |
||
727 | } else { |
||
728 | return -1; |
||
729 | } |
||
730 | } |
||
731 | |||
732 | |||
733 | /** |
||
734 | * Return label of current status |
||
735 | * |
||
736 | * @param int $mode 0=label long, 1=labels short, 2=Picto + Label short, 3=Picto, 4=Picto + Label long, 5=Label short + Picto |
||
737 | * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommend to put here amount paid if you have it, 1 otherwise) |
||
738 | * @return string Label |
||
739 | */ |
||
740 | public function getLibStatut($mode = 0, $alreadypaid = -1) |
||
741 | { |
||
742 | return $this->LibStatut($this->paye, $mode, $alreadypaid); |
||
743 | } |
||
744 | |||
745 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
746 | /** |
||
747 | * Return label of a given status |
||
748 | * |
||
749 | * @param int $status Id status |
||
750 | * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto |
||
751 | * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommend to put here amount paid if you have it, 1 otherwise) |
||
752 | * @return string Label |
||
753 | */ |
||
754 | public function LibStatut($status, $mode = 0, $alreadypaid = -1) |
||
755 | { |
||
756 | // phpcs:enable |
||
757 | global $langs; |
||
758 | |||
759 | // Load translation files required by the page |
||
760 | $langs->loadLangs(array("customers", "bills")); |
||
761 | |||
762 | // We reinit status array to force to redefine them because label may change according to properties values. |
||
763 | $this->labelStatus = array(); |
||
764 | $this->labelStatusShort = array(); |
||
765 | |||
766 | if (empty($this->labelStatus) || empty($this->labelStatusShort)) { |
||
767 | global $langs; |
||
768 | //$langs->load("mymodule"); |
||
769 | $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid'); |
||
770 | $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid'); |
||
771 | if ($status == self::STATUS_UNPAID && $alreadypaid != 0) { |
||
772 | $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted"); |
||
773 | } |
||
774 | $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid'); |
||
775 | $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid'); |
||
776 | if ($status == self::STATUS_UNPAID && $alreadypaid != 0) { |
||
777 | $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted"); |
||
778 | } |
||
779 | } |
||
780 | |||
781 | $statusType = 'status1'; |
||
782 | if ($status == 0 && $alreadypaid != 0) { |
||
783 | $statusType = 'status3'; |
||
784 | } |
||
785 | if ($status == 1) { |
||
786 | $statusType = 'status6'; |
||
787 | } |
||
788 | |||
789 | return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); |
||
790 | } |
||
791 | |||
792 | /** |
||
793 | * Return clicable link of object (with eventually picto) |
||
794 | * |
||
795 | * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) |
||
796 | * @param array $arraydata Array of data |
||
797 | * @return string HTML Code for Kanban thumb. |
||
798 | */ |
||
799 | public function getKanbanView($option = '', $arraydata = null) |
||
837 | } |
||
838 | |||
839 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
840 | /** |
||
841 | * Create a withdrawal request for a direct debit order or a credit transfer order. |
||
842 | * Use the remain to pay excluding all existing open direct debit requests. |
||
843 | * |
||
844 | * @param User $fuser User asking the direct debit transfer |
||
845 | * @param float $amount Amount we request direct debit for |
||
846 | * @param string $type 'direct-debit' or 'bank-transfer' |
||
847 | * @param string $sourcetype Source ('facture' or 'supplier_invoice') |
||
848 | * @param int $checkduplicateamongall 0=Default (check among open requests only to find if request already exists). 1=Check also among requests completely processed and cancel if at least 1 request exists whatever is its status. |
||
849 | * @return int Return integer <0 if KO, 0 if a request already exists, >0 if OK |
||
850 | */ |
||
851 | public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'salaire', $checkduplicateamongall = 0) |
||
958 | } |
||
959 | } |
||
960 | |||
961 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
962 | /** |
||
963 | * Remove a direct debit request or a credit transfer request |
||
964 | * |
||
965 | * @param User $fuser User making delete |
||
966 | * @param int $did ID of request to delete |
||
967 | * @return int Return integer <0 if OK, >0 if KO |
||
968 | */ |
||
969 | public function demande_prelevement_delete($fuser, $did) |
||
981 | } |
||
982 | } |
||
983 | } |
||
984 |