dolibarr 20.0.5
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 * Copyright (C) 2026 Lionel Vessiller <lvessiller@open-dsi.fr>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
35require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
37require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
38
43{
47 public $element = 'payment_supplier';
48
52 public $table_element = 'paiementfourn';
53
57 public $picto = 'payment';
58
59 public $statut; //Status of payment. 0 = unvalidated; 1 = validated
60 // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
61 // fk_paiement dans llx_paiement_facture est le rowid du paiement
62
67 public $type_label;
68
73 public $type_code;
74
78 public $id_prelevement;
79
83 public $num_prelevement;
84
85
91 public function __construct($db)
92 {
93 $this->db = $db;
94 }
95
104 public function fetch($id, $ref = '', $fk_bank = 0)
105 {
106 $error = 0;
107
108 $sql = 'SELECT p.rowid, p.ref, p.entity, p.datep as dp, p.amount, p.statut, p.fk_bank, p.multicurrency_amount,';
109 $sql .= ' c.code as payment_code, c.libelle as payment_type,';
110 $sql .= ' p.num_paiement as num_payment, p.note, b.fk_account, p.fk_paiement';
111 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p';
112 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
113 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
114 $sql .= ' WHERE p.entity IN ('.getEntity('facture_fourn').')';
115 if ($id > 0) {
116 $sql .= ' AND p.rowid = '.((int) $id);
117 } elseif ($ref) {
118 $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
119 } elseif ($fk_bank > 0) {
120 $sql .= ' AND p.fk_bank = '.((int) $fk_bank);
121 }
122 //print $sql;
123
124 $resql = $this->db->query($sql);
125 if ($resql) {
126 $num = $this->db->num_rows($resql);
127 if ($num > 0) {
128 $obj = $this->db->fetch_object($resql);
129
130 $this->id = $obj->rowid;
131 $this->ref = $obj->ref;
132 $this->entity = $obj->entity;
133 $this->date = $this->db->jdate($obj->dp);
134 $this->datepaye = $this->db->jdate($obj->dp);
135 $this->num_payment = $obj->num_payment;
136 $this->bank_account = $obj->fk_account;
137 $this->fk_account = $obj->fk_account;
138 $this->bank_line = $obj->fk_bank;
139 $this->montant = $obj->amount; // deprecated
140 $this->amount = $obj->amount;
141 $this->multicurrency_amount = $obj->multicurrency_amount;
142 $this->note = $obj->note;
143 $this->note_private = $obj->note;
144 $this->type_code = $obj->payment_code;
145 $this->type_label = $obj->payment_type;
146 $this->fk_paiement = $obj->fk_paiement;
147 $this->statut = $obj->statut;
148
149 $error = 1;
150 } else {
151 $error = -2; // TODO Use 0 instead
152 }
153 $this->db->free($resql);
154 } else {
155 dol_print_error($this->db);
156 $error = -1;
157 }
158 return $error;
159 }
160
169 public function create($user, $closepaidinvoices = 0, $thirdparty = null)
170 {
171 global $langs, $conf;
172
173 $error = 0;
174 $way = $this->getWay();
175
176 $now = dol_now();
177
178 // Clean parameters
179 $totalamount = 0;
180 $totalamount_converted = 0;
181 $atleastonepaymentnotnull = 0;
182
183 if ($way == 'dolibarr') {
184 $amounts = &$this->amounts;
185 $amounts_to_update = &$this->multicurrency_amounts;
186 } else {
187 $amounts = &$this->multicurrency_amounts;
188 $amounts_to_update = &$this->amounts;
189 }
190
191 $currencyofpayment = '';
192 $currencytxofpayment = '';
193
194 foreach ($amounts as $key => $value) {
195 if (empty($value)) {
196 continue;
197 }
198 // $key is id of invoice, $value is amount, $way is a 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
199 $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate($key, $value ? $value : 0, $way, 'facture_fourn');
200 // Add controls of input validity
201 if ($value_converted === false) {
202 // We failed to find the conversion for one invoice
203 $this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
204 return -1;
205 }
206 // Fallback: read invoice multicurrency code/tx if caller did not fill the arrays
207 $invoice_multicurrency_code = $this->multicurrency_code[$key] ?? '';
208 $invoice_multicurrency_tx = $this->multicurrency_tx[$key] ?? '';
209 if (empty($invoice_multicurrency_code) || empty($invoice_multicurrency_tx)) {
210 $rate = MultiCurrency::getInvoiceRate($key, 'facture_fourn');
211 if ($rate !== false) {
212 if (empty($invoice_multicurrency_tx)) {
213 //$invoice_multicurrency_tx = $tmparray['invoice_multicurrency_tx'];
214 $invoice_multicurrency_tx = $rate;
215 }
216 }
217 }
218
219 if (empty($currencyofpayment)) {
220 $currencyofpayment = $invoice_multicurrency_code;
221 }
222 if ($currencyofpayment != $invoice_multicurrency_code) {
223 // If we have invoices with different currencies in the payment, we stop here
224 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
225 return -1;
226 }
227 if (empty($currencytxofpayment)) {
228 $currencytxofpayment = $invoice_multicurrency_tx;
229 }
230
231 $totalamount_converted += $value_converted;
232 $amounts_to_update[$key] = price2num($value_converted, 'MT');
233
234 $newvalue = price2num($value, 'MT');
235 $amounts[$key] = $newvalue;
236 $totalamount += $newvalue;
237 if (!empty($newvalue)) {
238 $atleastonepaymentnotnull++;
239 }
240 }
241
242 if (!empty($currencyofpayment)) {
243 // We must check that the currency of invoices is the same than the currency of the bank
244 $bankaccount = new Account($this->db);
245 $bankaccount->fetch($this->fk_account);
246 $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
247 if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
248 $langs->load("errors");
249 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
250 return -1;
251 }
252 }
253
254
255 $totalamount = (float) price2num($totalamount);
256 $totalamount_converted = (float) price2num($totalamount_converted);
257
258 dol_syslog(get_class($this)."::create", LOG_DEBUG);
259
260 $this->db->begin();
261
262 if ($totalamount != 0) { // On accepte les montants negatifs
263 $ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
264
265 if ($way == 'dolibarr') {
266 $total = $totalamount;
267 $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
268 } else {
269 $total = $totalamount_converted; // Maybe use price2num with MT for the converted value
270 $mtotal = $totalamount;
271 }
272
273 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (';
274 $sql .= 'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
275 $sql .= " VALUES ('".$this->db->escape($ref)."', ".((int) $conf->entity).", '".$this->db->idate($now)."',";
276 $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)";
277
278 $resql = $this->db->query($sql);
279 if ($resql) {
280 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiementfourn');
281
282 // Insere tableau des montants / factures
283 foreach ($this->amounts as $key => $amount) {
284 $facid = $key;
285 if (is_numeric($amount) && $amount != 0) {
286 $amount = price2num($amount);
287 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount, multicurrency_code, multicurrency_tx)';
288 $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).')';
289 $resql = $this->db->query($sql);
290 if ($resql) {
291 $invoice = new FactureFournisseur($this->db);
292 $invoice->fetch($facid);
293
294 // If we want to closed paid invoices
295 if ($closepaidinvoices) {
296 $paiement = $invoice->getSommePaiement();
297 $creditnotes = $invoice->getSumCreditNotesUsed();
298 //$creditnotes = 0;
299 $deposits = $invoice->getSumDepositsUsed();
300 //$deposits = 0;
301 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
302 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
303 if ($remaintopay == 0) {
304 // If invoice is a down payment, we also convert down payment to discount
305 if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) {
306 $amount_ht = $amount_tva = $amount_ttc = array();
307 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
308
309 // Insert one discount by VAT rate category
310 require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
311 $discount = new DiscountAbsolute($this->db);
312 $discount->fetch('', 0, $invoice->id);
313 if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
314 $discount->discount_type = 1; // Supplier discount
315 $discount->description = '(DEPOSIT)';
316 $discount->fk_soc = $invoice->socid;
317 $discount->socid = $invoice->socid;
318 $discount->fk_invoice_supplier_source = $invoice->id;
319 $discount->multicurrency_code = $invoice->multicurrency_code;
320 $discount->multicurrency_tx = $invoice->multicurrency_tx;
321
322 // Loop on each vat rate
323 $i = 0;
324 foreach ($invoice->lines as $line) {
325 if ($line->total_ht != 0) { // no need to create discount if amount is null
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 // multi-currency
341 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
342 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
343 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
344 // keep compatibility
345 $discount->multicurrency_amount_ht = $discount->multicurrency_total_ht;
346 $discount->multicurrency_amount_tva = $discount->multicurrency_total_tva;
347 $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
348 $discount->tva_tx = abs($tva_tx);
349
350 $result = $discount->create($user);
351 if ($result < 0) {
352 $error++;
353 break;
354 }
355 }
356 }
357
358 if ($error) {
359 setEventMessages($discount->error, $discount->errors, 'errors');
360 $error++;
361 }
362 }
363
364 // Set invoice to paid
365 if (!$error) {
366 $result = $invoice->setPaid($user, '', '');
367 if ($result < 0) {
368 $this->error = $invoice->error;
369 $error++;
370 }
371 }
372 } else {
373 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
374 global $hookmanager;
375 $hookmanager->initHooks(array('payment_supplierdao'));
376 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
377 $action = 'CLOSEPAIDSUPPLIERINVOICE';
378 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
379 if ($reshook < 0) {
380 $this->error = $hookmanager->error;
381 $error++;
382 } elseif ($reshook == 0) {
383 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
384 }
385 }
386 }
387
388 // Regenerate documents of invoices
389 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
390 $newlang = '';
391 $outputlangs = $langs;
392 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
393 $invoice->fetch_thirdparty();
394 $newlang = $invoice->thirdparty->default_lang;
395 }
396 if (!empty($newlang)) {
397 $outputlangs = new Translate("", $conf);
398 $outputlangs->setDefaultLang($newlang);
399 }
400 $ret = $invoice->fetch($facid); // Reload to get new records
401 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs);
402 if ($result < 0) {
403 setEventMessages($invoice->error, $invoice->errors, 'errors');
404 $error++;
405 }
406 }
407 } else {
408 $this->error = $this->db->lasterror();
409 $error++;
410 }
411 } else {
412 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
413 }
414 }
415
416 if (!$error) {
417 // Call trigger
418 $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user);
419 if ($result < 0) {
420 $error++;
421 }
422 // End call triggers
423 }
424 } else {
425 $this->error = $this->db->lasterror();
426 $error++;
427 }
428 } else {
429 $this->error = "ErrorTotalIsNull";
430 dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
431 $error++;
432 }
433
434 if ($totalamount != 0 && $error == 0) { // On accepte les montants negatifs
435 $this->amount = $total;
436 $this->total = $total;
437 $this->multicurrency_amount = $mtotal;
438 $this->db->commit();
439 dol_syslog('PaiementFourn::Create Ok Total = '.$this->amount.', Total currency = '.$this->multicurrency_amount);
440 return $this->id;
441 } else {
442 $this->db->rollback();
443 return -1;
444 }
445 }
446
447
457 public function delete($user = null, $notrigger = 0)
458 {
459 if (empty($user)) {
460 global $user;
461 }
462
463 $bank_line_id = $this->bank_line;
464
465 $this->db->begin();
466
467 // Verifier si paiement porte pas sur une facture a l'etat payee
468 // Si c'est le cas, on refuse la suppression
469 $billsarray = $this->getBillsArray('paye=1');
470 if (is_array($billsarray)) {
471 if (count($billsarray)) {
472 $this->error = "ErrorCantDeletePaymentSharedWithPayedInvoice";
473 $this->db->rollback();
474 return -1;
475 }
476 } else {
477 $this->db->rollback();
478 return -2;
479 }
480
481 // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee
482 // Si c'est le cas, on refuse le delete
483 if ($bank_line_id) {
484 $accline = new AccountLine($this->db);
485 $accline->fetch($bank_line_id);
486 if ($accline->rappro) {
487 $this->error = "ErrorCantDeletePaymentReconciliated";
488 $this->db->rollback();
489 return -3;
490 }
491 }
492
493 // Efface la ligne de paiement (dans paiement_facture et paiement)
494 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
495 $sql .= ' WHERE fk_paiementfourn = '.((int) $this->id);
496 $resql = $this->db->query($sql);
497 if ($resql) {
498 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn';
499 $sql .= " WHERE rowid = ".((int) $this->id);
500 $result = $this->db->query($sql);
501 if (!$result) {
502 $this->error = $this->db->error();
503 $this->db->rollback();
504 return -3;
505 }
506
507 // Supprimer l'ecriture bancaire si paiement lie a ecriture
508 if ($bank_line_id) {
509 $accline = new AccountLine($this->db);
510 $result = $accline->fetch($bank_line_id);
511 if ($result > 0) { // If result = 0, record not found, we don't try to delete
512 $result = $accline->delete($user);
513 }
514 if ($result < 0) {
515 $this->error = $accline->error;
516 $this->db->rollback();
517 return -4;
518 }
519 }
520
521 if (!$notrigger) {
522 // Appel des triggers
523 $result = $this->call_trigger('PAYMENT_SUPPLIER_DELETE', $user);
524 if ($result < 0) {
525 $this->db->rollback();
526 return -1;
527 }
528 // Fin appel triggers
529 }
530
531 $this->db->commit();
532 return 1;
533 } else {
534 $this->error = $this->db->error;
535 $this->db->rollback();
536 return -5;
537 }
538 }
539
546 public function info($id)
547 {
548 $sql = 'SELECT c.rowid, datec, fk_user_author as fk_user_creat, tms as fk_user_modif';
549 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as c';
550 $sql .= ' WHERE c.rowid = '.((int) $id);
551
552 $resql = $this->db->query($sql);
553 if ($resql) {
554 $num = $this->db->num_rows($resql);
555 if ($num) {
556 $obj = $this->db->fetch_object($resql);
557
558 $this->id = $obj->rowid;
559 $this->user_creation_id = $obj->fk_user_creat;
560 $this->user_modification_id = $obj->fk_user_modif;
561 $this->date_creation = $this->db->jdate($obj->datec);
562 $this->date_modification = $this->db->jdate($obj->tms);
563 }
564 $this->db->free($resql);
565 } else {
566 dol_print_error($this->db);
567 }
568 }
569
576 public function getBillsArray($filter = '')
577 {
578 $sql = 'SELECT fk_facturefourn';
579 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f';
580 $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.((int) $this->id);
581 if ($filter) {
582 $sql .= " AND ".$filter;
583 }
584
585 dol_syslog(get_class($this).'::getBillsArray', LOG_DEBUG);
586 $resql = $this->db->query($sql);
587 if ($resql) {
588 $i = 0;
589 $num = $this->db->num_rows($resql);
590 $billsarray = array();
591
592 while ($i < $num) {
593 $obj = $this->db->fetch_object($resql);
594 $billsarray[$i] = $obj->fk_facturefourn;
595 $i++;
596 }
597
598 return $billsarray;
599 } else {
600 $this->error = $this->db->error();
601 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error);
602 return -1;
603 }
604 }
605
612 public function getLibStatut($mode = 0)
613 {
614 return $this->LibStatut($this->statut, $mode);
615 }
616
617 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
625 public function LibStatut($status, $mode = 0)
626 {
627 // phpcs:enable
628 global $langs;
629
630 $langs->load('compta');
631 /*if ($mode == 0)
632 {
633 if ($status == 0) return $langs->trans('ToValidate');
634 if ($status == 1) return $langs->trans('Validated');
635 }
636 if ($mode == 1)
637 {
638 if ($status == 0) return $langs->trans('ToValidate');
639 if ($status == 1) return $langs->trans('Validated');
640 }
641 if ($mode == 2)
642 {
643 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
644 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
645 }
646 if ($mode == 3)
647 {
648 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
649 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
650 }
651 if ($mode == 4)
652 {
653 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
654 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
655 }
656 if ($mode == 5)
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 if ($mode == 6)
662 {
663 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
664 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
665 }*/
666 return '';
667 }
668
669
680 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
681 {
682 global $langs, $conf, $hookmanager;
683
684 if (!empty($conf->dol_no_mouse_hover)) {
685 $notooltip = 1; // Force disable tooltips
686 }
687
688 $result = '';
689
690 $text = $this->ref; // Sometimes ref contains label
691 $reg = array();
692 if (preg_match('/^\‍((.*)\‍)$/i', $text, $reg)) {
693 // Label generique car entre parentheses. On l'affiche en le traduisant
694 if ($reg[1] == 'paiement') {
695 $reg[1] = 'Payment';
696 }
697 $text = $langs->trans($reg[1]);
698 }
699
700 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
701 $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$text;
702 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
703 if ($dateofpayment) {
704 $label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($dateofpayment, 'dayhour', 'tzuser');
705 }
706 if ($this->amount) {
707 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
708 }
709
710 $linkclose = '';
711 if (empty($notooltip)) {
712 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
713 $label = $langs->trans("Payment");
714 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
715 }
716 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
717 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
718 } else {
719 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
720 }
721
722 $linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$this->id.'"';
723 $linkstart .= $linkclose.'>';
724 $linkend = '</a>';
725
726 $result .= $linkstart;
727 if ($withpicto) {
728 $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);
729 }
730 if ($withpicto != 2) {
731 $result .= $this->ref;
732 }
733 $result .= $linkend;
734
735 global $action;
736 $hookmanager->initHooks(array($this->element . 'dao'));
737 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
738 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
739 if ($reshook > 0) {
740 $result = $hookmanager->resPrint;
741 } else {
742 $result .= $hookmanager->resPrint;
743 }
744 return $result;
745 }
746
755 public function initAsSpecimen($option = '')
756 {
757 $now = dol_now();
758 $arraynow = dol_getdate($now);
759 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
760
761 // Initialize parameters
762 $this->id = 0;
763 $this->ref = 'SPECIMEN';
764 $this->specimen = 1;
765 $this->facid = 1;
766 $this->socid = 1;
767 $this->datepaye = $nownotime;
768
769 return 1;
770 }
771
780 public function getNextNumRef($soc, $mode = 'next')
781 {
782 global $conf, $db, $langs;
783 $langs->load("bills");
784
785 // Clean parameters (if not defined or using deprecated value)
786 if (!getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
787 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
788 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'brodator') {
789 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator';
790 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'bronan') {
791 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
792 }
793
794 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
795 $mybool = false;
796
797 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
798 $classname = getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
799
800 // Include file with class
801 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
802
803 foreach ($dirmodels as $reldir) {
804 $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
805
806 // Load file with numbering class (if found)
807 if (is_file($dir.$file) && is_readable($dir.$file)) {
808 $mybool = (include_once $dir.$file) || $mybool;
809 }
810 }
811
812 // For compatibility
813 if ($mybool === false) {
814 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
815 $classname = "mod_supplier_payment_" . getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
816 $classname = preg_replace('/\-.*$/', '', $classname);
817 // Include file with class
818 foreach ($conf->file->dol_document_root as $dirroot) {
819 $dir = $dirroot."/core/modules/supplier_payment/";
820
821 // Load file with numbering class (if found)
822 if (is_file($dir.$file) && is_readable($dir.$file)) {
823 $mybool = (include_once $dir.$file) || $mybool;
824 }
825 }
826 }
827
828 if ($mybool === false) {
829 dol_print_error(null, "Failed to include file ".$file);
830 return '';
831 }
832
833 $obj = new $classname();
834 $numref = "";
835 $numref = $obj->getNextValue($soc, $this);
836
841 if ($mode != 'last' && !$numref) {
842 dol_print_error($db, "SupplierPayment::getNextNumRef ".$obj->error);
843 return "";
844 }
845
846 return $numref;
847 } else {
848 $langs->load("errors");
849 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Supplier"));
850 return "";
851 }
852 }
853
865 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
866 {
867 global $conf, $user, $langs;
868
869 $langs->load("suppliers");
870
871 // Set the model on the model name to use
872 if (empty($modele)) {
873 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF')) {
874 $modele = getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF');
875 } else {
876 $modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation
877 }
878 }
879
880 if (empty($modele)) {
881 return 0;
882 } else {
883 $modelpath = "core/modules/supplier_payment/doc/";
884
885 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
886 }
887 }
888
889
890
896 public function getWay()
897 {
898 global $conf;
899
900 $way = 'dolibarr';
901 if (isModEnabled("multicurrency")) {
902 foreach ($this->multicurrency_amounts as $value) {
903 if (!empty($value)) { // one value found then payment is in invoice currency
904 $way = 'customer';
905 break;
906 }
907 }
908 }
909
910 return $way;
911 }
912
913
914 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
921 public function fetch_thirdparty($force_thirdparty_id = 0)
922 {
923 // phpcs:enable
924 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
925
926 if (empty($force_thirdparty_id)) {
927 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
928 if (!empty($billsarray)) {
929 $supplier_invoice = new FactureFournisseur($this->db);
930 if ($supplier_invoice->fetch($billsarray[0]) > 0) {
931 $force_thirdparty_id = $supplier_invoice->socid;
932 }
933 }
934 }
935
936 return parent::fetch_thirdparty($force_thirdparty_id);
937 }
938}
$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 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...
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 clicable 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)
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).
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
Definition invoice.php:2051