dolibarr  9.0.0
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  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
34 if (! empty($conf->projet->enabled)) {
35  require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
36 }
37 
38 if (!$user->rights->facture->lire) accessforbidden();
39 
40 // Load translation files required by the page
41 $langs->loadLangs(array('bills', 'banks', 'withdrawals', 'companies'));
42 
43 $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
44 $ref=GETPOST('ref','alpha');
45 $socid=GETPOST('socid','int');
46 $action=GETPOST('action','alpha');
47 
48 $fieldid = (! empty($ref)?'facnumber':'rowid');
49 if ($user->societe_id) $socid=$user->societe_id;
50 $result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid);
51 
52 $object = new Facture($db);
53 
54 // Load object
55 if ($id > 0 || ! empty($ref))
56 {
57  $ret=$object->fetch($id, $ref);
58  if ($ret > 0)
59  {
60  $object->fetch_thirdparty();
61  }
62 }
63 
64 
65 /*
66  * Actions
67  */
68 
69 if ($action == "new")
70 {
71  if ($object->id > 0)
72  {
73  $db->begin();
74 
75  $result = $object->demande_prelevement($user, GETPOST('withdraw_request_amount'));
76  if ($result > 0)
77  {
78  $db->commit();
79 
80  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
81  }
82  else
83  {
84  $db->rollback();
85  setEventMessages($object->error, $object->errors, 'errors');
86  }
87  }
88  $action='';
89 }
90 
91 if ($action == "delete")
92 {
93  if ($object->id > 0)
94  {
95  $result = $object->demande_prelevement_delete($user, GETPOST('did'));
96  if ($result == 0)
97  {
98  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
99  exit;
100  }
101  }
102 }
103 
104 
105 /*
106  * View
107  */
108 
109 $now=dol_now();
110 
111 $title = $langs->trans('InvoiceCustomer') . " - " . $langs->trans('StandingOrders');
112 $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
113 llxHeader('', $title, $helpurl);
114 
115 $form = new Form($db);
116 
117 /* *************************************************************************** */
118 /* */
119 /* Mode fiche */
120 /* */
121 /* *************************************************************************** */
122 
123 if ($object->id > 0)
124 {
125  $selleruserevenustamp = $mysoc->useRevenueStamp();
126 
127  $totalpaye = $object->getSommePaiement();
128  $totalcreditnotes = $object->getSumCreditNotesUsed();
129  $totaldeposits = $object->getSumDepositsUsed();
130  //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
131 
132  // We can also use bcadd to avoid pb with floating points
133  // For example print 239.2 - 229.3 - 9.9; does not return 0.
134  //$resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
135  //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
136  $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
137 
138  if ($object->paye) $resteapayer=0;
139  $resteapayeraffiche=$resteapayer;
140 
141  if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
142  $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
143  $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
144  } else {
145  $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
146  $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
147  }
148 
149  $absolute_discount=$object->thirdparty->getAvailableDiscounts('',$filterabsolutediscount);
150  $absolute_creditnote=$object->thirdparty->getAvailableDiscounts('',$filtercreditnote);
151  $absolute_discount=price2num($absolute_discount,'MT');
152  $absolute_creditnote=price2num($absolute_creditnote,'MT');
153 
154  $author = new User($db);
155  if ($object->user_author)
156  {
157  $author->fetch($object->user_author);
158  }
159 
160  $head = facture_prepare_head($object);
161 
162  dol_fiche_head($head, 'standingorders', $langs->trans('InvoiceCustomer'), -1, 'bill');
163 
164  // Invoice content
165 
166  $linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
167 
168  $morehtmlref='<div class="refidno">';
169  // Ref customer
170  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
171  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
172  // Thirdparty
173  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
174  // Project
175  if (! empty($conf->projet->enabled))
176  {
177  $langs->load("projects");
178  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
179  if ($user->rights->facture->creer)
180  {
181  if ($action != 'classify')
182  //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
183  $morehtmlref.=' : ';
184  if ($action == 'classify') {
185  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
186  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
187  $morehtmlref.='<input type="hidden" name="action" value="classin">';
188  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
189  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
190  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
191  $morehtmlref.='</form>';
192  } else {
193  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
194  }
195  } else {
196  if (! empty($object->fk_project)) {
197  $proj = new Project($db);
198  $proj->fetch($object->fk_project);
199  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
200  $morehtmlref.=$proj->ref;
201  $morehtmlref.='</a>';
202  } else {
203  $morehtmlref.='';
204  }
205  }
206  }
207  $morehtmlref.='</div>';
208 
209  $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
210 
211  dol_banner_tab($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref, '', 0, '', '');
212 
213  print '<div class="fichecenter">';
214  print '<div class="fichehalfleft">';
215  print '<div class="underbanner clearboth"></div>';
216 
217  print '<table class="border" width="100%">';
218 
219  // Type
220  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td colspan="3">';
221  print $object->getLibType();
222  if ($object->type == Facture::TYPE_REPLACEMENT)
223  {
224  $facreplaced=new Facture($db);
225  $facreplaced->fetch($object->fk_facture_source);
226  print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
227  }
228  if ($object->type == Facture::TYPE_CREDIT_NOTE)
229  {
230  $facusing=new Facture($db);
231  $facusing->fetch($object->fk_facture_source);
232  print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
233  }
234 
235  $facidavoir=$object->getListIdAvoirFromInvoice();
236  if (count($facidavoir) > 0)
237  {
238  print ' ('.$langs->transnoentities("InvoiceHasAvoir");
239  $i=0;
240  foreach($facidavoir as $id)
241  {
242  if ($i==0) print ' ';
243  else print ',';
244  $facavoir=new Facture($db);
245  $facavoir->fetch($id);
246  print $facavoir->getNomUrl(1);
247  }
248  print ')';
249  }
250  /*
251  if ($facidnext > 0)
252  {
253  $facthatreplace=new Facture($db);
254  $facthatreplace->fetch($facidnext);
255  print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
256  }
257  */
258  print '</td></tr>';
259 
260  // Discounts
261  print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="3">';
262 
263  $thirdparty = $object->thirdparty;
264  $discount_type = 0;
265  $backtopage = urlencode($_SERVER["PHP_SELF"] . '?facid=' . $object->id);
266  $cannotApplyDiscount = 1;
267  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
268 
269  print '</td></tr>';
270 
271  // Date invoice
272  print '<tr><td>';
273  print '<table class="nobordernopadding" width="100%"><tr><td>';
274  print $langs->trans('DateInvoice');
275  print '</td>';
276  if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && ! empty($object->brouillon) && $user->rights->facture->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editinvoicedate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'),1).'</a></td>';
277  print '</tr></table>';
278  print '</td><td colspan="3">';
279 
280  if ($object->type != Facture::TYPE_CREDIT_NOTE)
281  {
282  if ($action == 'editinvoicedate')
283  {
284  $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id,$object->date,'invoicedate');
285  }
286  else
287  {
288  print dol_print_date($object->date,'daytext');
289  }
290  }
291  else
292  {
293  print dol_print_date($object->date,'daytext');
294  }
295  print '</td>';
296  print '</tr>';
297 
298  // Payment condition
299  print '<tr><td>';
300  print '<table class="nobordernopadding" width="100%"><tr><td>';
301  print $langs->trans('PaymentConditionsShort');
302  print '</td>';
303  if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && ! empty($object->brouillon) && $user->rights->facture->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
304  print '</tr></table>';
305  print '</td><td colspan="3">';
306  if ($object->type != Facture::TYPE_CREDIT_NOTE)
307  {
308  if ($action == 'editconditions')
309  {
310  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id');
311  }
312  else
313  {
314  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none');
315  }
316  }
317  else
318  {
319  print '&nbsp;';
320  }
321  print '</td></tr>';
322 
323  // Date payment term
324  print '<tr><td>';
325  print '<table class="nobordernopadding" width="100%"><tr><td>';
326  print $langs->trans('DateMaxPayment');
327  print '</td>';
328  if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && ! empty($object->brouillon) && $user->rights->facture->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editpaymentterm&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'),1).'</a></td>';
329  print '</tr></table>';
330  print '</td><td colspan="3">';
331  if ($object->type != Facture::TYPE_CREDIT_NOTE)
332  {
333  if ($action == 'editpaymentterm')
334  {
335  $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id,$object->date_lim_reglement,'paymentterm');
336  }
337  else
338  {
339  print dol_print_date($object->date_lim_reglement,'daytext');
340  if ($object->hasDelay()) {
341  print img_warning($langs->trans('Late'));
342  }
343  }
344  }
345  else
346  {
347  print '&nbsp;';
348  }
349  print '</td></tr>';
350 
351  // Payment mode
352  print '<tr><td>';
353  print '<table class="nobordernopadding" width="100%"><tr><td>';
354  print $langs->trans('PaymentMode');
355  print '</td>';
356  if ($action != 'editmode' && ! empty($object->brouillon) && $user->rights->facture->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
357  print '</tr></table>';
358  print '</td><td colspan="3">';
359  if ($action == 'editmode')
360  {
361  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id');
362  }
363  else
364  {
365  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
366  }
367  print '</td></tr>';
368 
369  // Bank Account
370  print '<tr><td class="nowrap">';
371  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
372  print $langs->trans('BankAccount');
373  print '<td>';
374  if (($action != 'editbankaccount') && $user->rights->commande->creer && ! empty($object->brouillon))
375  print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
376  print '</tr></table>';
377  print '</td><td colspan="3">';
378  if ($action == 'editbankaccount')
379  {
380  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
381  }
382  else
383  {
384  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
385  }
386  print "</td>";
387  print '</tr>';
388 
389  print '<tr><td>'.$langs->trans("RIB").'</td><td colspan="3">';
390  print $object->thirdparty->display_rib();
391  print '</td></tr>';
392 
393  print '</table>';
394 
395  print '</div>';
396  print '<div class="fichehalfright">';
397  print '<div class="ficheaddleft">';
398  print '<div class="underbanner clearboth"></div>';
399 
400  print '<table class="border centpercent">';
401 
402  if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
403  {
404  // Multicurrency Amount HT
405  print '<tr><td class="titlefieldmiddle">' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . '</td>';
406  print '<td class="nowrap">' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
407  print '</tr>';
408 
409  // Multicurrency Amount VAT
410  print '<tr><td>' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . '</td>';
411  print '<td class="nowrap">' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
412  print '</tr>';
413 
414  // Multicurrency Amount TTC
415  print '<tr><td>' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '</td>';
416  print '<td class="nowrap">' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
417  print '</tr>';
418  }
419 
420  // Amount
421  print '<tr><td class="titlefield">' . $langs->trans('AmountHT') . '</td>';
422  print '<td class="nowrap">' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
423 
424  // Vat
425  print '<tr><td>' . $langs->trans('AmountVAT') . '</td><td colspan="3" class="nowrap">' . price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
426  print '</tr>';
427 
428  // Amount Local Taxes
429  if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) // Localtax1
430  {
431  print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
432  print '<td class="nowrap">' . price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
433  }
434  if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) // Localtax2
435  {
436  print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
437  print '<td class=nowrap">' . price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
438  }
439 
440  // Revenue stamp
441  if ($selleruserevenustamp) // Test company use revenue stamp
442  {
443  print '<tr><td>';
444  print '<table class="nobordernopadding" width="100%"><tr><td>';
445  print $langs->trans('RevenueStamp');
446  print '</td>';
447  if ($action != 'editrevenuestamp' && ! empty($object->brouillon) && $user->rights->facture->creer)
448  {
449  print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editrevenuestamp&amp;facid=' . $object->id . '">' . img_edit($langs->trans('SetRevenuStamp'), 1) . '</a></td>';
450  }
451  print '</tr></table>';
452  print '</td><td>';
453  print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
454  print '</td></tr>';
455  }
456 
457  // Total with tax
458  print '<tr><td>' . $langs->trans('AmountTTC') . '</td><td class="nowrap">' . price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency) . '</td></tr>';
459 
460  $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
461 
462  // TODO Replace this by an include with same code to show already done payment visible in invoice card
463  print '<tr><td>'.$langs->trans('RemainderToPay').'</td><td class="nowrap">'.price($resteapayer, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
464 
465  print '</table>';
466 
467  print '</div>';
468  print '</div>';
469  print '</div>';
470 
471  print '<div class="clearboth"></div>';
472 
473 
474  dol_fiche_end();
475 
476 
477  $numopen = 0; $pending = 0; $numclosed = 0;
478 
479 
480  // How many Direct debit opened requests ?
481 
482  $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
483  $sql .= " , pfd.date_traite as date_traite";
484  $sql .= " , pfd.amount";
485  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
486  $sql .= " WHERE fk_facture = ".$object->id;
487  $sql .= " AND pfd.traite = 0";
488  $sql .= " ORDER BY pfd.date_demande DESC";
489 
490  $result_sql = $db->query($sql);
491  if ($result_sql)
492  {
493  $num = $db->num_rows($result_sql);
494  $numopen = $num;
495  }
496  else
497  {
498  dol_print_error($db);
499  }
500 
501  // For wich amount ?
502 
503  $sql = "SELECT SUM(pfd.amount) as amount";
504  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
505  $sql .= " WHERE fk_facture = ".$object->id;
506  $sql .= " AND pfd.traite = 0";
507 
508  $result_sql = $db->query($sql);
509  if ($result_sql)
510  {
511  $obj = $db->fetch_object($result_sql);
512  if ($obj) $pending = $obj->amount;
513  }
514  else
515  {
516  dol_print_error($db);
517  }
518 
519 
520  /*
521  * Buttons
522  */
523 
524  print "\n<div class=\"tabsAction\">\n";
525 
526  // Add a transfer request
527  if ($object->statut > Facture::STATUS_DRAFT && $object->paye == 0 && $num == 0)
528  {
529  if ($resteapayer > 0)
530  {
531  if ($user->rights->prelevement->bons->creer)
532  {
533  $remaintopaylesspendingdebit = $resteapayer - $pending;
534 
535  print '<form method="POST" action="">';
536  print '<input type="hidden" name="id" value="' . $object->id . '" />';
537  print '<input type="hidden" name="action" value="new" />';
538  print '<label for="withdraw_request_amount">' . $langs->trans('WithdrawRequestAmount') . ' </label>';
539  print '<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="' . $remaintopaylesspendingdebit . '" size="10" />';
540  print '<input type="submit" class="butAction" value="'.$langs->trans("MakeWithdrawRequest").'" />';
541  print '</form>';
542  }
543  else
544  {
545  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("MakeWithdrawRequest").'</a>';
546  }
547  }
548  else
549  {
550  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$langs->trans("MakeWithdrawRequest").'</a>';
551  }
552  }
553  else
554  {
555  if ($num == 0)
556  {
557  if ($object->statut > Facture::STATUS_DRAFT) print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("AlreadyPaid")).'">'.$langs->trans("MakeWithdrawRequest").'</a>';
558  else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("Draft")).'">'.$langs->trans("MakeWithdrawRequest").'</a>';
559  }
560  else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("RequestAlreadyDone")).'">'.$langs->trans("MakeWithdrawRequest").'</a>';
561  }
562 
563  print "</div><br>\n";
564 
565 
566  print '<div class="opacitymedium">'.$langs->trans("DoStandingOrdersBeforePayments").'</div><br>';
567 
568 
569  /*
570  * Withdrawals
571  */
572 
573  print '<div class="div-table-responsive-no-min">';
574  print '<table class="noborder" width="100%">';
575 
576  print '<tr class="liste_titre">';
577  print '<td align="left">'.$langs->trans("DateRequest").'</td>';
578  print '<td align="center">'.$langs->trans("User").'</td>';
579  print '<td align="center">'.$langs->trans("Amount").'</td>';
580  print '<td align="center">'.$langs->trans("WithdrawalReceipt").'</td>';
581  print '<td>&nbsp;</td>';
582  print '<td align="center">'.$langs->trans("DateProcess").'</td>';
583  print '<td>&nbsp;</td>';
584  print '</tr>';
585 
586  $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
587  $sql.= " , pfd.date_traite as date_traite, pfd.amount,";
588  $sql.= " u.rowid as user_id, u.lastname, u.firstname, u.login";
589  $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
590  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on pfd.fk_user_demande = u.rowid";
591  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
592  $sql.= " WHERE fk_facture = ".$object->id;
593  $sql.= " AND pfd.traite = 0";
594  $sql.= " ORDER BY pfd.date_demande DESC";
595 
596  $result_sql = $db->query($sql);
597 
598  $num = 0;
599  if ($result_sql)
600  {
601  $i = 0;
602 
603  $num = $db->num_rows($result);
604  while ($i < $num)
605  {
606  $obj = $db->fetch_object($result_sql);
607 
608  print '<tr class="oddeven">';
609  print '<td align="left">'.dol_print_date($db->jdate($obj->date_demande),'day')."</td>\n";
610  print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a></td>';
611  print '<td align="center">'.price($obj->amount).'</td>';
612  print '<td align="center">-</td>';
613  print '<td>&nbsp;</td>';
614 
615  print '<td align="center">'.$langs->trans("OrderWaiting").'</td>';
616 
617  print '<td align="right">';
618  print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete&amp;did='.$obj->rowid.'">';
619  print img_delete();
620  print '</a></td>';
621 
622  print "</tr>\n";
623  $i++;
624  }
625 
626  $db->free($result_sql);
627  }
628  else
629  {
630  dol_print_error($db);
631  }
632 
633 
634  // Past requests
635 
636  $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande, pfd.date_traite, pfd.fk_prelevement_bons, pfd.amount,";
637  $sql.= " pb.ref,";
638  $sql.= " u.rowid as user_id, u.lastname, u.firstname, u.login";
639  $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
640  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on pfd.fk_user_demande = u.rowid";
641  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
642  $sql.= " WHERE fk_facture = ".$object->id;
643  $sql.= " AND pfd.traite = 1";
644  $sql.= " ORDER BY pfd.date_demande DESC";
645 
646  $result = $db->query($sql);
647  if ($result)
648  {
649  $num = $db->num_rows($result);
650  $numclosed = $num;
651  $i = 0;
652 
653  while ($i < $num)
654  {
655  $obj = $db->fetch_object($result);
656 
657  print '<tr class="oddeven">';
658 
659  print '<td align="left">'.dol_print_date($db->jdate($obj->date_demande),'day')."</td>\n";
660 
661  print '<td align="center"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a></td>';
662 
663  print '<td align="center">'.price($obj->amount).'</td>';
664 
665  print '<td align="center">';
666  if ($obj->fk_prelevement_bons > 0)
667  {
668  $withdrawreceipt=new BonPrelevement($db);
669  $withdrawreceipt->id=$obj->fk_prelevement_bons;
670  $withdrawreceipt->ref=$obj->ref;
671  print $withdrawreceipt->getNomUrl(1);
672  }
673  print "</td>\n";
674 
675  print '<td>&nbsp;</td>';
676 
677  print '<td align="center">'.dol_print_date($db->jdate($obj->date_traite),'day')."</td>\n";
678 
679  print '<td>&nbsp;</td>';
680 
681  print "</tr>\n";
682  $i++;
683  }
684 
685  if (! $numopen && ! $numclosed)
686  print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
687 
688  $db->free($result);
689  }
690  else
691  {
692  dol_print_error($db);
693  }
694 
695  print "</table>";
696  print '</div>';
697 }
698 
699 // End of page
700 llxFooter();
701 $db->close();
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
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.
Class to manage Dolibarr users.
Definition: user.class.php:41
const TYPE_REPLACEMENT
Replacement invoice.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
img_delete($titlealt='default', $other='class="pictodelete"')
Show delete logo.
const TYPE_CREDIT_NOTE
Credit note invoice.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage withdrawal receipts.
dol_fiche_end($notab=0)
Show tab footer of a card.
const STATUS_DRAFT
Draft status.
llxHeader()
Empty header.
Definition: wrapper.php:44
dol_now($mode='gmt')
Return date for now.
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
Class to manage invoices.
fieldLabel($langkey, $fieldkey, $fieldrequired=0)
Show a string with the label tag dedicated to the HTML edit field.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
Definition: invoice.lib.php:36