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;
129 public $bank_account;
139 public $paiementtype;
159 public function create($user, $closepaidvat = 0)
161 global $conf, $langs;
167 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
170 if (!$this->datepaye) {
171 $this->error =
'ErrorBadValueForParameterCreatePaymentVAT';
176 if (isset($this->fk_tva)) {
177 $this->fk_tva = (int) $this->fk_tva;
179 if (isset($this->amount)) {
180 $this->amount = trim($this->amount);
182 if (isset($this->fk_typepaiement)) {
183 $this->fk_typepaiement = (int) $this->fk_typepaiement;
185 if (isset($this->num_paiement)) {
186 $this->num_paiement = trim($this->num_paiement);
188 if (isset($this->num_payment)) {
189 $this->num_payment = trim($this->num_payment);
191 if (isset($this->note)) {
192 $this->note = trim($this->note);
194 if (isset($this->fk_bank)) {
195 $this->fk_bank = (int) $this->fk_bank;
197 if (isset($this->fk_user_creat)) {
198 $this->fk_user_creat = (int) $this->fk_user_creat;
200 if (isset($this->fk_user_modif)) {
201 $this->fk_user_modif = (int) $this->fk_user_modif;
205 foreach ($this->amounts as $key => $value) {
207 $this->amounts[$key] = $newvalue;
208 $totalamount += $newvalue;
213 if ($totalamount == 0) {
220 if ($totalamount != 0) {
221 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_vat (fk_tva, datec, datep, amount,";
222 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
223 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
224 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
225 $sql .=
" ".((float) $totalamount).
",";
226 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".$user->id.
",";
229 $resql = $this->db->query($sql);
231 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_vat");
234 foreach ($this->amounts as $key => $amount) {
236 if (is_numeric($amount) && $amount != 0) {
241 $contrib =
new Tva($this->db);
242 $contrib->fetch($contribid);
243 $paiement = $contrib->getSommePaiement();
248 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
249 $remaintopay =
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
250 if ($remaintopay == 0) {
251 $result = $contrib->setPaid($user);
253 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
263 $result = $this->
call_trigger(
'PAYMENTVAT_CREATE', $user);
268 if ($totalamount != 0 && !$error) {
269 $this->amount = $totalamount;
270 $this->total = $totalamount;
274 $this->error = $this->db->error();
275 $this->db->rollback();
290 $sql .=
" t.fk_tva,";
294 $sql .=
" t.amount,";
295 $sql .=
" t.fk_typepaiement,";
296 $sql .=
" t.num_paiement as num_payment,";
297 $sql .=
" t.note as note_private,";
298 $sql .=
" t.fk_bank,";
299 $sql .=
" t.fk_user_creat,";
300 $sql .=
" t.fk_user_modif,";
301 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
302 $sql .=
' b.fk_account';
303 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_vat as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
304 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
305 $sql .=
" WHERE t.rowid = ".((int) $id);
308 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
309 $resql = $this->db->query($sql);
311 if ($this->db->num_rows($resql)) {
312 $obj = $this->db->fetch_object($resql);
314 $this->
id = $obj->rowid;
315 $this->
ref = $obj->rowid;
317 $this->fk_tva = $obj->fk_tva;
318 $this->datec = $this->db->jdate($obj->datec);
319 $this->tms = $this->db->jdate($obj->tms);
320 $this->datep = $this->db->jdate($obj->datep);
321 $this->amount = $obj->amount;
322 $this->fk_typepaiement = $obj->fk_typepaiement;
323 $this->num_paiement = $obj->num_payment;
324 $this->num_payment = $obj->num_payment;
325 $this->note = $obj->note_private;
326 $this->note_private = $obj->note_private;
327 $this->fk_bank = $obj->fk_bank;
328 $this->fk_user_creat = $obj->fk_user_creat;
329 $this->fk_user_modif = $obj->fk_user_modif;
331 $this->type_code = $obj->type_code;
332 $this->type_label = $obj->type_label;
334 $this->bank_account = $obj->fk_account;
335 $this->bank_line = $obj->fk_bank;
337 $this->db->free($resql);
341 $this->error =
"Error ".$this->db->lasterror();
354 public function update($user =
null, $notrigger = 0)
356 global $conf, $langs;
361 if (isset($this->fk_tva)) {
362 $this->fk_tva = (int) $this->fk_tva;
364 if (isset($this->amount)) {
365 $this->amount = trim($this->amount);
367 if (isset($this->fk_typepaiement)) {
368 $this->fk_typepaiement = (int) $this->fk_typepaiement;
370 if (isset($this->num_payment)) {
371 $this->num_payment = trim($this->num_payment);
373 if (isset($this->note)) {
374 $this->note = trim($this->note);
376 if (isset($this->fk_bank)) {
377 $this->fk_bank = (int) $this->fk_bank;
379 if (isset($this->fk_user_creat)) {
380 $this->fk_user_creat = (int) $this->fk_user_creat;
382 if (isset($this->fk_user_modif)) {
383 $this->fk_user_modif = (int) $this->fk_user_modif;
390 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET";
391 $sql .=
" fk_tva=".(isset($this->fk_tva) ? ((int) $this->fk_tva) :
"null").
",";
392 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
393 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
394 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
395 $sql .=
" amount=".(isset($this->amount) ? (float)
price2num($this->amount) :
"null").
",";
396 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) :
"null").
",";
397 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
398 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
399 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
400 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
401 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
402 $sql .=
" WHERE rowid=".((int) $this->
id);
406 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
407 $resql = $this->db->query($sql);
410 $this->errors[] =
"Error ".$this->db->lasterror();
415 foreach ($this->errors as $errmsg) {
416 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
417 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
419 $this->db->rollback();
435 public function delete($user, $notrigger = 0)
443 if ($this->bank_line > 0) {
445 $accline->fetch($this->bank_line);
446 $result = $accline->delete($user);
448 $this->errors[] = $accline->error;
454 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_vat";
455 $sql .=
" WHERE rowid=".((int) $this->
id);
457 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
458 $resql = $this->db->query($sql);
461 $this->errors[] =
"Error ".$this->db->lasterror();
467 foreach ($this->errors as $errmsg) {
468 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
469 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
471 $this->db->rollback();
497 $object->fetch($fromid);
504 $object->context[
'createfromclone'] =
'createfromclone';
505 $result = $object->create($user);
509 $this->error = $object->error;
513 unset($object->context[
'createfromclone']);
520 $this->db->rollback();
542 $this->fk_typepaiement =
'';
543 $this->num_payment =
'';
544 $this->note_private =
'';
545 $this->note_public =
'';
547 $this->fk_user_creat = 0;
548 $this->fk_user_modif = 0;
564 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
567 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
571 if (isModEnabled(
"banque")) {
572 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
575 $acc->fetch($accountid);
578 if ($mode ==
'payment_vat') {
583 $bank_line_id = $acc->addline(
597 if ($bank_line_id > 0) {
606 if ($mode ==
'payment_vat') {
607 $url = DOL_URL_ROOT.
'/compta/payment_vat/card.php?id=';
610 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
618 $linkaddedforthirdparty = array();
619 foreach ($this->amounts as $key => $value) {
620 if ($mode ==
'payment_vat') {
621 $tva =
new Tva($this->db);
623 $result = $acc->add_url_line($bank_line_id, $tva->id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
'('.$tva->label.
')',
'vat');
630 $this->error = $acc->error;
653 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
655 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
656 $result = $this->db->query($sql);
660 $this->error = $this->db->error();
690 $langs->load(
'compta');
742 if (empty($this->
ref)) {
743 $this->
ref = $this->lib;
746 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"VATPayment").
'</u>';
747 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
748 if (!empty($this->label)) {
749 $labeltoshow = $this->label;
751 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
753 if ($reg[1] ==
'paiement') {
756 $labeltoshow = $langs->trans($reg[1]);
758 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
761 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
764 if (!empty($this->
id)) {
765 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_vat/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
769 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
771 if ($withpicto && $withpicto != 2) {
774 if ($withpicto != 2) {
775 $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.
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.
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...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut