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