28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
40 public $element =
'paiementcharge';
45 public $table_element =
'paiementcharge';
50 public $picto =
'payment';
99 public $amounts = array();
104 public $fk_typepaiement;
111 public $num_paiement;
127 public $fk_user_creat;
132 public $fk_user_modif;
147 public $paiementtype;
168 public function create($user, $closepaidcontrib = 0)
174 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
177 if (!$this->datepaye) {
178 $this->error =
'ErrorBadValueForParameterCreatePaymentSocialContrib';
183 if (isset($this->fk_charge)) {
184 $this->fk_charge = (int) $this->fk_charge;
186 if (isset($this->amount)) {
187 $this->amount = (float) $this->amount;
189 if (isset($this->fk_typepaiement)) {
190 $this->fk_typepaiement = (int) $this->fk_typepaiement;
192 if (isset($this->num_payment)) {
193 $this->num_payment = trim($this->num_payment);
195 if (isset($this->note_private)) {
196 $this->note_private = trim($this->note_private);
198 if (isset($this->fk_bank)) {
199 $this->fk_bank = (int) $this->fk_bank;
201 if (isset($this->fk_user_creat)) {
202 $this->fk_user_creat = (int) $this->fk_user_creat;
204 if (isset($this->fk_user_modif)) {
205 $this->fk_user_modif = (int) $this->fk_user_modif;
209 foreach ($this->amounts as $key => $value) {
210 $newvalue = (float)
price2num($value,
'MT');
211 $this->amounts[$key] = $newvalue;
212 $totalamount += $newvalue;
214 $totalamount = (float)
price2num($totalamount);
217 if ($totalamount == 0) {
224 if ($totalamount != 0) {
225 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiementcharge (fk_charge, datec, datep, amount,";
226 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
227 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
228 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
229 $sql .=
" ".((float) $totalamount).
",";
230 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".$user->id.
",";
233 $resql = $this->db->query($sql);
235 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"paiementcharge");
238 foreach ($this->amounts as $key => $amount) {
240 if (is_numeric($amount) && $amount != 0) {
244 if ($closepaidcontrib) {
246 $contrib->fetch($contribid);
247 $paiement = $contrib->getSommePaiement();
252 $alreadypayed = (float)
price2num($paiement + $creditnotes + $deposits,
'MT');
253 $remaintopay = (float)
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
254 if ($remaintopay == 0) {
255 $result = $contrib->setPaid($user);
257 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
267 $result = $this->
call_trigger(
'PAYMENTSOCIALCONTRIBUTION_CREATE', $user);
272 if ($totalamount != 0 && !$error) {
273 $this->amount = $totalamount;
274 $this->total = $totalamount;
278 $this->error = $this->db->error();
279 $this->db->rollback();
294 $sql .=
" t.fk_charge,";
298 $sql .=
" t.amount,";
299 $sql .=
" t.fk_typepaiement,";
300 $sql .=
" t.num_paiement as num_payment,";
301 $sql .=
" t.note as note_private,";
302 $sql .=
" t.fk_bank,";
303 $sql .=
" t.fk_user_creat,";
304 $sql .=
" t.fk_user_modif,";
305 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
306 $sql .=
' b.fk_account';
307 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
308 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
309 $sql .=
" WHERE t.rowid = ".((int) $id);
312 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
313 $resql = $this->db->query($sql);
315 if ($this->db->num_rows($resql)) {
316 $obj = $this->db->fetch_object($resql);
318 $this->
id = $obj->rowid;
319 $this->
ref = $obj->rowid;
321 $this->fk_charge = $obj->fk_charge;
322 $this->datec = $this->db->jdate($obj->datec);
323 $this->tms = $this->db->jdate($obj->tms);
324 $this->datep = $this->db->jdate($obj->datep);
325 $this->amount = $obj->amount;
326 $this->total = $obj->amount;
327 $this->fk_typepaiement = $obj->fk_typepaiement;
328 $this->num_payment = $obj->num_payment;
329 $this->num_paiement = $obj->num_payment;
330 $this->note_private = $obj->note_private;
331 $this->fk_bank = $obj->fk_bank;
332 $this->fk_user_creat = $obj->fk_user_creat;
333 $this->fk_user_modif = $obj->fk_user_modif;
335 $this->type_code = $obj->type_code;
336 $this->type_label = $obj->type_label;
338 $this->bank_account = $obj->fk_account;
339 $this->bank_line = $obj->fk_bank;
341 $this->db->free($resql);
345 $this->error =
"Error ".$this->db->lasterror();
358 public function update($user =
null, $notrigger = 0)
360 global
$conf, $langs;
365 if (isset($this->fk_charge)) {
366 $this->fk_charge = (int) $this->fk_charge;
368 if (isset($this->amount)) {
369 $this->amount = (float) $this->amount;
371 if (isset($this->fk_typepaiement)) {
372 $this->fk_typepaiement = (int) $this->fk_typepaiement;
374 if (isset($this->num_payment)) {
375 $this->num_payment = trim($this->num_payment);
377 if (isset($this->note_private)) {
378 $this->note_private = trim($this->note_private);
380 if (isset($this->fk_bank)) {
381 $this->fk_bank = (int) $this->fk_bank;
383 if (isset($this->fk_user_creat)) {
384 $this->fk_user_creat = (int) $this->fk_user_creat;
386 if (isset($this->fk_user_modif)) {
387 $this->fk_user_modif = (int) $this->fk_user_modif;
396 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET";
397 $sql .=
" fk_charge=".(isset($this->fk_charge) ? ((int) $this->fk_charge) :
"null").
",";
398 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
399 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
400 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
401 $sql .=
" amount=".(isset($this->amount) ?
price2num($this->amount) :
"null").
",";
402 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) :
"null").
",";
403 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
404 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
405 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
406 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
407 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
408 $sql .=
" WHERE rowid=".((int) $this->
id);
412 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
413 $resql = $this->db->query($sql);
416 $this->errors[] =
"Error ".$this->db->lasterror();
421 foreach ($this->errors as $errmsg) {
422 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
423 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
425 $this->db->rollback();
441 public function delete($user, $notrigger = 0)
449 if ($this->bank_line > 0) {
451 $accline->fetch($this->bank_line);
452 $result = $accline->delete($user);
454 $this->errors[] = $accline->error;
460 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge";
461 $sql .=
" WHERE rowid=".((int) $this->
id);
463 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
464 $resql = $this->db->query($sql);
467 $this->errors[] =
"Error ".$this->db->lasterror();
473 foreach ($this->errors as $errmsg) {
474 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
475 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
477 $this->db->rollback();
511 $object->context[
'createfromclone'] =
'createfromclone';
512 $result =
$object->create($user);
520 unset(
$object->context[
'createfromclone']);
527 $this->db->rollback();
543 $this->fk_charge = 0;
548 $this->fk_typepaiement = 0;
549 $this->num_payment =
'ABC123';
550 $this->note_private =
'';
551 $this->note_public =
'';
553 $this->fk_user_creat = 0;
554 $this->fk_user_modif = 0;
572 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
574 global
$conf, $langs;
577 $this->num_payment = trim($this->num_payment);
581 if (isModEnabled(
"bank")) {
582 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
585 $acc->fetch($accountid);
587 $total = $this->amount;
588 if ($mode ==
'payment_sc') {
593 $bank_line_id = $acc->addline(
607 if ($bank_line_id > 0) {
615 if ($mode ==
'payment_sc') {
616 $url = DOL_URL_ROOT.
'/compta/payment_sc/card.php?id=';
619 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
627 $linkaddedforthirdparty = array();
628 foreach ($this->amounts as $key => $value) {
629 if ($mode ==
'payment_sc') {
631 $socialcontrib->fetch($key);
632 $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');
638 if ($socialcontrib->fk_user) {
639 $fuser =
new User($this->db);
640 $fuser->fetch($socialcontrib->fk_user);
643 $result = $acc->add_url_line(
645 $socialcontrib->fk_user,
646 DOL_URL_ROOT.
'/user/card.php?id=',
647 $fuser->getFullName($langs),
682 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
684 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
685 $result = $this->db->query($sql);
689 $this->error = $this->db->error();
703 return $this->
LibStatut($this->statut, $mode);
719 $langs->load(
'compta');
771 if (empty($this->
ref)) {
772 $this->
ref = $this->label;
775 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SocialContributionPayment").
'</u>';
776 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
777 if (!empty($this->label)) {
778 $labeltoshow = $this->label;
780 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
782 if ($reg[1] ==
'paiement') {
785 $labeltoshow = $langs->trans($reg[1]);
787 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
790 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
793 if (!empty($this->
id)) {
794 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_sc/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
798 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
800 if ($withpicto && $withpicto != 2) {
803 if ($withpicto != 2) {
804 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
820 $alreadydispatched = 0;
824 $sql =
" SELECT ".($mode ?
'DISTINCT piece_num' :
'COUNT(ab.rowid)').
" as nb";
825 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab";
826 $sql .=
" WHERE ab.doc_type = '".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $this->bank_line);
828 $resql = $this->db->query($sql);
830 $obj = $this->db->fetch_object($resql);
832 $alreadydispatched = $obj->nb;
835 $this->error = $this->db->lasterror();
839 if ($alreadydispatched) {
840 return $alreadydispatched;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage bank accounts.
Class to manage bank transaction lines.
Class for managing the social charges.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
setErrorsFromObject($object)
setErrorsFromObject
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 clickable name (with picto eventually)
getVentilExportCompta($mode=0)
Return if object was dispatched into bookkeeping, or return the array of bookkeeping id.
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)
Update the link between the Payment and the line generated in llx_bank.
initAsSpecimen()
Initialise an instance with random values.
Class to manage Dolibarr users.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...