dolibarr 24.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-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2026 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.'/core/modules/salaries/modules_salary.php';
31
32
36class Salary extends CommonObject
37{
41 public $element = 'salary';
42
46 public $db;
47
51 public $table_element = 'salary';
52
56 public $module = 'salaries';
57
61 public $picto = 'salary';
62
66 protected $childtables = array('payment_salary' => array('name' => 'SalaryPayment', 'fk_element' => 'fk_salary'));
67
68 // /**
69 // * @var array List of child tables. To know object to delete on cascade.
70 // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
71 // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
72 // */
73 //protected $childtablesoncascade = array('mymodule_myobjectdet');
74
75
79 public $fk_user;
80
84 public $datep;
88 public $datev;
89
93 public $salary;
97 public $amount;
98
102 public $fk_project;
103
107 public $type_payment; // TODO Rename into type_payment_id
111 public $type_payment_code;
112
116 public $num_payment;
117
121 public $label;
122
126 public $datesp;
130 public $dateep;
131
135 public $fk_bank;
136
142 public $fk_account;
143
147 public $accountid;
148
152 public $fk_user_author;
153
157 public $fk_user_modif;
158
162 public $user;
163
167 public $paye;
168
172 public $resteapayer;
173
174
175 const STATUS_UNPAID = 0;
176 const STATUS_PAID = 1;
177
178
179 public $fields = array(
180 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
181 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'visible' => 1, 'index' => 1, 'comment' => "Reference of object"),
182 'ref_ext' => array('type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => 1, 'visible' => 0, 'position' => 11),
183 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 12, 'notnull' => 0, 'visible' => 1),
184 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'position' => 30),
185 'datep' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 40, 'comment' => 'Date'),
186 'datev' => array('type' => 'date', 'label' => 'Date', 'enabled' => 1, 'visible' => 0, 'position' => 50, 'comment' => 'Date'),
187 'fk_user' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Employee', 'enabled' => 1, 'position' => 15, 'notnull' => 1, 'visible' => 1, 'picto' => 'user'),
188 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 20),
189 'salary' => array('type' => 'double(24,8)', 'label' => 'salary', 'enabled' => 1, 'visible' => 0, 'position' => 70),
190 'amount' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 80),
191 'fk_projet' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'enabled' => "isModEnabled('project')", 'visible' => 0, 'position' => 90),
192 'fk_typepayment' => array('type' => 'typepayment', 'label' => 'DefaultPaymentMode', 'enabled' => 1, 'visible' => 1, 'position' => 100, 'comment' => 'Payment type'),
193 'num_payment' => array('type' => 'string', 'label' => 'Reference', 'enabled' => 1, 'visible' => 0, 'position' => 110, 'comment' => 'Reference'),
194 'datesp' => array('type' => 'date', 'label' => 'DateStart', 'enabled' => 1, 'visible' => 1, 'position' => 130, 'comment' => 'Date'),
195 'dateep' => array('type' => 'date', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => 1, 'position' => 140, 'comment' => 'Date'),
196 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => 0, 'position' => 150, 'index' => 1),
197 'note' => array('type' => 'text', 'label' => 'Note', 'enabled' => 1, 'position' => 160, 'visible' => 0,),
198 'fk_bank' => array('type' => 'integer', 'label' => 'BankId', 'enabled' => 1, 'visible' => 0, 'position' => 170),
199 'paye' => array('type' => 'smallint(6)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 180),
200 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => 0, 'position' => 190),
201 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 200, 'visible' => 0,),
202 'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 220),
203 );
204
205
211 public function __construct($db)
212 {
213 $this->db = $db;
214 $this->element = 'salary';
215 $this->table_element = 'salary';
216 $this->isextrafieldmanaged = 1;
217
218 $this->fields['ref_ext']['visible'] = getDolGlobalInt('MAIN_LIST_SHOW_REF_EXT');
219 }
220
232 public function generateDocument($model, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = array())
233 {
234 global $conf, $langs;
235
236 if (!dol_strlen($model)) {
237 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Model"));
238 $this->errors[] = $this->error;
239 return 0;
240 }
241
242 $modelpath = 'core/modules/salaries/doc/';
243 $modelfile = $modelpath."pdf_".$model.".modules.php";
244
245 // Check if model file exists
246 if (file_exists(DOL_DOCUMENT_ROOT.'/'.$modelfile)) {
247 require_once DOL_DOCUMENT_ROOT.'/'.$modelfile;
248
249 $classname = 'pdf_'.$model;
250 if (class_exists($classname)) {
251 $module = new $classname($this->db);
252
253 // Generate the PDF
255 $result = $module->writeFile($this, $outputlangs);
256 if ($result > 0) {
257 // Index file in database, as commonGenerateDocument() does
258 if (!empty($module->result['fullpath'])) {
259 if (dol_is_file($module->result['fullpath'])) {
260 $this->indexFile($module->result['fullpath'], (empty($module->update_main_doc_field) ? 0 : 1));
261 }
262 } else {
263 dol_syslog('Method ->writeFile was called on object '.get_class($module).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING);
264 }
265
266 return 1;
267 } else {
268 $this->error = $module->error;
269 $this->errors = $module->errors;
270 return 0;
271 }
272 } else {
273 $this->error = 'Failed to load class '.$classname;
274 $this->errors[] = $this->error;
275 return 0;
276 }
277 } else {
278 $this->error = $langs->trans("ErrorModuleNotFound", $model);
279 $this->errors[] = $this->error;
280 return 0;
281 }
282 }
283
291 public function update($user = null, $notrigger = 0)
292 {
293 $error = 0;
294
295 // Clean parameters
296 $this->amount = trim((string) $this->amount);
297 $this->label = trim((string) $this->label);
298 $this->note = trim((string) $this->note);
299 $this->note_private = trim((string) $this->note_private);
300 $this->note_public = trim((string) $this->note_public);
301
302 // Check parameters
303 if (empty($this->fk_user) || $this->fk_user < 0) {
304 $this->error = 'ErrorBadParameter';
305 return -1;
306 }
307
308 $this->db->begin();
309
310 // Update request
311 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
312 $sql .= " tms='".$this->db->idate(dol_now())."',";
313 $sql .= " fk_user=".((int) $this->fk_user).",";
314 /*$sql .= " datep='".$this->db->idate($this->datep)."',";
315 $sql .= " datev='".$this->db->idate($this->datev)."',";*/
316 $sql .= " amount=".price2num($this->amount).",";
317 $sql .= " fk_projet=".($this->fk_project > 0 ? ((int) $this->fk_project) : "null").",";
318 $sql .= " fk_typepayment=".((int) $this->type_payment).",";
319 $sql .= " label='".$this->db->escape($this->label)."',";
320 $sql .= " datesp='".$this->db->idate($this->datesp)."',";
321 $sql .= " dateep='".$this->db->idate($this->dateep)."',";
322 $sql .= " note='".$this->db->escape($this->note)."',";
323 $sql .= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").",";
324 $sql .= " fk_user_author=".((int) $this->fk_user_author).",";
325 $sql .= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
326 $sql .= " WHERE rowid=".((int) $this->id);
327
328 dol_syslog(get_class($this)."::update", LOG_DEBUG);
329 $resql = $this->db->query($sql);
330 if (!$resql) {
331 $this->error = "Error ".$this->db->lasterror();
332 return -1;
333 }
334
335 // Update extrafield
336 $result = $this->insertExtraFields();
337 if ($result < 0) {
338 $error++;
339 }
340
341 if (!$notrigger) {
342 // Call trigger
343 $result = $this->call_trigger('SALARY_MODIFY', $user);
344 if ($result < 0) {
345 $error++;
346 }
347 // End call triggers
348 }
349
350 if (!$error) {
351 $this->db->commit();
352 return 1;
353 } else {
354 $this->db->rollback();
355 return -1;
356 }
357 }
358
359
367 public function fetch($id, $user = null)
368 {
369 $sql = "SELECT";
370 $sql .= " s.rowid,";
371 $sql .= " s.tms,";
372 $sql .= " s.fk_user,";
373 $sql .= " s.datep,";
374 $sql .= " s.datev,";
375 $sql .= " s.amount,";
376 $sql .= " s.fk_projet as fk_project,";
377 $sql .= " s.fk_typepayment,";
378 $sql .= " s.label,";
379 $sql .= " s.datesp,";
380 $sql .= " s.dateep,";
381 $sql .= " s.note as note_private,";
382 $sql .= " s.note_public,";
383 $sql .= " s.paye,";
384 $sql .= " s.fk_bank,";
385 $sql .= " s.fk_user_author,";
386 $sql .= " s.fk_user_modif,";
387 $sql .= " s.fk_account,";
388 $sql .= " cp.code as type_payment_code";
389 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
390 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
391 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON s.fk_typepayment = cp.id";
392 $sql .= " WHERE s.rowid = ".((int) $id);
393
394 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
395
396 $resql = $this->db->query($sql);
397 if ($resql) {
398 if ($this->db->num_rows($resql)) {
399 $obj = $this->db->fetch_object($resql);
400
401 $this->id = $obj->rowid;
402 $this->ref = $obj->rowid;
403 $this->tms = $this->db->jdate($obj->tms);
404 $this->fk_user = $obj->fk_user;
405 $this->datep = $this->db->jdate($obj->datep);
406 $this->datev = $this->db->jdate($obj->datev);
407 $this->amount = $obj->amount;
408 $this->fk_project = $obj->fk_project;
409 $this->type_payment = $obj->fk_typepayment;
410 $this->type_payment_code = $obj->type_payment_code;
411 $this->label = $obj->label;
412 $this->datesp = $this->db->jdate($obj->datesp);
413 $this->dateep = $this->db->jdate($obj->dateep);
414 $this->note = $obj->note_private;
415 $this->note_private = $obj->note_private;
416 $this->note_public = $obj->note_public;
417 $this->paye = $obj->paye;
418 $this->status = $obj->paye;
419 $this->fk_bank = $obj->fk_bank;
420 $this->fk_user_author = $obj->fk_user_author;
421 $this->fk_user_modif = $obj->fk_user_modif;
422 $this->fk_account = $obj->fk_account;
423 $this->accountid = $obj->fk_account;
424
425 // Retrieve all extrafield
426 // fetch optionals attributes and labels
427 $this->fetch_optionals();
428 }
429 $this->db->free($resql);
430
431 return 1;
432 } else {
433 $this->error = "Error ".$this->db->lasterror();
434 return -1;
435 }
436 }
437
438
446 public function delete($user, $notrigger = 0)
447 {
448 return $this->deleteCommon($user, $notrigger);
449 }
450
451
459 public function initAsSpecimen()
460 {
461 $this->id = 0;
462
463 $this->tms = dol_now();
464 $this->fk_user = 0;
465 $this->datep = '';
466 $this->datev = '';
467 $this->amount = '';
468 $this->label = '';
469 $this->datesp = '';
470 $this->dateep = '';
471 $this->note = '';
472 $this->fk_bank = 0;
473 $this->fk_user_author = 0;
474 $this->fk_user_modif = 0;
475
476 return 1;
477 }
478
485 public function create($user)
486 {
487 global $conf, $langs;
488
489 $error = 0;
490 $now = dol_now();
491
492 // Clean parameters
493 $this->amount = price2num(trim((string) $this->amount));
494 $this->label = trim((string) $this->label);
495 $this->note = trim((string) $this->note);
496 $this->fk_bank = (int) $this->fk_bank;
497 $this->fk_user_author = (int) $this->fk_user_author;
498 $this->fk_user_modif = (int) $this->fk_user_modif;
499 $this->accountid = (int) $this->accountid;
500 $this->paye = (int) $this->paye;
501
502 // Check parameters
503 if (!$this->label) {
504 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
505 return -3;
506 }
507 if ($this->fk_user < 0 || $this->fk_user == '') {
508 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee"));
509 return -4;
510 }
511 if ($this->amount == '') {
512 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
513 return -5;
514 }
515
516 $this->db->begin();
517
518 // Insert into llx_salary
519 $sql = "INSERT INTO ".MAIN_DB_PREFIX."salary (fk_user";
520 //$sql .= ", datep";
521 //$sql .= ", datev";
522 $sql .= ", amount";
523 $sql .= ", fk_projet";
524 $sql .= ", salary";
525 $sql .= ", fk_typepayment";
526 $sql .= ", fk_account";
527 if ($this->note) {
528 $sql .= ", note";
529 }
530 $sql .= ", label";
531 $sql .= ", datesp";
532 $sql .= ", dateep";
533 $sql .= ", fk_user_author";
534 $sql .= ", datec";
535 $sql .= ", fk_bank";
536 $sql .= ", entity";
537 $sql .= ") ";
538 $sql .= " VALUES (";
539 $sql .= ((int) $this->fk_user);
540 //$sql .= ", '".$this->db->idate($this->datep)."'";
541 //$sql .= ", '".$this->db->idate($this->datev)."'";
542 $sql .= ", ".((float) $this->amount);
543 $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : "null");
544 $sql .= ", ".($this->salary > 0 ? ((float) $this->salary) : "null");
545 $sql .= ", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
546 $sql .= ", ".($this->accountid > 0 ? ((int) $this->accountid) : "null");
547 if ($this->note) {
548 $sql .= ", '".$this->db->escape($this->note)."'";
549 }
550 $sql .= ", '".$this->db->escape($this->label)."'";
551 $sql .= ", '".$this->db->idate($this->datesp)."'";
552 $sql .= ", '".$this->db->idate($this->dateep)."'";
553 $sql .= ", ".((int) $user->id);
554 $sql .= ", '".$this->db->idate($now)."'";
555 $sql .= ", NULL";
556 $sql .= ", ".((int) $conf->entity);
557 $sql .= ")";
558
559 dol_syslog(get_class($this)."::create", LOG_DEBUG);
560 $result = $this->db->query($sql);
561 if ($result) {
562 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."salary");
563
564 if ($this->id > 0) {
565 // Update extrafield
566 $result = $this->insertExtraFields();
567 if ($result < 0) {
568 $error++;
569 }
570
571 // Call trigger
572 $result = $this->call_trigger('SALARY_CREATE', $user);
573 if ($result < 0) {
574 $error++;
575 }
576 // End call triggers
577 } else {
578 $error++;
579 }
580
581 if (!$error) {
582 $this->db->commit();
583 return $this->id;
584 } else {
585 $this->db->rollback();
586 return -2;
587 }
588 } else {
589 $this->error = $this->db->error();
590 $this->db->rollback();
591 return -1;
592 }
593 }
594
595 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
602 public function update_fk_bank($id_bank)
603 {
604 // phpcs:enable
605 $sql = 'UPDATE '.MAIN_DB_PREFIX.'salary SET fk_bank = '.((int) $id_bank);
606 $sql .= " WHERE rowid = ".((int) $this->id);
607 $result = $this->db->query($sql);
608 if ($result) {
609 return 1;
610 } else {
611 dol_print_error($this->db);
612 return -1;
613 }
614 }
615
622 public function getTooltipContentArray($params)
623 {
624 global $langs;
625
626 $langs->loadLangs(['salaries']);
627
628 // Complete datas
629 if (!empty($params['fromajaxtooltip']) && !isset($this->alreadypaid)) {
630 // Load the alreadypaid field
631 $this->alreadypaid = $this->getSommePaiement(0);
632 }
633
634 $datas = [];
635
636 $datas['picto'] = '<u>'.$langs->trans("Salary").'</u>';
637 if (isset($this->status) && isset($this->alreadypaid)) {
638 $datas['picto'] .= ' '.$this->getLibStatut(5, $this->alreadypaid);
639 }
640 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
641
642 return $datas;
643 }
644
655 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
656 {
657 global $conf, $langs, $hookmanager;
658
659 if (!empty($conf->dol_no_mouse_hover)) {
660 $notooltip = 1;
661 } // Force disable tooltips
662
663 $result = '';
664 $params = [
665 'id' => $this->id,
666 'objecttype' => $this->element,
667 'option' => $option,
668 ];
669 $classfortooltip = 'classfortooltip';
670 $dataparams = '';
671 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
672 $classfortooltip = 'classforajaxtooltip';
673 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
674 $label = '';
675 } else {
676 $label = implode($this->getTooltipContentArray($params));
677 }
678
679 $url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id;
680
681 if ($option != 'nolink') {
682 // Add param to save lastsearch_values or not
683 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
684 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
685 $add_save_lastsearch_values = 1;
686 }
687 if ($add_save_lastsearch_values) {
688 $url .= '&save_lastsearch_values=1';
689 }
690 }
691
692 $linkclose = '';
693 if (empty($notooltip)) {
694 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
695 $label = $langs->trans("ShowMyObject");
696 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
697 }
698 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
699 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
700 } else {
701 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
702 }
703
704 $linkstart = '<a href="'.$url.'"';
705 $linkstart .= $linkclose.'>';
706 $linkend = '</a>';
707
708 $result .= $linkstart;
709 if ($withpicto) {
710 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
711 }
712 if ($withpicto != 2) {
713 $result .= $this->ref;
714 }
715 $result .= $linkend;
716 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
717
718 global $action, $hookmanager;
719 $hookmanager->initHooks(array('salarypayment'));
720 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
721 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
722 if ($reshook > 0) {
723 $result = $hookmanager->resPrint;
724 } else {
725 $result .= $hookmanager->resPrint;
726 }
727
728 return $result;
729 }
730
737 public function getSommePaiement($multicurrency = 0)
738 {
739 $sql = "SELECT sum(amount) as amount";
740 //sum(multicurrency_amount) as multicurrency_amount // Not yet supported
741 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary";
742 $sql .= " WHERE fk_salary = ".((int) $this->id);
743
744 dol_syslog(get_class($this)."::getSommePaiement for salary id=".((int) $this->id), LOG_DEBUG);
745
746 $resql = $this->db->query($sql);
747
748 if ($resql) {
749 $obj = $this->db->fetch_object($resql);
750
751 $this->db->free($resql);
752
753 if ($obj) {
754 if ($multicurrency < 0) {
755 //$this->totalpaid = $obj->amount;
756 //$this->totalpaid_multicurrency = $obj->multicurrency_amount;
757 //return array('alreadypaid'=>(float) $obj->amount, 'alreadypaid_multicurrency'=>(float) $obj->multicurrency_amount);
758 return array(); // Not yet supported
759 } elseif ($multicurrency) {
760 //$this->totalpaid_multicurrency = $obj->multicurrency_amount;
761 //return (float) $obj->multicurrency_amount;
762 return -1; // Not yet supported
763 } else {
764 //$this->totalpaid = $obj->amount;
765 return (float) $obj->amount;
766 }
767 } else {
768 return 0;
769 }
770 } else {
771 $this->error = $this->db->lasterror();
772 return -1;
773 }
774 }
775
782 public function info($id)
783 {
784 $sql = 'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
785 $sql .= ' FROM '.MAIN_DB_PREFIX.'salary as ps';
786 $sql .= ' WHERE ps.rowid = '.((int) $id);
787
788 dol_syslog(get_class($this).'::info', LOG_DEBUG);
789 $result = $this->db->query($sql);
790
791 if ($result) {
792 if ($this->db->num_rows($result)) {
793 $obj = $this->db->fetch_object($result);
794
795 $this->id = $obj->rowid;
796
797 $this->user_creation_id = $obj->fk_user_author;
798 $this->user_modification_id = $obj->fk_user_modif;
799 $this->date_creation = $this->db->jdate($obj->datec);
800 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
801 }
802 $this->db->free($result);
803 } else {
804 dol_print_error($this->db);
805 }
806 }
807
808 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
817 public function set_paid($user)
818 {
819 // phpcs:enable
820 dol_syslog(get_class($this)."::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
821 return $this->setPaid($user);
822 }
823
830 public function setPaid($user)
831 {
832 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
833 $sql .= " paye = 1";
834 $sql .= " WHERE rowid = ".((int) $this->id);
835
836 $return = $this->db->query($sql);
837
838 if ($return) {
839 $this->paye = 1;
840 return 1;
841 } else {
842 return -1;
843 }
844 }
845
846 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
853 public function set_unpaid($user)
854 {
855 // phpcs:enable
856 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
857 $sql .= " paye = 0";
858 $sql .= " WHERE rowid = ".((int) $this->id);
859
860 $return = $this->db->query($sql);
861
862 if ($return) {
863 $this->paye = 0;
864 return 1;
865 } else {
866 return -1;
867 }
868 }
869
870
878 public function getLibStatut($mode = 0, $alreadypaid = -1)
879 {
880 return $this->LibStatut($this->paye, $mode, $alreadypaid);
881 }
882
883 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
892 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
893 {
894 // phpcs:enable
895 global $langs;
896
897 // Load translation files required by the page
898 $langs->loadLangs(array("customers", "bills"));
899
900 // We reinit status array to force to redefine them because label may change according to properties values.
901 $this->labelStatus = array();
902 $this->labelStatusShort = array();
903
904 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
905 global $langs;
906 //$langs->load("mymodule");
907 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
908 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
909 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
910 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
911 }
912 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
913 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
914 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
915 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
916 }
917 }
918
919 $statusType = 'status1';
920 if ($status == 0 && $alreadypaid != 0) {
921 $statusType = 'status3';
922 }
923 if ($status == 1) {
924 $statusType = 'status6';
925 }
926
927 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
928 }
929
937 public function getKanbanView($option = '', $arraydata = null)
938 {
939 global $langs;
940
941 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
942
943 $return = '<div class="box-flex-item box-flex-grow-zero">';
944 $return .= '<div class="info-box info-box-sm">';
945 $return .= '<span class="info-box-icon bg-infobox-action">';
946 $return .= img_picto('', $this->picto);
947 $return .= '</span>';
948 $return .= '<div class="info-box-content">';
949 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(1) . '</span>';
950 if ($selected >= 0) {
951 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
952 }
953 if (!empty($arraydata['user']) && is_object($arraydata['user'])) {
954 $user = $arraydata['user'];
955 '@phan-var-force User $user';
957 $return .= '<br><span class="info-box-label">'.$user->getNomUrl(empty($arraydata['user']->photo) ? 1 : -1, '', 0, 0, 16, 0, '', 'maxwidth100').'</span>';
958 }
959 $return .= '<br><span class="info-box-label amount">'.price($this->amount).'</span>';
960 if (!empty($this->type_payment)) {
961 $return .= ' <span class="info-box-label opacitymedium small">';
962 if ($langs->trans("PaymentTypeShort".$this->type_payment) != "PaymentTypeShort".$this->type_payment) {
963 $return .= $langs->trans("PaymentTypeShort".$this->type_payment);
964 } elseif ($langs->trans("PaymentType".$this->type_payment) != "PaymentType".$this->type_payment) {
965 $return .= $langs->trans("PaymentType".$this->type_payment);
966 }
967 $return .= '</span>';
968 }
969 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3, isset($this->alreadypaid) ? $this->alreadypaid : $this->totalpaid).'</div>';
970 $return .= '</div>';
971 $return .= '</div>';
972 $return .= '</div>';
973
974 return $return;
975 }
976
977 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
989 public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'salaire', $checkduplicateamongall = 0)
990 {
991 // phpcs:enable
992 global $conf, $mysoc;
993
994 $error = 0;
995
996 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
997 if ($this->paye == 0) {
998 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
999 $bac = new CompanyBankAccount($this->db);
1000 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1001 $bac->fetch(0, '', $mysoc->id);
1002
1003 $sql = "SELECT count(rowid) as nb";
1004 $sql .= " FROM ".$this->db->prefix()."prelevement_demande";
1005 if ($type == 'salaire') {
1006 $sql .= " WHERE fk_salary = ".((int) $this->id);
1007 } else {
1008 $sql .= " WHERE fk_facture = ".((int) $this->id);
1009 }
1010 $sql .= " AND type = 'ban'"; // To exclude record done for some online payments
1011 if (empty($checkduplicateamongall)) {
1012 $sql .= " AND traite = 0";
1013 }
1014
1015 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
1016
1017 $resql = $this->db->query($sql);
1018 if ($resql) {
1019 $obj = $this->db->fetch_object($resql);
1020 if ($obj && $obj->nb == 0) { // If no request found yet
1021 $now = dol_now();
1022
1023 $totalpaid = $this->getSommePaiement();
1024 // $totalcreditnotes = $this->getSumCreditNotesUsed();
1025 // $totaldeposits = $this->getSumDepositsUsed();
1026 //print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
1027
1028 // We can also use bcadd to avoid pb with floating points
1029 // For example print 239.2 - 229.3 - 9.9; does not return 0.
1030 //$resteapayer=bcadd($this->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT);
1031 //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
1032 // if (empty($amount)) {
1033 // $amount = price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
1034 // }
1035
1036 if (is_numeric($amount) && $amount != 0) {
1037 $sql = 'INSERT INTO '.$this->db->prefix().'prelevement_demande(';
1038 if ($type == 'salaire') {
1039 $sql .= 'fk_salary, ';
1040 } else {
1041 $sql .= 'fk_facture, ';
1042 }
1043 $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity)';
1044 $sql .= " VALUES (".((int) $this->id);
1045 $sql .= ", ".((float) price2num($amount));
1046 $sql .= ", '".$this->db->idate($now)."'";
1047 $sql .= ", ".((int) $fuser->id);
1048 $sql .= ", '".$this->db->escape($bac->code_banque)."'";
1049 $sql .= ", '".$this->db->escape($bac->code_guichet)."'";
1050 $sql .= ", '".$this->db->escape($bac->number)."'";
1051 $sql .= ", '".$this->db->escape($bac->cle_rib)."'";
1052 $sql .= ", '".$this->db->escape($sourcetype)."'";
1053 $sql .= ", 'ban'";
1054 $sql .= ", ".((int) $conf->entity);
1055 $sql .= ")";
1056
1057 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
1058 $resql = $this->db->query($sql);
1059 if (!$resql) {
1060 $this->error = $this->db->lasterror();
1061 dol_syslog(get_class($this).'::demandeprelevement Erreur');
1062 $error++;
1063 }
1064 } else {
1065 $this->error = 'WithdrawRequestErrorNilAmount';
1066 dol_syslog(get_class($this).'::demandeprelevement WithdrawRequestErrorNilAmount');
1067 $error++;
1068 }
1069
1070 if (!$error) {
1071 // Force payment mode of invoice to withdraw
1072 $payment_mode_id = dol_getIdFromCode($this->db, (($type == 'bank-transfer' || $type == 'salaire') ? 'VIR' : 'PRE'), 'c_paiement', 'code', 'id', 1);
1073 if ($payment_mode_id > 0) {
1074 $result = $this->setPaymentMethods($payment_mode_id);
1075 }
1076 }
1077
1078 if ($error) {
1079 return -1;
1080 }
1081 return 1;
1082 } else {
1083 $this->error = "A request already exists";
1084 dol_syslog(get_class($this).'::demandeprelevement Can t create a request to generate a direct debit, a request already exists.');
1085 return 0;
1086 }
1087 } else {
1088 $this->error = $this->db->error();
1089 dol_syslog(get_class($this).'::demandeprelevement Error -2');
1090 return -2;
1091 }
1092 } else {
1093 $this->error = "Status of invoice does not allow this";
1094 dol_syslog(get_class($this)."::demandeprelevement ".$this->error." $this->status, $this->paye, $this->mode_reglement_id");
1095 return -3;
1096 }
1097 }
1098
1099 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1107 public function demande_prelevement_delete($fuser, $did)
1108 {
1109 // phpcs:enable
1110 $sql = 'DELETE FROM '.$this->db->prefix().'prelevement_demande';
1111 $sql .= ' WHERE rowid = '.((int) $did);
1112 $sql .= ' AND traite = 0';
1113 if ($this->db->query($sql)) {
1114 return 0;
1115 } else {
1116 $this->error = $this->db->lasterror();
1117 dol_syslog(get_class($this).'::demande_prelevement_delete Error '.$this->error);
1118 return -1;
1119 }
1120 }
1121}
$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...
indexFile($destfull, $update_main_doc_field)
Index a file into the ECM database.
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.
generateDocument($model, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=array())
Generate a document from a model.
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:169
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_is_file($pathoffile)
Return if path is a file.
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)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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.
print $langs trans('Date')." left Ref 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 Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:494