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;
140 public $bank_account;
150 public $paiementtype;
170 public function create($user, $closepaidvat = 0)
176 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
179 if (!$this->datepaye) {
180 $this->error =
'ErrorBadValueForParameterCreatePaymentVAT';
185 if (isset($this->fk_tva)) {
186 $this->fk_tva = (int) $this->fk_tva;
188 if (isset($this->
amount)) {
191 if (isset($this->fk_typepaiement)) {
192 $this->fk_typepaiement = (int) $this->fk_typepaiement;
194 if (isset($this->num_paiement)) {
195 $this->num_paiement = trim($this->num_paiement);
197 if (isset($this->num_payment)) {
198 $this->num_payment = trim($this->num_payment);
200 if (isset($this->note)) {
201 $this->note = trim($this->note);
203 if (isset($this->fk_bank)) {
204 $this->fk_bank = (int) $this->fk_bank;
206 if (isset($this->fk_user_creat)) {
207 $this->fk_user_creat = (int) $this->fk_user_creat;
209 if (isset($this->fk_user_modif)) {
210 $this->fk_user_modif = (int) $this->fk_user_modif;
214 foreach ($this->amounts as $key => $value) {
215 $newvalue = (float)
price2num($value,
'MT');
216 $this->amounts[$key] = $newvalue;
217 $totalamount += $newvalue;
222 if ($totalamount == 0) {
229 if ($totalamount != 0) {
230 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_vat (fk_tva, datec, datep, amount,";
231 $sql .=
" fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
232 $sql .=
" VALUES (".((int) $this->chid).
", '".$this->db->idate($now).
"',";
233 $sql .=
" '".$this->db->idate($this->datepaye).
"',";
234 $sql .=
" ".((float) $totalamount).
",";
235 $sql .=
" ".((int) $this->paiementtype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note).
"', ".((int) $user->id).
",";
238 $resql = $this->db->query($sql);
240 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_vat");
243 foreach ($this->amounts as $key => $amount) {
245 if (is_numeric($amount) && $amount != 0) {
250 $contrib =
new Tva($this->db);
251 $contrib->fetch($contribid);
252 $paiement = $contrib->getSommePaiement();
257 $alreadypayed = (float)
price2num($paiement + $creditnotes + $deposits,
'MT');
258 $remaintopay = (float)
price2num($contrib->amount - $paiement - $creditnotes - $deposits,
'MT');
259 if ($remaintopay == 0) {
260 $result = $contrib->setPaid($user);
262 dol_syslog(
"Remain to pay for conrib ".$contribid.
" not null. We do nothing.");
272 $result = $this->call_trigger(
'PAYMENTVAT_CREATE', $user);
277 if ($totalamount != 0 && !$error) {
278 $this->
amount = $totalamount;
279 $this->total = $totalamount;
283 $this->error = $this->db->error();
284 $this->db->rollback();
299 $sql .=
" t.fk_tva,";
303 $sql .=
" t.amount,";
304 $sql .=
" t.fk_typepaiement,";
305 $sql .=
" t.num_paiement as num_payment,";
306 $sql .=
" t.note as note_private,";
307 $sql .=
" t.fk_bank,";
308 $sql .=
" t.fk_user_creat,";
309 $sql .=
" t.fk_user_modif,";
310 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
311 $sql .=
' b.fk_account';
312 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_vat as t LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepaiement = pt.id";
313 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
314 $sql .=
" WHERE t.rowid = ".((int) $id);
317 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
318 $resql = $this->db->query($sql);
320 if ($this->db->num_rows($resql)) {
321 $obj = $this->db->fetch_object($resql);
323 $this->
id = $obj->rowid;
324 $this->
ref = $obj->rowid;
326 $this->fk_tva = $obj->fk_tva;
327 $this->datec = $this->db->jdate($obj->datec);
328 $this->tms = $this->db->jdate($obj->tms);
329 $this->datep = $this->db->jdate($obj->datep);
330 $this->
amount = $obj->amount;
331 $this->fk_typepaiement = $obj->fk_typepaiement;
332 $this->num_paiement = $obj->num_payment;
333 $this->num_payment = $obj->num_payment;
334 $this->note = $obj->note_private;
335 $this->note_private = $obj->note_private;
336 $this->fk_bank = $obj->fk_bank;
337 $this->fk_user_creat = $obj->fk_user_creat;
338 $this->fk_user_modif = $obj->fk_user_modif;
340 $this->type_code = $obj->type_code;
341 $this->type_label = $obj->type_label;
343 $this->bank_account = $obj->fk_account;
344 $this->bank_line = $obj->fk_bank;
346 $this->db->free($resql);
350 $this->error =
"Error ".$this->db->lasterror();
363 public function update($user =
null, $notrigger = 0)
369 if (isset($this->fk_tva)) {
370 $this->fk_tva = (int) $this->fk_tva;
372 if (isset($this->
amount)) {
375 if (isset($this->fk_typepaiement)) {
376 $this->fk_typepaiement = (int) $this->fk_typepaiement;
378 if (isset($this->num_payment)) {
379 $this->num_payment = trim($this->num_payment);
381 if (isset($this->note)) {
382 $this->note = trim($this->note);
384 if (isset($this->fk_bank)) {
385 $this->fk_bank = (int) $this->fk_bank;
387 if (isset($this->fk_user_creat)) {
388 $this->fk_user_creat = (int) $this->fk_user_creat;
390 if (isset($this->fk_user_modif)) {
391 $this->fk_user_modif = (int) $this->fk_user_modif;
398 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET";
399 $sql .=
" fk_tva=".(isset($this->fk_tva) ? ((int) $this->fk_tva) :
"null").
",";
400 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
401 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
402 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
404 $sql .=
" fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) :
"null").
",";
405 $sql .=
" num_paiement=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
406 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
407 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
408 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
409 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
410 $sql .=
" WHERE rowid=".((int) $this->
id);
414 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
415 $resql = $this->db->query($sql);
418 $this->errors[] =
"Error ".$this->db->lasterror();
421 if (!$error && $user && !$notrigger) {
423 $result = $this->call_trigger(
'PAYMENTVAT_MODIFY', $user);
432 foreach ($this->errors as $errmsg) {
433 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
434 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
436 $this->db->rollback();
452 public function delete($user, $notrigger = 0)
460 if ($this->bank_line > 0) {
462 $result = $accline->fetch($this->bank_line);
464 $result = $accline->delete($user);
466 $this->errors[] = $accline->error;
473 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_vat";
474 $sql .=
" WHERE rowid=".((int) $this->
id);
476 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
477 $resql = $this->db->query($sql);
480 $this->errors[] =
"Error ".$this->db->lasterror();
484 if (!$error && !$notrigger) {
486 $result = $this->call_trigger(
'PAYMENTVAT_DELETE', $user);
495 foreach ($this->errors as $errmsg) {
496 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
497 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
499 $this->db->rollback();
533 $object->context[
'createfromclone'] =
'createfromclone';
534 $result =
$object->create($user);
542 unset(
$object->context[
'createfromclone']);
549 $this->db->rollback();
570 $this->fk_typepaiement = 0;
571 $this->num_payment =
'123456';
572 $this->note_private =
'Private note';
573 $this->note_public =
'Public note';
575 $this->fk_user_creat = 0;
576 $this->fk_user_modif = 0;
594 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
597 $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
602 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
605 $acc->fetch($accountid);
607 $total = $this->amount;
608 if ($mode ==
'payment_vat') {
613 $bank_line_id = $acc->addline(
627 if ($bank_line_id > 0) {
631 dol_print_error($this->db);
636 if ($mode ==
'payment_vat') {
637 $url = DOL_URL_ROOT.
'/compta/payment_vat/card.php?id=';
640 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
643 dol_print_error($this->db);
648 $linkaddedforthirdparty = array();
649 foreach ($this->amounts as $key => $value) {
650 if ($mode ==
'payment_vat') {
651 $tva =
new Tva($this->db);
653 $result = $acc->add_url_line($bank_line_id, $tva->id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
'('.$tva->label.
')',
'vat');
655 dol_print_error($this->db);
660 $this->error = $acc->error;
683 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_vat SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
685 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
686 $result = $this->db->query($sql);
690 $this->error = $this->db->error();
704 return $this->
LibStatut($this->statut, $mode);
720 $langs->load(
'compta');
772 $label = img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"VATPayment").
'</u>';
773 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
775 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'day');
778 if (!empty($this->
id)) {
779 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/payment_vat/card.php?id='.$this->
id.
'" title="'.dolPrintHTMLForAttribute($label).
'" class="classfortooltip">';
783 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
785 if ($withpicto && $withpicto != 2) {
788 if ($withpicto != 2) {
789 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
793 global $action, $hookmanager;
794 $hookmanager->initHooks(array($this->element .
'dao'));
795 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
796 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
798 $result = $hookmanager->resPrint;
800 $result .= $hookmanager->resPrint;
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.
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