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';
106 public $amounts = array();
111 public $fk_typepaiement;
118 public $num_paiement;
134 public $fk_user_creat;
139 public $fk_user_modif;
154 public $paiementtype;
175 public function create($user, $closepaidcontrib = 0)
181 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
184 if (!$this->datepaye) {
185 $this->error =
'ErrorBadValueForParameterCreatePaymentSocialContrib';
190 if (isset($this->fk_charge)) {
191 $this->fk_charge = (int) $this->fk_charge;
193 if (isset($this->
amount)) {
196 if (isset($this->fk_typepaiement)) {
197 $this->fk_typepaiement = (int) $this->fk_typepaiement;
199 if (isset($this->num_payment)) {
200 $this->num_payment = trim($this->num_payment);
202 if (isset($this->note_private)) {
203 $this->note_private = trim($this->note_private);
205 if (isset($this->fk_bank)) {
206 $this->fk_bank = (int) $this->fk_bank;
208 if (isset($this->fk_user_creat)) {
209 $this->fk_user_creat = (int) $this->fk_user_creat;
211 if (isset($this->fk_user_modif)) {
212 $this->fk_user_modif = (int) $this->fk_user_modif;
216 foreach ($this->amounts as $key => $value) {
217 $newvalue = (float)
price2num($value,
'MT');
218 $this->amounts[$key] = $newvalue;
219 $totalamount += $newvalue;
221 $totalamount = (float)
price2num($totalamount);
224 if ($totalamount == 0) {
225 $this->error =
'ErrorPaymentAmountMustNotBeNull';
232 if ($totalamount != 0) {
233 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiementcharge (fk_charge, datec, datep, amount,";
234 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
235 $sql .=
" VALUES (".((int) $this->chid).
", '".$this->db->idate($now).
"',";
236 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
237 $sql .=
" ".((float) $totalamount).
",";
238 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape((
string) $this->note).
"', ".((
int) $user->id).
",";
241 $resql = $this->db->query($sql);
243 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"paiementcharge");
246 foreach ($this->amounts as $key => $amount) {
248 if (is_numeric($amount) && $amount != 0) {
252 if ($closepaidcontrib) {
254 $contrib->fetch($contribid);
255 $paiement = $contrib->getSommePaiement();
260 $alreadypayed = (float)
price2num($paiement + $creditnotes + $deposits,
'MT');
261 $remaintopay = (float)
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
262 if ($remaintopay == 0) {
263 $result = $contrib->setPaid($user);
265 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
276 $result = $this->call_trigger(
'PAYMENTSOCIALCONTRIBUTION_CREATE', $user);
282 if ($totalamount != 0 && !$error) {
283 $this->
amount = $totalamount;
284 $this->total = $totalamount;
288 $this->error = $this->db->error();
289 $this->db->rollback();
304 $sql .=
" t.fk_charge,";
308 $sql .=
" t.amount,";
309 $sql .=
" t.fk_typepaiement,";
310 $sql .=
" t.num_paiement as num_payment,";
311 $sql .=
" t.note as note_private,";
312 $sql .=
" t.fk_bank,";
313 $sql .=
" t.fk_user_creat,";
314 $sql .=
" t.fk_user_modif,";
315 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
316 $sql .=
' b.fk_account';
317 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
318 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
319 $sql .=
" WHERE t.rowid = ".((int) $id);
322 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
323 $resql = $this->db->query($sql);
325 if ($this->db->num_rows($resql)) {
326 $obj = $this->db->fetch_object($resql);
328 $this->
id = $obj->rowid;
329 $this->
ref = $obj->rowid;
331 $this->fk_charge = $obj->fk_charge;
332 $this->datec = $this->db->jdate($obj->datec);
333 $this->tms = $this->db->jdate($obj->tms);
334 $this->datep = $this->db->jdate($obj->datep);
335 $this->
amount = $obj->amount;
336 $this->total = $obj->amount;
337 $this->fk_typepaiement = $obj->fk_typepaiement;
338 $this->num_payment = $obj->num_payment;
339 $this->num_paiement = $obj->num_payment;
340 $this->note_private = $obj->note_private;
341 $this->fk_bank = $obj->fk_bank;
342 $this->fk_user_creat = $obj->fk_user_creat;
343 $this->fk_user_modif = $obj->fk_user_modif;
345 $this->type_code = $obj->type_code;
346 $this->type_label = $obj->type_label;
348 $this->bank_account = $obj->fk_account;
349 $this->bank_line = $obj->fk_bank;
351 $this->db->free($resql);
355 $this->error =
"Error ".$this->db->lasterror();
368 public function update($user =
null, $notrigger = 0)
370 global
$conf, $langs;
375 if (isset($this->fk_charge)) {
376 $this->fk_charge = (int) $this->fk_charge;
378 if (isset($this->
amount)) {
381 if (isset($this->fk_typepaiement)) {
382 $this->fk_typepaiement = (int) $this->fk_typepaiement;
384 if (isset($this->num_payment)) {
385 $this->num_payment = trim($this->num_payment);
387 if (isset($this->note_private)) {
388 $this->note_private = trim($this->note_private);
390 if (isset($this->fk_bank)) {
391 $this->fk_bank = (int) $this->fk_bank;
393 if (isset($this->fk_user_creat)) {
394 $this->fk_user_creat = (int) $this->fk_user_creat;
396 if (isset($this->fk_user_modif)) {
397 $this->fk_user_modif = (int) $this->fk_user_modif;
406 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET";
407 $sql .=
" fk_charge=".(isset($this->fk_charge) ? ((int) $this->fk_charge) :
"null").
",";
408 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
409 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
410 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
412 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) :
"null").
",";
413 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
414 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
415 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
416 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
417 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
418 $sql .=
" WHERE rowid=".((int) $this->
id);
422 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
423 $resql = $this->db->query($sql);
426 $this->errors[] =
"Error ".$this->db->lasterror();
429 if (!$error && $user && !$notrigger) {
431 $result = $this->call_trigger(
'PAYMENTSOCIALCONTRIBUTION_MODIFY', $user);
440 foreach ($this->errors as $errmsg) {
441 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
442 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
444 $this->db->rollback();
460 public function delete($user, $notrigger = 0)
468 if ($this->bank_line > 0) {
470 $accline->fetch($this->bank_line);
471 $result = $accline->delete($user);
473 $this->errors[] = $accline->error;
479 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge";
480 $sql .=
" WHERE rowid=".((int) $this->
id);
482 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
483 $resql = $this->db->query($sql);
486 $this->errors[] =
"Error ".$this->db->lasterror();
490 if (!$error && !$notrigger) {
492 $result = $this->call_trigger(
'PAYMENTSOCIALCONTRIBUTION_DELETE', $user);
501 foreach ($this->errors as $errmsg) {
502 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
503 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
505 $this->db->rollback();
540 $object->context[
'createfromclone'] =
'createfromclone';
541 $result =
$object->create($user);
549 unset(
$object->context[
'createfromclone']);
556 $this->db->rollback();
572 $this->fk_charge = 0;
577 $this->fk_typepaiement = 0;
578 $this->num_payment =
'ABC123';
579 $this->note_private =
'';
580 $this->note_public =
'';
582 $this->fk_user_creat = 0;
583 $this->fk_user_modif = 0;
601 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
603 global
$conf, $langs;
606 $this->num_payment = trim($this->num_payment);
611 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
614 $acc->fetch($accountid);
616 $total = $this->amount;
617 if ($mode ==
'payment_sc') {
622 $bank_line_id = $acc->addline(
636 if ($bank_line_id > 0) {
644 if ($mode ==
'payment_sc') {
645 $url = DOL_URL_ROOT.
'/compta/payment_sc/card.php?id=';
648 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
656 $linkaddedforthirdparty = array();
657 foreach ($this->amounts as $key => $value) {
658 if ($mode ==
'payment_sc') {
660 $socialcontrib->fetch($key);
661 $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');
667 if ($socialcontrib->fk_user) {
668 $fuser =
new User($this->db);
669 $fuser->fetch($socialcontrib->fk_user);
672 $result = $acc->add_url_line(
674 $socialcontrib->fk_user,
675 DOL_URL_ROOT.
'/user/card.php?id=',
676 $fuser->getFullName($langs),
711 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
713 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
714 $result = $this->db->query($sql);
718 $this->error = $this->db->error();
732 return $this->
LibStatut($this->statut, $mode);
748 $langs->load(
'compta');
800 if (empty($this->
ref)) {
801 $this->
ref = $this->label;
804 $label = img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SocialContributionPayment").
'</u>';
805 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
806 if (!empty($this->label)) {
807 $labeltoshow = $this->label;
809 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
811 if ($reg[1] ==
'paiement') {
814 $labeltoshow = $langs->trans($reg[1]);
816 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
819 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
822 if (!empty($this->
id)) {
823 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_sc/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
827 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
829 if ($withpicto && $withpicto != 2) {
832 if ($withpicto != 2) {
833 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
837 global $action, $hookmanager;
838 $hookmanager->initHooks(array($this->element .
'dao'));
839 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
840 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
842 $result = $hookmanager->resPrint;
844 $result .= $hookmanager->resPrint;
859 $alreadydispatched = 0;
863 $sql =
" SELECT ".($mode ?
'DISTINCT piece_num' :
'COUNT(ab.rowid)').
" as nb";
864 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab";
865 $sql .=
" WHERE ab.doc_type = '".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $this->bank_line);
867 $resql = $this->db->query($sql);
869 $obj = $this->db->fetch_object($resql);
871 $alreadydispatched = $obj->nb;
874 $this->error = $this->db->lasterror();
878 if ($alreadydispatched) {
879 return $alreadydispatched;
if(! $sortfield) if(! $sortorder) $object
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage bank transaction lines.
Class for managing the social charges.
setErrorsFromObject($object)
setErrorsFromObject
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.
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
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.
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)
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount