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