dolibarr 25.0.0-alpha
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-2026 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 * Copyright (C) 2026 Lionel Vessiller <lvessiller@open-dsi.fr>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
34require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
36require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
37
42{
46 public $element = 'payment_supplier';
47
51 public $table_element = 'paiementfourn';
52
56 public $picto = 'payment';
57
61 public $statut;
62 // fk_paiement in llx_paiement is the id of the payment type (7 for CHQ, ...)
63 // fk_paiement dans llx_paiement_facture is rowid of payment
64
69 public $type_label;
70
75 public $type_code;
76
80 public $id_prelevement;
81
85 public $num_prelevement;
86
87
93 public function __construct($db)
94 {
95 $this->db = $db;
96 }
97
106 public function fetch($id, $ref = '', $fk_bank = 0)
107 {
108 $error = 0;
109
110 $sql = 'SELECT p.rowid, p.ref, p.entity, p.datep as dp, p.amount, p.statut, p.fk_bank, p.multicurrency_amount,';
111 $sql .= ' c.code as payment_code, c.libelle as payment_type,';
112 $sql .= ' p.num_paiement as num_payment, p.note, b.fk_account, p.fk_paiement';
113 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p';
114 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
115 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
116 $sql .= ' WHERE p.entity IN ('.getEntity('facture_fourn').')';
117 if ($id > 0) {
118 $sql .= ' AND p.rowid = '.((int) $id);
119 } elseif ($ref) {
120 $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
121 } elseif ($fk_bank > 0) {
122 $sql .= ' AND p.fk_bank = '.((int) $fk_bank);
123 }
124 //print $sql;
125
126 $resql = $this->db->query($sql);
127 if ($resql) {
128 $num = $this->db->num_rows($resql);
129 if ($num > 0) {
130 $obj = $this->db->fetch_object($resql);
131
132 $this->id = $obj->rowid;
133 $this->ref = $obj->ref;
134 $this->entity = $obj->entity;
135 $this->date = $this->db->jdate($obj->dp);
136 $this->datepaye = $this->db->jdate($obj->dp);
137 $this->num_payment = $obj->num_payment;
138 $this->bank_account = $obj->fk_account;
139 $this->fk_account = $obj->fk_account;
140 $this->bank_line = $obj->fk_bank;
141 $this->montant = $obj->amount; // deprecated
142 $this->amount = $obj->amount;
143 $this->multicurrency_amount = $obj->multicurrency_amount;
144 $this->note = $obj->note;
145 $this->note_private = $obj->note;
146 $this->type_code = $obj->payment_code;
147 $this->type_label = $obj->payment_type;
148 $this->fk_paiement = $obj->fk_paiement;
149 $this->statut = $obj->statut;
150
151 $error = 1;
152 } else {
153 $error = -2; // TODO Use 0 instead
154 }
155 $this->db->free($resql);
156 } else {
157 dol_print_error($this->db);
158 $error = -1;
159 }
160 return $error;
161 }
162
171 public function create($user, $closepaidinvoices = 0, $thirdparty = null)
172 {
173 global $langs, $conf;
174
175 $error = 0;
176 $way = $this->getWay();
177
178 $now = dol_now();
179
180 // Clean parameters
181 $totalamount = 0;
182 $totalamount_converted = 0;
183 $atleastonepaymentnotnull = 0;
184
185 if ($way == 'dolibarr') {
186 $amounts = &$this->amounts;
187 $amounts_to_update = &$this->multicurrency_amounts;
188 } else {
189 $amounts = &$this->multicurrency_amounts;
190 $amounts_to_update = &$this->amounts;
191 }
192
193 $currencyofpayment = '';
194 $currencytxofpayment = '';
195
196 foreach ($amounts as $key => $value) {
197 if (empty($value)) {
198 continue;
199 }
200 // $key is id of invoice, $value is amount, $way is a 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
201 $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate((int) $key, $value ? $value : 0, $way, 'facture_fourn');
202 // Add controls of input validity
203 if ($value_converted === false) {
204 // We failed to find the conversion for one invoice
205 $this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
206 return -1;
207 }
208 // Fallback: read invoice multicurrency code/tx if caller did not fill the arrays
209 $invoice_multicurrency_code = $this->multicurrency_code[$key] ?? '';
210 $invoice_multicurrency_tx = $this->multicurrency_tx[$key] ?? '';
211 if (empty($invoice_multicurrency_code) || empty($invoice_multicurrency_tx)) {
212 $tmparray = MultiCurrency::getInvoiceRate($key, 'facture_fourn');
213 if ($tmparray !== false) {
214 if (empty($invoice_multicurrency_code)) {
215 $invoice_multicurrency_code = $tmparray['invoice_multicurrency_code'];
216 }
217 if (empty($invoice_multicurrency_tx)) {
218 $invoice_multicurrency_tx = $tmparray['invoice_multicurrency_tx'];
219 }
220 }
221 }
222
223 if (empty($currencyofpayment)) {
224 $currencyofpayment = $invoice_multicurrency_code;
225 }
226 if ($currencyofpayment != $invoice_multicurrency_code) {
227 // If we have invoices with different currencies in the payment, we stop here
228 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
229 return -1;
230 }
231 if (empty($currencytxofpayment)) {
232 $currencytxofpayment = $invoice_multicurrency_tx;
233 }
234
235 $totalamount_converted += $value_converted;
236 $amounts_to_update[$key] = price2num($value_converted, 'MT');
237
238 $newvalue = price2num($value, 'MT');
239 $amounts[$key] = $newvalue;
240 $totalamount += $newvalue;
241 if (!empty($newvalue)) {
242 $atleastonepaymentnotnull++;
243 }
244 }
245
246 if (!empty($currencyofpayment)) {
247 // We must check that the currency of invoices is the same than the currency of the bank
248 $bankaccount = new Account($this->db);
249 $bankaccount->fetch($this->fk_account);
250 $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
251 if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
252 $langs->load("errors");
253 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
254 return -1;
255 }
256 }
257
258
259 $totalamount = (float) price2num($totalamount);
260 $totalamount_converted = (float) price2num($totalamount_converted);
261 $mtotal = 0;
262 $total = 0;
263
264 dol_syslog(get_class($this)."::create", LOG_DEBUG);
265
266 $this->db->begin();
267
268 if ($totalamount != 0) { // On accepte les montants negatifs
269 $ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
270
271 if ($way == 'dolibarr') {
272 $total = $totalamount;
273 $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
274 } else {
275 $total = $totalamount_converted; // Maybe use price2num with MT for the converted value
276 $mtotal = $totalamount;
277 }
278
279 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (';
280 $sql .= 'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
281 $sql .= " VALUES ('".$this->db->escape($ref)."', ".((int) $conf->entity).", '".$this->db->idate($now)."',";
282 $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)";
283
284 $resql = $this->db->query($sql);
285 if ($resql) {
286 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiementfourn');
287
288 // Insert array of amounts / invoices
289 foreach ($this->amounts as $key => $amount) {
290 $facid = $key;
291 if (is_numeric($amount) && $amount != 0) {
292 $amount = price2num($amount);
293 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount, multicurrency_code, multicurrency_tx)';
294 $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).')';
295 $resql = $this->db->query($sql);
296 if ($resql) {
297 $invoice = new FactureFournisseur($this->db);
298 $invoice->fetch($facid);
299
300 // If we want to closed paid invoices
301 if ($closepaidinvoices) {
302 $paiement = $invoice->getSommePaiement();
303 $creditnotes = $invoice->getSumCreditNotesUsed();
304 // $creditnotes = 0;
305 $deposits = $invoice->getSumDepositsUsed();
306 // $deposits = 0;
307 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
308 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
309 if ($remaintopay == 0) {
310 // If invoice is a down payment, we also convert down payment to discount
311 if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) {
312 $amount_ht = $amount_tva = $amount_ttc = array();
313 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
314 '
315 @phan-var-force array<string,float> $amount_ht
316 @phan-var-force array<string,float> $amount_tva
317 @phan-var-force array<string,float> $amount_ttc
318 @phan-var-force array<string,float> $multicurrency_amount_ht
319 @phan-var-force array<string,float> $multicurrency_amount_tva
320 @phan-var-force array<string,float> $multicurrency_amount_ttc
321 ';
322
323 // Insert one discount by VAT rate category
324 require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
325 $discount = new DiscountAbsolute($this->db);
326 $discount->fetch(0, 0, $invoice->id);
327 if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
328 $discount->discount_type = 1; // Supplier discount
329 $discount->description = '(DEPOSIT)';
330 $discount->fk_soc = $invoice->socid;
331 $discount->socid = $invoice->socid;
332 $discount->fk_invoice_supplier_source = $invoice->id;
333 $discount->multicurrency_code = $invoice->multicurrency_code;
334 $discount->multicurrency_tx = $invoice->multicurrency_tx;
335
336 // Loop on each vat rate
337 $i = 0;
338 foreach ($invoice->lines as $line) {
339 if ($line->total_ht != 0) { // no need to create discount if amount is null
340 if (!array_key_exists($line->tva_tx, $amount_ht)) {
341 $amount_ht[$line->tva_tx] = 0.0;
342 $amount_tva[$line->tva_tx] = 0.0;
343 $amount_ttc[$line->tva_tx] = 0.0;
344 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
345 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
346 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
347 }
348 $amount_ht[$line->tva_tx] += $line->total_ht;
349 $amount_tva[$line->tva_tx] += $line->total_tva;
350 $amount_ttc[$line->tva_tx] += $line->total_ttc;
351 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
352 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
353 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
354 $i++;
355 }
356 }
357
358 foreach ($amount_ht as $tva_tx => $xxx) {
359 $discount->total_ht = abs($amount_ht[$tva_tx]);
360 $discount->total_tva = abs($amount_tva[$tva_tx]);
361 $discount->total_ttc = abs($amount_ttc[$tva_tx]);
362
363 // keep compatibility
364 $discount->amount_ht = $discount->total_ht;
365 $discount->amount_tva = $discount->total_tva;
366 $discount->amount_ttc = $discount->total_ttc;
367
368 // multi-currency
369 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
370 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
371 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
372
373 // keep compatibility
374 $discount->multicurrency_amount_ht = $discount->multicurrency_total_ht;
375 $discount->multicurrency_amount_tva = $discount->multicurrency_total_tva;
376 $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
377
378 $discount->tva_tx = abs((float) $tva_tx);
379
380 $result = $discount->create($user);
381 if ($result < 0) {
382 $error++;
383 break;
384 }
385 }
386 }
387
388 if ($error) {
389 $this->error = $discount->error;
390 $this->errors = $discount->errors;
391 $error++;
392 }
393 }
394
395 // Set invoice to paid
396 if (!$error) {
397 $result = $invoice->setPaid($user, '', '');
398 if ($result < 0) {
399 $this->error = $invoice->error;
400 $error++;
401 }
402 }
403 } else {
404 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
405 global $hookmanager;
406 $hookmanager->initHooks(array('payment_supplierdao'));
407 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
408 $action = 'CLOSEPAIDSUPPLIERINVOICE';
409 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
410 if ($reshook < 0) {
411 $this->error = $hookmanager->error;
412 $error++;
413 } elseif ($reshook == 0) {
414 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
415 }
416 }
417 }
418
419 // Regenerate documents of invoices
420 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
421 $newlang = '';
422 $outputlangs = $langs;
423 if (getDolGlobalInt('MAIN_MULTILANGS')) {
424 $invoice->fetch_thirdparty();
425 $newlang = $invoice->thirdparty->default_lang;
426 }
427 if (!empty($newlang)) {
428 $outputlangs = new Translate("", $conf);
429 $outputlangs->setDefaultLang($newlang);
430 }
431 $ret = $invoice->fetch($facid); // Reload to get new records
432 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs);
433 if ($result < 0) {
434 $this->error = $invoice->error;
435 $this->errors = $invoice->errors;
436 $error++;
437 }
438 }
439 } else {
440 $this->error = $this->db->lasterror();
441 $error++;
442 }
443 } else {
444 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
445 }
446 }
447
448 if (!$error) {
449 // Call trigger
450 $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user);
451 if ($result < 0) {
452 $error++;
453 }
454 // End call triggers
455 }
456 } else {
457 $this->error = $this->db->lasterror();
458 $error++;
459 }
460 } else {
461 $this->error = "ErrorTotalIsNull";
462 dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
463 $error++;
464 }
465
466 if ($totalamount != 0 && $error == 0) { // On accepte les montants negatifs
467 $this->amount = $total;
468 $this->total = $total;
469 $this->multicurrency_amount = $mtotal;
470 $this->db->commit();
471 dol_syslog('PaiementFourn::Create Ok Total = '.$this->amount.', Total currency = '.$this->multicurrency_amount);
472 return $this->id;
473 } else {
474 $this->db->rollback();
475 return -1;
476 }
477 }
478
479
489 public function delete($user = null, $notrigger = 0)
490 {
491 if (empty($user)) {
492 global $user;
493 }
494
495 $bank_line_id = $this->bank_line;
496
497 $this->db->begin();
498
499 // Check if payment is completely paid, if payments are shared, we refuse deletion.
500 // TODO Check also if partially paid
501 $billsarray = $this->getBillsArray('paye:=:1');
502 if (is_array($billsarray)) {
503 if (count($billsarray)) {
504 $this->error = "ErrorCantDeletePaymentSharedWithPayedInvoice";
505 $this->db->rollback();
506 return -1;
507 }
508 } else {
509 $this->db->rollback();
510 return -2;
511 }
512
513 // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee
514 // Si c'est le cas, on refuse le delete
515 if ($bank_line_id) {
516 $accline = new AccountLine($this->db);
517 $accline->fetch($bank_line_id);
518 if ($accline->rappro) {
519 $this->error = "ErrorCantDeletePaymentReconciliated";
520 $this->db->rollback();
521 return -3;
522 }
523 }
524
525 // Delete payment line (from llx_paiement_facture and llx_paiement)
526 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
527 $sql .= ' WHERE fk_paiementfourn = '.((int) $this->id);
528 $resql = $this->db->query($sql);
529 if ($resql) {
530 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn';
531 $sql .= " WHERE rowid = ".((int) $this->id);
532 $result = $this->db->query($sql);
533 if (!$result) {
534 $this->error = $this->db->error();
535 $this->db->rollback();
536 return -3;
537 }
538
539 // Delete the bank entry if a payment is linked to an entry
540 if ($bank_line_id) {
541 $accline = new AccountLine($this->db);
542 $result = $accline->fetch($bank_line_id);
543 if ($result > 0) { // If result = 0, record not found, we don't try to delete
544 $result = $accline->delete($user);
545 }
546 if ($result < 0) {
547 $this->error = $accline->error;
548 $this->db->rollback();
549 return -4;
550 }
551 }
552
553 if (!$notrigger) {
554 // Call triggers
555 $result = $this->call_trigger('PAYMENT_SUPPLIER_DELETE', $user);
556 if ($result < 0) {
557 $this->db->rollback();
558 return -1;
559 }
560 // Fin appel triggers
561 }
562
563 $this->db->commit();
564 return 1;
565 } else {
566 $this->error = $this->db->error;
567 $this->db->rollback();
568 return -5;
569 }
570 }
571
578 public function info($id)
579 {
580 $sql = 'SELECT c.rowid, datec, fk_user_author as fk_user_creat, tms as fk_user_modif';
581 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as c';
582 $sql .= ' WHERE c.rowid = '.((int) $id);
583
584 $resql = $this->db->query($sql);
585 if ($resql) {
586 $num = $this->db->num_rows($resql);
587 if ($num) {
588 $obj = $this->db->fetch_object($resql);
589
590 $this->id = $obj->rowid;
591 $this->user_creation_id = $obj->fk_user_creat;
592 $this->user_modification_id = $obj->fk_user_modif;
593 $this->date_creation = $this->db->jdate($obj->datec);
594 $this->date_modification = $this->db->jdate($obj->tms);
595 }
596 $this->db->free($resql);
597 } else {
598 dol_print_error($this->db);
599 }
600 }
601
608 public function getBillsArray($filter = '')
609 {
610 $sql = 'SELECT fk_facturefourn';
611 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f';
612 $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.((int) $this->id);
613 if ($filter) {
615 }
616
617 dol_syslog(get_class($this).'::getBillsArray', LOG_DEBUG);
618 $resql = $this->db->query($sql);
619 if ($resql) {
620 $i = 0;
621 $num = $this->db->num_rows($resql);
622 $billsarray = array();
623
624 while ($i < $num) {
625 $obj = $this->db->fetch_object($resql);
626 $billsarray[$i] = $obj->fk_facturefourn;
627 $i++;
628 }
629
630 return $billsarray;
631 } else {
632 $this->error = $this->db->error();
633 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error);
634 return -1;
635 }
636 }
637
644 public function getLibStatut($mode = 0)
645 {
646 return $this->LibStatut($this->statut, $mode);
647 }
648
649 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
657 public function LibStatut($status, $mode = 0)
658 {
659 // phpcs:enable
660 global $langs;
661
662 $langs->load('compta');
663 /*if ($mode == 0) {
664 if ($status == 0) return $langs->trans('ToValidate');
665 if ($status == 1) return $langs->trans('Validated');
666 }
667 if ($mode == 1)
668 {
669 if ($status == 0) return $langs->trans('ToValidate');
670 if ($status == 1) return $langs->trans('Validated');
671 }
672 if ($mode == 2)
673 {
674 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
675 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
676 }
677 if ($mode == 3)
678 {
679 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
680 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
681 }
682 if ($mode == 4)
683 {
684 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
685 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
686 }
687 if ($mode == 5)
688 {
689 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
690 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
691 }
692 if ($mode == 6)
693 {
694 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
695 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
696 }*/
697 return '';
698 }
699
700
718 public function getTooltipContentArray($params)
719 {
720 global $conf, $langs;
721
722 $reflabel = $params['reflabel'] ?? $this->ref;
723
724 $datas = array();
725 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u>';
726 $datas['ref'] = '<br><strong>'.$langs->trans("Ref").':</strong> '.$reflabel;
727 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
728 if ($dateofpayment) {
729 $datas['date'] = '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($dateofpayment, 'dayhour', 'tzuser');
730 }
731 if ($this->amount) {
732 $datas['amount'] = '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
733 }
734
735 return $datas;
736 }
737
748 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
749 {
750 global $langs, $conf, $hookmanager;
751
752 if (!empty($conf->dol_no_mouse_hover)) {
753 $notooltip = 1; // Force disable tooltips
754 }
755
756 $result = '';
757
758 $text = $this->ref; // Sometimes ref contains label
759 $reg = array();
760 if (preg_match('/^\‍((.*)\‍)$/i', $text, $reg)) {
761 // Generic label because it is in parentheses. We display it translated.
762 if ($reg[1] == 'paiement') {
763 $reg[1] = 'Payment';
764 }
765 $text = $langs->trans($reg[1]);
766 }
767
768 $params = array('reflabel' => $text);
769 $label = $this->getTooltipContent($params);
770
771 $linkclose = '';
772 if (empty($notooltip)) {
773 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
774 $label = $langs->trans("Payment");
775 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
776 }
777 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
778 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
779 } else {
780 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
781 }
782
783 $linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$this->id.'"';
784 $linkstart .= $linkclose.'>';
785 $linkend = '</a>';
786
787 $result .= $linkstart;
788 if ($withpicto) {
789 $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);
790 }
791 if ($withpicto != 2) {
792 $result .= $this->ref;
793 }
794 $result .= $linkend;
795
796 global $action;
797 $hookmanager->initHooks(array($this->element . 'dao'));
798 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
799 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
800 if ($reshook > 0) {
801 $result = $hookmanager->resPrint;
802 } else {
803 $result .= $hookmanager->resPrint;
804 }
805 return $result;
806 }
807
816 public function initAsSpecimen($option = '')
817 {
818 $now = dol_now();
819 $arraynow = dol_getdate($now);
820 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
821
822 // Initialize parameters
823 $this->id = 0;
824 $this->ref = 'SPECIMEN';
825 $this->specimen = 1;
826 $this->facid = 1;
827 $this->socid = 1;
828 $this->datepaye = $nownotime;
829
830 return 1;
831 }
832
841 public function getNextNumRef($soc, $mode = 'next')
842 {
843 global $conf, $db, $langs;
844 $langs->load("bills");
845
846 // Clean parameters (if not defined or using deprecated value)
847 if (!getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
848 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
849 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'brodator') {
850 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator';
851 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'bronan') {
852 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
853 }
854
855 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
856 $mybool = false;
857
858 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
859 $classname = getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
860
861 // Include file with class
862 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
863
864 foreach ($dirmodels as $reldir) {
865 $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
866
867 // Load file with numbering class (if found)
868 if (is_file($dir.$file) && is_readable($dir.$file)) {
869 $mybool = ((bool) @include_once $dir.$file) || $mybool;
870 }
871 }
872
873 // For compatibility
874 if (!$mybool) {
875 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
876 $classname = "mod_supplier_payment_" . getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
877 $classname = preg_replace('/\-.*$/', '', $classname);
878 // Include file with class
879 foreach ($conf->file->dol_document_root as $dirroot) {
880 $dir = $dirroot."/core/modules/supplier_payment/";
881
882 // Load file with numbering class (if found)
883 if (is_file($dir.$file) && is_readable($dir.$file)) {
884 $mybool = ((bool) @include_once $dir.$file) || $mybool;
885 }
886 }
887 }
888
889 if (!$mybool) {
890 dol_print_error(null, "Failed to include file ".$file);
891 return '';
892 }
893
894 $obj = new $classname();
895 '@phan-var-force ModeleNumRefSupplierPayments $obj';
896 $numref = $obj->getNextValue($soc, $this);
897
902 if ($mode != 'last' && !$numref) {
903 dol_print_error($db, "SupplierPayment::getNextNumRef ".$obj->error);
904 return "";
905 }
906
907 return $numref;
908 } else {
909 $langs->load("errors");
910 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Supplier"));
911 return "";
912 }
913 }
914
926 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
927 {
928 global $conf, $user, $langs;
929
930 $langs->load("suppliers");
931
932 // Set the model on the model name to use
933 if (empty($modele)) {
934 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF')) {
935 $modele = getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF');
936 } else {
937 $modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation
938 }
939 }
940
941 if (empty($modele)) {
942 return 0;
943 } else {
944 $modelpath = "core/modules/supplier_payment/doc/";
945
946 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
947 }
948 }
949
950
951
957 public function getWay()
958 {
959 global $conf;
960
961 $way = 'dolibarr';
962 if (isModEnabled("multicurrency")) {
963 foreach ($this->multicurrency_amounts as $value) {
964 if (!empty($value)) { // one value found then payment is in invoice currency
965 $way = 'customer';
966 break;
967 }
968 }
969 }
970
971 return $way;
972 }
973
974
975 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
982 public function fetch_thirdparty($force_thirdparty_id = 0)
983 {
984 // phpcs:enable
985 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
986
987 if (empty($force_thirdparty_id)) {
988 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
989 if (!empty($billsarray)) {
990 $supplier_invoice = new FactureFournisseur($this->db);
991 if ($supplier_invoice->fetch($billsarray[0]) > 0) {
992 $force_thirdparty_id = $supplier_invoice->socid;
993 }
994 }
995 }
996
997 return parent::fetch_thirdparty($force_thirdparty_id);
998 }
999}
$object ref
Definition info.php:90
Class to manage bank accounts.
Class to manage bank transaction lines.
getTooltipContent($params)
getTooltipContent
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 getInvoiceRate($fk_facture, $table='facture')
Get current invoite rate.
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...
getTooltipContentArray($params)
Return clickable name (with picto eventually)
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:
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...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
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).
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:494
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:492