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