dolibarr  7.0.0-beta
releve.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2015 Jean-Fran├žois Ferry <jfefe@aternatik.fr>
6  * Copyright (C) 2017 Patrick Delcroix <pmpdelcroix@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
28 require('../../main.inc.php');
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
40 //show files
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
43 
44 $langs->loadLangs(array("banks","categories","companies","bills","trips"));
45 
46 $action=GETPOST('action', 'alpha');
47 $id=GETPOST('account','int');
48 $ref=GETPOST('ref','alpha');
49 $dvid=GETPOST('dvid','alpha');
50 $numref=GETPOST('num','alpha');
51 $ve=GETPOST("ve",'alpha');
52 $brref=GETPOST('brref','alpha');
53 $oldbankreceipt=GETPOST('oldbankreceipt','alpha');
54 $newbankreceipt=GETPOST('newbankreceipt','alpha');
55 
56 // Security check
57 $fieldid = (! empty($ref)?$ref:$id);
58 $fieldname = isset($ref)?'ref':'rowid';
59 if ($user->societe_id) $socid=$user->societe_id;
60 $result=restrictedArea($user,'banque',$fieldid,'bank_account','','',$fieldname);
61 
62 if ($user->rights->banque->consolidate && $action == 'dvnext' && ! empty($dvid))
63 {
64  $al = new AccountLine($db);
65  $al->datev_next($dvid);
66 }
67 
68 if ($user->rights->banque->consolidate && $action == 'dvprev' && ! empty($dvid))
69 {
70  $al = new AccountLine($db);
71  $al->datev_previous($dvid);
72 }
73 
74 
75 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
76 $sortfield = GETPOST("sortfield",'alpha');
77 $sortorder = GETPOST("sortorder",'alpha');
78 $page = GETPOST("page",'int');
79 $pageplusone = GETPOST("pageplusone",'int');
80 if ($pageplusone) $page = $pageplusone - 1;
81 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
82 $offset = $limit * $page;
83 $pageprev = $page - 1;
84 $pagenext = $page + 1;
85 if (! $sortorder) $sortorder="ASC";
86 if (! $sortfield) $sortfield="s.nom";
87 
88 $object = new Account($db);
89 if ($id > 0 || ! empty($ref))
90 {
91  $result=$object->fetch($id, $ref);
92  $account = $object->id; // Force the search field on id of account
93 }
94 
95 
96 // Initialize technical object to manage context to save list fields
97 $contextpage='banktransactionlist'.(empty($object->ref)?'':'-'.$object->id);
98 
99 
100 // Define number of receipt to show (current, previous or next one ?)
101 $found=false;
102 if ($_GET["rel"] == 'prev')
103 {
104  // Recherche valeur pour num = numero releve precedent
105  $sql = "SELECT DISTINCT(b.num_releve) as num";
106  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
107  $sql.= " WHERE b.num_releve < '".$db->escape($numref)."'";
108  $sql.= " AND b.fk_account = ".$object->id;
109  $sql.= " ORDER BY b.num_releve DESC";
110 
111  dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
112  $resql = $db->query($sql);
113  if ($resql)
114  {
115  $numrows = $db->num_rows($resql);
116  if ($numrows > 0)
117  {
118  $obj = $db->fetch_object($resql);
119  $numref = $obj->num;
120  $found=true;
121  }
122  }
123 }
124 elseif ($_GET["rel"] == 'next')
125 {
126  // Recherche valeur pour num = numero releve precedent
127  $sql = "SELECT DISTINCT(b.num_releve) as num";
128  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
129  $sql.= " WHERE b.num_releve > '".$db->escape($numref)."'";
130  $sql.= " AND b.fk_account = ".$object->id;
131  $sql.= " ORDER BY b.num_releve ASC";
132 
133  dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
134  $resql = $db->query($sql);
135  if ($resql)
136  {
137  $numrows = $db->num_rows($resql);
138  if ($numrows > 0)
139  {
140  $obj = $db->fetch_object($resql);
141  $numref = $obj->num;
142  $found=true;
143  }
144  }
145 }
146 else {
147  // On veut le releve num
148  $found=true;
149 }
150 
151 
152 $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
153 $sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
154 $sql.= " b.fk_bordereau,";
155 $sql.= " bc.ref,";
156 $sql.= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
157 $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
158 $sql.= ", ".MAIN_DB_PREFIX."bank as b";
159 $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bordereau_cheque as bc ON bc.rowid=b.fk_bordereau';
160 $sql.= " WHERE b.num_releve='".$db->escape($numref)."'";
161 if (empty($numref)) $sql.= " OR b.num_releve is null";
162 $sql.= " AND b.fk_account = ".$object->id;
163 $sql.= " AND b.fk_account = ba.rowid";
164 $sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
165 
166 $sqlrequestforbankline = $sql;
167 
168 
169 
170 /*
171  * Actions
172  */
173 
174 if ($action == 'confirm_editbankreceipt' && ! empty($oldbankreceipt) && ! empty($newbankreceipt))
175 {
176  // TODO Add a test to check newbankreceipt does not exists yet
177  $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX.'bank SET num_releve = "'.$db->escape($newbankreceipt).'" WHERE num_releve = "'.$db->escape($oldbankreceipt).'"';
178  $result = $db->query($sqlupdate);
179  if ($result < 0) dol_print_error($db);
180 
181  $action='view';
182 }
183 
184 // ZIP creation
185 if ($action=="dl" && $numref > 0)
186 {
187  // TODO Replace this with a standard builddoc action that use a document generation module to build the ZIP
188  $log = '';
189 
190  $outdir = $conf->bank->dir_temp.'/'.$numref.'-'.$object->label;
191  $outdirinvoices = $outdir.'/'.$langs->trans("BillsCustomers");
192  $outdirsupplierinvoices = $outdir.'/'.$langs->trans("BillsSuppliers");
193 
194  dol_mkdir($outdir);
195  dol_mkdir($outdirinvoices);
196  dol_mkdir($outdirsupplierinvoices);
197 
198  //$zipname = $object->label.'-'.$numref . '.zip';
199  //$zip = new ZipArchive();
200  //$zip->open($zipname, ZipArchive::OVERWRITE);
201 
202  $sql = $sqlrequestforbankline;
203 
204  $facturestatic=new Facture($db);
205 
206  $resd = $db->query($sql);
207  if ($resd) {
208  $numd = $db->num_rows($resd);
209  $i = 0;
210  if ($numd > 0)
211  {
212  $objd = $db->fetch_object($resd);
213 
214  $log.='Transaction '.$objd->rowid;
215  $links = $object->get_url($objd->rowid);
216 
217  foreach($links as $key=>$val)
218  {
219  $link = ''; $upload_dir = '';
220 
221  switch ($val['type']) {
222  case "payment":
223  $payment = new Paiement($db);
224  $payment->fetch($val['url_id']);
225  $arraybill = $payment->getBillsArray();
226  if (is_array($arraybill) && count($arraybill) > 0)
227  {
228  foreach ($arraybill as $billid)
229  {
230  $facturestatic->fetch($billid);
231  $subdir = get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice');
232 
233  $arrayofinclusion=array(); // TODO Find a way to get doc ODT or other
234  // TODO Use get_exdir
235  $arrayofinclusion[]=preg_quote($facturestatic->ref.'.pdf','/');
236  $listoffiles = dol_dir_list($conf->facture->dir_output.$subdir,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true);
237  // build list of files with full path
238  $files = array();
239  foreach($listoffiles as $filefound)
240  {
241  if (strstr($filefound["name"],$facturestatic->ref))
242  {
243  $files[] = $uploaddir.'/'.$facturestatic->ref.'/'.$filefound["name"];
244  break;
245  }
246  }
247  /*var_dump($files);*/
248  //var_dump($listoffiles);
249  foreach($listoffiles as $key => $srcfileobj)
250  {
251  $srcfile = $srcfileobj['fullname'];
252  $destfile = $outdirinvoices.'/'.$srcfileobj['name'];
253  //var_dump($srcfile.' - '.$destfile);
254  dol_copy($srcfile, $destfile);
255  }
256  }
257  }
258  break;
259  case "payment_supplier":
260  $payment = new PaiementFourn($db);
261  $payment->fetch($val['url_id']);
262  $arraybill = $payment->getBillsArray();
263  if (is_array($arraybill) && count($arraybill) > 0)
264  {
265  foreach ($arraybill as $billid)
266  {
267  $facturestatic->fetch($billid);
268  $subdir = get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice_supplier');
269 
270  $arrayofinclusion=array(); // TODO Find a way to get doc ODT or other
271  // TODO Use get_exdir
272  $arrayofinclusion[]=preg_quote($facturestatic->ref.'.pdf','/');
273  $listoffiles = dol_dir_list($conf->fournisseur->facture->dir_output.$subdir,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true);
274  // build list of files with full path
275  $files = array();
276  foreach($listoffiles as $filefound)
277  {
278  if (strstr($filefound["name"],$facturestatic->ref))
279  {
280  $files[] = $uploaddir.'/'.$facturestatic->ref.'/'.$filefound["name"];
281  break;
282  }
283  }
284  /*var_dump($files);*/
285  //var_dump($listoffiles);
286  foreach($listoffiles as $key => $srcfileobj)
287  {
288  $srcfile = $srcfileobj['fullname'];
289  $destfile = $outdirinvoices.'/'.$srcfileobj['name'];
290  //var_dump($srcfile.' - '.$destfile);
291  dol_copy($srcfile, $destfile);
292  }
293  }
294  }
295  break;
296  case "payment_expensereport":
297  /*$subdir = dol_sanitizeFileName($objd->refe);
298  $upload_dir = $conf->expensereport->dir_output . '/' . $subdir;*/
299  break;
300  case "payment_salary":
301  /*$subdir = dol_sanitizeFileName($objd->ids);
302  $upload_dir = $conf->salaries->dir_output . '/' . $subdir;*/
303  break;
304  case "payment_donation":
305  /*$subdir = get_exdir(null, 2, 0, 1, $objd, 'donation') . '/' . dol_sanitizeFileName($objd->idd);
306  $upload_dir = $conf->don->dir_output . '/' . $subdir;*/
307  break;
308  default:
309  break;
310  }
311  }
312  $log.="\n";
313 
314  /*if (! empty($upload_dir))
315  {
316  $files = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
317 
318  if (is_array($files)) {
319  foreach ($files as $file) {
320  $zip->addFile($file["fullname"], $file["name"]); //
321  $log .= $key . ',' . $file["name"] . "\n";
322  }
323  } else {
324  $log .= $key . ',' . $langs->trans("Nofile") . "\n";
325  }
326 
327  }*/
328  }
329  }
330 
331  $db->free($resd);
332 
333 
334  //$zip->addFromString('log '.$numref.'.csv', $log);
335  //$zip->close();
336 
337  // /Then download the zipped file.
338  /*header('Content-Type: application/zip');
339  header('Content-disposition: attachment; filename=' . $zipname);
340  header('Content-Length: ' . filesize($zipname));
341 
342  readfile($zipname);
343 
344  exit;*/
345 }
346 
347 
348 /*
349  * View
350  */
351 
352 $title = $langs->trans("FinancialAccount").' - '.$langs->trans("AccountStatements");
353 $helpurl = "";
354 llxHeader('',$title,$helpurl);
355 
356 $form = new Form($db);
357 $societestatic=new Societe($db);
358 $chargestatic=new ChargeSociales($db);
359 $memberstatic=new Adherent($db);
360 $paymentstatic=new Paiement($db);
361 $paymentsupplierstatic=new PaiementFourn($db);
362 $paymentvatstatic=new TVA($db);
363 $bankstatic=new Account($db);
364 $banklinestatic=new AccountLine($db);
365 $remisestatic = new RemiseCheque($db);
366 
367 // Must be before button action
368 $param='';
369 if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
370 if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
371 if ($id > 0) $param.='&id='.urlencode($id);
372 
373 
374 if (empty($numref))
375 {
376  $sortfield='numr';
377  $sortorder='DESC';
378 
379  // List of all standing receipts
380  $sql = "SELECT DISTINCT(b.num_releve) as numr";
381  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
382  $sql.= " WHERE b.fk_account = ".$object->id;
383  $sql.=$db->order($sortfield,$sortorder);
384 
385  // Count total nb of records
386  $nbtotalofrecords = '';
387  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
388  {
389  $result = $db->query($sql);
390  $nbtotalofrecords = $db->num_rows($result);
391  }
392 
393  $sql.= $db->plimit($conf->liste_limit+1,$offset);
394 
395  $result = $db->query($sql);
396  if ($result)
397  {
398  $var=True;
399  $numrows = $db->num_rows($result);
400  $i = 0;
401 
402  // Onglets
403  $head=bank_prepare_head($object);
404  dol_fiche_head($head,'statement',$langs->trans("FinancialAccount"),0,'account');
405 
406  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
407 
408  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
409 
410  dol_fiche_end();
411 
412 
413  print '<div class="tabsAction">';
414 
415  if ($object->canBeConciliated() > 0) {
416  // If not cash account and can be reconciliate
417  if ($user->rights->banque->consolidate) {
418  print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?action=reconcile&search_conciliated=0'.$param.'">'.$langs->trans("Conciliate").'</a>';
419  } else {
420  print '<a class="butActionRefused" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$langs->trans("Conciliate").'</a>';
421  }
422  }
423 
424  print '</div>';
425 
426 
427  print_barre_liste('', $page, $_SERVER["PHP_SELF"], "&account=".$object->id, $sortfield, $sortorder,'',$numrows, $totalnboflines, '');
428 
429  print '<form name="aaa" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
430  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
431  print '<input type="hidden" name="action" value="confirm_editbankreceipt">';
432  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
433  print '<input type="hidden" name="account" value="'.$object->id.'">';
434 
435  print '<table class="noborder" width="100%">';
436  print '<tr class="liste_titre">';
437  print '<td>'.$langs->trans("Ref").'</td>';
438  print '<td align="right">'.$langs->trans("InitialBankBalance").'</td>';
439  print '<td align="right">'.$langs->trans("EndBankBalance").'</td>';
440  print '<td></td>';
441  print '</tr>';
442 
443  $balancestart=array();
444  $content=array();
445 
446  while ($i < min($numrows,$conf->liste_limit))
447  {
448  $objp = $db->fetch_object($result);
449 
450  if (! isset($objp->numr))
451  {
452  //
453  }
454  else
455  {
456  print '<tr class="oddeven">';
457  print '<td>';
458  if ($action != 'editbankreceipt' || $objp->numr != $brref)
459  {
460  print '<a href="releve.php?num='.$objp->numr.'&account='.$object->id.'">'.$objp->numr.'</a>';
461  }
462  else
463  {
464  print '<input type="hidden" name="oldbankreceipt" value="'.$objp->numr.'">';
465  print '<input type="text" name="newbankreceipt" value="'.$objp->numr.'">';
466  print '<input type="submit" class="button" name="actionnewbankreceipt" value="'.$langs->trans("Rename").'">';
467  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
468  }
469  print '</td>';
470 
471  // Calculate start amount
472  $sql = "SELECT sum(b.amount) as amount";
473  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
474  $sql.= " WHERE b.num_releve < '".$db->escape($objp->numr)."'";
475  $sql.= " AND b.fk_account = ".$object->id;
476  $resql=$db->query($sql);
477  if ($resql)
478  {
479  $obj=$db->fetch_object($resql);
480  $balancestart[$objp->numr] = $obj->amount;
481  $db->free($resql);
482  }
483  print '<td align="right">'.price($balancestart[$objp->numr],'',$langs,1,-1,-1,$conf->currency).'</td>';
484 
485  // Calculate end amount
486  $sql = "SELECT sum(b.amount) as amount";
487  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
488  $sql.= " WHERE b.num_releve = '".$db->escape($objp->numr)."'";
489  $sql.= " AND b.fk_account = ".$object->id;
490  $resql=$db->query($sql);
491  if ($resql)
492  {
493  $obj=$db->fetch_object($resql);
494  $content[$objp->numr] = $obj->amount;
495  $db->free($resql);
496  }
497  print '<td align="right">'.price(($balancestart[$objp->numr]+$content[$objp->numr]),'',$langs,1,-1,-1,$conf->currency).'</td>';
498 
499  print '<td align="center">';
500  if ($user->rights->banque->consolidate && $action != 'editbankreceipt') {
501  print '<a href="'.$_SERVER["PHP_SELF"].'?account='.$object->id.'&action=editbankreceipt&brref='.$objp->numr.'">'.img_edit().'</a>';
502  }
503  print '</td>';
504 
505  print '</tr>'."\n";
506  }
507  $i++;
508  }
509  print "</table>\n";
510  print '</form>';
511 
512  print "\n</div>\n";
513  }
514  else
515  {
516  dol_print_error($db);
517  }
518 }
519 else
520 {
525  $mesprevnext='';
526  $mesprevnext.='<div class="pagination"><ul>';
527  $mesprevnext.='<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?rel=prev&amp;num='.$numref.'&amp;ve='.$ve.'&amp;account='.$object->id.'"><i class="fa fa-chevron-left" title="'.dol_escape_htmltag($langs->trans("Previous")).'"></i></a></li>';
528  //$mesprevnext.=' &nbsp; ';
529  $mesprevnext.='<li class="pagination"><span class="active">'.$langs->trans("AccountStatement")." ".$numref.'</span></li>';
530  //$mesprevnext.=' &nbsp; ';
531  $mesprevnext.='<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?rel=next&amp;num='.$numref.'&amp;ve='.$ve.'&amp;account='.$object->id.'"><i class="fa fa-chevron-right" title="'.dol_escape_htmltag($langs->trans("Next")).'"></i></a></li>';
532  $mesprevnext.='</ul></div>';
533 
534  $title=$langs->trans("AccountStatement").' '.$numref.' - '.$langs->trans("BankAccount").' '.$object->getNomUrl(1, 'receipts');
535  print load_fiche_titre($title, $mesprevnext, 'title_bank.png');
536  //print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, 0, $nbtotalofrecords, 'title_bank.png', 0, '', '', 0, 1);
537  print '<br>';
538 
539  print "<form method=\"post\" action=\"releve.php\">";
540  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
541  print "<input type=\"hidden\" name=\"action\" value=\"add\">";
542 
543  print '<div class="div-table-responsive">';
544  print '<table class="noborder" width="100%">';
545  print '<tr class="liste_titre">';
546  print '<td align="center">'.$langs->trans("DateOperationShort").'</td>';
547  print '<td align="center">'.$langs->trans("DateValueShort").'</td>';
548  print '<td>'.$langs->trans("Type").'</td>';
549  print '<td>'.$langs->trans("Description").'</td>';
550  print '<td align="right" width="60">'.$langs->trans("Debit").'</td>';
551  print '<td align="right" width="60">'.$langs->trans("Credit").'</td>';
552  print '<td align="right">'.$langs->trans("Balance").'</td>';
553  print '<td>&nbsp;</td>';
554  print "</tr>\n";
555 
556  // Calcul du solde de depart du releve
557  $sql = "SELECT sum(b.amount) as amount";
558  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
559  $sql.= " WHERE b.num_releve < '".$db->escape($numref)."'";
560  $sql.= " AND b.fk_account = ".$object->id;
561 
562  $resql=$db->query($sql);
563  if ($resql)
564  {
565  $obj=$db->fetch_object($resql);
566  $total = $obj->amount;
567  $db->free($resql);
568  }
569 
570  // Recherche les ecritures pour le releve
571  $sql = $sqlrequestforbankline;
572 
573  $result = $db->query($sql);
574  if ($result)
575  {
576  $var=False;
577  $numrows = $db->num_rows($result);
578  $i = 0;
579 
580  // Ligne Solde debut releve
581  print '<tr class="oddeven"><td colspan="3"></td>';
582  print '<td colspan="3"><b>'.$langs->trans("InitialBankBalance")." :</b></td>";
583  print '<td class="right"><b>'.price($total).'</b></td><td>&nbsp;</td>';
584  print "</tr>\n";
585 
586  while ($i < $numrows)
587  {
588  $objp = $db->fetch_object($result);
589  $total = $total + $objp->amount;
590 
591  print '<tr class="oddeven">';
592 
593  // Date operation
594  print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->do),"day").'</td>';
595 
596  // Date de valeur
597  print '<td align="center" valign="center" class="nowrap">';
598  print dol_print_date($db->jdate($objp->dv),"day") .' ';
599  print '<a href="releve.php?action=dvprev&amp;num='.$numref.'&amp;account='.$object->id.'&amp;dvid='.$objp->rowid.'">';
600  print img_edit_remove() . "</a> ";
601  print '<a href="releve.php?action=dvnext&amp;num='.$numref.'&amp;account='.$object->id.'&amp;dvid='.$objp->rowid.'">';
602  print img_edit_add() ."</a>";
603  print "</td>\n";
604  print '<a class="ajax" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
605 
606  // Type and num
607  if ($objp->fk_type == 'SOLD') {
608  $type_label='&nbsp;';
609  } else {
610  $type_label=($langs->trans("PaymentTypeShort".$objp->fk_type)!="PaymentTypeShort".$objp->fk_type)?$langs->trans("PaymentTypeShort".$objp->fk_type):$objp->fk_type;
611  }
612  $link='';
613  if ($objp->fk_bordereau>0) {
614  $remisestatic->id = $objp->fk_bordereau;
615  $remisestatic->ref = $objp->ref;
616  $link = ' '.$remisestatic->getNomUrl(1);
617  }
618  print '<td class="nowrap">'.$type_label.' '.($objp->num_chq?$objp->num_chq:'').$link.'</td>';
619 
620  // Description
621  print '<td valign="center"><a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$object->id.'">';
622  $reg=array();
623  preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parenthese on tente recherche de traduction
624  if ($reg[1] && $langs->trans($reg[1])!=$reg[1]) print $langs->trans($reg[1]);
625  else print $objp->label;
626  print '</a>';
627 
628  /*
629  * Ajout les liens (societe, company...)
630  */
631  $newline=1;
632  $links = $object->get_url($objp->rowid);
633  foreach($links as $key=>$val)
634  {
635  if (! $newline) print ' - ';
636  else print '<br>';
637  if ($links[$key]['type']=='payment')
638  {
639  $paymentstatic->id=$links[$key]['url_id'];
640  $paymentstatic->ref=$langs->trans("Payment");
641  print ' '.$paymentstatic->getNomUrl(1);
642  $newline=0;
643  }
644  elseif ($links[$key]['type']=='payment_supplier')
645  {
646  $paymentsupplierstatic->id=$links[$key]['url_id'];
647  $paymentsupplierstatic->ref=$langs->trans("Payment");
648  print ' '.$paymentsupplierstatic->getNomUrl(1);
649  $newline=0;
650  }
651  elseif ($links[$key]['type']=='payment_sc')
652  {
653  print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$links[$key]['url_id'].'">';
654  print ' '.img_object($langs->trans('ShowPayment'),'payment').' ';
655  print $langs->trans("SocialContributionPayment");
656  print '</a>';
657  $newline=0;
658  }
659  elseif ($links[$key]['type']=='payment_vat')
660  {
661  $paymentvatstatic->id=$links[$key]['url_id'];
662  $paymentvatstatic->ref=$langs->trans("Payment");
663  print ' '.$paymentvatstatic->getNomUrl(1);
664  }
665  elseif ($links[$key]['type']=='payment_salary')
666  {
667  print '<a href="'.DOL_URL_ROOT.'/compta/salaries/card.php?id='.$links[$key]['url_id'].'">';
668  print ' '.img_object($langs->trans('ShowPayment'),'payment').' ';
669  print $langs->trans("Payment");
670  print '</a>';
671  $newline=0;
672  }
673  elseif ($links[$key]['type']=='banktransfert') {
674  // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
675  if ($objp->amount > 0)
676  {
677  $banklinestatic->fetch($links[$key]['url_id']);
678  $bankstatic->id=$banklinestatic->fk_account;
679  $bankstatic->label=$banklinestatic->bank_account_label;
680  print ' ('.$langs->trans("from").' ';
681  print $bankstatic->getNomUrl(1,'transactions');
682  print ' '.$langs->trans("toward").' ';
683  $bankstatic->id=$objp->bankid;
684  $bankstatic->label=$objp->bankref;
685  print $bankstatic->getNomUrl(1,'');
686  print ')';
687  }
688  else
689  {
690  $bankstatic->id=$objp->bankid;
691  $bankstatic->label=$objp->bankref;
692  print ' ('.$langs->trans("from").' ';
693  print $bankstatic->getNomUrl(1,'');
694  print ' '.$langs->trans("toward").' ';
695  $banklinestatic->fetch($links[$key]['url_id']);
696  $bankstatic->id=$banklinestatic->fk_account;
697  $bankstatic->label=$banklinestatic->bank_account_label;
698  print $bankstatic->getNomUrl(1,'transactions');
699  print ')';
700  }
701  }
702  elseif ($links[$key]['type']=='company') {
703  $societestatic->id = $links[$key]['url_id'];
704  $societestatic->name = $links[$key]['label'];
705  print $societestatic->getNomUrl(1, 'company', 24);
706  $newline=0;
707  }
708  elseif ($links[$key]['type']=='member') {
709  print '<a href="'.DOL_URL_ROOT.'/adherents/card.php?rowid='.$links[$key]['url_id'].'">';
710  print img_object($langs->trans('ShowMember'),'user').' ';
711  print $links[$key]['label'];
712  print '</a>';
713  $newline=0;
714  }
715  elseif ($links[$key]['type']=='user') {
716  print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$links[$key]['url_id'].'">';
717  print img_object($langs->trans('ShowUser'),'user').' ';
718  print $links[$key]['label'];
719  print '</a>';
720  $newline=0;
721  }
722  elseif ($links[$key]['type']=='sc') {
723  print '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
724  print img_object($langs->trans('ShowBill'),'bill').' ';
725  print $langs->trans("SocialContribution");
726  print '</a>';
727  $newline=0;
728  }
729  else {
730  print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
731  print $links[$key]['label'];
732  print '</a>';
733  $newline=0;
734  }
735  }
736 
737  // Categories
738  if ($ve)
739  {
740  $sql = "SELECT label";
741  $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ as ct";
742  $sql.= ", ".MAIN_DB_PREFIX."bank_class as cl";
743  $sql.= " WHERE ct.rowid = cl.fk_categ";
744  $sql.= " AND ct.entity = ".$conf->entity;
745  $sql.= " AND cl.lineid = ".$objp->rowid;
746 
747  $resc = $db->query($sql);
748  if ($resc)
749  {
750  $numc = $db->num_rows($resc);
751  $ii = 0;
752  if ($numc && ! $newline) print '<br>';
753  while ($ii < $numc)
754  {
755  $objc = $db->fetch_object($resc);
756  print "<br>-&nbsp;<i>$objc->label</i>";
757  $ii++;
758  }
759  }
760  else
761  {
762  dol_print_error($db);
763  }
764  }
765 
766  print "</td>";
767 
768  if ($objp->amount < 0)
769  {
770  $totald = $totald + abs($objp->amount);
771  print '<td align="right" class="nowrap">'.price($objp->amount * -1)."</td><td>&nbsp;</td>\n";
772  }
773  else
774  {
775  $totalc = $totalc + abs($objp->amount);
776  print '<td>&nbsp;</td><td align="right" class="nowrap">'.price($objp->amount)."</td>\n";
777  }
778 
779  print '<td align="right" class="nowrap">'.price($total)."</td>\n";
780 
781  if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
782  {
783  print '<td align="center"><a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&account='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?account='.$object->id.'&num='.$numref).'">';
784  print img_edit();
785  print "</a></td>";
786  }
787  else
788  {
789  print "<td align=\"center\">&nbsp;</td>";
790  }
791  print "</tr>";
792  $i++;
793  }
794  $db->free($result);
795  }
796 
797  // Line Total
798  print "\n".'<tr class="liste_total"><td align="right" colspan="4">'.$langs->trans("Total")." :</td><td align=\"right\">".price($totald)."</td><td align=\"right\">".price($totalc)."</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
799 
800  // Line Balance
801  print "\n<tr><td align=\"right\" colspan=\"3\">&nbsp;</td><td colspan=\"3\"><b>".$langs->trans("EndBankBalance")." :</b></td>";
802  print '<td class="right"><b>'.price($total)."</b></td><td>&nbsp;</td>";
803  print "</tr>\n";
804  print "</table>";
805  print "</div>";
806 
807  print "</form>\n";
808 
809  // Add a download button
810  if ($conf->global->MAIN_FEATURES_LEVEL >= 2) // Started a rewrite to make this feature more Dolibarr compliant. Still need dev to be completed.
811  {
812  // TODO Replace this with standard box to generate document.
813  print '<a href="'.DOL_URL_ROOT.'/compta/bank/releve.php?num='.$numref.'&account='.$id.'&action=dl" class="butAction" name="Send" >'.$langs->trans('DownloadPackageWithAllDocuments')." </a>\n";
814  }
815 }
816 
817 
818 llxFooter();
819 
820 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:631
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition: bank.lib.php:34
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
Return a path to have a the directory according to object where files are stored. ...
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 bank transaction lines.
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
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Class to manage bank accounts.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="")
Scan a directory and return a list of files/directories.
Definition: files.lib.php:58
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage payments of customer invoices.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Class to manage members of a foundation.
llxHeader()
Empty header.
Definition: wrapper.php:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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).
img_edit_add($titlealt= 'default', $other= '')
Show logo +.
print
Draft customers invoices.
Definition: index.php:91
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
Class to manage invoices.
Class to manage payments for supplier invoices.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.
Class to manage cheque delivery receipts.
img_edit_remove($titlealt= 'default', $other='')
Show logo -.