dolibarr 24.0.0-beta
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-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 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Model")), null, 'errors');
238 return 0;
239 }
240
241 $modelpath = 'core/modules/salaries/doc/';
242 $modelfile = $modelpath."pdf_".$model.".modules.php";
243
244 // Check if model file exists
245 if (file_exists(DOL_DOCUMENT_ROOT.'/'.$modelfile)) {
246 require_once DOL_DOCUMENT_ROOT.'/'.$modelfile;
247
248 $classname = 'pdf_'.$model;
249 if (class_exists($classname)) {
250 $module = new $classname($this->db);
251
252 // Generate the PDF
254 $result = $module->writeFile($this, $outputlangs);
255 if ($result > 0) {
256 return 1;
257 } else {
258 setEventMessages($module->error, $module->errors, 'errors');
259 return 0;
260 }
261 } else {
262 setEventMessages('Failed to load class '.$classname, null, 'errors');
263 return 0;
264 }
265 } else {
266 setEventMessages($langs->trans("ErrorModuleNotFound", $model), null, 'errors');
267 return 0;
268 }
269 }
270
278 public function update($user = null, $notrigger = 0)
279 {
280 $error = 0;
281
282 // Clean parameters
283 $this->amount = trim($this->amount);
284 $this->label = trim($this->label);
285 $this->note = trim($this->note);
286 $this->note_private = trim($this->note_private);
287 $this->note_public = trim($this->note_public);
288
289 // Check parameters
290 if (empty($this->fk_user) || $this->fk_user < 0) {
291 $this->error = 'ErrorBadParameter';
292 return -1;
293 }
294
295 $this->db->begin();
296
297 // Update request
298 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
299 $sql .= " tms='".$this->db->idate(dol_now())."',";
300 $sql .= " fk_user=".((int) $this->fk_user).",";
301 /*$sql .= " datep='".$this->db->idate($this->datep)."',";
302 $sql .= " datev='".$this->db->idate($this->datev)."',";*/
303 $sql .= " amount=".price2num($this->amount).",";
304 $sql .= " fk_projet=".((int) $this->fk_project).",";
305 $sql .= " fk_typepayment=".((int) $this->type_payment).",";
306 $sql .= " label='".$this->db->escape($this->label)."',";
307 $sql .= " datesp='".$this->db->idate($this->datesp)."',";
308 $sql .= " dateep='".$this->db->idate($this->dateep)."',";
309 $sql .= " note='".$this->db->escape($this->note)."',";
310 $sql .= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").",";
311 $sql .= " fk_user_author=".((int) $this->fk_user_author).",";
312 $sql .= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
313 $sql .= " WHERE rowid=".((int) $this->id);
314
315 dol_syslog(get_class($this)."::update", LOG_DEBUG);
316 $resql = $this->db->query($sql);
317 if (!$resql) {
318 $this->error = "Error ".$this->db->lasterror();
319 return -1;
320 }
321
322 // Update extrafield
323 $result = $this->insertExtraFields();
324 if ($result < 0) {
325 $error++;
326 }
327
328 if (!$notrigger) {
329 // Call trigger
330 $result = $this->call_trigger('SALARY_MODIFY', $user);
331 if ($result < 0) {
332 $error++;
333 }
334 // End call triggers
335 }
336
337 if (!$error) {
338 $this->db->commit();
339 return 1;
340 } else {
341 $this->db->rollback();
342 return -1;
343 }
344 }
345
346
354 public function fetch($id, $user = null)
355 {
356 $sql = "SELECT";
357 $sql .= " s.rowid,";
358 $sql .= " s.tms,";
359 $sql .= " s.fk_user,";
360 $sql .= " s.datep,";
361 $sql .= " s.datev,";
362 $sql .= " s.amount,";
363 $sql .= " s.fk_projet as fk_project,";
364 $sql .= " s.fk_typepayment,";
365 $sql .= " s.label,";
366 $sql .= " s.datesp,";
367 $sql .= " s.dateep,";
368 $sql .= " s.note as note_private,";
369 $sql .= " s.note_public,";
370 $sql .= " s.paye,";
371 $sql .= " s.fk_bank,";
372 $sql .= " s.fk_user_author,";
373 $sql .= " s.fk_user_modif,";
374 $sql .= " s.fk_account,";
375 $sql .= " cp.code as type_payment_code";
376 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
377 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
378 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON s.fk_typepayment = cp.id";
379 $sql .= " WHERE s.rowid = ".((int) $id);
380
381 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
382
383 $resql = $this->db->query($sql);
384 if ($resql) {
385 if ($this->db->num_rows($resql)) {
386 $obj = $this->db->fetch_object($resql);
387
388 $this->id = $obj->rowid;
389 $this->ref = $obj->rowid;
390 $this->tms = $this->db->jdate($obj->tms);
391 $this->fk_user = $obj->fk_user;
392 $this->datep = $this->db->jdate($obj->datep);
393 $this->datev = $this->db->jdate($obj->datev);
394 $this->amount = $obj->amount;
395 $this->fk_project = $obj->fk_project;
396 $this->type_payment = $obj->fk_typepayment;
397 $this->type_payment_code = $obj->type_payment_code;
398 $this->label = $obj->label;
399 $this->datesp = $this->db->jdate($obj->datesp);
400 $this->dateep = $this->db->jdate($obj->dateep);
401 $this->note = $obj->note_private;
402 $this->note_private = $obj->note_private;
403 $this->note_public = $obj->note_public;
404 $this->paye = $obj->paye;
405 $this->status = $obj->paye;
406 $this->fk_bank = $obj->fk_bank;
407 $this->fk_user_author = $obj->fk_user_author;
408 $this->fk_user_modif = $obj->fk_user_modif;
409 $this->fk_account = $obj->fk_account;
410 $this->accountid = $obj->fk_account;
411
412 // Retrieve all extrafield
413 // fetch optionals attributes and labels
414 $this->fetch_optionals();
415 }
416 $this->db->free($resql);
417
418 return 1;
419 } else {
420 $this->error = "Error ".$this->db->lasterror();
421 return -1;
422 }
423 }
424
425
433 public function delete($user, $notrigger = 0)
434 {
435 return $this->deleteCommon($user, $notrigger);
436 }
437
438
446 public function initAsSpecimen()
447 {
448 $this->id = 0;
449
450 $this->tms = dol_now();
451 $this->fk_user = 0;
452 $this->datep = '';
453 $this->datev = '';
454 $this->amount = '';
455 $this->label = '';
456 $this->datesp = '';
457 $this->dateep = '';
458 $this->note = '';
459 $this->fk_bank = 0;
460 $this->fk_user_author = 0;
461 $this->fk_user_modif = 0;
462
463 return 1;
464 }
465
472 public function create($user)
473 {
474 global $conf, $langs;
475
476 $error = 0;
477 $now = dol_now();
478
479 // Clean parameters
480 $this->amount = price2num(trim($this->amount));
481 $this->label = trim($this->label);
482 $this->note = trim($this->note);
483 $this->fk_bank = (int) $this->fk_bank;
484 $this->fk_user_author = (int) $this->fk_user_author;
485 $this->fk_user_modif = (int) $this->fk_user_modif;
486 $this->accountid = (int) $this->accountid;
487 $this->paye = (int) $this->paye;
488
489 // Check parameters
490 if (!$this->label) {
491 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
492 return -3;
493 }
494 if ($this->fk_user < 0 || $this->fk_user == '') {
495 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee"));
496 return -4;
497 }
498 if ($this->amount == '') {
499 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
500 return -5;
501 }
502
503 $this->db->begin();
504
505 // Insert into llx_salary
506 $sql = "INSERT INTO ".MAIN_DB_PREFIX."salary (fk_user";
507 //$sql .= ", datep";
508 //$sql .= ", datev";
509 $sql .= ", amount";
510 $sql .= ", fk_projet";
511 $sql .= ", salary";
512 $sql .= ", fk_typepayment";
513 $sql .= ", fk_account";
514 if ($this->note) {
515 $sql .= ", note";
516 }
517 $sql .= ", label";
518 $sql .= ", datesp";
519 $sql .= ", dateep";
520 $sql .= ", fk_user_author";
521 $sql .= ", datec";
522 $sql .= ", fk_bank";
523 $sql .= ", entity";
524 $sql .= ") ";
525 $sql .= " VALUES (";
526 $sql .= "'".((int) $this->fk_user)."'";
527 //$sql .= ", '".$this->db->idate($this->datep)."'";
528 //$sql .= ", '".$this->db->idate($this->datev)."'";
529 $sql .= ", ".((float) $this->amount);
530 $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
531 $sql .= ", ".($this->salary > 0 ? ((float) $this->salary) : "null");
532 $sql .= ", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
533 $sql .= ", ".($this->accountid > 0 ? ((int) $this->accountid) : "null");
534 if ($this->note) {
535 $sql .= ", '".$this->db->escape($this->note)."'";
536 }
537 $sql .= ", '".$this->db->escape($this->label)."'";
538 $sql .= ", '".$this->db->idate($this->datesp)."'";
539 $sql .= ", '".$this->db->idate($this->dateep)."'";
540 $sql .= ", '".((int) $user->id)."'";
541 $sql .= ", '".$this->db->idate($now)."'";
542 $sql .= ", NULL";
543 $sql .= ", ".((int) $conf->entity);
544 $sql .= ")";
545
546 dol_syslog(get_class($this)."::create", LOG_DEBUG);
547 $result = $this->db->query($sql);
548 if ($result) {
549 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."salary");
550
551 if ($this->id > 0) {
552 // Update extrafield
553 $result = $this->insertExtraFields();
554 if ($result < 0) {
555 $error++;
556 }
557
558 // Call trigger
559 $result = $this->call_trigger('SALARY_CREATE', $user);
560 if ($result < 0) {
561 $error++;
562 }
563 // End call triggers
564 } else {
565 $error++;
566 }
567
568 if (!$error) {
569 $this->db->commit();
570 return $this->id;
571 } else {
572 $this->db->rollback();
573 return -2;
574 }
575 } else {
576 $this->error = $this->db->error();
577 $this->db->rollback();
578 return -1;
579 }
580 }
581
582 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
589 public function update_fk_bank($id_bank)
590 {
591 // phpcs:enable
592 $sql = 'UPDATE '.MAIN_DB_PREFIX.'salary SET fk_bank = '.((int) $id_bank);
593 $sql .= " WHERE rowid = ".((int) $this->id);
594 $result = $this->db->query($sql);
595 if ($result) {
596 return 1;
597 } else {
598 dol_print_error($this->db);
599 return -1;
600 }
601 }
602
609 public function getTooltipContentArray($params)
610 {
611 global $langs;
612
613 $langs->loadLangs(['salaries']);
614
615 // Complete datas
616 if (!empty($params['fromajaxtooltip']) && !isset($this->alreadypaid)) {
617 // Load the alreadypaid field
618 $this->alreadypaid = $this->getSommePaiement(0);
619 }
620
621 $datas = [];
622
623 $datas['picto'] = '<u>'.$langs->trans("Salary").'</u>';
624 if (isset($this->status) && isset($this->alreadypaid)) {
625 $datas['picto'] .= ' '.$this->getLibStatut(5, $this->alreadypaid);
626 }
627 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
628
629 return $datas;
630 }
631
642 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
643 {
644 global $conf, $langs, $hookmanager;
645
646 if (!empty($conf->dol_no_mouse_hover)) {
647 $notooltip = 1;
648 } // Force disable tooltips
649
650 $result = '';
651 $params = [
652 'id' => $this->id,
653 'objecttype' => $this->element,
654 'option' => $option,
655 ];
656 $classfortooltip = 'classfortooltip';
657 $dataparams = '';
658 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
659 $classfortooltip = 'classforajaxtooltip';
660 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
661 $label = '';
662 } else {
663 $label = implode($this->getTooltipContentArray($params));
664 }
665
666 $url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id;
667
668 if ($option != 'nolink') {
669 // Add param to save lastsearch_values or not
670 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
671 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
672 $add_save_lastsearch_values = 1;
673 }
674 if ($add_save_lastsearch_values) {
675 $url .= '&save_lastsearch_values=1';
676 }
677 }
678
679 $linkclose = '';
680 if (empty($notooltip)) {
681 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
682 $label = $langs->trans("ShowMyObject");
683 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
684 }
685 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
686 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
687 } else {
688 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
689 }
690
691 $linkstart = '<a href="'.$url.'"';
692 $linkstart .= $linkclose.'>';
693 $linkend = '</a>';
694
695 $result .= $linkstart;
696 if ($withpicto) {
697 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
698 }
699 if ($withpicto != 2) {
700 $result .= $this->ref;
701 }
702 $result .= $linkend;
703 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
704
705 global $action, $hookmanager;
706 $hookmanager->initHooks(array('salarypayment'));
707 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
708 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
709 if ($reshook > 0) {
710 $result = $hookmanager->resPrint;
711 } else {
712 $result .= $hookmanager->resPrint;
713 }
714
715 return $result;
716 }
717
724 public function getSommePaiement($multicurrency = 0)
725 {
726 $sql = "SELECT sum(amount) as amount";
727 //sum(multicurrency_amount) as multicurrency_amount // Not yet supported
728 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary";
729 $sql .= " WHERE fk_salary = ".((int) $this->id);
730
731 dol_syslog(get_class($this)."::getSommePaiement for salary id=".((int) $this->id), LOG_DEBUG);
732
733 $resql = $this->db->query($sql);
734
735 if ($resql) {
736 $obj = $this->db->fetch_object($resql);
737
738 $this->db->free($resql);
739
740 if ($obj) {
741 if ($multicurrency < 0) {
742 //$this->totalpaid = $obj->amount;
743 //$this->totalpaid_multicurrency = $obj->multicurrency_amount;
744 //return array('alreadypaid'=>(float) $obj->amount, 'alreadypaid_multicurrency'=>(float) $obj->multicurrency_amount);
745 return array(); // Not yet supported
746 } elseif ($multicurrency) {
747 //$this->totalpaid_multicurrency = $obj->multicurrency_amount;
748 //return (float) $obj->multicurrency_amount;
749 return -1; // Not yet supported
750 } else {
751 //$this->totalpaid = $obj->amount;
752 return (float) $obj->amount;
753 }
754 } else {
755 return 0;
756 }
757 } else {
758 $this->error = $this->db->lasterror();
759 return -1;
760 }
761 }
762
769 public function info($id)
770 {
771 $sql = 'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
772 $sql .= ' FROM '.MAIN_DB_PREFIX.'salary as ps';
773 $sql .= ' WHERE ps.rowid = '.((int) $id);
774
775 dol_syslog(get_class($this).'::info', LOG_DEBUG);
776 $result = $this->db->query($sql);
777
778 if ($result) {
779 if ($this->db->num_rows($result)) {
780 $obj = $this->db->fetch_object($result);
781
782 $this->id = $obj->rowid;
783
784 $this->user_creation_id = $obj->fk_user_author;
785 $this->user_modification_id = $obj->fk_user_modif;
786 $this->date_creation = $this->db->jdate($obj->datec);
787 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
788 }
789 $this->db->free($result);
790 } else {
791 dol_print_error($this->db);
792 }
793 }
794
795 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
804 public function set_paid($user)
805 {
806 // phpcs:enable
807 dol_syslog(get_class($this)."::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
808 return $this->setPaid($user);
809 }
810
817 public function setPaid($user)
818 {
819 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
820 $sql .= " paye = 1";
821 $sql .= " WHERE rowid = ".((int) $this->id);
822
823 $return = $this->db->query($sql);
824
825 if ($return) {
826 $this->paye = 1;
827 return 1;
828 } else {
829 return -1;
830 }
831 }
832
833 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
840 public function set_unpaid($user)
841 {
842 // phpcs:enable
843 $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET";
844 $sql .= " paye = 0";
845 $sql .= " WHERE rowid = ".((int) $this->id);
846
847 $return = $this->db->query($sql);
848
849 if ($return) {
850 $this->paye = 0;
851 return 1;
852 } else {
853 return -1;
854 }
855 }
856
857
865 public function getLibStatut($mode = 0, $alreadypaid = -1)
866 {
867 return $this->LibStatut($this->paye, $mode, $alreadypaid);
868 }
869
870 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
879 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
880 {
881 // phpcs:enable
882 global $langs;
883
884 // Load translation files required by the page
885 $langs->loadLangs(array("customers", "bills"));
886
887 // We reinit status array to force to redefine them because label may change according to properties values.
888 $this->labelStatus = array();
889 $this->labelStatusShort = array();
890
891 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
892 global $langs;
893 //$langs->load("mymodule");
894 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
895 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
896 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
897 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
898 }
899 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
900 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
901 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
902 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
903 }
904 }
905
906 $statusType = 'status1';
907 if ($status == 0 && $alreadypaid != 0) {
908 $statusType = 'status3';
909 }
910 if ($status == 1) {
911 $statusType = 'status6';
912 }
913
914 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
915 }
916
924 public function getKanbanView($option = '', $arraydata = null)
925 {
926 global $langs;
927
928 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
929
930 $return = '<div class="box-flex-item box-flex-grow-zero">';
931 $return .= '<div class="info-box info-box-sm">';
932 $return .= '<span class="info-box-icon bg-infobox-action">';
933 $return .= img_picto('', $this->picto);
934 $return .= '</span>';
935 $return .= '<div class="info-box-content">';
936 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(1) . '</span>';
937 if ($selected >= 0) {
938 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
939 }
940 if (!empty($arraydata['user']) && is_object($arraydata['user'])) {
941 $user = $arraydata['user'];
942 '@phan-var-force User $user';
944 $return .= '<br><span class="info-box-label">'.$user->getNomUrl(empty($arraydata['user']->photo) ? 1 : -1, '', 0, 0, 16, 0, '', 'maxwidth100').'</span>';
945 }
946 $return .= '<br><span class="info-box-label amount">'.price($this->amount).'</span>';
947 if (!empty($this->type_payment)) {
948 $return .= ' <span class="info-box-label opacitymedium small">';
949 if ($langs->trans("PaymentTypeShort".$this->type_payment) != "PaymentTypeShort".$this->type_payment) {
950 $return .= $langs->trans("PaymentTypeShort".$this->type_payment);
951 } elseif ($langs->trans("PaymentType".$this->type_payment) != "PaymentType".$this->type_payment) {
952 $return .= $langs->trans("PaymentType".$this->type_payment);
953 }
954 $return .= '</span>';
955 }
956 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3, isset($this->alreadypaid) ? $this->alreadypaid : $this->totalpaid).'</div>';
957 $return .= '</div>';
958 $return .= '</div>';
959 $return .= '</div>';
960
961 return $return;
962 }
963
964 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
976 public function demande_prelevement($fuser, $amount = 0, $type = 'direct-debit', $sourcetype = 'salaire', $checkduplicateamongall = 0)
977 {
978 // phpcs:enable
979 global $conf, $mysoc;
980
981 $error = 0;
982
983 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
984 if ($this->paye == 0) {
985 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
986 $bac = new CompanyBankAccount($this->db);
987 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
988 $bac->fetch(0, '', $mysoc->id);
989
990 $sql = "SELECT count(rowid) as nb";
991 $sql .= " FROM ".$this->db->prefix()."prelevement_demande";
992 if ($type == 'salaire') {
993 $sql .= " WHERE fk_salary = ".((int) $this->id);
994 } else {
995 $sql .= " WHERE fk_facture = ".((int) $this->id);
996 }
997 $sql .= " AND type = 'ban'"; // To exclude record done for some online payments
998 if (empty($checkduplicateamongall)) {
999 $sql .= " AND traite = 0";
1000 }
1001
1002 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
1003
1004 $resql = $this->db->query($sql);
1005 if ($resql) {
1006 $obj = $this->db->fetch_object($resql);
1007 if ($obj && $obj->nb == 0) { // If no request found yet
1008 $now = dol_now();
1009
1010 $totalpaid = $this->getSommePaiement();
1011 // $totalcreditnotes = $this->getSumCreditNotesUsed();
1012 // $totaldeposits = $this->getSumDepositsUsed();
1013 //print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
1014
1015 // We can also use bcadd to avoid pb with floating points
1016 // For example print 239.2 - 229.3 - 9.9; does not return 0.
1017 //$resteapayer=bcadd($this->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT);
1018 //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
1019 // if (empty($amount)) {
1020 // $amount = price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
1021 // }
1022
1023 if (is_numeric($amount) && $amount != 0) {
1024 $sql = 'INSERT INTO '.$this->db->prefix().'prelevement_demande(';
1025 if ($type == 'salaire') {
1026 $sql .= 'fk_salary, ';
1027 } else {
1028 $sql .= 'fk_facture, ';
1029 }
1030 $sql .= ' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity)';
1031 $sql .= " VALUES (".((int) $this->id);
1032 $sql .= ", ".((float) price2num($amount));
1033 $sql .= ", '".$this->db->idate($now)."'";
1034 $sql .= ", ".((int) $fuser->id);
1035 $sql .= ", '".$this->db->escape($bac->code_banque)."'";
1036 $sql .= ", '".$this->db->escape($bac->code_guichet)."'";
1037 $sql .= ", '".$this->db->escape($bac->number)."'";
1038 $sql .= ", '".$this->db->escape($bac->cle_rib)."'";
1039 $sql .= ", '".$this->db->escape($sourcetype)."'";
1040 $sql .= ", 'ban'";
1041 $sql .= ", ".((int) $conf->entity);
1042 $sql .= ")";
1043
1044 dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
1045 $resql = $this->db->query($sql);
1046 if (!$resql) {
1047 $this->error = $this->db->lasterror();
1048 dol_syslog(get_class($this).'::demandeprelevement Erreur');
1049 $error++;
1050 }
1051 } else {
1052 $this->error = 'WithdrawRequestErrorNilAmount';
1053 dol_syslog(get_class($this).'::demandeprelevement WithdrawRequestErrorNilAmount');
1054 $error++;
1055 }
1056
1057 if (!$error) {
1058 // Force payment mode of invoice to withdraw
1059 $payment_mode_id = dol_getIdFromCode($this->db, (($type == 'bank-transfer' || $type == 'salaire') ? 'VIR' : 'PRE'), 'c_paiement', 'code', 'id', 1);
1060 if ($payment_mode_id > 0) {
1061 $result = $this->setPaymentMethods($payment_mode_id);
1062 }
1063 }
1064
1065 if ($error) {
1066 return -1;
1067 }
1068 return 1;
1069 } else {
1070 $this->error = "A request already exists";
1071 dol_syslog(get_class($this).'::demandeprelevement Can t create a request to generate a direct debit, a request already exists.');
1072 return 0;
1073 }
1074 } else {
1075 $this->error = $this->db->error();
1076 dol_syslog(get_class($this).'::demandeprelevement Error -2');
1077 return -2;
1078 }
1079 } else {
1080 $this->error = "Status of invoice does not allow this";
1081 dol_syslog(get_class($this)."::demandeprelevement ".$this->error." $this->status, $this->paye, $this->mode_reglement_id");
1082 return -3;
1083 }
1084 }
1085
1086 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1094 public function demande_prelevement_delete($fuser, $did)
1095 {
1096 // phpcs:enable
1097 $sql = 'DELETE FROM '.$this->db->prefix().'prelevement_demande';
1098 $sql .= ' WHERE rowid = '.((int) $did);
1099 $sql .= ' AND traite = 0';
1100 if ($this->db->query($sql)) {
1101 return 0;
1102 } else {
1103 $this->error = $this->db->lasterror();
1104 dol_syslog(get_class($this).'::demande_prelevement_delete Error '.$this->error);
1105 return -1;
1106 }
1107 }
1108}
$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.
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:168
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_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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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:489