dolibarr 24.0.0-beta
paiementfourn.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
8 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
9 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
11 * Copyright (C) 2023 Sylvain Legrand <technique@infras.fr>
12 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
33require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
35require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
36
41{
45 public $element = 'payment_supplier';
46
50 public $table_element = 'paiementfourn';
51
55 public $picto = 'payment';
56
60 public $statut;
61 // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
62 // fk_paiement dans llx_paiement_facture is rowid of payment
63
68 public $type_label;
69
74 public $type_code;
75
79 public $id_prelevement;
80
84 public $num_prelevement;
85
86
92 public function __construct($db)
93 {
94 $this->db = $db;
95 }
96
105 public function fetch($id, $ref = '', $fk_bank = 0)
106 {
107 $error = 0;
108
109 $sql = 'SELECT p.rowid, p.ref, p.entity, p.datep as dp, p.amount, p.statut, p.fk_bank, p.multicurrency_amount,';
110 $sql .= ' c.code as payment_code, c.libelle as payment_type,';
111 $sql .= ' p.num_paiement as num_payment, p.note, b.fk_account, p.fk_paiement';
112 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p';
113 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
114 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
115 $sql .= ' WHERE p.entity IN ('.getEntity('facture_fourn').')';
116 if ($id > 0) {
117 $sql .= ' AND p.rowid = '.((int) $id);
118 } elseif ($ref) {
119 $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
120 } elseif ($fk_bank > 0) {
121 $sql .= ' AND p.fk_bank = '.((int) $fk_bank);
122 }
123 //print $sql;
124
125 $resql = $this->db->query($sql);
126 if ($resql) {
127 $num = $this->db->num_rows($resql);
128 if ($num > 0) {
129 $obj = $this->db->fetch_object($resql);
130
131 $this->id = $obj->rowid;
132 $this->ref = $obj->ref;
133 $this->entity = $obj->entity;
134 $this->date = $this->db->jdate($obj->dp);
135 $this->datepaye = $this->db->jdate($obj->dp);
136 $this->num_payment = $obj->num_payment;
137 $this->bank_account = $obj->fk_account;
138 $this->fk_account = $obj->fk_account;
139 $this->bank_line = $obj->fk_bank;
140 $this->montant = $obj->amount; // deprecated
141 $this->amount = $obj->amount;
142 $this->multicurrency_amount = $obj->multicurrency_amount;
143 $this->note = $obj->note;
144 $this->note_private = $obj->note;
145 $this->type_code = $obj->payment_code;
146 $this->type_label = $obj->payment_type;
147 $this->fk_paiement = $obj->fk_paiement;
148 $this->statut = $obj->statut;
149
150 $error = 1;
151 } else {
152 $error = -2; // TODO Use 0 instead
153 }
154 $this->db->free($resql);
155 } else {
156 dol_print_error($this->db);
157 $error = -1;
158 }
159 return $error;
160 }
161
170 public function create($user, $closepaidinvoices = 0, $thirdparty = null)
171 {
172 global $langs, $conf;
173
174 $error = 0;
175 $way = $this->getWay();
176
177 $now = dol_now();
178
179 // Clean parameters
180 $totalamount = 0;
181 $totalamount_converted = 0;
182 $atleastonepaymentnotnull = 0;
183
184 if ($way == 'dolibarr') {
185 $amounts = &$this->amounts;
186 $amounts_to_update = &$this->multicurrency_amounts;
187 } else {
188 $amounts = &$this->multicurrency_amounts;
189 $amounts_to_update = &$this->amounts;
190 }
191
192 $currencyofpayment = '';
193 $currencytxofpayment = '';
194
195 foreach ($amounts as $key => $value) {
196 if (empty($value)) {
197 continue;
198 }
199 // $key is id of invoice, $value is amount, $way is a 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
200 $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate((int) $key, $value ? $value : 0, $way, 'facture_fourn');
201 // Add controls of input validity
202 if ($value_converted === false) {
203 // We failed to find the conversion for one invoice
204 $this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
205 return -1;
206 }
207 if (empty($currencyofpayment)) {
208 $currencyofpayment = $this->multicurrency_code[$key];
209 }
210 if ($currencyofpayment != $this->multicurrency_code[$key]) {
211 // If we have invoices with different currencies in the payment, we stop here
212 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
213 return -1;
214 }
215 if (empty($currencytxofpayment)) {
216 $currencytxofpayment = $this->multicurrency_tx[$key];
217 }
218
219 $totalamount_converted += $value_converted;
220 $amounts_to_update[$key] = price2num($value_converted, 'MT');
221
222 $newvalue = price2num($value, 'MT');
223 $amounts[$key] = $newvalue;
224 $totalamount += $newvalue;
225 if (!empty($newvalue)) {
226 $atleastonepaymentnotnull++;
227 }
228 }
229
230 if (!empty($currencyofpayment)) {
231 // We must check that the currency of invoices is the same than the currency of the bank
232 $bankaccount = new Account($this->db);
233 $bankaccount->fetch($this->fk_account);
234 $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
235 if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
236 $langs->load("errors");
237 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
238 return -1;
239 }
240 }
241
242
243 $totalamount = (float) price2num($totalamount);
244 $totalamount_converted = (float) price2num($totalamount_converted);
245 $mtotal = 0;
246 $total = 0;
247
248 dol_syslog(get_class($this)."::create", LOG_DEBUG);
249
250 $this->db->begin();
251
252 if ($totalamount != 0) { // On accepte les montants negatifs
253 $ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
254
255 if ($way == 'dolibarr') {
256 $total = $totalamount;
257 $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
258 } else {
259 $total = $totalamount_converted; // Maybe use price2num with MT for the converted value
260 $mtotal = $totalamount;
261 }
262
263 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (';
264 $sql .= 'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
265 $sql .= " VALUES ('".$this->db->escape($ref)."', ".((int) $conf->entity).", '".$this->db->idate($now)."',";
266 $sql .= " '".$this->db->idate($this->datepaye)."', ".((float) $total).", ".((float) $mtotal).", ".((int) $this->paiementid).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', ".((int) $user->id).", 0)";
267
268 $resql = $this->db->query($sql);
269 if ($resql) {
270 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiementfourn');
271
272 // Insere tableau des montants / factures
273 foreach ($this->amounts as $key => $amount) {
274 $facid = $key;
275 if (is_numeric($amount) && $amount != 0) {
276 $amount = price2num($amount);
277 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount, multicurrency_code, multicurrency_tx)';
278 $sql .= " VALUES (".((int) $facid).", ".((int) $this->id).", ".((float) $amount).', '.((float) $this->multicurrency_amounts[$key]).', '.($currencyofpayment ? "'".$this->db->escape($currencyofpayment)."'" : 'NULL').', '.(!empty($currencytxofpayment) ? (float) $currencytxofpayment : 1).')';
279 $resql = $this->db->query($sql);
280 if ($resql) {
281 $invoice = new FactureFournisseur($this->db);
282 $invoice->fetch($facid);
283
284 // If we want to closed paid invoices
285 if ($closepaidinvoices) {
286 $paiement = $invoice->getSommePaiement();
287 $creditnotes = $invoice->getSumCreditNotesUsed();
288 // $creditnotes = 0;
289 $deposits = $invoice->getSumDepositsUsed();
290 // $deposits = 0;
291 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
292 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
293 if ($remaintopay == 0) {
294 // If invoice is a down payment, we also convert down payment to discount
295 if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) {
296 $amount_ht = $amount_tva = $amount_ttc = array();
297 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
298 '
299 @phan-var-force array<string,float> $amount_ht
300 @phan-var-force array<string,float> $amount_tva
301 @phan-var-force array<string,float> $amount_ttc
302 @phan-var-force array<string,float> $multicurrency_amount_ht
303 @phan-var-force array<string,float> $multicurrency_amount_tva
304 @phan-var-force array<string,float> $multicurrency_amount_ttc
305 ';
306
307 // Insert one discount by VAT rate category
308 require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
309 $discount = new DiscountAbsolute($this->db);
310 $discount->fetch(0, 0, $invoice->id);
311 if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
312 $discount->discount_type = 1; // Supplier discount
313 $discount->description = '(DEPOSIT)';
314 $discount->fk_soc = $invoice->socid;
315 $discount->socid = $invoice->socid;
316 $discount->fk_invoice_supplier_source = $invoice->id;
317
318 // Loop on each vat rate
319 $i = 0;
320 foreach ($invoice->lines as $line) {
321 if ($line->total_ht != 0) { // no need to create discount if amount is null
322 if (!array_key_exists($line->tva_tx, $amount_ht)) {
323 $amount_ht[$line->tva_tx] = 0.0;
324 $amount_tva[$line->tva_tx] = 0.0;
325 $amount_ttc[$line->tva_tx] = 0.0;
326 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
327 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
328 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
329 }
330 $amount_ht[$line->tva_tx] += $line->total_ht;
331 $amount_tva[$line->tva_tx] += $line->total_tva;
332 $amount_ttc[$line->tva_tx] += $line->total_ttc;
333 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
334 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
335 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
336 $i++;
337 }
338 }
339
340 foreach ($amount_ht as $tva_tx => $xxx) {
341 $discount->amount_ht = abs($amount_ht[$tva_tx]);
342 $discount->amount_tva = abs($amount_tva[$tva_tx]);
343 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
344 $discount->total_ht = abs($amount_ht[$tva_tx]);
345 $discount->total_tva = abs($amount_tva[$tva_tx]);
346 $discount->total_ttc = abs($amount_ttc[$tva_tx]);
347 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
348 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
349 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
350 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
351 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
352 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
353 $discount->tva_tx = abs((float) $tva_tx);
354
355 $result = $discount->create($user);
356 if ($result < 0) {
357 $error++;
358 break;
359 }
360 }
361 }
362
363 if ($error) {
364 setEventMessages($discount->error, $discount->errors, 'errors');
365 $error++;
366 }
367 }
368
369 // Set invoice to paid
370 if (!$error) {
371 $result = $invoice->setPaid($user, '', '');
372 if ($result < 0) {
373 $this->error = $invoice->error;
374 $error++;
375 }
376 }
377 } else {
378 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
379 global $hookmanager;
380 $hookmanager->initHooks(array('payment_supplierdao'));
381 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
382 $action = 'CLOSEPAIDSUPPLIERINVOICE';
383 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
384 if ($reshook < 0) {
385 $this->error = $hookmanager->error;
386 $error++;
387 } elseif ($reshook == 0) {
388 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
389 }
390 }
391 }
392
393 // Regenerate documents of invoices
394 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
395 $newlang = '';
396 $outputlangs = $langs;
397 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
398 $invoice->fetch_thirdparty();
399 $newlang = $invoice->thirdparty->default_lang;
400 }
401 if (!empty($newlang)) {
402 $outputlangs = new Translate("", $conf);
403 $outputlangs->setDefaultLang($newlang);
404 }
405 $ret = $invoice->fetch($facid); // Reload to get new records
406 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs);
407 if ($result < 0) {
408 setEventMessages($invoice->error, $invoice->errors, 'errors');
409 $error++;
410 }
411 }
412 } else {
413 $this->error = $this->db->lasterror();
414 $error++;
415 }
416 } else {
417 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
418 }
419 }
420
421 if (!$error) {
422 // Call trigger
423 $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user);
424 if ($result < 0) {
425 $error++;
426 }
427 // End call triggers
428 }
429 } else {
430 $this->error = $this->db->lasterror();
431 $error++;
432 }
433 } else {
434 $this->error = "ErrorTotalIsNull";
435 dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
436 $error++;
437 }
438
439 if ($totalamount != 0 && $error == 0) { // On accepte les montants negatifs
440 $this->amount = $total;
441 $this->total = $total;
442 $this->multicurrency_amount = $mtotal;
443 $this->db->commit();
444 dol_syslog('PaiementFourn::Create Ok Total = '.$this->amount.', Total currency = '.$this->multicurrency_amount);
445 return $this->id;
446 } else {
447 $this->db->rollback();
448 return -1;
449 }
450 }
451
452
462 public function delete($user = null, $notrigger = 0)
463 {
464 if (empty($user)) {
465 global $user;
466 }
467
468 $bank_line_id = $this->bank_line;
469
470 $this->db->begin();
471
472 // Check if payment is completely paid, if payments are shared, we refuse deletion.
473 // TODO Check also if partially paid
474 $billsarray = $this->getBillsArray('paye:=:1');
475 if (is_array($billsarray)) {
476 if (count($billsarray)) {
477 $this->error = "ErrorCantDeletePaymentSharedWithPayedInvoice";
478 $this->db->rollback();
479 return -1;
480 }
481 } else {
482 $this->db->rollback();
483 return -2;
484 }
485
486 // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee
487 // Si c'est le cas, on refuse le delete
488 if ($bank_line_id) {
489 $accline = new AccountLine($this->db);
490 $accline->fetch($bank_line_id);
491 if ($accline->rappro) {
492 $this->error = "ErrorCantDeletePaymentReconciliated";
493 $this->db->rollback();
494 return -3;
495 }
496 }
497
498 // Delete payment line (from llx_paiement_facture and llx_paiement)
499 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
500 $sql .= ' WHERE fk_paiementfourn = '.((int) $this->id);
501 $resql = $this->db->query($sql);
502 if ($resql) {
503 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn';
504 $sql .= " WHERE rowid = ".((int) $this->id);
505 $result = $this->db->query($sql);
506 if (!$result) {
507 $this->error = $this->db->error();
508 $this->db->rollback();
509 return -3;
510 }
511
512 // Delete the bank entry if a payment is linked to an entry
513 if ($bank_line_id) {
514 $accline = new AccountLine($this->db);
515 $result = $accline->fetch($bank_line_id);
516 if ($result > 0) { // If result = 0, record not found, we don't try to delete
517 $result = $accline->delete($user);
518 }
519 if ($result < 0) {
520 $this->error = $accline->error;
521 $this->db->rollback();
522 return -4;
523 }
524 }
525
526 if (!$notrigger) {
527 // Appel des triggers
528 $result = $this->call_trigger('PAYMENT_SUPPLIER_DELETE', $user);
529 if ($result < 0) {
530 $this->db->rollback();
531 return -1;
532 }
533 // Fin appel triggers
534 }
535
536 $this->db->commit();
537 return 1;
538 } else {
539 $this->error = $this->db->error;
540 $this->db->rollback();
541 return -5;
542 }
543 }
544
551 public function info($id)
552 {
553 $sql = 'SELECT c.rowid, datec, fk_user_author as fk_user_creat, tms as fk_user_modif';
554 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as c';
555 $sql .= ' WHERE c.rowid = '.((int) $id);
556
557 $resql = $this->db->query($sql);
558 if ($resql) {
559 $num = $this->db->num_rows($resql);
560 if ($num) {
561 $obj = $this->db->fetch_object($resql);
562
563 $this->id = $obj->rowid;
564 $this->user_creation_id = $obj->fk_user_creat;
565 $this->user_modification_id = $obj->fk_user_modif;
566 $this->date_creation = $this->db->jdate($obj->datec);
567 $this->date_modification = $this->db->jdate($obj->tms);
568 }
569 $this->db->free($resql);
570 } else {
571 dol_print_error($this->db);
572 }
573 }
574
581 public function getBillsArray($filter = '')
582 {
583 $sql = 'SELECT fk_facturefourn';
584 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f';
585 $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.((int) $this->id);
586 if ($filter) {
587 $sql .= forgeSQLFromUniversalSearchCriteria($filter);
588 }
589
590 dol_syslog(get_class($this).'::getBillsArray', LOG_DEBUG);
591 $resql = $this->db->query($sql);
592 if ($resql) {
593 $i = 0;
594 $num = $this->db->num_rows($resql);
595 $billsarray = array();
596
597 while ($i < $num) {
598 $obj = $this->db->fetch_object($resql);
599 $billsarray[$i] = $obj->fk_facturefourn;
600 $i++;
601 }
602
603 return $billsarray;
604 } else {
605 $this->error = $this->db->error();
606 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error);
607 return -1;
608 }
609 }
610
617 public function getLibStatut($mode = 0)
618 {
619 return $this->LibStatut($this->statut, $mode);
620 }
621
622 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
630 public function LibStatut($status, $mode = 0)
631 {
632 // phpcs:enable
633 global $langs;
634
635 $langs->load('compta');
636 /*if ($mode == 0) {
637 if ($status == 0) return $langs->trans('ToValidate');
638 if ($status == 1) return $langs->trans('Validated');
639 }
640 if ($mode == 1)
641 {
642 if ($status == 0) return $langs->trans('ToValidate');
643 if ($status == 1) return $langs->trans('Validated');
644 }
645 if ($mode == 2)
646 {
647 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
648 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
649 }
650 if ($mode == 3)
651 {
652 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
653 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
654 }
655 if ($mode == 4)
656 {
657 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
658 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
659 }
660 if ($mode == 5)
661 {
662 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
663 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
664 }
665 if ($mode == 6)
666 {
667 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
668 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
669 }*/
670 return '';
671 }
672
673
684 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
685 {
686 global $langs, $conf, $hookmanager;
687
688 if (!empty($conf->dol_no_mouse_hover)) {
689 $notooltip = 1; // Force disable tooltips
690 }
691
692 $result = '';
693
694 $text = $this->ref; // Sometimes ref contains label
695 $reg = array();
696 if (preg_match('/^\‍((.*)\‍)$/i', $text, $reg)) {
697 // Label generique car entre parentheses. On l'affiche en le traduisant
698 if ($reg[1] == 'paiement') {
699 $reg[1] = 'Payment';
700 }
701 $text = $langs->trans($reg[1]);
702 }
703
704 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
705 $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$text;
706 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
707 if ($dateofpayment) {
708 $label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($dateofpayment, 'dayhour', 'tzuser');
709 }
710 if ($this->amount) {
711 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
712 }
713
714 $linkclose = '';
715 if (empty($notooltip)) {
716 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
717 $label = $langs->trans("Payment");
718 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
719 }
720 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
721 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
722 } else {
723 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
724 }
725
726 $linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$this->id.'"';
727 $linkstart .= $linkclose.'>';
728 $linkend = '</a>';
729
730 $result .= $linkstart;
731 if ($withpicto) {
732 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
733 }
734 if ($withpicto != 2) {
735 $result .= $this->ref;
736 }
737 $result .= $linkend;
738
739 global $action;
740 $hookmanager->initHooks(array($this->element . 'dao'));
741 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
742 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
743 if ($reshook > 0) {
744 $result = $hookmanager->resPrint;
745 } else {
746 $result .= $hookmanager->resPrint;
747 }
748 return $result;
749 }
750
759 public function initAsSpecimen($option = '')
760 {
761 $now = dol_now();
762 $arraynow = dol_getdate($now);
763 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
764
765 // Initialize parameters
766 $this->id = 0;
767 $this->ref = 'SPECIMEN';
768 $this->specimen = 1;
769 $this->facid = 1;
770 $this->socid = 1;
771 $this->datepaye = $nownotime;
772
773 return 1;
774 }
775
784 public function getNextNumRef($soc, $mode = 'next')
785 {
786 global $conf, $db, $langs;
787 $langs->load("bills");
788
789 // Clean parameters (if not defined or using deprecated value)
790 if (!getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
791 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
792 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'brodator') {
793 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator';
794 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'bronan') {
795 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
796 }
797
798 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
799 $mybool = false;
800
801 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
802 $classname = getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
803
804 // Include file with class
805 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
806
807 foreach ($dirmodels as $reldir) {
808 $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
809
810 // Load file with numbering class (if found)
811 if (is_file($dir.$file) && is_readable($dir.$file)) {
812 $mybool = ((bool) @include_once $dir.$file) || $mybool;
813 }
814 }
815
816 // For compatibility
817 if (!$mybool) {
818 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
819 $classname = "mod_supplier_payment_" . getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
820 $classname = preg_replace('/\-.*$/', '', $classname);
821 // Include file with class
822 foreach ($conf->file->dol_document_root as $dirroot) {
823 $dir = $dirroot."/core/modules/supplier_payment/";
824
825 // Load file with numbering class (if found)
826 if (is_file($dir.$file) && is_readable($dir.$file)) {
827 $mybool = ((bool) @include_once $dir.$file) || $mybool;
828 }
829 }
830 }
831
832 if (!$mybool) {
833 dol_print_error(null, "Failed to include file ".$file);
834 return '';
835 }
836
837 $obj = new $classname();
838 '@phan-var-force ModeleNumRefSupplierPayments $obj';
839 $numref = $obj->getNextValue($soc, $this);
840
845 if ($mode != 'last' && !$numref) {
846 dol_print_error($db, "SupplierPayment::getNextNumRef ".$obj->error);
847 return "";
848 }
849
850 return $numref;
851 } else {
852 $langs->load("errors");
853 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Supplier"));
854 return "";
855 }
856 }
857
869 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
870 {
871 global $conf, $user, $langs;
872
873 $langs->load("suppliers");
874
875 // Set the model on the model name to use
876 if (empty($modele)) {
877 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF')) {
878 $modele = getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF');
879 } else {
880 $modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation
881 }
882 }
883
884 if (empty($modele)) {
885 return 0;
886 } else {
887 $modelpath = "core/modules/supplier_payment/doc/";
888
889 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
890 }
891 }
892
893
894
900 public function getWay()
901 {
902 global $conf;
903
904 $way = 'dolibarr';
905 if (isModEnabled("multicurrency")) {
906 foreach ($this->multicurrency_amounts as $value) {
907 if (!empty($value)) { // one value found then payment is in invoice currency
908 $way = 'customer';
909 break;
910 }
911 }
912 }
913
914 return $way;
915 }
916
917
918 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
925 public function fetch_thirdparty($force_thirdparty_id = 0)
926 {
927 // phpcs:enable
928 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
929
930 if (empty($force_thirdparty_id)) {
931 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
932 if (!empty($billsarray)) {
933 $supplier_invoice = new FactureFournisseur($this->db);
934 if ($supplier_invoice->fetch($billsarray[0]) > 0) {
935 $force_thirdparty_id = $supplier_invoice->socid;
936 }
937 }
938 }
939
940 return parent::fetch_thirdparty($force_thirdparty_id);
941 }
942}
$object ref
Definition info.php:90
Class to manage bank accounts.
Class to manage bank transaction lines.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
Class to manage absolute discounts.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
static getAmountConversionFromInvoiceRate($fk_facture, $amount, $way='dolibarr', $table='facture', $invoice_rate=null)
Get the conversion of amount with invoice rate.
Class to manage payments for supplier invoices.
LibStatut($status, $mode=0)
Return the label of a given status.
getNextNumRef($soc, $mode='next')
Return next reference of supplier invoice not already used (or last reference) according to numbering...
initAsSpecimen($option='')
Initialise an instance with random values.
getLibStatut($mode=0)
Return the label of the status.
__construct($db)
Constructor.
info($id)
Information on object.
create($user, $closepaidinvoices=0, $thirdparty=null)
Create payment in database.
getBillsArray($filter='')
Return list of supplier invoices the payment point to.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template model.
getNomUrl($withpicto=0, $option='', $mode='withlistofinvoices', $notooltip=0, $morecss='')
Return clickable name (with picto eventually)
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id into this->thirdparty.
getWay()
get the right way of payment
fetch($id, $ref='', $fk_bank=0)
Load payment object.
Class to manage payments of customer invoices.
Class to manage translations.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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 '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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
Definition receipt.php:489
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 date
Definition receipt.php:487