dolibarr  9.0.0
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 <http://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','withdrawals'));
35 
36 if (!$user->rights->prelevement->bons->lire)
38 
39 // Security check
40 if ($user->societe_id > 0) accessforbidden();
41 
42 // Get supervariables
43 $action = GETPOST('action','alpha');
44 $id = GETPOST('id','int');
45 $ref = GETPOST('ref', 'alpha');
46 $socid = GETPOST('socid','int');
47 
48 // Load variable for pagination
49 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
50 $sortfield = GETPOST('sortfield','alpha');
51 $sortorder = GETPOST('sortorder','alpha');
52 $page = GETPOST('page','int');
53 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 
58 if (! $sortfield) $sortfield='pl.fk_soc';
59 if (! $sortorder) $sortorder='DESC';
60 
61 $object = new BonPrelevement($db,"");
62 
63 // Load object
64 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
65 
66 
67 /*
68  * Actions
69  */
70 
71 if ( $action == 'confirm_delete' )
72 {
73  $res=$object->delete($user);
74  if ($res > 0)
75  {
76  header("Location: index.php");
77  exit;
78  }
79 }
80 
81 // Seems to no be used and replaced with $action == 'infocredit
82 if ( $action == 'confirm_credite' && GETPOST('confirm','alpha') == 'yes')
83 {
84  $res=$object->set_credite();
85  if ($res >= 0)
86  {
87  header("Location: card.php?id=".$id);
88  exit;
89  }
90 }
91 
92 if ($action == 'infotrans' && $user->rights->prelevement->bons->send)
93 {
94  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
95 
96  $dt = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
97 
98  /*
99  if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $object->ref)
100  {
101  $dir = $conf->prelevement->dir_output.'/receipts';
102 
103  if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0)
104  {
105  $object->set_infotrans($user, $dt, GETPOST('methode','alpha'));
106  }
107 
108  header("Location: card.php?id=".$id);
109  exit;
110  }
111  else
112  {
113  dol_syslog("Fichier invalide",LOG_WARNING);
114  $mesg='BadFile';
115  }*/
116 
117  $error = $object->set_infotrans($user, $dt, GETPOST('methode','alpha'));
118 
119  if ($error)
120  {
121  header("Location: card.php?id=".$id."&error=$error");
122  exit;
123  }
124 }
125 
126 // Set direct debit order to credited, create payment and close invoices
127 if ($action == 'infocredit' && $user->rights->prelevement->bons->credit)
128 {
129  $dt = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
130 
131  $error = $object->set_infocredit($user, $dt);
132 
133  if ($error)
134  {
135  header("Location: card.php?id=".$id."&error=$error");
136  exit;
137  }
138 }
139 
140 
141 
142 /*
143  * View
144  */
145 
146 $form = new Form($db);
147 
148 llxHeader('',$langs->trans("WithdrawalsReceipts"));
149 
150 if ($id > 0 || $ref)
151 {
152  $head = prelevement_prepare_head($object);
153  dol_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
154 
155  if (GETPOST('error','alpha')!='')
156  {
157  print '<div class="error">'.$object->getErrorString(GETPOST('error','alpha')).'</div>';
158  }
159 
160  /*if ($action == 'credite')
161  {
162  print $form->formconfirm("card.php?id=".$object->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite",'',1,1);
163 
164  }*/
165 
166  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/bons.php">'.$langs->trans("BackToList").'</a>';
167 
168  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
169 
170  print '<div class="fichecenter">';
171  print '<div class="underbanner clearboth"></div>';
172  print '<table class="border" width="100%">';
173 
174  //print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
175  print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec,'day').'</td></tr>';
176  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
177 
178  // Status
179  /*
180  print '<tr><td>'.$langs->trans('Status').'</td>';
181  print '<td>'.$object->getLibStatut(1).'</td>';
182  print '</tr>';
183  */
184 
185  if($object->date_trans <> 0)
186  {
187  $muser = new User($db);
188  $muser->fetch($object->user_trans);
189 
190  print '<tr><td>'.$langs->trans("TransData").'</td><td>';
191  print dol_print_date($object->date_trans,'day');
192  print ' '.$langs->trans("By").' '.$muser->getFullName($langs).'</td></tr>';
193  print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
194  print $object->methodes_trans[$object->method_trans];
195  print '</td></tr>';
196  }
197  if($object->date_credit <> 0)
198  {
199  print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
200  print dol_print_date($object->date_credit,'day');
201  print '</td></tr>';
202  }
203 
204  print '</table>';
205 
206  print '<br>';
207 
208  print '<div class="underbanner clearboth"></div>';
209  print '<table class="border" width="100%">';
210 
211  $acc = new Account($db);
212  $result=$acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT);
213 
214  print '<tr><td class="titlefield">';
215  print $langs->trans("BankToReceiveWithdraw");
216  print '</td>';
217  print '<td>';
218  if ($acc->id > 0)
219  print $acc->getNomUrl(1);
220  print '</td>';
221  print '</tr>';
222 
223  print '<tr><td class="titlefield">';
224  print $langs->trans("WithdrawalFile").'</td><td>';
225  $relativepath = 'receipts/'.$object->ref.'.xml';
226  print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart=prelevement&amp;file='.urlencode($relativepath).'">'.$relativepath.'</a>';
227  print '</td></tr></table>';
228 
229  print '</div>';
230 
231  dol_fiche_end();
232 
233 
234 
235  if (empty($object->date_trans) && $user->rights->prelevement->bons->send && $action=='settransmitted')
236  {
237  print '<form method="post" name="userfile" action="card.php?id='.$object->id.'" enctype="multipart/form-data">';
238  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
239  print '<input type="hidden" name="action" value="infotrans">';
240  print '<table class="noborder" width="100%">';
241  print '<tr class="liste_titre">';
242  print '<td colspan="3">'.$langs->trans("NotifyTransmision").'</td></tr>';
243  print '<tr class="oddeven"><td>'.$langs->trans("TransData").'</td><td>';
244  print $form->selectDate('', '', '', '', '', "userfile", 1, 1);
245  print '</td></tr>';
246  print '<tr class="oddeven"><td>'.$langs->trans("TransMetod").'</td><td>';
247  print $form->selectarray("methode",$object->methodes_trans);
248  print '</td></tr>';
249 /* print '<tr><td width="20%">'.$langs->trans("File").'</td><td>';
250  print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
251  print '<input class="flat" type="file" name="userfile"><br>';
252  print '</td></tr>';*/
253  print '</table><br>';
254  print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("SetToStatusSent")).'"></div>';
255  print '</form>';
256  print '<br>';
257  }
258 
259  if (! empty($object->date_trans) && $object->date_credit == 0 && $user->rights->prelevement->bons->credit && $action=='setcredited')
260  {
261  print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
262  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
263  print '<input type="hidden" name="action" value="infocredit">';
264  print '<table class="noborder" width="100%">';
265  print '<tr class="liste_titre">';
266  print '<td colspan="3">'.$langs->trans("NotifyCredit").'</td></tr>';
267  print '<tr class="oddeven"><td>'.$langs->trans('CreditDate').'</td><td>';
268  print $form->selectDate('', '', '', '', '', "infocredit", 1, 1);
269  print '</td></tr>';
270  print '</table>';
271  print '<br>'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice");
272  print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("ClassCredited")).'"></div>';
273  print '</form>';
274  print '<br>';
275  }
276 
277 
278  // Actions
279  if ($action != 'settransmitted' && $action != 'setcredited')
280  {
281  print "\n<div class=\"tabsAction\">\n";
282 
283  if (empty($object->date_trans) && $user->rights->prelevement->bons->send)
284  {
285  print "<a class=\"butAction\" href=\"card.php?action=settransmitted&id=".$object->id."\">".$langs->trans("SetToStatusSent")."</a>";
286  }
287 
288  if (! empty($object->date_trans) && $object->date_credit == 0)
289  {
290  print "<a class=\"butAction\" href=\"card.php?action=setcredited&id=".$object->id."\">".$langs->trans("ClassCredited")."</a>";
291  }
292 
293  print "<a class=\"butActionDelete\" href=\"card.php?action=confirm_delete&id=".$object->id."\">".$langs->trans("Delete")."</a>";
294 
295  print "</div>";
296  }
297 
298 
299  $ligne=new LignePrelevement($db,$user);
300 
301  /*
302  * Lines into withdraw request
303  */
304  $sql = "SELECT pl.rowid, pl.statut, pl.amount,";
305  $sql.= " s.rowid as socid, s.nom as name";
306  $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
307  $sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
308  $sql.= ", ".MAIN_DB_PREFIX."societe as s";
309  $sql.= " WHERE pl.fk_prelevement_bons = ".$id;
310  $sql.= " AND pl.fk_prelevement_bons = pb.rowid";
311  $sql.= " AND pb.entity = ".$conf->entity;
312  $sql.= " AND pl.fk_soc = s.rowid";
313  if ($socid) $sql.= " AND s.rowid = ".$socid;
314  $sql.= $db->order($sortfield, $sortorder);
315 
316  // Count total nb of records
317  $nbtotalofrecords = '';
318  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
319  {
320  $result = $db->query($sql);
321  $nbtotalofrecords = $db->num_rows($result);
322  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
323  {
324  $page = 0;
325  $offset = 0;
326  }
327  }
328 
329  $sql.= $db->plimit($limit+1, $offset);
330 
331  $result = $db->query($sql);
332 
333  if ($result)
334  {
335  $num = $db->num_rows($result);
336  $i = 0;
337 
338  $urladd = "&amp;id=".$id;
339 
340  print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
341 
342  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
343  print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
344  print '<tr class="liste_titre">';
345  print_liste_field_titre("Lines",$_SERVER["PHP_SELF"],"pl.rowid",'',$urladd);
346  print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],"s.nom",'',$urladd);
347  print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],"pl.amount","",$urladd,'align="right"');
349  print "</tr>\n";
350 
351  $var=false;
352 
353  $total = 0;
354 
355  while ($i < min($num,$conf->liste_limit))
356  {
357  $obj = $db->fetch_object($result);
358 
359  print '<tr class="oddeven">';
360 
361  // Status of line
362  print "<td>";
363  print $ligne->LibStatut($obj->statut,2);
364  print "&nbsp;";
365  print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/ligne.php?id='.$obj->rowid.'">';
366  print sprintf("%06s",$obj->rowid);
367  print '</a></td>';
368 
369  $thirdparty=new Societe($db);
370  $thirdparty->fetch($obj->socid);
371  print '<td>';
372  print $thirdparty->getNomUrl(1);
373  print "</td>\n";
374 
375  print '<td align="right">'.price($obj->amount)."</td>\n";
376 
377  print '<td>';
378 
379  if ($obj->statut == 3)
380  {
381  print '<b>'.$langs->trans("StatusRefused").'</b>';
382  }
383  else
384  {
385  print "&nbsp;";
386  }
387 
388  print '</td></tr>';
389 
390  $total += $obj->amount;
391 
392  $i++;
393  }
394 
395  if ($num > 0)
396  {
397  print '<tr class="liste_total">';
398  print '<td>'.$langs->trans("Total").'</td>';
399  print '<td>&nbsp;</td>';
400  print '<td align="right">';
401  if ($total != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices");
402  print price($total);
403  print "</td>\n";
404  print '<td>&nbsp;</td>';
405  print "</tr>\n";
406  }
407 
408  print "</table>";
409  print '</div>';
410 
411  $db->free($result);
412  }
413  else
414  {
415  dol_print_error($db);
416  }
417 }
418 
419 // End of page
420 llxFooter();
421 $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
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
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
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage bank accounts.
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.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage withdrawal receipts.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
prelevement_prepare_head(BonPrelevement $object)
Prepare array with list of tabs.
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).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
Class to manage withdrawals.