dolibarr 25.0.0-alpha
paymentsalary.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
3 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
5 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
31
32
37{
41 public $element = 'payment_salary';
42
46 public $table_element = 'payment_salary';
47
51 public $picto = 'payment';
52
58 public $chid;
59
63 public $fk_salary;
64
68 public $datec = '';
69
75 public $datepaye = '';
76
80 public $datep = '';
81
87 public $total;
88
92 public $amount;
93
97 public $amounts = array();
98
102 public $fk_typepayment;
103
108 public $num_payment;
109
115 public $fk_bank;
116
120 public $bank_line;
121
125 public $fk_user_author;
126
130 public $fk_user_modif;
131
135 public $type_code;
136
140 public $type_label;
141
145 public $bank_account;
146
150 public $datev = '';
151
155 public $fields = array(
156 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
157 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'visible' => 1, 'index' => 1, 'comment' => "Reference of object"),
158 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 20),
159 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'position' => 30),
160 'datep' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 40, 'comment' => 'Date'),
161 'datev' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 50, 'comment' => 'Date'),
162 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Employee', 'enabled' => 1, 'position' => 60, 'notnull' => 1, 'visible' => 1, 'picto' => 'user'),
163 'salary' => array('type' => 'double(24,8)', 'label' => 'salary', 'enabled' => 1, 'visible' => 0, 'position' => 70),
164 'amount' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 80),
165 'fk_projet' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'enabled' => "isModEnabled('project')", 'visible' => 0, 'position' => 90),
166 'fk_typepayment' => array('type' => 'typepayment', 'label' => 'DefaultPaymentMode', 'enabled' => 1, 'visible' => 1, 'position' => 100, 'comment' => 'Payment type'),
167 'num_payment' => array('type' => 'string', 'label' => 'Reference', 'enabled' => 1, 'visible' => 0, 'position' => 110, 'comment' => 'Reference'),
168 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 120, 'notnull' => 0, 'visible' => 1),
169 'datesp' => array('type' => 'date', 'label' => 'DateStart', 'enabled' => 1, 'visible' => 1, 'position' => 130, 'comment' => 'Date'),
170 'dateep' => array('type' => 'date', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => 1, 'position' => 140, 'comment' => 'Date'),
171 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => 0, 'position' => 150, 'index' => 1),
172 'note' => array('type' => 'text', 'label' => 'Note', 'enabled' => 1, 'position' => 160, 'visible' => 0,),
173 'fk_bank' => array('type' => 'integer', 'label' => 'BankId', 'enabled' => 1, 'visible' => 0, 'position' => 170),
174 'paye' => array('type' => 'smallint(6)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 180),
175 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => 0, 'position' => 190),
176 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 200, 'visible' => 0,),
177 'ref_ext' => array('type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => 1, 'visible' => 0, 'position' => 210),
178 'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 220),
179 );
180
186 public function __construct($db)
187 {
188 $this->db = $db;
189 }
190
199 public function create($user, $closepaidcontrib = 0)
200 {
201 global $conf;
202
203 $error = 0;
204
205 $now = dol_now();
206
207 dol_syslog(get_class($this)."::create", LOG_DEBUG);
208
209 //deprecated
210 if (!empty($this->datepaye) && empty($this->datep)) {
211 dol_syslog(__METHOD__.": using datepaye is deprecated, please use datep instead", LOG_WARNING);
212 $this->datep = $this->datepaye;
213 }
214
215 // Validate parameters
216 if (empty($this->datep)) {
217 $this->error = 'ErrorBadValueForParameterCreatePaymentSalary';
218 return -1;
219 }
220
221 // Clean parameters
222 if (isset($this->fk_salary)) {
223 $this->fk_salary = (int) $this->fk_salary;
224 }
225 if (isset($this->amount)) {
226 $this->amount = (float) $this->amount;
227 }
228 if (isset($this->fk_typepayment)) {
229 $this->fk_typepayment = (int) $this->fk_typepayment;
230 }
231 if (isset($this->num_payment)) {
232 $this->num_payment = trim($this->num_payment);
233 }
234 if (isset($this->note)) {
235 $this->note = trim($this->note);
236 }
237 if (isset($this->fk_bank)) {
238 $this->fk_bank = (int) $this->fk_bank;
239 }
240 if (isset($this->fk_user_author)) {
241 $this->fk_user_author = (int) $this->fk_user_author;
242 }
243 if (isset($this->fk_user_modif)) {
244 $this->fk_user_modif = (int) $this->fk_user_modif;
245 }
246
247 $totalamount = 0;
248 foreach ($this->amounts as $key => $value) { // How payment is dispatch
249 $newvalue = (float) price2num($value, 'MT');
250 $this->amounts[$key] = $newvalue;
251 $totalamount += $newvalue;
252 }
253
254 // Check parameters
255 $totalamount = (float) price2num($totalamount, 'MT'); // this is to ensure the following test is no biaised by a potential float equal to 0.0000000000001
256 if ($totalamount == 0) {
257 return -1;
258 } // Negative amounts are accepted (for direct debit rejections) but not null
259
260
261 $this->db->begin();
262
263 if ($totalamount != 0) {
264 // Insert array of amounts
265 foreach ($this->amounts as $key => $amount) {
266 $salary_id = $key;
267 if (is_numeric($amount) && !empty($amount)) {
268 // We can have n payments for 1 salary but we can't have 1 payments for n salaries (for invoices link is n-n, not for salaries).
269 $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (entity, fk_salary, datec, datep, amount,";
270 $sql .= " fk_typepayment, num_payment, note, fk_user_author, fk_bank)";
271 $sql .= " VALUES (".((int) $conf->entity).", ".((int) $salary_id).", '".$this->db->idate($now)."',";
272 $sql .= " '".$this->db->idate($this->datep)."',";
273 $sql .= " ".((float) $amount).",";
274 $sql .= " ".((int) $this->fk_typepayment).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".((int) $user->id).",";
275 $sql .= " 0)";
276
277 $resql = $this->db->query($sql);
278 if ($resql) {
279 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary");
280 }
281
282 // If we want to closed paid invoices
283 if ($closepaidcontrib) {
284 $tmpsalary = new Salary($this->db);
285 $tmpsalary->fetch($salary_id);
286 $paiement = $tmpsalary->getSommePaiement();
287 //$creditnotes=$tmpsalary->getSumCreditNotesUsed();
288 $creditnotes = 0;
289 //$deposits=$tmpsalary->getSumDepositsUsed();
290 $deposits = 0;
291 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
292 $remaintopay = price2num((float) $tmpsalary->amount - $paiement - $creditnotes - $deposits, 'MT');
293 if ($remaintopay == 0) {
294 $result = $tmpsalary->setPaid($user);
295 } else {
296 dol_syslog("Remain to pay for salary id=".$salary_id." not null. We do nothing.");
297 }
298 }
299 }
300 }
301 }
302
303 if (!$error) {
304 $result = $this->call_trigger('PAYMENTSALARY_CREATE', $user);
305 if ($result < 0) {
306 $error++;
307 }
308 }
309
310 if ($totalamount != 0 && !$error) {
311 $this->amount = $totalamount;
312 $this->total = $totalamount; // deprecated
313 $this->db->commit();
314 return $this->id; // id of the last payment inserted
315 } else {
316 $this->error = $this->db->error();
317 $this->db->rollback();
318 return -1;
319 }
320 }
321
328 public function fetch($id)
329 {
330 global $langs;
331 $sql = "SELECT";
332 $sql .= " t.rowid,";
333 $sql .= " t.fk_salary,";
334 $sql .= " t.datec,";
335 $sql .= " t.tms,";
336 $sql .= " t.datep,";
337 $sql .= " t.amount,";
338 $sql .= " t.fk_typepayment,";
339 $sql .= " t.num_payment as num_payment,";
340 $sql .= " t.note,";
341 $sql .= " t.fk_bank as bank_line,";
342 $sql .= " t.fk_user_author,";
343 $sql .= " t.fk_user_modif,";
344 $sql .= " pt.code as type_code, pt.libelle as type_label,";
345 $sql .= ' b.fk_account';
346 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id";
347 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
348 $sql .= " WHERE t.rowid = ".((int) $id);
349 // TODO link on entity of tax;
350
351 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
352 $resql = $this->db->query($sql);
353 if ($resql) {
354 if ($this->db->num_rows($resql)) {
355 $obj = $this->db->fetch_object($resql);
356
357 $this->id = $obj->rowid;
358 $this->ref = $obj->rowid;
359
360 $this->fk_salary = $obj->fk_salary;
361 $this->datec = $this->db->jdate($obj->datec);
362 $this->tms = $this->db->jdate($obj->tms);
363 $this->datepaye = $this->db->jdate($obj->datep);
364 $this->datep = $this->db->jdate($obj->datep);
365 $this->amount = $obj->amount;
366 $this->fk_typepayment = $obj->fk_typepayment;
367 $this->num_payment = $obj->num_payment;
368 $this->note = $obj->note;
369 $this->note_private = $obj->note;
370 $this->fk_user_author = $obj->fk_user_author;
371 $this->fk_user_modif = $obj->fk_user_modif;
372 $this->user_modification_id = $obj->fk_user_modif;
373
374 $this->type_code = $obj->type_code;
375 $this->type_label = $obj->type_label;
376
377 $this->bank_account = $obj->fk_account;
378 $this->fk_account = $obj->fk_account;
379
380 $this->fk_bank = $obj->bank_line;
381 $this->bank_line = $obj->bank_line;
382 }
383 $this->db->free($resql);
384
385 return 1;
386 } else {
387 $this->error = "Error ".$this->db->lasterror();
388 return -1;
389 }
390 }
391
392
400 public function update($user = null, $notrigger = 0)
401 {
402 global $conf, $langs;
403 $error = 0;
404
405 // Clean parameters
406
407 if (isset($this->fk_salary)) {
408 $this->fk_salary = (int) $this->fk_salary;
409 }
410 if (isset($this->amount)) {
411 $this->amount = (float) $this->amount;
412 }
413 if (isset($this->fk_typepayment)) {
414 $this->fk_typepayment = (int) $this->fk_typepayment;
415 }
416 if (isset($this->num_payment)) {
417 $this->num_payment = trim($this->num_payment);
418 }
419 if (isset($this->note)) {
420 $this->note = trim($this->note);
421 }
422 if (isset($this->fk_bank)) {
423 $this->fk_bank = (int) $this->fk_bank;
424 }
425 if (isset($this->fk_user_author)) {
426 $this->fk_user_author = (int) $this->fk_user_author;
427 }
428 if (isset($this->fk_user_modif)) {
429 $this->fk_user_modif = (int) $this->fk_user_modif;
430 }
431
432 // Check parameters
433 // Put here code to add control on parameters values
434
435 // Update request
436 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET";
437 $sql .= " fk_salary=".(isset($this->fk_salary) ? ((int) $this->fk_salary) : "null").",";
438 $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
439 $sql .= " tms=".(dol_strlen((string) $this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
440 $sql .= " datep=".(dol_strlen($this->datepaye) != 0 ? "'".$this->db->idate($this->datepaye)."'" : 'null').",";
441 $sql .= " amount=".(isset($this->amount) ? ((float) $this->amount) : "null").",";
442 $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? ((int) $this->fk_typepayment) : "null").",";
443 $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").",";
444 $sql .= " note=".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : "null").",";
445 $sql .= " fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) : "null").",";
446 $sql .= " fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) : "null").",";
447 $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) : "null");
448 $sql .= " WHERE rowid=".((int) $this->id);
449
450 $this->db->begin();
451
452 dol_syslog(get_class($this)."::update", LOG_DEBUG);
453 $resql = $this->db->query($sql);
454 if (!$resql) {
455 $error++;
456 $this->errors[] = "Error ".$this->db->lasterror();
457 }
458
459 if (!$error && $user && !$notrigger) {
460 // Call trigger
461 $result = $this->call_trigger('PAYMENTSALARY_MODIFY', $user);
462 if ($result < 0) {
463 $error++;
464 }
465 // End call triggers
466 }
467
468 // Commit or rollback
469 if ($error) {
470 foreach ($this->errors as $errmsg) {
471 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
472 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
473 }
474 $this->db->rollback();
475 return -1 * $error;
476 } else {
477 $this->db->commit();
478 return 1;
479 }
480 }
481
482
490 public function delete($user, $notrigger = 0)
491 {
492 $error = 0;
493
494 dol_syslog(get_class($this)."::delete");
495
496 $this->db->begin();
497
498 if ($this->bank_line > 0) {
499 $accline = new AccountLine($this->db);
500 $accline->fetch((int) $this->bank_line);
501 $result = $accline->delete($user);
502 if ($result < 0) {
503 $this->setErrorsFromObject($accline);
504 $error++;
505 }
506 }
507
508 if (!$error) {
509 $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary";
510 $sql .= " WHERE rowid=".((int) $this->id);
511
512 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
513 $resql = $this->db->query($sql);
514 if (!$resql) {
515 $error++;
516 $this->errors[] = "Error ".$this->db->lasterror();
517 }
518 }
519
520 if (!$error && !$notrigger) {
521 // Call trigger
522 $result = $this->call_trigger('PAYMENTSALARY_DELETE', $user);
523 if ($result < 0) {
524 $error++;
525 }
526 // End call triggers
527 }
528
529 // Commit or rollback
530 if ($error) {
531 foreach ($this->errors as $errmsg) {
532 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
533 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
534 }
535 $this->db->rollback();
536 return -1 * $error;
537 } else {
538 $this->db->commit();
539 return 1;
540 }
541 }
542
543
544
552 public function createFromClone(User $user, $fromid)
553 {
554 $error = 0;
555
556 $object = new PaymentSalary($this->db);
557
558 $this->db->begin();
559
560 // Load source object
561 $object->fetch($fromid);
562 $object->id = 0;
563 $object->statut = 0;
564
565 // Clear fields
566 // ...
567
568 // Create clone
569 $object->context['createfromclone'] = 'createfromclone';
570 $result = $object->create($user);
571
572 // Other options
573 if ($result < 0) {
574 $this->error = $object->error;
575 $error++;
576 }
577
578 unset($object->context['createfromclone']);
579
580 // End
581 if (!$error) {
582 $this->db->commit();
583 return $object->id;
584 } else {
585 $this->db->rollback();
586 return -1;
587 }
588 }
589
590
598 public function initAsSpecimen()
599 {
600 $this->id = 0;
601 $this->fk_salary = 0;
602 $this->datec = '';
603 $this->tms = dol_now();
604 $this->datepaye = dol_now();
605 $this->amount = 0.0;
606 $this->fk_typepayment = 0;
607 $this->num_payment = '';
608 $this->note_private = '';
609 $this->note_public = '';
610 $this->fk_bank = 0;
611 $this->fk_user_author = 0;
612 $this->fk_user_modif = 0;
613
614 return 1;
615 }
616
617
630 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
631 {
632 global $langs;
633
634 // Clean data
635 $this->num_payment = trim((string) $this->num_payment);
636
637 $error = 0;
638
639 if (isModEnabled("bank")) {
640 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
641
642 $acc = new Account($this->db);
643 $acc->fetch($accountid);
644
645 $total = $this->amount;
646
647 // Insert payment into llx_bank
648 $bank_line_id = $acc->addline(
649 $this->datep,
650 (string) $this->fk_typepayment, // Payment mode id or code ("CHQ or VIR for example")
651 $label,
652 -$total,
653 $this->num_payment,
654 0,
655 $user,
656 $emetteur_nom,
657 $emetteur_banque,
658 '',
659 $this->datev
660 );
661
662 // Update fk_bank into llx_payment_salary.
663 // so we know the payment that was used to generated the bank entry.
664 if ($bank_line_id > 0) {
665 $result = $this->update_fk_bank($bank_line_id);
666 if ($result <= 0) {
667 $error++;
668 dol_print_error($this->db);
669 }
670
671 // Add link 'payment_salary' in bank_url between payment and bank transaction
672 $url = '';
673 if ($mode == 'payment_salary') {
674 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id=';
675 }
676
677 if ($url) {
678 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
679 if ($result <= 0) {
680 $error++;
681 dol_print_error($this->db);
682 }
683 }
684
685 // Add link 'user' in bank_url between user and bank transaction
686 foreach ($this->amounts as $key => $value) {
687 if (!$error) {
688 if ($mode == 'payment_salary') {
689 $salary = new Salary($this->db);
690 $salary->fetch($key);
691 $salary->fetch_user($salary->fk_user);
692
693 $fuser = $salary->user;
694
695 if ($fuser->id > 0) {
696 $result = $acc->add_url_line(
697 $bank_line_id,
698 $fuser->id,
699 DOL_URL_ROOT.'/user/card.php?id=',
700 $fuser->getFullName($langs),
701 'user'
702 );
703 }
704 if ($result <= 0) {
705 $this->error = $this->db->lasterror();
706 dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->error);
707 $error++;
708 }
709 }
710 }
711 }
712 } else {
713 $this->error = $acc->error;
714 $error++;
715 }
716 }
717
718 if (!$error) {
719 return 1;
720 } else {
721 return -1;
722 }
723 }
724
725
726 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
733 public function update_fk_bank($id_bank)
734 {
735 // phpcs:enable
736 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id);
737
738 dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
739 $result = $this->db->query($sql);
740 if ($result) {
741 return 1;
742 } else {
743 $this->error = $this->db->error();
744 return 0;
745 }
746 }
747
755 public function updatePaymentDate($date)
756 {
757 $error = 0;
758
759 if (!empty($date)) {
760 $this->db->begin();
761
762 dol_syslog(get_class($this)."::updatePaymentDate with date = ".$date, LOG_DEBUG);
763
764 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
765 $sql .= " SET datep = '".$this->db->idate($date)."'";
766 $sql .= " WHERE rowid = ".((int) $this->id);
767
768 $result = $this->db->query($sql);
769 if (!$result) {
770 $error++;
771 $this->error = 'Error -1 '.$this->db->error();
772 }
773
774 $type = $this->element;
775
776 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
777 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
778 $sql .= " WHERE rowid IN (SELECT fk_bank FROM ".MAIN_DB_PREFIX."bank_url WHERE type = '".$this->db->escape($type)."' AND url_id = ".((int) $this->id).")";
779 $sql .= " AND rappro = 0";
780
781 $result = $this->db->query($sql);
782 if (!$result) {
783 $error++;
784 $this->error = 'Error -1 '.$this->db->error();
785 }
786
787 if (!$error) {
788 $this->datepaye = $date;
789
790 $this->db->commit();
791 return 0;
792 } else {
793 $this->db->rollback();
794 return -2;
795 }
796 }
797 return -1; //no date given or already validated
798 }
799
806 public function getLibStatut($mode = 0)
807 {
808 return $this->LibStatut($this->statut, $mode);
809 }
810
811 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
819 public function LibStatut($status, $mode = 0)
820 {
821 // phpcs:enable
822 global $langs; // TODO Return the English label and translate at display time
823
824 $langs->load('compta');
825 /*if ($mode == 0)
826 {
827 if ($status == 0) return $langs->trans('ToValidate');
828 if ($status == 1) return $langs->trans('Validated');
829 }
830 if ($mode == 1)
831 {
832 if ($status == 0) return $langs->trans('ToValidate');
833 if ($status == 1) return $langs->trans('Validated');
834 }
835 if ($mode == 2)
836 {
837 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
838 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
839 }
840 if ($mode == 3)
841 {
842 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
843 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
844 }
845 if ($mode == 4)
846 {
847 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
848 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
849 }
850 if ($mode == 5)
851 {
852 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
853 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
854 }
855 if ($mode == 6)
856 {
857 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
858 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
859 }*/
860 return '';
861 }
862
874 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1, $option = '')
875 {
876 global $conf, $langs, $hookmanager;
877
878 if (!empty($conf->dol_no_mouse_hover)) {
879 $notooltip = 1; // Force disable tooltips
880 }
881
882 $result = '';
883 $params = [
884 'id' => $this->id,
885 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
886 //'option' => $option,
887 ];
888 $classfortooltip = 'classfortooltip';
889 $dataparams = '';
890 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
891 $classfortooltip = 'classforajaxtooltip';
892 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
893 $label = '';
894 } else {
895 $label = implode($this->getTooltipContentArray($params));
896 }
897
898 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$this->id;
899
900 // if ($option !== 'nolink') {
901 // // Add param to save lastsearch_values or not
902 // $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
903 // if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
904 // $add_save_lastsearch_values = 1;
905 // }
906 // if ($url && $add_save_lastsearch_values) {
907 // $url .= '&save_lastsearch_values=1';
908 // }
909 // }
910
911 $linkclose = '';
912 if (empty($notooltip)) {
913 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
914 $label = $langs->trans("SalaryPayment");
915 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
916 }
917 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
918 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
919 } else {
920 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
921 }
922
923 if ($option == 'nolink') {
924 $linkstart = '<span';
925 } else {
926 $linkstart = '<a href="'.$url.'"';
927 }
928 $linkstart .= $linkclose.'>';
929 if ($option == 'nolink') {
930 $linkend = '</span>';
931 } else {
932 $linkend = '</a>';
933 }
934
935 $result .= $linkstart;
936
937 if (empty($this->showphoto_on_popup)) {
938 if ($withpicto) {
939 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
940 }
941 }
942
943 if ($withpicto != 2) {
944 $result .= $this->ref;
945 }
946
947 $result .= $linkend;
948 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
949
950 global $action, $hookmanager;
951 $hookmanager->initHooks(array($this->element.'dao'));
952 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
953 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
954 if ($reshook > 0) {
955 $result = $hookmanager->resPrint;
956 } else {
957 $result .= $hookmanager->resPrint;
958 }
959
960 return $result;
961 }
962
969 public function getTooltipContentArray($params)
970 {
971 global $conf, $langs, $user;
972
973 $langs->load('salaries');
974 $datas = [];
975
976 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
977 return ['optimize' => $langs->trans("SalaryPayment")];
978 }
979
980 if ($user->hasRight('salaries', 'read')) {
981 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("SalaryPayment").'</u>';
982 if (isset($this->status)) {
983 $datas['status'] = ' '.$this->getLibStatut(5);
984 }
985 $datas['Ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
986 if (!empty($this->total_ttc)) {
987 $datas['AmountTTC'] = '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
988 }
989 if (!empty($this->datep)) {
990 $datas['Date'] = '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datep, 'dayhour', 'tzuserrel');
991 } elseif (!empty($this->datepaye)) {
992 $datas['Date'] = '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datepaye, 'dayhour', 'tzuserrel');
993 }
994 }
995
996 return $datas;
997 }
998
1006 public function getKanbanView($option = '', $arraydata = null)
1007 {
1008 global $langs;
1009
1010 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1011
1012 $return = '<div class="box-flex-item box-flex-grow-zero">';
1013 $return .= '<div class="info-box info-box-sm">';
1014 $return .= '<span class="info-box-icon bg-infobox-action">';
1015 $return .= img_picto('', $this->picto);
1016 $return .= '</span>';
1017 $return .= '<div class="info-box-content">';
1018 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(1) . '</span>';
1019 if ($selected >= 0) {
1020 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1021 }
1022 if (!empty($this->fk_bank) && is_numeric($this->fk_bank)) {
1023 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1024 $account = new AccountLine($this->db);
1025 $account->fetch($this->fk_bank);
1026 $return .= ' | <span class="info-box-label">'.$account->getNomUrl(1).'</span>';
1027 }
1028 if (!empty($this->fk_user_author) && is_numeric($this->fk_user_author)) {
1029 $userstatic = new User($this->db);
1030 $userstatic->fetch($this->fk_user_author);
1031 $return .= '<br><span class="info-box-status">'.$userstatic->getNomUrl(1).'</span>';
1032 }
1033
1034 if (!empty($this->fk_typepayment)) {
1035 $return .= '<br><span class="opacitymedium">'.$langs->trans("PaymentMode").'</span> : <span class="info-box-label">'.$this->fk_typepayment.'</span>';
1036 }
1037 $return .= '<br><span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
1038 $return .= '</div>';
1039 $return .= '</div>';
1040 $return .= '</div>';
1041 return $return;
1042 }
1043}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage bank transaction lines.
setErrorsFromObject($object)
setErrorsFromObject
Class to manage payments of salaries.
LibStatut($status, $mode=0)
Return the status.
update_fk_bank($id_bank)
Update the relation between the salary paiment and the line generated in llx_bank.
updatePaymentDate($date)
Updates the payment date.
getLibStatut($mode=0)
Return the label of the status.
initAsSpecimen()
Initialise an instance with random values.
create($user, $closepaidcontrib=0)
Create payment of salary into database.
__construct($db)
Constructor.
update($user=null, $notrigger=0)
Update database.
getTooltipContentArray($params)
getTooltipContentArray
addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
Add record into bank for payment with links between this bank record and invoices of payment.
getNomUrl($withpicto=0, $maxlen=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1, $option='')
Return clickable name (with picto eventually)
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
fetch($id)
Load object in memory from database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
Class to manage salary payments.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:494