28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
40 public $element =
'payment_vat';
45 public $table_element =
'payment_vat';
50 public $picto =
'payment';
76 public $amounts = array();
81 public $fk_typepaiement;
104 public $fk_user_creat;
109 public $fk_user_modif;
141 public $bank_account;
151 public $paiementtype;
171 public function create($user, $closepaidvat = 0)
177 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
180 if (!$this->datepaye) {
181 $this->error =
'ErrorBadValueForParameterCreatePaymentVAT';
186 if (isset($this->fk_tva)) {
187 $this->fk_tva = (int) $this->fk_tva;
189 if (isset($this->amount)) {
190 $this->amount = (float) $this->amount;
192 if (isset($this->fk_typepaiement)) {
193 $this->fk_typepaiement = (int) $this->fk_typepaiement;
195 if (isset($this->num_paiement)) {
196 $this->num_paiement = trim($this->num_paiement);
198 if (isset($this->num_payment)) {
199 $this->num_payment = trim($this->num_payment);
201 if (isset($this->note)) {
202 $this->note = trim($this->note);
204 if (isset($this->fk_bank)) {
205 $this->fk_bank = (int) $this->fk_bank;
207 if (isset($this->fk_user_creat)) {
208 $this->fk_user_creat = (int) $this->fk_user_creat;
210 if (isset($this->fk_user_modif)) {
211 $this->fk_user_modif = (int) $this->fk_user_modif;
215 foreach ($this->amounts as $key => $value) {
216 $newvalue = (float)
price2num($value,
'MT');
217 $this->amounts[$key] = $newvalue;
218 $totalamount += $newvalue;
223 if ($totalamount == 0) {
230 if ($totalamount != 0) {
231 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_vat (fk_tva, datec, datep, amount,";
232 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
233 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
234 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
235 $sql .=
" ".((float) $totalamount).
",";
236 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".$user->id.
",";
239 $resql = $this->db->query($sql);
241 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_vat");
244 foreach ($this->amounts as $key => $amount) {
246 if (is_numeric($amount) && $amount != 0) {
251 $contrib =
new Tva($this->db);
252 $contrib->fetch($contribid);
253 $paiement = $contrib->getSommePaiement();
258 $alreadypayed = (float)
price2num($paiement + $creditnotes + $deposits,
'MT');
259 $remaintopay = (float)
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
260 if ($remaintopay == 0) {
261 $result = $contrib->setPaid($user);
263 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
273 $result = $this->
call_trigger(
'PAYMENTVAT_CREATE', $user);
278 if ($totalamount != 0 && !$error) {
279 $this->amount = $totalamount;
280 $this->total = $totalamount;
284 $this->error = $this->db->error();
285 $this->db->rollback();
300 $sql .=
" t.fk_tva,";
304 $sql .=
" t.amount,";
305 $sql .=
" t.fk_typepaiement,";
306 $sql .=
" t.num_paiement as num_payment,";
307 $sql .=
" t.note as note_private,";
308 $sql .=
" t.fk_bank,";
309 $sql .=
" t.fk_user_creat,";
310 $sql .=
" t.fk_user_modif,";
311 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
312 $sql .=
' b.fk_account';
313 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_vat as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
314 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
315 $sql .=
" WHERE t.rowid = ".((int) $id);
318 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
319 $resql = $this->db->query($sql);
321 if ($this->db->num_rows($resql)) {
322 $obj = $this->db->fetch_object($resql);
324 $this->
id = $obj->rowid;
325 $this->
ref = $obj->rowid;
327 $this->fk_tva = $obj->fk_tva;
328 $this->datec = $this->db->jdate($obj->datec);
329 $this->tms = $this->db->jdate($obj->tms);
330 $this->datep = $this->db->jdate($obj->datep);
331 $this->amount = $obj->amount;
332 $this->fk_typepaiement = $obj->fk_typepaiement;
333 $this->num_paiement = $obj->num_payment;
334 $this->num_payment = $obj->num_payment;
335 $this->note = $obj->note_private;
336 $this->note_private = $obj->note_private;
337 $this->fk_bank = $obj->fk_bank;
338 $this->fk_user_creat = $obj->fk_user_creat;
339 $this->fk_user_modif = $obj->fk_user_modif;
341 $this->type_code = $obj->type_code;
342 $this->type_label = $obj->type_label;
344 $this->bank_account = $obj->fk_account;
345 $this->bank_line = $obj->fk_bank;
347 $this->db->free($resql);
351 $this->error =
"Error ".$this->db->lasterror();
364 public function update($user =
null, $notrigger = 0)
366 global $conf, $langs;
371 if (isset($this->fk_tva)) {
372 $this->fk_tva = (int) $this->fk_tva;
374 if (isset($this->amount)) {
375 $this->amount = (float) $this->amount;
377 if (isset($this->fk_typepaiement)) {
378 $this->fk_typepaiement = (int) $this->fk_typepaiement;
380 if (isset($this->num_payment)) {
381 $this->num_payment = trim($this->num_payment);
383 if (isset($this->note)) {
384 $this->note = trim($this->note);
386 if (isset($this->fk_bank)) {
387 $this->fk_bank = (int) $this->fk_bank;
389 if (isset($this->fk_user_creat)) {
390 $this->fk_user_creat = (int) $this->fk_user_creat;
392 if (isset($this->fk_user_modif)) {
393 $this->fk_user_modif = (int) $this->fk_user_modif;
400 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET";
401 $sql .=
" fk_tva=".(isset($this->fk_tva) ? ((int) $this->fk_tva) :
"null").
",";
402 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
403 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
404 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
405 $sql .=
" amount=".(isset($this->amount) ? (float)
price2num($this->amount) :
"null").
",";
406 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) :
"null").
",";
407 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
408 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
409 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
410 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
411 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
412 $sql .=
" WHERE rowid=".((int) $this->
id);
416 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
417 $resql = $this->db->query($sql);
420 $this->errors[] =
"Error ".$this->db->lasterror();
425 foreach ($this->errors as $errmsg) {
426 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
427 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
429 $this->db->rollback();
445 public function delete($user, $notrigger = 0)
453 if ($this->bank_line > 0) {
455 $accline->fetch($this->bank_line);
456 $result = $accline->delete($user);
458 $this->errors[] = $accline->error;
464 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_vat";
465 $sql .=
" WHERE rowid=".((int) $this->
id);
467 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
468 $resql = $this->db->query($sql);
471 $this->errors[] =
"Error ".$this->db->lasterror();
477 foreach ($this->errors as $errmsg) {
478 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
479 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
481 $this->db->rollback();
514 $object->context[
'createfromclone'] =
'createfromclone';
515 $result =
$object->create($user);
523 unset(
$object->context[
'createfromclone']);
530 $this->db->rollback();
551 $this->fk_typepaiement = 0;
552 $this->num_payment =
'123456';
553 $this->note_private =
'Private note';
554 $this->note_public =
'Public note';
556 $this->fk_user_creat = 0;
557 $this->fk_user_modif = 0;
575 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
578 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
582 if (isModEnabled(
"bank")) {
583 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
586 $acc->fetch($accountid);
588 $total = $this->amount;
589 if ($mode ==
'payment_vat') {
594 $bank_line_id = $acc->addline(
608 if ($bank_line_id > 0) {
617 if ($mode ==
'payment_vat') {
618 $url = DOL_URL_ROOT.
'/compta/payment_vat/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_vat') {
632 $tva =
new Tva($this->db);
634 $result = $acc->add_url_line($bank_line_id, $tva->id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
'('.$tva->label.
')',
'vat');
641 $this->error = $acc->error;
664 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
666 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
667 $result = $this->db->query($sql);
671 $this->error = $this->db->error();
701 $langs->load(
'compta');
753 if (empty($this->
ref)) {
754 $this->
ref = $this->lib;
757 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"VATPayment").
'</u>';
758 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
759 if (!empty($this->label)) {
760 $labeltoshow = $this->label;
762 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
764 if ($reg[1] ==
'paiement') {
767 $labeltoshow = $langs->trans($reg[1]);
769 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
772 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
775 if (!empty($this->
id)) {
776 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_vat/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
780 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
782 if ($withpicto && $withpicto != 2) {
785 if ($withpicto != 2) {
786 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage bank accounts.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage payments of social contributions.
initAsSpecimen()
Initialise an instance with random values.
LibStatut($status, $mode=0)
Return the label of a given status.
create($user, $closepaidvat=0)
Create payment of vat into database.
__construct($db)
Constructor.
update_fk_bank($id_bank)
Update link between vat payment and line in llx_bank generated.
fetch($id)
Load object in memory from database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
getLibStatut($mode=0)
Return the label of the status.
getNomUrl($withpicto=0, $maxlen=0)
Return clickable name (with picto eventually)
update($user=null, $notrigger=0)
Update 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.
Put here description of your class.
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