26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
27require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
38 public $element =
'paiementcharge';
43 public $table_element =
'paiementcharge';
48 public $picto =
'payment';
71 public $amounts = array();
76 public $fk_typepaiement;
97 public $fk_user_creat;
102 public $fk_user_modif;
117 public $paiementtype;
138 public function create($user, $closepaidcontrib = 0)
140 global $conf, $langs;
146 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
149 if (!$this->datepaye) {
150 $this->error =
'ErrorBadValueForParameterCreatePaymentSocialContrib';
155 if (isset($this->fk_charge)) {
156 $this->fk_charge = (int) $this->fk_charge;
158 if (isset($this->amount)) {
159 $this->amount = trim($this->amount);
161 if (isset($this->fk_typepaiement)) {
162 $this->fk_typepaiement = (int) $this->fk_typepaiement;
164 if (isset($this->num_payment)) {
165 $this->num_payment = trim($this->num_payment);
167 if (isset($this->note_private)) {
168 $this->note_private = trim($this->note_private);
170 if (isset($this->fk_bank)) {
171 $this->fk_bank = (int) $this->fk_bank;
173 if (isset($this->fk_user_creat)) {
174 $this->fk_user_creat = (int) $this->fk_user_creat;
176 if (isset($this->fk_user_modif)) {
177 $this->fk_user_modif = (int) $this->fk_user_modif;
181 foreach ($this->amounts as $key => $value) {
183 $this->amounts[$key] = $newvalue;
184 $totalamount += $newvalue;
189 if ($totalamount == 0) {
196 if ($totalamount != 0) {
197 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiementcharge (fk_charge, datec, datep, amount,";
198 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
199 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
200 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
201 $sql .=
" ".((float) $totalamount).
",";
202 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".$user->id.
",";
205 $resql = $this->db->query($sql);
207 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"paiementcharge");
210 foreach ($this->amounts as $key => $amount) {
212 if (is_numeric($amount) && $amount <> 0) {
216 if ($closepaidcontrib) {
218 $contrib->fetch($contribid);
219 $paiement = $contrib->getSommePaiement();
224 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
225 $remaintopay =
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
226 if ($remaintopay == 0) {
227 $result = $contrib->setPaid($user);
229 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
239 $result = $this->
call_trigger(
'PAYMENTSOCIALCONTRIBUTION_CREATE', $user);
244 if ($totalamount != 0 && !$error) {
245 $this->amount = $totalamount;
246 $this->total = $totalamount;
250 $this->error = $this->db->error();
251 $this->db->rollback();
267 $sql .=
" t.fk_charge,";
271 $sql .=
" t.amount,";
272 $sql .=
" t.fk_typepaiement,";
273 $sql .=
" t.num_paiement as num_payment,";
275 $sql .=
" t.fk_bank,";
276 $sql .=
" t.fk_user_creat,";
277 $sql .=
" t.fk_user_modif,";
278 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
279 $sql .=
' b.fk_account';
280 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
281 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
282 $sql .=
" WHERE t.rowid = ".((int) $id);
285 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
286 $resql = $this->db->query($sql);
288 if ($this->db->num_rows($resql)) {
289 $obj = $this->db->fetch_object($resql);
291 $this->
id = $obj->rowid;
292 $this->
ref = $obj->rowid;
294 $this->fk_charge = $obj->fk_charge;
295 $this->datec = $this->db->jdate($obj->datec);
296 $this->tms = $this->db->jdate($obj->tms);
297 $this->datep = $this->db->jdate($obj->datep);
298 $this->amount = $obj->amount;
299 $this->fk_typepaiement = $obj->fk_typepaiement;
300 $this->num_payment = $obj->num_payment;
301 $this->note_private = $obj->note;
302 $this->fk_bank = $obj->fk_bank;
303 $this->fk_user_creat = $obj->fk_user_creat;
304 $this->fk_user_modif = $obj->fk_user_modif;
306 $this->type_code = $obj->type_code;
307 $this->type_label = $obj->type_label;
309 $this->bank_account = $obj->fk_account;
310 $this->bank_line = $obj->fk_bank;
312 $this->db->free($resql);
316 $this->error =
"Error ".$this->db->lasterror();
329 public function update($user =
null, $notrigger = 0)
331 global $conf, $langs;
336 if (isset($this->fk_charge)) {
337 $this->fk_charge = (int) $this->fk_charge;
339 if (isset($this->amount)) {
340 $this->amount = trim($this->amount);
342 if (isset($this->fk_typepaiement)) {
343 $this->fk_typepaiement = (int) $this->fk_typepaiement;
345 if (isset($this->num_payment)) {
346 $this->num_payment = trim($this->num_payment);
348 if (isset($this->note_private)) {
349 $this->note_private = trim($this->note_private);
351 if (isset($this->fk_bank)) {
352 $this->fk_bank = (int) $this->fk_bank;
354 if (isset($this->fk_user_creat)) {
355 $this->fk_user_creat = (int) $this->fk_user_creat;
357 if (isset($this->fk_user_modif)) {
358 $this->fk_user_modif = (int) $this->fk_user_modif;
367 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET";
368 $sql .=
" fk_charge=".(isset($this->fk_charge) ? ((int) $this->fk_charge) :
"null").
",";
369 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
370 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
371 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
372 $sql .=
" amount=".(isset($this->amount) ?
price2num($this->amount) :
"null").
",";
373 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) :
"null").
",";
374 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
375 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
376 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
377 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
378 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
379 $sql .=
" WHERE rowid=".((int) $this->
id);
383 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
384 $resql = $this->db->query($sql);
387 $this->errors[] =
"Error ".$this->db->lasterror();
392 foreach ($this->errors as $errmsg) {
393 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
394 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
396 $this->db->rollback();
412 public function delete($user, $notrigger = 0)
414 global $conf, $langs;
421 if ($this->bank_line > 0) {
423 $accline->fetch($this->bank_line);
424 $result = $accline->delete();
426 $this->errors[] = $accline->error;
432 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge";
433 $sql .=
" WHERE rowid=".((int) $this->
id);
435 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
436 $resql = $this->db->query($sql);
439 $this->errors[] =
"Error ".$this->db->lasterror();
445 foreach ($this->errors as $errmsg) {
446 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
447 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
449 $this->db->rollback();
475 $object->fetch($fromid);
483 $object->context[
'createfromclone'] =
'createfromclone';
484 $result = $object->create($user);
488 $this->error = $object->error;
492 unset($object->context[
'createfromclone']);
499 $this->db->rollback();
516 $this->fk_charge =
'';
521 $this->fk_typepaiement =
'';
522 $this->num_payment =
'';
523 $this->note_private =
'';
524 $this->note_public =
'';
526 $this->fk_user_creat =
'';
527 $this->fk_user_modif =
'';
543 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
545 global $conf, $langs;
548 $this->num_payment = trim($this->num_payment);
552 if (isModEnabled(
"banque")) {
553 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
556 $acc->fetch($accountid);
559 if ($mode ==
'payment_sc') {
564 $bank_line_id = $acc->addline(
578 if ($bank_line_id > 0) {
587 if ($mode ==
'payment_sc') {
588 $url = DOL_URL_ROOT.
'/compta/payment_sc/card.php?id=';
591 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
599 $linkaddedforthirdparty = array();
600 foreach ($this->amounts as $key => $value) {
601 if ($mode ==
'payment_sc') {
603 $socialcontrib->fetch($key);
604 $result = $acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.
'/compta/charges.php?id=', $socialcontrib->type_label.(($socialcontrib->lib && $socialcontrib->lib != $socialcontrib->type_label) ?
' ('.$socialcontrib->lib.
')' :
''),
'sc');
609 if ($socialcontrib->fk_user) {
610 $fuser =
new User($this->db);
611 $fuser->fetch($socialcontrib->fk_user);
614 $result = $acc->add_url_line(
616 $socialcontrib->fk_user,
617 DOL_URL_ROOT.
'/user/card.php?id=',
618 $fuser->getFullName($langs),
623 $this->error = $acc->error;
630 $this->error = $acc->error;
653 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
655 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
656 $result = $this->db->query($sql);
660 $this->error = $this->db->error();
690 $langs->load(
'compta');
742 if (empty($this->
ref)) {
743 $this->
ref = $this->label;
746 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SocialContributionPayment").
'</u>';
747 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
748 if (!empty($this->label)) {
749 $labeltoshow = $this->label;
751 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
753 if ($reg[1] ==
'paiement') {
756 $labeltoshow = $langs->trans($reg[1]);
758 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
761 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
764 if (!empty($this->
id)) {
765 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_sc/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
769 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
771 if ($withpicto && $withpicto != 2) {
774 if ($withpicto != 2) {
775 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
790 $alreadydispatched = 0;
794 $sql =
" SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $this->bank_line);
795 $resql = $this->db->query($sql);
797 $obj = $this->db->fetch_object($resql);
799 $alreadydispatched = $obj->nb;
802 $this->error = $this->db->lasterror();
806 if ($alreadydispatched) {
Class to manage bank accounts.
Class to manage bank transaction lines.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage payments of social contributions.
getLibStatut($mode=0)
Return the label of the status.
__construct(DoliDB $db)
Constructor.
fetch($id)
Load object in memory from database.
getNomUrl($withpicto=0, $maxlen=0)
Return clicable name (with picto eventually)
getVentilExportCompta()
Return if object was dispatched into bookkeeping.
create($user, $closepaidcontrib=0)
Create payment of social contribution into 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.
LibStatut($status, $mode=0)
Return the label of a given status.
update($user=null, $notrigger=0)
Update database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
update_fk_bank($id_bank)
Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee.
initAsSpecimen()
Initialise an instance with random values.
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...
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.
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...