25 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
26 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
37 public $element =
'paiementcharge';
42 public $table_element =
'paiementcharge';
47 public $picto =
'payment';
65 public $amounts = array();
70 public $fk_typepaiement;
91 public $fk_user_creat;
96 public $fk_user_modif;
116 public function create($user, $closepaidcontrib = 0)
118 global $conf, $langs;
124 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
127 if (!$this->datepaye)
129 $this->error =
'ErrorBadValueForParameterCreatePaymentSocialContrib';
134 if (isset($this->fk_charge)) $this->fk_charge = (int) $this->fk_charge;
135 if (isset($this->amount)) $this->amount = trim($this->amount);
136 if (isset($this->fk_typepaiement)) $this->fk_typepaiement = (
int) $this->fk_typepaiement;
137 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
138 if (isset($this->note_private)) $this->note_private = trim($this->note_private);
139 if (isset($this->fk_bank)) $this->fk_bank = (
int) $this->fk_bank;
140 if (isset($this->fk_user_creat)) $this->fk_user_creat = (
int) $this->fk_user_creat;
141 if (isset($this->fk_user_modif)) $this->fk_user_modif = (
int) $this->fk_user_modif;
144 foreach ($this->amounts as $key => $value)
147 $this->amounts[$key] = $newvalue;
148 $totalamount += $newvalue;
153 if ($totalamount == 0)
return -1;
158 if ($totalamount != 0)
160 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiementcharge (fk_charge, datec, datep, amount,";
161 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
162 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
163 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
164 $sql .=
" ".$totalamount.
",";
165 $sql .=
" ".$this->paiementtype.
", '".$this->
db->escape($this->num_payment).
"', '".$this->
db->escape($this->
note).
"', ".$user->id.
",";
171 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"paiementcharge");
174 foreach ($this->amounts as $key => $amount)
177 if (is_numeric($amount) && $amount <> 0)
182 if ($closepaidcontrib)
185 $contrib->fetch($contribid);
186 $paiement = $contrib->getSommePaiement();
191 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
192 $remaintopay =
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
193 if ($remaintopay == 0)
195 $result = $contrib->set_paid($user);
196 }
else dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
205 $result = $this->
call_trigger(
'PAYMENTSOCIALCONTRIBUTION_CREATE', $user);
206 if ($result < 0) $error++;
208 if ($totalamount != 0 && !$error)
210 $this->amount = $totalamount;
211 $this->total = $totalamount;
215 $this->error = $this->
db->error();
216 $this->
db->rollback();
232 $sql .=
" t.fk_charge,";
236 $sql .=
" t.amount,";
237 $sql .=
" t.fk_typepaiement,";
238 $sql .=
" t.num_paiement as num_payment,";
240 $sql .=
" t.fk_bank,";
241 $sql .=
" t.fk_user_creat,";
242 $sql .=
" t.fk_user_modif,";
243 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
244 $sql .=
' b.fk_account';
245 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
246 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
247 $sql .=
" WHERE t.rowid = ".$id;
250 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
256 $obj = $this->
db->fetch_object(
$resql);
258 $this->
id = $obj->rowid;
259 $this->ref = $obj->rowid;
261 $this->fk_charge = $obj->fk_charge;
262 $this->datec = $this->
db->jdate($obj->datec);
263 $this->tms = $this->
db->jdate($obj->tms);
264 $this->datep = $this->
db->jdate($obj->datep);
265 $this->amount = $obj->amount;
266 $this->fk_typepaiement = $obj->fk_typepaiement;
267 $this->num_payment = $obj->num_payment;
268 $this->note_private = $obj->note;
269 $this->fk_bank = $obj->fk_bank;
270 $this->fk_user_creat = $obj->fk_user_creat;
271 $this->fk_user_modif = $obj->fk_user_modif;
273 $this->type_code = $obj->type_code;
274 $this->type_label = $obj->type_label;
276 $this->bank_account = $obj->fk_account;
277 $this->bank_line = $obj->fk_bank;
283 $this->error =
"Error ".$this->db->lasterror();
296 public function update($user = null, $notrigger = 0)
298 global $conf, $langs;
303 if (isset($this->fk_charge)) $this->fk_charge = (int) $this->fk_charge;
304 if (isset($this->amount)) $this->amount = trim($this->amount);
305 if (isset($this->fk_typepaiement)) $this->fk_typepaiement = (
int) $this->fk_typepaiement;
306 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
307 if (isset($this->note_private)) $this->note_private = trim($this->note_private);
308 if (isset($this->fk_bank)) $this->fk_bank = (
int) $this->fk_bank;
309 if (isset($this->fk_user_creat)) $this->fk_user_creat = (
int) $this->fk_user_creat;
310 if (isset($this->fk_user_modif)) $this->fk_user_modif = (
int) $this->fk_user_modif;
318 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET";
320 $sql .=
" fk_charge=".(isset($this->fk_charge) ? $this->fk_charge :
"null").
",";
321 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
322 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
323 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
324 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
325 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? $this->fk_typepaiement :
"null").
",";
326 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
327 $sql .=
" note=".(isset($this->
note) ?
"'".$this->db->escape($this->
note).
"'" :
"null").
",";
328 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
329 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
330 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null").
"";
333 $sql .=
" WHERE rowid=".$this->id;
337 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
339 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
344 foreach ($this->errors as $errmsg)
346 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
347 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
349 $this->
db->rollback();
365 public function delete($user, $notrigger = 0)
367 global $conf, $langs;
374 if ($this->bank_line > 0)
377 $accline->fetch($this->bank_line);
378 $result = $accline->delete();
380 $this->errors[] = $accline->error;
387 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge";
388 $sql .=
" WHERE rowid=".$this->id;
390 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
392 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
398 foreach ($this->errors as $errmsg)
400 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
401 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
403 $this->
db->rollback();
429 $object->fetch($fromid);
437 $object->context[
'createfromclone'] =
'createfromclone';
438 $result = $object->create($user);
443 $this->error = $object->error;
447 unset($object->context[
'createfromclone']);
455 $this->
db->rollback();
472 $this->fk_charge =
'';
477 $this->fk_typepaiement =
'';
478 $this->num_payment =
'';
479 $this->note_private =
'';
480 $this->note_public =
'';
482 $this->fk_user_creat =
'';
483 $this->fk_user_modif =
'';
499 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
504 $this->num_payment = trim($this->num_payment);
508 if (!empty($conf->banque->enabled))
510 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
513 $acc->fetch($accountid);
519 $bank_line_id = $acc->addline(
533 if ($bank_line_id > 0)
544 if ($mode ==
'payment_sc') $url = DOL_URL_ROOT.
'/compta/payment_sc/card.php?id=';
547 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
556 $linkaddedforthirdparty = array();
557 foreach ($this->amounts as $key => $value)
559 if ($mode ==
'payment_sc')
562 $socialcontrib->fetch($key);
563 $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');
568 $this->error = $acc->error;
592 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET fk_bank = ".$id_bank.
" WHERE rowid = ".$this->id;
594 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
595 $result = $this->
db->query($sql);
600 $this->error = $this->
db->error();
630 $langs->load(
'compta');
682 if (empty($this->ref)) $this->ref = $this->lib;
684 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SocialContributionPayment").
'</u>';
685 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
686 if (!empty($this->label)) {
687 $labeltoshow = $this->label;
689 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg))
692 if ($reg[1] ==
'paiement') $reg[1] =
'Payment';
693 $labeltoshow = $langs->trans($reg[1]);
695 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
697 if ($this->datep) $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
699 if (!empty($this->
id)) {
700 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_sc/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
703 if ($withpicto) $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
704 if ($withpicto && $withpicto != 2) $result .=
' ';
705 if ($withpicto != 2) $result .= $link.($maxlen ?
dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
719 $alreadydispatched = 0;
723 $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 = ".$this->bank_line;
727 $obj = $this->
db->fetch_object(
$resql);
730 $alreadydispatched = $obj->nb;
733 $this->error = $this->
db->lasterror();
737 if ($alreadydispatched)
getLibStatut($mode=0)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) ...
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
fetch($id)
Load object in memory from database.
dol_now($mode= 'auto')
Return date for now.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
Class to manage Dolibarr users.
Class to manage payments of social contributions.
Class to manage bank transaction lines.
$conf db
API class for accounts.
Class to manage bank accounts.
__construct($db)
Constructor.
update($user=null, $notrigger=0)
Update database.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
initAsSpecimen()
Initialise an instance with random values.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getNomUrl($withpicto=0, $maxlen=0)
Return clicable name (with picto eventually)
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
update_fk_bank($id_bank)
Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
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.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
getVentilExportCompta()
Return if object was dispatched into bookkeeping.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
create($user, $closepaidcontrib=0)
Create payment of social contribution into database.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...