dolibarr  9.0.0
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@inodbox.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 // Load translation files required by the page
45 $langs->loadLangs(array("banks","categories","companies","bills","trips"));
46 
47 $action=GETPOST('action', 'alpha');
48 $id=GETPOST('account','int');
49 $ref=GETPOST('ref','alpha');
50 $dvid=GETPOST('dvid','alpha');
51 $numref=GETPOST('num','alpha');
52 $ve=GETPOST("ve",'alpha');
53 $brref=GETPOST('brref','alpha');
54 $oldbankreceipt=GETPOST('oldbankreceipt','alpha');
55 $newbankreceipt=GETPOST('newbankreceipt','alpha');
56 
57 // Security check
58 $fieldid = (! empty($ref)?$ref:$id);
59 $fieldname = isset($ref)?'ref':'rowid';
60 if ($user->societe_id) $socid=$user->societe_id;
61 $result=restrictedArea($user,'banque',$fieldid,'bank_account','','',$fieldname);
62 
63 if ($user->rights->banque->consolidate && $action == 'dvnext' && ! empty($dvid))
64 {
65  $al = new AccountLine($db);
66  $al->datev_next($dvid);
67 }
68 
69 if ($user->rights->banque->consolidate && $action == 'dvprev' && ! empty($dvid))
70 {
71  $al = new AccountLine($db);
72  $al->datev_previous($dvid);
73 }
74 
75 
76 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
77 $sortfield = GETPOST("sortfield",'alpha');
78 $sortorder = GETPOST("sortorder",'alpha');
79 $page = GETPOST("page",'int');
80 $pageplusone = GETPOST("pageplusone",'int');
81 if ($pageplusone) $page = $pageplusone - 1;
82 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
83 $offset = $limit * $page;
84 $pageprev = $page - 1;
85 $pagenext = $page + 1;
86 if (! $sortorder) $sortorder="ASC";
87 if (! $sortfield) $sortfield="s.nom";
88 
89 $object = new Account($db);
90 if ($id > 0 || ! empty($ref))
91 {
92  $result=$object->fetch($id, $ref);
93  $account = $object->id; // Force the search field on id of account
94 }
95 
96 
97 // Initialize technical object to manage context to save list fields
98 $contextpage='banktransactionlist'.(empty($object->ref)?'':'-'.$object->id);
99 
100 
101 // Define number of receipt to show (current, previous or next one ?)
102 $found=false;
103 if ($_GET["rel"] == 'prev')
104 {
105  // Recherche valeur pour num = numero releve precedent
106  $sql = "SELECT DISTINCT(b.num_releve) as num";
107  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
108  $sql.= " WHERE b.num_releve < '".$db->escape($numref)."'";
109  $sql.= " AND b.fk_account = ".$object->id;
110  $sql.= " ORDER BY b.num_releve DESC";
111 
112  dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
113  $resql = $db->query($sql);
114  if ($resql)
115  {
116  $numrows = $db->num_rows($resql);
117  if ($numrows > 0)
118  {
119  $obj = $db->fetch_object($resql);
120  $numref = $obj->num;
121  $found=true;
122  }
123  }
124 }
125 elseif ($_GET["rel"] == 'next')
126 {
127  // Recherche valeur pour num = numero releve precedent
128  $sql = "SELECT DISTINCT(b.num_releve) as num";
129  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
130  $sql.= " WHERE b.num_releve > '".$db->escape($numref)."'";
131  $sql.= " AND b.fk_account = ".$object->id;
132  $sql.= " ORDER BY b.num_releve ASC";
133 
134  dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
135  $resql = $db->query($sql);
136  if ($resql)
137  {
138  $numrows = $db->num_rows($resql);
139  if ($numrows > 0)
140  {
141  $obj = $db->fetch_object($resql);
142  $numref = $obj->num;
143  $found=true;
144  }
145  }
146 }
147 else {
148  // On veut le releve num
149  $found=true;
150 }
151 
152 
153 $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
154 $sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
155 $sql.= " b.fk_bordereau,";
156 $sql.= " bc.ref,";
157 $sql.= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
158 $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
159 $sql.= ", ".MAIN_DB_PREFIX."bank as b";
160 $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bordereau_cheque as bc ON bc.rowid=b.fk_bordereau';
161 $sql.= " WHERE b.num_releve='".$db->escape($numref)."'";
162 if (empty($numref)) $sql.= " OR b.num_releve is null";
163 $sql.= " AND b.fk_account = ".$object->id;
164 $sql.= " AND b.fk_account = ba.rowid";
165 $sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
166 
167 $sqlrequestforbankline = $sql;
168 
169 
170 
171 /*
172  * Actions
173  */
174 
175 if ($action == 'confirm_editbankreceipt' && ! empty($oldbankreceipt) && ! empty($newbankreceipt))
176 {
177  // TODO Add a test to check newbankreceipt does not exists yet
178  $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX.'bank SET num_releve = "'.$db->escape($newbankreceipt).'" WHERE num_releve = "'.$db->escape($oldbankreceipt).'"';
179  $result = $db->query($sqlupdate);
180  if ($result < 0) dol_print_error($db);
181 
182  $action='view';
183 }
184 
185 // ZIP creation
186 if ($action=="dl" && $numref > 0)
187 {
188  // TODO Replace this with a standard builddoc action that use a document generation module to build the ZIP
189  $log = '';
190 
191  $outdir = $conf->bank->dir_temp.'/'.$numref.'-'.$object->label;
192  $outdirinvoices = $outdir.'/'.$langs->trans("BillsCustomers");
193  $outdirsupplierinvoices = $outdir.'/'.$langs->trans("BillsSuppliers");
194 
195  dol_mkdir($outdir);
196  dol_mkdir($outdirinvoices);
197  dol_mkdir($outdirsupplierinvoices);
198 
199  //$zipname = $object->label.'-'.$numref . '.zip';
200  //$zip = new ZipArchive();
201  //$zip->open($zipname, ZipArchive::OVERWRITE);
202 
203  $sql = $sqlrequestforbankline;
204 
205  $facturestatic=new Facture($db);
206 
207  $resd = $db->query($sql);
208  if ($resd) {
209  $numd = $db->num_rows($resd);
210  $i = 0;
211  if ($numd > 0)
212  {
213  $objd = $db->fetch_object($resd);
214 
215  $log.='Transaction '.$objd->rowid;
216  $links = $object->get_url($objd->rowid);
217 
218  foreach($links as $key=>$val)
219  {
220  $link = ''; $upload_dir = '';
221 
222  switch ($val['type']) {
223  case "payment":
224  $payment = new Paiement($db);
225  $payment->fetch($val['url_id']);
226  $arraybill = $payment->getBillsArray();
227  if (is_array($arraybill) && count($arraybill) > 0)
228  {
229  foreach ($arraybill as $billid)
230  {
231  $facturestatic->fetch($billid);
232  $subdir = get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice');
233 
234  $arrayofinclusion=array(); // TODO Find a way to get doc ODT or other
235  // TODO Use get_exdir
236  $arrayofinclusion[]=preg_quote($facturestatic->ref.'.pdf','/');
237  $listoffiles = dol_dir_list($conf->facture->dir_output.$subdir,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true);
238  // build list of files with full path
239  $files = array();
240  foreach($listoffiles as $filefound)
241  {
242  if (strstr($filefound["name"],$facturestatic->ref))
243  {
244  $files[] = $uploaddir.'/'.$facturestatic->ref.'/'.$filefound["name"];
245  break;
246  }
247  }
248  /*var_dump($files);*/
249  //var_dump($listoffiles);
250  foreach($listoffiles as $key => $srcfileobj)
251  {
252  $srcfile = $srcfileobj['fullname'];
253  $destfile = $outdirinvoices.'/'.$srcfileobj['name'];
254  //var_dump($srcfile.' - '.$destfile);
255  dol_copy($srcfile, $destfile);
256  }
257  }
258  }
259  break;
260  case "payment_supplier":
261  $payment = new PaiementFourn($db);
262  $payment->fetch($val['url_id']);
263  $arraybill = $payment->getBillsArray();
264  if (is_array($arraybill) && count($arraybill) > 0)
265  {
266  foreach ($arraybill as $billid)
267  {
268  $facturestatic->fetch($billid);
269  $subdir = get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice_supplier');
270 
271  $arrayofinclusion=array(); // TODO Find a way to get doc ODT or other
272  // TODO Use get_exdir
273  $arrayofinclusion[]=preg_quote($facturestatic->ref.'.pdf','/');
274  $listoffiles = dol_dir_list($conf->fournisseur->facture->dir_output.$subdir,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true);
275  // build list of files with full path
276  $files = array();
277  foreach($listoffiles as $filefound)
278  {
279  if (strstr($filefound["name"],$facturestatic->ref))
280  {
281  $files[] = $uploaddir.'/'.$facturestatic->ref.'/'.$filefound["name"];
282  break;
283  }
284  }
285  /*var_dump($files);*/
286  //var_dump($listoffiles);
287  foreach($listoffiles as $key => $srcfileobj)
288  {
289  $srcfile = $srcfileobj['fullname'];
290  $destfile = $outdirinvoices.'/'.$srcfileobj['name'];
291  //var_dump($srcfile.' - '.$destfile);
292  dol_copy($srcfile, $destfile);
293  }
294  }
295  }
296  break;
297  case "payment_expensereport":
298  /*$subdir = dol_sanitizeFileName($objd->refe);
299  $upload_dir = $conf->expensereport->dir_output . '/' . $subdir;*/
300  break;
301  case "payment_salary":
302  /*$subdir = dol_sanitizeFileName($objd->ids);
303  $upload_dir = $conf->salaries->dir_output . '/' . $subdir;*/
304  break;
305  case "payment_donation":
306  /*$subdir = get_exdir(null, 2, 0, 1, $objd, 'donation') . '/' . dol_sanitizeFileName($objd->idd);
307  $upload_dir = $conf->don->dir_output . '/' . $subdir;*/
308  break;
309  default:
310  break;
311  }
312  }
313  $log.="\n";
314 
315  /*if (! empty($upload_dir))
316  {
317  $files = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
318 
319  if (is_array($files)) {
320  foreach ($files as $file) {
321  $zip->addFile($file["fullname"], $file["name"]); //
322  $log .= $key . ',' . $file["name"] . "\n";
323  }
324  } else {
325  $log .= $key . ',' . $langs->trans("Nofile") . "\n";
326  }
327 
328  }*/
329  }
330  }
331 
332  $db->free($resd);
333 
334 
335  //$zip->addFromString('log '.$numref.'.csv', $log);
336  //$zip->close();
337 
338  // /Then download the zipped file.
339  /*header('Content-Type: application/zip');
340  header('Content-disposition: attachment; filename=' . $zipname);
341  header('Content-Length: ' . filesize($zipname));
342 
343  readfile($zipname);
344 
345  exit;*/
346 }
347 
348 
349 /*
350  * View
351  */
352 
353 $title = $langs->trans("FinancialAccount").' - '.$langs->trans("AccountStatements");
354 $helpurl = "";
355 llxHeader('',$title,$helpurl);
356 
357 $form = new Form($db);
358 $societestatic=new Societe($db);
359 $chargestatic=new ChargeSociales($db);
360 $memberstatic=new Adherent($db);
361 $paymentstatic=new Paiement($db);
362 $paymentsupplierstatic=new PaiementFourn($db);
363 $paymentvatstatic=new TVA($db);
364 $bankstatic=new Account($db);
365 $banklinestatic=new AccountLine($db);
366 $remisestatic = new RemiseCheque($db);
367 
368 // Must be before button action
369 $param='';
370 if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
371 if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
372 if ($id > 0) $param.='&id='.urlencode($id);
373 
374 
375 if (empty($numref))
376 {
377  $sortfield='numr';
378  $sortorder='DESC';
379 
380  // List of all standing receipts
381  $sql = "SELECT DISTINCT(b.num_releve) as numr";
382  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
383  $sql.= " WHERE b.fk_account = ".$object->id;
384  $sql.=$db->order($sortfield,$sortorder);
385 
386  // Count total nb of records
387  $nbtotalofrecords = '';
388  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
389  {
390  $result = $db->query($sql);
391  $nbtotalofrecords = $db->num_rows($result);
392  }
393 
394  $sql.= $db->plimit($conf->liste_limit+1,$offset);
395 
396  $result = $db->query($sql);
397  if ($result)
398  {
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 
538  print "<form method=\"post\" action=\"releve.php\">";
539  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
540  print '<input type="hidden" name="action" value="add">';
541 
542  print '<div class="div-table-responsive">';
543  print '<table class="noborder" width="100%">';
544  print '<tr class="liste_titre">';
545  print '<td align="center">'.$langs->trans("DateOperationShort").'</td>';
546  print '<td align="center">'.$langs->trans("DateValueShort").'</td>';
547  print '<td>'.$langs->trans("Type").'</td>';
548  print '<td>'.$langs->trans("Description").'</td>';
549  print '<td align="right" width="60">'.$langs->trans("Debit").'</td>';
550  print '<td align="right" width="60">'.$langs->trans("Credit").'</td>';
551  print '<td align="right">'.$langs->trans("Balance").'</td>';
552  print '<td>&nbsp;</td>';
553  print "</tr>\n";
554 
555  // Calcul du solde de depart du releve
556  $sql = "SELECT sum(b.amount) as amount";
557  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
558  $sql.= " WHERE b.num_releve < '".$db->escape($numref)."'";
559  $sql.= " AND b.fk_account = ".$object->id;
560 
561  $resql=$db->query($sql);
562  if ($resql)
563  {
564  $obj=$db->fetch_object($resql);
565  $total = $obj->amount;
566  $db->free($resql);
567  }
568 
569  // Recherche les ecritures pour le releve
570  $sql = $sqlrequestforbankline;
571 
572  $result = $db->query($sql);
573  if ($result)
574  {
575  $numrows = $db->num_rows($result);
576  $i = 0;
577 
578  // Ligne Solde debut releve
579  print '<tr class="oddeven"><td colspan="3"></td>';
580  print '<td colspan="3"><b>'.$langs->trans("InitialBankBalance")." :</b></td>";
581  print '<td class="right"><b>'.price($total).'</b></td><td>&nbsp;</td>';
582  print "</tr>\n";
583 
584  while ($i < $numrows)
585  {
586  $objp = $db->fetch_object($result);
587  $total = $total + $objp->amount;
588 
589  print '<tr class="oddeven">';
590 
591  // Date operation
592  print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->do),"day").'</td>';
593 
594  // Date de valeur
595  print '<td align="center" valign="center" class="nowrap">';
596  print dol_print_date($db->jdate($objp->dv),"day") .' ';
597  print '<a href="releve.php?action=dvprev&amp;num='.$numref.'&amp;account='.$object->id.'&amp;dvid='.$objp->rowid.'">';
598  print img_edit_remove() . "</a> ";
599  print '<a href="releve.php?action=dvnext&amp;num='.$numref.'&amp;account='.$object->id.'&amp;dvid='.$objp->rowid.'">';
600  print img_edit_add() ."</a>";
601  print "</td>\n";
602  print '<a class="ajax" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
603 
604  // Type and num
605  if ($objp->fk_type == 'SOLD') {
606  $type_label='&nbsp;';
607  } else {
608  $type_label=($langs->trans("PaymentTypeShort".$objp->fk_type)!="PaymentTypeShort".$objp->fk_type)?$langs->trans("PaymentTypeShort".$objp->fk_type):$objp->fk_type;
609  }
610  $link='';
611  if ($objp->fk_bordereau>0) {
612  $remisestatic->id = $objp->fk_bordereau;
613  $remisestatic->ref = $objp->ref;
614  $link = ' '.$remisestatic->getNomUrl(1);
615  }
616  print '<td class="nowrap">'.$type_label.' '.($objp->num_chq?$objp->num_chq:'').$link.'</td>';
617 
618  // Description
619  print '<td valign="center"><a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$object->id.'">';
620  $reg=array();
621  preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parenthese on tente recherche de traduction
622  if ($reg[1] && $langs->trans($reg[1])!=$reg[1]) print $langs->trans($reg[1]);
623  else print $objp->label;
624  print '</a>';
625 
626  /*
627  * Ajout les liens (societe, company...)
628  */
629  $newline=1;
630  $links = $object->get_url($objp->rowid);
631  foreach($links as $key=>$val)
632  {
633  if (! $newline) print ' - ';
634  else print '<br>';
635  if ($links[$key]['type']=='payment')
636  {
637  $paymentstatic->id=$links[$key]['url_id'];
638  $paymentstatic->ref=$langs->trans("Payment");
639  print ' '.$paymentstatic->getNomUrl(1);
640  $newline=0;
641  }
642  elseif ($links[$key]['type']=='payment_supplier')
643  {
644  $paymentsupplierstatic->id=$links[$key]['url_id'];
645  $paymentsupplierstatic->ref=$langs->trans("Payment");
646  print ' '.$paymentsupplierstatic->getNomUrl(1);
647  $newline=0;
648  }
649  elseif ($links[$key]['type']=='payment_sc')
650  {
651  print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$links[$key]['url_id'].'">';
652  print ' '.img_object($langs->trans('ShowPayment'),'payment').' ';
653  print $langs->trans("SocialContributionPayment");
654  print '</a>';
655  $newline=0;
656  }
657  elseif ($links[$key]['type']=='payment_vat')
658  {
659  $paymentvatstatic->id=$links[$key]['url_id'];
660  $paymentvatstatic->ref=$langs->trans("Payment");
661  print ' '.$paymentvatstatic->getNomUrl(1);
662  }
663  elseif ($links[$key]['type']=='payment_salary')
664  {
665  print '<a href="'.DOL_URL_ROOT.'/compta/salaries/card.php?id='.$links[$key]['url_id'].'">';
666  print ' '.img_object($langs->trans('ShowPayment'),'payment').' ';
667  print $langs->trans("Payment");
668  print '</a>';
669  $newline=0;
670  }
671  elseif ($links[$key]['type']=='banktransfert') {
672  // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
673  if ($objp->amount > 0)
674  {
675  $banklinestatic->fetch($links[$key]['url_id']);
676  $bankstatic->id=$banklinestatic->fk_account;
677  $bankstatic->label=$banklinestatic->bank_account_label;
678  print ' ('.$langs->trans("from").' ';
679  print $bankstatic->getNomUrl(1,'transactions');
680  print ' '.$langs->trans("toward").' ';
681  $bankstatic->id=$objp->bankid;
682  $bankstatic->label=$objp->bankref;
683  print $bankstatic->getNomUrl(1,'');
684  print ')';
685  }
686  else
687  {
688  $bankstatic->id=$objp->bankid;
689  $bankstatic->label=$objp->bankref;
690  print ' ('.$langs->trans("from").' ';
691  print $bankstatic->getNomUrl(1,'');
692  print ' '.$langs->trans("toward").' ';
693  $banklinestatic->fetch($links[$key]['url_id']);
694  $bankstatic->id=$banklinestatic->fk_account;
695  $bankstatic->label=$banklinestatic->bank_account_label;
696  print $bankstatic->getNomUrl(1,'transactions');
697  print ')';
698  }
699  }
700  elseif ($links[$key]['type']=='company') {
701  $societestatic->id = $links[$key]['url_id'];
702  $societestatic->name = $links[$key]['label'];
703  print $societestatic->getNomUrl(1, 'company', 24);
704  $newline=0;
705  }
706  elseif ($links[$key]['type']=='member') {
707  print '<a href="'.DOL_URL_ROOT.'/adherents/card.php?rowid='.$links[$key]['url_id'].'">';
708  print img_object($langs->trans('ShowMember'),'user').' ';
709  print $links[$key]['label'];
710  print '</a>';
711  $newline=0;
712  }
713  elseif ($links[$key]['type']=='user') {
714  print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$links[$key]['url_id'].'">';
715  print img_object($langs->trans('ShowUser'),'user').' ';
716  print $links[$key]['label'];
717  print '</a>';
718  $newline=0;
719  }
720  elseif ($links[$key]['type']=='sc') {
721  print '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
722  print img_object($langs->trans('ShowBill'),'bill').' ';
723  print $langs->trans("SocialContribution");
724  print '</a>';
725  $newline=0;
726  }
727  else {
728  print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
729  print $links[$key]['label'];
730  print '</a>';
731  $newline=0;
732  }
733  }
734 
735  // Categories
736  if ($ve)
737  {
738  $sql = "SELECT label";
739  $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ as ct";
740  $sql.= ", ".MAIN_DB_PREFIX."bank_class as cl";
741  $sql.= " WHERE ct.rowid = cl.fk_categ";
742  $sql.= " AND ct.entity = ".$conf->entity;
743  $sql.= " AND cl.lineid = ".$objp->rowid;
744 
745  $resc = $db->query($sql);
746  if ($resc)
747  {
748  $numc = $db->num_rows($resc);
749  $ii = 0;
750  if ($numc && ! $newline) print '<br>';
751  while ($ii < $numc)
752  {
753  $objc = $db->fetch_object($resc);
754  print "<br>-&nbsp;<i>".$objc->label."</i>";
755  $ii++;
756  }
757  }
758  else
759  {
760  dol_print_error($db);
761  }
762  }
763 
764  print "</td>";
765 
766  if ($objp->amount < 0)
767  {
768  $totald = $totald + abs($objp->amount);
769  print '<td align="right" class="nowrap">'.price($objp->amount * -1)."</td><td>&nbsp;</td>\n";
770  }
771  else
772  {
773  $totalc = $totalc + abs($objp->amount);
774  print '<td>&nbsp;</td><td align="right" class="nowrap">'.price($objp->amount)."</td>\n";
775  }
776 
777  print '<td align="right" class="nowrap">'.price(price2num($total, 'MT'))."</td>\n";
778 
779  if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
780  {
781  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).'">';
782  print img_edit();
783  print "</a></td>";
784  }
785  else
786  {
787  print "<td align=\"center\">&nbsp;</td>";
788  }
789  print "</tr>";
790  $i++;
791  }
792  $db->free($result);
793  }
794 
795  // Line Total
796  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>";
797 
798  // Line Balance
799  print "\n<tr>";
800  print "<td align=\"right\" colspan=\"3\">&nbsp;</td><td colspan=\"3\"><b>".$langs->trans("EndBankBalance")." :</b></td>";
801  print '<td class="right"><b>'.price(price2num($total, 'MT'))."</b></td><td>&nbsp;</td>";
802  print "</tr>\n";
803  print "</table>";
804  print "</div>";
805 
806  print "</form>\n";
807 
808  // Add a download button
809  if ($conf->global->MAIN_FEATURES_LEVEL >= 2) // Started a rewrite to make this feature more Dolibarr compliant. Still need dev to be completed.
810  {
811  // TODO Replace this with standard box to generate document.
812  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";
813  }
814 }
815 
816 // End of page
817 llxFooter();
818 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:666
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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
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:1053
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition: bank.lib.php:34
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
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...
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.
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...)
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage payments of customer invoices.
Class to manage members of a foundation.
llxHeader()
Empty header.
Definition: wrapper.php:44
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:59
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).
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
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.
img_edit_add($titlealt='default', $other='')
Show logo +.
Class to manage invoices.
Class to manage payments for supplier invoices.
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage cheque delivery receipts.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_edit_remove($titlealt='default', $other='')
Show logo -.