dolibarr 23.0.3
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->total_ht = abs($amount_ht[$tva_tx]);
361 $discount->total_tva = abs($amount_tva[$tva_tx]);
362 $discount->total_ttc = abs($amount_ttc[$tva_tx]);
363
364 // keep compatibility
365 $discount->amount_ht = $discount->total_ht;
366 $discount->amount_tva = $discount->total_tva;
367 $discount->amount_ttc = $discount->total_ttc;
368
369 // multi-currency
370 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
371 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
372 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
373
374 // keep compatibility
375 $discount->multicurrency_amount_ht = $discount->multicurrency_total_ht;
376 $discount->multicurrency_amount_tva = $discount->multicurrency_total_tva;
377 $discount->multicurrency_amount_ttc = $discount->multicurrency_total_ttc;
378
379 $discount->tva_tx = abs((float) $tva_tx);
380
381 $result = $discount->create($user);
382 if ($result < 0) {
383 $error++;
384 break;
385 }
386 }
387 }
388
389 if ($error) {
390 setEventMessages($discount->error, $discount->errors, 'errors');
391 $error++;
392 }
393 }
394
395 // Set invoice to paid
396 if (!$error) {
397 $result = $invoice->setPaid($user, '', '');
398 if ($result < 0) {
399 $this->error = $invoice->error;
400 $error++;
401 }
402 }
403 } else {
404 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
405 global $hookmanager;
406 $hookmanager->initHooks(array('payment_supplierdao'));
407 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
408 $action = 'CLOSEPAIDSUPPLIERINVOICE';
409 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
410 if ($reshook < 0) {
411 $this->error = $hookmanager->error;
412 $error++;
413 } elseif ($reshook == 0) {
414 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
415 }
416 }
417 }
418
419 // Regenerate documents of invoices
420 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
421 $newlang = '';
422 $outputlangs = $langs;
423 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
424 $invoice->fetch_thirdparty();
425 $newlang = $invoice->thirdparty->default_lang;
426 }
427 if (!empty($newlang)) {
428 $outputlangs = new Translate("", $conf);
429 $outputlangs->setDefaultLang($newlang);
430 }
431 $ret = $invoice->fetch($facid); // Reload to get new records
432 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs);
433 if ($result < 0) {
434 setEventMessages($invoice->error, $invoice->errors, 'errors');
435 $error++;
436 }
437 }
438 } else {
439 $this->error = $this->db->lasterror();
440 $error++;
441 }
442 } else {
443 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
444 }
445 }
446
447 if (!$error) {
448 // Call trigger
449 $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user);
450 if ($result < 0) {
451 $error++;
452 }
453 // End call triggers
454 }
455 } else {
456 $this->error = $this->db->lasterror();
457 $error++;
458 }
459 } else {
460 $this->error = "ErrorTotalIsNull";
461 dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
462 $error++;
463 }
464
465 if ($totalamount != 0 && $error == 0) { // On accepte les montants negatifs
466 $this->amount = $total;
467 $this->total = $total;
468 $this->multicurrency_amount = $mtotal;
469 $this->db->commit();
470 dol_syslog('PaiementFourn::Create Ok Total = '.$this->amount.', Total currency = '.$this->multicurrency_amount);
471 return $this->id;
472 } else {
473 $this->db->rollback();
474 return -1;
475 }
476 }
477
478
488 public function delete($user = null, $notrigger = 0)
489 {
490 if (empty($user)) {
491 global $user;
492 }
493
494 $bank_line_id = $this->bank_line;
495
496 $this->db->begin();
497
498 // Verifier si paiement porte pas sur une facture a l'etat payee
499 // Si c'est le cas, on refuse la suppression
500 $billsarray = $this->getBillsArray('paye=1');
501 if (is_array($billsarray)) {
502 if (count($billsarray)) {
503 $this->error = "ErrorCantDeletePaymentSharedWithPayedInvoice";
504 $this->db->rollback();
505 return -1;
506 }
507 } else {
508 $this->db->rollback();
509 return -2;
510 }
511
512 // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee
513 // Si c'est le cas, on refuse le delete
514 if ($bank_line_id) {
515 $accline = new AccountLine($this->db);
516 $accline->fetch($bank_line_id);
517 if ($accline->rappro) {
518 $this->error = "ErrorCantDeletePaymentReconciliated";
519 $this->db->rollback();
520 return -3;
521 }
522 }
523
524 // Efface la ligne de paiement (dans paiement_facture et paiement)
525 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
526 $sql .= ' WHERE fk_paiementfourn = '.((int) $this->id);
527 $resql = $this->db->query($sql);
528 if ($resql) {
529 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn';
530 $sql .= " WHERE rowid = ".((int) $this->id);
531 $result = $this->db->query($sql);
532 if (!$result) {
533 $this->error = $this->db->error();
534 $this->db->rollback();
535 return -3;
536 }
537
538 // Supprimer l'ecriture bancaire si paiement lie a ecriture
539 if ($bank_line_id) {
540 $accline = new AccountLine($this->db);
541 $result = $accline->fetch($bank_line_id);
542 if ($result > 0) { // If result = 0, record not found, we don't try to delete
543 $result = $accline->delete($user);
544 }
545 if ($result < 0) {
546 $this->error = $accline->error;
547 $this->db->rollback();
548 return -4;
549 }
550 }
551
552 if (!$notrigger) {
553 // Appel des triggers
554 $result = $this->call_trigger('PAYMENT_SUPPLIER_DELETE', $user);
555 if ($result < 0) {
556 $this->db->rollback();
557 return -1;
558 }
559 // Fin appel triggers
560 }
561
562 $this->db->commit();
563 return 1;
564 } else {
565 $this->error = $this->db->error;
566 $this->db->rollback();
567 return -5;
568 }
569 }
570
577 public function info($id)
578 {
579 $sql = 'SELECT c.rowid, datec, fk_user_author as fk_user_creat, tms as fk_user_modif';
580 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as c';
581 $sql .= ' WHERE c.rowid = '.((int) $id);
582
583 $resql = $this->db->query($sql);
584 if ($resql) {
585 $num = $this->db->num_rows($resql);
586 if ($num) {
587 $obj = $this->db->fetch_object($resql);
588
589 $this->id = $obj->rowid;
590 $this->user_creation_id = $obj->fk_user_creat;
591 $this->user_modification_id = $obj->fk_user_modif;
592 $this->date_creation = $this->db->jdate($obj->datec);
593 $this->date_modification = $this->db->jdate($obj->tms);
594 }
595 $this->db->free($resql);
596 } else {
597 dol_print_error($this->db);
598 }
599 }
600
607 public function getBillsArray($filter = '')
608 {
609 $sql = 'SELECT fk_facturefourn';
610 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f';
611 $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.((int) $this->id);
612 if ($filter) {
613 $sql .= " AND ".$filter;
614 }
615
616 dol_syslog(get_class($this).'::getBillsArray', LOG_DEBUG);
617 $resql = $this->db->query($sql);
618 if ($resql) {
619 $i = 0;
620 $num = $this->db->num_rows($resql);
621 $billsarray = array();
622
623 while ($i < $num) {
624 $obj = $this->db->fetch_object($resql);
625 $billsarray[$i] = $obj->fk_facturefourn;
626 $i++;
627 }
628
629 return $billsarray;
630 } else {
631 $this->error = $this->db->error();
632 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error);
633 return -1;
634 }
635 }
636
643 public function getLibStatut($mode = 0)
644 {
645 return $this->LibStatut($this->statut, $mode);
646 }
647
648 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
656 public function LibStatut($status, $mode = 0)
657 {
658 // phpcs:enable
659 global $langs;
660
661 $langs->load('compta');
662 /*if ($mode == 0)
663 {
664 if ($status == 0) return $langs->trans('ToValidate');
665 if ($status == 1) return $langs->trans('Validated');
666 }
667 if ($mode == 1)
668 {
669 if ($status == 0) return $langs->trans('ToValidate');
670 if ($status == 1) return $langs->trans('Validated');
671 }
672 if ($mode == 2)
673 {
674 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
675 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
676 }
677 if ($mode == 3)
678 {
679 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
680 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
681 }
682 if ($mode == 4)
683 {
684 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
685 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
686 }
687 if ($mode == 5)
688 {
689 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
690 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
691 }
692 if ($mode == 6)
693 {
694 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
695 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
696 }*/
697 return '';
698 }
699
700
711 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
712 {
713 global $langs, $conf, $hookmanager;
714
715 if (!empty($conf->dol_no_mouse_hover)) {
716 $notooltip = 1; // Force disable tooltips
717 }
718
719 $result = '';
720
721 $text = $this->ref; // Sometimes ref contains label
722 $reg = array();
723 if (preg_match('/^\‍((.*)\‍)$/i', $text, $reg)) {
724 // Label generique car entre parentheses. On l'affiche en le traduisant
725 if ($reg[1] == 'paiement') {
726 $reg[1] = 'Payment';
727 }
728 $text = $langs->trans($reg[1]);
729 }
730
731 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
732 $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$text;
733 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
734 if ($dateofpayment) {
735 $label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($dateofpayment, 'dayhour', 'tzuser');
736 }
737 if ($this->amount) {
738 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
739 }
740
741 $linkclose = '';
742 if (empty($notooltip)) {
743 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
744 $label = $langs->trans("Payment");
745 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
746 }
747 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
748 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
749 } else {
750 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
751 }
752
753 $linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$this->id.'"';
754 $linkstart .= $linkclose.'>';
755 $linkend = '</a>';
756
757 $result .= $linkstart;
758 if ($withpicto) {
759 $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);
760 }
761 if ($withpicto != 2) {
762 $result .= $this->ref;
763 }
764 $result .= $linkend;
765
766 global $action;
767 $hookmanager->initHooks(array($this->element . 'dao'));
768 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
769 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
770 if ($reshook > 0) {
771 $result = $hookmanager->resPrint;
772 } else {
773 $result .= $hookmanager->resPrint;
774 }
775 return $result;
776 }
777
786 public function initAsSpecimen($option = '')
787 {
788 $now = dol_now();
789 $arraynow = dol_getdate($now);
790 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
791
792 // Initialize parameters
793 $this->id = 0;
794 $this->ref = 'SPECIMEN';
795 $this->specimen = 1;
796 $this->facid = 1;
797 $this->socid = 1;
798 $this->datepaye = $nownotime;
799
800 return 1;
801 }
802
811 public function getNextNumRef($soc, $mode = 'next')
812 {
813 global $conf, $db, $langs;
814 $langs->load("bills");
815
816 // Clean parameters (if not defined or using deprecated value)
817 if (!getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
818 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
819 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'brodator') {
820 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator';
821 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'bronan') {
822 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
823 }
824
825 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
826 $mybool = false;
827
828 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
829 $classname = getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
830
831 // Include file with class
832 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
833
834 foreach ($dirmodels as $reldir) {
835 $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
836
837 // Load file with numbering class (if found)
838 if (is_file($dir.$file) && is_readable($dir.$file)) {
839 $mybool = ((bool) @include_once $dir.$file) || $mybool;
840 }
841 }
842
843 // For compatibility
844 if (!$mybool) {
845 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
846 $classname = "mod_supplier_payment_" . getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
847 $classname = preg_replace('/\-.*$/', '', $classname);
848 // Include file with class
849 foreach ($conf->file->dol_document_root as $dirroot) {
850 $dir = $dirroot."/core/modules/supplier_payment/";
851
852 // Load file with numbering class (if found)
853 if (is_file($dir.$file) && is_readable($dir.$file)) {
854 $mybool = ((bool) @include_once $dir.$file) || $mybool;
855 }
856 }
857 }
858
859 if (!$mybool) {
860 dol_print_error(null, "Failed to include file ".$file);
861 return '';
862 }
863
864 $obj = new $classname();
865 '@phan-var-force ModeleNumRefSupplierPayments $obj';
866 $numref = $obj->getNextValue($soc, $this);
867
872 if ($mode != 'last' && !$numref) {
873 dol_print_error($db, "SupplierPayment::getNextNumRef ".$obj->error);
874 return "";
875 }
876
877 return $numref;
878 } else {
879 $langs->load("errors");
880 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Supplier"));
881 return "";
882 }
883 }
884
896 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
897 {
898 global $conf, $user, $langs;
899
900 $langs->load("suppliers");
901
902 // Set the model on the model name to use
903 if (empty($modele)) {
904 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF')) {
905 $modele = getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF');
906 } else {
907 $modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation
908 }
909 }
910
911 if (empty($modele)) {
912 return 0;
913 } else {
914 $modelpath = "core/modules/supplier_payment/doc/";
915
916 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
917 }
918 }
919
920
921
927 public function getWay()
928 {
929 global $conf;
930
931 $way = 'dolibarr';
932 if (isModEnabled("multicurrency")) {
933 foreach ($this->multicurrency_amounts as $value) {
934 if (!empty($value)) { // one value found then payment is in invoice currency
935 $way = 'customer';
936 break;
937 }
938 }
939 }
940
941 return $way;
942 }
943
944
945 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
952 public function fetch_thirdparty($force_thirdparty_id = 0)
953 {
954 // phpcs:enable
955 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
956
957 if (empty($force_thirdparty_id)) {
958 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
959 if (!empty($billsarray)) {
960 $supplier_invoice = new FactureFournisseur($this->db);
961 if ($supplier_invoice->fetch($billsarray[0]) > 0) {
962 $force_thirdparty_id = $supplier_invoice->socid;
963 }
964 }
965 }
966
967 return parent::fetch_thirdparty($force_thirdparty_id);
968 }
969}
$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.
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.
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.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:466
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:464