dolibarr 25.0.0-alpha
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 $langs->load("errors");
279 $this->error = $langs->trans("ErrorModuleNotFound", $model);
280 $this->errors[] = $this->error;
281 return 0;
282 }
283 }
284
292 public function update($user = null, $notrigger = 0)
293 {
294 $error = 0;
295
296 // Clean parameters
297 $this->amount = trim((string) $this->amount);
298 $this->label = trim((string) $this->label);
299 $this->note = trim((string) $this->note);
300 $this->note_private = trim((string) $this->note_private);
301 $this->note_public = trim((string) $this->note_public);
302
303 // Check parameters
304 if (empty($this->fk_user) || $this->fk_user < 0) {
305 $this->error = 'ErrorBadParameter';
306 return -1;
307 }
308
309 $this->db->begin();
310
311 // Update request
312 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
313 $sql .= " tms='".$this->db->idate(dol_now())."',";
314 $sql .= " fk_user=".((int) $this->fk_user).",";
315 /*$sql .= " datep='".$this->db->idate($this->datep)."',";
316 $sql .= " datev='".$this->db->idate($this->datev)."',";*/
317 $sql .= " amount=".price2num($this->amount).",";
318 $sql .= " fk_projet=".($this->fk_project > 0 ? ((int) $this->fk_project) : "null").",";
319 $sql .= " fk_typepayment=".((int) $this->type_payment).",";
320 $sql .= " label='".$this->db->escape($this->label)."',";
321 $sql .= " datesp='".$this->db->idate($this->datesp)."',";
322 $sql .= " dateep='".$this->db->idate($this->dateep)."',";
323 $sql .= " note='".$this->db->escape($this->note)."',";
324 $sql .= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").",";
325 $sql .= " fk_user_author=".((int) $this->fk_user_author).",";
326 $sql .= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
327 $sql .= " WHERE rowid=".((int) $this->id);
328
329 dol_syslog(get_class($this)."::update", LOG_DEBUG);
330 $resql = $this->db->query($sql);
331 if (!$resql) {
332 $this->error = "Error ".$this->db->lasterror();
333 return -1;
334 }
335
336 // Update extrafield
337 $result = $this->insertExtraFields();
338 if ($result < 0) {
339 $error++;
340 }
341
342 if (!$notrigger) {
343 // Call trigger
344 $result = $this->call_trigger('SALARY_MODIFY', $user);
345 if ($result < 0) {
346 $error++;
347 }
348 // End call triggers
349 }
350
351 if (!$error) {
352 $this->db->commit();
353 return 1;
354 } else {
355 $this->db->rollback();
356 return -1;
357 }
358 }
359
360
368 public function fetch($id, $user = null)
369 {
370 $sql = "SELECT";
371 $sql .= " s.rowid,";
372 $sql .= " s.tms,";
373 $sql .= " s.fk_user,";
374 $sql .= " s.datep,";
375 $sql .= " s.datev,";
376 $sql .= " s.amount,";
377 $sql .= " s.fk_projet as fk_project,";
378 $sql .= " s.fk_typepayment,";
379 $sql .= " s.label,";
380 $sql .= " s.datesp,";
381 $sql .= " s.dateep,";
382 $sql .= " s.note as note_private,";
383 $sql .= " s.note_public,";
384 $sql .= " s.paye,";
385 $sql .= " s.fk_bank,";
386 $sql .= " s.fk_user_author,";
387 $sql .= " s.fk_user_modif,";
388 $sql .= " s.fk_account,";
389 $sql .= " cp.code as type_payment_code";
390 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
391 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
392 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON s.fk_typepayment = cp.id";
393 $sql .= " WHERE s.rowid = ".((int) $id);
394
395 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
396
397 $resql = $this->db->query($sql);
398 if ($resql) {
399 if ($this->db->num_rows($resql)) {
400 $obj = $this->db->fetch_object($resql);
401
402 $this->id = $obj->rowid;
403 $this->ref = $obj->rowid;
404 $this->tms = $this->db->jdate($obj->tms);
405 $this->fk_user = $obj->fk_user;
406 $this->datep = $this->db->jdate($obj->datep);
407 $this->datev = $this->db->jdate($obj->datev);
408 $this->amount = $obj->amount;
409 $this->fk_project = $obj->fk_project;
410 $this->type_payment = $obj->fk_typepayment;
411 $this->type_payment_code = $obj->type_payment_code;
412 $this->label = $obj->label;
413 $this->datesp = $this->db->jdate($obj->datesp);
414 $this->dateep = $this->db->jdate($obj->dateep);
415 $this->note = $obj->note_private;
416 $this->note_private = $obj->note_private;
417 $this->note_public = $obj->note_public;
418 $this->paye = $obj->paye;
419 $this->status = $obj->paye;
420 $this->fk_bank = $obj->fk_bank;
421 $this->fk_user_author = $obj->fk_user_author;
422 $this->fk_user_modif = $obj->fk_user_modif;
423 $this->fk_account = $obj->fk_account;
424 $this->accountid = $obj->fk_account;
425
426 // Retrieve all extrafield
427 // fetch optionals attributes and labels
428 $this->fetch_optionals();
429 }
430 $this->db->free($resql);
431
432 return 1;
433 } else {
434 $this->error = "Error ".$this->db->lasterror();
435 return -1;
436 }
437 }
438
439
447 public function delete($user, $notrigger = 0)
448 {
449 return $this->deleteCommon($user, $notrigger);
450 }
451
452
460 public function initAsSpecimen()
461 {
462 $this->id = 0;
463
464 $this->tms = dol_now();
465 $this->fk_user = 0;
466 $this->datep = '';
467 $this->datev = '';
468 $this->amount = '';
469 $this->label = '';
470 $this->datesp = '';
471 $this->dateep = '';
472 $this->note = '';
473 $this->fk_bank = 0;
474 $this->fk_user_author = 0;
475 $this->fk_user_modif = 0;
476
477 return 1;
478 }
479
486 public function create($user)
487 {
488 global $conf, $langs;
489
490 $error = 0;
491 $now = dol_now();
492
493 // Clean parameters
494 $this->amount = price2num(trim((string) $this->amount));
495 $this->label = trim((string) $this->label);
496 $this->note = trim((string) $this->note);
497 $this->fk_bank = (int) $this->fk_bank;
498 $this->fk_user_author = (int) $this->fk_user_author;
499 $this->fk_user_modif = (int) $this->fk_user_modif;
500 $this->accountid = (int) $this->accountid;
501 $this->paye = (int) $this->paye;
502
503 // Check parameters
504 if (!$this->label) {
505 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
506 return -3;
507 }
508 if ($this->fk_user < 0 || $this->fk_user == '') {
509 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee"));
510 return -4;
511 }
512 if ($this->amount == '') {
513 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
514 return -5;
515 }
516
517 $this->db->begin();
518
519 // Insert into llx_salary
520 $sql = "INSERT INTO ".MAIN_DB_PREFIX."salary (fk_user";
521 //$sql .= ", datep";
522 //$sql .= ", datev";
523 $sql .= ", amount";
524 $sql .= ", fk_projet";
525 $sql .= ", salary";
526 $sql .= ", fk_typepayment";
527 $sql .= ", fk_account";
528 if ($this->note) {
529 $sql .= ", note";
530 }
531 $sql .= ", label";
532 $sql .= ", datesp";
533 $sql .= ", dateep";
534 $sql .= ", fk_user_author";
535 $sql .= ", datec";
536 $sql .= ", fk_bank";
537 $sql .= ", entity";
538 $sql .= ") ";
539 $sql .= " VALUES (";
540 $sql .= ((int) $this->fk_user);
541 //$sql .= ", '".$this->db->idate($this->datep)."'";
542 //$sql .= ", '".$this->db->idate($this->datev)."'";
543 $sql .= ", ".((float) $this->amount);
544 $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : "null");
545 $sql .= ", ".($this->salary > 0 ? ((float) $this->salary) : "null");
546 $sql .= ", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
547 $sql .= ", ".($this->accountid > 0 ? ((int) $this->accountid) : "null");
548 if ($this->note) {
549 $sql .= ", '".$this->db->escape($this->note)."'";
550 }
551 $sql .= ", '".$this->db->escape($this->label)."'";
552 $sql .= ", '".$this->db->idate($this->datesp)."'";
553 $sql .= ", '".$this->db->idate($this->dateep)."'";
554 $sql .= ", ".((int) $user->id);
555 $sql .= ", '".$this->db->idate($now)."'";
556 $sql .= ", NULL";
557 $sql .= ", ".((int) $conf->entity);
558 $sql .= ")";
559
560 dol_syslog(get_class($this)."::create", LOG_DEBUG);
561 $result = $this->db->query($sql);
562 if ($result) {
563 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."salary");
564
565 if ($this->id > 0) {
566 // Update extrafield
567 $result = $this->insertExtraFields();
568 if ($result < 0) {
569 $error++;
570 }
571
572 // Call trigger
573 $result = $this->call_trigger('SALARY_CREATE', $user);
574 if ($result < 0) {
575 $error++;
576 }
577 // End call triggers
578 } else {
579 $error++;
580 }
581
582 if (!$error) {
583 $this->db->commit();
584 return $this->id;
585 } else {
586 $this->db->rollback();
587 return -2;
588 }
589 } else {
590 $this->error = $this->db->error();
591 $this->db->rollback();
592 return -1;
593 }
594 }
595
596 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
603 public function update_fk_bank($id_bank)
604 {
605 // phpcs:enable
606 $sql = 'UPDATE '.MAIN_DB_PREFIX.'salary SET fk_bank = '.((int) $id_bank);
607 $sql .= " WHERE rowid = ".((int) $this->id);
608 $result = $this->db->query($sql);
609 if ($result) {
610 return 1;
611 } else {
612 dol_print_error($this->db);
613 return -1;
614 }
615 }
616
623 public function getTooltipContentArray($params)
624 {
625 global $langs;
626
627 $langs->loadLangs(['salaries']);
628
629 // Complete datas
630 if (!empty($params['fromajaxtooltip']) && !isset($this->totalpaid)) {
631 // Load the totalpaid field
632 $this->totalpaid = $this->getSommePaiement(0);
633 }
634
635 $datas = [];
636
637 $datas['picto'] = '<u>'.$langs->trans("Salary").'</u>';
638 if (isset($this->status) && isset($this->totalpaid)) {
639 $datas['picto'] .= ' '.$this->getLibStatut(5, $this->totalpaid);
640 }
641 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
642
643 return $datas;
644 }
645
656 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
657 {
658 global $conf, $langs, $hookmanager;
659
660 if (!empty($conf->dol_no_mouse_hover)) {
661 $notooltip = 1;
662 } // Force disable tooltips
663
664 $result = '';
665 $params = [
666 'id' => $this->id,
667 'objecttype' => $this->element,
668 'option' => $option,
669 ];
670 $classfortooltip = 'classfortooltip';
671 $dataparams = '';
672 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
673 $classfortooltip = 'classforajaxtooltip';
674 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
675 $label = '';
676 } else {
677 $label = implode($this->getTooltipContentArray($params));
678 }
679
680 $url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id;
681
682 if ($option != 'nolink') {
683 // Add param to save lastsearch_values or not
684 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
685 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
686 $add_save_lastsearch_values = 1;
687 }
688 if ($add_save_lastsearch_values) {
689 $url .= '&save_lastsearch_values=1';
690 }
691 }
692
693 $linkclose = '';
694 if (empty($notooltip)) {
695 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
696 $label = $langs->trans("ShowMyObject");
697 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
698 }
699 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
700 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
701 } else {
702 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
703 }
704
705 $linkstart = '<a href="'.$url.'"';
706 $linkstart .= $linkclose.'>';
707 $linkend = '</a>';
708
709 $result .= $linkstart;
710 if ($withpicto) {
711 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
712 }
713 if ($withpicto != 2) {
714 $result .= $this->ref;
715 }
716 $result .= $linkend;
717 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
718
719 global $action, $hookmanager;
720 $hookmanager->initHooks(array('salarypayment'));
721 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
722 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
723 if ($reshook > 0) {
724 $result = $hookmanager->resPrint;
725 } else {
726 $result .= $hookmanager->resPrint;
727 }
728
729 return $result;
730 }
731
738 public function getSommePaiement($multicurrency = 0)
739 {
740 $sql = "SELECT sum(amount) as amount";
741 //sum(multicurrency_amount) as multicurrency_amount // Not yet supported
742 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary";
743 $sql .= " WHERE fk_salary = ".((int) $this->id);
744
745 dol_syslog(get_class($this)."::getSommePaiement for salary id=".((int) $this->id), LOG_DEBUG);
746
747 $resql = $this->db->query($sql);
748
749 if ($resql) {
750 $obj = $this->db->fetch_object($resql);
751
752 $this->db->free($resql);
753
754 if ($obj) {
755 if ($multicurrency < 0) {
756 //$this->totalpaid = $obj->amount;
757 //$this->totalpaid_multicurrency = $obj->multicurrency_amount;
758 //return array('alreadypaid'=>(float) $obj->amount, 'alreadypaid_multicurrency'=>(float) $obj->multicurrency_amount);
759 return array(); // Not yet supported
760 } elseif ($multicurrency) {
761 //$this->totalpaid_multicurrency = $obj->multicurrency_amount;
762 //return (float) $obj->multicurrency_amount;
763 return -1; // Not yet supported
764 } else {
765 //$this->totalpaid = $obj->amount;
766 return (float) $obj->amount;
767 }
768 } else {
769 return 0;
770 }
771 } else {
772 $this->error = $this->db->lasterror();
773 return -1;
774 }
775 }
776
783 public function info($id)
784 {
785 $sql = 'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
786 $sql .= ' FROM '.MAIN_DB_PREFIX.'salary as ps';
787 $sql .= ' WHERE ps.rowid = '.((int) $id);
788
789 dol_syslog(get_class($this).'::info', LOG_DEBUG);
790 $result = $this->db->query($sql);
791
792 if ($result) {
793 if ($this->db->num_rows($result)) {
794 $obj = $this->db->fetch_object($result);
795
796 $this->id = $obj->rowid;
797
798 $this->user_creation_id = $obj->fk_user_author;
799 $this->user_modification_id = $obj->fk_user_modif;
800 $this->date_creation = $this->db->jdate($obj->datec);
801 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
802 }
803 $this->db->free($result);
804 } else {
805 dol_print_error($this->db);
806 }
807 }
808
809 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
818 public function set_paid($user)
819 {
820 // phpcs:enable
821 dol_syslog(get_class($this)."::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
822 return $this->setPaid($user);
823 }
824
831 public function setPaid($user)
832 {
833 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
834 $sql .= " paye = 1";
835 $sql .= " WHERE rowid = ".((int) $this->id);
836
837 $return = $this->db->query($sql);
838
839 if ($return) {
840 $this->paye = 1;
841 return 1;
842 } else {
843 return -1;
844 }
845 }
846
847 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
854 public function set_unpaid($user)
855 {
856 // phpcs:enable
857 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
858 $sql .= " paye = 0";
859 $sql .= " WHERE rowid = ".((int) $this->id);
860
861 $return = $this->db->query($sql);
862
863 if ($return) {
864 $this->paye = 0;
865 return 1;
866 } else {
867 return -1;
868 }
869 }
870
871
879 public function getLibStatut($mode = 0, $alreadypaid = -1)
880 {
881 return $this->LibStatut($this->paye, $mode, $alreadypaid);
882 }
883
884 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
893 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
894 {
895 // phpcs:enable
896 global $langs;
897
898 // Load translation files required by the page
899 $langs->loadLangs(array("customers", "bills"));
900
901 // We reinit status array to force to redefine them because label may change according to properties values.
902 $this->labelStatus = array();
903 $this->labelStatusShort = array();
904
905 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
906 global $langs;
907 //$langs->load("mymodule");
908 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
909 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
910 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
911 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
912 }
913 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
914 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
915 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
916 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
917 }
918 }
919
920 $statusType = 'status1';
921 if ($status == 0 && $alreadypaid != 0) {
922 $statusType = 'status3';
923 }
924 if ($status == 1) {
925 $statusType = 'status6';
926 }
927
928 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
929 }
930
938 public function getKanbanView($option = '', $arraydata = null)
939 {
940 global $langs;
941
942 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
943
944 $return = '<div class="box-flex-item box-flex-grow-zero">';
945 $return .= '<div class="info-box info-box-sm">';
946 $return .= '<span class="info-box-icon bg-infobox-action">';
947 $return .= img_picto('', $this->picto);
948 $return .= '</span>';
949 $return .= '<div class="info-box-content">';
950 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(1) . '</span>';
951 if ($selected >= 0) {
952 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
953 }
954 if (!empty($arraydata['user']) && is_object($arraydata['user'])) {
955 $user = $arraydata['user'];
956 '@phan-var-force User $user';
958 $return .= '<br><span class="info-box-label">'.$user->getNomUrl(empty($arraydata['user']->photo) ? 1 : -1, '', 0, 0, 16, 0, '', 'maxwidth100').'</span>';
959 }
960 $return .= '<br><span class="info-box-label amount">'.price($this->amount).'</span>';
961 if (!empty($this->type_payment)) {
962 $return .= ' <span class="info-box-label opacitymedium small">';
963 if ($langs->trans("PaymentTypeShort".$this->type_payment) != "PaymentTypeShort".$this->type_payment) {
964 $return .= $langs->trans("PaymentTypeShort".$this->type_payment);
965 } elseif ($langs->trans("PaymentType".$this->type_payment) != "PaymentType".$this->type_payment) {
966 $return .= $langs->trans("PaymentType".$this->type_payment);
967 }
968 $return .= '</span>';
969 }
970 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3, $this->totalpaid).'</div>';
971 $return .= '</div>';
972 $return .= '</div>';
973 $return .= '</div>';
974
975 return $return;
976 }
977
978 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
990 public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'salaire', $checkduplicateamongall = 0)
991 {
992 // phpcs:enable
993 global $conf, $mysoc;
994
995 $error = 0;
996
997 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
998 if ($this->paye == 0) {
999 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1000 $bac = new CompanyBankAccount($this->db);
1001 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1002 $bac->fetch(0, '', $mysoc->id);
1003
1004 $sql = "SELECT count(rowid) as nb";
1005 $sql .= " FROM ".$this->db->prefix()."prelevement_demande";
1006 if ($type == 'salaire') {
1007 $sql .= " WHERE fk_salary = ".((int) $this->id);
1008 } else {
1009 $sql .= " WHERE fk_facture = ".((int) $this->id);
1010 }
1011 $sql .= " AND type = 'ban'"; // To exclude record done for some online payments
1012 if (empty($checkduplicateamongall)) {
1013 $sql .= " AND traite = 0";
1014 }
1015
1016 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
1017
1018 $resql = $this->db->query($sql);
1019 if ($resql) {
1020 $obj = $this->db->fetch_object($resql);
1021 if ($obj && $obj->nb == 0) { // If no request found yet
1022 $now = dol_now();
1023
1024 $totalpaid = $this->getSommePaiement();
1025 // $totalcreditnotes = $this->getSumCreditNotesUsed();
1026 // $totaldeposits = $this->getSumDepositsUsed();
1027 //print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
1028
1029 // We can also use bcadd to avoid pb with floating points
1030 // For example print 239.2 - 229.3 - 9.9; does not return 0.
1031 //$resteapayer=bcadd($this->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT);
1032 //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
1033 // if (empty($amount)) {
1034 // $amount = price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
1035 // }
1036
1037 if (is_numeric($amount) && $amount != 0) {
1038 $sql = 'INSERT INTO '.$this->db->prefix().'prelevement_demande(';
1039 if ($type == 'salaire') {
1040 $sql .= 'fk_salary, ';
1041 } else {
1042 $sql .= 'fk_facture, ';
1043 }
1044 $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity)';
1045 $sql .= " VALUES (".((int) $this->id);
1046 $sql .= ", ".((float) price2num($amount));
1047 $sql .= ", '".$this->db->idate($now)."'";
1048 $sql .= ", ".((int) $fuser->id);
1049 $sql .= ", '".$this->db->escape($bac->code_banque)."'";
1050 $sql .= ", '".$this->db->escape($bac->code_guichet)."'";
1051 $sql .= ", '".$this->db->escape($bac->number)."'";
1052 $sql .= ", '".$this->db->escape($bac->cle_rib)."'";
1053 $sql .= ", '".$this->db->escape($sourcetype)."'";
1054 $sql .= ", 'ban'";
1055 $sql .= ", ".((int) $conf->entity);
1056 $sql .= ")";
1057
1058 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
1059 $resql = $this->db->query($sql);
1060 if (!$resql) {
1061 $this->error = $this->db->lasterror();
1062 dol_syslog(get_class($this).'::demandeprelevement Erreur');
1063 $error++;
1064 }
1065 } else {
1066 $this->error = 'WithdrawRequestErrorNilAmount';
1067 dol_syslog(get_class($this).'::demandeprelevement WithdrawRequestErrorNilAmount');
1068 $error++;
1069 }
1070
1071 if (!$error) {
1072 // Force payment mode of invoice to withdraw
1073 $payment_mode_id = dol_getIdFromCode($this->db, (($type == 'bank-transfer' || $type == 'salaire') ? 'VIR' : 'PRE'), 'c_paiement', 'code', 'id', 1);
1074 if ($payment_mode_id > 0) {
1075 $result = $this->setPaymentMethods($payment_mode_id);
1076 }
1077 }
1078
1079 if ($error) {
1080 return -1;
1081 }
1082 return 1;
1083 } else {
1084 $this->error = "A request already exists";
1085 dol_syslog(get_class($this).'::demandeprelevement Can t create a request to generate a direct debit, a request already exists.');
1086 return 0;
1087 }
1088 } else {
1089 $this->error = $this->db->error();
1090 dol_syslog(get_class($this).'::demandeprelevement Error -2');
1091 return -2;
1092 }
1093 } else {
1094 $this->error = "Status of invoice does not allow this";
1095 dol_syslog(get_class($this)."::demandeprelevement ".$this->error." $this->status, $this->paye, $this->mode_reglement_id");
1096 return -3;
1097 }
1098 }
1099
1100 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1108 public function demande_prelevement_delete($fuser, $did)
1109 {
1110 // phpcs:enable
1111 $sql = 'DELETE FROM '.$this->db->prefix().'prelevement_demande';
1112 $sql .= ' WHERE rowid = '.((int) $did);
1113 $sql .= ' AND traite = 0';
1114 if ($this->db->query($sql)) {
1115 return 0;
1116 } else {
1117 $this->error = $this->db->lasterror();
1118 dol_syslog(get_class($this).'::demande_prelevement_delete Error '.$this->error);
1119 return -1;
1120 }
1121 }
1122}
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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
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.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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