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'));
82 public $type_payment_code;
111 public $fk_user_author;
116 public $fk_user_modif;
129 const STATUS_UNPAID = 0;
130 const STATUS_PAID = 1;
143 $this->element =
'salary';
144 $this->table_element =
'salary';
154 public function update($user =
null, $notrigger = 0)
159 $this->amount = trim($this->amount);
160 $this->label = trim($this->label);
161 $this->note = trim($this->note);
164 if (empty($this->fk_user) || $this->fk_user < 0) {
165 $this->error =
'ErrorBadParameter';
172 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"salary SET";
173 $sql .=
" tms='".$this->db->idate(
dol_now()).
"',";
174 $sql .=
" fk_user=".((int) $this->fk_user).
",";
177 $sql .=
" amount=".price2num($this->amount).
",";
178 $sql .=
" fk_projet=".((int) $this->fk_project).
",";
179 $sql .=
" fk_typepayment=".((int) $this->type_payment).
",";
180 $sql .=
" label='".$this->db->escape($this->label).
"',";
181 $sql .=
" datesp='".$this->db->idate($this->datesp).
"',";
182 $sql .=
" dateep='".$this->db->idate($this->dateep).
"',";
183 $sql .=
" note='".$this->db->escape($this->note).
"',";
184 $sql .=
" fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank :
"null").
",";
185 $sql .=
" fk_user_author=".((int) $this->fk_user_author).
",";
186 $sql .=
" fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
187 $sql .=
" WHERE rowid=".((int) $this->
id);
189 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
190 $resql = $this->db->query($sql);
192 $this->error =
"Error ".$this->db->lasterror();
217 $this->db->rollback();
230 public function fetch($id, $user =
null)
235 $sql .=
" s.fk_user,";
238 $sql .=
" s.amount,";
239 $sql .=
" s.fk_projet as fk_project,";
240 $sql .=
" s.fk_typepayment,";
242 $sql .=
" s.datesp,";
243 $sql .=
" s.dateep,";
244 $sql .=
" s.note as note_private,";
245 $sql .=
" s.note_public,";
247 $sql .=
" s.fk_bank,";
248 $sql .=
" s.fk_user_author,";
249 $sql .=
" s.fk_user_modif,";
250 $sql .=
" s.fk_account,";
251 $sql .=
" cp.code as type_payment_code";
252 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
253 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON s.fk_bank = b.rowid";
254 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON s.fk_typepayment = cp.id";
255 $sql .=
" WHERE s.rowid = ".((int) $id);
257 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
259 $resql = $this->db->query($sql);
261 if ($this->db->num_rows($resql)) {
262 $obj = $this->db->fetch_object($resql);
264 $this->
id = $obj->rowid;
265 $this->
ref = $obj->rowid;
266 $this->tms = $this->db->jdate($obj->tms);
267 $this->fk_user = $obj->fk_user;
268 $this->datep = $this->db->jdate($obj->datep);
269 $this->datev = $this->db->jdate($obj->datev);
270 $this->amount = $obj->amount;
271 $this->fk_project = $obj->fk_project;
272 $this->type_payment = $obj->fk_typepayment;
273 $this->type_payment_code = $obj->type_payment_code;
274 $this->label = $obj->label;
275 $this->datesp = $this->db->jdate($obj->datesp);
276 $this->dateep = $this->db->jdate($obj->dateep);
277 $this->note = $obj->note_private;
278 $this->note_private = $obj->note_private;
279 $this->note_public = $obj->note_public;
280 $this->paye = $obj->paye;
281 $this->
status = $obj->paye;
282 $this->fk_bank = $obj->fk_bank;
283 $this->fk_user_author = $obj->fk_user_author;
284 $this->fk_user_modif = $obj->fk_user_modif;
285 $this->fk_account = $obj->fk_account;
286 $this->accountid = $obj->fk_account;
292 $this->db->free($resql);
296 $this->error =
"Error ".$this->db->lasterror();
309 public function delete($user, $notrigger = 0)
336 $this->fk_user_author = 0;
337 $this->fk_user_modif = 0;
350 global $conf, $langs;
356 $this->amount =
price2num(trim($this->amount));
357 $this->label = trim($this->label);
358 $this->note = trim($this->note);
359 $this->fk_bank = (int) $this->fk_bank;
360 $this->fk_user_author = (int) $this->fk_user_author;
361 $this->fk_user_modif = (int) $this->fk_user_modif;
362 $this->accountid = (int) $this->accountid;
363 $this->paye = (int) $this->paye;
367 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
370 if ($this->fk_user < 0 || $this->fk_user ==
'') {
371 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Employee"));
374 if ($this->amount ==
'') {
375 $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";
396 $sql .=
", fk_user_author";
402 $sql .=
"'".$this->db->escape($this->fk_user).
"'";
405 $sql .=
", ".((float) $this->amount);
406 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0);
407 $sql .=
", ".($this->salary > 0 ? ((float) $this->salary) :
"null");
408 $sql .=
", ".($this->type_payment > 0 ? ((int) $this->type_payment) : 0);
409 $sql .=
", ".($this->accountid > 0 ? ((int) $this->accountid) :
"null");
411 $sql .=
", '".$this->db->escape($this->note).
"'";
413 $sql .=
", '".$this->db->escape($this->label).
"'";
414 $sql .=
", '".$this->db->idate($this->datesp).
"'";
415 $sql .=
", '".$this->db->idate($this->dateep).
"'";
416 $sql .=
", '".$this->db->escape($user->id).
"'";
417 $sql .=
", '".$this->db->idate($now).
"'";
419 $sql .=
", ".((int) $conf->entity);
422 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
423 $result = $this->db->query($sql);
425 $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 for salary id=".((
int) $this->
id), 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">'.$this->getLibStatut(3, isset($this->alreadypaid) ? $this->alreadypaid : $this->totalpaid).
'</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';
870 $bac->fetch(0,
'', $mysoc->id);
872 $sql =
"SELECT count(rowid) as nb";
873 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
874 if ($type ==
'salaire') {
875 $sql .=
" WHERE fk_salary = ".((int) $this->
id);
877 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
879 $sql .=
" AND type = 'ban'";
880 if (empty($checkduplicateamongall)) {
881 $sql .=
" AND traite = 0";
884 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
886 $resql = $this->db->query($sql);
888 $obj = $this->db->fetch_object($resql);
889 if ($obj && $obj->nb == 0) {
905 if (is_numeric($amount) && $amount != 0) {
906 $sql =
'INSERT INTO '.$this->db->prefix().
'prelevement_demande(';
907 if ($type ==
'salaire') {
908 $sql .=
'fk_salary, ';
910 $sql .=
'fk_facture, ';
912 $sql .=
' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity)';
913 $sql .=
" VALUES (".((int) $this->
id);
914 $sql .=
", ".((float)
price2num($amount));
915 $sql .=
", '".$this->db->idate($now).
"'";
916 $sql .=
", ".((int) $fuser->id);
917 $sql .=
", '".$this->db->escape($bac->code_banque).
"'";
918 $sql .=
", '".$this->db->escape($bac->code_guichet).
"'";
919 $sql .=
", '".$this->db->escape($bac->number).
"'";
920 $sql .=
", '".$this->db->escape($bac->cle_rib).
"'";
921 $sql .=
", '".$this->db->escape($sourcetype).
"'";
923 $sql .=
", ".((int) $conf->entity);
926 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
927 $resql = $this->db->query($sql);
929 $this->error = $this->db->lasterror();
930 dol_syslog(get_class($this).
'::demandeprelevement Erreur');
934 $this->error =
'WithdrawRequestErrorNilAmount';
935 dol_syslog(get_class($this).
'::demandeprelevement WithdrawRequestErrorNilAmount');
941 $payment_mode_id =
dol_getIdFromCode($this->db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
942 if ($payment_mode_id > 0) {
952 $this->error =
"A request already exists";
953 dol_syslog(get_class($this).
'::demandeprelevement Can t create a request to generate a direct debit, a request already exists.');
957 $this->error = $this->db->error();
958 dol_syslog(get_class($this).
'::demandeprelevement Error -2');
962 $this->error =
"Status of invoice does not allow this";
963 dol_syslog(get_class($this).
"::demandeprelevement ".$this->error.
" $this->status, $this->paye, $this->mode_reglement_id");
979 $sql =
'DELETE FROM '.$this->db->prefix().
'prelevement_demande';
980 $sql .=
' WHERE rowid = '.((int) $did);
981 $sql .=
' AND traite = 0';
982 if ($this->db->query($sql)) {
985 $this->error = $this->db->lasterror();
986 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.