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