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