dolibarr 23.0.3
salary.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-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 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';
30
31
35class Salary extends CommonObject
36{
40 public $element = 'salary';
41
45 public $table_element = 'salary';
46
50 public $picto = 'salary';
51
55 protected $childtables = array('payment_salary' => array('name' => 'SalaryPayment', 'fk_element' => 'fk_salary'));
56
57 // /**
58 // * @var array List of child tables. To know object to delete on cascade.
59 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
60 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
61 // */
62 //protected $childtablesoncascade = array('mymodule_myobjectdet');
63
64
68 public $fk_user;
69
73 public $datep;
77 public $datev;
78
82 public $salary;
86 public $amount;
87
91 public $fk_project;
92
96 public $type_payment; // TODO Rename into type_payment_id
100 public $type_payment_code;
101
105 public $label;
106
110 public $datesp;
114 public $dateep;
115
119 public $fk_bank;
120
126 public $fk_account;
127
131 public $accountid;
132
136 public $fk_user_author;
137
141 public $fk_user_modif;
142
146 public $user;
147
151 public $paye;
152
156 public $resteapayer;
157
158
159 const STATUS_UNPAID = 0;
160 const STATUS_PAID = 1;
161
162
163 public $fields = array(
164 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
165 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'visible' => 1, 'index' => 1, 'comment' => "Reference of object"),
166 'ref_ext' => array('type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => 1, 'visible' => 0, 'position' => 11),
167 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 12, 'notnull' => 0, 'visible' => 1),
168 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'position' => 30),
169 'datep' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 40, 'comment' => 'Date'),
170 'datev' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 50, 'comment' => 'Date'),
171 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Employee', 'enabled' => 1, 'position' => 15, 'notnull' => 1, 'visible' => 1, 'picto' => 'user'),
172 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 20),
173 'salary' => array('type' => 'double(24,8)', 'label' => 'salary', 'enabled' => 1, 'visible' => 0, 'position' => 70),
174 'amount' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 80),
175 'fk_projet' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'enabled' => "isModEnabled('project')", 'visible' => 0, 'position' => 90),
176 'fk_typepayment' => array('type' => 'typepayment', 'label' => 'DefaultPaymentMode', 'enabled' => 1, 'visible' => 1, 'position' => 100, 'comment' => 'Payment type'),
177 'num_payment' => array('type' => 'string', 'label' => 'Reference', 'enabled' => 1, 'visible' => 0, 'position' => 110, 'comment' => 'Reference'),
178 'datesp' => array('type' => 'date', 'label' => 'DateStart', 'enabled' => 1, 'visible' => 1, 'position' => 130, 'comment' => 'Date'),
179 'dateep' => array('type' => 'date', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => 1, 'position' => 140, 'comment' => 'Date'),
180 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => 0, 'position' => 150, 'index' => 1),
181 'note' => array('type' => 'text', 'label' => 'Note', 'enabled' => 1, 'position' => 160, 'visible' => 0,),
182 'fk_bank' => array('type' => 'integer', 'label' => 'BankId', 'enabled' => 1, 'visible' => 0, 'position' => 170),
183 'paye' => array('type' => 'smallint(6)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 180),
184 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => 0, 'position' => 190),
185 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 200, 'visible' => 0,),
186 'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 220),
187 );
188
189
195 public function __construct($db)
196 {
197 $this->db = $db;
198 $this->element = 'salary';
199 $this->table_element = 'salary';
200 $this->isextrafieldmanaged = 1;
201
202 $this->fields['ref_ext']['visible'] = getDolGlobalInt('MAIN_LIST_SHOW_REF_EXT');
203 }
204
212 public function update($user = null, $notrigger = 0)
213 {
214 $error = 0;
215
216 // Clean parameters
217 $this->amount = trim($this->amount);
218 $this->label = trim($this->label);
219 $this->note = trim($this->note);
220 $this->note_private = trim($this->note_private);
221 $this->note_public = trim($this->note_public);
222
223 // Check parameters
224 if (empty($this->fk_user) || $this->fk_user < 0) {
225 $this->error = 'ErrorBadParameter';
226 return -1;
227 }
228
229 $this->db->begin();
230
231 // Update request
232 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
233 $sql .= " tms='".$this->db->idate(dol_now())."',";
234 $sql .= " fk_user=".((int) $this->fk_user).",";
235 /*$sql .= " datep='".$this->db->idate($this->datep)."',";
236 $sql .= " datev='".$this->db->idate($this->datev)."',";*/
237 $sql .= " amount=".price2num($this->amount).",";
238 $sql .= " fk_projet=".((int) $this->fk_project).",";
239 $sql .= " fk_typepayment=".((int) $this->type_payment).",";
240 $sql .= " label='".$this->db->escape($this->label)."',";
241 $sql .= " datesp='".$this->db->idate($this->datesp)."',";
242 $sql .= " dateep='".$this->db->idate($this->dateep)."',";
243 $sql .= " note='".$this->db->escape($this->note)."',";
244 $sql .= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").",";
245 $sql .= " fk_user_author=".((int) $this->fk_user_author).",";
246 $sql .= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
247 $sql .= " WHERE rowid=".((int) $this->id);
248
249 dol_syslog(get_class($this)."::update", LOG_DEBUG);
250 $resql = $this->db->query($sql);
251 if (!$resql) {
252 $this->error = "Error ".$this->db->lasterror();
253 return -1;
254 }
255
256 // Update extrafield
257 $result = $this->insertExtraFields();
258 if ($result < 0) {
259 $error++;
260 }
261
262 if (!$notrigger) {
263 // Call trigger
264 $result = $this->call_trigger('SALARY_MODIFY', $user);
265 if ($result < 0) {
266 $error++;
267 }
268 // End call triggers
269 }
270
271 if (!$error) {
272 $this->db->commit();
273 return 1;
274 } else {
275 $this->db->rollback();
276 return -1;
277 }
278 }
279
280
288 public function fetch($id, $user = null)
289 {
290 $sql = "SELECT";
291 $sql .= " s.rowid,";
292 $sql .= " s.tms,";
293 $sql .= " s.fk_user,";
294 $sql .= " s.datep,";
295 $sql .= " s.datev,";
296 $sql .= " s.amount,";
297 $sql .= " s.fk_projet as fk_project,";
298 $sql .= " s.fk_typepayment,";
299 $sql .= " s.label,";
300 $sql .= " s.datesp,";
301 $sql .= " s.dateep,";
302 $sql .= " s.note as note_private,";
303 $sql .= " s.note_public,";
304 $sql .= " s.paye,";
305 $sql .= " s.fk_bank,";
306 $sql .= " s.fk_user_author,";
307 $sql .= " s.fk_user_modif,";
308 $sql .= " s.fk_account,";
309 $sql .= " cp.code as type_payment_code";
310 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
311 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
312 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON s.fk_typepayment = cp.id";
313 $sql .= " WHERE s.rowid = ".((int) $id);
314
315 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
316
317 $resql = $this->db->query($sql);
318 if ($resql) {
319 if ($this->db->num_rows($resql)) {
320 $obj = $this->db->fetch_object($resql);
321
322 $this->id = $obj->rowid;
323 $this->ref = $obj->rowid;
324 $this->tms = $this->db->jdate($obj->tms);
325 $this->fk_user = $obj->fk_user;
326 $this->datep = $this->db->jdate($obj->datep);
327 $this->datev = $this->db->jdate($obj->datev);
328 $this->amount = $obj->amount;
329 $this->fk_project = $obj->fk_project;
330 $this->type_payment = $obj->fk_typepayment;
331 $this->type_payment_code = $obj->type_payment_code;
332 $this->label = $obj->label;
333 $this->datesp = $this->db->jdate($obj->datesp);
334 $this->dateep = $this->db->jdate($obj->dateep);
335 $this->note = $obj->note_private;
336 $this->note_private = $obj->note_private;
337 $this->note_public = $obj->note_public;
338 $this->paye = $obj->paye;
339 $this->status = $obj->paye;
340 $this->fk_bank = $obj->fk_bank;
341 $this->fk_user_author = $obj->fk_user_author;
342 $this->fk_user_modif = $obj->fk_user_modif;
343 $this->fk_account = $obj->fk_account;
344 $this->accountid = $obj->fk_account;
345
346 // Retrieve all extrafield
347 // fetch optionals attributes and labels
348 $this->fetch_optionals();
349 }
350 $this->db->free($resql);
351
352 return 1;
353 } else {
354 $this->error = "Error ".$this->db->lasterror();
355 return -1;
356 }
357 }
358
359
367 public function delete($user, $notrigger = 0)
368 {
369 return $this->deleteCommon($user, $notrigger);
370 }
371
372
380 public function initAsSpecimen()
381 {
382 $this->id = 0;
383
384 $this->tms = dol_now();
385 $this->fk_user = 0;
386 $this->datep = '';
387 $this->datev = '';
388 $this->amount = '';
389 $this->label = '';
390 $this->datesp = '';
391 $this->dateep = '';
392 $this->note = '';
393 $this->fk_bank = 0;
394 $this->fk_user_author = 0;
395 $this->fk_user_modif = 0;
396
397 return 1;
398 }
399
406 public function create($user)
407 {
408 global $conf, $langs;
409
410 $error = 0;
411 $now = dol_now();
412
413 // Clean parameters
414 $this->amount = price2num(trim($this->amount));
415 $this->label = trim($this->label);
416 $this->note = trim($this->note);
417 $this->fk_bank = (int) $this->fk_bank;
418 $this->fk_user_author = (int) $this->fk_user_author;
419 $this->fk_user_modif = (int) $this->fk_user_modif;
420 $this->accountid = (int) $this->accountid;
421 $this->paye = (int) $this->paye;
422
423 // Check parameters
424 if (!$this->label) {
425 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
426 return -3;
427 }
428 if ($this->fk_user < 0 || $this->fk_user == '') {
429 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee"));
430 return -4;
431 }
432 if ($this->amount == '') {
433 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
434 return -5;
435 }
436
437 $this->db->begin();
438
439 // Insert into llx_salary
440 $sql = "INSERT INTO ".MAIN_DB_PREFIX."salary (fk_user";
441 //$sql .= ", datep";
442 //$sql .= ", datev";
443 $sql .= ", amount";
444 $sql .= ", fk_projet";
445 $sql .= ", salary";
446 $sql .= ", fk_typepayment";
447 $sql .= ", fk_account";
448 if ($this->note) {
449 $sql .= ", note";
450 }
451 $sql .= ", label";
452 $sql .= ", datesp";
453 $sql .= ", dateep";
454 $sql .= ", fk_user_author";
455 $sql .= ", datec";
456 $sql .= ", fk_bank";
457 $sql .= ", entity";
458 $sql .= ") ";
459 $sql .= " VALUES (";
460 $sql .= "'".((int) $this->fk_user)."'";
461 //$sql .= ", '".$this->db->idate($this->datep)."'";
462 //$sql .= ", '".$this->db->idate($this->datev)."'";
463 $sql .= ", ".((float) $this->amount);
464 $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
465 $sql .= ", ".($this->salary > 0 ? ((float) $this->salary) : "null");
466 $sql .= ", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
467 $sql .= ", ".($this->accountid > 0 ? ((int) $this->accountid) : "null");
468 if ($this->note) {
469 $sql .= ", '".$this->db->escape($this->note)."'";
470 }
471 $sql .= ", '".$this->db->escape($this->label)."'";
472 $sql .= ", '".$this->db->idate($this->datesp)."'";
473 $sql .= ", '".$this->db->idate($this->dateep)."'";
474 $sql .= ", '".((int) $user->id)."'";
475 $sql .= ", '".$this->db->idate($now)."'";
476 $sql .= ", NULL";
477 $sql .= ", ".((int) $conf->entity);
478 $sql .= ")";
479
480 dol_syslog(get_class($this)."::create", LOG_DEBUG);
481 $result = $this->db->query($sql);
482 if ($result) {
483 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."salary");
484
485 if ($this->id > 0) {
486 // Update extrafield
487 $result = $this->insertExtraFields();
488 if ($result < 0) {
489 $error++;
490 }
491
492 // Call trigger
493 $result = $this->call_trigger('SALARY_CREATE', $user);
494 if ($result < 0) {
495 $error++;
496 }
497 // End call triggers
498 } else {
499 $error++;
500 }
501
502 if (!$error) {
503 $this->db->commit();
504 return $this->id;
505 } else {
506 $this->db->rollback();
507 return -2;
508 }
509 } else {
510 $this->error = $this->db->error();
511 $this->db->rollback();
512 return -1;
513 }
514 }
515
516 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
523 public function update_fk_bank($id_bank)
524 {
525 // phpcs:enable
526 $sql = 'UPDATE '.MAIN_DB_PREFIX.'salary SET fk_bank = '.((int) $id_bank);
527 $sql .= " WHERE rowid = ".((int) $this->id);
528 $result = $this->db->query($sql);
529 if ($result) {
530 return 1;
531 } else {
532 dol_print_error($this->db);
533 return -1;
534 }
535 }
536
543 public function getTooltipContentArray($params)
544 {
545 global $langs;
546
547 $langs->loadLangs(['salaries']);
548
549 // Complete datas
550 if (!empty($params['fromajaxtooltip']) && !isset($this->alreadypaid)) {
551 // Load the alreadypaid field
552 $this->alreadypaid = $this->getSommePaiement(0);
553 }
554
555 $datas = [];
556
557 $datas['picto'] = '<u>'.$langs->trans("Salary").'</u>';
558 if (isset($this->status) && isset($this->alreadypaid)) {
559 $datas['picto'] .= ' '.$this->getLibStatut(5, $this->alreadypaid);
560 }
561 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
562
563 return $datas;
564 }
565
576 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
577 {
578 global $conf, $langs, $hookmanager;
579
580 if (!empty($conf->dol_no_mouse_hover)) {
581 $notooltip = 1;
582 } // Force disable tooltips
583
584 $result = '';
585 $params = [
586 'id' => $this->id,
587 'objecttype' => $this->element,
588 'option' => $option,
589 ];
590 $classfortooltip = 'classfortooltip';
591 $dataparams = '';
592 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
593 $classfortooltip = 'classforajaxtooltip';
594 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
595 $label = '';
596 } else {
597 $label = implode($this->getTooltipContentArray($params));
598 }
599
600 $url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id;
601
602 if ($option != 'nolink') {
603 // Add param to save lastsearch_values or not
604 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
605 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
606 $add_save_lastsearch_values = 1;
607 }
608 if ($add_save_lastsearch_values) {
609 $url .= '&save_lastsearch_values=1';
610 }
611 }
612
613 $linkclose = '';
614 if (empty($notooltip)) {
615 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
616 $label = $langs->trans("ShowMyObject");
617 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
618 }
619 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
620 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
621 } else {
622 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
623 }
624
625 $linkstart = '<a href="'.$url.'"';
626 $linkstart .= $linkclose.'>';
627 $linkend = '</a>';
628
629 $result .= $linkstart;
630 if ($withpicto) {
631 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
632 }
633 if ($withpicto != 2) {
634 $result .= $this->ref;
635 }
636 $result .= $linkend;
637 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
638
639 global $action, $hookmanager;
640 $hookmanager->initHooks(array('salarypayment'));
641 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
642 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
643 if ($reshook > 0) {
644 $result = $hookmanager->resPrint;
645 } else {
646 $result .= $hookmanager->resPrint;
647 }
648
649 return $result;
650 }
651
658 public function getSommePaiement($multicurrency = 0)
659 {
660 $table = 'payment_salary';
661 $field = 'fk_salary';
662
663 $sql = "SELECT sum(amount) as amount";
664 //sum(multicurrency_amount) as multicurrency_amount // Not yet supported
665 $sql .= " FROM ".MAIN_DB_PREFIX.$table;
666 $sql .= " WHERE ".$field." = ".((int) $this->id);
667
668 dol_syslog(get_class($this)."::getSommePaiement for salary id=".((int) $this->id), LOG_DEBUG);
669
670 $resql = $this->db->query($sql);
671
672 if ($resql) {
673 $obj = $this->db->fetch_object($resql);
674
675 $this->db->free($resql);
676
677 if ($obj) {
678 if ($multicurrency < 0) {
679 //$this->totalpaid = $obj->amount;
680 //$this->totalpaid_multicurrency = $obj->multicurrency_amount;
681 //return array('alreadypaid'=>(float) $obj->amount, 'alreadypaid_multicurrency'=>(float) $obj->multicurrency_amount);
682 return array(); // Not yet supported
683 } elseif ($multicurrency) {
684 //$this->totalpaid_multicurrency = $obj->multicurrency_amount;
685 //return (float) $obj->multicurrency_amount;
686 return -1; // Not yet supported
687 } else {
688 //$this->totalpaid = $obj->amount;
689 return (float) $obj->amount;
690 }
691 } else {
692 return 0;
693 }
694 } else {
695 $this->error = $this->db->lasterror();
696 return -1;
697 }
698 }
699
706 public function info($id)
707 {
708 $sql = 'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
709 $sql .= ' FROM '.MAIN_DB_PREFIX.'salary as ps';
710 $sql .= ' WHERE ps.rowid = '.((int) $id);
711
712 dol_syslog(get_class($this).'::info', LOG_DEBUG);
713 $result = $this->db->query($sql);
714
715 if ($result) {
716 if ($this->db->num_rows($result)) {
717 $obj = $this->db->fetch_object($result);
718
719 $this->id = $obj->rowid;
720
721 $this->user_creation_id = $obj->fk_user_author;
722 $this->user_modification_id = $obj->fk_user_modif;
723 $this->date_creation = $this->db->jdate($obj->datec);
724 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
725 }
726 $this->db->free($result);
727 } else {
728 dol_print_error($this->db);
729 }
730 }
731
732 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
741 public function set_paid($user)
742 {
743 // phpcs:enable
744 dol_syslog(get_class($this)."::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
745 return $this->setPaid($user);
746 }
747
754 public function setPaid($user)
755 {
756 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
757 $sql .= " paye = 1";
758 $sql .= " WHERE rowid = ".((int) $this->id);
759
760 $return = $this->db->query($sql);
761
762 if ($return) {
763 $this->paye = 1;
764 return 1;
765 } else {
766 return -1;
767 }
768 }
769
770 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
777 public function set_unpaid($user)
778 {
779 // phpcs:enable
780 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
781 $sql .= " paye = 0";
782 $sql .= " WHERE rowid = ".((int) $this->id);
783
784 $return = $this->db->query($sql);
785
786 if ($return) {
787 $this->paye = 0;
788 return 1;
789 } else {
790 return -1;
791 }
792 }
793
794
802 public function getLibStatut($mode = 0, $alreadypaid = -1)
803 {
804 return $this->LibStatut($this->paye, $mode, $alreadypaid);
805 }
806
807 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
816 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
817 {
818 // phpcs:enable
819 global $langs;
820
821 // Load translation files required by the page
822 $langs->loadLangs(array("customers", "bills"));
823
824 // We reinit status array to force to redefine them because label may change according to properties values.
825 $this->labelStatus = array();
826 $this->labelStatusShort = array();
827
828 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
829 global $langs;
830 //$langs->load("mymodule");
831 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
832 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
833 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
834 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
835 }
836 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
837 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
838 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
839 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
840 }
841 }
842
843 $statusType = 'status1';
844 if ($status == 0 && $alreadypaid != 0) {
845 $statusType = 'status3';
846 }
847 if ($status == 1) {
848 $statusType = 'status6';
849 }
850
851 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
852 }
853
861 public function getKanbanView($option = '', $arraydata = null)
862 {
863 global $langs;
864
865 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
866
867 $return = '<div class="box-flex-item box-flex-grow-zero">';
868 $return .= '<div class="info-box info-box-sm">';
869 $return .= '<span class="info-box-icon bg-infobox-action">';
870 $return .= img_picto('', $this->picto);
871 $return .= '</span>';
872 $return .= '<div class="info-box-content">';
873 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(1) . '</span>';
874 if ($selected >= 0) {
875 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
876 }
877 if (!empty($arraydata['user']) && is_object($arraydata['user'])) {
878 $user = $arraydata['user'];
879 '@phan-var-force User $user';
881 $return .= '<br><span class="info-box-label">'.$user->getNomUrl(empty($arraydata['user']->photo) ? 1 : -1, '', 0, 0, 16, 0, '', 'maxwidth100').'</span>';
882 }
883 $return .= '<br><span class="info-box-label amount">'.price($this->amount).'</span>';
884 if (!empty($this->type_payment)) {
885 $return .= ' <span class="info-box-label opacitymedium small">';
886 if ($langs->trans("PaymentTypeShort".$this->type_payment) != "PaymentTypeShort".$this->type_payment) {
887 $return .= $langs->trans("PaymentTypeShort".$this->type_payment);
888 } elseif ($langs->trans("PaymentType".$this->type_payment) != "PaymentType".$this->type_payment) {
889 $return .= $langs->trans("PaymentType".$this->type_payment);
890 }
891 $return .= '</span>';
892 }
893 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3, isset($this->alreadypaid) ? $this->alreadypaid : $this->totalpaid).'</div>';
894 $return .= '</div>';
895 $return .= '</div>';
896 $return .= '</div>';
897
898 return $return;
899 }
900
901 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
913 public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'salaire', $checkduplicateamongall = 0)
914 {
915 // phpcs:enable
916 global $conf, $mysoc;
917
918 $error = 0;
919
920 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
921 if ($this->paye == 0) {
922 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
923 $bac = new CompanyBankAccount($this->db);
924 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
925 $bac->fetch(0, '', $mysoc->id);
926
927 $sql = "SELECT count(rowid) as nb";
928 $sql .= " FROM ".$this->db->prefix()."prelevement_demande";
929 if ($type == 'salaire') {
930 $sql .= " WHERE fk_salary = ".((int) $this->id);
931 } else {
932 $sql .= " WHERE fk_facture = ".((int) $this->id);
933 }
934 $sql .= " AND type = 'ban'"; // To exclude record done for some online payments
935 if (empty($checkduplicateamongall)) {
936 $sql .= " AND traite = 0";
937 }
938
939 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
940
941 $resql = $this->db->query($sql);
942 if ($resql) {
943 $obj = $this->db->fetch_object($resql);
944 if ($obj && $obj->nb == 0) { // If no request found yet
945 $now = dol_now();
946
947 $totalpaid = $this->getSommePaiement();
948 // $totalcreditnotes = $this->getSumCreditNotesUsed();
949 // $totaldeposits = $this->getSumDepositsUsed();
950 //print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
951
952 // We can also use bcadd to avoid pb with floating points
953 // For example print 239.2 - 229.3 - 9.9; does not return 0.
954 //$resteapayer=bcadd($this->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT);
955 //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
956 // if (empty($amount)) {
957 // $amount = price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
958 // }
959
960 if (is_numeric($amount) && $amount != 0) {
961 $sql = 'INSERT INTO '.$this->db->prefix().'prelevement_demande(';
962 if ($type == 'salaire') {
963 $sql .= 'fk_salary, ';
964 } else {
965 $sql .= 'fk_facture, ';
966 }
967 $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity)';
968 $sql .= " VALUES (".((int) $this->id);
969 $sql .= ", ".((float) price2num($amount));
970 $sql .= ", '".$this->db->idate($now)."'";
971 $sql .= ", ".((int) $fuser->id);
972 $sql .= ", '".$this->db->escape($bac->code_banque)."'";
973 $sql .= ", '".$this->db->escape($bac->code_guichet)."'";
974 $sql .= ", '".$this->db->escape($bac->number)."'";
975 $sql .= ", '".$this->db->escape($bac->cle_rib)."'";
976 $sql .= ", '".$this->db->escape($sourcetype)."'";
977 $sql .= ", 'ban'";
978 $sql .= ", ".((int) $conf->entity);
979 $sql .= ")";
980
981 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
982 $resql = $this->db->query($sql);
983 if (!$resql) {
984 $this->error = $this->db->lasterror();
985 dol_syslog(get_class($this).'::demandeprelevement Erreur');
986 $error++;
987 }
988 } else {
989 $this->error = 'WithdrawRequestErrorNilAmount';
990 dol_syslog(get_class($this).'::demandeprelevement WithdrawRequestErrorNilAmount');
991 $error++;
992 }
993
994 if (!$error) {
995 // Force payment mode of invoice to withdraw
996 $payment_mode_id = dol_getIdFromCode($this->db, (($type == 'bank-transfer' || $type == 'salaire') ? 'VIR' : 'PRE'), 'c_paiement', 'code', 'id', 1);
997 if ($payment_mode_id > 0) {
998 $result = $this->setPaymentMethods($payment_mode_id);
999 }
1000 }
1001
1002 if ($error) {
1003 return -1;
1004 }
1005 return 1;
1006 } else {
1007 $this->error = "A request already exists";
1008 dol_syslog(get_class($this).'::demandeprelevement Can t create a request to generate a direct debit, a request already exists.');
1009 return 0;
1010 }
1011 } else {
1012 $this->error = $this->db->error();
1013 dol_syslog(get_class($this).'::demandeprelevement Error -2');
1014 return -2;
1015 }
1016 } else {
1017 $this->error = "Status of invoice does not allow this";
1018 dol_syslog(get_class($this)."::demandeprelevement ".$this->error." $this->status, $this->paye, $this->mode_reglement_id");
1019 return -3;
1020 }
1021 }
1022
1023 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1031 public function demande_prelevement_delete($fuser, $did)
1032 {
1033 // phpcs:enable
1034 $sql = 'DELETE FROM '.$this->db->prefix().'prelevement_demande';
1035 $sql .= ' WHERE rowid = '.((int) $did);
1036 $sql .= ' AND traite = 0';
1037 if ($this->db->query($sql)) {
1038 return 0;
1039 } else {
1040 $this->error = $this->db->lasterror();
1041 dol_syslog(get_class($this).'::demande_prelevement_delete Error '.$this->error);
1042 return -1;
1043 }
1044 }
1045}
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
setPaymentMethods($id)
Change the payments methods.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage bank accounts description of third parties.
Class to manage salary payments.
fetch($id, $user=null)
Load object in memory from database.
initAsSpecimen()
Initialise an instance with random values.
update($user=null, $notrigger=0)
Update database.
getTooltipContentArray($params)
getTooltipContentArray
update_fk_bank($id_bank)
Update link between payment salary and line generate into llx_bank.
LibStatut($status, $mode=0, $alreadypaid=-1)
Return label of a given status.
set_paid($user)
Tag social contribution as paid completely.
demande_prelevement_delete($fuser, $did)
Remove a direct debit request or a credit transfer request.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Send name clickable (with possibly the picto)
set_unpaid($user)
Remove tag paid on social contribution.
create($user)
Create in database.
getSommePaiement($multicurrency=0)
Return amount of payments already done.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of current status.
info($id)
Information on record.
__construct($db)
Constructor.
setPaid($user)
Tag social contribution as paid completely.
demande_prelevement($fuser, $amount=0, $type='direct-debit', $sourcetype='salaire', $checkduplicateamongall=0)
Create a withdrawal request for a direct debit order or a credit transfer order.
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
global $mysoc
dol_now($mode='gmt')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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 '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:466