dolibarr 21.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 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
87 public $total;
88
92 public $amount;
93
97 public $amounts = array();
98
102 public $fk_typepayment;
103
108 public $num_paiement;
109
114 public $num_payment;
115
120 public $fk_bank;
121
125 public $bank_line;
126
130 public $fk_user_author;
131
135 public $fk_user_modif;
136
140 public $type_code;
141
145 public $type_label;
146
150 public $bank_account;
151
155 public $datev = '';
156
160 public $fields = array(
161 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
162 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'visible' => 1, 'index' => 1, 'comment' => "Reference of object"),
163 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 20),
164 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'position' => 30),
165 'datep' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 40, 'comment' => 'Date'),
166 'datev' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 50, 'comment' => 'Date'),
167 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Employee', 'enabled' => 1, 'position' => 60, 'notnull' => 1, 'visible' => 1, 'picto' => 'user'),
168 'salary' => array('type' => 'double(24,8)', 'label' => 'salary', 'enabled' => 1, 'visible' => 0, 'position' => 70),
169 'amount' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 80),
170 'fk_projet' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'enabled' => "isModEnabled('project')", 'visible' => 0, 'position' => 90),
171 'fk_typepayment' => array('type' => 'typepayment', 'label' => 'DefaultPaymentMode', 'enabled' => 1, 'visible' => 1, 'position' => 100, 'comment' => 'Payment type'),
172 'num_payment' => array('type' => 'string', 'label' => 'Reference', 'enabled' => 1, 'visible' => 0, 'position' => 110, 'comment' => 'Reference'),
173 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 120, 'notnull' => 0, 'visible' => 1),
174 'datesp' => array('type' => 'date', 'label' => 'DateStart', 'enabled' => 1, 'visible' => 1, 'position' => 130, 'comment' => 'Date'),
175 'dateep' => array('type' => 'date', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => 1, 'position' => 140, 'comment' => 'Date'),
176 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => 0, 'position' => 150, 'index' => 1),
177 'note' => array('type' => 'text', 'label' => 'Note', 'enabled' => 1, 'position' => 160, 'visible' => 0,),
178 'fk_bank' => array('type' => 'integer', 'label' => 'BankId', 'enabled' => 1, 'visible' => 0, 'position' => 170),
179 'paye' => array('type' => 'smallint(6)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 180),
180 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => 0, 'position' => 190),
181 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 200, 'visible' => 0,),
182 'ref_ext' => array('type' => 'varchar(128)', 'label' => 'Ref ext', 'enabled' => 1, 'visible' => 0, 'position' => 210),
183 'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 220),
184 );
185
191 public function __construct($db)
192 {
193 $this->db = $db;
194 }
195
204 public function create($user, $closepaidcontrib = 0)
205 {
206 global $conf;
207
208 $error = 0;
209
210 $now = dol_now();
211
212 dol_syslog(get_class($this)."::create", LOG_DEBUG);
213
214 //deprecated
215 if (!empty($this->datepaye) && empty($this->datep)) {
216 dol_syslog(__METHOD__.": using datepaye is deprecated, please use datep instead", LOG_WARNING);
217 $this->datep = $this->datepaye;
218 }
219
220 // Validate parameters
221 if (empty($this->datep)) {
222 $this->error = 'ErrorBadValueForParameterCreatePaymentSalary';
223 return -1;
224 }
225
226 // Clean parameters
227 if (isset($this->fk_salary)) {
228 $this->fk_salary = (int) $this->fk_salary;
229 }
230 if (isset($this->amount)) {
231 $this->amount = (float) $this->amount;
232 }
233 if (isset($this->fk_typepayment)) {
234 $this->fk_typepayment = (int) $this->fk_typepayment;
235 }
236 if (isset($this->num_paiement)) {
237 $this->num_paiement = trim($this->num_paiement);
238 } // deprecated
239 if (isset($this->num_payment)) {
240 $this->num_payment = trim($this->num_payment);
241 }
242 if (isset($this->note)) {
243 $this->note = trim($this->note);
244 }
245 if (isset($this->fk_bank)) {
246 $this->fk_bank = (int) $this->fk_bank;
247 }
248 if (isset($this->fk_user_author)) {
249 $this->fk_user_author = (int) $this->fk_user_author;
250 }
251 if (isset($this->fk_user_modif)) {
252 $this->fk_user_modif = (int) $this->fk_user_modif;
253 }
254
255 $totalamount = 0;
256 foreach ($this->amounts as $key => $value) { // How payment is dispatch
257 $newvalue = (float) price2num($value, 'MT');
258 $this->amounts[$key] = $newvalue;
259 $totalamount += $newvalue;
260 }
261
262 // Check parameters
263 $totalamount = (float) price2num($totalamount, 'MT'); // this is to ensure the following test is no biaised by a potential float equal to 0.0000000000001
264 if ($totalamount == 0) {
265 return -1;
266 } // On accepte les montants negatifs pour les rejets de prelevement mais pas null
267
268
269 $this->db->begin();
270
271 if ($totalamount != 0) {
272 // Insert array of amounts
273 foreach ($this->amounts as $key => $amount) {
274 $salary_id = $key;
275 if (is_numeric($amount) && !empty($amount)) {
276 // 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).
277 $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (entity, fk_salary, datec, datep, amount,";
278 $sql .= " fk_typepayment, num_payment, note, fk_user_author, fk_bank)";
279 $sql .= " VALUES (".((int) $conf->entity).", ".((int) $salary_id).", '".$this->db->idate($now)."',";
280 $sql .= " '".$this->db->idate($this->datep)."',";
281 $sql .= " ".((float) $amount).",";
282 $sql .= " ".((int) $this->fk_typepayment).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".((int) $user->id).",";
283 $sql .= " 0)";
284
285 $resql = $this->db->query($sql);
286 if ($resql) {
287 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary");
288 }
289
290 // If we want to closed paid invoices
291 if ($closepaidcontrib) {
292 $tmpsalary = new Salary($this->db);
293 $tmpsalary->fetch($salary_id);
294 $paiement = $tmpsalary->getSommePaiement();
295 //$creditnotes=$tmpsalary->getSumCreditNotesUsed();
296 $creditnotes = 0;
297 //$deposits=$tmpsalary->getSumDepositsUsed();
298 $deposits = 0;
299 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
300 $remaintopay = price2num((float) $tmpsalary->amount - $paiement - $creditnotes - $deposits, 'MT');
301 if ($remaintopay == 0) {
302 $result = $tmpsalary->setPaid($user);
303 } else {
304 dol_syslog("Remain to pay for salary id=".$salary_id." not null. We do nothing.");
305 }
306 }
307 }
308 }
309 }
310
311 $result = $this->call_trigger('PAYMENTSALARY_CREATE', $user);
312 if ($result < 0) {
313 $error++;
314 }
315
316 if ($totalamount != 0 && !$error) {
317 $this->amount = $totalamount;
318 $this->total = $totalamount; // deprecated
319 $this->db->commit();
320 return $this->id; // id of the last payment inserted
321 } else {
322 $this->error = $this->db->error();
323 $this->db->rollback();
324 return -1;
325 }
326 }
327
334 public function fetch($id)
335 {
336 global $langs;
337 $sql = "SELECT";
338 $sql .= " t.rowid,";
339 $sql .= " t.fk_salary,";
340 $sql .= " t.datec,";
341 $sql .= " t.tms,";
342 $sql .= " t.datep,";
343 $sql .= " t.amount,";
344 $sql .= " t.fk_typepayment,";
345 $sql .= " t.num_payment as num_payment,";
346 $sql .= " t.note,";
347 $sql .= " t.fk_bank,";
348 $sql .= " t.fk_user_author,";
349 $sql .= " t.fk_user_modif,";
350 $sql .= " pt.code as type_code, pt.libelle as type_label,";
351 $sql .= ' b.fk_account';
352 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id";
353 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
354 $sql .= " WHERE t.rowid = ".((int) $id);
355 // TODO link on entity of tax;
356
357 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
358 $resql = $this->db->query($sql);
359 if ($resql) {
360 if ($this->db->num_rows($resql)) {
361 $obj = $this->db->fetch_object($resql);
362
363 $this->id = $obj->rowid;
364 $this->ref = $obj->rowid;
365
366 $this->fk_salary = $obj->fk_salary;
367 $this->datec = $this->db->jdate($obj->datec);
368 $this->tms = $this->db->jdate($obj->tms);
369 $this->datepaye = $this->db->jdate($obj->datep);
370 $this->datep = $this->db->jdate($obj->datep);
371 $this->amount = $obj->amount;
372 $this->fk_typepayment = $obj->fk_typepayment;
373 $this->num_paiement = $obj->num_payment;
374 $this->num_payment = $obj->num_payment;
375 $this->note = $obj->note;
376 $this->note_private = $obj->note;
377 $this->fk_bank = $obj->fk_bank;
378 $this->fk_user_author = $obj->fk_user_author;
379 $this->fk_user_modif = $obj->fk_user_modif;
380
381 $this->type_code = $obj->type_code;
382 $this->type_label = $obj->type_label;
383
384 $this->bank_account = $obj->fk_account;
385 $this->bank_line = $obj->fk_bank;
386 }
387 $this->db->free($resql);
388
389 return 1;
390 } else {
391 $this->error = "Error ".$this->db->lasterror();
392 return -1;
393 }
394 }
395
396
404 public function update($user = null, $notrigger = 0)
405 {
406 global $conf, $langs;
407 $error = 0;
408
409 // Clean parameters
410
411 if (isset($this->fk_salary)) {
412 $this->fk_salary = (int) $this->fk_salary;
413 }
414 if (isset($this->amount)) {
415 $this->amount = (float) $this->amount;
416 }
417 if (isset($this->fk_typepayment)) {
418 $this->fk_typepayment = (int) $this->fk_typepayment;
419 }
420 if (isset($this->num_paiement)) {
421 $this->num_paiement = trim($this->num_paiement);
422 } // deprecated
423 if (isset($this->num_payment)) {
424 $this->num_payment = trim($this->num_payment);
425 }
426 if (isset($this->note)) {
427 $this->note = trim($this->note);
428 }
429 if (isset($this->fk_bank)) {
430 $this->fk_bank = (int) $this->fk_bank;
431 }
432 if (isset($this->fk_user_author)) {
433 $this->fk_user_author = (int) $this->fk_user_author;
434 }
435 if (isset($this->fk_user_modif)) {
436 $this->fk_user_modif = (int) $this->fk_user_modif;
437 }
438
439 // Check parameters
440 // Put here code to add control on parameters values
441
442 // Update request
443 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET";
444 $sql .= " fk_salary=".(isset($this->fk_salary) ? $this->fk_salary : "null").",";
445 $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
446 $sql .= " tms=".(dol_strlen((string) $this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
447 $sql .= " datep=".(dol_strlen($this->datepaye) != 0 ? "'".$this->db->idate($this->datepaye)."'" : 'null').",";
448 $sql .= " amount=".(isset($this->amount) ? $this->amount : "null").",";
449 $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").",";
450 $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").",";
451 $sql .= " note=".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : "null").",";
452 $sql .= " fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) : "null").",";
453 $sql .= " fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) : "null").",";
454 $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) : "null");
455 $sql .= " WHERE rowid=".((int) $this->id);
456
457 $this->db->begin();
458
459 dol_syslog(get_class($this)."::update", LOG_DEBUG);
460 $resql = $this->db->query($sql);
461 if (!$resql) {
462 $error++;
463 $this->errors[] = "Error ".$this->db->lasterror();
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($this->bank_line);
499 $result = $accline->delete($user);
500 if ($result < 0) {
501 $this->errors[] = $accline->error;
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 // Commit or rollback
519 if ($error) {
520 foreach ($this->errors as $errmsg) {
521 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
522 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
523 }
524 $this->db->rollback();
525 return -1 * $error;
526 } else {
527 $this->db->commit();
528 return 1;
529 }
530 }
531
532
533
541 public function createFromClone(User $user, $fromid)
542 {
543 $error = 0;
544
545 $object = new PaymentSalary($this->db);
546
547 $this->db->begin();
548
549 // Load source object
550 $object->fetch($fromid);
551 $object->id = 0;
552 $object->statut = 0;
553
554 // Clear fields
555 // ...
556
557 // Create clone
558 $object->context['createfromclone'] = 'createfromclone';
559 $result = $object->create($user);
560
561 // Other options
562 if ($result < 0) {
563 $this->error = $object->error;
564 $error++;
565 }
566
567 unset($object->context['createfromclone']);
568
569 // End
570 if (!$error) {
571 $this->db->commit();
572 return $object->id;
573 } else {
574 $this->db->rollback();
575 return -1;
576 }
577 }
578
579
587 public function initAsSpecimen()
588 {
589 $this->id = 0;
590 $this->fk_salary = 0;
591 $this->datec = '';
592 $this->tms = dol_now();
593 $this->datepaye = dol_now();
594 $this->amount = 0.0;
595 $this->fk_typepayment = 0;
596 $this->num_payment = '';
597 $this->note_private = '';
598 $this->note_public = '';
599 $this->fk_bank = 0;
600 $this->fk_user_author = 0;
601 $this->fk_user_modif = 0;
602
603 return 1;
604 }
605
606
619 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
620 {
621 global $langs;
622
623 // Clean data
624 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
625
626 $error = 0;
627
628 if (isModEnabled("bank")) {
629 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
630
631 $acc = new Account($this->db);
632 $acc->fetch($accountid);
633
634 $total = $this->amount;
635
636 // Insert payment into llx_bank
637 $bank_line_id = $acc->addline(
638 $this->datep,
639 $this->fk_typepayment, // Payment mode id or code ("CHQ or VIR for example")
640 $label,
641 -$total,
642 $this->num_payment,
643 0,
644 $user,
645 $emetteur_nom,
646 $emetteur_banque,
647 '',
648 $this->datev
649 );
650
651 // Update fk_bank into llx_paiement_salary.
652 // so we know the payment that was used to generated the bank entry.
653 if ($bank_line_id > 0) {
654 $result = $this->update_fk_bank($bank_line_id);
655 if ($result <= 0) {
656 $error++;
657 dol_print_error($this->db);
658 }
659
660 // Add link 'payment_salary' in bank_url between payment and bank transaction
661 $url = '';
662 if ($mode == 'payment_salary') {
663 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id=';
664 }
665
666 if ($url) {
667 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
668 if ($result <= 0) {
669 $error++;
670 dol_print_error($this->db);
671 }
672 }
673
674 // Add link 'user' in bank_url between user and bank transaction
675 foreach ($this->amounts as $key => $value) {
676 if (!$error) {
677 if ($mode == 'payment_salary') {
678 $salary = new Salary($this->db);
679 $salary->fetch($key);
680 $salary->fetch_user($salary->fk_user);
681
682 $fuser = $salary->user;
683
684 if ($fuser->id > 0) {
685 $result = $acc->add_url_line(
686 $bank_line_id,
687 $fuser->id,
688 DOL_URL_ROOT.'/user/card.php?id=',
689 $fuser->getFullName($langs),
690 'user'
691 );
692 }
693 if ($result <= 0) {
694 $this->error = $this->db->lasterror();
695 dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->error);
696 $error++;
697 }
698 }
699 }
700 }
701 } else {
702 $this->error = $acc->error;
703 $error++;
704 }
705 }
706
707 if (!$error) {
708 return 1;
709 } else {
710 return -1;
711 }
712 }
713
714
715 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
722 public function update_fk_bank($id_bank)
723 {
724 // phpcs:enable
725 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id);
726
727 dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
728 $result = $this->db->query($sql);
729 if ($result) {
730 return 1;
731 } else {
732 $this->error = $this->db->error();
733 return 0;
734 }
735 }
736
744 public function updatePaymentDate($date)
745 {
746 $error = 0;
747
748 if (!empty($date)) {
749 $this->db->begin();
750
751 dol_syslog(get_class($this)."::updatePaymentDate with date = ".$date, LOG_DEBUG);
752
753 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
754 $sql .= " SET datep = '".$this->db->idate($date)."'";
755 $sql .= " WHERE rowid = ".((int) $this->id);
756
757 $result = $this->db->query($sql);
758 if (!$result) {
759 $error++;
760 $this->error = 'Error -1 '.$this->db->error();
761 }
762
763 $type = $this->element;
764
765 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
766 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
767 $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).")";
768 $sql .= " AND rappro = 0";
769
770 $result = $this->db->query($sql);
771 if (!$result) {
772 $error++;
773 $this->error = 'Error -1 '.$this->db->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:66
$object ref
Definition info.php:89
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)
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.
getNomUrl($withpicto=0, $maxlen=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clickable 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 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:171
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79