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