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)
170 global $conf, $langs;
176 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
179 if (!$this->datepaye) {
180 $this->error =
'ErrorBadValueForParameterCreatePaymentSocialContrib';
185 if (isset($this->fk_charge)) {
186 $this->fk_charge = (int) $this->fk_charge;
188 if (isset($this->amount)) {
189 $this->amount = (float) $this->amount;
191 if (isset($this->fk_typepaiement)) {
192 $this->fk_typepaiement = (int) $this->fk_typepaiement;
194 if (isset($this->num_payment)) {
195 $this->num_payment = trim($this->num_payment);
197 if (isset($this->note_private)) {
198 $this->note_private = trim($this->note_private);
200 if (isset($this->fk_bank)) {
201 $this->fk_bank = (int) $this->fk_bank;
203 if (isset($this->fk_user_creat)) {
204 $this->fk_user_creat = (int) $this->fk_user_creat;
206 if (isset($this->fk_user_modif)) {
207 $this->fk_user_modif = (int) $this->fk_user_modif;
211 foreach ($this->amounts as $key => $value) {
212 $newvalue = (float)
price2num($value,
'MT');
213 $this->amounts[$key] = $newvalue;
214 $totalamount += $newvalue;
216 $totalamount = (float)
price2num($totalamount);
219 if ($totalamount == 0) {
226 if ($totalamount != 0) {
227 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiementcharge (fk_charge, datec, datep, amount,";
228 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
229 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
230 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
231 $sql .=
" ".((float) $totalamount).
",";
232 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".$user->id.
",";
235 $resql = $this->db->query($sql);
237 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"paiementcharge");
240 foreach ($this->amounts as $key => $amount) {
242 if (is_numeric($amount) && $amount != 0) {
246 if ($closepaidcontrib) {
248 $contrib->fetch($contribid);
249 $paiement = $contrib->getSommePaiement();
254 $alreadypayed = (float)
price2num($paiement + $creditnotes + $deposits,
'MT');
255 $remaintopay = (float)
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
256 if ($remaintopay == 0) {
257 $result = $contrib->setPaid($user);
259 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
269 $result = $this->
call_trigger(
'PAYMENTSOCIALCONTRIBUTION_CREATE', $user);
274 if ($totalamount != 0 && !$error) {
275 $this->amount = $totalamount;
276 $this->total = $totalamount;
280 $this->error = $this->db->error();
281 $this->db->rollback();
297 $sql .=
" t.fk_charge,";
301 $sql .=
" t.amount,";
302 $sql .=
" t.fk_typepaiement,";
303 $sql .=
" t.num_paiement as num_payment,";
305 $sql .=
" t.fk_bank,";
306 $sql .=
" t.fk_user_creat,";
307 $sql .=
" t.fk_user_modif,";
308 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
309 $sql .=
' b.fk_account';
310 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
311 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
312 $sql .=
" WHERE t.rowid = ".((int) $id);
315 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
316 $resql = $this->db->query($sql);
318 if ($this->db->num_rows($resql)) {
319 $obj = $this->db->fetch_object($resql);
321 $this->
id = $obj->rowid;
322 $this->
ref = $obj->rowid;
324 $this->fk_charge = $obj->fk_charge;
325 $this->datec = $this->db->jdate($obj->datec);
326 $this->tms = $this->db->jdate($obj->tms);
327 $this->datep = $this->db->jdate($obj->datep);
328 $this->amount = $obj->amount;
329 $this->total = $obj->amount;
330 $this->fk_typepaiement = $obj->fk_typepaiement;
331 $this->num_payment = $obj->num_payment;
332 $this->num_paiement = $obj->num_payment;
333 $this->note_private = $obj->note;
334 $this->fk_bank = $obj->fk_bank;
335 $this->fk_user_creat = $obj->fk_user_creat;
336 $this->fk_user_modif = $obj->fk_user_modif;
338 $this->type_code = $obj->type_code;
339 $this->type_label = $obj->type_label;
341 $this->bank_account = $obj->fk_account;
342 $this->bank_line = $obj->fk_bank;
344 $this->db->free($resql);
348 $this->error =
"Error ".$this->db->lasterror();
361 public function update($user =
null, $notrigger = 0)
363 global $conf, $langs;
368 if (isset($this->fk_charge)) {
369 $this->fk_charge = (int) $this->fk_charge;
371 if (isset($this->amount)) {
372 $this->amount = (float) $this->amount;
374 if (isset($this->fk_typepaiement)) {
375 $this->fk_typepaiement = (int) $this->fk_typepaiement;
377 if (isset($this->num_payment)) {
378 $this->num_payment = trim($this->num_payment);
380 if (isset($this->note_private)) {
381 $this->note_private = trim($this->note_private);
383 if (isset($this->fk_bank)) {
384 $this->fk_bank = (int) $this->fk_bank;
386 if (isset($this->fk_user_creat)) {
387 $this->fk_user_creat = (int) $this->fk_user_creat;
389 if (isset($this->fk_user_modif)) {
390 $this->fk_user_modif = (int) $this->fk_user_modif;
399 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET";
400 $sql .=
" fk_charge=".(isset($this->fk_charge) ? ((int) $this->fk_charge) :
"null").
",";
401 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
402 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
403 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
404 $sql .=
" amount=".(isset($this->amount) ?
price2num($this->amount) :
"null").
",";
405 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) :
"null").
",";
406 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
407 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
408 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
409 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
410 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
411 $sql .=
" WHERE rowid=".((int) $this->
id);
415 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
416 $resql = $this->db->query($sql);
419 $this->errors[] =
"Error ".$this->db->lasterror();
424 foreach ($this->errors as $errmsg) {
425 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
426 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
428 $this->db->rollback();
444 public function delete($user, $notrigger = 0)
452 if ($this->bank_line > 0) {
454 $accline->fetch($this->bank_line);
455 $result = $accline->delete($user);
457 $this->errors[] = $accline->error;
463 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge";
464 $sql .=
" WHERE rowid=".((int) $this->
id);
466 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
467 $resql = $this->db->query($sql);
470 $this->errors[] =
"Error ".$this->db->lasterror();
476 foreach ($this->errors as $errmsg) {
477 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
478 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
480 $this->db->rollback();
514 $object->context[
'createfromclone'] =
'createfromclone';
515 $result =
$object->create($user);
523 unset(
$object->context[
'createfromclone']);
530 $this->db->rollback();
546 $this->fk_charge = 0;
551 $this->fk_typepaiement = 0;
552 $this->num_payment =
'ABC123';
553 $this->note_private =
'';
554 $this->note_public =
'';
556 $this->fk_user_creat = 0;
557 $this->fk_user_modif = 0;
575 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
577 global $conf, $langs;
580 $this->num_payment = trim($this->num_payment);
584 if (isModEnabled(
"bank")) {
585 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
588 $acc->fetch($accountid);
590 $total = $this->amount;
591 if ($mode ==
'payment_sc') {
596 $bank_line_id = $acc->addline(
610 if ($bank_line_id > 0) {
619 if ($mode ==
'payment_sc') {
620 $url = DOL_URL_ROOT.
'/compta/payment_sc/card.php?id=';
623 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
631 $linkaddedforthirdparty = array();
632 foreach ($this->amounts as $key => $value) {
633 if ($mode ==
'payment_sc') {
635 $socialcontrib->fetch($key);
636 $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');
641 if ($socialcontrib->fk_user) {
642 $fuser =
new User($this->db);
643 $fuser->fetch($socialcontrib->fk_user);
646 $result = $acc->add_url_line(
648 $socialcontrib->fk_user,
649 DOL_URL_ROOT.
'/user/card.php?id=',
650 $fuser->getFullName($langs),
655 $this->error = $acc->error;
662 $this->error = $acc->error;
685 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
687 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
688 $result = $this->db->query($sql);
692 $this->error = $this->db->error();
722 $langs->load(
'compta');
774 if (empty($this->
ref)) {
775 $this->
ref = $this->label;
778 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SocialContributionPayment").
'</u>';
779 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
780 if (!empty($this->label)) {
781 $labeltoshow = $this->label;
783 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
785 if ($reg[1] ==
'paiement') {
788 $labeltoshow = $langs->trans($reg[1]);
790 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
793 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
796 if (!empty($this->
id)) {
797 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_sc/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
801 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
803 if ($withpicto && $withpicto != 2) {
806 if ($withpicto != 2) {
807 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
822 $alreadydispatched = 0;
826 $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);
827 $resql = $this->db->query($sql);
829 $obj = $this->db->fetch_object($resql);
831 $alreadydispatched = $obj->nb;
834 $this->error = $this->db->lasterror();
838 if ($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,...
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut