26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
27 require_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.
",";
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);
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;
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";
369 $sql .=
" fk_charge=".(isset($this->fk_charge) ? $this->fk_charge :
"null").
",";
370 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
371 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
372 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
373 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
374 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? $this->fk_typepaiement :
"null").
",";
375 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
376 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
377 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
378 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
379 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null").
"";
382 $sql .=
" WHERE rowid=".((int) $this->
id);
386 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
390 $this->errors[] =
"Error ".$this->db->lasterror();
395 foreach ($this->errors as $errmsg) {
396 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
397 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
399 $this->
db->rollback();
415 public function delete($user, $notrigger = 0)
417 global $conf, $langs;
424 if ($this->bank_line > 0) {
426 $accline->fetch($this->bank_line);
427 $result = $accline->delete();
429 $this->errors[] = $accline->error;
435 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge";
436 $sql .=
" WHERE rowid=".((int) $this->
id);
438 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
442 $this->errors[] =
"Error ".$this->db->lasterror();
448 foreach ($this->errors as $errmsg) {
449 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
450 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
452 $this->
db->rollback();
478 $object->fetch($fromid);
486 $object->context[
'createfromclone'] =
'createfromclone';
487 $result = $object->create($user);
491 $this->error = $object->error;
495 unset($object->context[
'createfromclone']);
502 $this->
db->rollback();
519 $this->fk_charge =
'';
524 $this->fk_typepaiement =
'';
525 $this->num_payment =
'';
526 $this->note_private =
'';
527 $this->note_public =
'';
529 $this->fk_user_creat =
'';
530 $this->fk_user_modif =
'';
546 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
548 global $conf, $langs;
551 $this->num_payment = trim($this->num_payment);
556 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
559 $acc->fetch($accountid);
562 if ($mode ==
'payment_sc') {
567 $bank_line_id = $acc->addline(
581 if ($bank_line_id > 0) {
590 if ($mode ==
'payment_sc') {
591 $url = DOL_URL_ROOT.
'/compta/payment_sc/card.php?id=';
594 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
602 $linkaddedforthirdparty = array();
603 foreach ($this->amounts as $key => $value) {
604 if ($mode ==
'payment_sc') {
606 $socialcontrib->fetch($key);
607 $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');
612 if ($socialcontrib->fk_user) {
613 $fuser =
new User($this->
db);
614 $fuser->fetch($socialcontrib->fk_user);
617 $result = $acc->add_url_line(
619 $socialcontrib->fk_user,
620 DOL_URL_ROOT.
'/user/card.php?id=',
621 $fuser->getFullName($langs),
626 $this->error = $acc->error;
633 $this->error = $acc->error;
656 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
658 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
659 $result = $this->
db->query($sql);
663 $this->error = $this->
db->error();
677 return $this->
LibStatut($this->statut, $mode);
693 $langs->load(
'compta');
745 if (empty($this->
ref)) {
746 $this->
ref = $this->label;
749 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SocialContributionPayment").
'</u>';
750 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
751 if (!empty($this->label)) {
752 $labeltoshow = $this->label;
754 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
756 if ($reg[1] ==
'paiement') {
759 $labeltoshow = $langs->trans($reg[1]);
761 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
764 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
767 if (!empty($this->
id)) {
768 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_sc/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
772 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
774 if ($withpicto && $withpicto != 2) {
777 if ($withpicto != 2) {
778 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
793 $alreadydispatched = 0;
797 $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);
800 $obj = $this->
db->fetch_object(
$resql);
802 $alreadydispatched = $obj->nb;
805 $this->error = $this->
db->lasterror();
809 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)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
__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)
Renvoi le libelle d'un statut donne.
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.
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.