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