dolibarr 25.0.0-alpha
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2023 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
7 * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
33// Load Dolibarr environment
34require '../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
43require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
46if (isModEnabled("bank")) {
47 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
48}
49if (isModEnabled('margin')) {
50 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
51}
52
53// Load translation files required by the page
54$langs->loadLangs(array('bills', 'banks', 'companies'));
55
56$id = GETPOSTINT('id');
57$ref = GETPOST('ref', 'alpha');
58$action = GETPOST('action', 'aZ09');
59$confirm = GETPOST('confirm', 'alpha');
60$backtopage = GETPOST('backtopage', 'alpha');
61
62$socid = GETPOSTINT('socid');
63if ($socid < 0) {
64 $socid = 0;
65}
66
67$object = new Paiement($db);
68// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
69$hookmanager->initHooks(array('paymentcard', 'globalcard'));
70
71// Load object
72include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
73
74$result = restrictedArea($user, $object->element, $object->id, 'paiement'); // This also test permission on read invoice
75
76// Security check
77if ($user->socid) {
78 $socid = $user->socid;
79}
80// Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
81// It should be enough because all payments are done on invoices of the same thirdparty.
82if ($socid && $socid != $object->thirdparty->id) {
84}
85
86$stripecu = null;
87$stripeacc = null;
88
89// Init Stripe objects
90if (isModEnabled('stripe')) {
91 require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
92
93 $service = 'StripeTest';
94 $servicestatus = 0;
95 if (getDolGlobalString('STRIPE_LIVE')/* && !GETPOST('forcesandbox', 'alpha')*/) {
96 $service = 'StripeLive';
97 $servicestatus = 1;
98 }
99
100 // Force to use the correct API key
101 global $stripearrayofkeysbyenv;
102 $site_account = $stripearrayofkeysbyenv[$servicestatus]['publishable_key'];
103
104 $stripe = new Stripe($db);
105 $stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account (no remote access to Stripe here)
106}
107
108$error = 0;
109
110/*
111 * Actions
112 */
113$parameters = array('socid' => $socid);
114$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
115if ($reshook < 0) {
116 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
117}
118
119if (empty($reshook)) {
120 if ($action == 'setnote' && $user->hasRight('facture', 'paiement')) {
121 $db->begin();
122
123 $result = $object->update_note(GETPOST('note', 'restricthtml'));
124 if ($result > 0) {
125 $db->commit();
126 $action = '';
127 } else {
128 setEventMessages($object->error, $object->errors, 'errors');
129 $db->rollback();
130 }
131 }
132
133 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('facture', 'paiement')) {
134 $db->begin();
135
136 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
137 $result = $object->delete($user);
138 if ($result > 0) {
139 $db->commit();
140
141 if ($backtopage) {
142 header("Location: ".$backtopage);
143 exit;
144 } else {
145 header("Location: list.php");
146 exit;
147 }
148 } else {
149 $langs->load("errors");
150 setEventMessages($object->error, $object->errors, 'errors');
151 $db->rollback();
152 }
153 }
154
155 if ($action == 'confirm_validate' && $confirm == 'yes' && $user->hasRight('facture', 'paiement')) {
156 $db->begin();
157
158 if ($object->validate($user) > 0) {
159 $db->commit();
160
161 // Loop on each invoice linked to this payment to rebuild PDF
162 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
163 $outputlangs = $langs;
164 if (GETPOST('lang_id', 'aZ09')) {
165 $outputlangs = new Translate("", $conf);
166 $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
167 }
168
169 $hidedetails = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0;
170 $hidedesc = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0;
171 $hideref = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0;
172
173 $sql = 'SELECT f.rowid as facid';
174 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
175 $sql .= ' WHERE pf.fk_facture = f.rowid';
176 $sql .= ' AND f.fk_soc = s.rowid';
177 $sql .= ' AND f.entity IN ('.getEntity('invoice').')';
178 $sql .= ' AND pf.fk_paiement = '.((int) $object->id);
179 $resql = $db->query($sql);
180 if ($resql) {
181 $i = 0;
182 $num = $db->num_rows($resql);
183
184 if ($num > 0) {
185 while ($i < $num) {
186 $objp = $db->fetch_object($resql);
187
188 $invoice = new Facture($db);
189
190 if ($invoice->fetch($objp->facid) <= 0) {
191 $error++;
192 setEventMessages($invoice->error, $invoice->errors, 'errors');
193 break;
194 }
195
196 if ($invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref) < 0) {
197 $error++;
198 setEventMessages($invoice->error, $invoice->errors, 'errors');
199 break;
200 }
201
202 $i++;
203 }
204 }
205
206 $db->free($resql);
207 } else {
208 $error++;
209 setEventMessages($db->error, null, 'errors');
210 }
211 }
212
213 if (! $error) {
214 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
215 exit;
216 }
217 } else {
218 $db->rollback();
219
220 $langs->load("errors");
221 setEventMessages($object->error, $object->errors, 'errors');
222 }
223 }
224
225 if ($action == 'setnum_paiement' && GETPOST('num_paiement') && $user->hasRight('facture', 'paiement')) {
226 $res = $object->update_num(GETPOST('num_paiement'));
227 if ($res === 0) {
228 setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
229 } else {
230 setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
231 }
232 }
233
234 if ($action == 'setdatep' && GETPOST('datepday') && $user->hasRight('facture', 'paiement')) {
235 $datepaye = dol_mktime(GETPOSTINT('datephour'), GETPOSTINT('datepmin'), GETPOSTINT('datepsec'), GETPOSTINT('datepmonth'), GETPOSTINT('datepday'), GETPOSTINT('datepyear'));
236 $res = $object->update_date($datepaye);
237 if ($res === 0) {
238 setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
239 } else {
240 setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
241 }
242 }
243
244 if ($action == 'createbankpayment' && $user->hasRight('facture', 'paiement')) {
245 $db->begin();
246
247 // Create the record into bank for the amount of payment $object
248 if (!$error) {
249 $label = '(CustomerInvoicePayment)';
250 if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) {
251 $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
252 }
253
254 $bankaccountid = GETPOSTINT('accountid');
255 if ($bankaccountid > 0) {
256 $object->paiementcode = $object->type_code;
257 $object->amounts = $object->getAmountsArray();
258
259 $result = $object->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
260 if ($result < 0) {
261 setEventMessages($object->error, $object->errors, 'errors');
262 $error++;
263 }
264 } else {
265 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
266 $error++;
267 }
268 }
269
270 if (!$error) {
271 $db->commit();
272 } else {
273 $db->rollback();
274 }
275 }
276}
277
278/*
279 * View
280 */
281
282llxHeader('', $langs->trans("Payment"));
283
284$thirdpartystatic = new Societe($db);
285
286$result = $object->fetch($id, $ref);
287if ($result <= 0) {
288 recordNotFound('', 0);
289}
290
291$form = new Form($db);
292
293$head = payment_prepare_head($object);
294
295print dol_get_fiche_head($head, 'payment', $langs->trans("PaymentCustomerInvoice"), -1, 'payment', 0, '', '', 0, '', 1);
296
297// Confirmation of payment delete
298if ($action == 'delete') {
299 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
300}
301
302// Confirmation of payment validation
303if ($action == 'valide') {
304 $facid = GETPOSTINT('facid');
305 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&facid='.((int) $facid), $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_validate', '', 0, 2);
306}
307
308$linkback = '<a href="'.DOL_URL_ROOT.'/compta/paiement/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
309
310dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
311
312
313print '<div class="fichecenter">';
314print '<div class="underbanner clearboth"></div>';
315
316print '<table class="border tableforfield centpercent">'."\n";
317
318// Date payment
319print '<tr><td class="titlefield">'.$form->editfieldkey("Date", 'datep', $object->date, $object, $user->hasRight('facture', 'paiement')).'</td><td>';
320print $form->editfieldval("Date", 'datep', $object->date, $object, $user->hasRight('facture', 'paiement'), 'datehourpicker', '', null, $langs->trans('PaymentDateUpdateSucceeded'), '', 0, '', 'id', 'tzuser');
321print '</td></tr>';
322
323// Payment type (VIR, LIQ, ...)
324$labeltype = $langs->trans("PaymentType".$object->type_code) != "PaymentType".$object->type_code ? $langs->trans("PaymentType".$object->type_code) : $object->type_label;
325print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>'.$labeltype;
326print $object->num_payment ? ' - '.$object->num_payment : '';
327print '</td></tr>';
328
329// Payment number
330$titlefield=$langs->trans('Numero').' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
331print '<tr><td>'.$form->editfieldkey($titlefield, 'num_paiement', $object->num_payment, $object, $object->statut == 0 && $user->hasRight("facture", "creer")).'</td><td>';
332print $form->editfieldval($titlefield, 'num_paiement', $object->num_payment, $object, $object->statut == 0 && $user->hasRight("facture", "creer"), 'string', '', null, $langs->trans('PaymentNumberUpdateSucceeded'));
333print '</td></tr>';
334
335// Amount
336print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $langs, 0, -1, -1, $conf->currency).'</td></tr>';
337
338$disable_delete = 0;
339$bankline = null;
340
341// Bank account
342if (isModEnabled("bank")) {
343 $bankline = new AccountLine($db);
344
345 if ($object->fk_account > 0) {
346 $bankline->fetch($object->bank_line);
347 if ($bankline->rappro) {
348 $disable_delete = 1;
349 $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
350 }
351
352 print '<tr>';
353 print '<td>'.$langs->trans('BankAccount').'</td>';
354 print '<td>';
355 $accountstatic = new Account($db);
356 $accountstatic->fetch($bankline->fk_account);
357 print $accountstatic->getNomUrl(1);
358 print '</td>';
359 print '</tr>';
360 }
361}
362
363// Payment numero
364/*
365$titlefield=$langs->trans('Numero').' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
366print '<tr><td>'.$form->editfieldkey($titlefield,'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
367print $form->editfieldval($titlefield,'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
368print '</td></tr>';
369
370// Check transmitter
371$titlefield=$langs->trans('CheckTransmitter').' <em>('.$langs->trans("ChequeMaker").')</em>';
372print '<tr><td>'.$form->editfieldkey($titlefield,'chqemetteur',$object->,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
373print $form->editfieldval($titlefield,'chqemetteur',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('ChequeMakeUpdateSucceeded'));
374print '</td></tr>';
375
376// Bank name
377$titlefield=$langs->trans('Bank').' <em>('.$langs->trans("ChequeBank").')</em>';
378print '<tr><td>'.$form->editfieldkey($titlefield,'chqbank',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td>';
379print $form->editfieldval($titlefield,'chqbank',$object->aaa,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('ChequeBankUpdateSucceeded'));
380print '</td></tr>';
381*/
382
383// Bank account
384if (isModEnabled("bank")) {
385 if ($object->fk_account > 0) {
386 if ($object->type_code == 'CHQ' && $bankline->fk_bordereau > 0) {
387 include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
388 $bordereau = new RemiseCheque($db);
389 $bordereau->fetch($bankline->fk_bordereau);
390
391 print '<tr>';
392 print '<td>'.$langs->trans('CheckReceipt').'</td>';
393 print '<td>';
394 print $bordereau->getNomUrl(1);
395 print '</td>';
396 print '</tr>';
397 }
398 }
399
400 print '<tr>';
401 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
402 print '<td>';
403 if ($object->fk_account > 0 && $bankline !== null) {
404 print $bankline->getNomUrl(1, 0, 'showconciliatedandaccounted');
405 } else {
406 $langs->load("admin");
407 print '<span class="opacitymedium">';
408 print $langs->trans("NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv("Module85Name"));
409 print '</span>';
410 if ($user->hasRight('facture', 'paiement')) {
411 // Try to guess $bankaccountidofinvoices that is ID of bank account defined on invoice.
412 // Return null if not found, return 0 if it has different value for at least 2 invoices, return the value if same on all invoices where a bank is defined.
413 $amountofpayments = $object->getAmountsArray();
414 $bankaccountidofinvoices = null;
415 foreach ($amountofpayments as $idinvoice => $amountofpayment) {
416 $tmpinvoice = new Facture($db);
417 $tmpinvoice->fetch($idinvoice);
418 if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
419 if (is_null($bankaccountidofinvoices)) {
420 $bankaccountidofinvoices = $tmpinvoice->fk_account;
421 } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
422 $bankaccountidofinvoices = 0;
423 }
424 }
425 }
426
427 print '<form method="POST" name="createbankpayment">';
428 print '<input type="hidden" name="token" value="'.newToken().'">';
429 print '<input type="hidden" name="action" value="createbankpayment">';
430 print '<input type="hidden" name="id" value="'.$object->id.'">';
431 print ' '.$langs->trans("ToCreateRelatedRecordIntoBank").': ';
432 print $form->select_comptes($bankaccountidofinvoices, 'accountid', 0, '', 2, '', 0, '', 1);
433 //print '<span class="opacitymedium">';
434 print '<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans("ClickHere").'">';
435 //print '</span>';
436 print '</form>';
437 }
438 }
439 print '</td>';
440 print '</tr>';
441}
442
443// Comments
444print '<tr><td class="'.($user->hasRight('facture', 'paiement') ? 'tdtop' : '').'">'.$form->editfieldkey("Comments", 'note', $object->note_private, $object, $user->hasRight('facture', 'paiement'), 'string', '', 0, 0).'</td><td class="wordbreak">';
445print $form->editfieldval("Note", 'note', $object->note_private, $object, $user->hasRight('facture', 'paiement'), 'textarea:'.ROWS_3.':90%');
446print '</td></tr>';
447
448if (!empty($object->ext_payment_id)) {
449 // External payment ID
450 print '<tr><td class="tdtop">'.$langs->trans("StripePaymentId").'</td><td class="wordbreak">';
451 if (isModEnabled('stripe') && in_array($object->ext_payment_site, array('Stripe', 'StripeLive'))) {
452 $tmp1 = explode('@', $object->ext_payment_id);
453 $site_account_payment = '';
454 if (!empty($tmp1[1])) {
455 $site_account_payment = $tmp1[1]; // pk_live_...
456 }
457 $tmp2 = explode(':', $tmp1[0]);
458 if (!empty($tmp2[1])) {
459 $stripecu = $tmp2[1];
460 }
461
462 print dol_escape_htmltag($tmp1[0]);
463
464 $connect = '';
465 if (!empty($stripeacc)) {
466 $connect = $stripeacc.'/';
467 }
468
469 if ($stripecu) {
470 $url = 'https://dashboard.stripe.com/'.$connect.($object->ext_payment_site == 'Stripe' ? 'test/' : '').'customers/'.$stripecu;
471 if (!empty($stripearrayofkeysbyenv[1]['publishable_key']) && $stripearrayofkeysbyenv[1]['publishable_key'] == $site_account_payment) {
472 $url = 'https://dashboard.stripe.com/'.$connect.'customers/'.$stripecu;
473 }
474 } else {
475 $url = 'https://dashboard.stripe.com/'.($object->ext_payment_site == 'Stripe' ? 'test/' : '').'payments/'.$object->ext_payment_id;
476 }
477
478 print ' <a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe').' - Publishable key = '.$site_account_payment, 'globe').'</a>';
479 } else {
480 print dol_escape_htmltag($object->ext_payment_id);
481 }
482 print '</td></tr>';
483}
484
485// Other attributes
486$cols = 2;
487include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
488
489// Other attributes
490$parameters = array();
491$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
492print $hookmanager->resPrint;
493
494print '</table>';
495
496print '</div>';
497
498print dol_get_fiche_end();
499
500
501/*
502 * List of invoices
503 */
504
505$sql = 'SELECT f.rowid as facid, f.ref, f.type, f.total_ttc, f.paye, f.entity, f.fk_statut, pf.amount, s.nom as name, s.rowid as socid';
506$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
507$sql .= ' WHERE pf.fk_facture = f.rowid';
508$sql .= ' AND f.fk_soc = s.rowid';
509$sql .= ' AND f.entity IN ('.getEntity('invoice').')';
510$sql .= ' AND pf.fk_paiement = '.((int) $object->id);
511$resql = $db->query($sql);
512if ($resql) {
513 $num = $db->num_rows($resql);
514
515 $i = 0;
516 $total = 0;
517
518 print '<br>';
519
520 print '<div class="div-table-responsive">';
521 print '<table class="noborder centpercent">';
522
523 print '<tr class="liste_titre">';
524 print '<td>'.$langs->trans('Bill').'</td>';
525 print '<td>'.$langs->trans('Company').'</td>';
526 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
527 print '<td>'.$langs->trans('Entity').'</td>';
528 }
529 //Add Margin
530 if (isModEnabled('margin') && getDolGlobalInt('MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
531 print '<td class="right">'.$langs->trans('Margin').'</td>';
532 }
533 print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
534 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
535 print '<td class="right">'.$langs->trans('RemainderToPay').'</td>';
536 print '<td class="right">'.$langs->trans('Status').'</td>';
537
538 $parameters = array();
539 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
540
541 print "</tr>\n";
542
543 if ($num > 0) {
544 while ($i < $num) {
545 $objp = $db->fetch_object($resql);
546
547 $thirdpartystatic->fetch($objp->socid);
548
549 $invoice = new Facture($db);
550 $invoice->fetch($objp->facid);
551 $marginInfo = null;
552
553 // Add Margin
554 if (isModEnabled('margin') && getDolGlobalInt('MARGIN_SHOW_MARGIN_ON_PAYMENT')) {
555 $formmargin = new FormMargin($db);
556 $marginInfo = array();
557 $invoice->fetch_lines();
558 $marginInfo = $formmargin->getMarginInfosArray($invoice);
559 }
560
561 $paiement = $invoice->getSommePaiement();
562 $creditnotes = $invoice->getSumCreditNotesUsed();
563 $deposits = $invoice->getSumDepositsUsed();
564 $alreadypaid = price2num($paiement + $creditnotes + $deposits, 'MT');
565 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
566
567 print '<tr class="oddeven">';
568
569 // Invoice
570 print '<td class="tdoverflowmax150">';
571 print $invoice->getNomUrl(1);
572 print "</td>\n";
573
574 // Third party
575 print '<td class="tdoverflowmax150">';
576 print $thirdpartystatic->getNomUrl(1);
577 print '</td>';
578
579 // Expected to pay
580 if (isModEnabled('multicompany') && isset($mc) && getDolGlobalString('MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
581 print '<td>';
582 $mc->getInfo($objp->entity);
583 print $mc->label;
584 print '</td>';
585 }
586
587 // Add margin
588 if (isModEnabled('margin') && getDolGlobalInt('MARGIN_SHOW_MARGIN_ON_PAYMENT') && $marginInfo !== null) {
589 print '<td class="right">'.price($marginInfo['total_margin']).'</td>';
590 }
591
592 // Expected to pay
593 print '<td class="right"><span class="amount">'.price($objp->total_ttc).'</span></td>';
594
595 // Amount paid
596 print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
597
598 // Remain to pay
599 print '<td class="right"><span class="amount">'.price($remaintopay).'</span></td>';
600
601 // Status
602 print '<td class="right">'.$invoice->getLibStatut(5, (float) $alreadypaid).'</td>';
603
604 $parameters = array('fk_paiement' => (int) $object->id);
605 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook
606
607 print "</tr>\n";
608
609 // If at least one invoice is paid, disable delete. INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED Can be use for maintenance purpose. Never use this in production
610 if ($objp->paye == 1 && !getDolGlobalString('INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED')) {
611 $disable_delete = 1;
612 $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
613 }
614
615 $total += $objp->amount;
616 $i++;
617 }
618 }
619
620
621 print "</table>\n";
622 print '</div>';
623
624 $db->free($resql);
625} else {
626 dol_print_error($db);
627}
628
629
630
631/*
632 * Actions Buttons
633 */
634
635print '<div class="tabsAction">';
636
637if (getDolGlobalString('BILL_ADD_PAYMENT_VALIDATION')) {
638 if ($user->socid == 0 && $object->statut == 0 && $action == '') {
639 if ($user->hasRight('facture', 'paiement')) {
640 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&action=valide&token='.newToken().'">'.$langs->trans('Valid').'</a>';
641 }
642 }
643}
644
645$params = array('attr' => array('class' => 'reposition'));
646if (! empty($title_button)) {
647 $params['attr']['title'] = $title_button;
648}
649
650if ($user->socid == 0 && $action == '') {
651 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $user->hasRight('facture', 'paiement') && !$disable_delete, $params)."\n";
652}
653
654print '</div>';
655
656// End of page
657llxFooter();
658$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage bank accounts.
Class to manage bank transaction lines.
Class to manage invoices.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage generation of HTML components Only common components must be here.
Class to manage "other" html components Only common components are here.
Class to manage payments of customer invoices.
Class to manage cheque delivery receipts.
Class to manage third parties objects (customers, suppliers, prospects...)
Stripe class @TODO No reason to extend CommonObject.
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:
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
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...
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.