29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'salary';
45 public $table_element =
'salary';
50 public $picto =
'salary';
55 protected $childtables = array(
'payment_salary' => array(
'name' =>
'SalaryPayment',
'fk_element' =>
'fk_salary'));
110 public $fk_user_author;
115 public $fk_user_modif;
128 const STATUS_UNPAID = 0;
129 const STATUS_PAID = 1;
141 $this->element =
'salary';
142 $this->table_element =
'salary';
152 public function update($user =
null, $notrigger = 0)
157 $this->amount = trim($this->amount);
158 $this->label = trim($this->label);
159 $this->note = trim($this->note);
162 if (empty($this->fk_user) || $this->fk_user < 0) {
163 $this->error =
'ErrorBadParameter';
170 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
171 $sql .=
" tms='".$this->db->idate(
dol_now()).
"',";
172 $sql .=
" fk_user=".((int) $this->fk_user).
",";
175 $sql .=
" amount=".price2num($this->amount).
",";
176 $sql .=
" fk_projet=".((int) $this->fk_project).
",";
177 $sql .=
" fk_typepayment=".((int) $this->type_payment).
",";
178 $sql .=
" label='".$this->db->escape($this->label).
"',";
179 $sql .=
" datesp='".$this->db->idate($this->datesp).
"',";
180 $sql .=
" dateep='".$this->db->idate($this->dateep).
"',";
181 $sql .=
" note='".$this->db->escape($this->note).
"',";
182 $sql .=
" fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank :
"null").
",";
183 $sql .=
" fk_user_author=".((int) $this->fk_user_author).
",";
184 $sql .=
" fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
185 $sql .=
" WHERE rowid=".((int) $this->
id);
187 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
188 $resql = $this->db->query($sql);
190 $this->error =
"Error ".$this->db->lasterror();
215 $this->db->rollback();
228 public function fetch($id, $user =
null)
233 $sql .=
" s.fk_user,";
236 $sql .=
" s.amount,";
237 $sql .=
" s.fk_projet as fk_project,";
238 $sql .=
" s.fk_typepayment,";
240 $sql .=
" s.datesp,";
241 $sql .=
" s.dateep,";
244 $sql .=
" s.fk_bank,";
245 $sql .=
" s.fk_user_author,";
246 $sql .=
" s.fk_user_modif,";
247 $sql .=
" s.fk_account";
248 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
249 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON s.fk_bank = b.rowid";
250 $sql .=
" WHERE s.rowid = ".((int) $id);
252 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
253 $resql = $this->db->query($sql);
255 if ($this->db->num_rows($resql)) {
256 $obj = $this->db->fetch_object($resql);
258 $this->
id = $obj->rowid;
259 $this->
ref = $obj->rowid;
260 $this->tms = $this->db->jdate($obj->tms);
261 $this->fk_user = $obj->fk_user;
262 $this->datep = $this->db->jdate($obj->datep);
263 $this->datev = $this->db->jdate($obj->datev);
264 $this->amount = $obj->amount;
265 $this->fk_project = $obj->fk_project;
266 $this->type_payment = $obj->fk_typepayment;
267 $this->label = $obj->label;
268 $this->datesp = $this->db->jdate($obj->datesp);
269 $this->dateep = $this->db->jdate($obj->dateep);
270 $this->note = $obj->note;
271 $this->paye = $obj->paye;
272 $this->
status = $obj->paye;
273 $this->fk_bank = $obj->fk_bank;
274 $this->fk_user_author = $obj->fk_user_author;
275 $this->fk_user_modif = $obj->fk_user_modif;
276 $this->fk_account = $obj->fk_account;
277 $this->accountid = $obj->fk_account;
283 $this->db->free($resql);
287 $this->error =
"Error ".$this->db->lasterror();
300 public function delete($user, $notrigger = 0)
327 $this->fk_user_author = 0;
328 $this->fk_user_modif = 0;
341 global $conf, $langs;
347 $this->amount =
price2num(trim($this->amount));
348 $this->label = trim($this->label);
349 $this->note = trim($this->note);
350 $this->fk_bank = (int) $this->fk_bank;
351 $this->fk_user_author = (int) $this->fk_user_author;
352 $this->fk_user_modif = (int) $this->fk_user_modif;
353 $this->accountid = (int) $this->accountid;
354 $this->paye = (int) $this->paye;
358 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
361 if ($this->fk_user < 0 || $this->fk_user ==
'') {
362 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Employee"));
365 if ($this->amount ==
'') {
366 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
373 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"salary (fk_user";
377 $sql .=
", fk_projet";
379 $sql .=
", fk_typepayment";
380 $sql .=
", fk_account";
387 $sql .=
", fk_user_author";
393 $sql .=
"'".$this->db->escape($this->fk_user).
"'";
396 $sql .=
", ".((float) $this->amount);
397 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
398 $sql .=
", ".($this->salary > 0 ? ((float) $this->salary) :
"null");
399 $sql .=
", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
400 $sql .=
", ".($this->accountid > 0 ? ((int) $this->accountid) :
"null");
402 $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");
441 $this->db->rollback();
445 $this->error = $this->db->error();
446 $this->db->rollback();
461 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'salary SET fk_bank = '.((int) $id_bank);
462 $sql .=
" WHERE rowid = ".((int) $this->
id);
463 $result = $this->db->query($sql);
483 $langs->loadLangs([
'salaries']);
486 if (!empty($params[
'fromajaxtooltip']) && !isset($this->alreadypaid)) {
493 $datas[
'picto'] =
'<u>'.$langs->trans(
"Salary").
'</u>';
494 if (isset($this->
status) && isset($this->alreadypaid)) {
495 $datas[
'picto'] .=
' '.$this->getLibStatut(5, $this->alreadypaid);
497 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
512 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
514 global $conf, $langs, $hookmanager;
516 if (!empty($conf->dol_no_mouse_hover)) {
523 'objecttype' => $this->element,
526 $classfortooltip =
'classfortooltip';
529 $classfortooltip =
'classforajaxtooltip';
530 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
536 $url = DOL_URL_ROOT.
'/salaries/card.php?id='.$this->id;
538 if ($option !=
'nolink') {
540 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
541 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
542 $add_save_lastsearch_values = 1;
544 if ($add_save_lastsearch_values) {
545 $url .=
'&save_lastsearch_values=1';
550 if (empty($notooltip)) {
552 $label = $langs->trans(
"ShowMyObject");
553 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
555 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
556 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
558 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
561 $linkstart =
'<a href="'.$url.
'"';
562 $linkstart .= $linkclose.
'>';
565 $result .= $linkstart;
567 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
569 if ($withpicto != 2) {
570 $result .= $this->ref;
575 global $action, $hookmanager;
576 $hookmanager->initHooks(array(
'salarypayment'));
577 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
578 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
580 $result = $hookmanager->resPrint;
582 $result .= $hookmanager->resPrint;
596 $table =
'payment_salary';
597 $field =
'fk_salary';
599 $sql =
"SELECT sum(amount) as amount";
601 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
602 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
604 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
606 $resql = $this->db->query($sql);
609 $obj = $this->db->fetch_object($resql);
611 $this->db->free($resql);
614 if ($multicurrency < 0) {
619 } elseif ($multicurrency) {
625 return (
float) $obj->amount;
631 $this->error = $this->db->lasterror();
644 $sql =
'SELECT ps.rowid, ps.datec, ps.tms as datem, ps.fk_user_author, ps.fk_user_modif';
645 $sql .=
' FROM '.MAIN_DB_PREFIX.
'salary as ps';
646 $sql .=
' WHERE ps.rowid = '.((int) $id);
648 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
649 $result = $this->db->query($sql);
652 if ($this->db->num_rows($result)) {
653 $obj = $this->db->fetch_object($result);
655 $this->
id = $obj->rowid;
657 $this->user_creation_id = $obj->fk_user_author;
658 $this->user_modification_id = $obj->fk_user_modif;
659 $this->date_creation = $this->db->jdate($obj->datec);
660 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
662 $this->db->free($result);
680 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
692 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
694 $sql .=
" WHERE rowid = ".((int) $this->
id);
696 $return = $this->db->query($sql);
716 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
718 $sql .=
" WHERE rowid = ".((int) $this->
id);
720 $return = $this->db->query($sql);
740 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
752 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
758 $langs->loadLangs(array(
"customers",
"bills"));
761 $this->labelStatus = array();
762 $this->labelStatusShort = array();
764 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
767 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
768 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
769 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
770 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
772 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
773 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
774 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
775 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
779 $statusType =
'status1';
780 if ($status == 0 && $alreadypaid != 0) {
781 $statusType =
'status3';
784 $statusType =
'status6';
787 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
801 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
803 $return =
'<div class="box-flex-item box-flex-grow-zero">';
804 $return .=
'<div class="info-box info-box-sm">';
805 $return .=
'<span class="info-box-icon bg-infobox-action">';
807 $return .=
'</span>';
808 $return .=
'<div class="info-box-content">';
809 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
810 if ($selected >= 0) {
811 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
813 if (!empty($arraydata[
'user']) && is_object($arraydata[
'user'])) {
814 $return .=
'<br><span class="info-box-label">'.$arraydata[
'user']->getNomUrl(1,
'', 0, 0, 16, 0,
'',
'maxwidth100').
'</span>';
816 if (property_exists($this,
'amount')) {
817 $return .=
'<br><span class="info-box-label amount">'.price($this->amount).
'</span>';
818 if (property_exists($this,
'type_payment') && !empty($this->type_payment)) {
819 $return .=
' <span class="info-box-label opacitymedium small">';
820 if ($langs->trans(
"PaymentTypeShort".$this->type_payment) !=
"PaymentTypeShort".$this->type_payment) {
821 $return .= $langs->trans(
"PaymentTypeShort".$this->type_payment);
822 } elseif ($langs->trans(
"PaymentType".$this->type_payment) !=
"PaymentType".$this->type_payment) {
823 $return .= $langs->trans(
"PaymentType".$this->type_payment);
825 $return .=
'</span>';
828 if (method_exists($this,
'LibStatut')) {
829 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3, isset($this->alreadypaid) ? $this->alreadypaid : $this->totalpaid).
'</div>';
849 public function demande_prelevement($fuser, $amount = 0, $type =
'direct-debit', $sourcetype =
'salaire', $checkduplicateamongall = 0)
852 global $conf, $mysoc;
856 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
857 if ($this->paye == 0) {
858 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
861 $bac->fetch(0,
'', $mysoc->id);
863 $sql =
"SELECT count(rowid) as nb";
864 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
865 if ($type ==
'salaire') {
866 $sql .=
" WHERE fk_salary = ".((int) $this->
id);
868 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
870 $sql .=
" AND type = 'ban'";
871 if (empty($checkduplicateamongall)) {
872 $sql .=
" AND traite = 0";
875 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
877 $resql = $this->db->query($sql);
879 $obj = $this->db->fetch_object($resql);
880 if ($obj && $obj->nb == 0) {
896 if (is_numeric($amount) && $amount != 0) {
897 $sql =
'INSERT INTO '.$this->db->prefix().
'prelevement_demande(';
898 if ($type ==
'salaire') {
899 $sql .=
'fk_salary, ';
901 $sql .=
'fk_facture, ';
903 $sql .=
' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity)';
904 $sql .=
" VALUES (".((int) $this->
id);
905 $sql .=
", ".((float)
price2num($amount));
906 $sql .=
", '".$this->db->idate($now).
"'";
907 $sql .=
", ".((int) $fuser->id);
908 $sql .=
", '".$this->db->escape($bac->code_banque).
"'";
909 $sql .=
", '".$this->db->escape($bac->code_guichet).
"'";
910 $sql .=
", '".$this->db->escape($bac->number).
"'";
911 $sql .=
", '".$this->db->escape($bac->cle_rib).
"'";
912 $sql .=
", '".$this->db->escape($sourcetype).
"'";
914 $sql .=
", ".((int) $conf->entity);
917 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
918 $resql = $this->db->query($sql);
920 $this->error = $this->db->lasterror();
921 dol_syslog(get_class($this).
'::demandeprelevement Erreur');
925 $this->error =
'WithdrawRequestErrorNilAmount';
926 dol_syslog(get_class($this).
'::demandeprelevement WithdrawRequestErrorNilAmount');
932 $payment_mode_id =
dol_getIdFromCode($this->db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
933 if ($payment_mode_id > 0) {
943 $this->error =
"A request already exists";
944 dol_syslog(get_class($this).
'::demandeprelevement Can t create a request to generate a direct debit, a request already exists.');
948 $this->error = $this->db->error();
949 dol_syslog(get_class($this).
'::demandeprelevement Error -2');
953 $this->error =
"Status of invoice does not allow this";
954 dol_syslog(get_class($this).
"::demandeprelevement ".$this->error.
" $this->status, $this->paye, $this->mode_reglement_id");
970 $sql =
'DELETE FROM '.$this->db->prefix().
'prelevement_demande';
971 $sql .=
' WHERE rowid = '.((int) $did);
972 $sql .=
' AND traite = 0';
973 if ($this->db->query($sql)) {
976 $this->error = $this->db->lasterror();
977 dol_syslog(get_class($this).
'::demande_prelevement_delete Error '.$this->error);
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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.
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 paid 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 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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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 '.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.