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)
127 global $conf, $langs;
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).
",";
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) {
188 $contrib->fetch($contribid);
189 $paiement = $contrib->getSommePaiement();
194 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
195 $remaintopay =
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
196 if ($remaintopay == 0) {
197 $result = $contrib->set_paid($user);
198 }
else dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
207 $result = $this->
call_trigger(
'PAYMENTSALARY_CREATE', $user);
208 if ($result < 0) $error++;
210 if ($totalamount != 0 && !$error) {
211 $this->amount = $totalamount;
212 $this->total = $totalamount;
216 $this->error = $this->
db->error();
217 $this->
db->rollback();
233 $sql .=
" t.fk_salary,";
237 $sql .=
" t.amount,";
238 $sql .=
" t.fk_typepayment,";
239 $sql .=
" t.num_payment as num_payment,";
241 $sql .=
" t.fk_bank,";
242 $sql .=
" t.fk_user_author,";
243 $sql .=
" t.fk_user_modif,";
244 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
245 $sql .=
' b.fk_account';
246 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
247 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
248 $sql .=
" WHERE t.rowid = ".((int) $id);
251 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
255 $obj = $this->
db->fetch_object(
$resql);
257 $this->
id = $obj->rowid;
258 $this->
ref = $obj->rowid;
260 $this->fk_salary = $obj->fk_salary;
261 $this->datec = $this->
db->jdate($obj->datec);
262 $this->tms = $this->
db->jdate($obj->tms);
263 $this->datep = $this->
db->jdate($obj->datep);
264 $this->amount = $obj->amount;
265 $this->fk_typepayment = $obj->fk_typepayment;
266 $this->num_paiement = $obj->num_payment;
267 $this->num_payment = $obj->num_payment;
268 $this->note = $obj->note;
269 $this->note_private = $obj->note;
270 $this->fk_bank = $obj->fk_bank;
271 $this->fk_user_author = $obj->fk_user_author;
272 $this->fk_user_modif = $obj->fk_user_modif;
274 $this->type_code = $obj->type_code;
275 $this->type_label = $obj->type_label;
277 $this->bank_account = $obj->fk_account;
278 $this->bank_line = $obj->fk_bank;
284 $this->error =
"Error ".$this->db->lasterror();
297 public function update($user =
null, $notrigger = 0)
299 global $conf, $langs;
304 if (isset($this->fk_salary)) $this->fk_salary = (int) $this->fk_salary;
305 if (isset($this->amount)) $this->amount = trim($this->amount);
306 if (isset($this->fk_typepayment)) $this->fk_typepayment = (
int) $this->fk_typepayment;
307 if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement);
308 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
309 if (isset($this->note)) $this->note = trim($this->note);
310 if (isset($this->fk_bank)) $this->fk_bank = (
int) $this->fk_bank;
311 if (isset($this->fk_user_author)) $this->fk_user_author = (
int) $this->fk_user_author;
312 if (isset($this->fk_user_modif)) $this->fk_user_modif = (
int) $this->fk_user_modif;
318 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_salary SET";
319 $sql .=
" fk_salary=".(isset($this->fk_salary) ? $this->fk_salary :
"null").
",";
320 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
321 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
322 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
323 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
324 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
325 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
326 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
327 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
328 $sql .=
" fk_user_author=".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) :
"null").
",";
329 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
330 $sql .=
" WHERE rowid=".((int) $this->
id);
334 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
336 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
340 foreach ($this->errors as $errmsg) {
341 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
342 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
344 $this->
db->rollback();
360 public function delete($user, $notrigger = 0)
362 global $conf, $langs;
369 if ($this->bank_line > 0) {
371 $accline->fetch($this->bank_line);
372 $result = $accline->delete();
374 $this->errors[] = $accline->error;
380 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_salary";
381 $sql .=
" WHERE rowid=".((int) $this->
id);
383 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
385 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
390 foreach ($this->errors as $errmsg) {
391 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
392 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
394 $this->
db->rollback();
420 $object->fetch($fromid);
428 $object->context[
'createfromclone'] =
'createfromclone';
429 $result = $object->create($user);
433 $this->error = $object->error;
437 unset($object->context[
'createfromclone']);
444 $this->
db->rollback();
461 $this->fk_salary =
'';
466 $this->fk_typepayment =
'';
467 $this->num_payment =
'';
468 $this->note_private =
'';
469 $this->note_public =
'';
471 $this->fk_user_author =
'';
472 $this->fk_user_modif =
'';
488 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
490 global $conf, $langs;
493 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
498 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
501 $acc->fetch($accountid);
506 $bank_line_id = $acc->addline(
522 if ($bank_line_id > 0) {
531 if ($mode ==
'payment_salary') {
532 $url = DOL_URL_ROOT.
'/salaries/payment_salary/card.php?id=';
536 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
544 foreach ($this->amounts as $key => $value) {
546 if ($mode ==
'payment_salary') {
548 $salary->fetch($key);
549 $salary->fetch_user($salary->fk_user);
551 $fuser = $salary->user;
553 if ($fuser->id > 0) {
554 $result = $acc->add_url_line(
557 DOL_URL_ROOT.
'/user/card.php?id=',
558 $fuser->getFullName($langs),
563 $this->error = $this->
db->lasterror();
564 dol_syslog(get_class($this) .
'::addPaymentToBank ' . $this->error);
571 $this->error = $acc->error;
594 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_salary SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
596 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
597 $result = $this->
db->query($sql);
601 $this->error = $this->
db->error();
620 dol_syslog(get_class($this).
"::updatePaymentDate with date = ".$date, LOG_DEBUG);
622 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
623 $sql .=
" SET datep = '".$this->db->idate($date).
"'";
624 $sql .=
" WHERE rowid = ".((int) $this->
id);
626 $result = $this->
db->query($sql);
629 $this->error =
'Error -1 '.$this->db->error();
632 $type = $this->element;
634 $sql =
"UPDATE ".MAIN_DB_PREFIX.
'bank';
635 $sql .=
" SET dateo = '".$this->db->idate($date).
"', datev = '".$this->
db->idate($date).
"'";
636 $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).
")";
637 $sql .=
" AND rappro = 0";
639 $result = $this->
db->query($sql);
642 $this->error =
'Error -1 '.$this->db->error();
649 $this->datep = $date;
654 $this->
db->rollback();
669 return $this->
LibStatut($this->statut, $mode);
685 $langs->load(
'compta');
737 if (empty($this->
ref)) $this->
ref = $this->lib;
739 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SalaryPayment").
'</u>';
740 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
741 if (!empty($this->label)) {
742 $labeltoshow = $this->label;
744 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
746 if ($reg[1] ==
'paiement') $reg[1] =
'Payment';
747 $labeltoshow = $langs->trans($reg[1]);
749 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
752 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
755 if (!empty($this->
id)) {
756 $link =
'<a href="'.DOL_URL_ROOT.
'/salaries/payment_salary/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
759 if ($withpicto) $result .= ($link.img_object($label,
'payment',
'class="classfortooltip pictofixedwidth"').$linkend);
760 if ($withpicto != 2) $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
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.
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') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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...
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.
$conf db
API class for accounts.