dolibarr 24.0.0-beta
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-2025 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 } // On accepte les montants negatifs pour les rejets de prelevement mais pas 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 $result = $this->call_trigger('PAYMENTSALARY_CREATE', $user);
304 if ($result < 0) {
305 $error++;
306 }
307
308 if ($totalamount != 0 && !$error) {
309 $this->amount = $totalamount;
310 $this->total = $totalamount; // deprecated
311 $this->db->commit();
312 return $this->id; // id of the last payment inserted
313 } else {
314 $this->error = $this->db->error();
315 $this->db->rollback();
316 return -1;
317 }
318 }
319
326 public function fetch($id)
327 {
328 global $langs;
329 $sql = "SELECT";
330 $sql .= " t.rowid,";
331 $sql .= " t.fk_salary,";
332 $sql .= " t.datec,";
333 $sql .= " t.tms,";
334 $sql .= " t.datep,";
335 $sql .= " t.amount,";
336 $sql .= " t.fk_typepayment,";
337 $sql .= " t.num_payment as num_payment,";
338 $sql .= " t.note,";
339 $sql .= " t.fk_bank as bank_line,";
340 $sql .= " t.fk_user_author,";
341 $sql .= " t.fk_user_modif,";
342 $sql .= " pt.code as type_code, pt.libelle as type_label,";
343 $sql .= ' b.fk_account';
344 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id";
345 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
346 $sql .= " WHERE t.rowid = ".((int) $id);
347 // TODO link on entity of tax;
348
349 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
350 $resql = $this->db->query($sql);
351 if ($resql) {
352 if ($this->db->num_rows($resql)) {
353 $obj = $this->db->fetch_object($resql);
354
355 $this->id = $obj->rowid;
356 $this->ref = $obj->rowid;
357
358 $this->fk_salary = $obj->fk_salary;
359 $this->datec = $this->db->jdate($obj->datec);
360 $this->tms = $this->db->jdate($obj->tms);
361 $this->datepaye = $this->db->jdate($obj->datep);
362 $this->datep = $this->db->jdate($obj->datep);
363 $this->amount = $obj->amount;
364 $this->fk_typepayment = $obj->fk_typepayment;
365 $this->num_payment = $obj->num_payment;
366 $this->note = $obj->note;
367 $this->note_private = $obj->note;
368 $this->fk_user_author = $obj->fk_user_author;
369 $this->fk_user_modif = $obj->fk_user_modif;
370 $this->user_modification_id = $obj->fk_user_modif;
371
372 $this->type_code = $obj->type_code;
373 $this->type_label = $obj->type_label;
374
375 $this->bank_account = $obj->fk_account;
376 $this->fk_account = $obj->fk_account;
377
378 $this->fk_bank = $obj->bank_line;
379 $this->bank_line = $obj->bank_line;
380 }
381 $this->db->free($resql);
382
383 return 1;
384 } else {
385 $this->error = "Error ".$this->db->lasterror();
386 return -1;
387 }
388 }
389
390
398 public function update($user = null, $notrigger = 0)
399 {
400 global $conf, $langs;
401 $error = 0;
402
403 // Clean parameters
404
405 if (isset($this->fk_salary)) {
406 $this->fk_salary = (int) $this->fk_salary;
407 }
408 if (isset($this->amount)) {
409 $this->amount = (float) $this->amount;
410 }
411 if (isset($this->fk_typepayment)) {
412 $this->fk_typepayment = (int) $this->fk_typepayment;
413 }
414 if (isset($this->num_payment)) {
415 $this->num_payment = trim($this->num_payment);
416 }
417 if (isset($this->note)) {
418 $this->note = trim($this->note);
419 }
420 if (isset($this->fk_bank)) {
421 $this->fk_bank = (int) $this->fk_bank;
422 }
423 if (isset($this->fk_user_author)) {
424 $this->fk_user_author = (int) $this->fk_user_author;
425 }
426 if (isset($this->fk_user_modif)) {
427 $this->fk_user_modif = (int) $this->fk_user_modif;
428 }
429
430 // Check parameters
431 // Put here code to add control on parameters values
432
433 // Update request
434 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET";
435 $sql .= " fk_salary=".(isset($this->fk_salary) ? $this->fk_salary : "null").",";
436 $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
437 $sql .= " tms=".(dol_strlen((string) $this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
438 $sql .= " datep=".(dol_strlen($this->datepaye) != 0 ? "'".$this->db->idate($this->datepaye)."'" : 'null').",";
439 $sql .= " amount=".(isset($this->amount) ? $this->amount : "null").",";
440 $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").",";
441 $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").",";
442 $sql .= " note=".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : "null").",";
443 $sql .= " fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) : "null").",";
444 $sql .= " fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) : "null").",";
445 $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) : "null");
446 $sql .= " WHERE rowid=".((int) $this->id);
447
448 $this->db->begin();
449
450 dol_syslog(get_class($this)."::update", LOG_DEBUG);
451 $resql = $this->db->query($sql);
452 if (!$resql) {
453 $error++;
454 $this->errors[] = "Error ".$this->db->lasterror();
455 }
456
457 // Commit or rollback
458 if ($error) {
459 foreach ($this->errors as $errmsg) {
460 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
461 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
462 }
463 $this->db->rollback();
464 return -1 * $error;
465 } else {
466 $this->db->commit();
467 return 1;
468 }
469 }
470
471
479 public function delete($user, $notrigger = 0)
480 {
481 $error = 0;
482
483 dol_syslog(get_class($this)."::delete");
484
485 $this->db->begin();
486
487 if ($this->bank_line > 0) {
488 $accline = new AccountLine($this->db);
489 $accline->fetch((int) $this->bank_line);
490 $result = $accline->delete($user);
491 if ($result < 0) {
492 $this->setErrorsFromObject($accline);
493 $error++;
494 }
495 }
496
497 if (!$error) {
498 $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary";
499 $sql .= " WHERE rowid=".((int) $this->id);
500
501 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
502 $resql = $this->db->query($sql);
503 if (!$resql) {
504 $error++;
505 $this->errors[] = "Error ".$this->db->lasterror();
506 }
507 }
508
509 // Commit or rollback
510 if ($error) {
511 foreach ($this->errors as $errmsg) {
512 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
513 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
514 }
515 $this->db->rollback();
516 return -1 * $error;
517 } else {
518 $this->db->commit();
519 return 1;
520 }
521 }
522
523
524
532 public function createFromClone(User $user, $fromid)
533 {
534 $error = 0;
535
536 $object = new PaymentSalary($this->db);
537
538 $this->db->begin();
539
540 // Load source object
541 $object->fetch($fromid);
542 $object->id = 0;
543 $object->statut = 0;
544
545 // Clear fields
546 // ...
547
548 // Create clone
549 $object->context['createfromclone'] = 'createfromclone';
550 $result = $object->create($user);
551
552 // Other options
553 if ($result < 0) {
554 $this->error = $object->error;
555 $error++;
556 }
557
558 unset($object->context['createfromclone']);
559
560 // End
561 if (!$error) {
562 $this->db->commit();
563 return $object->id;
564 } else {
565 $this->db->rollback();
566 return -1;
567 }
568 }
569
570
578 public function initAsSpecimen()
579 {
580 $this->id = 0;
581 $this->fk_salary = 0;
582 $this->datec = '';
583 $this->tms = dol_now();
584 $this->datepaye = dol_now();
585 $this->amount = 0.0;
586 $this->fk_typepayment = 0;
587 $this->num_payment = '';
588 $this->note_private = '';
589 $this->note_public = '';
590 $this->fk_bank = 0;
591 $this->fk_user_author = 0;
592 $this->fk_user_modif = 0;
593
594 return 1;
595 }
596
597
610 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
611 {
612 global $langs;
613
614 // Clean data
615 $this->num_payment = trim((string) $this->num_payment);
616
617 $error = 0;
618
619 if (isModEnabled("bank")) {
620 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
621
622 $acc = new Account($this->db);
623 $acc->fetch($accountid);
624
625 $total = $this->amount;
626
627 // Insert payment into llx_bank
628 $bank_line_id = $acc->addline(
629 $this->datep,
630 (string) $this->fk_typepayment, // Payment mode id or code ("CHQ or VIR for example")
631 $label,
632 -$total,
633 $this->num_payment,
634 0,
635 $user,
636 $emetteur_nom,
637 $emetteur_banque,
638 '',
639 $this->datev
640 );
641
642 // Update fk_bank into llx_payment_salary.
643 // so we know the payment that was used to generated the bank entry.
644 if ($bank_line_id > 0) {
645 $result = $this->update_fk_bank($bank_line_id);
646 if ($result <= 0) {
647 $error++;
648 dol_print_error($this->db);
649 }
650
651 // Add link 'payment_salary' in bank_url between payment and bank transaction
652 $url = '';
653 if ($mode == 'payment_salary') {
654 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id=';
655 }
656
657 if ($url) {
658 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
659 if ($result <= 0) {
660 $error++;
661 dol_print_error($this->db);
662 }
663 }
664
665 // Add link 'user' in bank_url between user and bank transaction
666 foreach ($this->amounts as $key => $value) {
667 if (!$error) {
668 if ($mode == 'payment_salary') {
669 $salary = new Salary($this->db);
670 $salary->fetch($key);
671 $salary->fetch_user($salary->fk_user);
672
673 $fuser = $salary->user;
674
675 if ($fuser->id > 0) {
676 $result = $acc->add_url_line(
677 $bank_line_id,
678 $fuser->id,
679 DOL_URL_ROOT.'/user/card.php?id=',
680 $fuser->getFullName($langs),
681 'user'
682 );
683 }
684 if ($result <= 0) {
685 $this->error = $this->db->lasterror();
686 dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->error);
687 $error++;
688 }
689 }
690 }
691 }
692 } else {
693 $this->error = $acc->error;
694 $error++;
695 }
696 }
697
698 if (!$error) {
699 return 1;
700 } else {
701 return -1;
702 }
703 }
704
705
706 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
713 public function update_fk_bank($id_bank)
714 {
715 // phpcs:enable
716 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id);
717
718 dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
719 $result = $this->db->query($sql);
720 if ($result) {
721 return 1;
722 } else {
723 $this->error = $this->db->error();
724 return 0;
725 }
726 }
727
735 public function updatePaymentDate($date)
736 {
737 $error = 0;
738
739 if (!empty($date)) {
740 $this->db->begin();
741
742 dol_syslog(get_class($this)."::updatePaymentDate with date = ".$date, LOG_DEBUG);
743
744 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
745 $sql .= " SET datep = '".$this->db->idate($date)."'";
746 $sql .= " WHERE rowid = ".((int) $this->id);
747
748 $result = $this->db->query($sql);
749 if (!$result) {
750 $error++;
751 $this->error = 'Error -1 '.$this->db->error();
752 }
753
754 $type = $this->element;
755
756 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
757 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
758 $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).")";
759 $sql .= " AND rappro = 0";
760
761 $result = $this->db->query($sql);
762 if (!$result) {
763 $error++;
764 $this->error = 'Error -1 '.$this->db->error();
765 }
766
767 if (!$error) {
768 $this->datepaye = $date;
769
770 $this->db->commit();
771 return 0;
772 } else {
773 $this->db->rollback();
774 return -2;
775 }
776 }
777 return -1; //no date given or already validated
778 }
779
786 public function getLibStatut($mode = 0)
787 {
788 return $this->LibStatut($this->statut, $mode);
789 }
790
791 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
799 public function LibStatut($status, $mode = 0)
800 {
801 // phpcs:enable
802 global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
803
804 $langs->load('compta');
805 /*if ($mode == 0)
806 {
807 if ($status == 0) return $langs->trans('ToValidate');
808 if ($status == 1) return $langs->trans('Validated');
809 }
810 if ($mode == 1)
811 {
812 if ($status == 0) return $langs->trans('ToValidate');
813 if ($status == 1) return $langs->trans('Validated');
814 }
815 if ($mode == 2)
816 {
817 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
818 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
819 }
820 if ($mode == 3)
821 {
822 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
823 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
824 }
825 if ($mode == 4)
826 {
827 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
828 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
829 }
830 if ($mode == 5)
831 {
832 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
833 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
834 }
835 if ($mode == 6)
836 {
837 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
838 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
839 }*/
840 return '';
841 }
842
854 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1, $option = '')
855 {
856 global $conf, $langs, $hookmanager;
857
858 if (!empty($conf->dol_no_mouse_hover)) {
859 $notooltip = 1; // Force disable tooltips
860 }
861
862 $result = '';
863 $params = [
864 'id' => $this->id,
865 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
866 //'option' => $option,
867 ];
868 $classfortooltip = 'classfortooltip';
869 $dataparams = '';
870 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
871 $classfortooltip = 'classforajaxtooltip';
872 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
873 $label = '';
874 } else {
875 $label = implode($this->getTooltipContentArray($params));
876 }
877
878 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$this->id;
879
880 // if ($option !== 'nolink') {
881 // // Add param to save lastsearch_values or not
882 // $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
883 // if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
884 // $add_save_lastsearch_values = 1;
885 // }
886 // if ($url && $add_save_lastsearch_values) {
887 // $url .= '&save_lastsearch_values=1';
888 // }
889 // }
890
891 $linkclose = '';
892 if (empty($notooltip)) {
893 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
894 $label = $langs->trans("SalaryPayment");
895 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
896 }
897 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
898 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
899 } else {
900 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
901 }
902
903 if ($option == 'nolink') {
904 $linkstart = '<span';
905 } else {
906 $linkstart = '<a href="'.$url.'"';
907 }
908 $linkstart .= $linkclose.'>';
909 if ($option == 'nolink') {
910 $linkend = '</span>';
911 } else {
912 $linkend = '</a>';
913 }
914
915 $result .= $linkstart;
916
917 if (empty($this->showphoto_on_popup)) {
918 if ($withpicto) {
919 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
920 }
921 }
922
923 if ($withpicto != 2) {
924 $result .= $this->ref;
925 }
926
927 $result .= $linkend;
928 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
929
930 global $action, $hookmanager;
931 $hookmanager->initHooks(array($this->element.'dao'));
932 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
933 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
934 if ($reshook > 0) {
935 $result = $hookmanager->resPrint;
936 } else {
937 $result .= $hookmanager->resPrint;
938 }
939
940 return $result;
941 }
942
949 public function getTooltipContentArray($params)
950 {
951 global $conf, $langs, $user;
952
953 $langs->load('salaries');
954 $datas = [];
955
956 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
957 return ['optimize' => $langs->trans("SalaryPayment")];
958 }
959
960 if ($user->hasRight('salaries', 'read')) {
961 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("SalaryPayment").'</u>';
962 if (isset($this->status)) {
963 $datas['status'] = ' '.$this->getLibStatut(5);
964 }
965 $datas['Ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
966 if (!empty($this->total_ttc)) {
967 $datas['AmountTTC'] = '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
968 }
969 if (!empty($this->datep)) {
970 $datas['Date'] = '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datep, 'dayhour', 'tzuserrel');
971 } elseif (!empty($this->datepaye)) {
972 $datas['Date'] = '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datepaye, 'dayhour', 'tzuserrel');
973 }
974 }
975
976 return $datas;
977 }
978
986 public function getKanbanView($option = '', $arraydata = null)
987 {
988 global $langs;
989
990 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
991
992 $return = '<div class="box-flex-item box-flex-grow-zero">';
993 $return .= '<div class="info-box info-box-sm">';
994 $return .= '<span class="info-box-icon bg-infobox-action">';
995 $return .= img_picto('', $this->picto);
996 $return .= '</span>';
997 $return .= '<div class="info-box-content">';
998 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(1) . '</span>';
999 if ($selected >= 0) {
1000 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1001 }
1002 if (!empty($this->fk_bank) && is_numeric($this->fk_bank)) {
1003 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1004 $account = new AccountLine($this->db);
1005 $account->fetch($this->fk_bank);
1006 $return .= ' | <span class="info-box-label">'.$account->getNomUrl(1).'</span>';
1007 }
1008 if (!empty($this->fk_user_author) && is_numeric($this->fk_user_author)) {
1009 $userstatic = new User($this->db);
1010 $userstatic->fetch($this->fk_user_author);
1011 $return .= '<br><span class="info-box-status">'.$userstatic->getNomUrl(1).'</span>';
1012 }
1013
1014 if (!empty($this->fk_typepayment)) {
1015 $return .= '<br><span class="opacitymedium">'.$langs->trans("PaymentMode").'</span> : <span class="info-box-label">'.$this->fk_typepayment.'</span>';
1016 }
1017 $return .= '<br><span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
1018 $return .= '</div>';
1019 $return .= '</div>';
1020 $return .= '</div>';
1021 return $return;
1022 }
1023}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
Class to manage bank accounts.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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:168
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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:489