dolibarr 21.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-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
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 est le rowid du paiement
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($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
318 // Loop on each vat rate
319 $i = 0;
320 foreach ($invoice->lines as $line) {
321 if ($line->total_ht != 0) { // no need to create discount if amount is null
322 if (!array_key_exists($line->tva_tx, $amount_ht)) {
323 $amount_ht[$line->tva_tx] = 0.0;
324 $amount_tva[$line->tva_tx] = 0.0;
325 $amount_ttc[$line->tva_tx] = 0.0;
326 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
327 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
328 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
329 }
330 $amount_ht[$line->tva_tx] += $line->total_ht;
331 $amount_tva[$line->tva_tx] += $line->total_tva;
332 $amount_ttc[$line->tva_tx] += $line->total_ttc;
333 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
334 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
335 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
336 $i++;
337 }
338 }
339
340 foreach ($amount_ht as $tva_tx => $xxx) {
341 $discount->amount_ht = abs($amount_ht[$tva_tx]);
342 $discount->amount_tva = abs($amount_tva[$tva_tx]);
343 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
344 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
345 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
346 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
347 $discount->tva_tx = abs((float) $tva_tx);
348
349 $result = $discount->create($user);
350 if ($result < 0) {
351 $error++;
352 break;
353 }
354 }
355 }
356
357 if ($error) {
358 setEventMessages($discount->error, $discount->errors, 'errors');
359 $error++;
360 }
361 }
362
363 // Set invoice to paid
364 if (!$error) {
365 $result = $invoice->setPaid($user, '', '');
366 if ($result < 0) {
367 $this->error = $invoice->error;
368 $error++;
369 }
370 }
371 } else {
372 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
373 global $hookmanager;
374 $hookmanager->initHooks(array('payment_supplierdao'));
375 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
376 $action = 'CLOSEPAIDSUPPLIERINVOICE';
377 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
378 if ($reshook < 0) {
379 $this->error = $hookmanager->error;
380 $error++;
381 } elseif ($reshook == 0) {
382 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
383 }
384 }
385 }
386
387 // Regenerate documents of invoices
388 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
389 $newlang = '';
390 $outputlangs = $langs;
391 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
392 $invoice->fetch_thirdparty();
393 $newlang = $invoice->thirdparty->default_lang;
394 }
395 if (!empty($newlang)) {
396 $outputlangs = new Translate("", $conf);
397 $outputlangs->setDefaultLang($newlang);
398 }
399 $ret = $invoice->fetch($facid); // Reload to get new records
400 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs);
401 if ($result < 0) {
402 setEventMessages($invoice->error, $invoice->errors, 'errors');
403 $error++;
404 }
405 }
406 } else {
407 $this->error = $this->db->lasterror();
408 $error++;
409 }
410 } else {
411 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
412 }
413 }
414
415 if (!$error) {
416 // Call trigger
417 $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user);
418 if ($result < 0) {
419 $error++;
420 }
421 // End call triggers
422 }
423 } else {
424 $this->error = $this->db->lasterror();
425 $error++;
426 }
427 } else {
428 $this->error = "ErrorTotalIsNull";
429 dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
430 $error++;
431 }
432
433 if ($totalamount != 0 && $error == 0) { // On accepte les montants negatifs
434 $this->amount = $total;
435 $this->total = $total;
436 $this->multicurrency_amount = $mtotal;
437 $this->db->commit();
438 dol_syslog('PaiementFourn::Create Ok Total = '.$this->amount.', Total currency = '.$this->multicurrency_amount);
439 return $this->id;
440 } else {
441 $this->db->rollback();
442 return -1;
443 }
444 }
445
446
456 public function delete($user = null, $notrigger = 0)
457 {
458 if (empty($user)) {
459 global $user;
460 }
461
462 $bank_line_id = $this->bank_line;
463
464 $this->db->begin();
465
466 // Verifier si paiement porte pas sur une facture a l'etat payee
467 // Si c'est le cas, on refuse la suppression
468 $billsarray = $this->getBillsArray('paye=1');
469 if (is_array($billsarray)) {
470 if (count($billsarray)) {
471 $this->error = "ErrorCantDeletePaymentSharedWithPayedInvoice";
472 $this->db->rollback();
473 return -1;
474 }
475 } else {
476 $this->db->rollback();
477 return -2;
478 }
479
480 // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee
481 // Si c'est le cas, on refuse le delete
482 if ($bank_line_id) {
483 $accline = new AccountLine($this->db);
484 $accline->fetch($bank_line_id);
485 if ($accline->rappro) {
486 $this->error = "ErrorCantDeletePaymentReconciliated";
487 $this->db->rollback();
488 return -3;
489 }
490 }
491
492 // Efface la ligne de paiement (dans paiement_facture et paiement)
493 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
494 $sql .= ' WHERE fk_paiementfourn = '.((int) $this->id);
495 $resql = $this->db->query($sql);
496 if ($resql) {
497 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn';
498 $sql .= " WHERE rowid = ".((int) $this->id);
499 $result = $this->db->query($sql);
500 if (!$result) {
501 $this->error = $this->db->error();
502 $this->db->rollback();
503 return -3;
504 }
505
506 // Supprimer l'ecriture bancaire si paiement lie a ecriture
507 if ($bank_line_id) {
508 $accline = new AccountLine($this->db);
509 $result = $accline->fetch($bank_line_id);
510 if ($result > 0) { // If result = 0, record not found, we don't try to delete
511 $result = $accline->delete($user);
512 }
513 if ($result < 0) {
514 $this->error = $accline->error;
515 $this->db->rollback();
516 return -4;
517 }
518 }
519
520 if (!$notrigger) {
521 // Appel des triggers
522 $result = $this->call_trigger('PAYMENT_SUPPLIER_DELETE', $user);
523 if ($result < 0) {
524 $this->db->rollback();
525 return -1;
526 }
527 // Fin appel triggers
528 }
529
530 $this->db->commit();
531 return 1;
532 } else {
533 $this->error = $this->db->error;
534 $this->db->rollback();
535 return -5;
536 }
537 }
538
545 public function info($id)
546 {
547 $sql = 'SELECT c.rowid, datec, fk_user_author as fk_user_creat, tms as fk_user_modif';
548 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as c';
549 $sql .= ' WHERE c.rowid = '.((int) $id);
550
551 $resql = $this->db->query($sql);
552 if ($resql) {
553 $num = $this->db->num_rows($resql);
554 if ($num) {
555 $obj = $this->db->fetch_object($resql);
556
557 $this->id = $obj->rowid;
558 $this->user_creation_id = $obj->fk_user_creat;
559 $this->user_modification_id = $obj->fk_user_modif;
560 $this->date_creation = $this->db->jdate($obj->datec);
561 $this->date_modification = $this->db->jdate($obj->tms);
562 }
563 $this->db->free($resql);
564 } else {
565 dol_print_error($this->db);
566 }
567 }
568
575 public function getBillsArray($filter = '')
576 {
577 $sql = 'SELECT fk_facturefourn';
578 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f';
579 $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.((int) $this->id);
580 if ($filter) {
581 $sql .= " AND ".$filter;
582 }
583
584 dol_syslog(get_class($this).'::getBillsArray', LOG_DEBUG);
585 $resql = $this->db->query($sql);
586 if ($resql) {
587 $i = 0;
588 $num = $this->db->num_rows($resql);
589 $billsarray = array();
590
591 while ($i < $num) {
592 $obj = $this->db->fetch_object($resql);
593 $billsarray[$i] = $obj->fk_facturefourn;
594 $i++;
595 }
596
597 return $billsarray;
598 } else {
599 $this->error = $this->db->error();
600 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error);
601 return -1;
602 }
603 }
604
611 public function getLibStatut($mode = 0)
612 {
613 return $this->LibStatut($this->statut, $mode);
614 }
615
616 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
624 public function LibStatut($status, $mode = 0)
625 {
626 // phpcs:enable
627 global $langs;
628
629 $langs->load('compta');
630 /*if ($mode == 0)
631 {
632 if ($status == 0) return $langs->trans('ToValidate');
633 if ($status == 1) return $langs->trans('Validated');
634 }
635 if ($mode == 1)
636 {
637 if ($status == 0) return $langs->trans('ToValidate');
638 if ($status == 1) return $langs->trans('Validated');
639 }
640 if ($mode == 2)
641 {
642 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
643 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
644 }
645 if ($mode == 3)
646 {
647 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
648 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
649 }
650 if ($mode == 4)
651 {
652 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
653 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
654 }
655 if ($mode == 5)
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 if ($mode == 6)
661 {
662 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
663 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
664 }*/
665 return '';
666 }
667
668
679 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
680 {
681 global $langs, $conf, $hookmanager;
682
683 if (!empty($conf->dol_no_mouse_hover)) {
684 $notooltip = 1; // Force disable tooltips
685 }
686
687 $result = '';
688
689 $text = $this->ref; // Sometimes ref contains label
690 $reg = array();
691 if (preg_match('/^\‍((.*)\‍)$/i', $text, $reg)) {
692 // Label generique car entre parentheses. On l'affiche en le traduisant
693 if ($reg[1] == 'paiement') {
694 $reg[1] = 'Payment';
695 }
696 $text = $langs->trans($reg[1]);
697 }
698
699 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
700 $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$text;
701 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
702 if ($dateofpayment) {
703 $label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($dateofpayment, 'dayhour', 'tzuser');
704 }
705 if ($this->amount) {
706 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
707 }
708
709 $linkclose = '';
710 if (empty($notooltip)) {
711 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
712 $label = $langs->trans("Payment");
713 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
714 }
715 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
716 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
717 } else {
718 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
719 }
720
721 $linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$this->id.'"';
722 $linkstart .= $linkclose.'>';
723 $linkend = '</a>';
724
725 $result .= $linkstart;
726 if ($withpicto) {
727 $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);
728 }
729 if ($withpicto != 2) {
730 $result .= $this->ref;
731 }
732 $result .= $linkend;
733
734 global $action;
735 $hookmanager->initHooks(array($this->element . 'dao'));
736 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
737 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
738 if ($reshook > 0) {
739 $result = $hookmanager->resPrint;
740 } else {
741 $result .= $hookmanager->resPrint;
742 }
743 return $result;
744 }
745
754 public function initAsSpecimen($option = '')
755 {
756 $now = dol_now();
757 $arraynow = dol_getdate($now);
758 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
759
760 // Initialize parameters
761 $this->id = 0;
762 $this->ref = 'SPECIMEN';
763 $this->specimen = 1;
764 $this->facid = 1;
765 $this->socid = 1;
766 $this->datepaye = $nownotime;
767
768 return 1;
769 }
770
779 public function getNextNumRef($soc, $mode = 'next')
780 {
781 global $conf, $db, $langs;
782 $langs->load("bills");
783
784 // Clean parameters (if not defined or using deprecated value)
785 if (!getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
786 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
787 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'brodator') {
788 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator';
789 } elseif (getDolGlobalString('SUPPLIER_PAYMENT_ADDON') == 'bronan') {
790 $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
791 }
792
793 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON')) {
794 $mybool = false;
795
796 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
797 $classname = getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
798
799 // Include file with class
800 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
801
802 foreach ($dirmodels as $reldir) {
803 $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
804
805 // Load file with numbering class (if found)
806 if (is_file($dir.$file) && is_readable($dir.$file)) {
807 $mybool = ((bool) @include_once $dir.$file) || $mybool;
808 }
809 }
810
811 // For compatibility
812 if (!$mybool) {
813 $file = getDolGlobalString('SUPPLIER_PAYMENT_ADDON') . ".php";
814 $classname = "mod_supplier_payment_" . getDolGlobalString('SUPPLIER_PAYMENT_ADDON');
815 $classname = preg_replace('/\-.*$/', '', $classname);
816 // Include file with class
817 foreach ($conf->file->dol_document_root as $dirroot) {
818 $dir = $dirroot."/core/modules/supplier_payment/";
819
820 // Load file with numbering class (if found)
821 if (is_file($dir.$file) && is_readable($dir.$file)) {
822 $mybool = ((bool) @include_once $dir.$file) || $mybool;
823 }
824 }
825 }
826
827 if (!$mybool) {
828 dol_print_error(null, "Failed to include file ".$file);
829 return '';
830 }
831
832 $obj = new $classname();
833 '@phan-var-force ModeleNumRefSupplierPayments $obj';
834 $numref = $obj->getNextValue($soc, $this);
835
840 if ($mode != 'last' && !$numref) {
841 dol_print_error($db, "SupplierPayment::getNextNumRef ".$obj->error);
842 return "";
843 }
844
845 return $numref;
846 } else {
847 $langs->load("errors");
848 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Supplier"));
849 return "";
850 }
851 }
852
864 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
865 {
866 global $conf, $user, $langs;
867
868 $langs->load("suppliers");
869
870 // Set the model on the model name to use
871 if (empty($modele)) {
872 if (getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF')) {
873 $modele = getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF');
874 } else {
875 $modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation
876 }
877 }
878
879 if (empty($modele)) {
880 return 0;
881 } else {
882 $modelpath = "core/modules/supplier_payment/doc/";
883
884 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
885 }
886 }
887
888
889
895 public function getWay()
896 {
897 global $conf;
898
899 $way = 'dolibarr';
900 if (isModEnabled("multicurrency")) {
901 foreach ($this->multicurrency_amounts as $value) {
902 if (!empty($value)) { // one value found then payment is in invoice currency
903 $way = 'customer';
904 break;
905 }
906 }
907 }
908
909 return $way;
910 }
911
912
913 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
920 public function fetch_thirdparty($force_thirdparty_id = 0)
921 {
922 // phpcs:enable
923 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
924
925 if (empty($force_thirdparty_id)) {
926 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
927 if (!empty($billsarray)) {
928 $supplier_invoice = new FactureFournisseur($this->db);
929 if ($supplier_invoice->fetch($billsarray[0]) > 0) {
930 $force_thirdparty_id = $supplier_invoice->socid;
931 }
932 }
933 }
934
935 return parent::fetch_thirdparty($force_thirdparty_id);
936 }
937}
$object ref
Definition info.php:89
Class to manage bank accounts.
Class to manage bank transaction lines.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage absolute discounts.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
static 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79