dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'withdrawals'));
35 
36 // Security check
37 if ($user->socid > 0) accessforbidden();
38 
39 // Get supervariables
40 $action = GETPOST('action', 'aZ09');
41 $id = GETPOST('id', 'int');
42 $ref = GETPOST('ref', 'alpha');
43 $socid = GETPOST('socid', 'int');
44 $type = GETPOST('type', 'aZ09');
45 
46 // Load variable for pagination
47 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
48 $sortfield = GETPOST('sortfield', 'aZ09comma');
49 $sortorder = GETPOST('sortorder', 'aZ09comma');
50 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
51 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
52 $offset = $limit * $page;
53 $pageprev = $page - 1;
54 $pagenext = $page + 1;
55 
56 if (!$sortfield) $sortfield = 'pl.fk_soc';
57 if (!$sortorder) $sortorder = 'DESC';
58 
59 $object = new BonPrelevement($db);
60 
61 // Load object
62 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
63 
64 $hookmanager->initHooks(array('directdebitprevcard', 'globalcard', 'directdebitprevlist'));
65 
66 if (!$user->rights->prelevement->bons->lire && $object->type != 'bank-transfer') {
68 }
69 if (!$user->rights->paymentbybanktransfer->read && $object->type == 'bank-transfer') {
71 }
72 
73 
74 /*
75  * Actions
76  */
77 
78 $parameters = array('socid' => $socid);
79 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
80 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
81 
82 if (empty($reshook))
83 {
84  if ($action == 'confirm_delete')
85  {
86  $res = $object->delete($user);
87  if ($res > 0)
88  {
89  if ($object->type == 'bank-transfer') {
90  header("Location: ".DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php');
91  } else {
92  header("Location: ".DOL_URL_ROOT.'/compta/prelevement/index.php');
93  }
94  exit;
95  }
96  }
97 
98  // Seems to no be used and replaced with $action == 'infocredit'
99  if ($action == 'confirm_credite' && GETPOST('confirm', 'alpha') == 'yes')
100  {
101  if ($object->statut == 2) {
102  $res = -1;
103  setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors');
104  } else {
105  $res = $object->set_credite();
106  }
107 
108  if ($res >= 0)
109  {
110  header("Location: card.php?id=".$id);
111  exit;
112  }
113  }
114 
115  if ($action == 'infotrans' && $user->rights->prelevement->bons->send)
116  {
117  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
118 
119  $dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
120 
121  /*
122  if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $object->ref)
123  {
124  $dir = $conf->prelevement->dir_output.'/receipts';
125 
126  if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0)
127  {
128  $object->set_infotrans($user, $dt, GETPOST('methode','alpha'));
129  }
130 
131  header("Location: card.php?id=".$id);
132  exit;
133  }
134  else
135  {
136  dol_syslog("Fichier invalide",LOG_WARNING);
137  $mesg='BadFile';
138  }*/
139 
140  $error = $object->set_infotrans($user, $dt, GETPOST('methode', 'alpha'));
141 
142  if ($error)
143  {
144  header("Location: card.php?id=".$id."&error=$error");
145  exit;
146  }
147  }
148 
149  // Set direct debit order to credited, create payment and close invoices
150  if ($action == 'infocredit' && $user->rights->prelevement->bons->credit)
151  {
152  $dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
153 
154  if ($object->statut == 2) {
155  $error = 1;
156  setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors');
157  } else {
158  $error = $object->set_infocredit($user, $dt);
159  }
160 
161  if ($error)
162  {
163  setEventMessages($object->error, $object->errors, 'errors');
164  }
165  }
166 }
167 
168 
169 
170 /*
171  * View
172  */
173 
174 $form = new Form($db);
175 
176 llxHeader('', $langs->trans("WithdrawalsReceipts"));
177 
178 if ($id > 0 || $ref)
179 {
180  $head = prelevement_prepare_head($object);
181  print dol_get_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
182 
183  if (GETPOST('error', 'alpha') != '')
184  {
185  print '<div class="error">'.$object->getErrorString(GETPOST('error', 'alpha')).'</div>';
186  }
187 
188  /*if ($action == 'credite')
189  {
190  print $form->formconfirm("card.php?id=".$object->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite",'',1,1);
191 
192  }*/
193 
194  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/orders_list.php?restore_lastsearch_values=1'.($object->type != 'bank-transfer' ? '' : '&type=bank-transfer').'">'.$langs->trans("BackToList").'</a>';
195 
196  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
197 
198  print '<div class="fichecenter">';
199  print '<div class="underbanner clearboth"></div>';
200  print '<table class="border centpercent tableforfield">';
201 
202  //print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
203  print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
204  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
205 
206  // Status
207  /*
208  print '<tr><td>'.$langs->trans('Status').'</td>';
209  print '<td>'.$object->getLibStatut(1).'</td>';
210  print '</tr>';
211  */
212 
213  if ($object->date_trans <> 0)
214  {
215  $muser = new User($db);
216  $muser->fetch($object->user_trans);
217 
218  print '<tr><td>'.$langs->trans("TransData").'</td><td>';
219  print dol_print_date($object->date_trans, 'day');
220  print ' <span class="opacitymedium">'.$langs->trans("By").'</span> '.$muser->getFullName($langs).'</td></tr>';
221  print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
222  print $object->methodes_trans[$object->method_trans];
223  print '</td></tr>';
224  }
225  if ($object->date_credit <> 0)
226  {
227  print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
228  print dol_print_date($object->date_credit, 'day');
229  print '</td></tr>';
230  }
231 
232  print '</table>';
233 
234  print '<br>';
235 
236  print '<div class="underbanner clearboth"></div>';
237  print '<table class="border centpercent tableforfield">';
238 
239  $acc = new Account($db);
240  $result = $acc->fetch(($object->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT));
241 
242  print '<tr><td class="titlefield">';
243  $labelofbankfield = "BankToReceiveWithdraw";
244  if ($object->type == 'bank-transfer') $labelofbankfield = 'BankToPayCreditTransfer';
245  print $langs->trans($labelofbankfield);
246  print '</td>';
247  print '<td>';
248  if ($acc->id > 0)
249  print $acc->getNomUrl(1);
250  print '</td>';
251  print '</tr>';
252 
253  print '<tr><td class="titlefield">';
254  $labelfororderfield = 'WithdrawalFile';
255  if ($object->type == 'bank-transfer') $labelfororderfield = 'CreditTransferFile';
256  print $langs->trans($labelfororderfield).'</td><td>';
257  $relativepath = 'receipts/'.$object->ref.'.xml';
258  $modulepart = 'prelevement';
259  if ($object->type == 'bank-transfer') $modulepart = 'paymentbybanktransfer';
260  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath.'</a>';
261  print '</td></tr></table>';
262 
263  print '</div>';
264 
266 
267 
268  $formconfirm = '';
269 
270  // Confirmation to delete
271  if ($action == 'delete')
272  {
273  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Delete'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
274  }
275 
276  // Call Hook formConfirm
277  /*$parameters = array('formConfirm' => $formconfirm);
278  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
279  if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
280  elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;*/
281 
282  // Print form confirm
283  print $formconfirm;
284 
285 
286  if (empty($object->date_trans) && $user->rights->prelevement->bons->send && $action == 'settransmitted')
287  {
288  print '<form method="post" name="userfile" action="card.php?id='.$object->id.'" enctype="multipart/form-data">';
289  print '<input type="hidden" name="token" value="'.newToken().'">';
290  print '<input type="hidden" name="action" value="infotrans">';
291  print '<table class="noborder centpercent">';
292  print '<tr class="liste_titre">';
293  print '<td colspan="3">'.$langs->trans("NotifyTransmision").'</td></tr>';
294  print '<tr class="oddeven"><td>'.$langs->trans("TransData").'</td><td>';
295  print $form->selectDate('', '', '', '', '', "userfile", 1, 1);
296  print '</td></tr>';
297  print '<tr class="oddeven"><td>'.$langs->trans("TransMetod").'</td><td>';
298  print $form->selectarray("methode", $object->methodes_trans);
299  print '</td></tr>';
300  print '</table><br>';
301  print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("SetToStatusSent")).'"></div>';
302  print '</form>';
303  print '<br>';
304  }
305 
306  if (!empty($object->date_trans) && $object->date_credit == 0 && $user->rights->prelevement->bons->credit && $action == 'setcredited')
307  {
308  print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
309  print '<input type="hidden" name="token" value="'.newToken().'">';
310  print '<input type="hidden" name="action" value="infocredit">';
311  print '<table class="noborder centpercent">';
312  print '<tr class="liste_titre">';
313  print '<td colspan="3">'.$langs->trans("NotifyCredit").'</td></tr>';
314  print '<tr class="oddeven"><td>'.$langs->trans('CreditDate').'</td><td>';
315  print $form->selectDate('', '', '', '', '', "infocredit", 1, 1);
316  print '</td></tr>';
317  print '</table>';
318  print '<br><div class="center"><span class="opacitymedium">'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice").'</span></div>';
319  print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("ClassCredited")).'"></div>';
320  print '</form>';
321  print '<br>';
322  }
323 
324 
325  // Actions
326  if ($action != 'settransmitted' && $action != 'setcredited')
327  {
328  print "\n<div class=\"tabsAction\">\n";
329 
330  if (empty($object->date_trans) && $user->rights->prelevement->bons->send)
331  {
332  print "<a class=\"butAction\" href=\"card.php?action=settransmitted&token='.newToken().'&id=".$object->id."\">".$langs->trans("SetToStatusSent")."</a>";
333  }
334 
335  if (!empty($object->date_trans) && $object->date_credit == 0)
336  {
337  print "<a class=\"butAction\" href=\"card.php?action=setcredited&token='.newToken().'&id=".$object->id."\">".$langs->trans("ClassCredited")."</a>";
338  }
339 
340  print "<a class=\"butActionDelete\" href=\"card.php?action=delete&token='.newToken().'&id=".$object->id."\">".$langs->trans("Delete")."</a>";
341 
342  print "</div>";
343  }
344 
345 
346  $ligne = new LignePrelevement($db);
347 
348  /*
349  * Lines into withdraw request
350  */
351  $sql = "SELECT pl.rowid, pl.statut, pl.amount,";
352  $sql .= " s.rowid as socid, s.nom as name";
353  $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
354  $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
355  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
356  $sql .= " WHERE pl.fk_prelevement_bons = ".$id;
357  $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
358  $sql .= " AND pb.entity = ".$conf->entity;
359  $sql .= " AND pl.fk_soc = s.rowid";
360  if ($socid) $sql .= " AND s.rowid = ".$socid;
361  $sql .= $db->order($sortfield, $sortorder);
362 
363  // Count total nb of records
364  $nbtotalofrecords = '';
365  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
366  {
367  $result = $db->query($sql);
368  $nbtotalofrecords = $db->num_rows($result);
369  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
370  {
371  $page = 0;
372  $offset = 0;
373  }
374  }
375 
376  $sql .= $db->plimit($limit + 1, $offset);
377 
378  $result = $db->query($sql);
379 
380  if ($result)
381  {
382  $num = $db->num_rows($result);
383  $i = 0;
384 
385  $urladd = "&amp;id=".$id;
386 
387  print '<form method="get" action="'.$_SERVER ['PHP_SELF'].'" name="search_form">'."\n";
388  print '<input type="hidden" name="id" value="'.$id.'"/>';
389  print '<input type="hidden" name="socid" value="'.$socid.'"/>';
390  if (!empty($page)) {
391  print '<input type="hidden" name="page" value="'.$page.'"/>';
392  }
393  if (!empty($limit)) {
394  print '<input type="hidden" name="limit" value="'.$limit.'"/>';
395  }
396  print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
397 
398  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
399  print '<table class="noborder liste" width="100%" cellspacing="0" cellpadding="4">';
400  print '<tr class="liste_titre">';
401  print_liste_field_titre("Lines", $_SERVER["PHP_SELF"], "pl.rowid", '', $urladd);
402  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $urladd);
403  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $urladd, 'class="right"');
405  print "</tr>\n";
406 
407  $total = 0;
408 
409  while ($i < min($num, $limit))
410  {
411  $obj = $db->fetch_object($result);
412 
413  print '<tr class="oddeven">';
414 
415  // Status of line
416  print "<td>";
417  print $ligne->LibStatut($obj->statut, 2);
418  print "&nbsp;";
419  print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'&type='.$object->type.'">';
420  print sprintf("%06s", $obj->rowid);
421  print '</a></td>';
422 
423  $thirdparty = new Societe($db);
424  $thirdparty->fetch($obj->socid);
425  print '<td>';
426  print $thirdparty->getNomUrl(1);
427  print "</td>\n";
428 
429  print '<td class="right">'.price($obj->amount)."</td>\n";
430 
431  print '<td class="right">';
432 
433  if ($obj->statut == 3)
434  {
435  print '<b>'.$langs->trans("StatusRefused").'</b>';
436  } else {
437  if ($object->statut == BonPrelevement::STATUS_CREDITED)
438  {
439  if ($obj->statut == 2) {
440  if ($user->rights->prelevement->bons->credit)
441  {
442  //print '<a class="butActionDelete" href="line.php?action=rejet&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>';
443  print '<a href="line.php?action=rejet&type='.$object->type.'&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>';
444  } else {
445  //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
446  }
447  }
448  } else {
449  //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
450  }
451  }
452 
453  print '</td></tr>';
454 
455  $total += $obj->amount;
456 
457  $i++;
458  }
459 
460  if ($num > 0)
461  {
462  print '<tr class="liste_total">';
463  print '<td>'.$langs->trans("Total").'</td>';
464  print '<td>&nbsp;</td>';
465  print '<td class="right">';
466  if (empty($offset) && $num <= $limit) // If we have all record on same page, then the following test/warning can be done
467  {
468  if ($total != $object->amount) print img_warning("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines");
469  }
470  print price($total);
471  print "</td>\n";
472  print '<td>&nbsp;</td>';
473  print "</tr>\n";
474  }
475 
476  print "</table>";
477  print '</div>';
478  print '</form>';
479 
480  $db->free($result);
481  } else {
482  dol_print_error($db);
483  }
484 }
485 
486 // End of page
487 llxFooter();
488 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage bank accounts.
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.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage withdrawal receipts.
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 ...
prelevement_prepare_head(BonPrelevement $object)
Prepare array with list of tabs.
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...
dol_get_fiche_end($notab=0)
Return tab footer 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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
Class to manage withdrawals.