26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
27require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
38 public $element =
'payment_vat';
43 public $table_element =
'payment_vat';
48 public $picto =
'payment';
66 public $amounts = array();
71 public $fk_typepaiement;
92 public $fk_user_creat;
97 public $fk_user_modif;
119 public $paiementtype;
139 public function create($user, $closepaidcontrib = 0)
141 global $conf, $langs;
147 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
150 if (!$this->datepaye) {
151 $this->error =
'ErrorBadValueForParameterCreatePaymentVAT';
156 if (isset($this->fk_tva)) {
157 $this->fk_tva = (int) $this->fk_tva;
159 if (isset($this->amount)) {
160 $this->amount = trim($this->amount);
162 if (isset($this->fk_typepaiement)) {
163 $this->fk_typepaiement = (int) $this->fk_typepaiement;
165 if (isset($this->num_paiement)) {
166 $this->num_paiement = trim($this->num_paiement);
168 if (isset($this->num_payment)) {
169 $this->num_payment = trim($this->num_payment);
171 if (isset($this->note)) {
172 $this->note = trim($this->note);
174 if (isset($this->fk_bank)) {
175 $this->fk_bank = (int) $this->fk_bank;
177 if (isset($this->fk_user_creat)) {
178 $this->fk_user_creat = (int) $this->fk_user_creat;
180 if (isset($this->fk_user_modif)) {
181 $this->fk_user_modif = (int) $this->fk_user_modif;
185 foreach ($this->amounts as $key => $value) {
187 $this->amounts[$key] = $newvalue;
188 $totalamount += $newvalue;
193 if ($totalamount == 0) {
200 if ($totalamount != 0) {
201 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_vat (fk_tva, datec, datep, amount,";
202 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
203 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
204 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
205 $sql .=
" ".((float) $totalamount).
",";
206 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".$user->id.
",";
209 $resql = $this->db->query($sql);
211 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_vat");
214 foreach ($this->amounts as $key => $amount) {
216 if (is_numeric($amount) && $amount <> 0) {
220 if ($closepaidcontrib) {
221 $contrib =
new Tva($this->db);
222 $contrib->fetch($contribid);
223 $paiement = $contrib->getSommePaiement();
228 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
229 $remaintopay =
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
230 if ($remaintopay == 0) {
231 $result = $contrib->setPaid($user);
233 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
243 $result = $this->
call_trigger(
'PAYMENTVAT_CREATE', $user);
248 if ($totalamount != 0 && !$error) {
249 $this->amount = $totalamount;
250 $this->total = $totalamount;
254 $this->error = $this->db->error();
255 $this->db->rollback();
270 $sql .=
" t.fk_tva,";
274 $sql .=
" t.amount,";
275 $sql .=
" t.fk_typepaiement,";
276 $sql .=
" t.num_paiement as num_payment,";
277 $sql .=
" t.note as note_private,";
278 $sql .=
" t.fk_bank,";
279 $sql .=
" t.fk_user_creat,";
280 $sql .=
" t.fk_user_modif,";
281 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
282 $sql .=
' b.fk_account';
283 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_vat as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
284 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
285 $sql .=
" WHERE t.rowid = ".((int) $id);
288 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
289 $resql = $this->db->query($sql);
291 if ($this->db->num_rows($resql)) {
292 $obj = $this->db->fetch_object($resql);
294 $this->
id = $obj->rowid;
295 $this->
ref = $obj->rowid;
297 $this->fk_tva = $obj->fk_tva;
298 $this->datec = $this->db->jdate($obj->datec);
299 $this->tms = $this->db->jdate($obj->tms);
300 $this->datep = $this->db->jdate($obj->datep);
301 $this->amount = $obj->amount;
302 $this->fk_typepaiement = $obj->fk_typepaiement;
303 $this->num_paiement = $obj->num_payment;
304 $this->num_payment = $obj->num_payment;
305 $this->note = $obj->note_private;
306 $this->note_private = $obj->note_private;
307 $this->fk_bank = $obj->fk_bank;
308 $this->fk_user_creat = $obj->fk_user_creat;
309 $this->fk_user_modif = $obj->fk_user_modif;
311 $this->type_code = $obj->type_code;
312 $this->type_label = $obj->type_label;
314 $this->bank_account = $obj->fk_account;
315 $this->bank_line = $obj->fk_bank;
317 $this->db->free($resql);
321 $this->error =
"Error ".$this->db->lasterror();
334 public function update($user =
null, $notrigger = 0)
336 global $conf, $langs;
341 if (isset($this->fk_tva)) {
342 $this->fk_tva = (int) $this->fk_tva;
344 if (isset($this->amount)) {
345 $this->amount = trim($this->amount);
347 if (isset($this->fk_typepaiement)) {
348 $this->fk_typepaiement = (int) $this->fk_typepaiement;
350 if (isset($this->num_paiement)) {
351 $this->num_paiement = trim($this->num_paiement);
353 if (isset($this->num_payment)) {
354 $this->num_payment = trim($this->num_payment);
356 if (isset($this->note)) {
357 $this->note = trim($this->note);
359 if (isset($this->fk_bank)) {
360 $this->fk_bank = (int) $this->fk_bank;
362 if (isset($this->fk_user_creat)) {
363 $this->fk_user_creat = (int) $this->fk_user_creat;
365 if (isset($this->fk_user_modif)) {
366 $this->fk_user_modif = (int) $this->fk_user_modif;
373 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET";
374 $sql .=
" fk_tva=".(isset($this->fk_tva) ? ((int) $this->fk_tva) :
"null").
",";
375 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
376 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
377 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
378 $sql .=
" amount=".(isset($this->amount) ? (float)
price2num($this->amount) :
"null").
",";
379 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) :
"null").
",";
380 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
381 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
382 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
383 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
384 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
385 $sql .=
" WHERE rowid=".((int) $this->
id);
389 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
390 $resql = $this->db->query($sql);
393 $this->errors[] =
"Error ".$this->db->lasterror();
398 foreach ($this->errors as $errmsg) {
399 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
400 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
402 $this->db->rollback();
418 public function delete($user, $notrigger = 0)
420 global $conf, $langs;
427 if ($this->bank_line > 0) {
429 $accline->fetch($this->bank_line);
430 $result = $accline->delete();
432 $this->errors[] = $accline->error;
438 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_vat";
439 $sql .=
" WHERE rowid=".((int) $this->
id);
441 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
442 $resql = $this->db->query($sql);
445 $this->errors[] =
"Error ".$this->db->lasterror();
451 foreach ($this->errors as $errmsg) {
452 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
453 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
455 $this->db->rollback();
481 $object->fetch($fromid);
489 $object->context[
'createfromclone'] =
'createfromclone';
490 $result = $object->create($user);
494 $this->error = $object->error;
498 unset($object->context[
'createfromclone']);
505 $this->db->rollback();
527 $this->fk_typepaiement =
'';
528 $this->num_payment =
'';
529 $this->note_private =
'';
530 $this->note_public =
'';
532 $this->fk_user_creat = 0;
533 $this->fk_user_modif = 0;
549 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
554 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
558 if (isModEnabled(
"banque")) {
559 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
562 $acc->fetch($accountid);
565 if ($mode ==
'payment_vat') {
570 $bank_line_id = $acc->addline(
584 if ($bank_line_id > 0) {
593 if ($mode ==
'payment_vat') {
594 $url = DOL_URL_ROOT.
'/compta/payment_vat/card.php?id=';
597 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
605 $linkaddedforthirdparty = array();
606 foreach ($this->amounts as $key => $value) {
607 if ($mode ==
'payment_vat') {
608 $tva =
new Tva($this->db);
610 $result = $acc->add_url_line($bank_line_id, $tva->id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
'('.$tva->label.
')',
'vat');
617 $this->error = $acc->error;
640 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
642 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
643 $result = $this->db->query($sql);
647 $this->error = $this->db->error();
677 $langs->load(
'compta');
729 if (empty($this->
ref)) {
730 $this->
ref = $this->lib;
733 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"VATPayment").
'</u>';
734 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
735 if (!empty($this->label)) {
736 $labeltoshow = $this->label;
738 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
740 if ($reg[1] ==
'paiement') {
743 $labeltoshow = $langs->trans($reg[1]);
745 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
748 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
751 if (!empty($this->
id)) {
752 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_vat/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
756 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
758 if ($withpicto && $withpicto != 2) {
761 if ($withpicto != 2) {
762 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
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.
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.
__construct($db)
Constructor.
update_fk_bank($id_bank)
Mise a jour du lien entre le paiement de tva et la ligne dans llx_bank generee.
fetch($id)
Load object in memory from database.
create($user, $closepaidcontrib=0)
Create payment of social contribution into database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
getLibStatut($mode=0)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
getNomUrl($withpicto=0, $maxlen=0)
Return clicable 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.
print $langs trans("Ref").' m m m statut
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.
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...