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