dolibarr 18.0.6
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Put here all includes required by your class file
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
29
30
35{
39 public $element = 'payment_salary';
40
44 public $table_element = 'payment_salary';
45
49 public $picto = 'payment';
50
54 public $fk_salary;
55
56 public $datec = '';
57 public $tms = '';
58 public $datep = '';
59
64 public $total;
65
66 public $amount; // Total amount of payment
67 public $amounts = array(); // Array of amounts
68
72 public $fk_typepayment;
73
78 public $num_paiement;
79
83 public $num_payment;
84
88 public $fk_bank;
89
93 public $fk_user_author;
94
98 public $fk_user_modif;
99
103 public $fields = array(
104 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
105 );
106
112 public function __construct($db)
113 {
114 $this->db = $db;
115 }
116
125 public function create($user, $closepaidcontrib = 0)
126 {
127 global $conf;
128
129 $error = 0;
130
131 $now = dol_now();
132
133 dol_syslog(get_class($this)."::create", LOG_DEBUG);
134
135 // Validate parametres
136 if (!$this->datepaye) {
137 $this->error = 'ErrorBadValueForParameterCreatePaymentSalary';
138 return -1;
139 }
140
141 // Clean parameters
142 if (isset($this->fk_salary)) $this->fk_salary = (int) $this->fk_salary;
143 if (isset($this->amount)) $this->amount = trim($this->amount);
144 if (isset($this->fk_typepayment)) $this->fk_typepayment = (int) $this->fk_typepayment;
145 if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement); // deprecated
146 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
147 if (isset($this->note)) $this->note = trim($this->note);
148 if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank;
149 if (isset($this->fk_user_author)) $this->fk_user_author = (int) $this->fk_user_author;
150 if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif;
151
152 $totalamount = 0;
153 foreach ($this->amounts as $key => $value) { // How payment is dispatch
154 $newvalue = price2num($value, 'MT');
155 $this->amounts[$key] = $newvalue;
156 $totalamount += $newvalue;
157 }
158 $totalamount = price2num($totalamount);
159
160 // Check parameters
161 if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
162
163
164 $this->db->begin();
165
166 if ($totalamount != 0) {
167 $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (entity, fk_salary, datec, datep, amount,";
168 $sql .= " fk_typepayment, num_payment, note, fk_user_author, fk_bank)";
169 $sql .= " VALUES (".((int) $conf->entity).", ".((int) $this->chid).", '".$this->db->idate($now)."',";
170 $sql .= " '".$this->db->idate($this->datepaye)."',";
171 $sql .= " ".price2num($totalamount).",";
172 $sql .= " ".((int) $this->paiementtype).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".((int) $user->id).",";
173 $sql .= " 0)";
174
175 $resql = $this->db->query($sql);
176 if ($resql) {
177 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary");
178
179 // Insere tableau des montants / factures
180 foreach ($this->amounts as $key => $amount) {
181 $contribid = $key;
182 if (is_numeric($amount) && $amount <> 0) {
183 $amount = price2num($amount);
184
185 // If we want to closed payed invoices
186 if ($closepaidcontrib) {
187 $tmpsalary = new Salary($this->db);
188 $tmpsalary->fetch($contribid);
189 $paiement = $tmpsalary->getSommePaiement();
190 //$creditnotes=$tmpsalary->getSumCreditNotesUsed();
191 $creditnotes = 0;
192 //$deposits=$tmpsalary->getSumDepositsUsed();
193 $deposits = 0;
194 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
195 $remaintopay = price2num($tmpsalary->amount - $paiement - $creditnotes - $deposits, 'MT');
196 if ($remaintopay == 0) {
197 $result = $tmpsalary->set_paid($user);
198 } else {
199 dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing.");
200 }
201 }
202 }
203 }
204 } else {
205 $error++;
206 }
207 }
208
209 $result = $this->call_trigger('PAYMENTSALARY_CREATE', $user);
210 if ($result < 0) $error++;
211
212 if ($totalamount != 0 && !$error) {
213 $this->amount = $totalamount;
214 $this->total = $totalamount; // deprecated
215 $this->db->commit();
216 return $this->id;
217 } else {
218 $this->error = $this->db->error();
219 $this->db->rollback();
220 return -1;
221 }
222 }
223
230 public function fetch($id)
231 {
232 global $langs;
233 $sql = "SELECT";
234 $sql .= " t.rowid,";
235 $sql .= " t.fk_salary,";
236 $sql .= " t.datec,";
237 $sql .= " t.tms,";
238 $sql .= " t.datep,";
239 $sql .= " t.amount,";
240 $sql .= " t.fk_typepayment,";
241 $sql .= " t.num_payment as num_payment,";
242 $sql .= " t.note,";
243 $sql .= " t.fk_bank,";
244 $sql .= " t.fk_user_author,";
245 $sql .= " t.fk_user_modif,";
246 $sql .= " pt.code as type_code, pt.libelle as type_label,";
247 $sql .= ' b.fk_account';
248 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id";
249 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
250 $sql .= " WHERE t.rowid = ".((int) $id);
251 // TODO link on entity of tax;
252
253 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
254 $resql = $this->db->query($sql);
255 if ($resql) {
256 if ($this->db->num_rows($resql)) {
257 $obj = $this->db->fetch_object($resql);
258
259 $this->id = $obj->rowid;
260 $this->ref = $obj->rowid;
261
262 $this->fk_salary = $obj->fk_salary;
263 $this->datec = $this->db->jdate($obj->datec);
264 $this->tms = $this->db->jdate($obj->tms);
265 $this->datep = $this->db->jdate($obj->datep);
266 $this->amount = $obj->amount;
267 $this->fk_typepayment = $obj->fk_typepayment;
268 $this->num_paiement = $obj->num_payment;
269 $this->num_payment = $obj->num_payment;
270 $this->note = $obj->note;
271 $this->note_private = $obj->note;
272 $this->fk_bank = $obj->fk_bank;
273 $this->fk_user_author = $obj->fk_user_author;
274 $this->fk_user_modif = $obj->fk_user_modif;
275
276 $this->type_code = $obj->type_code;
277 $this->type_label = $obj->type_label;
278
279 $this->bank_account = $obj->fk_account;
280 $this->bank_line = $obj->fk_bank;
281 }
282 $this->db->free($resql);
283
284 return 1;
285 } else {
286 $this->error = "Error ".$this->db->lasterror();
287 return -1;
288 }
289 }
290
291
299 public function update($user = null, $notrigger = 0)
300 {
301 global $conf, $langs;
302 $error = 0;
303
304 // Clean parameters
305
306 if (isset($this->fk_salary)) $this->fk_salary = (int) $this->fk_salary;
307 if (isset($this->amount)) $this->amount = trim($this->amount);
308 if (isset($this->fk_typepayment)) $this->fk_typepayment = (int) $this->fk_typepayment;
309 if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement); // deprecated
310 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
311 if (isset($this->note)) $this->note = trim($this->note);
312 if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank;
313 if (isset($this->fk_user_author)) $this->fk_user_author = (int) $this->fk_user_author;
314 if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif;
315
316 // Check parameters
317 // Put here code to add control on parameters values
318
319 // Update request
320 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET";
321 $sql .= " fk_salary=".(isset($this->fk_salary) ? $this->fk_salary : "null").",";
322 $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
323 $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
324 $sql .= " datep=".(dol_strlen($this->datep) != 0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
325 $sql .= " amount=".(isset($this->amount) ? $this->amount : "null").",";
326 $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").",";
327 $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").",";
328 $sql .= " note=".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : "null").",";
329 $sql .= " fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) : "null").",";
330 $sql .= " fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) : "null").",";
331 $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) : "null");
332 $sql .= " WHERE rowid=".((int) $this->id);
333
334 $this->db->begin();
335
336 dol_syslog(get_class($this)."::update", LOG_DEBUG);
337 $resql = $this->db->query($sql);
338 if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
339
340 // Commit or rollback
341 if ($error) {
342 foreach ($this->errors as $errmsg) {
343 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
344 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
345 }
346 $this->db->rollback();
347 return -1 * $error;
348 } else {
349 $this->db->commit();
350 return 1;
351 }
352 }
353
354
362 public function delete($user, $notrigger = 0)
363 {
364 global $conf, $langs;
365 $error = 0;
366
367 dol_syslog(get_class($this)."::delete");
368
369 $this->db->begin();
370
371 if ($this->bank_line > 0) {
372 $accline = new AccountLine($this->db);
373 $accline->fetch($this->bank_line);
374 $result = $accline->delete();
375 if ($result < 0) {
376 $this->errors[] = $accline->error;
377 $error++;
378 }
379 }
380
381 if (!$error) {
382 $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary";
383 $sql .= " WHERE rowid=".((int) $this->id);
384
385 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
386 $resql = $this->db->query($sql);
387 if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
388 }
389
390 // Commit or rollback
391 if ($error) {
392 foreach ($this->errors as $errmsg) {
393 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
394 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
395 }
396 $this->db->rollback();
397 return -1 * $error;
398 } else {
399 $this->db->commit();
400 return 1;
401 }
402 }
403
404
405
413 public function createFromClone(User $user, $fromid)
414 {
415 $error = 0;
416
417 $object = new PaymentSalary($this->db);
418
419 $this->db->begin();
420
421 // Load source object
422 $object->fetch($fromid);
423 $object->id = 0;
424 $object->statut = 0;
425
426 // Clear fields
427 // ...
428
429 // Create clone
430 $object->context['createfromclone'] = 'createfromclone';
431 $result = $object->create($user);
432
433 // Other options
434 if ($result < 0) {
435 $this->error = $object->error;
436 $error++;
437 }
438
439 unset($object->context['createfromclone']);
440
441 // End
442 if (!$error) {
443 $this->db->commit();
444 return $object->id;
445 } else {
446 $this->db->rollback();
447 return -1;
448 }
449 }
450
451
459 public function initAsSpecimen()
460 {
461 $this->id = 0;
462
463 $this->fk_salary = '';
464 $this->datec = '';
465 $this->tms = '';
466 $this->datep = '';
467 $this->amount = '';
468 $this->fk_typepayment = '';
469 $this->num_payment = '';
470 $this->note_private = '';
471 $this->note_public = '';
472 $this->fk_bank = '';
473 $this->fk_user_author = '';
474 $this->fk_user_modif = '';
475 }
476
477
490 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
491 {
492 global $conf, $langs;
493
494 // Clean data
495 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
496
497 $error = 0;
498
499 if (isModEnabled("banque")) {
500 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
501
502 $acc = new Account($this->db);
503 $acc->fetch($accountid);
504
505 $total = $this->amount;
506
507 // Insert payment into llx_bank
508 $bank_line_id = $acc->addline(
509 $this->datepaye,
510 $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example")
511 $label,
512 -$total,
513 $this->num_payment,
514 '',
515 $user,
516 $emetteur_nom,
517 $emetteur_banque,
518 '',
519 $this->datev
520 );
521
522 // Update fk_bank into llx_paiement_salary.
523 // so we know the payment that was used to generated the bank entry.
524 if ($bank_line_id > 0) {
525 $result = $this->update_fk_bank($bank_line_id);
526 if ($result <= 0) {
527 $error++;
528 dol_print_error($this->db);
529 }
530
531 // Add link 'payment_salary' in bank_url between payment and bank transaction
532 $url = '';
533 if ($mode == 'payment_salary') {
534 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id=';
535 }
536
537 if ($url) {
538 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
539 if ($result <= 0) {
540 $error++;
541 dol_print_error($this->db);
542 }
543 }
544
545 // Add link 'user' in bank_url between user and bank transaction
546 foreach ($this->amounts as $key => $value) {
547 if (!$error) {
548 if ($mode == 'payment_salary') {
549 $salary = new Salary($this->db);
550 $salary->fetch($key);
551 $salary->fetch_user($salary->fk_user);
552
553 $fuser = $salary->user;
554
555 if ($fuser->id > 0) {
556 $result = $acc->add_url_line(
557 $bank_line_id,
558 $fuser->id,
559 DOL_URL_ROOT.'/user/card.php?id=',
560 $fuser->getFullName($langs),
561 'user'
562 );
563 }
564 if ($result <= 0) {
565 $this->error = $this->db->lasterror();
566 dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->error);
567 $error++;
568 }
569 }
570 }
571 }
572 } else {
573 $this->error = $acc->error;
574 $error++;
575 }
576 }
577
578 if (!$error) {
579 return 1;
580 } else {
581 return -1;
582 }
583 }
584
585
586 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
593 public function update_fk_bank($id_bank)
594 {
595 // phpcs:enable
596 $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id);
597
598 dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
599 $result = $this->db->query($sql);
600 if ($result) {
601 return 1;
602 } else {
603 $this->error = $this->db->error();
604 return 0;
605 }
606 }
607
615 public function updatePaymentDate($date)
616 {
617 $error = 0;
618
619 if (!empty($date)) {
620 $this->db->begin();
621
622 dol_syslog(get_class($this)."::updatePaymentDate with date = ".$date, LOG_DEBUG);
623
624 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
625 $sql .= " SET datep = '".$this->db->idate($date)."'";
626 $sql .= " WHERE rowid = ".((int) $this->id);
627
628 $result = $this->db->query($sql);
629 if (!$result) {
630 $error++;
631 $this->error = 'Error -1 '.$this->db->error();
632 }
633
634 $type = $this->element;
635
636 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
637 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
638 $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).")";
639 $sql .= " AND rappro = 0";
640
641 $result = $this->db->query($sql);
642 if (!$result) {
643 $error++;
644 $this->error = 'Error -1 '.$this->db->error();
645 }
646
647 if (!$error) {
648 }
649
650 if (!$error) {
651 $this->datep = $date;
652
653 $this->db->commit();
654 return 0;
655 } else {
656 $this->db->rollback();
657 return -2;
658 }
659 }
660 return -1; //no date given or already validated
661 }
662
669 public function getLibStatut($mode = 0)
670 {
671 return $this->LibStatut($this->statut, $mode);
672 }
673
674 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
682 public function LibStatut($status, $mode = 0)
683 {
684 // phpcs:enable
685 global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
686
687 $langs->load('compta');
688 /*if ($mode == 0)
689 {
690 if ($status == 0) return $langs->trans('ToValidate');
691 if ($status == 1) return $langs->trans('Validated');
692 }
693 if ($mode == 1)
694 {
695 if ($status == 0) return $langs->trans('ToValidate');
696 if ($status == 1) return $langs->trans('Validated');
697 }
698 if ($mode == 2)
699 {
700 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
701 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
702 }
703 if ($mode == 3)
704 {
705 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
706 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
707 }
708 if ($mode == 4)
709 {
710 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
711 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
712 }
713 if ($mode == 5)
714 {
715 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
716 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
717 }
718 if ($mode == 6)
719 {
720 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
721 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
722 }*/
723 return '';
724 }
725
736 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
737 {
738 global $conf, $langs, $hookmanager;
739
740 $option = '';
741
742 if (!empty($conf->dol_no_mouse_hover)) {
743 $notooltip = 1; // Force disable tooltips
744 }
745
746 $result = '';
747 $params = [
748 'id' => $this->id,
749 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''),
750 //'option' => $option,
751 ];
752 $classfortooltip = 'classfortooltip';
753 $dataparams = '';
754 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
755 $classfortooltip = 'classforajaxtooltip';
756 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
757 $label = '';
758 } else {
759 $label = implode($this->getTooltipContentArray($params));
760 }
761
762 $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$this->id;
763
764 if ($option !== 'nolink') {
765 // Add param to save lastsearch_values or not
766 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
767 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
768 $add_save_lastsearch_values = 1;
769 }
770 if ($url && $add_save_lastsearch_values) {
771 $url .= '&save_lastsearch_values=1';
772 }
773 }
774
775 $linkclose = '';
776 if (empty($notooltip)) {
777 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
778 $label = $langs->trans("SalaryPayment");
779 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
780 }
781 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
782 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
783 } else {
784 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
785 }
786
787 if ($option == 'nolink' || empty($url)) {
788 $linkstart = '<span';
789 } else {
790 $linkstart = '<a href="'.$url.'"';
791 }
792 $linkstart .= $linkclose.'>';
793 if ($option == 'nolink' || empty($url)) {
794 $linkend = '</span>';
795 } else {
796 $linkend = '</a>';
797 }
798
799 $result .= $linkstart;
800
801 if (empty($this->showphoto_on_popup)) {
802 if ($withpicto) {
803 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
804 }
805 }
806
807 if ($withpicto != 2) {
808 $result .= $this->ref;
809 }
810
811 $result .= $linkend;
812 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
813
814 global $action, $hookmanager;
815 $hookmanager->initHooks(array($this->element.'dao'));
816 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
817 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
818 if ($reshook > 0) {
819 $result = $hookmanager->resPrint;
820 } else {
821 $result .= $hookmanager->resPrint;
822 }
823
824 /*
825 if (empty($this->ref)) $this->ref = $this->lib;
826
827 $label = img_picto('', $this->picto).' <u>'.$langs->trans("SalaryPayment").'</u>';
828 $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
829 if (!empty($this->label)) {
830 $labeltoshow = $this->label;
831 $reg = array();
832 if (preg_match('/^\‍((.*)\‍)$/i', $this->label, $reg)) {
833 // Label generique car entre parentheses. On l'affiche en le traduisant
834 if ($reg[1] == 'paiement') $reg[1] = 'Payment';
835 $labeltoshow = $langs->trans($reg[1]);
836 }
837 $label .= '<br><b>'.$langs->trans('Label').':</b> '.$labeltoshow;
838 }
839 if ($this->datep) {
840 $label .= '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datep, 'day');
841 }
842
843 if (!empty($this->id)) {
844 $link = '<a href="'.DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
845 $linkend = '</a>';
846
847 if ($withpicto) $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend);
848 if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
849 }
850 */
851 return $result;
852 }
853
860 public function getTooltipContentArray($params)
861 {
862 global $conf, $langs, $user;
863
864 $langs->load('salaries');
865 $datas = [];
866
867 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
868 return ['optimize' => $langs->trans("SalaryPayment")];
869 }
870
871 if ($user->hasRight('salaries', 'read')) {
872 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("SalaryPayment").'</u>';
873 if (isset($this->status)) {
874 $datas['status'] = ' '.$this->getLibStatut(5);
875 }
876 $datas['Ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
877 if (!empty($this->total_ttc)) {
878 $datas['AmountTTC'] = '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
879 }
880 if (!empty($this->datep)) {
881 $datas['Date'] = '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datep, 'day');
882 }
883 }
884
885 return $datas;
886 }
887
895 public function getKanbanView($option = '', $arraydata = null)
896 {
897 global $langs;
898
899 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
900
901 $return = '<div class="box-flex-item box-flex-grow-zero">';
902 $return .= '<div class="info-box info-box-sm">';
903 $return .= '<span class="info-box-icon bg-infobox-action">';
904 $return .= img_picto('', $this->picto);
905 $return .= '</span>';
906 $return .= '<div class="info-box-content">';
907 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
908 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
909 if (property_exists($this, 'fk_bank')) {
910 $return .= ' | <span class="info-box-label">'.$this->fk_bank.'</span>';
911 }
912 if (property_exists($this, 'fk_user_author')) {
913 $return .= '<br><span class="info-box-status">'.$this->fk_user_author.'</span>';
914 }
915
916 if (property_exists($this, 'fk_typepayment')) {
917 $return .= '<br><span class="opacitymedium">'.$langs->trans("PaymentMode").'</span> : <span class="info-box-label">'.$this->fk_typepayment.'</span>';
918 }
919 if (property_exists($this, 'amount')) {
920 $return .= '<br><span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
921 }
922 $return .= '</div>';
923 $return .= '</div>';
924 $return .= '</div>';
925 return $return;
926 }
927}
$object ref
Definition info.php:78
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.
print $langs trans("Ref").' m m m statut
Definition index.php:152
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.