dolibarr 21.0.0-alpha
paymentsalary.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
3 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 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
86 public $total;
87
91 public $amount;
92
96 public $amounts = array();
97
101 public $fk_typepayment;
102
107 public $num_paiement;
108
113 public $num_payment;
114
118 public $fk_bank;
119
123 public $bank_line;
124
128 public $fk_user_author;
129
133 public $fk_user_modif;
134
138 public $type_code;
139
143 public $type_label;
144
148 public $bank_account;
149
153 public $datev = '';
154
158 public $fields = array(
159 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
160 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'visible' => 1, 'index' => 1, 'comment' => "Reference of object"),
161 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 20),
162 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'position' => 30),
163 'datep' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 40, 'comment' => 'Date'),
164 'datev' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 50, 'comment' => 'Date'),
165 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Employee', 'enabled' => 1, 'position' => 60, 'notnull' => 1, 'visible' => 1, 'picto' => 'user'),
166 'salary' => array('type' => 'double(24,8)', 'label' => 'salary', 'enabled' => 1, 'visible' => 0, 'position' => 70),
167 'amount' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 80),
168 'fk_projet' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'enabled' => "isModEnabled('project')", 'visible' => 0, 'position' => 90),
169 'fk_typepayment' => array('type' => 'typepayment', 'label' => 'DefaultPaymentMode', 'enabled' => 1, 'visible' => 1, 'position' => 100, 'comment' => 'Payment type'),
170 'num_payment' => array('type' => 'string', 'label' => 'Reference', 'enabled' => 1, 'visible' => 0, 'position' => 110, 'comment' => 'Reference'),
171 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 120, 'notnull' => 0, 'visible' => 1),
172 'datesp' => array('type' => 'date', 'label' => 'DateStart', 'enabled' => 1, 'visible' => 1, 'position' => 130, 'comment' => 'Date'),
173 'dateep' => array('type' => 'date', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => 1, 'position' => 140, 'comment' => 'Date'),
174 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => 0, 'position' => 150, 'index' => 1),
175 'note' => array('type' => 'text', 'label' => 'Note', 'enabled' => 1, 'position' => 160, 'visible' => 0,),
176 'fk_bank' => array('type' => 'integer', 'label' => 'BankId', 'enabled' => 1, 'visible' => 0, 'position' => 170),
177 'paye' => array('type' => 'smallint(6)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 180),
178 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => 0, 'position' => 190),
179 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 200, 'visible' => 0,),
180 'ref_ext' => array('type' => 'varchar(128)', 'label' => 'Ref ext', 'enabled' => 1, 'visible' => 0, 'position' => 210),
181 'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 220),
182 );
183
189 public function __construct($db)
190 {
191 $this->db = $db;
192 }
193
202 public function create($user, $closepaidcontrib = 0)
203 {
204 global $conf;
205
206 $error = 0;
207
208 $now = dol_now();
209
210 dol_syslog(get_class($this)."::create", LOG_DEBUG);
211
212 //deprecatd
213 if (!empty($this->datepaye) && empty($this->datep)) {
214 dol_syslog(__METHOD__.": using datepaye is deprecated, please use datep instead", LOG_WARNING);
215 $this->datep = $this->datepaye;
216 }
217
218 // Validate parameters
219 if (empty($this->datep)) {
220 $this->error = 'ErrorBadValueForParameterCreatePaymentSalary';
221 return -1;
222 }
223
224 // Clean parameters
225 if (isset($this->fk_salary)) {
226 $this->fk_salary = (int) $this->fk_salary;
227 }
228 if (isset($this->amount)) {
229 $this->amount = (float) $this->amount;
230 }
231 if (isset($this->fk_typepayment)) {
232 $this->fk_typepayment = (int) $this->fk_typepayment;
233 }
234 if (isset($this->num_paiement)) {
235 $this->num_paiement = trim($this->num_paiement);
236 } // deprecated
237 if (isset($this->num_payment)) {
238 $this->num_payment = trim($this->num_payment);
239 }
240 if (isset($this->note)) {
241 $this->note = trim($this->note);
242 }
243 if (isset($this->fk_bank)) {
244 $this->fk_bank = (int) $this->fk_bank;
245 }
246 if (isset($this->fk_user_author)) {
247 $this->fk_user_author = (int) $this->fk_user_author;
248 }
249 if (isset($this->fk_user_modif)) {
250 $this->fk_user_modif = (int) $this->fk_user_modif;
251 }
252
253 $totalamount = 0;
254 foreach ($this->amounts as $key => $value) { // How payment is dispatch
255 $newvalue = (float) price2num($value, 'MT');
256 $this->amounts[$key] = $newvalue;
257 $totalamount += $newvalue;
258 }
259
260 // Check parameters
261 $totalamount = (float) price2num($totalamount, 'MT'); // this is to ensure the following test is no biaised by a potential float equal to 0.0000000000001
262 if ($totalamount == 0) {
263 return -1;
264 } // On accepte les montants negatifs pour les rejets de prelevement mais pas null
265
266
267 $this->db->begin();
268
269 if ($totalamount != 0) {
270 // Insert array of amounts
271 foreach ($this->amounts as $key => $amount) {
272 $salary_id = $key;
273 if (is_numeric($amount) && !empty($amount)) {
274 // 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).
275 $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (entity, fk_salary, datec, datep, amount,";
276 $sql .= " fk_typepayment, num_payment, note, fk_user_author, fk_bank)";
277 $sql .= " VALUES (".((int) $conf->entity).", ".((int) $salary_id).", '".$this->db->idate($now)."',";
278 $sql .= " '".$this->db->idate($this->datep)."',";
279 $sql .= " ".((float) $amount).",";
280 $sql .= " ".((int) $this->fk_typepayment).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".((int) $user->id).",";
281 $sql .= " 0)";
282
283 $resql = $this->db->query($sql);
284 if ($resql) {
285 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary");
286 }
287
288 // If we want to closed paid invoices
289 if ($closepaidcontrib) {
290 $tmpsalary = new Salary($this->db);
291 $tmpsalary->fetch($salary_id);
292 $paiement = $tmpsalary->getSommePaiement();
293 //$creditnotes=$tmpsalary->getSumCreditNotesUsed();
294 $creditnotes = 0;
295 //$deposits=$tmpsalary->getSumDepositsUsed();
296 $deposits = 0;
297 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
298 $remaintopay = price2num($tmpsalary->amount - $paiement - $creditnotes - $deposits, 'MT');
299 if ($remaintopay == 0) {
300 $result = $tmpsalary->setPaid($user);
301 } else {
302 dol_syslog("Remain to pay for salary id=".$salary_id." not null. We do nothing.");
303 }
304 }
305 }
306 }
307 }
308
309 $result = $this->call_trigger('PAYMENTSALARY_CREATE', $user);
310 if ($result < 0) {
311 $error++;
312 }
313
314 if ($totalamount != 0 && !$error) {
315 $this->amount = $totalamount;
316 $this->total = $totalamount; // deprecated
317 $this->db->commit();
318 return $this->id; // id of the last payment inserted
319 } else {
320 $this->error = $this->db->error();
321 $this->db->rollback();
322 return -1;
323 }
324 }
325
332 public function fetch($id)
333 {
334 global $langs;
335 $sql = "SELECT";
336 $sql .= " t.rowid,";
337 $sql .= " t.fk_salary,";
338 $sql .= " t.datec,";
339 $sql .= " t.tms,";
340 $sql .= " t.datep,";
341 $sql .= " t.amount,";
342 $sql .= " t.fk_typepayment,";
343 $sql .= " t.num_payment as num_payment,";
344 $sql .= " t.note,";
345 $sql .= " t.fk_bank,";
346 $sql .= " t.fk_user_author,";
347 $sql .= " t.fk_user_modif,";
348 $sql .= " pt.code as type_code, pt.libelle as type_label,";
349 $sql .= ' b.fk_account';
350 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id";
351 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
352 $sql .= " WHERE t.rowid = ".((int) $id);
353 // TODO link on entity of tax;
354
355 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
356 $resql = $this->db->query($sql);
357 if ($resql) {
358 if ($this->db->num_rows($resql)) {
359 $obj = $this->db->fetch_object($resql);
360
361 $this->id = $obj->rowid;
362 $this->ref = $obj->rowid;
363
364 $this->fk_salary = $obj->fk_salary;
365 $this->datec = $this->db->jdate($obj->datec);
366 $this->tms = $this->db->jdate($obj->tms);
367 $this->datepaye = $this->db->jdate($obj->datep);
368 $this->amount = $obj->amount;
369 $this->fk_typepayment = $obj->fk_typepayment;
370 $this->num_paiement = $obj->num_payment;
371 $this->num_payment = $obj->num_payment;
372 $this->note = $obj->note;
373 $this->note_private = $obj->note;
374 $this->fk_bank = $obj->fk_bank;
375 $this->fk_user_author = $obj->fk_user_author;
376 $this->fk_user_modif = $obj->fk_user_modif;
377
378 $this->type_code = $obj->type_code;
379 $this->type_label = $obj->type_label;
380
381 $this->bank_account = $obj->fk_account;
382 $this->bank_line = $obj->fk_bank;
383 }
384 $this->db->free($resql);
385
386 return 1;
387 } else {
388 $this->error = "Error ".$this->db->lasterror();
389 return -1;
390 }
391 }
392
393
401 public function update($user = null, $notrigger = 0)
402 {
403 global $conf, $langs;
404 $error = 0;
405
406 // Clean parameters
407
408 if (isset($this->fk_salary)) {
409 $this->fk_salary = (int) $this->fk_salary;
410 }
411 if (isset($this->amount)) {
412 $this->amount = (float) $this->amount;
413 }
414 if (isset($this->fk_typepayment)) {
415 $this->fk_typepayment = (int) $this->fk_typepayment;
416 }
417 if (isset($this->num_paiement)) {
418 $this->num_paiement = trim($this->num_paiement);
419 } // deprecated
420 if (isset($this->num_payment)) {
421 $this->num_payment = trim($this->num_payment);
422 }
423 if (isset($this->note)) {
424 $this->note = trim($this->note);
425 }
426 if (isset($this->fk_bank)) {
427 $this->fk_bank = (int) $this->fk_bank;
428 }
429 if (isset($this->fk_user_author)) {
430 $this->fk_user_author = (int) $this->fk_user_author;
431 }
432 if (isset($this->fk_user_modif)) {
433 $this->fk_user_modif = (int) $this->fk_user_modif;
434 }
435
436 // Check parameters
437 // Put here code to add control on parameters values
438
439 // Update request
440 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET";
441 $sql .= " fk_salary=".(isset($this->fk_salary) ? $this->fk_salary : "null").",";
442 $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
443 $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
444 $sql .= " datep=".(dol_strlen($this->datepaye) != 0 ? "'".$this->db->idate($this->datepaye)."'" : 'null').",";
445 $sql .= " amount=".(isset($this->amount) ? $this->amount : "null").",";
446 $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").",";
447 $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").",";
448 $sql .= " note=".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : "null").",";
449 $sql .= " fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) : "null").",";
450 $sql .= " fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) : "null").",";
451 $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) : "null");
452 $sql .= " WHERE rowid=".((int) $this->id);
453
454 $this->db->begin();
455
456 dol_syslog(get_class($this)."::update", LOG_DEBUG);
457 $resql = $this->db->query($sql);
458 if (!$resql) {
459 $error++;
460 $this->errors[] = "Error ".$this->db->lasterror();
461 }
462
463 // Commit or rollback
464 if ($error) {
465 foreach ($this->errors as $errmsg) {
466 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
467 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
468 }
469 $this->db->rollback();
470 return -1 * $error;
471 } else {
472 $this->db->commit();
473 return 1;
474 }
475 }
476
477
485 public function delete($user, $notrigger = 0)
486 {
487 $error = 0;
488
489 dol_syslog(get_class($this)."::delete");
490
491 $this->db->begin();
492
493 if ($this->bank_line > 0) {
494 $accline = new AccountLine($this->db);
495 $accline->fetch($this->bank_line);
496 $result = $accline->delete($user);
497 if ($result < 0) {
498 $this->errors[] = $accline->error;
499 $error++;
500 }
501 }
502
503 if (!$error) {
504 $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary";
505 $sql .= " WHERE rowid=".((int) $this->id);
506
507 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
508 $resql = $this->db->query($sql);
509 if (!$resql) {
510 $error++;
511 $this->errors[] = "Error ".$this->db->lasterror();
512 }
513 }
514
515 // Commit or rollback
516 if ($error) {
517 foreach ($this->errors as $errmsg) {
518 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
519 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
520 }
521 $this->db->rollback();
522 return -1 * $error;
523 } else {
524 $this->db->commit();
525 return 1;
526 }
527 }
528
529
530
538 public function createFromClone(User $user, $fromid)
539 {
540 $error = 0;
541
542 $object = new PaymentSalary($this->db);
543
544 $this->db->begin();
545
546 // Load source object
547 $object->fetch($fromid);
548 $object->id = 0;
549 $object->statut = 0;
550
551 // Clear fields
552 // ...
553
554 // Create clone
555 $object->context['createfromclone'] = 'createfromclone';
556 $result = $object->create($user);
557
558 // Other options
559 if ($result < 0) {
560 $this->error = $object->error;
561 $error++;
562 }
563
564 unset($object->context['createfromclone']);
565
566 // End
567 if (!$error) {
568 $this->db->commit();
569 return $object->id;
570 } else {
571 $this->db->rollback();
572 return -1;
573 }
574 }
575
576
584 public function initAsSpecimen()
585 {
586 $this->id = 0;
587 $this->fk_salary = 0;
588 $this->datec = '';
589 $this->tms = dol_now();
590 $this->datepaye = dol_now();
591 $this->amount = 0.0;
592 $this->fk_typepayment = 0;
593 $this->num_payment = '';
594 $this->note_private = '';
595 $this->note_public = '';
596 $this->fk_bank = 0;
597 $this->fk_user_author = 0;
598 $this->fk_user_modif = 0;
599
600 return 1;
601 }
602
603
616 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
617 {
618 global $langs;
619
620 // Clean data
621 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
622
623 $error = 0;
624
625 if (isModEnabled("bank")) {
626 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
627
628 $acc = new Account($this->db);
629 $acc->fetch($accountid);
630
631 $total = $this->amount;
632
633 // Insert payment into llx_bank
634 $bank_line_id = $acc->addline(
635 $this->datep,
636 $this->fk_typepayment, // Payment mode id or code ("CHQ or VIR for example")
637 $label,
638 -$total,
639 $this->num_payment,
640 '',
641 $user,
642 $emetteur_nom,
643 $emetteur_banque,
644 '',
645 $this->datev
646 );
647
648 // Update fk_bank into llx_paiement_salary.
649 // so we know the payment that was used to generated the bank entry.
650 if ($bank_line_id > 0) {
651 $result = $this->update_fk_bank($bank_line_id);
652 if ($result <= 0) {
653 $error++;
654 dol_print_error($this->db);
655 }
656
657 // Add link 'payment_salary' in bank_url between payment and bank transaction
658 $url = '';
659 if ($mode == 'payment_salary') {
660 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id=';
661 }
662
663 if ($url) {
664 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
665 if ($result <= 0) {
666 $error++;
667 dol_print_error($this->db);
668 }
669 }
670
671 // Add link 'user' in bank_url between user and bank transaction
672 foreach ($this->amounts as $key => $value) {
673 if (!$error) {
674 if ($mode == 'payment_salary') {
675 $salary = new Salary($this->db);
676 $salary->fetch($key);
677 $salary->fetch_user($salary->fk_user);
678
679 $fuser = $salary->user;
680
681 if ($fuser->id > 0) {
682 $result = $acc->add_url_line(
683 $bank_line_id,
684 $fuser->id,
685 DOL_URL_ROOT.'/user/card.php?id=',
686 $fuser->getFullName($langs),
687 'user'
688 );
689 }
690 if ($result <= 0) {
691 $this->error = $this->db->lasterror();
692 dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->error);
693 $error++;
694 }
695 }
696 }
697 }
698 } else {
699 $this->error = $acc->error;
700 $error++;
701 }
702 }
703
704 if (!$error) {
705 return 1;
706 } else {
707 return -1;
708 }
709 }
710
711
712 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
719 public function update_fk_bank($id_bank)
720 {
721 // phpcs:enable
722 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id);
723
724 dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
725 $result = $this->db->query($sql);
726 if ($result) {
727 return 1;
728 } else {
729 $this->error = $this->db->error();
730 return 0;
731 }
732 }
733
741 public function updatePaymentDate($date)
742 {
743 $error = 0;
744
745 if (!empty($date)) {
746 $this->db->begin();
747
748 dol_syslog(get_class($this)."::updatePaymentDate with date = ".$date, LOG_DEBUG);
749
750 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
751 $sql .= " SET datep = '".$this->db->idate($date)."'";
752 $sql .= " WHERE rowid = ".((int) $this->id);
753
754 $result = $this->db->query($sql);
755 if (!$result) {
756 $error++;
757 $this->error = 'Error -1 '.$this->db->error();
758 }
759
760 $type = $this->element;
761
762 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
763 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
764 $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).")";
765 $sql .= " AND rappro = 0";
766
767 $result = $this->db->query($sql);
768 if (!$result) {
769 $error++;
770 $this->error = 'Error -1 '.$this->db->error();
771 }
772
773 if (!$error) {
774 }
775
776 if (!$error) {
777 $this->datepaye = $date;
778
779 $this->db->commit();
780 return 0;
781 } else {
782 $this->db->rollback();
783 return -2;
784 }
785 }
786 return -1; //no date given or already validated
787 }
788
795 public function getLibStatut($mode = 0)
796 {
797 return $this->LibStatut($this->statut, $mode);
798 }
799
800 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
808 public function LibStatut($status, $mode = 0)
809 {
810 // phpcs:enable
811 global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
812
813 $langs->load('compta');
814 /*if ($mode == 0)
815 {
816 if ($status == 0) return $langs->trans('ToValidate');
817 if ($status == 1) return $langs->trans('Validated');
818 }
819 if ($mode == 1)
820 {
821 if ($status == 0) return $langs->trans('ToValidate');
822 if ($status == 1) return $langs->trans('Validated');
823 }
824 if ($mode == 2)
825 {
826 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
827 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
828 }
829 if ($mode == 3)
830 {
831 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
832 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
833 }
834 if ($mode == 4)
835 {
836 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
837 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
838 }
839 if ($mode == 5)
840 {
841 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
842 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
843 }
844 if ($mode == 6)
845 {
846 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
847 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
848 }*/
849 return '';
850 }
851
862 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
863 {
864 global $conf, $langs, $hookmanager;
865
866 $option = '';
867
868 if (!empty($conf->dol_no_mouse_hover)) {
869 $notooltip = 1; // Force disable tooltips
870 }
871
872 $result = '';
873 $params = [
874 'id' => $this->id,
875 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
876 //'option' => $option,
877 ];
878 $classfortooltip = 'classfortooltip';
879 $dataparams = '';
880 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
881 $classfortooltip = 'classforajaxtooltip';
882 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
883 $label = '';
884 } else {
885 $label = implode($this->getTooltipContentArray($params));
886 }
887
888 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$this->id;
889
890 if ($option !== 'nolink') {
891 // Add param to save lastsearch_values or not
892 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
893 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
894 $add_save_lastsearch_values = 1;
895 }
896 if ($url && $add_save_lastsearch_values) {
897 $url .= '&save_lastsearch_values=1';
898 }
899 }
900
901 $linkclose = '';
902 if (empty($notooltip)) {
903 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
904 $label = $langs->trans("SalaryPayment");
905 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
906 }
907 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
908 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
909 } else {
910 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
911 }
912
913 if ($option == 'nolink' || empty($url)) {
914 $linkstart = '<span';
915 } else {
916 $linkstart = '<a href="'.$url.'"';
917 }
918 $linkstart .= $linkclose.'>';
919 if ($option == 'nolink' || empty($url)) {
920 $linkend = '</span>';
921 } else {
922 $linkend = '</a>';
923 }
924
925 $result .= $linkstart;
926
927 if (empty($this->showphoto_on_popup)) {
928 if ($withpicto) {
929 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
930 }
931 }
932
933 if ($withpicto != 2) {
934 $result .= $this->ref;
935 }
936
937 $result .= $linkend;
938 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
939
940 global $action, $hookmanager;
941 $hookmanager->initHooks(array($this->element.'dao'));
942 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
943 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
944 if ($reshook > 0) {
945 $result = $hookmanager->resPrint;
946 } else {
947 $result .= $hookmanager->resPrint;
948 }
949
950 return $result;
951 }
952
959 public function getTooltipContentArray($params)
960 {
961 global $conf, $langs, $user;
962
963 $langs->load('salaries');
964 $datas = [];
965
966 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
967 return ['optimize' => $langs->trans("SalaryPayment")];
968 }
969
970 if ($user->hasRight('salaries', 'read')) {
971 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("SalaryPayment").'</u>';
972 if (isset($this->status)) {
973 $datas['status'] = ' '.$this->getLibStatut(5);
974 }
975 $datas['Ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
976 if (!empty($this->total_ttc)) {
977 $datas['AmountTTC'] = '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
978 }
979 if (!empty($this->datep)) {
980 $datas['Date'] = '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datep, 'dayhour', 'tzuserrel');
981 } elseif (!empty($this->datepaye)) {
982 $datas['Date'] = '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datepaye, 'dayhour', 'tzuserrel');
983 }
984 }
985
986 return $datas;
987 }
988
996 public function getKanbanView($option = '', $arraydata = null)
997 {
998 global $langs;
999
1000 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1001
1002 $return = '<div class="box-flex-item box-flex-grow-zero">';
1003 $return .= '<div class="info-box info-box-sm">';
1004 $return .= '<span class="info-box-icon bg-infobox-action">';
1005 $return .= img_picto('', $this->picto);
1006 $return .= '</span>';
1007 $return .= '<div class="info-box-content">';
1008 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
1009 if ($selected >= 0) {
1010 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1011 }
1012 if (property_exists($this, 'fk_bank') && is_numeric($this->fk_bank)) {
1013 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1014 $account = new AccountLine($this->db);
1015 $account->fetch($this->fk_bank);
1016 $return .= ' | <span class="info-box-label">'.$account->getNomUrl(1).'</span>';
1017 }
1018 if (property_exists($this, 'fk_user_author') && is_numeric($this->fk_user_author)) {
1019 $userstatic = new User($this->db);
1020 $userstatic->fetch($this->fk_user_author);
1021 $return .= '<br><span class="info-box-status">'.$userstatic->getNomUrl(1).'</span>';
1022 }
1023
1024 if (property_exists($this, 'fk_typepayment')) {
1025 $return .= '<br><span class="opacitymedium">'.$langs->trans("PaymentMode").'</span> : <span class="info-box-label">'.$this->fk_typepayment.'</span>';
1026 }
1027 if (property_exists($this, 'amount')) {
1028 $return .= '<br><span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
1029 }
1030 $return .= '</div>';
1031 $return .= '</div>';
1032 $return .= '</div>';
1033 return $return;
1034 }
1035}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:626
$object ref
Definition info.php:79
Class to manage bank accounts.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage payments of salaries.
LibStatut($status, $mode=0)
Return the status.
update_fk_bank($id_bank)
Mise a jour du lien entre le paiement de salaire et la ligne dans llx_bank generee.
updatePaymentDate($date)
Updates the payment date.
getLibStatut($mode=0)
Return the label of the status.
initAsSpecimen()
Initialise an instance with random values.
getNomUrl($withpicto=0, $maxlen=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
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.
getKanbanView($option='', $arraydata=null)
Return clicable 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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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 '.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
Definition invoice.php:1929