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).
"', ".$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 $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();
521 $object->context[
'createfromclone'] =
'createfromclone';
522 $result =
$object->create($user);
530 unset(
$object->context[
'createfromclone']);
537 $this->db->rollback();
558 $this->fk_typepaiement = 0;
559 $this->num_payment =
'123456';
560 $this->note_private =
'Private note';
561 $this->note_public =
'Public note';
563 $this->fk_user_creat = 0;
564 $this->fk_user_modif = 0;
582 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
585 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
590 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
593 $acc->fetch($accountid);
595 $total = $this->amount;
596 if ($mode ==
'payment_vat') {
601 $bank_line_id = $acc->addline(
615 if ($bank_line_id > 0) {
624 if ($mode ==
'payment_vat') {
625 $url = DOL_URL_ROOT.
'/compta/payment_vat/card.php?id=';
628 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
636 $linkaddedforthirdparty = array();
637 foreach ($this->amounts as $key => $value) {
638 if ($mode ==
'payment_vat') {
639 $tva =
new Tva($this->db);
641 $result = $acc->add_url_line($bank_line_id, $tva->id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
'('.$tva->label.
')',
'vat');
648 $this->error = $acc->error;
671 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
673 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
674 $result = $this->db->query($sql);
678 $this->error = $this->db->error();
692 return $this->
LibStatut($this->statut, $mode);
708 $langs->load(
'compta');
760 if (empty($this->
ref)) {
761 $this->
ref = $this->lib;
764 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"VATPayment").
'</u>';
765 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
766 if (!empty($this->label)) {
767 $labeltoshow = $this->label;
769 if (preg_match(
'/^\((.*)\)$/i', $this->label, $reg)) {
771 if ($reg[1] ==
'paiement') {
774 $labeltoshow = $langs->trans($reg[1]);
776 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
779 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
782 if (!empty($this->
id)) {
783 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_vat/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
787 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
789 if ($withpicto && $withpicto != 2) {
792 if ($withpicto != 2) {
793 $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.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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.
dol_now($mode='gmt')
Return date for now.
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)
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_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.
isModEnabled($module)
Is Dolibarr module enabled.
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...
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount