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 $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) ? ((int) $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) ? ((float) $this->amount) : "null").",";
440 $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? ((int) $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 if (!$error && $user && !$notrigger) {
458 // Call trigger
459 $result = $this->call_trigger('PAYMENTSALARY_MODIFY', $user);
460 if ($result < 0) {
461 $error++;
462 }
463 // End call triggers
464 }
465
466 // Commit or rollback
467 if ($error) {
468 foreach ($this->errors as $errmsg) {
469 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
470 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
471 }
472 $this->db->rollback();
473 return -1 * $error;
474 } else {
475 $this->db->commit();
476 return 1;
477 }
478 }
479
480
488 public function delete($user, $notrigger = 0)
489 {
490 $error = 0;
491
492 dol_syslog(get_class($this)."::delete");
493
494 $this->db->begin();
495
496 if ($this->bank_line > 0) {
497 $accline = new AccountLine($this->db);
498 $accline->fetch((int) $this->bank_line);
499 $result = $accline->delete($user);
500 if ($result < 0) {
501 $this->setErrorsFromObject($accline);
502 $error++;
503 }
504 }
505
506 if (!$error) {
507 $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary";
508 $sql .= " WHERE rowid=".((int) $this->id);
509
510 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
511 $resql = $this->db->query($sql);
512 if (!$resql) {
513 $error++;
514 $this->errors[] = "Error ".$this->db->lasterror();
515 }
516 }
517
518 if (!$error && !$notrigger) {
519 // Call trigger
520 $result = $this->call_trigger('PAYMENTSALARY_DELETE', $user);
521 if ($result < 0) {
522 $error++;
523 }
524 // End call triggers
525 }
526
527 // Commit or rollback
528 if ($error) {
529 foreach ($this->errors as $errmsg) {
530 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
531 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
532 }
533 $this->db->rollback();
534 return -1 * $error;
535 } else {
536 $this->db->commit();
537 return 1;
538 }
539 }
540
541
542
550 public function createFromClone(User $user, $fromid)
551 {
552 $error = 0;
553
554 $object = new PaymentSalary($this->db);
555
556 $this->db->begin();
557
558 // Load source object
559 $object->fetch($fromid);
560 $object->id = 0;
561 $object->statut = 0;
562
563 // Clear fields
564 // ...
565
566 // Create clone
567 $object->context['createfromclone'] = 'createfromclone';
568 $result = $object->create($user);
569
570 // Other options
571 if ($result < 0) {
572 $this->error = $object->error;
573 $error++;
574 }
575
576 unset($object->context['createfromclone']);
577
578 // End
579 if (!$error) {
580 $this->db->commit();
581 return $object->id;
582 } else {
583 $this->db->rollback();
584 return -1;
585 }
586 }
587
588
596 public function initAsSpecimen()
597 {
598 $this->id = 0;
599 $this->fk_salary = 0;
600 $this->datec = '';
601 $this->tms = dol_now();
602 $this->datepaye = dol_now();
603 $this->amount = 0.0;
604 $this->fk_typepayment = 0;
605 $this->num_payment = '';
606 $this->note_private = '';
607 $this->note_public = '';
608 $this->fk_bank = 0;
609 $this->fk_user_author = 0;
610 $this->fk_user_modif = 0;
611
612 return 1;
613 }
614
615
628 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
629 {
630 global $langs;
631
632 // Clean data
633 $this->num_payment = trim((string) $this->num_payment);
634
635 $error = 0;
636
637 if (isModEnabled("bank")) {
638 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
639
640 $acc = new Account($this->db);
641 $acc->fetch($accountid);
642
643 $total = $this->amount;
644
645 // Insert payment into llx_bank
646 $bank_line_id = $acc->addline(
647 $this->datep,
648 (string) $this->fk_typepayment, // Payment mode id or code ("CHQ or VIR for example")
649 $label,
650 -$total,
651 $this->num_payment,
652 0,
653 $user,
654 $emetteur_nom,
655 $emetteur_banque,
656 '',
657 $this->datev
658 );
659
660 // Update fk_bank into llx_payment_salary.
661 // so we know the payment that was used to generated the bank entry.
662 if ($bank_line_id > 0) {
663 $result = $this->update_fk_bank($bank_line_id);
664 if ($result <= 0) {
665 $error++;
666 dol_print_error($this->db);
667 }
668
669 // Add link 'payment_salary' in bank_url between payment and bank transaction
670 $url = '';
671 if ($mode == 'payment_salary') {
672 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id=';
673 }
674
675 if ($url) {
676 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
677 if ($result <= 0) {
678 $error++;
679 dol_print_error($this->db);
680 }
681 }
682
683 // Add link 'user' in bank_url between user and bank transaction
684 foreach ($this->amounts as $key => $value) {
685 if (!$error) {
686 if ($mode == 'payment_salary') {
687 $salary = new Salary($this->db);
688 $salary->fetch($key);
689 $salary->fetch_user($salary->fk_user);
690
691 $fuser = $salary->user;
692
693 if ($fuser->id > 0) {
694 $result = $acc->add_url_line(
695 $bank_line_id,
696 $fuser->id,
697 DOL_URL_ROOT.'/user/card.php?id=',
698 $fuser->getFullName($langs),
699 'user'
700 );
701 }
702 if ($result <= 0) {
703 $this->error = $this->db->lasterror();
704 dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->error);
705 $error++;
706 }
707 }
708 }
709 }
710 } else {
711 $this->error = $acc->error;
712 $error++;
713 }
714 }
715
716 if (!$error) {
717 return 1;
718 } else {
719 return -1;
720 }
721 }
722
723
724 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
731 public function update_fk_bank($id_bank)
732 {
733 // phpcs:enable
734 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id);
735
736 dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
737 $result = $this->db->query($sql);
738 if ($result) {
739 return 1;
740 } else {
741 $this->error = $this->db->error();
742 return 0;
743 }
744 }
745
753 public function updatePaymentDate($date)
754 {
755 $error = 0;
756
757 if (!empty($date)) {
758 $this->db->begin();
759
760 dol_syslog(get_class($this)."::updatePaymentDate with date = ".$date, LOG_DEBUG);
761
762 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
763 $sql .= " SET datep = '".$this->db->idate($date)."'";
764 $sql .= " WHERE rowid = ".((int) $this->id);
765
766 $result = $this->db->query($sql);
767 if (!$result) {
768 $error++;
769 $this->error = 'Error -1 '.$this->db->error();
770 }
771
772 $type = $this->element;
773
774 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
775 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
776 $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).")";
777 $sql .= " AND rappro = 0";
778
779 $result = $this->db->query($sql);
780 if (!$result) {
781 $error++;
782 $this->error = 'Error -1 '.$this->db->error();
783 }
784
785 if (!$error) {
786 $this->datepaye = $date;
787
788 $this->db->commit();
789 return 0;
790 } else {
791 $this->db->rollback();
792 return -2;
793 }
794 }
795 return -1; //no date given or already validated
796 }
797
804 public function getLibStatut($mode = 0)
805 {
806 return $this->LibStatut($this->statut, $mode);
807 }
808
809 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
817 public function LibStatut($status, $mode = 0)
818 {
819 // phpcs:enable
820 global $langs; // TODO Return the English label and translate at display time
821
822 $langs->load('compta');
823 /*if ($mode == 0)
824 {
825 if ($status == 0) return $langs->trans('ToValidate');
826 if ($status == 1) return $langs->trans('Validated');
827 }
828 if ($mode == 1)
829 {
830 if ($status == 0) return $langs->trans('ToValidate');
831 if ($status == 1) return $langs->trans('Validated');
832 }
833 if ($mode == 2)
834 {
835 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
836 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
837 }
838 if ($mode == 3)
839 {
840 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
841 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
842 }
843 if ($mode == 4)
844 {
845 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
846 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
847 }
848 if ($mode == 5)
849 {
850 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
851 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
852 }
853 if ($mode == 6)
854 {
855 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
856 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
857 }*/
858 return '';
859 }
860
872 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1, $option = '')
873 {
874 global $conf, $langs, $hookmanager;
875
876 if (!empty($conf->dol_no_mouse_hover)) {
877 $notooltip = 1; // Force disable tooltips
878 }
879
880 $result = '';
881 $params = [
882 'id' => $this->id,
883 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
884 //'option' => $option,
885 ];
886 $classfortooltip = 'classfortooltip';
887 $dataparams = '';
888 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
889 $classfortooltip = 'classforajaxtooltip';
890 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
891 $label = '';
892 } else {
893 $label = implode($this->getTooltipContentArray($params));
894 }
895
896 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$this->id;
897
898 // if ($option !== 'nolink') {
899 // // Add param to save lastsearch_values or not
900 // $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
901 // if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
902 // $add_save_lastsearch_values = 1;
903 // }
904 // if ($url && $add_save_lastsearch_values) {
905 // $url .= '&save_lastsearch_values=1';
906 // }
907 // }
908
909 $linkclose = '';
910 if (empty($notooltip)) {
911 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
912 $label = $langs->trans("SalaryPayment");
913 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
914 }
915 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
916 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
917 } else {
918 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
919 }
920
921 if ($option == 'nolink') {
922 $linkstart = '<span';
923 } else {
924 $linkstart = '<a href="'.$url.'"';
925 }
926 $linkstart .= $linkclose.'>';
927 if ($option == 'nolink') {
928 $linkend = '</span>';
929 } else {
930 $linkend = '</a>';
931 }
932
933 $result .= $linkstart;
934
935 if (empty($this->showphoto_on_popup)) {
936 if ($withpicto) {
937 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
938 }
939 }
940
941 if ($withpicto != 2) {
942 $result .= $this->ref;
943 }
944
945 $result .= $linkend;
946 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
947
948 global $action, $hookmanager;
949 $hookmanager->initHooks(array($this->element.'dao'));
950 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
951 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
952 if ($reshook > 0) {
953 $result = $hookmanager->resPrint;
954 } else {
955 $result .= $hookmanager->resPrint;
956 }
957
958 return $result;
959 }
960
967 public function getTooltipContentArray($params)
968 {
969 global $conf, $langs, $user;
970
971 $langs->load('salaries');
972 $datas = [];
973
974 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
975 return ['optimize' => $langs->trans("SalaryPayment")];
976 }
977
978 if ($user->hasRight('salaries', 'read')) {
979 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("SalaryPayment").'</u>';
980 if (isset($this->status)) {
981 $datas['status'] = ' '.$this->getLibStatut(5);
982 }
983 $datas['Ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
984 if (!empty($this->total_ttc)) {
985 $datas['AmountTTC'] = '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
986 }
987 if (!empty($this->datep)) {
988 $datas['Date'] = '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datep, 'dayhour', 'tzuserrel');
989 } elseif (!empty($this->datepaye)) {
990 $datas['Date'] = '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datepaye, 'dayhour', 'tzuserrel');
991 }
992 }
993
994 return $datas;
995 }
996
1004 public function getKanbanView($option = '', $arraydata = null)
1005 {
1006 global $langs;
1007
1008 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1009
1010 $return = '<div class="box-flex-item box-flex-grow-zero">';
1011 $return .= '<div class="info-box info-box-sm">';
1012 $return .= '<span class="info-box-icon bg-infobox-action">';
1013 $return .= img_picto('', $this->picto);
1014 $return .= '</span>';
1015 $return .= '<div class="info-box-content">';
1016 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(1) . '</span>';
1017 if ($selected >= 0) {
1018 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1019 }
1020 if (!empty($this->fk_bank) && is_numeric($this->fk_bank)) {
1021 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1022 $account = new AccountLine($this->db);
1023 $account->fetch($this->fk_bank);
1024 $return .= ' | <span class="info-box-label">'.$account->getNomUrl(1).'</span>';
1025 }
1026 if (!empty($this->fk_user_author) && is_numeric($this->fk_user_author)) {
1027 $userstatic = new User($this->db);
1028 $userstatic->fetch($this->fk_user_author);
1029 $return .= '<br><span class="info-box-status">'.$userstatic->getNomUrl(1).'</span>';
1030 }
1031
1032 if (!empty($this->fk_typepayment)) {
1033 $return .= '<br><span class="opacitymedium">'.$langs->trans("PaymentMode").'</span> : <span class="info-box-label">'.$this->fk_typepayment.'</span>';
1034 }
1035 $return .= '<br><span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
1036 $return .= '</div>';
1037 $return .= '</div>';
1038 $return .= '</div>';
1039 return $return;
1040 }
1041}
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.
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
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.
price2num($amount, $rounding='', $option=0)
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