27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/salaries/class/salary.class.php';
39 public $element =
'payment_salary';
44 public $table_element =
'payment_salary';
49 public $picto =
'payment';
71 public $datepaye =
'';
85 public $amounts = array();
90 public $fk_typepayment;
116 public $fk_user_author;
121 public $fk_user_modif;
136 public $bank_account;
146 public $fields = array(
147 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
168 public function create($user, $closepaidcontrib = 0)
176 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
179 if (!empty($this->datepaye) && empty($this->datep)) {
180 dol_syslog(__METHOD__.
": using datepaye is deprecated, please use datep instead", LOG_WARNING);
181 $this->datep = $this->datepaye;
185 if (empty($this->datep)) {
186 $this->error =
'ErrorBadValueForParameterCreatePaymentSalary';
191 if (isset($this->fk_salary)) {
192 $this->fk_salary = (int) $this->fk_salary;
194 if (isset($this->amount)) {
195 $this->amount = trim($this->amount);
197 if (isset($this->fk_typepayment)) {
198 $this->fk_typepayment = (int) $this->fk_typepayment;
200 if (isset($this->num_paiement)) {
201 $this->num_paiement = trim($this->num_paiement);
203 if (isset($this->num_payment)) {
204 $this->num_payment = trim($this->num_payment);
206 if (isset($this->note)) {
207 $this->note = trim($this->note);
209 if (isset($this->fk_bank)) {
210 $this->fk_bank = (int) $this->fk_bank;
212 if (isset($this->fk_user_author)) {
213 $this->fk_user_author = (int) $this->fk_user_author;
215 if (isset($this->fk_user_modif)) {
216 $this->fk_user_modif = (int) $this->fk_user_modif;
220 foreach ($this->amounts as $key => $value) {
222 $this->amounts[$key] = $newvalue;
223 $totalamount += $newvalue;
228 if ($totalamount == 0) {
235 if ($totalamount != 0) {
237 foreach ($this->amounts as $key => $amount) {
240 if (is_numeric($amount) && !empty($amount)) {
242 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_salary (entity, fk_salary, datec, datep, amount,";
243 $sql .=
" fk_typepayment, num_payment, note, fk_user_author, fk_bank)";
244 $sql .=
" VALUES (".((int) $conf->entity).
", ".((int) $salary_id).
", '".$this->db->idate($now).
"',";
245 $sql .=
" '".$this->db->idate($this->datep).
"',";
246 $sql .=
" ".price2num($amount).
",";
247 $sql .=
" ".((int) $this->fk_typepayment).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".((int) $user->id).
",";
250 $resql = $this->db->query($sql);
252 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_salary");
256 if ($closepaidcontrib) {
257 $tmpsalary =
new Salary($this->db);
258 $tmpsalary->fetch($salary_id);
259 $paiement = $tmpsalary->getSommePaiement();
264 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
265 $remaintopay =
price2num($tmpsalary->amount - $paiement - $creditnotes - $deposits,
'MT');
266 if ($remaintopay == 0) {
267 $result = $tmpsalary->setPaid($user);
269 dol_syslog(
"Remain to pay for salary id=".$salary_id.
" not null. We do nothing.");
276 $result = $this->
call_trigger(
'PAYMENTSALARY_CREATE', $user);
281 if ($totalamount != 0 && !$error) {
282 $this->amount = $totalamount;
283 $this->total = $totalamount;
287 $this->error = $this->db->error();
288 $this->db->rollback();
304 $sql .=
" t.fk_salary,";
308 $sql .=
" t.amount,";
309 $sql .=
" t.fk_typepayment,";
310 $sql .=
" t.num_payment as num_payment,";
312 $sql .=
" t.fk_bank,";
313 $sql .=
" t.fk_user_author,";
314 $sql .=
" t.fk_user_modif,";
315 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
316 $sql .=
' b.fk_account';
317 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
318 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
319 $sql .=
" WHERE t.rowid = ".((int) $id);
322 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
323 $resql = $this->db->query($sql);
325 if ($this->db->num_rows($resql)) {
326 $obj = $this->db->fetch_object($resql);
328 $this->
id = $obj->rowid;
329 $this->
ref = $obj->rowid;
331 $this->fk_salary = $obj->fk_salary;
332 $this->datec = $this->db->jdate($obj->datec);
333 $this->tms = $this->db->jdate($obj->tms);
334 $this->datepaye = $this->db->jdate($obj->datep);
335 $this->amount = $obj->amount;
336 $this->fk_typepayment = $obj->fk_typepayment;
337 $this->num_paiement = $obj->num_payment;
338 $this->num_payment = $obj->num_payment;
339 $this->note = $obj->note;
340 $this->note_private = $obj->note;
341 $this->fk_bank = $obj->fk_bank;
342 $this->fk_user_author = $obj->fk_user_author;
343 $this->fk_user_modif = $obj->fk_user_modif;
345 $this->type_code = $obj->type_code;
346 $this->type_label = $obj->type_label;
348 $this->bank_account = $obj->fk_account;
349 $this->bank_line = $obj->fk_bank;
351 $this->db->free($resql);
355 $this->error =
"Error ".$this->db->lasterror();
368 public function update($user =
null, $notrigger = 0)
370 global $conf, $langs;
375 if (isset($this->fk_salary)) {
376 $this->fk_salary = (int) $this->fk_salary;
378 if (isset($this->amount)) {
379 $this->amount = trim($this->amount);
381 if (isset($this->fk_typepayment)) {
382 $this->fk_typepayment = (int) $this->fk_typepayment;
384 if (isset($this->num_paiement)) {
385 $this->num_paiement = trim($this->num_paiement);
387 if (isset($this->num_payment)) {
388 $this->num_payment = trim($this->num_payment);
390 if (isset($this->note)) {
391 $this->note = trim($this->note);
393 if (isset($this->fk_bank)) {
394 $this->fk_bank = (int) $this->fk_bank;
396 if (isset($this->fk_user_author)) {
397 $this->fk_user_author = (int) $this->fk_user_author;
399 if (isset($this->fk_user_modif)) {
400 $this->fk_user_modif = (int) $this->fk_user_modif;
407 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_salary SET";
408 $sql .=
" fk_salary=".(isset($this->fk_salary) ? $this->fk_salary :
"null").
",";
409 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
410 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
411 $sql .=
" datep=".(dol_strlen($this->datepaye) != 0 ?
"'".$this->db->idate($this->datepaye).
"'" :
'null').
",";
412 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
413 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
414 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
415 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
416 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
417 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) :
"null").
",";
418 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
419 $sql .=
" WHERE rowid=".((int) $this->
id);
423 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
424 $resql = $this->db->query($sql);
427 $this->errors[] =
"Error ".$this->db->lasterror();
432 foreach ($this->errors as $errmsg) {
433 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
434 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
436 $this->db->rollback();
452 public function delete($user, $notrigger = 0)
460 if ($this->bank_line > 0) {
462 $accline->fetch($this->bank_line);
463 $result = $accline->delete($user);
465 $this->errors[] = $accline->error;
471 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_salary";
472 $sql .=
" WHERE rowid=".((int) $this->
id);
474 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
475 $resql = $this->db->query($sql);
478 $this->errors[] =
"Error ".$this->db->lasterror();
484 foreach ($this->errors as $errmsg) {
485 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
486 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
488 $this->db->rollback();
514 $object->fetch($fromid);
522 $object->context[
'createfromclone'] =
'createfromclone';
523 $result = $object->create($user);
527 $this->error = $object->error;
531 unset($object->context[
'createfromclone']);
538 $this->db->rollback();
555 $this->fk_salary =
'';
558 $this->datepaye =
'';
560 $this->fk_typepayment =
'';
561 $this->num_payment =
'';
562 $this->note_private =
'';
563 $this->note_public =
'';
565 $this->fk_user_author =
'';
566 $this->fk_user_modif =
'';
582 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
587 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
591 if (isModEnabled(
"banque")) {
592 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
595 $acc->fetch($accountid);
600 $bank_line_id = $acc->addline(
602 $this->fk_typepayment,
616 if ($bank_line_id > 0) {
625 if ($mode ==
'payment_salary') {
626 $url = DOL_URL_ROOT.
'/salaries/payment_salary/card.php?id=';
630 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
638 foreach ($this->amounts as $key => $value) {
640 if ($mode ==
'payment_salary') {
641 $salary =
new Salary($this->db);
642 $salary->fetch($key);
643 $salary->fetch_user($salary->fk_user);
645 $fuser = $salary->user;
647 if ($fuser->id > 0) {
648 $result = $acc->add_url_line(
651 DOL_URL_ROOT.
'/user/card.php?id=',
652 $fuser->getFullName($langs),
657 $this->error = $this->db->lasterror();
658 dol_syslog(get_class($this) .
'::addPaymentToBank ' . $this->error);
665 $this->error = $acc->error;
688 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_salary SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
690 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
691 $result = $this->db->query($sql);
695 $this->error = $this->db->error();
714 dol_syslog(get_class($this).
"::updatePaymentDate with date = ".$date, LOG_DEBUG);
716 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
717 $sql .=
" SET datep = '".$this->db->idate($date).
"'";
718 $sql .=
" WHERE rowid = ".((int) $this->
id);
720 $result = $this->db->query($sql);
723 $this->error =
'Error -1 '.$this->db->error();
726 $type = $this->element;
728 $sql =
"UPDATE ".MAIN_DB_PREFIX.
'bank';
729 $sql .=
" SET dateo = '".$this->db->idate($date).
"', datev = '".$this->db->idate($date).
"'";
730 $sql .=
" WHERE rowid IN (SELECT fk_bank FROM ".MAIN_DB_PREFIX.
"bank_url WHERE type = '".$this->db->escape($type).
"' AND url_id = ".((int) $this->
id).
")";
731 $sql .=
" AND rappro = 0";
733 $result = $this->db->query($sql);
736 $this->error =
'Error -1 '.$this->db->error();
743 $this->datepaye = $date;
748 $this->db->rollback();
779 $langs->load(
'compta');
828 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
830 global $conf, $langs, $hookmanager;
834 if (!empty($conf->dol_no_mouse_hover)) {
841 'objecttype' => $this->element.($this->module ?
'@'.$this->module :
''),
844 $classfortooltip =
'classfortooltip';
847 $classfortooltip =
'classforajaxtooltip';
848 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
854 $url = DOL_URL_ROOT.
'/salaries/payment_salary/card.php?id='.$this->id;
856 if ($option !==
'nolink') {
858 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
859 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
860 $add_save_lastsearch_values = 1;
862 if ($url && $add_save_lastsearch_values) {
863 $url .=
'&save_lastsearch_values=1';
868 if (empty($notooltip)) {
870 $label = $langs->trans(
"SalaryPayment");
871 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
873 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
874 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
876 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
879 if ($option ==
'nolink' || empty($url)) {
880 $linkstart =
'<span';
882 $linkstart =
'<a href="'.$url.
'"';
884 $linkstart .= $linkclose.
'>';
885 if ($option ==
'nolink' || empty($url)) {
886 $linkend =
'</span>';
891 $result .= $linkstart;
893 if (empty($this->showphoto_on_popup)) {
895 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
899 if ($withpicto != 2) {
900 $result .= $this->ref;
906 global $action, $hookmanager;
907 $hookmanager->initHooks(array($this->element.
'dao'));
908 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
909 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
911 $result = $hookmanager->resPrint;
913 $result .= $hookmanager->resPrint;
927 global $conf, $langs, $user;
929 $langs->load(
'salaries');
933 return [
'optimize' => $langs->trans(
"SalaryPayment")];
936 if ($user->hasRight(
'salaries',
'read')) {
937 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"SalaryPayment").
'</u>';
938 if (isset($this->
status)) {
939 $datas[
'status'] =
' '.$this->getLibStatut(5);
941 $datas[
'Ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
942 if (!empty($this->total_ttc)) {
943 $datas[
'AmountTTC'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
945 if (!empty($this->datep)) {
946 $datas[
'Date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'dayhour',
'tzuserrel');
947 } elseif (!empty($this->datepaye)) {
948 $datas[
'Date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datepaye,
'dayhour',
'tzuserrel');
966 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
968 $return =
'<div class="box-flex-item box-flex-grow-zero">';
969 $return .=
'<div class="info-box info-box-sm">';
970 $return .=
'<span class="info-box-icon bg-infobox-action">';
972 $return .=
'</span>';
973 $return .=
'<div class="info-box-content">';
974 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
975 if ($selected >= 0) {
976 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
978 if (property_exists($this,
'fk_bank')) {
979 $return .=
' | <span class="info-box-label">'.$this->fk_bank.
'</span>';
981 if (property_exists($this,
'fk_user_author')) {
982 $return .=
'<br><span class="info-box-status">'.$this->fk_user_author.
'</span>';
985 if (property_exists($this,
'fk_typepayment')) {
986 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"PaymentMode").
'</span> : <span class="info-box-label">'.$this->fk_typepayment.
'</span>';
988 if (property_exists($this,
'amount')) {
989 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Class to manage bank accounts.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage payments of salaries.
LibStatut($status, $mode=0)
Return the status.
update_fk_bank($id_bank)
Mise a jour du lien entre le paiement de salaire et la ligne dans llx_bank generee.
updatePaymentDate($date)
Updates the payment date.
getLibStatut($mode=0)
Return the label of the status.
initAsSpecimen()
Initialise an instance with random values.
getNomUrl($withpicto=0, $maxlen=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
create($user, $closepaidcontrib=0)
Create payment of salary into database.
__construct($db)
Constructor.
update($user=null, $notrigger=0)
Update database.
getTooltipContentArray($params)
getTooltipContentArray
addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
Add record into bank for payment with links between this bank record and invoices of payment.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
fetch($id)
Load object in memory from database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
Class to manage salary payments.
Class to manage Dolibarr users.
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)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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)
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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut