dolibarr 21.0.0-beta
prelevement.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
4 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
8 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Load Dolibarr environment
32require '../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
38require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
39require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
40require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
41require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
42require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
43require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
44
45
55// Load translation files required by the page
56$langs->loadLangs(array('bills', 'banks', 'withdrawals', 'companies'));
57
58$id = (GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility
59$ref = GETPOST('ref', 'alpha');
60$socid = GETPOSTINT('socid');
61$action = GETPOST('action', 'aZ09');
62$type = GETPOST('type', 'aZ09');
63
64$fieldid = (!empty($ref) ? 'ref' : 'rowid');
65if ($user->socid) {
66 $socid = $user->socid;
67}
68
69$moreparam = '';
70if ($type == 'bank-transfer') {
71 $object = new FactureFournisseur($db);
72 $moreparam = '&type='.$type;
73} else {
74 $object = new Facture($db);
75}
76
77// Load object
78$isdraft = 1;
79if ($id > 0 || !empty($ref)) {
80 $ret = $object->fetch($id, $ref);
81 $isdraft = (($object->status == FactureFournisseur::STATUS_DRAFT) ? 1 : 0);
82 if ($ret > 0) {
83 $object->fetch_thirdparty();
84 }
85}
86
87$hookmanager->initHooks(array('directdebitcard', 'globalcard'));
88
89if ($type == 'bank-transfer') {
90 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture', 'fk_soc', $fieldid, $isdraft);
91 if (!$user->hasRight('fournisseur', 'facture', 'lire')) {
93 }
94} else {
95 $result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid, $isdraft);
96 if (!$user->hasRight('facture', 'lire')) {
98 }
99}
100
101if ($type == 'bank-transfer') {
102 $usercancreate = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
103} else {
104 $usercancreate = $user->hasRight('facture', 'creer');
105}
106
107
108/*
109 * Actions
110 */
111
112$parameters = array('socid' => $socid);
113$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
114if ($reshook < 0) {
115 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
116}
117
118if (empty($reshook)) {
119 if ($action == "new" && $usercancreate) {
120 if ($object->id > 0) {
121 $db->begin();
122
123 $newtype = $type;
124 $sourcetype = 'facture';
125 if ($type == 'bank-transfer') {
126 $sourcetype = 'supplier_invoice';
127 $newtype = 'bank-transfer';
128 }
129 $paymentservice = GETPOST('paymentservice');
130
131 // Get chosen iban id
132 $iban = GETPOSTINT('accountcustomerid');
133 $amount = GETPOST('withdraw_request_amount', 'alpha');
134 $result = $object->demande_prelevement($user, price2num($amount), $newtype, $sourcetype, 0, $iban ?? 0);
135
136 if ($result > 0) {
137 $db->commit();
138
139 setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
140 } else {
141 $db->rollback();
142 setEventMessages($object->error, $object->errors, 'errors');
143 }
144 }
145 $action = '';
146 }
147
148 if ($action == "delete" && $usercancreate) {
149 if ($object->id > 0) {
150 $result = $object->demande_prelevement_delete($user, GETPOSTINT('did'));
151 if ($result == 0) {
152 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id.'&type='.$type);
153 exit;
154 }
155 }
156 }
157
158 // Make payment with Direct Debit Stripe
159 if ($action == 'sepastripedirectdebit' && $usercancreate) {
160 $result = $object->makeStripeSepaRequest($user, GETPOSTINT('did'), 'direct-debit', 'facture');
161 if ($result < 0) {
162 setEventMessages($object->error, $object->errors, 'errors');
163 } else {
164 // We refresh object data
165 $ret = $object->fetch($id, $ref);
166 $isdraft = (($object->status == Facture::STATUS_DRAFT) ? 1 : 0);
167 if ($ret > 0) {
168 $object->fetch_thirdparty();
169 }
170 }
171 }
172
173 // Make payment with Direct Debit Stripe
174 if ($action == 'sepastripecredittransfer' && $usercancreate) {
175 $result = $object->makeStripeSepaRequest($user, GETPOSTINT('did'), 'bank-transfer', 'supplier_invoice');
176 if ($result < 0) {
177 setEventMessages($object->error, $object->errors, 'errors');
178 } else {
179 // We refresh object data
180 $ret = $object->fetch($id, $ref);
181 $isdraft = (($object->status == FactureFournisseur::STATUS_DRAFT) ? 1 : 0);
182 if ($ret > 0) {
183 $object->fetch_thirdparty();
184 }
185 }
186 }
187
188 // Set payments conditions
189 if ($action == 'setconditions' && $usercancreate) {
190 $object->fetch($id);
191 $object->cond_reglement_code = 0; // To clean property
192 $object->cond_reglement_id = 0; // To clean property
193
194 $error = 0;
195
196 $db->begin();
197
198 if (!$error) {
199 $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_id'));
200 if ($result < 0) {
201 $error++;
202 setEventMessages($object->error, $object->errors, 'errors');
203 }
204 }
205
206 if (!$error) {
207 $old_date_echeance = $object->date_echeance;
208 $new_date_echeance = $object->calculate_date_lim_reglement();
209 if ($new_date_echeance > $old_date_echeance) {
210 $object->date_echeance = $new_date_echeance;
211 }
212 if ($object->date_echeance < $object->date) {
213 $object->date_echeance = $object->date;
214 }
215 $result = $object->update($user);
216 if ($result < 0) {
217 $error++;
218 setEventMessages($object->error, $object->errors, 'errors');
219 }
220 }
221
222 if ($error) {
223 $db->rollback();
224 } else {
225 $db->commit();
226 }
227 } elseif ($action == 'setmode' && $usercancreate) {
228 // payment mode
229 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
230 } elseif ($action == 'setdatef' && $usercancreate) {
231 $newdate = dol_mktime(0, 0, 0, GETPOSTINT('datefmonth'), GETPOSTINT('datefday'), GETPOSTINT('datefyear'), 'tzserver');
232 if ($newdate > (dol_now('tzuserrel') + getDolGlobalInt('INVOICE_MAX_FUTURE_DELAY'))) {
233 if (!getDolGlobalString('INVOICE_MAX_FUTURE_DELAY')) {
234 setEventMessages($langs->trans("WarningInvoiceDateInFuture"), null, 'warnings');
235 } else {
236 setEventMessages($langs->trans("WarningInvoiceDateTooFarInFuture"), null, 'warnings');
237 }
238 }
239
240 $object->date = $newdate;
241 $date_echence_calc = $object->calculate_date_lim_reglement();
242 if (!empty($object->date_echeance) && $object->date_echeance < $date_echence_calc) {
243 $object->date_echeance = $date_echence_calc;
244 }
245 if ($object->date_echeance && $object->date_echeance < $object->date) {
246 $object->date_echeance = $object->date;
247 }
248
249 $result = $object->update($user);
250 if ($result < 0) {
251 dol_print_error($db, $object->error);
252 }
253 } elseif ($action == 'setdate_lim_reglement' && $usercancreate) {
254 $object->date_echeance = dol_mktime(12, 0, 0, GETPOSTINT('date_lim_reglementmonth'), GETPOSTINT('date_lim_reglementday'), GETPOSTINT('date_lim_reglementyear'));
255 if (!empty($object->date_echeance) && $object->date_echeance < $object->date) {
256 $object->date_echeance = $object->date;
257 setEventMessages($langs->trans("DatePaymentTermCantBeLowerThanObjectDate"), null, 'warnings');
258 }
259 $result = $object->update($user);
260 if ($result < 0) {
261 dol_print_error($db, $object->error);
262 }
263 }
264}
265
266
267/*
268 * View
269 */
270
271$form = new Form($db);
272
273$now = dol_now();
274
275if ($type == 'bank-transfer') {
276 $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('CreditTransfer');
277 $helpurl = "";
278} else {
279 $title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('StandingOrders');
280 $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
281}
282
283llxHeader('', $title, $helpurl);
284
285
286if ($object->id > 0) {
287 $selleruserevenustamp = $mysoc->useRevenueStamp();
288
289 $totalpaid = $object->getSommePaiement();
290 $totalcreditnotes = $object->getSumCreditNotesUsed();
291 $totaldeposits = $object->getSumDepositsUsed();
292 //print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
293
294 // We can also use bcadd to avoid pb with floating points
295 // For example print 239.2 - 229.3 - 9.9; does not return 0.
296 //$resteapayer=bcadd($object->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT);
297 //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
298 $resteapayer = price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
299
300 if ($object->paid) {
301 $resteapayer = 0;
302 }
303
304 if ($type == 'bank-transfer') {
305 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { // Not recommended
306 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
307 $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
308 } else {
309 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
310 $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
311 }
312
313 $absolute_discount = $object->thirdparty->getAvailableDiscounts(null, $filterabsolutediscount, 0, 1);
314 $absolute_creditnote = $object->thirdparty->getAvailableDiscounts(null, $filtercreditnote, 0, 1);
315 $absolute_discount = price2num($absolute_discount, 'MT');
316 $absolute_creditnote = price2num($absolute_creditnote, 'MT');
317 } else {
318 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { // Not recommended
319 $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
320 $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
321 } else {
322 $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
323 $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
324 }
325
326 $absolute_discount = $object->thirdparty->getAvailableDiscounts(null, $filterabsolutediscount);
327 $absolute_creditnote = $object->thirdparty->getAvailableDiscounts(null, $filtercreditnote);
328 $absolute_discount = price2num($absolute_discount, 'MT');
329 $absolute_creditnote = price2num($absolute_creditnote, 'MT');
330 }
331
332 $author = new User($db);
333 if (!empty($object->user_creation_id)) {
334 $author->fetch($object->user_creation_id);
335 } elseif (!empty($object->fk_user_author)) { // For backward compatibility
336 $author->fetch($object->fk_user_author);
337 }
338
339 if ($type == 'bank-transfer') {
341 } else {
343 }
344
345 $numopen = 0;
346 $pending = 0;
347 $numclosed = 0;
348
349 // How many Direct debit or Credit transfer open requests ?
350 $listofopendirectdebitorcredittransfer = $object->getListOfOpenDirectDebitOrCreditTransfer($type);
351 $numopen = count($listofopendirectdebitorcredittransfer);
352
353 print dol_get_fiche_head($head, 'standingorders', $title, -1, ($type == 'bank-transfer' ? 'supplier_invoice' : 'bill'));
354
355 // Invoice content
356 if ($type == 'bank-transfer') {
357 $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
358 } else {
359 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
360 }
361
362 $morehtmlref = '<div class="refidno">';
363 // Ref customer
364 if ($type == 'bank-transfer') {
365 $morehtmlref .= $form->editfieldkey("RefSupplierBill", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
366 $morehtmlref .= $form->editfieldval("RefSupplierBill", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
367 } else {
368 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_customer, $object, 0, 'string', '', 0, 1);
369 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1);
370 }
371 // Thirdparty
372 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
373 if ($type == 'bank-transfer') {
374 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
375 $morehtmlref .= ' <div class="inline-block valignmiddle">(<a class="valignmiddle" href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)</div>';
376 }
377 } else {
378 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
379 $morehtmlref .= ' <div class="inline-block valignmiddle">(<a class="valignmiddle" href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)</div>';
380 }
381 }
382 // Project
383 if (isModEnabled('project')) {
384 $langs->load("projects");
385 $morehtmlref .= '<br>';
386 if (0) {
387 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
388 if ($action != 'classify') {
389 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
390 }
391 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
392 } else {
393 if (!empty($object->fk_project)) {
394 $proj = new Project($db);
395 $proj->fetch($object->fk_project);
396 $morehtmlref .= $proj->getNomUrl(1);
397 if ($proj->title) {
398 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
399 }
400 }
401 }
402 }
403 $morehtmlref .= '</div>';
404
405 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
406
407 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $moreparam, 0, '', '');
408
409 print '<div class="fichecenter">';
410 print '<div class="fichehalfleft">';
411 print '<div class="underbanner clearboth"></div>';
412
413 print '<table class="border centpercent tableforfield">';
414
415 // Type
416 print '<tr><td class="titlefield fieldname_type">'.$langs->trans('Type').'</td><td colspan="3">';
417 print '<span class="badgeneutral">';
418 print $object->getLibType();
419 print '</span>';
420 if (!empty($object->module_source)) {
421 print ' <span class="opacitymediumbycolor paddingleft">('.$langs->trans("POS").' '.$object->module_source.' - '.$langs->trans("Terminal").' '.$object->pos_source.')</span>';
422 }
423 if ($object->type == $object::TYPE_REPLACEMENT) {
424 if ($type == 'bank-transfer') {
425 $facreplaced = new FactureFournisseur($db);
426 } else {
427 $facreplaced = new Facture($db);
428 }
429 $facreplaced->fetch($object->fk_facture_source);
430 print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).'</span>';
431 }
432 if ($object->type == $object::TYPE_CREDIT_NOTE && !empty($object->fk_facture_source)) {
433 if ($type == 'bank-transfer') {
434 $facusing = new FactureFournisseur($db);
435 } else {
436 $facusing = new Facture($db);
437 }
438 $facusing->fetch($object->fk_facture_source);
439 print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).'</span>';
440 }
441
442 $facidavoir = $object->getListIdAvoirFromInvoice();
443 if (count($facidavoir) > 0) {
444 $invoicecredits = array();
445 foreach ($facidavoir as $facid) {
446 if ($type == 'bank-transfer') {
447 $facavoir = new FactureFournisseur($db);
448 } else {
449 $facavoir = new Facture($db);
450 }
451 $facavoir->fetch($facid);
452 $invoicecredits[] = $facavoir->getNomUrl(1);
453 }
454 print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("InvoiceHasAvoir");
455 print ' '. (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits);
456 print '</span>';
457 }
458 /*
459 if ($objectidnext > 0) {
460 $facthatreplace=new Facture($db);
461 $facthatreplace->fetch($objectidnext);
462 print ' <span class="opacitymediumbycolor paddingleft">'.str_replace('{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities("ReplacedByInvoice", '{s1}')).'</span>';
463 }
464 */
465 print '</td></tr>';
466
467 // Relative and absolute discounts
468 print '<!-- Discounts -->'."\n";
469 print '<tr><td>'.$langs->trans('DiscountStillRemaining').'</td><td colspan="3">';
470
471 if ($type == 'bank-transfer') {
472 //$societe = new Fournisseur($db);
473 //$result = $societe->fetch($object->socid);
474 $thirdparty = $object->thirdparty;
475 $discount_type = 1;
476 } else {
477 $thirdparty = $object->thirdparty;
478 $discount_type = 0;
479 }
480 $backtopage = urlencode($_SERVER["PHP_SELF"].'?facid='.$object->id);
481 $cannotApplyDiscount = 1;
482 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
483
484 print '</td></tr>';
485
486 // Label
487 if ($type == 'bank-transfer') {
488 print '<tr>';
489 print '<td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td>';
490 print '<td>'.$form->editfieldval("Label", 'label', $object->label, $object, 0).'</td>';
491 print '</tr>';
492 }
493
494 // Date invoice
495 print '<tr><td>';
496 print '<table class="nobordernopadding centpercent"><tr><td>';
497 print $langs->trans('DateInvoice');
498 print '</td>';
499 if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
500 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editinvoicedate&token='.newToken().'&id='.$object->id.'&type='.urlencode($type).'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
501 }
502 print '</tr></table>';
503 print '</td><td colspan="3">';
504
505 if ($object->type != $object::TYPE_CREDIT_NOTE) {
506 if ($action == 'editinvoicedate') {
507 print $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $object->date, 'invoicedate', 0, 0, 1, $type);
508 } else {
509 print dol_print_date($object->date, 'day');
510 }
511 } else {
512 print dol_print_date($object->date, 'day');
513 }
514 print '</td>';
515 print '</tr>';
516
517 // Payment condition
518 print '<tr><td>';
519 print '<table class="nobordernopadding centpercent"><tr><td>';
520 print $langs->trans('PaymentConditionsShort');
521 print '</td>';
522 if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editconditions' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
523 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&token='.newToken().'&id='.$object->id.'&type='.urlencode($type).'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
524 }
525 print '</tr></table>';
526 print '</td><td colspan="3">';
527 if ($object->type != $object::TYPE_CREDIT_NOTE) {
528 if ($action == 'editconditions') {
529 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 0, $type);
530 } else {
531 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
532 }
533 } else {
534 print '&nbsp;';
535 }
536 print '</td></tr>';
537
538 // Date payment term
539 print '<tr><td>';
540 print '<table class="nobordernopadding centpercent"><tr><td>';
541 print $langs->trans('DateMaxPayment');
542 print '</td>';
543 if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
544 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editpaymentterm&token='.newToken().'&id='.$object->id.'&type='.urlencode($type).'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
545 }
546 print '</tr></table>';
547 print '</td><td colspan="3">';
548 if ($object->type != $object::TYPE_CREDIT_NOTE) {
549 $duedate = $object->date_lim_reglement;
550 if ($type == 'bank-transfer') {
551 $duedate = $object->date_echeance;
552 }
553
554 if ($action == 'editpaymentterm') {
555 print $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $duedate, 'paymentterm', 0, 0, 1, $type);
556 } else {
557 print dol_print_date($duedate, 'day');
558 if ($object->hasDelay()) {
559 print img_warning($langs->trans('Late'));
560 }
561 }
562 } else {
563 print '&nbsp;';
564 }
565 print '</td></tr>';
566
567 // Payment mode
568 print '<tr><td>';
569 print '<table class="nobordernopadding centpercent"><tr><td>';
570 print $langs->trans('PaymentMode');
571 print '</td>';
572 if ($action != 'editmode' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
573 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'&type='.urlencode($type).'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
574 }
575 print '</tr></table>';
576 print '</td><td colspan="3">';
577 $filtertype = 'CRDT';
578 if ($type == 'bank-transfer') {
579 $filtertype = 'DBIT';
580 }
581 if ($action == 'editmode') {
582 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', $filtertype, 1, 0, $type);
583 } else {
584 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
585 }
586 print '</td></tr>';
587
588 // Bank Account
589 print '<tr><td class="nowrap">';
590 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
591 print $langs->trans('BankAccount');
592 print '<td>';
593 if (($action != 'editbankaccount') && $user->hasRight('commande', 'creer') && $object->status == $object::STATUS_DRAFT) {
594 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'&type='.urlencode($type).'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
595 }
596 print '</tr></table>';
597 print '</td><td colspan="3">';
598 if ($action == 'editbankaccount') {
599 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
600 } else {
601 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
602 }
603 print '</td>';
604 print '</tr>';
605 print '</table>';
606 print '</div>';
607
608 print '<div class="fichehalfright">';
609 print '<!-- amounts -->'."\n";
610 print '<div class="underbanner clearboth"></div>'."\n";
611
612 print '<table class="border tableforfield centpercent">';
613
614 include DOL_DOCUMENT_ROOT.'/core/tpl/object_currency_amount.tpl.php';
615
616 $sign = 1;
617 if (getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE_SCREEN') && $object->type == $object::TYPE_CREDIT_NOTE) {
618 $sign = -1; // We invert sign for output
619 }
620 print '<tr>';
621 // Amount HT
622 print '<td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
623 print '<td class="nowrap amountcard right">' . price($sign * $object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
624 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
625 // Multicurrency Amount HT
626 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_ht, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
627 }
628 print '</tr>';
629
630 print '<tr>';
631 // Amount VAT
632 print '<td>' . $langs->trans('AmountVAT') . '</td>';
633 print '<td class="nowrap amountcard right">' . price($sign * $object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
634 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
635 // Multicurrency Amount VAT
636 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_tva, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
637 }
638 print '</tr>';
639
640 // Amount Local Taxes
641 if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
642 print '<tr>';
643 print '<td class="titlefieldmiddle">' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
644 print '<td class="nowrap amountcard right">' . price($sign * $object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
645 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
646 $object->multicurrency_total_localtax1 = (float) price2num($object->total_localtax1 * $object->multicurrency_tx, 'MT');
647
648 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
649 }
650 print '</tr>';
651 }
652
653 if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) {
654 print '<tr>';
655 print '<td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
656 print '<td class="nowrap amountcard right">' . price($sign * $object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
657 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
658 $object->multicurrency_total_localtax2 = (float) price2num($object->total_localtax2 * $object->multicurrency_tx, 'MT');
659
660 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
661 }
662 print '</tr>';
663 }
664
665 // Revenue stamp
666 if ($selleruserevenustamp) { // Test company use revenue stamp
667 print '<tr><td>';
668 print '<table class="nobordernopadding centpercent"><tr><td>';
669 print $langs->trans('RevenueStamp');
670 print '</td>';
671 if ($action != 'editrevenuestamp' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
672 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrevenuestamp&token='.newToken().'&facid='.$object->id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'</a></td>';
673 }
674 print '</tr></table>';
675 print '</td><td class="nowrap right">';
676 print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
677 print '</td></tr>';
678 }
679
680 print '<tr>';
681 // Amount TTC
682 print '<td>' . $langs->trans('AmountTTC') . '</td>';
683 print '<td class="nowrap amountcard right">' . price($sign * $object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
684 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
685 // Multicurrency Amount TTC
686 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
687 }
688 print '</tr>';
689
690
691 $resteapayer = price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
692
693 // Hook to change amount for other reasons, e.g. apply cash discount for payment before agreed date
694 $parameters = array('remaintopay' => $resteapayer);
695 $reshook = $hookmanager->executeHooks('finalizeAmountOfInvoice', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
696 if ($reshook > 0) {
697 print $hookmanager->resPrint;
698 if (!empty($remaintopay = $hookmanager->resArray['remaintopay'])) {
699 $resteapayer = $remaintopay;
700 }
701 }
702
703 // TODO Replace this by an include with same code to show already done payment visible in invoice card
704 print '<tr><td>'.$langs->trans('RemainderToPay').'</td><td class="nowrap right">'.price($resteapayer, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
705 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
706 print '<td></td>';
707 }
708 print '</tr>';
709
710 print '</table>';
711
712 print '</div>';
713 print '</div>';
714
715 print '<div class="clearboth"></div>';
716
717
718 print dol_get_fiche_end();
719
720
721 // For which amount ?
722
723 $sql = "SELECT SUM(pfd.amount) as amount";
724 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
725 if ($type == 'bank-transfer') {
726 $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
727 } else {
728 $sql .= " WHERE fk_facture = ".((int) $object->id);
729 }
730 $sql .= " AND pfd.traite = 0";
731 $sql .= " AND pfd.type = 'ban'";
732
733 $resql = $db->query($sql);
734 if ($resql) {
735 $obj = $db->fetch_object($resql);
736 if ($obj) {
737 $pending = $obj->amount;
738 }
739 } else {
740 dol_print_error($db);
741 }
742
743
744 /*
745 * Buttons
746 */
747
748 print "\n".'<div class="tabsAction">'."\n";
749
750 $buttonlabel = $langs->trans("MakeWithdrawRequest");
751 $user_perms = $user->hasRight('prelevement', 'bons', 'creer');
752 if ($type == 'bank-transfer') {
753 $buttonlabel = $langs->trans("MakeBankTransferOrder");
754 $user_perms = $user->hasRight('paymentbybanktransfer', 'create');
755 }
756
757 // Add a transfer request
758 if ($object->status > $object::STATUS_DRAFT && $object->paid == 0 && $num == 0) {
759 if ($resteapayer > 0) {
760 if ($user_perms) {
761 $remaintopaylesspendingdebit = $resteapayer - $pending;
762
763 $title = $langs->trans("NewStandingOrder");
764 if ($type == 'bank-transfer') {
765 $title = $langs->trans("NewPaymentByBankTransfer");
766 }
767
768 print '<!-- form to select BAN -->';
769 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
770 print '<input type="hidden" name="token" value="'.newToken().'" />';
771 print '<input type="hidden" name="id" value="'.$object->id.'" />';
772 print '<input type="hidden" name="type" value="'.$type.'" />';
773 print '<input type="hidden" name="action" value="new" />';
774
775 print '<div class="center formconsumeproduce">';
776
777 print $langs->trans('CustomerIBAN').' ';
778
779 // if societe rib in model invoice, we preselect it
780 $selectedRib = '';
781 if ($object->element == 'invoice' && $object->fk_fac_rec_source) {
782 $facturerec = new FactureRec($db);
783 $facturerec->fetch($object->fk_fac_rec_source);
784 if ($facturerec->fk_societe_rib) {
785 $companyBankAccount = new CompanyBankAccount($db);
786 $res = $companyBankAccount->fetch($facturerec->fk_societe_rib);
787 $selectedRib = $companyBankAccount->id;
788 }
789 }
790
791 $selectedRib = $form->selectRib($selectedRib, 'accountcustomerid', 'fk_soc='.$object->socid, 1, '', 1);
792
793 $defaultRibId = $object->thirdparty->getDefaultRib();
794 if ($defaultRibId) {
795 $companyBankAccount = new CompanyBankAccount($db);
796 $res = $companyBankAccount->fetch($defaultRibId);
797 if ($res > 0 && !$companyBankAccount->verif()) {
798 print img_warning('Error on default bank number for IBAN : '.$langs->trans($companyBankAccount->error));
799 }
800 } elseif ($numopen || ($type != 'bank-transfer' && $object->mode_reglement_code == 'PRE') || ($type == 'bank-transfer' && $object->mode_reglement_code == 'VIR')) {
801 print img_warning($langs->trans("NoDefaultIBANFound"));
802 }
803
804
805 // Bank Transfer Amount
806 print ' &nbsp; &nbsp; <label for="withdraw_request_amount">';
807 if ($type == 'bank-transfer') {
808 print $langs->trans('BankTransferAmount');
809 } else {
810 print $langs->trans("WithdrawRequestAmount");
811 }
812 print '</label> ';
813 print '<input type="text" class="right width75" id="withdraw_request_amount" name="withdraw_request_amount" value="'.$remaintopaylesspendingdebit.'">';
814
815 // Button
816 print '<br><br>';
817 print '<input type="submit" class="butAction small" value="'.$buttonlabel.'" />';
818 print '<br><br>';
819
820 print '</div>';
821
822 print '</form>';
823
824 if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT_SHOW_OLD_BUTTON')) { // This is hidden, prefer to use mode enabled with STRIPE_SEPA_DIRECT_DEBIT
825 // TODO Replace this with a checkbox for each payment mode: "Send request to XXX immediately..."
826 print "<br>";
827 // Add stripe sepa button
828 $buttonlabel = $langs->trans("MakeWithdrawRequestStripe");
829 print '<form method="POST" action="">';
830 print '<input type="hidden" name="token" value="'.newToken().'" />';
831 print '<input type="hidden" name="id" value="'.$object->id.'" />';
832 print '<input type="hidden" name="type" value="'.$type.'" />';
833 print '<input type="hidden" name="action" value="new" />';
834 print '<input type="hidden" name="paymenservice" value="stripesepa" />';
835 print '<label for="withdraw_request_amount">'.$langs->trans('BankTransferAmount').' </label>';
836 print '<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="'.$remaintopaylesspendingdebit.'" size="9" />';
837 print '<input type="submit" class="butAction small" value="'.$buttonlabel.'" />';
838 print '</form>';
839 }
840 } else {
841 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$buttonlabel.'</a>';
842 }
843 } else {
844 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$buttonlabel.'</a>';
845 }
846 } else {
847 if ($num == 0) {
848 if ($object->status > $object::STATUS_DRAFT) {
849 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AlreadyPaid")).'">'.$buttonlabel.'</a>';
850 } else {
851 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("Draft")).'">'.$buttonlabel.'</a>';
852 }
853 } else {
854 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("RequestAlreadyDone")).'">'.$buttonlabel.'</a>';
855 }
856 }
857
858 print "</div>\n";
859
860
861 if ($type == 'bank-transfer') {
862 print '<div class="opacitymedium justify">'.$langs->trans("DoCreditTransferBeforePayments");
863 if (isModEnabled('stripe') && getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
864 print ' '.$langs->trans("DoStandingOrdersBeforePayments2");
865 }
866 print ' '.$langs->trans("DoStandingOrdersBeforePayments3");
867 print '</div><br><br>';
868 } else {
869 print '<div class="opacitymedium justify">'.$langs->trans("DoStandingOrdersBeforePayments");
870 if (isModEnabled('stripe') && getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
871 print ' '.$langs->trans("DoStandingOrdersBeforePayments2");
872 }
873 print ' '.$langs->trans("DoStandingOrdersBeforePayments3");
874 print '</div><br><br>';
875 }
876
877 /*
878 * Withdrawals
879 */
880
881 print '<div class="div-table-responsive-no-min">';
882 print '<table class="noborder centpercent">';
883
884 print '<tr class="liste_titre">';
885 // Action column
886 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
887 print '<td>&nbsp;</td>';
888 }
889 print '<td class="left">'.$langs->trans("DateRequest").'</td>';
890 print '<td>'.$langs->trans("User").'</td>';
891 print '<td class="center">'.$langs->trans("Amount").'</td>';
892 print '<td class="center">'.$langs->trans("IBAN").'</td>';
893 print '<td class="center">'.$langs->trans("DateProcess").'</td>';
894 if ($type == 'bank-transfer') {
895 print '<td class="">'.$langs->trans("BankTransferReceipt").'</td>';
896 } else {
897 print '<td class="">'.$langs->trans("WithdrawalReceipt").'</td>';
898 }
899 print '<td>&nbsp;</td>';
900 // Action column
901 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
902 print '<td>&nbsp;</td>';
903 }
904 print '</tr>';
905
906 $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande,";
907 $sql .= " pfd.date_traite as date_traite, pfd.amount, pfd.fk_prelevement_bons,";
908 $sql .= " pb.ref, pb.date_trans, pb.method_trans, pb.credite, pb.date_credit, pb.datec, pb.statut as status, pb.amount as pb_amount,";
909 $sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status,";
910 $sql .= " sr.iban_prefix as iban, sr.bic as bic";
911 $sql .= " FROM ".$db->prefix()."prelevement_demande as pfd";
912 $sql .= " LEFT JOIN ".$db->prefix()."user as u on pfd.fk_user_demande = u.rowid";
913 $sql .= " LEFT JOIN ".$db->prefix()."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
914 $sql .= " LEFT JOIN ".$db->prefix()."societe_rib as sr ON sr.rowid = pfd.fk_societe_rib";
915 if ($type == 'bank-transfer') {
916 $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
917 } else {
918 $sql .= " WHERE fk_facture = ".((int) $object->id);
919 }
920 $sql .= " AND pfd.traite = 0";
921 $sql .= " AND pfd.type = 'ban'";
922 $sql .= " ORDER BY pfd.date_demande DESC";
923
924 $resql = $db->query($sql);
925
926 $num = 0;
927 if ($resql) {
928 $i = 0;
929
930 $tmpuser = new User($db);
931
932 $num = $db->num_rows($result);
933 while ($i < $num) {
934 $obj = $db->fetch_object($resql);
935
936 $tmpuser->id = $obj->user_id;
937 $tmpuser->login = $obj->login;
938 $tmpuser->ref = $obj->login;
939 $tmpuser->email = $obj->email;
940 $tmpuser->lastname = $obj->lastname;
941 $tmpuser->firstname = $obj->firstname;
942 $tmpuser->statut = $obj->user_status;
943 $tmpuser->status = $obj->user_status;
944
945 print '<tr class="oddeven">';
946
947 // Action column
948 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
949 print '<td class="center">';
950 print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'&did='.$obj->rowid.'&type='.urlencode($type).'">';
951 print img_delete();
952 print '</a>';
953 print '</td>';
954 }
955
956 // Date
957 print '<td class="nowraponall">'.dol_print_date($db->jdate($obj->date_demande), 'dayhour')."</td>\n";
958
959 // User
960 print '<td class="tdoverflowmax125">';
961 print $tmpuser->getNomUrl(-1, '', 0, 0, 0, 0, 'login');
962 print '</td>';
963
964 // Amount
965 print '<td class="center"><span class="amount">'.price($obj->amount).'</span></td>';
966
967 // Iban
968 print '<td class="center"><span class="iban">';
969 print dolDecrypt($obj->iban);
970 if ($obj->iban && $obj->bic) {
971 print " / ";
972 }
973 print $obj->bic;
974 print '</span></td>';
975
976 // Date process
977 print '<td class="center"><span class="opacitymedium">'.$langs->trans("OrderWaiting").'</span></td>';
978
979 // Link to make payment now
980 print '<td class="minwidth75">';
981 if ($obj->fk_prelevement_bons > 0) {
982 $withdrawreceipt = new BonPrelevement($db);
983 $withdrawreceipt->id = $obj->fk_prelevement_bons;
984 $withdrawreceipt->ref = $obj->ref;
985 $withdrawreceipt->date_trans = $db->jdate($obj->date_trans);
986 $withdrawreceipt->date_credit = $db->jdate($obj->date_credit);
987 $withdrawreceipt->date_creation = $db->jdate($obj->datec);
988 $withdrawreceipt->statut = $obj->status;
989 $withdrawreceipt->status = $obj->status;
990 $withdrawreceipt->amount = $obj->pb_amount;
991 //$withdrawreceipt->credite = $db->jdate($obj->credite);
992
993 print $withdrawreceipt->getNomUrl(1);
994 }
995
996 if ($type != 'bank-transfer') {
997 if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
998 $langs->load("stripe");
999 if ($obj->fk_prelevement_bons > 0) {
1000 print ' &nbsp; ';
1001 }
1002 print '<a href="'.$_SERVER["PHP_SELF"].'?action=sepastripedirectdebit&paymentservice=stripesepa&token='.newToken().'&did='.$obj->rowid.'&id='.$object->id.'&type='.urlencode($type).'">'.img_picto('', 'stripe', 'class="pictofixedwidth"').$langs->trans("RequestDirectDebitWithStripe").'</a>';
1003 }
1004 } else {
1005 if (getDolGlobalString('STRIPE_SEPA_CREDIT_TRANSFER')) {
1006 $langs->load("stripe");
1007 if ($obj->fk_prelevement_bons > 0) {
1008 print ' &nbsp; ';
1009 }
1010 print '<a href="'.$_SERVER["PHP_SELF"].'?action=sepastripecredittransfer&paymentservice=stripesepa&token='.newToken().'&did='.$obj->rowid.'&id='.$object->id.'&type='.urlencode($type).'">'.img_picto('', 'stripe', 'class="pictofixedwidth"').$langs->trans("RequestDirectDebitWithStripe").'</a>';
1011 }
1012 }
1013 print '</td>';
1014
1015 // Withraw ref
1016 print '<td class="">';
1017 //print '<span class="opacitymedium">'.$langs->trans("OrderWaiting").'</span>';
1018 print '</td>';
1019
1020 // Action column
1021 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1022 print '<td class="center">';
1023 print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'&did='.$obj->rowid.'&type='.urlencode($type).'">';
1024 print img_delete();
1025 print '</a></td>';
1026 }
1027
1028 print "</tr>\n";
1029 $i++;
1030 }
1031
1032 $db->free($resql);
1033 } else {
1034 dol_print_error($db);
1035 }
1036
1037
1038 // Past requests
1039
1040 $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande, pfd.date_traite, pfd.fk_prelevement_bons, pfd.amount,";
1041 $sql .= " pb.ref, pb.date_trans, pb.method_trans, pb.credite, pb.date_credit, pb.datec, pb.statut as status, pb.fk_bank_account, pb.amount as pb_amount,";
1042 $sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo as user_photo,";
1043 $sql .= " sr.iban_prefix as iban, sr.bic as bic";
1044 $sql .= " FROM ".$db->prefix()."prelevement_demande as pfd";
1045 $sql .= " LEFT JOIN ".$db->prefix()."user as u on pfd.fk_user_demande = u.rowid";
1046 $sql .= " LEFT JOIN ".$db->prefix()."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
1047 $sql .= " LEFT JOIN ".$db->prefix()."societe_rib as sr ON sr.rowid = pfd.fk_societe_rib";
1048 if ($type == 'bank-transfer') {
1049 $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
1050 } else {
1051 $sql .= " WHERE fk_facture = ".((int) $object->id);
1052 }
1053 $sql .= " AND pfd.traite = 1";
1054 $sql .= " AND pfd.type = 'ban'";
1055 $sql .= " ORDER BY pfd.date_demande DESC";
1056
1057 $resql = $db->query($sql);
1058 if ($resql) {
1059 $num = $db->num_rows($resql);
1060 $numclosed = $num;
1061 $i = 0;
1062
1063 $tmpuser = new User($db);
1064
1065 while ($i < $num) {
1066 $obj = $db->fetch_object($resql);
1067
1068 $tmpuser->id = $obj->user_id;
1069 $tmpuser->login = $obj->login;
1070 $tmpuser->ref = $obj->login;
1071 $tmpuser->email = $obj->email;
1072 $tmpuser->lastname = $obj->lastname;
1073 $tmpuser->firstname = $obj->firstname;
1074 $tmpuser->statut = $obj->user_status;
1075 $tmpuser->status = $obj->user_status;
1076 $tmpuser->photo = $obj->user_photo;
1077
1078 print '<tr class="oddeven">';
1079
1080 // Action column
1081 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1082 print '<td>&nbsp;</td>';
1083 }
1084
1085 // Date
1086 print '<td class="nowraponall">'.dol_print_date($db->jdate($obj->date_demande), 'day', 'tzuserrel')."</td>\n";
1087
1088 // User
1089 print '<td class="tdoverflowmax125">';
1090 print $tmpuser->getNomUrl(-1, '', 0, 0, 0, 0, 'login');
1091 print '</td>';
1092
1093 // Amount
1094 print '<td class="center"><span class="amount">'.price($obj->amount).'</span></td>';
1095
1096 // Iban
1097 print '<td class="center"><span class="iban">';
1098 print dolDecrypt($obj->iban);
1099 if ($obj->iban && $obj->bic) {
1100 print " / ";
1101 }
1102 print $obj->bic;
1103 print '</span></td>';
1104
1105 // Date process
1106 print '<td class="center nowraponall">'.dol_print_date($db->jdate($obj->date_traite), 'dayhour', 'tzuserrel')."</td>\n";
1107
1108 // Link to payment request done
1109 print '<td class="minwidth75">';
1110 if ($obj->fk_prelevement_bons > 0) {
1111 $withdrawreceipt = new BonPrelevement($db);
1112 $withdrawreceipt->id = $obj->fk_prelevement_bons;
1113 $withdrawreceipt->ref = $obj->ref;
1114 $withdrawreceipt->date_trans = $db->jdate($obj->date_trans);
1115 $withdrawreceipt->date_credit = $db->jdate($obj->date_credit);
1116 $withdrawreceipt->date_creation = $db->jdate($obj->datec);
1117 $withdrawreceipt->statut = $obj->status;
1118 $withdrawreceipt->status = $obj->status;
1119 $withdrawreceipt->fk_bank_account = $obj->fk_bank_account;
1120 $withdrawreceipt->amount = $obj->pb_amount;
1121 //$withdrawreceipt->credite = $db->jdate($obj->credite);
1122
1123 print $withdrawreceipt->getNomUrl(1);
1124 print ' ';
1125 print $withdrawreceipt->getLibStatut(2);
1126
1127 // Show the bank account
1128 $fk_bank_account = $withdrawreceipt->fk_bank_account;
1129 if (empty($fk_bank_account)) {
1130 $fk_bank_account = ($object->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
1131 }
1132 if ($fk_bank_account > 0) {
1133 $bankaccount = new Account($db);
1134 $result = $bankaccount->fetch($fk_bank_account);
1135 if ($result > 0) {
1136 print ' - ';
1137 print $bankaccount->getNomUrl(1);
1138 }
1139 }
1140 }
1141 print "</td>\n";
1142
1143 //
1144 print '<td>&nbsp;</td>';
1145
1146 // Action column
1147 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1148 print '<td>&nbsp;</td>';
1149 }
1150
1151 print "</tr>\n";
1152 $i++;
1153 }
1154
1155 if (!$numopen && !$numclosed) {
1156 print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1157 }
1158
1159 $db->free($resql);
1160 } else {
1161 dol_print_error($db);
1162 }
1163
1164 print "</table>";
1165 print '</div>';
1166}
1167
1168// End of page
1169llxFooter();
1170$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
Class to manage bank accounts.
Class to manage withdrawal receipts.
Class to manage bank accounts description of third parties.
Class to manage suppliers invoices.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
Class to manage invoice templates.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage Dolibarr users.
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
Definition fourn.lib.php:37
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_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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).
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)
Return value of a param into GET or POST supervariable.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.