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';
82 public $amounts = array();
87 public $fk_typepaiement;
110 public $fk_user_creat;
115 public $fk_user_modif;
147 public $bank_account;
157 public $paiementtype;
177 public function create($user, $closepaidvat = 0)
183 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
186 if (!$this->datepaye) {
187 $this->error =
'ErrorBadValueForParameterCreatePaymentVAT';
192 if (isset($this->fk_tva)) {
193 $this->fk_tva = (int) $this->fk_tva;
195 if (isset($this->amount)) {
196 $this->amount = (float) $this->amount;
198 if (isset($this->fk_typepaiement)) {
199 $this->fk_typepaiement = (int) $this->fk_typepaiement;
201 if (isset($this->num_paiement)) {
202 $this->num_paiement = trim($this->num_paiement);
204 if (isset($this->num_payment)) {
205 $this->num_payment = trim($this->num_payment);
207 if (isset($this->note)) {
208 $this->note = trim($this->note);
210 if (isset($this->fk_bank)) {
211 $this->fk_bank = (int) $this->fk_bank;
213 if (isset($this->fk_user_creat)) {
214 $this->fk_user_creat = (int) $this->fk_user_creat;
216 if (isset($this->fk_user_modif)) {
217 $this->fk_user_modif = (int) $this->fk_user_modif;
221 foreach ($this->amounts as $key => $value) {
222 $newvalue = (float)
price2num($value,
'MT');
223 $this->amounts[$key] = $newvalue;
224 $totalamount += $newvalue;
229 if ($totalamount == 0) {
236 if ($totalamount != 0) {
237 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_vat (fk_tva, datec, datep, amount,";
238 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
239 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
240 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
241 $sql .=
" ".((float) $totalamount).
",";
242 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".$user->id.
",";
245 $resql = $this->db->query($sql);
247 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_vat");
250 foreach ($this->amounts as $key => $amount) {
252 if (is_numeric($amount) && $amount != 0) {
257 $contrib =
new Tva($this->db);
258 $contrib->fetch($contribid);
259 $paiement = $contrib->getSommePaiement();
264 $alreadypayed = (float)
price2num($paiement + $creditnotes + $deposits,
'MT');
265 $remaintopay = (float)
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
266 if ($remaintopay == 0) {
267 $result = $contrib->setPaid($user);
269 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
279 $result = $this->
call_trigger(
'PAYMENTVAT_CREATE', $user);
284 if ($totalamount != 0 && !$error) {
285 $this->amount = $totalamount;
286 $this->total = $totalamount;
290 $this->error = $this->db->error();
291 $this->db->rollback();
306 $sql .=
" t.fk_tva,";
310 $sql .=
" t.amount,";
311 $sql .=
" t.fk_typepaiement,";
312 $sql .=
" t.num_paiement as num_payment,";
313 $sql .=
" t.note as note_private,";
314 $sql .=
" t.fk_bank,";
315 $sql .=
" t.fk_user_creat,";
316 $sql .=
" t.fk_user_modif,";
317 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
318 $sql .=
' b.fk_account';
319 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_vat as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
320 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
321 $sql .=
" WHERE t.rowid = ".((int) $id);
324 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
325 $resql = $this->db->query($sql);
327 if ($this->db->num_rows($resql)) {
328 $obj = $this->db->fetch_object($resql);
330 $this->
id = $obj->rowid;
331 $this->
ref = $obj->rowid;
333 $this->fk_tva = $obj->fk_tva;
334 $this->datec = $this->db->jdate($obj->datec);
335 $this->tms = $this->db->jdate($obj->tms);
336 $this->datep = $this->db->jdate($obj->datep);
337 $this->amount = $obj->amount;
338 $this->fk_typepaiement = $obj->fk_typepaiement;
339 $this->num_paiement = $obj->num_payment;
340 $this->num_payment = $obj->num_payment;
341 $this->note = $obj->note_private;
342 $this->note_private = $obj->note_private;
343 $this->fk_bank = $obj->fk_bank;
344 $this->fk_user_creat = $obj->fk_user_creat;
345 $this->fk_user_modif = $obj->fk_user_modif;
347 $this->type_code = $obj->type_code;
348 $this->type_label = $obj->type_label;
350 $this->bank_account = $obj->fk_account;
351 $this->bank_line = $obj->fk_bank;
353 $this->db->free($resql);
357 $this->error =
"Error ".$this->db->lasterror();
370 public function update($user =
null, $notrigger = 0)
372 global $conf, $langs;
377 if (isset($this->fk_tva)) {
378 $this->fk_tva = (int) $this->fk_tva;
380 if (isset($this->amount)) {
381 $this->amount = (float) $this->amount;
383 if (isset($this->fk_typepaiement)) {
384 $this->fk_typepaiement = (int) $this->fk_typepaiement;
386 if (isset($this->num_payment)) {
387 $this->num_payment = trim($this->num_payment);
389 if (isset($this->note)) {
390 $this->note = trim($this->note);
392 if (isset($this->fk_bank)) {
393 $this->fk_bank = (int) $this->fk_bank;
395 if (isset($this->fk_user_creat)) {
396 $this->fk_user_creat = (int) $this->fk_user_creat;
398 if (isset($this->fk_user_modif)) {
399 $this->fk_user_modif = (int) $this->fk_user_modif;
406 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET";
407 $sql .=
" fk_tva=".(isset($this->fk_tva) ? ((int) $this->fk_tva) :
"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').
",";
411 $sql .=
" amount=".(isset($this->amount) ? (float)
price2num($this->amount) :
"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();
431 foreach ($this->errors as $errmsg) {
432 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
433 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
435 $this->db->rollback();
451 public function delete($user, $notrigger = 0)
459 if ($this->bank_line > 0) {
461 $accline->fetch($this->bank_line);
462 $result = $accline->delete($user);
464 $this->errors[] = $accline->error;
470 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_vat";
471 $sql .=
" WHERE rowid=".((int) $this->
id);
473 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
474 $resql = $this->db->query($sql);
477 $this->errors[] =
"Error ".$this->db->lasterror();
483 foreach ($this->errors as $errmsg) {
484 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
485 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
487 $this->db->rollback();
520 $object->context[
'createfromclone'] =
'createfromclone';
521 $result =
$object->create($user);
529 unset(
$object->context[
'createfromclone']);
536 $this->db->rollback();
557 $this->fk_typepaiement = 0;
558 $this->num_payment =
'123456';
559 $this->note_private =
'Private note';
560 $this->note_public =
'Public note';
562 $this->fk_user_creat = 0;
563 $this->fk_user_modif = 0;
581 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
584 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
588 if (isModEnabled(
"bank")) {
589 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
592 $acc->fetch($accountid);
594 $total = $this->amount;
595 if ($mode ==
'payment_vat') {
600 $bank_line_id = $acc->addline(
614 if ($bank_line_id > 0) {
623 if ($mode ==
'payment_vat') {
624 $url = DOL_URL_ROOT.
'/compta/payment_vat/card.php?id=';
627 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
635 $linkaddedforthirdparty = array();
636 foreach ($this->amounts as $key => $value) {
637 if ($mode ==
'payment_vat') {
638 $tva =
new Tva($this->db);
640 $result = $acc->add_url_line($bank_line_id, $tva->id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
'('.$tva->label.
')',
'vat');
647 $this->error = $acc->error;
670 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
672 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
673 $result = $this->db->query($sql);
677 $this->error = $this->db->error();
691 return $this->
LibStatut($this->statut, $mode);
707 $langs->load(
'compta');
759 if (empty($this->
ref)) {
760 $this->
ref = $this->lib;
763 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"VATPayment").
'</u>';
764 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
765 if (!empty($this->label)) {
766 $labeltoshow = $this->label;
768 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
770 if ($reg[1] ==
'paiement') {
773 $labeltoshow = $langs->trans($reg[1]);
775 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
778 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
781 if (!empty($this->
id)) {
782 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_vat/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
786 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
788 if ($withpicto && $withpicto != 2) {
791 if ($withpicto != 2) {
792 $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.
Class to manage VAT - Value-added tax (also known in French as TVA - Taxe sur la valeur ajoutée)
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...