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)) {
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 (".((int) $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).
"', ".((int) $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)) {
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').
",";
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 $result = $accline->fetch($this->bank_line);
463 $result = $accline->delete($user);
465 $this->errors[] = $accline->error;
472 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_vat";
473 $sql .=
" WHERE rowid=".((int) $this->
id);
475 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
476 $resql = $this->db->query($sql);
479 $this->errors[] =
"Error ".$this->db->lasterror();
485 foreach ($this->errors as $errmsg) {
486 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
487 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
489 $this->db->rollback();
523 $object->context[
'createfromclone'] =
'createfromclone';
524 $result =
$object->create($user);
532 unset(
$object->context[
'createfromclone']);
539 $this->db->rollback();
560 $this->fk_typepaiement = 0;
561 $this->num_payment =
'123456';
562 $this->note_private =
'Private note';
563 $this->note_public =
'Public note';
565 $this->fk_user_creat = 0;
566 $this->fk_user_modif = 0;
584 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
587 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
592 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
595 $acc->fetch($accountid);
597 $total = $this->amount;
598 if ($mode ==
'payment_vat') {
603 $bank_line_id = $acc->addline(
617 if ($bank_line_id > 0) {
626 if ($mode ==
'payment_vat') {
627 $url = DOL_URL_ROOT.
'/compta/payment_vat/card.php?id=';
630 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
638 $linkaddedforthirdparty = array();
639 foreach ($this->amounts as $key => $value) {
640 if ($mode ==
'payment_vat') {
641 $tva =
new Tva($this->db);
643 $result = $acc->add_url_line($bank_line_id, $tva->id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
'('.$tva->label.
')',
'vat');
650 $this->error = $acc->error;
673 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
675 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
676 $result = $this->db->query($sql);
680 $this->error = $this->db->error();
694 return $this->
LibStatut($this->statut, $mode);
710 $langs->load(
'compta');
762 if (empty($this->
ref)) {
763 $this->
ref = $this->lib;
766 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"VATPayment").
'</u>';
767 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
768 if (!empty($this->label)) {
769 $labeltoshow = $this->label;
771 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
773 if ($reg[1] ==
'paiement') {
776 $labeltoshow = $langs->trans($reg[1]);
778 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
781 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
784 if (!empty($this->
id)) {
785 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_vat/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
789 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
791 if ($withpicto && $withpicto != 2) {
794 if ($withpicto != 2) {
795 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
if(! $sortfield) if(! $sortorder) $object
Class to manage bank accounts.
Class to manage bank transaction lines.
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)
Class to manage Dolibarr users.
dol_now($mode='gmt')
Return date for now.
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.
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)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
print $langs trans('Date')." left Ref 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 Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount