27 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $element =
'salary';
43 public $table_element =
'salary';
48 public $picto =
'salary';
55 protected $childtables = array(
'payment_salary' => array(
'name'=>
'SalaryPayment',
'fk_element'=>
'fk_salary'));
109 public $fk_user_author;
114 public $fk_user_modif;
126 const STATUS_UNPAID = 0;
127 const STATUS_PAID = 1;
138 $this->element =
'salary';
139 $this->table_element =
'salary';
149 public function update($user =
null, $notrigger = 0)
151 global $conf, $langs;
156 $this->amount = trim($this->amount);
157 $this->label = trim($this->label);
158 $this->note = trim($this->note);
161 if (empty($this->fk_user) || $this->fk_user < 0) {
162 $this->error =
'ErrorBadParameter';
169 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
171 $sql .=
" fk_user=".((int) $this->fk_user).
",";
174 $sql .=
" amount=".price2num($this->amount).
",";
175 $sql .=
" fk_projet=".((int) $this->fk_project).
",";
176 $sql .=
" fk_typepayment=".((int) $this->type_payment).
",";
177 $sql .=
" label='".$this->db->escape($this->label).
"',";
178 $sql .=
" datesp='".$this->db->idate($this->datesp).
"',";
179 $sql .=
" dateep='".$this->db->idate($this->dateep).
"',";
180 $sql .=
" note='".$this->db->escape($this->note).
"',";
181 $sql .=
" fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank :
"null").
",";
182 $sql .=
" fk_user_author=".((int) $this->fk_user_author).
",";
183 $sql .=
" fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (
int) $user->id);
184 $sql .=
" WHERE rowid=".((int) $this->
id);
186 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
187 $resql = $this->db->query(
$sql);
189 $this->error =
"Error ".$this->db->lasterror();
206 if ($result < 0) $error++;
214 $this->db->rollback();
227 public function fetch($id, $user =
null)
234 $sql .=
" s.fk_user,";
237 $sql .=
" s.amount,";
238 $sql .=
" s.fk_projet as fk_project,";
239 $sql .=
" s.fk_typepayment,";
241 $sql .=
" s.datesp,";
242 $sql .=
" s.dateep,";
245 $sql .=
" s.fk_bank,";
246 $sql .=
" s.fk_user_author,";
247 $sql .=
" s.fk_user_modif,";
248 $sql .=
" s.fk_account";
250 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
251 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON s.fk_bank = b.rowid";
252 $sql .=
" WHERE s.rowid = ".((int) $id);
254 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
255 $resql = $this->db->query(
$sql);
257 if ($this->db->num_rows($resql)) {
258 $obj = $this->db->fetch_object($resql);
260 $this->
id = $obj->rowid;
261 $this->
ref = $obj->rowid;
262 $this->tms = $this->db->jdate($obj->tms);
263 $this->fk_user = $obj->fk_user;
264 $this->datep = $this->db->jdate($obj->datep);
265 $this->datev = $this->db->jdate($obj->datev);
266 $this->amount = $obj->amount;
267 $this->fk_project = $obj->fk_project;
268 $this->type_payment = $obj->fk_typepayment;
269 $this->label = $obj->label;
270 $this->datesp = $this->db->jdate($obj->datesp);
271 $this->dateep = $this->db->jdate($obj->dateep);
272 $this->note = $obj->note;
273 $this->paye = $obj->paye;
274 $this->fk_bank = $obj->fk_bank;
275 $this->fk_user_author = $obj->fk_user_author;
276 $this->fk_user_modif = $obj->fk_user_modif;
277 $this->fk_account = $obj->fk_account;
278 $this->accountid = $obj->fk_account;
284 $this->db->free($resql);
288 $this->error =
"Error ".$this->db->lasterror();
301 public function delete($user, $notrigger = 0)
328 $this->fk_user_author =
'';
329 $this->fk_user_modif =
'';
340 global $conf, $langs;
346 $this->amount =
price2num(trim($this->amount));
347 $this->label = trim($this->label);
348 $this->note = trim($this->note);
349 $this->fk_bank = trim($this->fk_bank);
350 $this->fk_user_author = trim($this->fk_user_author);
351 $this->fk_user_modif = trim($this->fk_user_modif);
352 $this->accountid = trim($this->accountid);
353 $this->paye = trim($this->paye);
357 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
360 if ($this->fk_user < 0 || $this->fk_user ==
'') {
361 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Employee"));
364 if ($this->amount ==
'') {
365 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
382 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"salary (fk_user";
386 $sql .=
", fk_projet";
388 $sql .=
", fk_typepayment";
389 $sql .=
", fk_account";
390 if ($this->note)
$sql .=
", note";
394 $sql .=
", fk_user_author";
400 $sql .=
"'".$this->db->escape($this->fk_user).
"'";
403 $sql .=
", ".((double) $this->amount);
404 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
405 $sql .=
", ".($this->salary > 0 ? ((double) $this->salary) :
"null");
406 $sql .=
", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
407 $sql .=
", ".($this->accountid > 0 ? ((int) $this->accountid) :
"null");
408 if ($this->note)
$sql .=
", '".$this->db->escape($this->note).
"'";
409 $sql .=
", '".$this->db->escape($this->label).
"'";
410 $sql .=
", '".$this->db->idate($this->datesp).
"'";
411 $sql .=
", '".$this->db->idate($this->dateep).
"'";
412 $sql .=
", '".$this->db->escape($user->id).
"'";
413 $sql .=
", '".$this->db->idate($now).
"'";
415 $sql .=
", ".((int) $conf->entity);
418 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
419 $result = $this->db->query(
$sql);
421 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"salary");
436 if ($result < 0) $error++;
444 $this->db->rollback();
448 $this->error = $this->db->error();
449 $this->db->rollback();
464 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'salary SET fk_bank = '.((int) $id_bank);
465 $sql .=
" WHERE rowid = ".((int) $this->
id);
466 $result = $this->db->query(
$sql);
483 global $conf, $langs, $user;
485 $langs->loadLangs([
'salaries']);
488 $option = $params[
'option'] ??
'';
489 $datas[
'picto'] =
'<u>'.$langs->trans(
"Salary").
'</u>';
490 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
505 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
507 global $db, $conf, $langs, $hookmanager;
508 global $dolibarr_main_authentication, $dolibarr_main_demo;
511 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
516 'objecttype' => $this->element,
519 $classfortooltip =
'classfortooltip';
522 $classfortooltip =
'classforajaxtooltip';
523 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
529 $url = DOL_URL_ROOT.
'/salaries/card.php?id='.$this->id;
531 if ($option !=
'nolink') {
533 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
534 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
535 $add_save_lastsearch_values = 1;
537 if ($add_save_lastsearch_values) {
538 $url .=
'&save_lastsearch_values=1';
543 if (empty($notooltip)) {
544 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
545 $label = $langs->trans(
"ShowMyObject");
546 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
548 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
549 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
551 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
554 $linkstart =
'<a href="'.$url.
'"';
555 $linkstart .= $linkclose.
'>';
558 $result .= $linkstart;
560 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright pictofixedwidth"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
' pictofixedwidth"'), 0, 0, $notooltip ? 0 : 1);
562 if ($withpicto != 2) {
563 $result .= $this->ref;
568 global $action, $hookmanager;
569 $hookmanager->initHooks(array(
'salarypayment'));
570 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
571 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
572 if ($reshook > 0) $result = $hookmanager->resPrint;
573 else $result .= $hookmanager->resPrint;
585 $table =
'payment_salary';
586 $field =
'fk_salary';
588 $sql =
"SELECT sum(amount) as amount";
589 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
590 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
592 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
593 $resql = $this->db->query(
$sql);
598 $obj = $this->db->fetch_object($resql);
599 if ($obj) $amount = $obj->amount ? $obj->amount : 0;
601 $this->db->free($resql);
616 $sql =
'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
617 $sql .=
' FROM '.MAIN_DB_PREFIX.
'salary as ps';
618 $sql .=
' WHERE ps.rowid = '.((int) $id);
620 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
621 $result = $this->db->query(
$sql);
624 if ($this->db->num_rows($result)) {
625 $obj = $this->db->fetch_object($result);
626 $this->
id = $obj->rowid;
628 $this->user_creation_id = $obj->fk_user_author;
629 $this->user_modification_id = $obj->fk_user_modif;
630 $this->date_creation = $this->db->jdate($obj->datec);
631 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
633 $this->db->free($result);
649 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
651 $sql .=
" WHERE rowid = ".((int) $this->
id);
652 $return = $this->db->query(
$sql);
653 if ($return)
return 1;
667 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
669 $sql .=
" WHERE rowid = ".((int) $this->
id);
670 $return = $this->db->query(
$sql);
671 if ($return)
return 1;
685 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
697 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
703 $langs->loadLangs(array(
"customers",
"bills"));
706 $this->labelStatus = array();
707 $this->labelStatusShort = array();
709 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
712 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
713 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
714 if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
715 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
716 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
717 if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
720 $statusType =
'status1';
721 if ($status == 0 && $alreadypaid <> 0) $statusType =
'status3';
722 if ($status == 1) $statusType =
'status6';
724 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
738 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
740 $return =
'<div class="box-flex-item box-flex-grow-zero">';
741 $return .=
'<div class="info-box info-box-sm">';
742 $return .=
'<span class="info-box-icon bg-infobox-action">';
744 $return .=
'</span>';
745 $return .=
'<div class="info-box-content">';
746 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
747 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
748 if (!empty($arraydata[
'user']) && is_object($arraydata[
'user'])) {
749 $return .=
'<br><span class="info-box-label">'.$arraydata[
'user']->getNomUrl(1,
'', 0, 0, 16, 0,
'',
'maxwidth100').
'</span>';
751 if (property_exists($this,
'amount')) {
752 $return .=
'<br><span class="info-box-label amount">'.price($this->amount).
'</span>';
753 if (property_exists($this,
'type_payment') && !empty($this->type_payment)) {
754 $return .=
' <span class="info-box-label opacitymedium small">';
755 if ($langs->trans(
"PaymentTypeShort".$this->type_payment) !=
"PaymentTypeShort".$this->type_payment) {
756 $return .= $langs->trans(
"PaymentTypeShort".$this->type_payment);
757 } elseif ($langs->trans(
"PaymentType".$this->type_payment) !=
"PaymentType".$this->type_payment) {
758 $return .= $langs->trans(
"PaymentType".$this->type_payment);
760 $return .=
'</span>';
763 if (method_exists($this,
'LibStatut')) {
764 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, $this->alreadypaid).
'</div>';