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