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)) {
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) {
218 $this->error =
'ErrorPaymentAmountMustNotBeNull';
225 if ($totalamount != 0) {
226 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiementcharge (fk_charge, datec, datep, amount,";
227 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
228 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
229 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
230 $sql .=
" ".((float) $totalamount).
",";
231 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".$user->id.
",";
234 $resql = $this->db->query($sql);
236 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"paiementcharge");
239 foreach ($this->amounts as $key => $amount) {
241 if (is_numeric($amount) && $amount != 0) {
245 if ($closepaidcontrib) {
247 $contrib->fetch($contribid);
248 $paiement = $contrib->getSommePaiement();
253 $alreadypayed = (float)
price2num($paiement + $creditnotes + $deposits,
'MT');
254 $remaintopay = (float)
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
255 if ($remaintopay == 0) {
256 $result = $contrib->setPaid($user);
258 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
268 $result = $this->call_trigger(
'PAYMENTSOCIALCONTRIBUTION_CREATE', $user);
273 if ($totalamount != 0 && !$error) {
274 $this->
amount = $totalamount;
275 $this->total = $totalamount;
279 $this->error = $this->db->error();
280 $this->db->rollback();
295 $sql .=
" t.fk_charge,";
299 $sql .=
" t.amount,";
300 $sql .=
" t.fk_typepaiement,";
301 $sql .=
" t.num_paiement as num_payment,";
302 $sql .=
" t.note as note_private,";
303 $sql .=
" t.fk_bank,";
304 $sql .=
" t.fk_user_creat,";
305 $sql .=
" t.fk_user_modif,";
306 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
307 $sql .=
' b.fk_account';
308 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementcharge as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
309 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
310 $sql .=
" WHERE t.rowid = ".((int) $id);
313 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
314 $resql = $this->db->query($sql);
316 if ($this->db->num_rows($resql)) {
317 $obj = $this->db->fetch_object($resql);
319 $this->
id = $obj->rowid;
320 $this->
ref = $obj->rowid;
322 $this->fk_charge = $obj->fk_charge;
323 $this->datec = $this->db->jdate($obj->datec);
324 $this->tms = $this->db->jdate($obj->tms);
325 $this->datep = $this->db->jdate($obj->datep);
326 $this->
amount = $obj->amount;
327 $this->total = $obj->amount;
328 $this->fk_typepaiement = $obj->fk_typepaiement;
329 $this->num_payment = $obj->num_payment;
330 $this->num_paiement = $obj->num_payment;
331 $this->note_private = $obj->note_private;
332 $this->fk_bank = $obj->fk_bank;
333 $this->fk_user_creat = $obj->fk_user_creat;
334 $this->fk_user_modif = $obj->fk_user_modif;
336 $this->type_code = $obj->type_code;
337 $this->type_label = $obj->type_label;
339 $this->bank_account = $obj->fk_account;
340 $this->bank_line = $obj->fk_bank;
342 $this->db->free($resql);
346 $this->error =
"Error ".$this->db->lasterror();
359 public function update($user =
null, $notrigger = 0)
361 global $conf, $langs;
366 if (isset($this->fk_charge)) {
367 $this->fk_charge = (int) $this->fk_charge;
369 if (isset($this->
amount)) {
372 if (isset($this->fk_typepaiement)) {
373 $this->fk_typepaiement = (int) $this->fk_typepaiement;
375 if (isset($this->num_payment)) {
376 $this->num_payment = trim($this->num_payment);
378 if (isset($this->note_private)) {
379 $this->note_private = trim($this->note_private);
381 if (isset($this->fk_bank)) {
382 $this->fk_bank = (int) $this->fk_bank;
384 if (isset($this->fk_user_creat)) {
385 $this->fk_user_creat = (int) $this->fk_user_creat;
387 if (isset($this->fk_user_modif)) {
388 $this->fk_user_modif = (int) $this->fk_user_modif;
397 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET";
398 $sql .=
" fk_charge=".(isset($this->fk_charge) ? ((int) $this->fk_charge) :
"null").
",";
399 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
400 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
401 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
403 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) :
"null").
",";
404 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
405 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
406 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
407 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
408 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
409 $sql .=
" WHERE rowid=".((int) $this->
id);
413 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
414 $resql = $this->db->query($sql);
417 $this->errors[] =
"Error ".$this->db->lasterror();
422 foreach ($this->errors as $errmsg) {
423 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
424 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
426 $this->db->rollback();
442 public function delete($user, $notrigger = 0)
450 if ($this->bank_line > 0) {
452 $accline->fetch($this->bank_line);
453 $result = $accline->delete($user);
455 $this->errors[] = $accline->error;
461 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"paiementcharge";
462 $sql .=
" WHERE rowid=".((int) $this->
id);
464 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
465 $resql = $this->db->query($sql);
468 $this->errors[] =
"Error ".$this->db->lasterror();
474 foreach ($this->errors as $errmsg) {
475 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
476 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
478 $this->db->rollback();
513 $object->context[
'createfromclone'] =
'createfromclone';
514 $result =
$object->create($user);
522 unset(
$object->context[
'createfromclone']);
529 $this->db->rollback();
545 $this->fk_charge = 0;
550 $this->fk_typepaiement = 0;
551 $this->num_payment =
'ABC123';
552 $this->note_private =
'';
553 $this->note_public =
'';
555 $this->fk_user_creat = 0;
556 $this->fk_user_modif = 0;
574 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
576 global $conf, $langs;
579 $this->num_payment = trim($this->num_payment);
584 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
587 $acc->fetch($accountid);
589 $total = $this->amount;
590 if ($mode ==
'payment_sc') {
595 $bank_line_id = $acc->addline(
609 if ($bank_line_id > 0) {
617 if ($mode ==
'payment_sc') {
618 $url = DOL_URL_ROOT.
'/compta/payment_sc/card.php?id=';
621 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
629 $linkaddedforthirdparty = array();
630 foreach ($this->amounts as $key => $value) {
631 if ($mode ==
'payment_sc') {
633 $socialcontrib->fetch($key);
634 $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');
640 if ($socialcontrib->fk_user) {
641 $fuser =
new User($this->db);
642 $fuser->fetch($socialcontrib->fk_user);
645 $result = $acc->add_url_line(
647 $socialcontrib->fk_user,
648 DOL_URL_ROOT.
'/user/card.php?id=',
649 $fuser->getFullName($langs),
684 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiementcharge SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
686 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
687 $result = $this->db->query($sql);
691 $this->error = $this->db->error();
705 return $this->
LibStatut($this->statut, $mode);
721 $langs->load(
'compta');
773 if (empty($this->
ref)) {
774 $this->
ref = $this->label;
777 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"SocialContributionPayment").
'</u>';
778 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
779 if (!empty($this->label)) {
780 $labeltoshow = $this->label;
782 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
784 if ($reg[1] ==
'paiement') {
787 $labeltoshow = $langs->trans($reg[1]);
789 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
792 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
795 if (!empty($this->
id)) {
796 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_sc/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
800 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
802 if ($withpicto && $withpicto != 2) {
805 if ($withpicto != 2) {
806 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
822 $alreadydispatched = 0;
826 $sql =
" SELECT ".($mode ?
'DISTINCT piece_num' :
'COUNT(ab.rowid)').
" as nb";
827 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab";
828 $sql .=
" WHERE ab.doc_type = '".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $this->bank_line);
830 $resql = $this->db->query($sql);
832 $obj = $this->db->fetch_object($resql);
834 $alreadydispatched = $obj->nb;
837 $this->error = $this->db->lasterror();
841 if ($alreadydispatched) {
842 return $alreadydispatched;
if(! $sortfield) if(! $sortorder) $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
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.
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_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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount