dolibarr  13.0.2
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 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
40 
41 // Load translation files required by the page
42 $langs->loadLangs(array('bills', 'banks', 'withdrawals', 'companies'));
43 
44 $id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
45 $ref = GETPOST('ref', 'alpha');
46 $socid = GETPOST('socid', 'int');
47 $action = GETPOST('action', 'aZ09');
48 $type = GETPOST('type', 'aZ09');
49 
50 $fieldid = (!empty($ref) ? 'ref' : 'rowid');
51 if ($user->socid) $socid = $user->socid;
52 
53 if ($type == 'bank-transfer') {
54  $object = new FactureFournisseur($db);
55 } else {
56  $object = new Facture($db);
57 }
58 
59 // Load object
60 if ($id > 0 || !empty($ref))
61 {
62  $ret = $object->fetch($id, $ref);
63  $isdraft = (($object->statut == FactureFournisseur::STATUS_DRAFT) ? 1 : 0);
64  if ($ret > 0)
65  {
66  $object->fetch_thirdparty();
67  }
68 }
69 
70 $hookmanager->initHooks(array('directdebitcard', 'globalcard'));
71 
72 if ($type == 'bank-transfer') {
73  $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture', 'fk_soc', $fieldid, $isdraft);
74  if (!$user->rights->fournisseur->facture->lire) accessforbidden();
75 } else {
76  $result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid, $isdraft);
77  if (!$user->rights->facture->lire) accessforbidden();
78 }
79 
80 
81 /*
82  * Actions
83  */
84 
85 $parameters = array('socid' => $socid);
86 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
87 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
88 
89 if (empty($reshook))
90 {
91  if ($action == "new")
92  {
93  if ($object->id > 0)
94  {
95  $db->begin();
96 
97  $newtype = $type;
98  $sourcetype = 'facture';
99  if ($type == 'bank-transfer') {
100  $sourcetype = 'supplier_invoice';
101  $newtype = 'bank-transfer';
102  }
103 
104  $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $sourcetype);
105  if ($result > 0)
106  {
107  $db->commit();
108 
109  setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
110  } else {
111  $db->rollback();
112  setEventMessages($object->error, $object->errors, 'errors');
113  }
114  }
115  $action = '';
116  }
117 
118  if ($action == "delete")
119  {
120  if ($object->id > 0)
121  {
122  $result = $object->demande_prelevement_delete($user, GETPOST('did', 'int'));
123  if ($result == 0)
124  {
125  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id.'&type='.$type);
126  exit;
127  }
128  }
129  }
130 }
131 
132 
133 /*
134  * View
135  */
136 
137 $form = new Form($db);
138 
139 $now = dol_now();
140 
141 if ($type == 'bank-transfer') {
142  $title = $langs->trans('InvoiceSupplier')." - ".$langs->trans('CreditTransfer');
143  $helpurl = "";
144 } else {
145  $title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('StandingOrders');
146  $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
147 }
148 
149 llxHeader('', $title, $helpurl);
150 
151 
152 /* *************************************************************************** */
153 /* */
154 /* Mode fiche */
155 /* */
156 /* *************************************************************************** */
157 
158 if ($object->id > 0)
159 {
160  $selleruserevenustamp = $mysoc->useRevenueStamp();
161 
162  $totalpaye = $object->getSommePaiement();
163  $totalcreditnotes = $object->getSumCreditNotesUsed();
164  $totaldeposits = $object->getSumDepositsUsed();
165  //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
166 
167  // We can also use bcadd to avoid pb with floating points
168  // For example print 239.2 - 229.3 - 9.9; does not return 0.
169  //$resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
170  //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
171  $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
172 
173  if ($object->paye) $resteapayer = 0;
174  $resteapayeraffiche = $resteapayer;
175 
176  if ($type == 'bank-transfer') {
177  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { // Never use this
178  $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
179  $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
180  } else {
181  $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
182  $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
183  }
184 
185  $absolute_discount = $object->thirdparty->getAvailableDiscounts('', $filterabsolutediscount, 0, 1);
186  $absolute_creditnote = $object->thirdparty->getAvailableDiscounts('', $filtercreditnote, 0, 1);
187  $absolute_discount = price2num($absolute_discount, 'MT');
188  $absolute_creditnote = price2num($absolute_creditnote, 'MT');
189  } else {
190  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
191  $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
192  $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
193  } else {
194  $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
195  $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
196  }
197 
198  $absolute_discount = $object->thirdparty->getAvailableDiscounts('', $filterabsolutediscount);
199  $absolute_creditnote = $object->thirdparty->getAvailableDiscounts('', $filtercreditnote);
200  $absolute_discount = price2num($absolute_discount, 'MT');
201  $absolute_creditnote = price2num($absolute_creditnote, 'MT');
202  }
203 
204  $author = new User($db);
205  if ($object->user_author)
206  {
207  $author->fetch($object->user_author);
208  }
209 
210  if ($type == 'bank-transfer') {
211  $head = facturefourn_prepare_head($object);
212  } else {
213  $head = facture_prepare_head($object);
214  }
215 
216  print dol_get_fiche_head($head, 'standingorders', $title, -1, ($type == 'bank-transfer' ? 'supplier_invoice' : 'bill'));
217 
218  // Invoice content
219  if ($type == 'bank-transfer') {
220  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
221  } else {
222  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
223  }
224 
225  $morehtmlref = '<div class="refidno">';
226  // Ref customer
227  if ($type == 'bank-transfer') {
228  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
229  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
230  } else {
231  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
232  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
233  }
234  // Thirdparty
235  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
236  if ($type == 'bank-transfer') {
237  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
238  } else {
239  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
240  }
241  // Project
242  if (!empty($conf->projet->enabled))
243  {
244  $langs->load("projects");
245  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
246  if ($user->rights->facture->creer)
247  {
248  if ($action != 'classify') {
249  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
250  $morehtmlref .= ' : ';
251  }
252  if ($action == 'classify') {
253  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
254  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
255  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
256  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
257  $morehtmlref .= '<input type="hidden" name="type" value="'.$type.'">';
258  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
259  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
260  $morehtmlref .= '</form>';
261  } else {
262  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
263  }
264  } else {
265  if (!empty($object->fk_project)) {
266  $proj = new Project($db);
267  $proj->fetch($object->fk_project);
268  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
269  $morehtmlref .= $proj->ref;
270  $morehtmlref .= '</a>';
271  } else {
272  $morehtmlref .= '';
273  }
274  }
275  }
276  $morehtmlref .= '</div>';
277 
278  $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
279 
280  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '');
281 
282  print '<div class="fichecenter">';
283  print '<div class="fichehalfleft">';
284  print '<div class="underbanner clearboth"></div>';
285 
286  print '<table class="border centpercent tableforfield">';
287 
288  // Type
289  print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td colspan="3">';
290  print $object->getLibType();
291  if ($object->module_source) {
292  print ' <span class="opacitymediumbycolor">('.$langs->trans("POS").' '.$object->module_source.' - '.$langs->trans("Terminal").' '.$object->pos_source.')</span>';
293  }
294  if ($object->type == $object::TYPE_REPLACEMENT)
295  {
296  if ($type == 'bank-transfer') {
297  $facreplaced = new FactureFournisseur($db);
298  } else {
299  $facreplaced = new Facture($db);
300  }
301  $facreplaced->fetch($object->fk_facture_source);
302  print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
303  }
304  if ($object->type == $object::TYPE_CREDIT_NOTE)
305  {
306  if ($type == 'bank-transfer') {
307  $facusing = new FactureFournisseur($db);
308  } else {
309  $facusing = new Facture($db);
310  }
311  $facusing->fetch($object->fk_facture_source);
312  print ' ('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')';
313  }
314 
315  $facidavoir = $object->getListIdAvoirFromInvoice();
316  if (count($facidavoir) > 0)
317  {
318  print ' ('.$langs->transnoentities("InvoiceHasAvoir");
319  $i = 0;
320  foreach ($facidavoir as $id)
321  {
322  if ($i == 0) print ' ';
323  else print ',';
324  if ($type == 'bank-transfer') {
325  $facavoir = new FactureFournisseur($db);
326  } else {
327  $facavoir = new Facture($db);
328  }
329  $facavoir->fetch($id);
330  print $facavoir->getNomUrl(1);
331  }
332  print ')';
333  }
334  /*
335  if ($facidnext > 0)
336  {
337  $facthatreplace=new Facture($db);
338  $facthatreplace->fetch($facidnext);
339  print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
340  }
341  */
342  print '</td></tr>';
343 
344  // Discounts
345  print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="3">';
346 
347  if ($type == 'bank-transfer') {
348  //$societe = new Fournisseur($db);
349  //$result = $societe->fetch($object->socid);
350  $thirdparty = $object->thirdparty;
351  $discount_type = 1;
352  } else {
353  $thirdparty = $object->thirdparty;
354  $discount_type = 0;
355  }
356  $backtopage = urlencode($_SERVER["PHP_SELF"].'?facid='.$object->id);
357  $cannotApplyDiscount = 1;
358  include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
359 
360  print '</td></tr>';
361 
362  // Label
363  if ($type == 'bank-transfer') {
364  print '<tr>';
365  print '<td>'.$form->editfieldkey("Label", 'label', $object->label, $object, 0).'</td>';
366  print '<td>'.$form->editfieldval("Label", 'label', $object->label, $object, 0).'</td>';
367  print '</tr>';
368  }
369 
370  // Date invoice
371  print '<tr><td>';
372  print '<table class="nobordernopadding centpercent"><tr><td>';
373  print $langs->trans('DateInvoice');
374  print '</td>';
375  if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && !empty($object->brouillon) && $user->rights->facture->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editinvoicedate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
376  print '</tr></table>';
377  print '</td><td colspan="3">';
378 
379  if ($object->type != $object::TYPE_CREDIT_NOTE)
380  {
381  if ($action == 'editinvoicedate')
382  {
383  $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $object->date, 'invoicedate');
384  } else {
385  print dol_print_date($object->date, 'day');
386  }
387  } else {
388  print dol_print_date($object->date, 'day');
389  }
390  print '</td>';
391  print '</tr>';
392 
393  // Payment condition
394  print '<tr><td>';
395  print '<table class="nobordernopadding centpercent"><tr><td>';
396  print $langs->trans('PaymentConditionsShort');
397  print '</td>';
398  if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editconditions' && !empty($object->brouillon) && $user->rights->facture->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
399  print '</tr></table>';
400  print '</td><td colspan="3">';
401  if ($object->type != $object::TYPE_CREDIT_NOTE)
402  {
403  if ($action == 'editconditions')
404  {
405  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id');
406  } else {
407  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
408  }
409  } else {
410  print '&nbsp;';
411  }
412  print '</td></tr>';
413 
414  // Date payment term
415  print '<tr><td>';
416  print '<table class="nobordernopadding centpercent"><tr><td>';
417  print $langs->trans('DateMaxPayment');
418  print '</td>';
419  if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && !empty($object->brouillon) && $user->rights->facture->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editpaymentterm&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
420  print '</tr></table>';
421  print '</td><td colspan="3">';
422  if ($object->type != $object::TYPE_CREDIT_NOTE)
423  {
424  $duedate = $object->date_lim_reglement;
425  if ($type == 'bank-transfer') {
426  $duedate = $object->date_echeance;
427  }
428 
429  if ($action == 'editpaymentterm')
430  {
431  $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $duedate, 'paymentterm');
432  } else {
433  print dol_print_date($duedate, 'day');
434  if ($object->hasDelay()) {
435  print img_warning($langs->trans('Late'));
436  }
437  }
438  } else {
439  print '&nbsp;';
440  }
441  print '</td></tr>';
442 
443  // Payment mode
444  print '<tr><td>';
445  print '<table class="nobordernopadding centpercent"><tr><td>';
446  print $langs->trans('PaymentMode');
447  print '</td>';
448  if ($action != 'editmode' && !empty($object->brouillon) && $user->rights->facture->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
449  print '</tr></table>';
450  print '</td><td colspan="3">';
451  if ($action == 'editmode')
452  {
453  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id');
454  } else {
455  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
456  }
457  print '</td></tr>';
458 
459  // Bank Account
460  print '<tr><td class="nowrap">';
461  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
462  print $langs->trans('BankAccount');
463  print '<td>';
464  if (($action != 'editbankaccount') && $user->rights->commande->creer && !empty($object->brouillon))
465  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
466  print '</tr></table>';
467  print '</td><td colspan="3">';
468  if ($action == 'editbankaccount')
469  {
470  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
471  } else {
472  $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
473  }
474  print "</td>";
475  print '</tr>';
476 
477  $title = 'CustomerIBAN';
478  if ($type == 'bank-transfer') {
479  $title = 'SupplierIBAN';
480  }
481  print '<tr><td>'.$langs->trans($title).'</td><td colspan="3">';
482 
483  $bac = new CompanyBankAccount($db);
484  $bac->fetch(0, $object->thirdparty->id);
485 
486  print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
487  if (!empty($bac->iban)) {
488  if ($bac->verif() <= 0) print img_warning('Error on default bank number for IBAN : '.$bac->error_message);
489  } else {
490  print img_warning($langs->trans("NoDefaultIBANFound"));
491  }
492 
493  print '</td></tr>';
494 
495  print '</table>';
496 
497  print '</div>';
498  print '<div class="fichehalfright">';
499  print '<div class="ficheaddleft">';
500  print '<div class="underbanner clearboth"></div>';
501 
502  print '<table class="border centpercent tableforfield">';
503 
504  if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
505  {
506  // Multicurrency Amount HT
507  print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';
508  print '<td class="nowrap">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
509  print '</tr>';
510 
511  // Multicurrency Amount VAT
512  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>';
513  print '<td class="nowrap">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
514  print '</tr>';
515 
516  // Multicurrency Amount TTC
517  print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>';
518  print '<td class="nowrap">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
519  print '</tr>';
520  }
521 
522  // Amount
523  print '<tr><td class="titlefield">'.$langs->trans('AmountHT').'</td>';
524  print '<td class="nowrap">'.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
525 
526  // Vat
527  print '<tr><td>'.$langs->trans('AmountVAT').'</td><td colspan="3" class="nowrap">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
528  print '</tr>';
529 
530  // Amount Local Taxes
531  if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) // Localtax1
532  {
533  print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
534  print '<td class="nowrap">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
535  }
536  if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) // Localtax2
537  {
538  print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
539  print '<td class=nowrap">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
540  }
541 
542  // Revenue stamp
543  if ($selleruserevenustamp) // Test company use revenue stamp
544  {
545  print '<tr><td>';
546  print '<table class="nobordernopadding" width="100%"><tr><td>';
547  print $langs->trans('RevenueStamp');
548  print '</td>';
549  if ($action != 'editrevenuestamp' && !empty($object->brouillon) && $user->rights->facture->creer)
550  {
551  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrevenuestamp&amp;facid='.$object->id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'</a></td>';
552  }
553  print '</tr></table>';
554  print '</td><td>';
555  print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
556  print '</td></tr>';
557  }
558 
559  // Total with tax
560  print '<tr><td>'.$langs->trans('AmountTTC').'</td><td class="nowrap">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
561 
562  $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
563 
564  // TODO Replace this by an include with same code to show already done payment visible in invoice card
565  print '<tr><td>'.$langs->trans('RemainderToPay').'</td><td class="nowrap">'.price($resteapayer, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
566 
567  print '</table>';
568 
569  print '</div>';
570  print '</div>';
571  print '</div>';
572 
573  print '<div class="clearboth"></div>';
574 
575 
576  print dol_get_fiche_end();
577 
578 
579  $numopen = 0; $pending = 0; $numclosed = 0;
580 
581 
582  // How many Direct debit opened requests ?
583 
584  $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
585  $sql .= " , pfd.date_traite as date_traite";
586  $sql .= " , pfd.amount";
587  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
588  if ($type == 'bank-transfer') {
589  $sql .= " WHERE fk_facture_fourn = ".$object->id;
590  } else {
591  $sql .= " WHERE fk_facture = ".$object->id;
592  }
593  $sql .= " AND pfd.traite = 0";
594  $sql .= " AND pfd.ext_payment_id IS NULL";
595  $sql .= " ORDER BY pfd.date_demande DESC";
596 
597  $result_sql = $db->query($sql);
598  if ($result_sql)
599  {
600  $num = $db->num_rows($result_sql);
601  $numopen = $num;
602  } else {
603  dol_print_error($db);
604  }
605 
606  // For which amount ?
607 
608  $sql = "SELECT SUM(pfd.amount) as amount";
609  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
610  if ($type == 'bank-transfer') {
611  $sql .= " WHERE fk_facture_fourn = ".$object->id;
612  } else {
613  $sql .= " WHERE fk_facture = ".$object->id;
614  }
615  $sql .= " AND pfd.traite = 0";
616  $sql .= " AND pfd.ext_payment_id IS NULL";
617 
618  $result_sql = $db->query($sql);
619  if ($result_sql)
620  {
621  $obj = $db->fetch_object($result_sql);
622  if ($obj) $pending = $obj->amount;
623  } else {
624  dol_print_error($db);
625  }
626 
627 
628  /*
629  * Buttons
630  */
631 
632  print "\n<div class=\"tabsAction\">\n";
633 
634  $buttonlabel = $langs->trans("MakeWithdrawRequest");
635  $user_perms = $user->rights->prelevement->bons->creer;
636  if ($type == 'bank-transfer') {
637  $buttonlabel = $langs->trans("MakeBankTransferOrder");
638  $user_perms = $user->rights->paymentbybanktransfer->create;
639  }
640 
641  // Add a transfer request
642  if ($object->statut > $object::STATUS_DRAFT && $object->paye == 0 && $num == 0)
643  {
644  if ($resteapayer > 0)
645  {
646  if ($user_perms)
647  {
648  $remaintopaylesspendingdebit = $resteapayer - $pending;
649 
650  print '<form method="POST" action="">';
651  print '<input type="hidden" name="token" value="'.newToken().'" />';
652  print '<input type="hidden" name="id" value="'.$object->id.'" />';
653  print '<input type="hidden" name="type" value="'.$type.'" />';
654  print '<input type="hidden" name="action" value="new" />';
655  print '<label for="withdraw_request_amount">'.$langs->trans('BankTransferAmount').' </label>';
656  print '<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="'.$remaintopaylesspendingdebit.'" size="9" />';
657  print '<input type="submit" class="butAction" value="'.$buttonlabel.'" />';
658  print '</form>';
659  } else {
660  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$buttonlabel.'</a>';
661  }
662  } else {
663  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$buttonlabel.'</a>';
664  }
665  } else {
666  if ($num == 0)
667  {
668  if ($object->statut > $object::STATUS_DRAFT) print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AlreadyPaid")).'">'.$buttonlabel.'</a>';
669  else print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("Draft")).'">'.$buttonlabel.'</a>';
670  } else {
671  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("RequestAlreadyDone")).'">'.$buttonlabel.'</a>';
672  }
673  }
674 
675  print "</div><br>\n";
676 
677 
678  if ($type == 'bank-transfer') {
679  print '<div class="opacitymedium">'.$langs->trans("DoCreditTransferBeforePayments").'</div><br>';
680  } else {
681  print '<div class="opacitymedium">'.$langs->trans("DoStandingOrdersBeforePayments").'</div><br>';
682  }
683 
684  /*
685  * Withdrawals
686  */
687 
688  print '<div class="div-table-responsive-no-min">';
689  print '<table class="noborder centpercent">';
690 
691  print '<tr class="liste_titre">';
692  print '<td class="left">'.$langs->trans("DateRequest").'</td>';
693  print '<td class="center">'.$langs->trans("User").'</td>';
694  print '<td class="center">'.$langs->trans("Amount").'</td>';
695  if ($type == 'bank-transfer') {
696  print '<td class="center">'.$langs->trans("BankTransferReceipt").'</td>';
697  } else {
698  print '<td class="center">'.$langs->trans("WithdrawalReceipt").'</td>';
699  }
700  print '<td>&nbsp;</td>';
701  print '<td class="center">'.$langs->trans("DateProcess").'</td>';
702  print '<td>&nbsp;</td>';
703  print '</tr>';
704 
705  $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande,";
706  $sql .= " pfd.date_traite as date_traite, pfd.amount,";
707  $sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status";
708  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
709  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on pfd.fk_user_demande = u.rowid";
710  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
711  if ($type == 'bank-transfer') {
712  $sql .= " WHERE fk_facture_fourn = ".$object->id;
713  } else {
714  $sql .= " WHERE fk_facture = ".$object->id;
715  }
716  $sql .= " AND pfd.traite = 0";
717  $sql .= " AND pfd.ext_payment_id IS NULL";
718  $sql .= " ORDER BY pfd.date_demande DESC";
719 
720  $result_sql = $db->query($sql);
721 
722  $num = 0;
723  if ($result_sql)
724  {
725  $i = 0;
726 
727  $tmpuser = new User($db);
728 
729  $num = $db->num_rows($result);
730  while ($i < $num)
731  {
732  $obj = $db->fetch_object($result_sql);
733 
734  $tmpuser->id = $obj->user_id;
735  $tmpuser->login = $obj->login;
736  $tmpuser->ref = $obj->login;
737  $tmpuser->email = $obj->email;
738  $tmpuser->lastname = $obj->lastname;
739  $tmpuser->firstname = $obj->firstname;
740  $tmpuser->statut = $obj->user_status;
741 
742  print '<tr class="oddeven">';
743 
744  print '<td class="left">'.dol_print_date($db->jdate($obj->date_demande), 'dayhour')."</td>\n";
745 
746  print '<td align="center">';
747  print $tmpuser->getNomUrl(1, '', 0, 0, 0, 0, 'login');
748  print '</td>';
749 
750  print '<td class="center">'.price($obj->amount).'</td>';
751  print '<td align="center">-</td>';
752  print '<td>&nbsp;</td>';
753 
754  print '<td class="center">'.$langs->trans("OrderWaiting").'</td>';
755 
756  print '<td class="right">';
757  print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'&did='.$obj->rowid.'&type='.$type.'">';
758  print img_delete();
759  print '</a></td>';
760 
761  print "</tr>\n";
762  $i++;
763  }
764 
765  $db->free($result_sql);
766  } else {
767  dol_print_error($db);
768  }
769 
770 
771  // Past requests
772 
773  $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande, pfd.date_traite, pfd.fk_prelevement_bons, pfd.amount,";
774  $sql .= " pb.ref,";
775  $sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status";
776  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
777  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on pfd.fk_user_demande = u.rowid";
778  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons";
779  if ($type == 'bank-transfer') {
780  $sql .= " WHERE fk_facture_fourn = ".$object->id;
781  } else {
782  $sql .= " WHERE fk_facture = ".$object->id;
783  }
784  $sql .= " AND pfd.traite = 1";
785  $sql .= " AND pfd.ext_payment_id IS NULL";
786  $sql .= " ORDER BY pfd.date_demande DESC";
787 
788  $result = $db->query($sql);
789  if ($result)
790  {
791  $num = $db->num_rows($result);
792  $numclosed = $num;
793  $i = 0;
794 
795  $tmpuser = new User($db);
796 
797  while ($i < $num)
798  {
799  $obj = $db->fetch_object($result);
800 
801  $tmpuser->id = $obj->user_id;
802  $tmpuser->login = $obj->login;
803  $tmpuser->ref = $obj->login;
804  $tmpuser->email = $obj->email;
805  $tmpuser->lastname = $obj->lastname;
806  $tmpuser->firstname = $obj->firstname;
807  $tmpuser->statut = $obj->user_status;
808 
809  print '<tr class="oddeven">';
810 
811  print '<td class="left">'.dol_print_date($db->jdate($obj->date_demande), 'day')."</td>\n";
812 
813  print '<td align="center">';
814  print $tmpuser->getNomUrl(1, '', 0, 0, 0, 0, 'login');
815  print '</td>';
816 
817  print '<td class="center">'.price($obj->amount).'</td>';
818 
819  print '<td class="center">';
820  if ($obj->fk_prelevement_bons > 0)
821  {
822  $withdrawreceipt = new BonPrelevement($db);
823  $withdrawreceipt->id = $obj->fk_prelevement_bons;
824  $withdrawreceipt->ref = $obj->ref;
825  print $withdrawreceipt->getNomUrl(1);
826  }
827  print "</td>\n";
828 
829  print '<td>&nbsp;</td>';
830 
831  print '<td class="center">'.dol_print_date($db->jdate($obj->date_traite), 'day')."</td>\n";
832 
833  print '<td>&nbsp;</td>';
834 
835  print "</tr>\n";
836  $i++;
837  }
838 
839  if (!$numopen && !$numclosed)
840  print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
841 
842  $db->free($result);
843  } else {
844  dol_print_error($db);
845  }
846 
847  print "</table>";
848  print '</div>';
849 }
850 
851 // End of page
852 llxFooter();
853 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage bank accounts description of third parties.
Class to manage suppliers invoices.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning 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...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage withdrawal receipts.
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.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
facturefourn_prepare_head($object)
Prepare array with list of tabs.
Definition: fourn.lib.php:34
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
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_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage invoices.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
Definition: invoice.lib.php:36