dolibarr 21.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 Frédéric France <frederic.francenetlogic.fr>
10 * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
11 * Copyright (C) 2023 Sylvain Legrand <technique@infras.fr>
12 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
13 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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
58 public $statut; //Status of payment. 0 = unvalidated; 1 = validated
59 // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
60 // fk_paiement dans llx_paiement_facture est le rowid du paiement
61
66 public $type_label;
67
72 public $type_code;
73
77 public $id_prelevement;
78
82 public $num_prelevement;
83
84
90 public function __construct($db)
91 {
92 $this->db = $db;
93 }
94
103 public function fetch($id, $ref = '', $fk_bank = 0)
104 {
105 $error = 0;
106
107 $sql = 'SELECT p.rowid, p.ref, p.entity, p.datep as dp, p.amount, p.statut, p.fk_bank, p.multicurrency_amount,';
108 $sql .= ' c.code as payment_code, c.libelle as payment_type,';
109 $sql .= ' p.num_paiement as num_payment, p.note, b.fk_account, p.fk_paiement';
110 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p';
111 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
112 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
113 $sql .= ' WHERE p.entity IN ('.getEntity('facture_fourn').')';
114 if ($id > 0) {
115 $sql .= ' AND p.rowid = '.((int) $id);
116 } elseif ($ref) {
117 $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
118 } elseif ($fk_bank > 0) {
119 $sql .= ' AND p.fk_bank = '.((int) $fk_bank);
120 }
121 //print $sql;
122
123 $resql = $this->db->query($sql);
124 if ($resql) {
125 $num = $this->db->num_rows($resql);
126 if ($num > 0) {
127 $obj = $this->db->fetch_object($resql);
128
129 $this->id = $obj->rowid;
130 $this->ref = $obj->ref;
131 $this->entity = $obj->entity;
132 $this->date = $this->db->jdate($obj->dp);
133 $this->datepaye = $this->db->jdate($obj->dp);
134 $this->num_payment = $obj->num_payment;
135 $this->bank_account = $obj->fk_account;
136 $this->fk_account = $obj->fk_account;
137 $this->bank_line = $obj->fk_bank;
138 $this->montant = $obj->amount; // deprecated
139 $this->amount = $obj->amount;
140 $this->multicurrency_amount = $obj->multicurrency_amount;
141 $this->note = $obj->note;
142 $this->note_private = $obj->note;
143 $this->type_code = $obj->payment_code;
144 $this->type_label = $obj->payment_type;
145 $this->fk_paiement = $obj->fk_paiement;
146 $this->statut = $obj->statut;
147
148 $error = 1;
149 } else {
150 $error = -2; // TODO Use 0 instead
151 }
152 $this->db->free($resql);
153 } else {
154 dol_print_error($this->db);
155 $error = -1;
156 }
157 return $error;
158 }
159
168 public function create($user, $closepaidinvoices = 0, $thirdparty = null)
169 {
170 global $langs, $conf;
171
172 $error = 0;
173 $way = $this->getWay();
174
175 $now = dol_now();
176
177 // Clean parameters
178 $totalamount = 0;
179 $totalamount_converted = 0;
180 $atleastonepaymentnotnull = 0;
181
182 if ($way == 'dolibarr') {
183 $amounts = &$this->amounts;
184 $amounts_to_update = &$this->multicurrency_amounts;
185 } else {
186 $amounts = &$this->multicurrency_amounts;
187 $amounts_to_update = &$this->amounts;
188 }
189
190 $currencyofpayment = '';
191 $currencytxofpayment = '';
192
193 foreach ($amounts as $key => $value) {
194 if (empty($value)) {
195 continue;
196 }
197 // $key is id of invoice, $value is amount, $way is a 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
198 $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate($key, $value ? $value : 0, $way, 'facture_fourn');
199 // Add controls of input validity
200 if ($value_converted === false) {
201 // We failed to find the conversion for one invoice
202 $this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
203 return -1;
204 }
205 if (empty($currencyofpayment)) {
206 $currencyofpayment = $this->multicurrency_code[$key];
207 }
208 if ($currencyofpayment != $this->multicurrency_code[$key]) {
209 // If we have invoices with different currencies in the payment, we stop here
210 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
211 return -1;
212 }
213 if (empty($currencytxofpayment)) {
214 $currencytxofpayment = $this->multicurrency_tx[$key];
215 }
216
217 $totalamount_converted += $value_converted;
218 $amounts_to_update[$key] = price2num($value_converted, 'MT');
219
220 $newvalue = price2num($value, 'MT');
221 $amounts[$key] = $newvalue;
222 $totalamount += $newvalue;
223 if (!empty($newvalue)) {
224 $atleastonepaymentnotnull++;
225 }
226 }
227
228 if (!empty($currencyofpayment)) {
229 // We must check that the currency of invoices is the same than the currency of the bank
230 $bankaccount = new Account($this->db);
231 $bankaccount->fetch($this->fk_account);
232 $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
233 if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
234 $langs->load("errors");
235 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
236 return -1;
237 }
238 }
239
240
241 $totalamount = (float) price2num($totalamount);
242 $totalamount_converted = (float) price2num($totalamount_converted);
243
244 dol_syslog(get_class($this)."::create", LOG_DEBUG);
245
246 $this->db->begin();
247
248 if ($totalamount != 0) { // On accepte les montants negatifs
249 $ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
250
251 if ($way == 'dolibarr') {
252 $total = $totalamount;
253 $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
254 } else {
255 $total = $totalamount_converted; // Maybe use price2num with MT for the converted value
256 $mtotal = $totalamount;
257 }
258
259 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (';
260 $sql .= 'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
261 $sql .= " VALUES ('".$this->db->escape($ref)."', ".((int) $conf->entity).", '".$this->db->idate($now)."',";
262 $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)";
263
264 $resql = $this->db->query($sql);
265 if ($resql) {
266 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiementfourn');
267
268 // Insere tableau des montants / factures
269 foreach ($this->amounts as $key => $amount) {
270 $facid = $key;
271 if (is_numeric($amount) && $amount != 0) {
272 $amount = price2num($amount);
273 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount, multicurrency_code, multicurrency_tx)';
274 $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).')';
275 $resql = $this->db->query($sql);
276 if ($resql) {
277 $invoice = new FactureFournisseur($this->db);
278 $invoice->fetch($facid);
279
280 // If we want to closed paid invoices
281 if ($closepaidinvoices) {
282 $paiement = $invoice->getSommePaiement();
283 $creditnotes = $invoice->getSumCreditNotesUsed();
284 //$creditnotes = 0;
285 $deposits = $invoice->getSumDepositsUsed();
286 //$deposits = 0;
287 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
288 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
289 if ($remaintopay == 0) {
290 // If invoice is a down payment, we also convert down payment to discount
291 if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) {
292 $amount_ht = $amount_tva = $amount_ttc = array();
293 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
294 '
295 @phan-var-force array<string,float> $amount_ht
296 @phan-var-force array<string,float> $amount_tva
297 @phan-var-force array<string,float> $amount_ttc
298 @phan-var-force array<string,float> $multicurrency_amount_ht
299 @phan-var-force array<string,float> $multicurrency_amount_tva
300 @phan-var-force array<string,float> $multicurrency_amount_ttc
301 ';
302
303 // Insert one discount by VAT rate category
304 require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
305 $discount = new DiscountAbsolute($this->db);
306 $discount->fetch('', 0, $invoice->id);
307 if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
308 $discount->discount_type = 1; // Supplier discount
309 $discount->description = '(DEPOSIT)';
310 $discount->fk_soc = $invoice->socid;
311 $discount->socid = $invoice->socid;
312 $discount->fk_invoice_supplier_source = $invoice->id;
313
314 // Loop on each vat rate
315 $i = 0;
316 foreach ($invoice->lines as $line) {
317 if ($line->total_ht != 0) { // no need to create discount if amount is null
318 if (!array_key_exists($line->tva_tx, $amount_ht)) {
319 $amount_ht[$line->tva_tx] = 0.0;
320 $amount_tva[$line->tva_tx] = 0.0;
321 $amount_ttc[$line->tva_tx] = 0.0;
322 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
323 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
324 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
325 }
326 $amount_ht[$line->tva_tx] += $line->total_ht;
327 $amount_tva[$line->tva_tx] += $line->total_tva;
328 $amount_ttc[$line->tva_tx] += $line->total_ttc;
329 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
330 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
331 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
332 $i++;
333 }
334 }
335
336 foreach ($amount_ht as $tva_tx => $xxx) {
337 $discount->amount_ht = abs($amount_ht[$tva_tx]);
338 $discount->amount_tva = abs($amount_tva[$tva_tx]);
339 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
340 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
341 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
342 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
343 $discount->tva_tx = abs((float) $tva_tx);
344
345 $result = $discount->create($user);
346 if ($result < 0) {
347 $error++;
348 break;
349 }
350 }
351 }
352
353 if ($error) {
354 setEventMessages($discount->error, $discount->errors, 'errors');
355 $error++;
356 }
357 }
358
359 // Set invoice to paid
360 if (!$error) {
361 $result = $invoice->setPaid($user, '', '');
362 if ($result < 0) {
363 $this->error = $invoice->error;
364 $error++;
365 }
366 }
367 } else {
368 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
369 global $hookmanager;
370 $hookmanager->initHooks(array('payment_supplierdao'));
371 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
372 $action = 'CLOSEPAIDSUPPLIERINVOICE';
373 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
374 if ($reshook < 0) {
375 $this->error = $hookmanager->error;
376 $error++;
377 } elseif ($reshook == 0) {
378 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
379 }
380 }
381 }
382
383 // Regenerate documents of invoices
384 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
385 $newlang = '';
386 $outputlangs = $langs;
387 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
388 $invoice->fetch_thirdparty();
389 $newlang = $invoice->thirdparty->default_lang;
390 }
391 if (!empty($newlang)) {
392 $outputlangs = new Translate("", $conf);
393 $outputlangs->setDefaultLang($newlang);
394 }
395 $ret = $invoice->fetch($facid); // Reload to get new records
396 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs);
397 if ($result < 0) {
398 setEventMessages($invoice->error, $invoice->errors, 'errors');
399 $error++;
400 }
401 }
402 } else {
403 $this->error = $this->db->lasterror();
404 $error++;
405 }
406 } else {
407 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
408 }
409 }
410
411 if (!$error) {
412 // Call trigger
413 $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user);
414 if ($result < 0) {
415 $error++;
416 }
417 // End call triggers
418 }
419 } else {
420 $this->error = $this->db->lasterror();
421 $error++;
422 }
423 } else {
424 $this->error = "ErrorTotalIsNull";
425 dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
426 $error++;
427 }
428
429 if ($totalamount != 0 && $error == 0) { // On accepte les montants negatifs
430 $this->amount = $total;
431 $this->total = $total;
432 $this->multicurrency_amount = $mtotal;
433 $this->db->commit();
434 dol_syslog('PaiementFourn::Create Ok Total = '.$this->amount.', Total currency = '.$this->multicurrency_amount);
435 return $this->id;
436 } else {
437 $this->db->rollback();
438 return -1;
439 }
440 }
441
442
452 public function delete($user = null, $notrigger = 0)
453 {
454 if (empty($user)) {
455 global $user;
456 }
457
458 $bank_line_id = $this->bank_line;
459
460 $this->db->begin();
461
462 // Verifier si paiement porte pas sur une facture a l'etat payee
463 // Si c'est le cas, on refuse la suppression
464 $billsarray = $this->getBillsArray('paye=1');
465 if (is_array($billsarray)) {
466 if (count($billsarray)) {
467 $this->error = "ErrorCantDeletePaymentSharedWithPayedInvoice";
468 $this->db->rollback();
469 return -1;
470 }
471 } else {
472 $this->db->rollback();
473 return -2;
474 }
475
476 // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee
477 // Si c'est le cas, on refuse le delete
478 if ($bank_line_id) {
479 $accline = new AccountLine($this->db);
480 $accline->fetch($bank_line_id);
481 if ($accline->rappro) {
482 $this->error = "ErrorCantDeletePaymentReconciliated";
483 $this->db->rollback();
484 return -3;
485 }
486 }
487
488 // Efface la ligne de paiement (dans paiement_facture et paiement)
489 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
490 $sql .= ' WHERE fk_paiementfourn = '.((int) $this->id);
491 $resql = $this->db->query($sql);
492 if ($resql) {
493 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn';
494 $sql .= " WHERE rowid = ".((int) $this->id);
495 $result = $this->db->query($sql);
496 if (!$result) {
497 $this->error = $this->db->error();
498 $this->db->rollback();
499 return -3;
500 }
501
502 // Supprimer l'ecriture bancaire si paiement lie a ecriture
503 if ($bank_line_id) {
504 $accline = new AccountLine($this->db);
505 $result = $accline->fetch($bank_line_id);
506 if ($result > 0) { // If result = 0, record not found, we don't try to delete
507 $result = $accline->delete($user);
508 }
509 if ($result < 0) {
510 $this->error = $accline->error;
511 $this->db->rollback();
512 return -4;
513 }
514 }
515
516 if (!$notrigger) {
517 // Appel des triggers
518 $result = $this->call_trigger('PAYMENT_SUPPLIER_DELETE', $user);
519 if ($result < 0) {
520 $this->db->rollback();
521 return -1;
522 }
523 // Fin appel triggers
524 }
525
526 $this->db->commit();
527 return 1;
528 } else {
529 $this->error = $this->db->error;
530 $this->db->rollback();
531 return -5;
532 }
533 }
534
541 public function info($id)
542 {
543 $sql = 'SELECT c.rowid, datec, fk_user_author as fk_user_creat, tms as fk_user_modif';
544 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as c';
545 $sql .= ' WHERE c.rowid = '.((int) $id);
546
547 $resql = $this->db->query($sql);
548 if ($resql) {
549 $num = $this->db->num_rows($resql);
550 if ($num) {
551 $obj = $this->db->fetch_object($resql);
552
553 $this->id = $obj->rowid;
554 $this->user_creation_id = $obj->fk_user_creat;
555 $this->user_modification_id = $obj->fk_user_modif;
556 $this->date_creation = $this->db->jdate($obj->datec);
557 $this->date_modification = $this->db->jdate($obj->tms);
558 }
559 $this->db->free($resql);
560 } else {
561 dol_print_error($this->db);
562 }
563 }
564
571 public function getBillsArray($filter = '')
572 {
573 $sql = 'SELECT fk_facturefourn';
574 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f';
575 $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.((int) $this->id);
576 if ($filter) {
577 $sql .= " AND ".$filter;
578 }
579
580 dol_syslog(get_class($this).'::getBillsArray', LOG_DEBUG);
581 $resql = $this->db->query($sql);
582 if ($resql) {
583 $i = 0;
584 $num = $this->db->num_rows($resql);
585 $billsarray = array();
586
587 while ($i < $num) {
588 $obj = $this->db->fetch_object($resql);
589 $billsarray[$i] = $obj->fk_facturefourn;
590 $i++;
591 }
592
593 return $billsarray;
594 } else {
595 $this->error = $this->db->error();
596 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error);
597 return -1;
598 }
599 }
600
607 public function getLibStatut($mode = 0)
608 {
609 return $this->LibStatut($this->statut, $mode);
610 }
611
612 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
620 public function LibStatut($status, $mode = 0)
621 {
622 // phpcs:enable
623 global $langs;
624
625 $langs->load('compta');
626 /*if ($mode == 0)
627 {
628 if ($status == 0) return $langs->trans('ToValidate');
629 if ($status == 1) return $langs->trans('Validated');
630 }
631 if ($mode == 1)
632 {
633 if ($status == 0) return $langs->trans('ToValidate');
634 if ($status == 1) return $langs->trans('Validated');
635 }
636 if ($mode == 2)
637 {
638 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
639 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
640 }
641 if ($mode == 3)
642 {
643 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
644 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
645 }
646 if ($mode == 4)
647 {
648 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
649 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
650 }
651 if ($mode == 5)
652 {
653 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
654 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
655 }
656 if ($mode == 6)
657 {
658 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
659 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
660 }*/
661 return '';
662 }
663
664
675 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
676 {
677 global $langs, $conf, $hookmanager;
678
679 if (!empty($conf->dol_no_mouse_hover)) {
680 $notooltip = 1; // Force disable tooltips
681 }
682
683 $result = '';
684
685 $text = $this->ref; // Sometimes ref contains label
686 $reg = array();
687 if (preg_match('/^\‍((.*)\‍)$/i', $text, $reg)) {
688 // Label generique car entre parentheses. On l'affiche en le traduisant
689 if ($reg[1] == 'paiement') {
690 $reg[1] = 'Payment';
691 }
692 $text = $langs->trans($reg[1]);
693 }
694
695 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
696 $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$text;
697 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
698 if ($dateofpayment) {
699 $label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($dateofpayment, 'dayhour', 'tzuser');
700 }
701 if ($this->amount) {
702 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
703 }
704
705 $linkclose = '';
706 if (empty($notooltip)) {
707 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
708 $label = $langs->trans("Payment");
709 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
710 }
711 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
712 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
713 } else {
714 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
715 }
716
717 $linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$this->id.'"';
718 $linkstart .= $linkclose.'>';
719 $linkend = '</a>';
720
721 $result .= $linkstart;
722 if ($withpicto) {
723 $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);
724 }
725 if ($withpicto != 2) {
726 $result .= $this->ref;
727 }
728 $result .= $linkend;
729
730 global $action;
731 $hookmanager->initHooks(array($this->element . 'dao'));
732 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
733 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
734 if ($reshook > 0) {
735 $result = $hookmanager->resPrint;
736 } else {
737 $result .= $hookmanager->resPrint;
738 }
739 return $result;
740 }
741
750 public function initAsSpecimen($option = '')
751 {
752 $now = dol_now();
753 $arraynow = dol_getdate($now);
754 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
755
756 // Initialize parameters
757 $this->id = 0;
758 $this->ref = 'SPECIMEN';
759 $this->specimen = 1;
760 $this->facid = 1;
761 $this->socid = 1;
762 $this->datepaye = $nownotime;
763
764 return 1;
765 }
766
775 public function getNextNumRef($soc, $mode = 'next')
776 {
777 global $conf, $db, $langs;
778 $langs->load("bills");
779
780 // Clean parameters (if not defined or using deprecated value)
781 if (!getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
782 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
783 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'brodator') {
784 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator';
785 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'bronan') {
786 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
787 }
788
789 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
790 $mybool = false;
791
792 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
793 $classname = getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
794
795 // Include file with class
796 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
797
798 foreach ($dirmodels as $reldir) {
799 $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
800
801 // Load file with numbering class (if found)
802 if (is_file($dir.$file) && is_readable($dir.$file)) {
803 $mybool = ((bool) @include_once $dir.$file) || $mybool;
804 }
805 }
806
807 // For compatibility
808 if (!$mybool) {
809 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
810 $classname = "mod_supplier_payment_" . getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
811 $classname = preg_replace('/\-.*$/', '', $classname);
812 // Include file with class
813 foreach ($conf->file->dol_document_root as $dirroot) {
814 $dir = $dirroot."/core/modules/supplier_payment/";
815
816 // Load file with numbering class (if found)
817 if (is_file($dir.$file) && is_readable($dir.$file)) {
818 $mybool = ((bool) @include_once $dir.$file) || $mybool;
819 }
820 }
821 }
822
823 if (!$mybool) {
824 dol_print_error(null, "Failed to include file ".$file);
825 return '';
826 }
827
828 $obj = new $classname();
829 '@phan-var-force ModeleNumRefSupplierPayments $obj';
830 $numref = $obj->getNextValue($soc, $this);
831
836 if ($mode != 'last' && !$numref) {
837 dol_print_error($db, "SupplierPayment::getNextNumRef ".$obj->error);
838 return "";
839 }
840
841 return $numref;
842 } else {
843 $langs->load("errors");
844 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Supplier"));
845 return "";
846 }
847 }
848
860 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
861 {
862 global $conf, $user, $langs;
863
864 $langs->load("suppliers");
865
866 // Set the model on the model name to use
867 if (empty($modele)) {
868 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF')) {
869 $modele = getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF');
870 } else {
871 $modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation
872 }
873 }
874
875 if (empty($modele)) {
876 return 0;
877 } else {
878 $modelpath = "core/modules/supplier_payment/doc/";
879
880 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
881 }
882 }
883
884
885
891 public function getWay()
892 {
893 global $conf;
894
895 $way = 'dolibarr';
896 if (isModEnabled("multicurrency")) {
897 foreach ($this->multicurrency_amounts as $value) {
898 if (!empty($value)) { // one value found then payment is in invoice currency
899 $way = 'customer';
900 break;
901 }
902 }
903 }
904
905 return $way;
906 }
907
908
909 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
916 public function fetch_thirdparty($force_thirdparty_id = 0)
917 {
918 // phpcs:enable
919 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
920
921 if (empty($force_thirdparty_id)) {
922 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
923 if (!empty($billsarray)) {
924 $supplier_invoice = new FactureFournisseur($this->db);
925 if ($supplier_invoice->fetch($billsarray[0]) > 0) {
926 $force_thirdparty_id = $supplier_invoice->socid;
927 }
928 }
929 }
930
931 return parent::fetch_thirdparty($force_thirdparty_id);
932 }
933}
$object ref
Definition info.php:79
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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)
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 '.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
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.