27 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
28 require_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);
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();
671 return $this->
LibStatut($this->statut, $mode);
687 $langs->load(
'compta');
739 if (empty($this->
ref)) $this->
ref = $this->lib;
741 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SalaryPayment").
'</u>';
742 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
743 if (!empty($this->label)) {
744 $labeltoshow = $this->label;
746 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
748 if ($reg[1] ==
'paiement') $reg[1] =
'Payment';
749 $labeltoshow = $langs->trans($reg[1]);
751 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
754 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
757 if (!empty($this->
id)) {
758 $link =
'<a href="'.DOL_URL_ROOT.
'/salaries/payment_salary/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
761 if ($withpicto) $result .= ($link.img_object($label,
'payment',
'class="classfortooltip pictofixedwidth"').$linkend);
762 if ($withpicto != 2) $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
779 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
781 $return =
'<div class="box-flex-item box-flex-grow-zero">';
782 $return .=
'<div class="info-box info-box-sm">';
783 $return .=
'<span class="info-box-icon bg-infobox-action">';
785 $return .=
'</span>';
786 $return .=
'<div class="info-box-content">';
787 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
788 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
789 if (property_exists($this,
'fk_bank')) {
790 $return .=
' | <span class="info-box-label">'.$this->fk_bank.
'</span>';
792 if (property_exists($this,
'fk_user_author')) {
793 $return .=
'<br><span class="info-box-status">'.$this->fk_user_author.
'</span>';
796 if (property_exists($this,
'fk_typepayment')) {
797 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"PaymentMode").
'</span> : <span class="info-box-label">'.$this->fk_typepayment.
'</span>';
799 if (property_exists($this,
'amount')) {
800 $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.
getNomUrl($withpicto=0, $maxlen=0)
Return clicable name (with picto eventually)
updatePaymentDate($date)
Updates the payment date.
getLibStatut($mode=0)
Return the label of the status.
initAsSpecimen()
Initialise an instance with random values.
create($user, $closepaidcontrib=0)
Create payment of salary into database.
__construct($db)
Constructor.
update($user=null, $notrigger=0)
Update database.
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.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
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...
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.
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_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...