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();
214 $this->db->rollback();
227 public function fetch($id, $user =
null)
232 $sql .=
" s.fk_user,";
235 $sql .=
" s.amount,";
236 $sql .=
" s.fk_projet as fk_project,";
237 $sql .=
" s.fk_typepayment,";
239 $sql .=
" s.datesp,";
240 $sql .=
" s.dateep,";
243 $sql .=
" s.fk_bank,";
244 $sql .=
" s.fk_user_author,";
245 $sql .=
" s.fk_user_modif,";
246 $sql .=
" s.fk_account";
247 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
248 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON s.fk_bank = b.rowid";
249 $sql .=
" WHERE s.rowid = ".((int) $id);
251 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
252 $resql = $this->db->query($sql);
254 if ($this->db->num_rows($resql)) {
255 $obj = $this->db->fetch_object($resql);
257 $this->
id = $obj->rowid;
258 $this->
ref = $obj->rowid;
259 $this->tms = $this->db->jdate($obj->tms);
260 $this->fk_user = $obj->fk_user;
261 $this->datep = $this->db->jdate($obj->datep);
262 $this->datev = $this->db->jdate($obj->datev);
263 $this->amount = $obj->amount;
264 $this->fk_project = $obj->fk_project;
265 $this->type_payment = $obj->fk_typepayment;
266 $this->label = $obj->label;
267 $this->datesp = $this->db->jdate($obj->datesp);
268 $this->dateep = $this->db->jdate($obj->dateep);
269 $this->note = $obj->note;
270 $this->paye = $obj->paye;
271 $this->
status = $obj->paye;
272 $this->fk_bank = $obj->fk_bank;
273 $this->fk_user_author = $obj->fk_user_author;
274 $this->fk_user_modif = $obj->fk_user_modif;
275 $this->fk_account = $obj->fk_account;
276 $this->accountid = $obj->fk_account;
282 $this->db->free($resql);
286 $this->error =
"Error ".$this->db->lasterror();
299 public function delete($user, $notrigger = 0)
326 $this->fk_user_author =
'';
327 $this->fk_user_modif =
'';
338 global $conf, $langs;
344 $this->amount =
price2num(trim($this->amount));
345 $this->label = trim($this->label);
346 $this->note = trim($this->note);
347 $this->fk_bank = trim($this->fk_bank);
348 $this->fk_user_author = trim($this->fk_user_author);
349 $this->fk_user_modif = trim($this->fk_user_modif);
350 $this->accountid = trim($this->accountid);
351 $this->paye = trim($this->paye);
355 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
358 if ($this->fk_user < 0 || $this->fk_user ==
'') {
359 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Employee"));
362 if ($this->amount ==
'') {
363 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
380 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"salary (fk_user";
384 $sql .=
", fk_projet";
386 $sql .=
", fk_typepayment";
387 $sql .=
", fk_account";
394 $sql .=
", fk_user_author";
400 $sql .=
"'".$this->db->escape($this->fk_user).
"'";
403 $sql .=
", ".((float) $this->amount);
404 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
405 $sql .=
", ".($this->salary > 0 ? ((float) $this->salary) :
"null");
406 $sql .=
", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
407 $sql .=
", ".($this->accountid > 0 ? ((int) $this->accountid) :
"null");
409 $sql .=
", '".$this->db->escape($this->note).
"'";
411 $sql .=
", '".$this->db->escape($this->label).
"'";
412 $sql .=
", '".$this->db->idate($this->datesp).
"'";
413 $sql .=
", '".$this->db->idate($this->dateep).
"'";
414 $sql .=
", '".$this->db->escape($user->id).
"'";
415 $sql .=
", '".$this->db->idate($now).
"'";
417 $sql .=
", ".((int) $conf->entity);
420 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
421 $result = $this->db->query($sql);
423 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"salary");
450 $this->db->rollback();
454 $this->error = $this->db->error();
455 $this->db->rollback();
470 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'salary SET fk_bank = '.((int) $id_bank);
471 $sql .=
" WHERE rowid = ".((int) $this->
id);
472 $result = $this->db->query($sql);
492 $langs->loadLangs([
'salaries']);
495 if (!empty($params[
'fromajaxtooltip']) && !isset($this->alreadypaid)) {
502 $datas[
'picto'] =
'<u>'.$langs->trans(
"Salary").
'</u>';
503 if (isset($this->
status) && isset($this->alreadypaid)) {
504 $datas[
'picto'] .=
' '.$this->getLibStatut(5, $this->alreadypaid);
506 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
521 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
523 global $conf, $langs, $hookmanager;
525 if (!empty($conf->dol_no_mouse_hover)) {
532 'objecttype' => $this->element,
535 $classfortooltip =
'classfortooltip';
538 $classfortooltip =
'classforajaxtooltip';
539 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
545 $url = DOL_URL_ROOT.
'/salaries/card.php?id='.$this->id;
547 if ($option !=
'nolink') {
549 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
550 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
551 $add_save_lastsearch_values = 1;
553 if ($add_save_lastsearch_values) {
554 $url .=
'&save_lastsearch_values=1';
559 if (empty($notooltip)) {
561 $label = $langs->trans(
"ShowMyObject");
562 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
564 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
565 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
567 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
570 $linkstart =
'<a href="'.$url.
'"';
571 $linkstart .= $linkclose.
'>';
574 $result .= $linkstart;
576 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
578 if ($withpicto != 2) {
579 $result .= $this->ref;
584 global $action, $hookmanager;
585 $hookmanager->initHooks(array(
'salarypayment'));
586 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
587 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
589 $result = $hookmanager->resPrint;
591 $result .= $hookmanager->resPrint;
605 $table =
'payment_salary';
606 $field =
'fk_salary';
608 $sql =
"SELECT sum(amount) as amount";
610 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
611 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
613 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
615 $resql = $this->db->query($sql);
618 $obj = $this->db->fetch_object($resql);
620 $this->db->free($resql);
623 if ($multicurrency < 0) {
628 } elseif ($multicurrency) {
634 return (
float) $obj->amount;
640 $this->error = $this->db->lasterror();
653 $sql =
'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
654 $sql .=
' FROM '.MAIN_DB_PREFIX.
'salary as ps';
655 $sql .=
' WHERE ps.rowid = '.((int) $id);
657 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
658 $result = $this->db->query($sql);
661 if ($this->db->num_rows($result)) {
662 $obj = $this->db->fetch_object($result);
664 $this->
id = $obj->rowid;
666 $this->user_creation_id = $obj->fk_user_author;
667 $this->user_modification_id = $obj->fk_user_modif;
668 $this->date_creation = $this->db->jdate($obj->datec);
669 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
671 $this->db->free($result);
689 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
701 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
703 $sql .=
" WHERE rowid = ".((int) $this->
id);
705 $return = $this->db->query($sql);
725 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
727 $sql .=
" WHERE rowid = ".((int) $this->
id);
729 $return = $this->db->query($sql);
749 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
761 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
767 $langs->loadLangs(array(
"customers",
"bills"));
770 $this->labelStatus = array();
771 $this->labelStatusShort = array();
773 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
776 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
777 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
778 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
779 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
781 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
782 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
783 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
784 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
788 $statusType =
'status1';
789 if ($status == 0 && $alreadypaid != 0) {
790 $statusType =
'status3';
793 $statusType =
'status6';
796 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
810 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
812 $return =
'<div class="box-flex-item box-flex-grow-zero">';
813 $return .=
'<div class="info-box info-box-sm">';
814 $return .=
'<span class="info-box-icon bg-infobox-action">';
816 $return .=
'</span>';
817 $return .=
'<div class="info-box-content">';
818 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
819 if ($selected >= 0) {
820 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
822 if (!empty($arraydata[
'user']) && is_object($arraydata[
'user'])) {
823 $return .=
'<br><span class="info-box-label">'.$arraydata[
'user']->getNomUrl(1,
'', 0, 0, 16, 0,
'',
'maxwidth100').
'</span>';
825 if (property_exists($this,
'amount')) {
826 $return .=
'<br><span class="info-box-label amount">'.price($this->amount).
'</span>';
827 if (property_exists($this,
'type_payment') && !empty($this->type_payment)) {
828 $return .=
' <span class="info-box-label opacitymedium small">';
829 if ($langs->trans(
"PaymentTypeShort".$this->type_payment) !=
"PaymentTypeShort".$this->type_payment) {
830 $return .= $langs->trans(
"PaymentTypeShort".$this->type_payment);
831 } elseif ($langs->trans(
"PaymentType".$this->type_payment) !=
"PaymentType".$this->type_payment) {
832 $return .= $langs->trans(
"PaymentType".$this->type_payment);
834 $return .=
'</span>';
837 if (method_exists($this,
'LibStatut')) {
838 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, $this->alreadypaid).
'</div>';
858 public function demande_prelevement($fuser, $amount = 0, $type =
'direct-debit', $sourcetype =
'salaire', $checkduplicateamongall = 0)
861 global $conf, $mysoc;
865 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
866 if ($this->paye == 0) {
867 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
869 $bac->fetch(0, $mysoc->id);
871 $sql =
"SELECT count(rowid) as nb";
872 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
873 if ($type ==
'salaire') {
874 $sql .=
" WHERE fk_salary = ".((int) $this->
id);
876 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
878 $sql .=
" AND type = 'ban'";
879 if (empty($checkduplicateamongall)) {
880 $sql .=
" AND traite = 0";
883 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
885 $resql = $this->db->query($sql);
887 $obj = $this->db->fetch_object($resql);
888 if ($obj && $obj->nb == 0) {
904 if (is_numeric($amount) && $amount != 0) {
905 $sql =
'INSERT INTO '.$this->db->prefix().
'prelevement_demande(';
906 if ($type ==
'salaire') {
907 $sql .=
'fk_salary, ';
909 $sql .=
'fk_facture, ';
911 $sql .=
' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity)';
912 $sql .=
" VALUES (".((int) $this->
id);
913 $sql .=
", ".((float)
price2num($amount));
914 $sql .=
", '".$this->db->idate($now).
"'";
915 $sql .=
", ".((int) $fuser->id);
916 $sql .=
", '".$this->db->escape($bac->code_banque).
"'";
917 $sql .=
", '".$this->db->escape($bac->code_guichet).
"'";
918 $sql .=
", '".$this->db->escape($bac->number).
"'";
919 $sql .=
", '".$this->db->escape($bac->cle_rib).
"'";
920 $sql .=
", '".$this->db->escape($sourcetype).
"'";
922 $sql .=
", ".((int) $conf->entity);
925 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
926 $resql = $this->db->query($sql);
928 $this->error = $this->db->lasterror();
929 dol_syslog(get_class($this).
'::demandeprelevement Erreur');
933 $this->error =
'WithdrawRequestErrorNilAmount';
934 dol_syslog(get_class($this).
'::demandeprelevement WithdrawRequestErrorNilAmount');
940 $payment_mode_id =
dol_getIdFromCode($this->db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
941 if ($payment_mode_id > 0) {
951 $this->error =
"A request already exists";
952 dol_syslog(get_class($this).
'::demandeprelevement Can t create a request to generate a direct debit, a request already exists.');
956 $this->error = $this->db->error();
957 dol_syslog(get_class($this).
'::demandeprelevement Error -2');
961 $this->error =
"Status of invoice does not allow this";
962 dol_syslog(get_class($this).
"::demandeprelevement ".$this->error.
" $this->status, $this->paye, $this->mode_reglement_id");
978 $sql =
'DELETE FROM '.$this->db->prefix().
'prelevement_demande';
979 $sql .=
' WHERE rowid = '.((int) $did);
980 $sql .=
' AND traite = 0';
981 if ($this->db->query($sql)) {
984 $this->error = $this->db->lasterror();
985 dol_syslog(get_class($this).
'::demande_prelevement_delete Error '.$this->error);
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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.
setPaymentMethods($id)
Change the payments methods.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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
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.
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 clicable (with possibly the picto)
set_unpaid($user)
Remove tag payed 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.
$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.
setPaid($user)
Tag social contribution as payed 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.
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 a 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_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.