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