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