27require_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)
154 $this->amount = trim($this->amount);
155 $this->label = trim($this->label);
156 $this->note = trim($this->note);
159 if (empty($this->fk_user) || $this->fk_user < 0) {
160 $this->error =
'ErrorBadParameter';
167 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
168 $sql .=
" tms='".$this->db->idate(
dol_now()).
"',";
169 $sql .=
" fk_user=".((int) $this->fk_user).
",";
172 $sql .=
" amount=".price2num($this->amount).
",";
173 $sql .=
" fk_projet=".((int) $this->fk_project).
",";
174 $sql .=
" fk_typepayment=".((int) $this->type_payment).
",";
175 $sql .=
" label='".$this->db->escape($this->label).
"',";
176 $sql .=
" datesp='".$this->db->idate($this->datesp).
"',";
177 $sql .=
" dateep='".$this->db->idate($this->dateep).
"',";
178 $sql .=
" note='".$this->db->escape($this->note).
"',";
179 $sql .=
" fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank :
"null").
",";
180 $sql .=
" fk_user_author=".((int) $this->fk_user_author).
",";
181 $sql .=
" fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
182 $sql .=
" WHERE rowid=".((int) $this->
id);
184 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
185 $resql = $this->db->query($sql);
187 $this->error =
"Error ".$this->db->lasterror();
204 if ($result < 0) $error++;
212 $this->db->rollback();
225 public function fetch($id, $user =
null)
230 $sql .=
" s.fk_user,";
233 $sql .=
" s.amount,";
234 $sql .=
" s.fk_projet as fk_project,";
235 $sql .=
" s.fk_typepayment,";
237 $sql .=
" s.datesp,";
238 $sql .=
" s.dateep,";
241 $sql .=
" s.fk_bank,";
242 $sql .=
" s.fk_user_author,";
243 $sql .=
" s.fk_user_modif,";
244 $sql .=
" s.fk_account";
245 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
246 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON s.fk_bank = b.rowid";
247 $sql .=
" WHERE s.rowid = ".((int) $id);
249 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
250 $resql = $this->db->query($sql);
252 if ($this->db->num_rows($resql)) {
253 $obj = $this->db->fetch_object($resql);
255 $this->
id = $obj->rowid;
256 $this->
ref = $obj->rowid;
257 $this->tms = $this->db->jdate($obj->tms);
258 $this->fk_user = $obj->fk_user;
259 $this->datep = $this->db->jdate($obj->datep);
260 $this->datev = $this->db->jdate($obj->datev);
261 $this->amount = $obj->amount;
262 $this->fk_project = $obj->fk_project;
263 $this->type_payment = $obj->fk_typepayment;
264 $this->label = $obj->label;
265 $this->datesp = $this->db->jdate($obj->datesp);
266 $this->dateep = $this->db->jdate($obj->dateep);
267 $this->note = $obj->note;
268 $this->paye = $obj->paye;
269 $this->fk_bank = $obj->fk_bank;
270 $this->fk_user_author = $obj->fk_user_author;
271 $this->fk_user_modif = $obj->fk_user_modif;
272 $this->fk_account = $obj->fk_account;
273 $this->accountid = $obj->fk_account;
279 $this->db->free($resql);
283 $this->error =
"Error ".$this->db->lasterror();
296 public function delete($user, $notrigger = 0)
323 $this->fk_user_author =
'';
324 $this->fk_user_modif =
'';
335 global $conf, $langs;
341 $this->amount =
price2num(trim($this->amount));
342 $this->label = trim($this->label);
343 $this->note = trim($this->note);
344 $this->fk_bank = trim($this->fk_bank);
345 $this->fk_user_author = trim($this->fk_user_author);
346 $this->fk_user_modif = trim($this->fk_user_modif);
347 $this->accountid = trim($this->accountid);
348 $this->paye = trim($this->paye);
352 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
355 if ($this->fk_user < 0 || $this->fk_user ==
'') {
356 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Employee"));
359 if ($this->amount ==
'') {
360 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
377 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"salary (fk_user";
381 $sql .=
", fk_projet";
383 $sql .=
", fk_typepayment";
384 $sql .=
", fk_account";
385 if ($this->note) $sql .=
", note";
389 $sql .=
", fk_user_author";
395 $sql .=
"'".$this->db->escape($this->fk_user).
"'";
398 $sql .=
", ".((double) $this->amount);
399 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
400 $sql .=
", ".($this->salary > 0 ? ((double) $this->salary) :
"null");
401 $sql .=
", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
402 $sql .=
", ".($this->accountid > 0 ? ((int) $this->accountid) :
"null");
403 if ($this->note) $sql .=
", '".$this->db->escape($this->note).
"'";
404 $sql .=
", '".$this->db->escape($this->label).
"'";
405 $sql .=
", '".$this->db->idate($this->datesp).
"'";
406 $sql .=
", '".$this->db->idate($this->dateep).
"'";
407 $sql .=
", '".$this->db->escape($user->id).
"'";
408 $sql .=
", '".$this->db->idate($now).
"'";
410 $sql .=
", ".((int) $conf->entity);
413 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
414 $result = $this->db->query($sql);
416 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"salary");
431 if ($result < 0) $error++;
439 $this->db->rollback();
443 $this->error = $this->db->error();
444 $this->db->rollback();
459 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'salary SET fk_bank = '.((int) $id_bank);
460 $sql .=
" WHERE rowid = ".((int) $this->
id);
461 $result = $this->db->query($sql);
478 global $conf, $langs, $user;
480 $langs->loadLangs([
'salaries']);
483 $option = $params[
'option'] ??
'';
484 $datas[
'picto'] =
'<u>'.$langs->trans(
"Salary").
'</u>';
485 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
500 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
502 global $db, $conf, $langs, $hookmanager;
503 global $dolibarr_main_authentication, $dolibarr_main_demo;
506 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
511 'objecttype' => $this->element,
514 $classfortooltip =
'classfortooltip';
517 $classfortooltip =
'classforajaxtooltip';
518 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
524 $url = DOL_URL_ROOT.
'/salaries/card.php?id='.$this->id;
526 if ($option !=
'nolink') {
528 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
529 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
530 $add_save_lastsearch_values = 1;
532 if ($add_save_lastsearch_values) {
533 $url .=
'&save_lastsearch_values=1';
538 if (empty($notooltip)) {
539 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
540 $label = $langs->trans(
"ShowMyObject");
541 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
543 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
544 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
546 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
549 $linkstart =
'<a href="'.$url.
'"';
550 $linkstart .= $linkclose.
'>';
553 $result .= $linkstart;
555 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
557 if ($withpicto != 2) {
558 $result .= $this->ref;
563 global $action, $hookmanager;
564 $hookmanager->initHooks(array(
'salarypayment'));
565 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
566 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
567 if ($reshook > 0) $result = $hookmanager->resPrint;
568 else $result .= $hookmanager->resPrint;
580 $table =
'payment_salary';
581 $field =
'fk_salary';
583 $sql =
"SELECT sum(amount) as amount";
584 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
585 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
587 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
588 $resql = $this->db->query($sql);
593 $obj = $this->db->fetch_object($resql);
594 if ($obj) $amount = $obj->amount ? $obj->amount : 0;
596 $this->db->free($resql);
611 $sql =
'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
612 $sql .=
' FROM '.MAIN_DB_PREFIX.
'salary as ps';
613 $sql .=
' WHERE ps.rowid = '.((int) $id);
615 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
616 $result = $this->db->query($sql);
619 if ($this->db->num_rows($result)) {
620 $obj = $this->db->fetch_object($result);
621 $this->
id = $obj->rowid;
623 $this->user_creation_id = $obj->fk_user_author;
624 $this->user_modification_id = $obj->fk_user_modif;
625 $this->date_creation = $this->db->jdate($obj->datec);
626 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
628 $this->db->free($result);
644 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
646 $sql .=
" WHERE rowid = ".((int) $this->
id);
648 $return = $this->db->query($sql);
668 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
670 $sql .=
" WHERE rowid = ".((int) $this->
id);
672 $return = $this->db->query($sql);
692 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
704 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
710 $langs->loadLangs(array(
"customers",
"bills"));
713 $this->labelStatus = array();
714 $this->labelStatusShort = array();
716 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
719 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
720 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
721 if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
722 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
723 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
724 if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
727 $statusType =
'status1';
728 if ($status == 0 && $alreadypaid <> 0) $statusType =
'status3';
729 if ($status == 1) $statusType =
'status6';
731 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
745 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
747 $return =
'<div class="box-flex-item box-flex-grow-zero">';
748 $return .=
'<div class="info-box info-box-sm">';
749 $return .=
'<span class="info-box-icon bg-infobox-action">';
751 $return .=
'</span>';
752 $return .=
'<div class="info-box-content">';
753 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
754 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
755 if (!empty($arraydata[
'user']) && is_object($arraydata[
'user'])) {
756 $return .=
'<br><span class="info-box-label">'.$arraydata[
'user']->getNomUrl(1,
'', 0, 0, 16, 0,
'',
'maxwidth100').
'</span>';
758 if (property_exists($this,
'amount')) {
759 $return .=
'<br><span class="info-box-label amount">'.price($this->amount).
'</span>';
760 if (property_exists($this,
'type_payment') && !empty($this->type_payment)) {
761 $return .=
' <span class="info-box-label opacitymedium small">';
762 if ($langs->trans(
"PaymentTypeShort".$this->type_payment) !=
"PaymentTypeShort".$this->type_payment) {
763 $return .= $langs->trans(
"PaymentTypeShort".$this->type_payment);
764 } elseif ($langs->trans(
"PaymentType".$this->type_payment) !=
"PaymentType".$this->type_payment) {
765 $return .= $langs->trans(
"PaymentType".$this->type_payment);
767 $return .=
'</span>';
770 if (method_exists($this,
'LibStatut')) {
771 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, $this->alreadypaid).
'</div>';
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...
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
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 payed completely.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Send name clicable (with possibly the picto)
set_unpaid($user)
Remove tag payed on social contribution.
create($user)
Create in database.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of current status.
$paye
1 if salary paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code)
info($id)
Information on record.
__construct($db)
Constructor.
getSommePaiement()
Return amount of payments already done.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.