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';
67 public $amounts = array();
72 public $fk_typepayment;
93 public $fk_user_author;
98 public $fk_user_modif;
103 public $fields = array(
104 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
125 public function create($user, $closepaidcontrib = 0)
133 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
136 if (!$this->datepaye) {
137 $this->error =
'ErrorBadValueForParameterCreatePaymentSalary';
142 if (isset($this->fk_salary)) $this->fk_salary = (int) $this->fk_salary;
143 if (isset($this->amount)) $this->amount = trim($this->amount);
144 if (isset($this->fk_typepayment)) $this->fk_typepayment = (
int) $this->fk_typepayment;
145 if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement);
146 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
147 if (isset($this->note)) $this->note = trim($this->note);
148 if (isset($this->fk_bank)) $this->fk_bank = (
int) $this->fk_bank;
149 if (isset($this->fk_user_author)) $this->fk_user_author = (
int) $this->fk_user_author;
150 if (isset($this->fk_user_modif)) $this->fk_user_modif = (
int) $this->fk_user_modif;
153 foreach ($this->amounts as $key => $value) {
155 $this->amounts[$key] = $newvalue;
156 $totalamount += $newvalue;
161 if ($totalamount == 0)
return -1;
166 if ($totalamount != 0) {
167 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_salary (entity, fk_salary, datec, datep, amount,";
168 $sql .=
" fk_typepayment, num_payment, note, fk_user_author, fk_bank)";
169 $sql .=
" VALUES (".((int) $conf->entity).
", ".((int) $this->chid).
", '".$this->db->idate($now).
"',";
170 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
171 $sql .=
" ".price2num($totalamount).
",";
172 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".((int) $user->id).
",";
175 $resql = $this->db->query($sql);
177 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_salary");
180 foreach ($this->amounts as $key => $amount) {
182 if (is_numeric($amount) && $amount <> 0) {
186 if ($closepaidcontrib) {
187 $tmpsalary =
new Salary($this->db);
188 $tmpsalary->fetch($contribid);
189 $paiement = $tmpsalary->getSommePaiement();
194 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
195 $remaintopay =
price2num($tmpsalary->amount - $paiement - $creditnotes - $deposits,
'MT');
196 if ($remaintopay == 0) {
197 $result = $tmpsalary->set_paid($user);
199 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
209 $result = $this->
call_trigger(
'PAYMENTSALARY_CREATE', $user);
210 if ($result < 0) $error++;
212 if ($totalamount != 0 && !$error) {
213 $this->amount = $totalamount;
214 $this->total = $totalamount;
218 $this->error = $this->db->error();
219 $this->db->rollback();
235 $sql .=
" t.fk_salary,";
239 $sql .=
" t.amount,";
240 $sql .=
" t.fk_typepayment,";
241 $sql .=
" t.num_payment as num_payment,";
243 $sql .=
" t.fk_bank,";
244 $sql .=
" t.fk_user_author,";
245 $sql .=
" t.fk_user_modif,";
246 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
247 $sql .=
' b.fk_account';
248 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
249 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
250 $sql .=
" WHERE t.rowid = ".((int) $id);
253 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
254 $resql = $this->db->query($sql);
256 if ($this->db->num_rows($resql)) {
257 $obj = $this->db->fetch_object($resql);
259 $this->
id = $obj->rowid;
260 $this->
ref = $obj->rowid;
262 $this->fk_salary = $obj->fk_salary;
263 $this->datec = $this->db->jdate($obj->datec);
264 $this->tms = $this->db->jdate($obj->tms);
265 $this->datep = $this->db->jdate($obj->datep);
266 $this->amount = $obj->amount;
267 $this->fk_typepayment = $obj->fk_typepayment;
268 $this->num_paiement = $obj->num_payment;
269 $this->num_payment = $obj->num_payment;
270 $this->note = $obj->note;
271 $this->note_private = $obj->note;
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;
276 $this->type_code = $obj->type_code;
277 $this->type_label = $obj->type_label;
279 $this->bank_account = $obj->fk_account;
280 $this->bank_line = $obj->fk_bank;
282 $this->db->free($resql);
286 $this->error =
"Error ".$this->db->lasterror();
299 public function update($user =
null, $notrigger = 0)
301 global $conf, $langs;
306 if (isset($this->fk_salary)) $this->fk_salary = (int) $this->fk_salary;
307 if (isset($this->amount)) $this->amount = trim($this->amount);
308 if (isset($this->fk_typepayment)) $this->fk_typepayment = (
int) $this->fk_typepayment;
309 if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement);
310 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
311 if (isset($this->note)) $this->note = trim($this->note);
312 if (isset($this->fk_bank)) $this->fk_bank = (
int) $this->fk_bank;
313 if (isset($this->fk_user_author)) $this->fk_user_author = (
int) $this->fk_user_author;
314 if (isset($this->fk_user_modif)) $this->fk_user_modif = (
int) $this->fk_user_modif;
320 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_salary SET";
321 $sql .=
" fk_salary=".(isset($this->fk_salary) ? $this->fk_salary :
"null").
",";
322 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
323 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
324 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
325 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
326 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
327 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
328 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
329 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
330 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) :
"null").
",";
331 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
332 $sql .=
" WHERE rowid=".((int) $this->
id);
336 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
337 $resql = $this->db->query($sql);
338 if (!$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
342 foreach ($this->errors as $errmsg) {
343 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
344 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
346 $this->db->rollback();
362 public function delete($user, $notrigger = 0)
364 global $conf, $langs;
371 if ($this->bank_line > 0) {
373 $accline->fetch($this->bank_line);
374 $result = $accline->delete();
376 $this->errors[] = $accline->error;
382 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_salary";
383 $sql .=
" WHERE rowid=".((int) $this->
id);
385 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
386 $resql = $this->db->query($sql);
387 if (!$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
392 foreach ($this->errors as $errmsg) {
393 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
394 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
396 $this->db->rollback();
422 $object->fetch($fromid);
430 $object->context[
'createfromclone'] =
'createfromclone';
431 $result = $object->create($user);
435 $this->error = $object->error;
439 unset($object->context[
'createfromclone']);
446 $this->db->rollback();
463 $this->fk_salary =
'';
468 $this->fk_typepayment =
'';
469 $this->num_payment =
'';
470 $this->note_private =
'';
471 $this->note_public =
'';
473 $this->fk_user_author =
'';
474 $this->fk_user_modif =
'';
490 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
492 global $conf, $langs;
495 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
499 if (isModEnabled(
"banque")) {
500 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
503 $acc->fetch($accountid);
508 $bank_line_id = $acc->addline(
524 if ($bank_line_id > 0) {
533 if ($mode ==
'payment_salary') {
534 $url = DOL_URL_ROOT.
'/salaries/payment_salary/card.php?id=';
538 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
546 foreach ($this->amounts as $key => $value) {
548 if ($mode ==
'payment_salary') {
549 $salary =
new Salary($this->db);
550 $salary->fetch($key);
551 $salary->fetch_user($salary->fk_user);
553 $fuser = $salary->user;
555 if ($fuser->id > 0) {
556 $result = $acc->add_url_line(
559 DOL_URL_ROOT.
'/user/card.php?id=',
560 $fuser->getFullName($langs),
565 $this->error = $this->db->lasterror();
566 dol_syslog(get_class($this) .
'::addPaymentToBank ' . $this->error);
573 $this->error = $acc->error;
596 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_salary SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
598 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
599 $result = $this->db->query($sql);
603 $this->error = $this->db->error();
622 dol_syslog(get_class($this).
"::updatePaymentDate with date = ".$date, LOG_DEBUG);
624 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
625 $sql .=
" SET datep = '".$this->db->idate($date).
"'";
626 $sql .=
" WHERE rowid = ".((int) $this->
id);
628 $result = $this->db->query($sql);
631 $this->error =
'Error -1 '.$this->db->error();
634 $type = $this->element;
636 $sql =
"UPDATE ".MAIN_DB_PREFIX.
'bank';
637 $sql .=
" SET dateo = '".$this->db->idate($date).
"', datev = '".$this->db->idate($date).
"'";
638 $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).
")";
639 $sql .=
" AND rappro = 0";
641 $result = $this->db->query($sql);
644 $this->error =
'Error -1 '.$this->db->error();
651 $this->datep = $date;
656 $this->db->rollback();
687 $langs->load(
'compta');
736 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
738 global $conf, $langs, $hookmanager;
742 if (!empty($conf->dol_no_mouse_hover)) {
749 'objecttype' => $this->element.($this->module ?
'@'.$this->module :
''),
752 $classfortooltip =
'classfortooltip';
755 $classfortooltip =
'classforajaxtooltip';
756 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
762 $url = DOL_URL_ROOT.
'/salaries/payment_salary/card.php?id='.$this->id;
764 if ($option !==
'nolink') {
766 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
767 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
768 $add_save_lastsearch_values = 1;
770 if ($url && $add_save_lastsearch_values) {
771 $url .=
'&save_lastsearch_values=1';
776 if (empty($notooltip)) {
778 $label = $langs->trans(
"SalaryPayment");
779 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
781 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
782 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
784 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
787 if ($option ==
'nolink' || empty($url)) {
788 $linkstart =
'<span';
790 $linkstart =
'<a href="'.$url.
'"';
792 $linkstart .= $linkclose.
'>';
793 if ($option ==
'nolink' || empty($url)) {
794 $linkend =
'</span>';
799 $result .= $linkstart;
801 if (empty($this->showphoto_on_popup)) {
803 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
807 if ($withpicto != 2) {
808 $result .= $this->ref;
814 global $action, $hookmanager;
815 $hookmanager->initHooks(array($this->element.
'dao'));
816 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
817 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
819 $result = $hookmanager->resPrint;
821 $result .= $hookmanager->resPrint;
862 global $conf, $langs, $user;
864 $langs->load(
'salaries');
867 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
868 return [
'optimize' => $langs->trans(
"SalaryPayment")];
871 if ($user->hasRight(
'salaries',
'read')) {
872 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"SalaryPayment").
'</u>';
873 if (isset($this->status)) {
874 $datas[
'status'] =
' '.$this->getLibStatut(5);
876 $datas[
'Ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
877 if (!empty($this->total_ttc)) {
878 $datas[
'AmountTTC'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
880 if (!empty($this->datep)) {
881 $datas[
'Date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
899 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
901 $return =
'<div class="box-flex-item box-flex-grow-zero">';
902 $return .=
'<div class="info-box info-box-sm">';
903 $return .=
'<span class="info-box-icon bg-infobox-action">';
905 $return .=
'</span>';
906 $return .=
'<div class="info-box-content">';
907 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
908 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
909 if (property_exists($this,
'fk_bank')) {
910 $return .=
' | <span class="info-box-label">'.$this->fk_bank.
'</span>';
912 if (property_exists($this,
'fk_user_author')) {
913 $return .=
'<br><span class="info-box-status">'.$this->fk_user_author.
'</span>';
916 if (property_exists($this,
'fk_typepayment')) {
917 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"PaymentMode").
'</span> : <span class="info-box-label">'.$this->fk_typepayment.
'</span>';
919 if (property_exists($this,
'amount')) {
920 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
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.
print $langs trans("Ref").' m m m statut
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 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.