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 $resteapayeraffiche = $resteapayer;
304
305 if ($type == 'bank-transfer') {
306 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { // Not recommended
307 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
308 $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
309 } else {
310 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
311 $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
312 }
313
314 $absolute_discount = $object->thirdparty->getAvailableDiscounts(null, $filterabsolutediscount, 0, 1);
315 $absolute_creditnote = $object->thirdparty->getAvailableDiscounts(null, $filtercreditnote, 0, 1);
316 $absolute_discount = price2num($absolute_discount, 'MT');
317 $absolute_creditnote = price2num($absolute_creditnote, 'MT');
318 } else {
319 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { // Not recommended
320 $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
321 $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be subtracted to payments only and not to total of final invoice
322 } else {
323 $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
324 $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
325 }
326
327 $absolute_discount = $object->thirdparty->getAvailableDiscounts(null, $filterabsolutediscount);
328 $absolute_creditnote = $object->thirdparty->getAvailableDiscounts(null, $filtercreditnote);
329 $absolute_discount = price2num($absolute_discount, 'MT');
330 $absolute_creditnote = price2num($absolute_creditnote, 'MT');
331 }
332
333 $author = new User($db);
334 if (!empty($object->user_creation_id)) {
335 $author->fetch($object->user_creation_id);
336 } elseif (!empty($object->fk_user_author)) {
337 $author->fetch($object->fk_user_author);
338 }
339
340 if ($type == 'bank-transfer') {
342 } else {
344 }
345
346 $numopen = 0;
347 $pending = 0;
348 $numclosed = 0;
349
350 // How many Direct debit or Credit transfer open requests ?
351
352 $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
353 $sql .= " , pfd.date_traite as date_traite";
354 $sql .= " , pfd.amount";
355 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
356 if ($type == 'bank-transfer') {
357 $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
358 } else {
359 $sql .= " WHERE fk_facture = ".((int) $object->id);
360 }
361 $sql .= " AND pfd.traite = 0";
362 $sql .= " AND pfd.type = 'ban'";
363 $sql .= " ORDER BY pfd.date_demande DESC";
364
365 $resql = $db->query($sql);
366 if ($resql) {
367 $num = $db->num_rows($resql);
368 $numopen = $num;
369 } else {
370 dol_print_error($db);
371 }
372
373
374 print dol_get_fiche_head($head, 'standingorders', $title, -1, ($type == 'bank-transfer' ? 'supplier_invoice' : 'bill'));
375
376 // Invoice content
377 if ($type == 'bank-transfer') {
378 $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
379 } else {
380 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
381 }
382
383 $morehtmlref = '<div class="refidno">';
384 // Ref customer
385 if ($type == 'bank-transfer') {
386 $morehtmlref .= $form->editfieldkey("RefSupplierBill", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
387 $morehtmlref .= $form->editfieldval("RefSupplierBill", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
388 } else {
389 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_customer, $object, 0, 'string', '', 0, 1);
390 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1);
391 }
392 // Thirdparty
393 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
394 if ($type == 'bank-transfer') {
395 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
396 $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>';
397 }
398 } else {
399 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
400 $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>';
401 }
402 }
403 // Project
404 if (isModEnabled('project')) {
405 $langs->load("projects");
406 $morehtmlref .= '<br>';
407 if (0) {
408 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
409 if ($action != 'classify') {
410 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
411 }
412 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
413 } else {
414 if (!empty($object->fk_project)) {
415 $proj = new Project($db);
416 $proj->fetch($object->fk_project);
417 $morehtmlref .= $proj->getNomUrl(1);
418 if ($proj->title) {
419 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
420 }
421 }
422 }
423 }
424 $morehtmlref .= '</div>';
425
426 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
427
428 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $moreparam, 0, '', '');
429
430 print '<div class="fichecenter">';
431 print '<div class="fichehalfleft">';
432 print '<div class="underbanner clearboth"></div>';
433
434 print '<table class="border centpercent tableforfield">';
435
436 // Type
437 print '<tr><td class="titlefield fieldname_type">'.$langs->trans('Type').'</td><td colspan="3">';
438 print '<span class="badgeneutral">';
439 print $object->getLibType();
440 print '</span>';
441 if (!empty($object->module_source)) {
442 print ' <span class="opacitymediumbycolor paddingleft">('.$langs->trans("POS").' '.$object->module_source.' - '.$langs->trans("Terminal").' '.$object->pos_source.')</span>';
443 }
444 if ($object->type == $object::TYPE_REPLACEMENT) {
445 if ($type == 'bank-transfer') {
446 $facreplaced = new FactureFournisseur($db);
447 } else {
448 $facreplaced = new Facture($db);
449 }
450 $facreplaced->fetch($object->fk_facture_source);
451 print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).'</span>';
452 }
453 if ($object->type == $object::TYPE_CREDIT_NOTE && !empty($object->fk_facture_source)) {
454 if ($type == 'bank-transfer') {
455 $facusing = new FactureFournisseur($db);
456 } else {
457 $facusing = new Facture($db);
458 }
459 $facusing->fetch($object->fk_facture_source);
460 print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).'</span>';
461 }
462
463 $facidavoir = $object->getListIdAvoirFromInvoice();
464 if (count($facidavoir) > 0) {
465 $invoicecredits = array();
466 foreach ($facidavoir as $facid) {
467 if ($type == 'bank-transfer') {
468 $facavoir = new FactureFournisseur($db);
469 } else {
470 $facavoir = new Facture($db);
471 }
472 $facavoir->fetch($facid);
473 $invoicecredits[] = $facavoir->getNomUrl(1);
474 }
475 print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("InvoiceHasAvoir");
476 print ' '. (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits);
477 print '</span>';
478 }
479 /*
480 if ($objectidnext > 0) {
481 $facthatreplace=new Facture($db);
482 $facthatreplace->fetch($objectidnext);
483 print ' <span class="opacitymediumbycolor paddingleft">'.str_replace('{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities("ReplacedByInvoice", '{s1}')).'</span>';
484 }
485 */
486 print '</td></tr>';
487
488 // Relative and absolute discounts
489 print '<!-- Discounts -->'."\n";
490 print '<tr><td>'.$langs->trans('DiscountStillRemaining').'</td><td colspan="3">';
491
492 if ($type == 'bank-transfer') {
493 //$societe = new Fournisseur($db);
494 //$result = $societe->fetch($object->socid);
495 $thirdparty = $object->thirdparty;
496 $discount_type = 1;
497 } else {
498 $thirdparty = $object->thirdparty;
499 $discount_type = 0;
500 }
501 $backtopage = urlencode($_SERVER["PHP_SELF"].'?facid='.$object->id);
502 $cannotApplyDiscount = 1;
503 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
504
505 print '</td></tr>';
506
507 // Label
508 if ($type == 'bank-transfer') {
509 print '<tr>';
510 print '<td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td>';
511 print '<td>'.$form->editfieldval("Label", 'label', $object->label, $object, 0).'</td>';
512 print '</tr>';
513 }
514
515 // Date invoice
516 print '<tr><td>';
517 print '<table class="nobordernopadding centpercent"><tr><td>';
518 print $langs->trans('DateInvoice');
519 print '</td>';
520 if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
521 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>';
522 }
523 print '</tr></table>';
524 print '</td><td colspan="3">';
525
526 if ($object->type != $object::TYPE_CREDIT_NOTE) {
527 if ($action == 'editinvoicedate') {
528 print $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $object->date, 'invoicedate', 0, 0, 1, $type);
529 } else {
530 print dol_print_date($object->date, 'day');
531 }
532 } else {
533 print dol_print_date($object->date, 'day');
534 }
535 print '</td>';
536 print '</tr>';
537
538 // Payment condition
539 print '<tr><td>';
540 print '<table class="nobordernopadding centpercent"><tr><td>';
541 print $langs->trans('PaymentConditionsShort');
542 print '</td>';
543 if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editconditions' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
544 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>';
545 }
546 print '</tr></table>';
547 print '</td><td colspan="3">';
548 if ($object->type != $object::TYPE_CREDIT_NOTE) {
549 if ($action == 'editconditions') {
550 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 0, $type);
551 } else {
552 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
553 }
554 } else {
555 print '&nbsp;';
556 }
557 print '</td></tr>';
558
559 // Date payment term
560 print '<tr><td>';
561 print '<table class="nobordernopadding centpercent"><tr><td>';
562 print $langs->trans('DateMaxPayment');
563 print '</td>';
564 if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
565 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>';
566 }
567 print '</tr></table>';
568 print '</td><td colspan="3">';
569 if ($object->type != $object::TYPE_CREDIT_NOTE) {
570 $duedate = $object->date_lim_reglement;
571 if ($type == 'bank-transfer') {
572 $duedate = $object->date_echeance;
573 }
574
575 if ($action == 'editpaymentterm') {
576 print $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $duedate, 'paymentterm', 0, 0, 1, $type);
577 } else {
578 print dol_print_date($duedate, 'day');
579 if ($object->hasDelay()) {
580 print img_warning($langs->trans('Late'));
581 }
582 }
583 } else {
584 print '&nbsp;';
585 }
586 print '</td></tr>';
587
588 // Payment mode
589 print '<tr><td>';
590 print '<table class="nobordernopadding centpercent"><tr><td>';
591 print $langs->trans('PaymentMode');
592 print '</td>';
593 if ($action != 'editmode' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
594 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>';
595 }
596 print '</tr></table>';
597 print '</td><td colspan="3">';
598 $filtertype = 'CRDT';
599 if ($type == 'bank-transfer') {
600 $filtertype = 'DBIT';
601 }
602 if ($action == 'editmode') {
603 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', $filtertype, 1, 0, $type);
604 } else {
605 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
606 }
607 print '</td></tr>';
608
609 // Bank Account
610 print '<tr><td class="nowrap">';
611 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
612 print $langs->trans('BankAccount');
613 print '<td>';
614 if (($action != 'editbankaccount') && $user->hasRight('commande', 'creer') && $object->status == $object::STATUS_DRAFT) {
615 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>';
616 }
617 print '</tr></table>';
618 print '</td><td colspan="3">';
619 if ($action == 'editbankaccount') {
620 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
621 } else {
622 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
623 }
624 print '</td>';
625 print '</tr>';
626 print '</table>';
627 print '</div>';
628
629 print '<div class="fichehalfright">';
630 print '<!-- amounts -->'."\n";
631 print '<div class="underbanner clearboth"></div>'."\n";
632
633 print '<table class="border tableforfield centpercent">';
634
635 include DOL_DOCUMENT_ROOT.'/core/tpl/object_currency_amount.tpl.php';
636
637 $sign = 1;
638 if (getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE_SCREEN') && $object->type == $object::TYPE_CREDIT_NOTE) {
639 $sign = -1; // We invert sign for output
640 }
641 print '<tr>';
642 // Amount HT
643 print '<td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
644 print '<td class="nowrap amountcard right">' . price($sign * $object->total_ht, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
645 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
646 // Multicurrency Amount HT
647 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_ht, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
648 }
649 print '</tr>';
650
651 print '<tr>';
652 // Amount VAT
653 print '<td>' . $langs->trans('AmountVAT') . '</td>';
654 print '<td class="nowrap amountcard right">' . price($sign * $object->total_tva, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
655 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
656 // Multicurrency Amount VAT
657 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_tva, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
658 }
659 print '</tr>';
660
661 // Amount Local Taxes
662 if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) {
663 print '<tr>';
664 print '<td class="titlefieldmiddle">' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
665 print '<td class="nowrap amountcard right">' . price($sign * $object->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
666 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
667 $object->multicurrency_total_localtax1 = (float) price2num($object->total_localtax1 * $object->multicurrency_tx, 'MT');
668
669 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
670 }
671 print '</tr>';
672 }
673
674 if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) {
675 print '<tr>';
676 print '<td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
677 print '<td class="nowrap amountcard right">' . price($sign * $object->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
678 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
679 $object->multicurrency_total_localtax2 = (float) price2num($object->total_localtax2 * $object->multicurrency_tx, 'MT');
680
681 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
682 }
683 print '</tr>';
684 }
685
686 // Revenue stamp
687 if ($selleruserevenustamp) { // Test company use revenue stamp
688 print '<tr><td>';
689 print '<table class="nobordernopadding centpercent"><tr><td>';
690 print $langs->trans('RevenueStamp');
691 print '</td>';
692 if ($action != 'editrevenuestamp' && $object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer')) {
693 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>';
694 }
695 print '</tr></table>';
696 print '</td><td class="nowrap right">';
697 print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
698 print '</td></tr>';
699 }
700
701 print '<tr>';
702 // Amount TTC
703 print '<td>' . $langs->trans('AmountTTC') . '</td>';
704 print '<td class="nowrap amountcard right">' . price($sign * $object->total_ttc, 0, $langs, 0, -1, -1, $conf->currency) . '</td>';
705 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
706 // Multicurrency Amount TTC
707 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
708 }
709 print '</tr>';
710
711
712 $resteapayer = price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
713
714 // Hook to change amount for other reasons, e.g. apply cash discount for payment before agreed date
715 $parameters = array('remaintopay' => $resteapayer);
716 $reshook = $hookmanager->executeHooks('finalizeAmountOfInvoice', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
717 if ($reshook > 0) {
718 print $hookmanager->resPrint;
719 if (!empty($remaintopay = $hookmanager->resArray['remaintopay'])) {
720 $resteapayer = $remaintopay;
721 }
722 }
723
724 // TODO Replace this by an include with same code to show already done payment visible in invoice card
725 print '<tr><td>'.$langs->trans('RemainderToPay').'</td><td class="nowrap right">'.price($resteapayer, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
726 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
727 print '<td></td>';
728 }
729 print '</tr>';
730
731 print '</table>';
732
733 print '</div>';
734 print '</div>';
735
736 print '<div class="clearboth"></div>';
737
738
739 print dol_get_fiche_end();
740
741
742 // For which amount ?
743
744 $sql = "SELECT SUM(pfd.amount) as amount";
745 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
746 if ($type == 'bank-transfer') {
747 $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
748 } else {
749 $sql .= " WHERE fk_facture = ".((int) $object->id);
750 }
751 $sql .= " AND pfd.traite = 0";
752 $sql .= " AND pfd.type = 'ban'";
753
754 $resql = $db->query($sql);
755 if ($resql) {
756 $obj = $db->fetch_object($resql);
757 if ($obj) {
758 $pending = $obj->amount;
759 }
760 } else {
761 dol_print_error($db);
762 }
763
764
765 /*
766 * Buttons
767 */
768
769 print "\n".'<div class="tabsAction">'."\n";
770
771 $buttonlabel = $langs->trans("MakeWithdrawRequest");
772 $user_perms = $user->hasRight('prelevement', 'bons', 'creer');
773 if ($type == 'bank-transfer') {
774 $buttonlabel = $langs->trans("MakeBankTransferOrder");
775 $user_perms = $user->hasRight('paymentbybanktransfer', 'create');
776 }
777
778 // Add a transfer request
779 if ($object->status > $object::STATUS_DRAFT && $object->paid == 0 && $num == 0) {
780 if ($resteapayer > 0) {
781 if ($user_perms) {
782 $remaintopaylesspendingdebit = $resteapayer - $pending;
783
784 $title = $langs->trans("NewStandingOrder");
785 if ($type == 'bank-transfer') {
786 $title = $langs->trans("NewPaymentByBankTransfer");
787 }
788
789 print '<!-- form to select BAN -->';
790 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
791 print '<input type="hidden" name="token" value="'.newToken().'" />';
792 print '<input type="hidden" name="id" value="'.$object->id.'" />';
793 print '<input type="hidden" name="type" value="'.$type.'" />';
794 print '<input type="hidden" name="action" value="new" />';
795
796 print '<div class="center formconsumeproduce">';
797
798 //print '<table class="">';
799 //print '<tr><td class="left">'.
800 print $langs->trans('CustomerIBAN').' ';
801 //print '</td>';
802 //print '<td class="left nowraponall">';
803
804 // if societe rib in model invoice, we preselect it
805 $selectedRib = '';
806 if ($object->element == 'invoice' && $object->fk_fac_rec_source) {
807 $facturerec = new FactureRec($db);
808 $facturerec->fetch($object->fk_fac_rec_source);
809 if ($facturerec->fk_societe_rib) {
810 $companyBankAccount = new CompanyBankAccount($db);
811 $res = $companyBankAccount->fetch($facturerec->fk_societe_rib);
812 $selectedRib = $companyBankAccount->id;
813 }
814 }
815
816 $selectedRib = $form->selectRib($selectedRib, 'accountcustomerid', 'fk_soc='.$object->socid, 1, '', 1);
817
818 $defaultRibId = $object->thirdparty->getDefaultRib();
819 if ($defaultRibId) {
820 $companyBankAccount = new CompanyBankAccount($db);
821 $res = $companyBankAccount->fetch($defaultRibId);
822 if ($res > 0 && !$companyBankAccount->verif()) {
823 print img_warning('Error on default bank number for IBAN : '.$langs->trans($companyBankAccount->error));
824 }
825 } elseif ($numopen || ($type != 'bank-transfer' && $object->mode_reglement_code == 'PRE') || ($type == 'bank-transfer' && $object->mode_reglement_code == 'VIR')) {
826 print img_warning($langs->trans("NoDefaultIBANFound"));
827 }
828
829 //print '</td></tr>';
830
831 // Bank Transfer Amount
832 //print '<tr><td class="nowrap left">';
833 print ' &nbsp; &nbsp; <label for="withdraw_request_amount">'.$langs->trans('BankTransferAmount').'</label>';
834 //print '</td><td class="left">';
835 print '<input type="text" class="right width75" id="withdraw_request_amount" name="withdraw_request_amount" value="'.$remaintopaylesspendingdebit.'">';
836 //print '</td></tr>';
837
838 //print '</table>';
839
840 // Button
841 print '<br><br>';
842 print '<input type="submit" class="butAction small" value="'.$buttonlabel.'" />';
843 print '<br><br>';
844
845 print '</div>';
846
847 print '</form>';
848
849 if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT_SHOW_OLD_BUTTON')) { // This is hidden, prefer to use mode enabled with STRIPE_SEPA_DIRECT_DEBIT
850 // TODO Replace this with a checkbox for each payment mode: "Send request to XXX immediately..."
851 print "<br>";
852 //add stripe sepa button
853 $buttonlabel = $langs->trans("MakeWithdrawRequestStripe");
854 print '<form method="POST" action="">';
855 print '<input type="hidden" name="token" value="'.newToken().'" />';
856 print '<input type="hidden" name="id" value="'.$object->id.'" />';
857 print '<input type="hidden" name="type" value="'.$type.'" />';
858 print '<input type="hidden" name="action" value="new" />';
859 print '<input type="hidden" name="paymenservice" value="stripesepa" />';
860 print '<label for="withdraw_request_amount">'.$langs->trans('BankTransferAmount').' </label>';
861 print '<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="'.$remaintopaylesspendingdebit.'" size="9" />';
862 print '<input type="submit" class="butAction small" value="'.$buttonlabel.'" />';
863 print '</form>';
864 }
865 } else {
866 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$buttonlabel.'</a>';
867 }
868 } else {
869 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$buttonlabel.'</a>';
870 }
871 } else {
872 if ($num == 0) {
873 if ($object->status > $object::STATUS_DRAFT) {
874 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AlreadyPaid")).'">'.$buttonlabel.'</a>';
875 } else {
876 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("Draft")).'">'.$buttonlabel.'</a>';
877 }
878 } else {
879 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("RequestAlreadyDone")).'">'.$buttonlabel.'</a>';
880 }
881 }
882
883 print "</div>\n";
884
885
886 if ($type == 'bank-transfer') {
887 print '<div class="opacitymedium justify">'.$langs->trans("DoCreditTransferBeforePayments");
888 if (isModEnabled('stripe') && getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
889 print ' '.$langs->trans("DoStandingOrdersBeforePayments2");
890 }
891 print ' '.$langs->trans("DoStandingOrdersBeforePayments3");
892 print '</div><br><br>';
893 } else {
894 print '<div class="opacitymedium justify">'.$langs->trans("DoStandingOrdersBeforePayments");
895 if (isModEnabled('stripe') && getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
896 print ' '.$langs->trans("DoStandingOrdersBeforePayments2");
897 }
898 print ' '.$langs->trans("DoStandingOrdersBeforePayments3");
899 print '</div><br><br>';
900 }
901
902 /*
903 * Withdrawals
904 */
905
906 print '<div class="div-table-responsive-no-min">';
907 print '<table class="noborder centpercent">';
908
909 print '<tr class="liste_titre">';
910 // Action column
911 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
912 print '<td>&nbsp;</td>';
913 }
914 print '<td class="left">'.$langs->trans("DateRequest").'</td>';
915 print '<td>'.$langs->trans("User").'</td>';
916 print '<td class="center">'.$langs->trans("Amount").'</td>';
917 print '<td class="center">'.$langs->trans("IBAN").'</td>';
918 print '<td class="center">'.$langs->trans("DateProcess").'</td>';
919 if ($type == 'bank-transfer') {
920 print '<td class="">'.$langs->trans("BankTransferReceipt").'</td>';
921 } else {
922 print '<td class="">'.$langs->trans("WithdrawalReceipt").'</td>';
923 }
924 print '<td>&nbsp;</td>';
925 // Action column
926 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
927 print '<td>&nbsp;</td>';
928 }
929 print '</tr>';
930
931 $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande,";
932 $sql .= " pfd.date_traite as date_traite, pfd.amount, pfd.fk_prelevement_bons,";
933 $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,";
934 $sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status,";
935 $sql .= " sr.iban_prefix as iban, sr.bic as bic";
936 $sql .= " FROM ".$db->prefix()."prelevement_demande as pfd";
937 $sql .= " LEFT JOIN ".$db->prefix()."user as u on pfd.fk_user_demande = u.rowid";
938 $sql .= " LEFT JOIN ".$db->prefix()."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
939 $sql .= " LEFT JOIN ".$db->prefix()."societe_rib as sr ON sr.rowid = pfd.fk_societe_rib";
940 if ($type == 'bank-transfer') {
941 $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
942 } else {
943 $sql .= " WHERE fk_facture = ".((int) $object->id);
944 }
945 $sql .= " AND pfd.traite = 0";
946 $sql .= " AND pfd.type = 'ban'";
947 $sql .= " ORDER BY pfd.date_demande DESC";
948
949 $resql = $db->query($sql);
950
951 $num = 0;
952 if ($resql) {
953 $i = 0;
954
955 $tmpuser = new User($db);
956
957 $num = $db->num_rows($result);
958 while ($i < $num) {
959 $obj = $db->fetch_object($resql);
960
961 $tmpuser->id = $obj->user_id;
962 $tmpuser->login = $obj->login;
963 $tmpuser->ref = $obj->login;
964 $tmpuser->email = $obj->email;
965 $tmpuser->lastname = $obj->lastname;
966 $tmpuser->firstname = $obj->firstname;
967 $tmpuser->statut = $obj->user_status;
968 $tmpuser->status = $obj->user_status;
969
970 print '<tr class="oddeven">';
971
972 // Action column
973 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
974 print '<td class="center">';
975 print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'&did='.$obj->rowid.'&type='.urlencode($type).'">';
976 print img_delete();
977 print '</a>';
978 print '</td>';
979 }
980
981 // Date
982 print '<td class="nowraponall">'.dol_print_date($db->jdate($obj->date_demande), 'dayhour')."</td>\n";
983
984 // User
985 print '<td class="tdoverflowmax125">';
986 print $tmpuser->getNomUrl(-1, '', 0, 0, 0, 0, 'login');
987 print '</td>';
988
989 // Amount
990 print '<td class="center"><span class="amount">'.price($obj->amount).'</span></td>';
991
992 // Iban
993 print '<td class="center"><span class="iban">';
994 print dolDecrypt($obj->iban);
995 if ($obj->iban && $obj->bic) {
996 print " / ";
997 }
998 print $obj->bic;
999 print '</span></td>';
1000
1001 // Date process
1002 print '<td class="center"><span class="opacitymedium">'.$langs->trans("OrderWaiting").'</span></td>';
1003
1004 // Link to make payment now
1005 print '<td class="minwidth75">';
1006 if ($obj->fk_prelevement_bons > 0) {
1007 $withdrawreceipt = new BonPrelevement($db);
1008 $withdrawreceipt->id = $obj->fk_prelevement_bons;
1009 $withdrawreceipt->ref = $obj->ref;
1010 $withdrawreceipt->date_trans = $db->jdate($obj->date_trans);
1011 $withdrawreceipt->date_credit = $db->jdate($obj->date_credit);
1012 $withdrawreceipt->date_creation = $db->jdate($obj->datec);
1013 $withdrawreceipt->statut = $obj->status;
1014 $withdrawreceipt->status = $obj->status;
1015 $withdrawreceipt->amount = $obj->pb_amount;
1016 //$withdrawreceipt->credite = $db->jdate($obj->credite);
1017
1018 print $withdrawreceipt->getNomUrl(1);
1019 }
1020
1021 if ($type != 'bank-transfer') {
1022 if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
1023 $langs->load("stripe");
1024 if ($obj->fk_prelevement_bons > 0) {
1025 print ' &nbsp; ';
1026 }
1027 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>';
1028 }
1029 } else {
1030 if (getDolGlobalString('STRIPE_SEPA_CREDIT_TRANSFER')) {
1031 $langs->load("stripe");
1032 if ($obj->fk_prelevement_bons > 0) {
1033 print ' &nbsp; ';
1034 }
1035 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>';
1036 }
1037 }
1038 print '</td>';
1039
1040 // Withraw ref
1041 print '<td class="">';
1042 //print '<span class="opacitymedium">'.$langs->trans("OrderWaiting").'</span>';
1043 print '</td>';
1044
1045 // Action column
1046 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1047 print '<td class="center">';
1048 print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'&did='.$obj->rowid.'&type='.urlencode($type).'">';
1049 print img_delete();
1050 print '</a></td>';
1051 }
1052
1053 print "</tr>\n";
1054 $i++;
1055 }
1056
1057 $db->free($resql);
1058 } else {
1059 dol_print_error($db);
1060 }
1061
1062
1063 // Past requests
1064
1065 $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande, pfd.date_traite, pfd.fk_prelevement_bons, pfd.amount,";
1066 $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,";
1067 $sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo as user_photo,";
1068 $sql .= " sr.iban_prefix as iban, sr.bic as bic";
1069 $sql .= " FROM ".$db->prefix()."prelevement_demande as pfd";
1070 $sql .= " LEFT JOIN ".$db->prefix()."user as u on pfd.fk_user_demande = u.rowid";
1071 $sql .= " LEFT JOIN ".$db->prefix()."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
1072 $sql .= " LEFT JOIN ".$db->prefix()."societe_rib as sr ON sr.rowid = pfd.fk_societe_rib";
1073 if ($type == 'bank-transfer') {
1074 $sql .= " WHERE fk_facture_fourn = ".((int) $object->id);
1075 } else {
1076 $sql .= " WHERE fk_facture = ".((int) $object->id);
1077 }
1078 $sql .= " AND pfd.traite = 1";
1079 $sql .= " AND pfd.type = 'ban'";
1080 $sql .= " ORDER BY pfd.date_demande DESC";
1081
1082 $resql = $db->query($sql);
1083 if ($resql) {
1084 $num = $db->num_rows($resql);
1085 $numclosed = $num;
1086 $i = 0;
1087
1088 $tmpuser = new User($db);
1089
1090 while ($i < $num) {
1091 $obj = $db->fetch_object($resql);
1092
1093 $tmpuser->id = $obj->user_id;
1094 $tmpuser->login = $obj->login;
1095 $tmpuser->ref = $obj->login;
1096 $tmpuser->email = $obj->email;
1097 $tmpuser->lastname = $obj->lastname;
1098 $tmpuser->firstname = $obj->firstname;
1099 $tmpuser->statut = $obj->user_status;
1100 $tmpuser->status = $obj->user_status;
1101 $tmpuser->photo = $obj->user_photo;
1102
1103 print '<tr class="oddeven">';
1104
1105 // Action column
1106 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1107 print '<td>&nbsp;</td>';
1108 }
1109
1110 // Date
1111 print '<td class="nowraponall">'.dol_print_date($db->jdate($obj->date_demande), 'day')."</td>\n";
1112
1113 // User
1114 print '<td class="tdoverflowmax125">';
1115 print $tmpuser->getNomUrl(-1, '', 0, 0, 0, 0, 'login');
1116 print '</td>';
1117
1118 // Amount
1119 print '<td class="center"><span class="amount">'.price($obj->amount).'</span></td>';
1120
1121 // Iban
1122 print '<td class="center"><span class="iban">';
1123 print dolDecrypt($obj->iban);
1124 if ($obj->iban && $obj->bic) {
1125 print " / ";
1126 }
1127 print $obj->bic;
1128 print '</span></td>';
1129
1130 // Date process
1131 print '<td class="center nowraponall">'.dol_print_date($db->jdate($obj->date_traite), 'dayhour', 'tzuserrel')."</td>\n";
1132
1133 // Link to payment request done
1134 print '<td class="minwidth75">';
1135 if ($obj->fk_prelevement_bons > 0) {
1136 $withdrawreceipt = new BonPrelevement($db);
1137 $withdrawreceipt->id = $obj->fk_prelevement_bons;
1138 $withdrawreceipt->ref = $obj->ref;
1139 $withdrawreceipt->date_trans = $db->jdate($obj->date_trans);
1140 $withdrawreceipt->date_credit = $db->jdate($obj->date_credit);
1141 $withdrawreceipt->date_creation = $db->jdate($obj->datec);
1142 $withdrawreceipt->statut = $obj->status;
1143 $withdrawreceipt->status = $obj->status;
1144 $withdrawreceipt->fk_bank_account = $obj->fk_bank_account;
1145 $withdrawreceipt->amount = $obj->pb_amount;
1146 //$withdrawreceipt->credite = $db->jdate($obj->credite);
1147
1148 print $withdrawreceipt->getNomUrl(1);
1149 print ' ';
1150 print $withdrawreceipt->getLibStatut(2);
1151
1152 // Show the bank account
1153 $fk_bank_account = $withdrawreceipt->fk_bank_account;
1154 if (empty($fk_bank_account)) {
1155 $fk_bank_account = ($object->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
1156 }
1157 if ($fk_bank_account > 0) {
1158 $bankaccount = new Account($db);
1159 $result = $bankaccount->fetch($fk_bank_account);
1160 if ($result > 0) {
1161 print ' - ';
1162 print $bankaccount->getNomUrl(1);
1163 }
1164 }
1165 }
1166 print "</td>\n";
1167
1168 //
1169 print '<td>&nbsp;</td>';
1170
1171 // Action column
1172 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1173 print '<td>&nbsp;</td>';
1174 }
1175
1176 print "</tr>\n";
1177 $i++;
1178 }
1179
1180 if (!$numopen && !$numclosed) {
1181 print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1182 }
1183
1184 $db->free($resql);
1185 } else {
1186 dol_print_error($db);
1187 }
1188
1189 print "</table>";
1190 print '</div>';
1191}
1192
1193// End of page
1194llxFooter();
1195$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
llxFooter()
Footer empty.
Definition document.php:107
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.