releve.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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. /**
  22. * \file htdocs/compta/bank/releve.php
  23. * \ingroup banque
  24. * \brief Page to show a bank statement report
  25. */
  26. require('../../main.inc.php');
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  38. //show files
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  41. $langs->load("banks");
  42. $langs->load("categories");
  43. $langs->load("companies");
  44. $langs->load("bills");
  45. $action=GETPOST('action', 'alpha');
  46. $id=GETPOST('account');
  47. $ref=GETPOST('ref');
  48. $dvid=GETPOST('dvid');
  49. $numref=GETPOST('num');
  50. // Security check
  51. $fieldid = (! empty($ref)?$ref:$id);
  52. $fieldname = isset($ref)?'ref':'rowid';
  53. if ($user->societe_id) $socid=$user->societe_id;
  54. $result=restrictedArea($user,'banque',$fieldid,'bank_account','','',$fieldname);
  55. if ($user->rights->banque->consolidate && $action == 'dvnext' && ! empty($dvid))
  56. {
  57. $al = new AccountLine($db);
  58. $al->datev_next($dvid);
  59. }
  60. if ($user->rights->banque->consolidate && $action == 'dvprev' && ! empty($dvid))
  61. {
  62. $al = new AccountLine($db);
  63. $al->datev_previous($dvid);
  64. }
  65. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  66. $sortfield = GETPOST("sortfield",'alpha');
  67. $sortorder = GETPOST("sortorder",'alpha');
  68. $page = GETPOST("page",'int');
  69. $pageplusone = GETPOST("pageplusone",'int');
  70. if ($pageplusone) $page = $pageplusone - 1;
  71. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  72. $offset = $limit * $page;
  73. $pageprev = $page - 1;
  74. $pagenext = $page + 1;
  75. if (! $sortorder) $sortorder="ASC";
  76. if (! $sortfield) $sortfield="s.nom";
  77. $object = new Account($db);
  78. if ($id > 0 || ! empty($ref))
  79. {
  80. $result=$object->fetch($id, $ref);
  81. $account = $object->id; // Force the search field on id of account
  82. }
  83. // Initialize technical object to manage context to save list fields
  84. $contextpage='banktransactionlist'.(empty($object->ref)?'':'-'.$object->id);
  85. $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
  86. $sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
  87. $sql.= " b.fk_bordereau,";
  88. $sql.= " bc.ref,";
  89. $sql.= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
  90. $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
  91. $sql.= ", ".MAIN_DB_PREFIX."bank as b";
  92. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bordereau_cheque as bc ON bc.rowid=b.fk_bordereau';
  93. $sql.= " WHERE b.num_releve='".$db->escape($numref)."'";
  94. if (!isset($numref)) $sql.= " OR b.num_releve is null";
  95. $sql.= " AND b.fk_account = ".$object->id;
  96. $sql.= " AND b.fk_account = ba.rowid";
  97. $sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
  98. $sqlrequestforbankline = $sql;
  99. /*
  100. * Actions
  101. */
  102. // ZIP creation
  103. if ($action=="dl" && $numref > 0)
  104. {
  105. // TODO Replace this with a standard builddoc action that use a document generation module to build the ZIP
  106. $log = '';
  107. $outdir = $conf->bank->dir_temp.'/'.$numref.'-'.$object->label;
  108. $outdirinvoices = $outdir.'/'.$langs->trans("BillsCustomers");
  109. $outdirsupplierinvoices = $outdir.'/'.$langs->trans("BillsSuppliers");
  110. dol_mkdir($outdir);
  111. dol_mkdir($outdirinvoices);
  112. dol_mkdir($outdirsupplierinvoices);
  113. //$zipname = $object->label.'-'.$numref . '.zip';
  114. //$zip = new ZipArchive();
  115. //$zip->open($zipname, ZipArchive::OVERWRITE);
  116. $sql = $sqlrequestforbankline;
  117. $facturestatic=new Facture($db);
  118. $resd = $db->query($sql);
  119. if ($resd) {
  120. $numd = $db->num_rows($resd);
  121. $i = 0;
  122. if ($numd > 0)
  123. {
  124. $objd = $db->fetch_object($resd);
  125. $log.='Transaction '.$objd->rowid;
  126. $links = $object->get_url($objd->rowid);
  127. foreach($links as $key=>$val)
  128. {
  129. $link = ''; $upload_dir = '';
  130. switch ($val['type']) {
  131. case "payment":
  132. $payment = new Paiement($db);
  133. $payment->fetch($val['url_id']);
  134. $arraybill = $payment->getBillsArray();
  135. if (count($arraybill) > 0)
  136. {
  137. foreach ($arraybill as $billid)
  138. {
  139. $facturestatic->fetch($billid);
  140. $subdir = get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice');
  141. $arrayofinclusion=array(); // TODO Find a way to get doc ODT or other
  142. // TODO Use get_exdir
  143. $arrayofinclusion[]=preg_quote($facturestatic->ref.'.pdf','/');
  144. $listoffiles = dol_dir_list($conf->facture->dir_output.$subdir,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true);
  145. // build list of files with full path
  146. $files = array();
  147. foreach($listoffiles as $filefound)
  148. {
  149. if (strstr($filefound["name"],$facturestatic->ref))
  150. {
  151. $files[] = $uploaddir.'/'.$facturestatic->ref.'/'.$filefound["name"];
  152. break;
  153. }
  154. }
  155. /*var_dump($files);*/
  156. //var_dump($listoffiles);
  157. foreach($listoffiles as $key => $srcfileobj)
  158. {
  159. $srcfile = $srcfileobj['fullname'];
  160. $destfile = $outdirinvoices.'/'.$srcfileobj['name'];
  161. //var_dump($srcfile.' - '.$destfile);
  162. dol_copy($srcfile, $destfile);
  163. }
  164. }
  165. }
  166. break;
  167. case "payment_supplier":
  168. $payment = new PaiementFourn($db);
  169. $payment->fetch($val['url_id']);
  170. $arraybill = $payment->getBillsArray();
  171. if (count($arraybill) > 0)
  172. {
  173. foreach ($arraybill as $billid)
  174. {
  175. $facturestatic->fetch($billid);
  176. $subdir = get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice_supplier');
  177. $arrayofinclusion=array(); // TODO Find a way to get doc ODT or other
  178. // TODO Use get_exdir
  179. $arrayofinclusion[]=preg_quote($facturestatic->ref.'.pdf','/');
  180. $listoffiles = dol_dir_list($conf->fournisseur->facture->dir_output.$subdir,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true);
  181. // build list of files with full path
  182. $files = array();
  183. foreach($listoffiles as $filefound)
  184. {
  185. if (strstr($filefound["name"],$facturestatic->ref))
  186. {
  187. $files[] = $uploaddir.'/'.$facturestatic->ref.'/'.$filefound["name"];
  188. break;
  189. }
  190. }
  191. /*var_dump($files);*/
  192. //var_dump($listoffiles);
  193. foreach($listoffiles as $key => $srcfileobj)
  194. {
  195. $srcfile = $srcfileobj['fullname'];
  196. $destfile = $outdirinvoices.'/'.$srcfileobj['name'];
  197. //var_dump($srcfile.' - '.$destfile);
  198. dol_copy($srcfile, $destfile);
  199. }
  200. }
  201. }
  202. break;
  203. case "payment_expensereport":
  204. /*$subdir = dol_sanitizeFileName($objd->refe);
  205. $upload_dir = $conf->expensereport->dir_output . '/' . $subdir;*/
  206. break;
  207. case "payment_salary":
  208. /*$subdir = dol_sanitizeFileName($objd->ids);
  209. $upload_dir = $conf->salaries->dir_output . '/' . $subdir;*/
  210. break;
  211. case "payment_donation":
  212. /*$subdir = get_exdir(null, 2, 0, 1, $objd, 'donation') . '/' . dol_sanitizeFileName($objd->idd);
  213. $upload_dir = $conf->don->dir_output . '/' . $subdir;*/
  214. break;
  215. default:
  216. break;
  217. }
  218. }
  219. $log.="\n";
  220. /*if (! empty($upload_dir))
  221. {
  222. $files = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
  223. if (is_array($files)) {
  224. foreach ($files as $file) {
  225. $zip->addFile($file["fullname"], $file["name"]); //
  226. $log .= $key . ',' . $file["name"] . "\n";
  227. }
  228. } else {
  229. $log .= $key . ',' . $langs->trans("Nofile") . "\n";
  230. }
  231. }*/
  232. }
  233. }
  234. $db->free($resd);
  235. //$zip->addFromString('log '.$numref.'.csv', $log);
  236. //$zip->close();
  237. // /Then download the zipped file.
  238. /*header('Content-Type: application/zip');
  239. header('Content-disposition: attachment; filename=' . $zipname);
  240. header('Content-Length: ' . filesize($zipname));
  241. readfile($zipname);
  242. exit;*/
  243. }
  244. /*
  245. * View
  246. */
  247. $title = $langs->trans("FinancialAccount").' - '.$langs->trans("AccountStatements");
  248. $helpurl = "";
  249. llxHeader('',$title,$helpurl);
  250. $form = new Form($db);
  251. $societestatic=new Societe($db);
  252. $chargestatic=new ChargeSociales($db);
  253. $memberstatic=new Adherent($db);
  254. $paymentstatic=new Paiement($db);
  255. $paymentsupplierstatic=new PaiementFourn($db);
  256. $paymentvatstatic=new TVA($db);
  257. $bankstatic=new Account($db);
  258. $banklinestatic=new AccountLine($db);
  259. $remisestatic = new RemiseCheque($db);
  260. // Must be before button action
  261. $param='';
  262. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  263. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  264. if ($id > 0) $param.='&id='.urlencode($id);
  265. if (empty($numref))
  266. {
  267. // List of all standing receipts
  268. $sql = "SELECT DISTINCT(b.num_releve) as numr";
  269. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  270. $sql.= " WHERE b.fk_account = ".$object->id;
  271. $sql.= " ORDER BY numr DESC";
  272. $sql.= $db->plimit($conf->liste_limit+1,$offset);
  273. $result = $db->query($sql);
  274. if ($result)
  275. {
  276. $var=True;
  277. $numrows = $db->num_rows($result);
  278. $i = 0;
  279. // Onglets
  280. $head=bank_prepare_head($object);
  281. dol_fiche_head($head,'statement',$langs->trans("FinancialAccount"),0,'account');
  282. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/index.php">'.$langs->trans("BackToList").'</a>';
  283. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  284. dol_fiche_end();
  285. print '<div class="tabsAction">';
  286. if ($object->canBeConciliated() > 0) {
  287. // If not cash account and can be reconciliate
  288. if ($user->rights->banque->consolidate) {
  289. print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/bankentries.php?action=reconcile'.$param.'">'.$langs->trans("Conciliate").'</a>';
  290. } else {
  291. print '<a class="butActionRefused" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$langs->trans("Conciliate").'</a>';
  292. }
  293. }
  294. print '</div>';
  295. print '<br><br>';
  296. print_barre_liste('', $page, $_SERVER["PHP_SELF"], "&account=".$object->id, $sortfield, $sortorder,'',$numrows);
  297. print '<table class="noborder" width="100%">';
  298. print '<tr class="liste_titre">';
  299. print '<td>'.$langs->trans("AccountStatement").'</td>';
  300. print '<td align="right">'.$langs->trans("InitialBankBalance").'</td>';
  301. print '<td align="right">'.$langs->trans("EndBankBalance").'</td>';
  302. print '</tr>';
  303. $balancestart=array();
  304. $content=array();
  305. while ($i < min($numrows,$conf->liste_limit))
  306. {
  307. $objp = $db->fetch_object($result);
  308. if (! isset($objp->numr))
  309. {
  310. //
  311. }
  312. else
  313. {
  314. print '<tr class="oddeven"><td><a href="releve.php?num='.$objp->numr.'&amp;account='.$object->id.'">'.$objp->numr.'</a></td>';
  315. // Calculate start amount
  316. $sql = "SELECT sum(b.amount) as amount";
  317. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  318. $sql.= " WHERE b.num_releve < '".$db->escape($objp->numr)."'";
  319. $sql.= " AND b.fk_account = ".$object->id;
  320. $resql=$db->query($sql);
  321. if ($resql)
  322. {
  323. $obj=$db->fetch_object($resql);
  324. $balancestart[$objp->numr] = $obj->amount;
  325. $db->free($resql);
  326. }
  327. print '<td align="right">'.price($balancestart[$objp->numr],'',$langs,1,-1,-1,$conf->currency).'</td>';
  328. // Calculate end amount
  329. $sql = "SELECT sum(b.amount) as amount";
  330. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  331. $sql.= " WHERE b.num_releve = '".$db->escape($objp->numr)."'";
  332. $sql.= " AND b.fk_account = ".$object->id;
  333. $resql=$db->query($sql);
  334. if ($resql)
  335. {
  336. $obj=$db->fetch_object($resql);
  337. $content[$objp->numr] = $obj->amount;
  338. $db->free($resql);
  339. }
  340. print '<td align="right">'.price(($balancestart[$objp->numr]+$content[$objp->numr]),'',$langs,1,-1,-1,$conf->currency).'</td>';
  341. print '</tr>'."\n";
  342. }
  343. $i++;
  344. }
  345. print "</table>\n";
  346. print "\n</div>\n";
  347. }
  348. else
  349. {
  350. dol_print_error($db);
  351. }
  352. }
  353. else
  354. {
  355. /**
  356. * Show list of bank statements
  357. */
  358. $ve=$_GET["ve"];
  359. // Define number of receipt to show (current, previous or next one ?)
  360. $found=false;
  361. if ($_GET["rel"] == 'prev')
  362. {
  363. // Recherche valeur pour num = numero releve precedent
  364. $sql = "SELECT DISTINCT(b.num_releve) as num";
  365. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  366. $sql.= " WHERE b.num_releve < '".$db->escape($numref)."'";
  367. $sql.= " AND b.fk_account = ".$object->id;
  368. $sql.= " ORDER BY b.num_releve DESC";
  369. dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
  370. $resql = $db->query($sql);
  371. if ($resql)
  372. {
  373. $numrows = $db->num_rows($resql);
  374. if ($numrows > 0)
  375. {
  376. $obj = $db->fetch_object($resql);
  377. $numref = $obj->num;
  378. $found=true;
  379. }
  380. }
  381. }
  382. elseif ($_GET["rel"] == 'next')
  383. {
  384. // Recherche valeur pour num = numero releve precedent
  385. $sql = "SELECT DISTINCT(b.num_releve) as num";
  386. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  387. $sql.= " WHERE b.num_releve > '".$db->escape($numref)."'";
  388. $sql.= " AND b.fk_account = ".$object->id;
  389. $sql.= " ORDER BY b.num_releve ASC";
  390. dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
  391. $resql = $db->query($sql);
  392. if ($resql)
  393. {
  394. $numrows = $db->num_rows($resql);
  395. if ($numrows > 0)
  396. {
  397. $obj = $db->fetch_object($resql);
  398. $numref = $obj->num;
  399. $found=true;
  400. }
  401. }
  402. }
  403. else {
  404. // On veut le releve num
  405. $found=true;
  406. }
  407. $mesprevnext='';
  408. $mesprevnext.='<div class="pagination"><ul>';
  409. $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>';
  410. //$mesprevnext.=' &nbsp; ';
  411. $mesprevnext.='<li class="pagination"><span class="active">'.$langs->trans("AccountStatement")." ".$numref.'</span></li>';
  412. //$mesprevnext.=' &nbsp; ';
  413. $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>';
  414. $mesprevnext.='</ul></div>';
  415. $title=$langs->trans("AccountStatement").' '.$numref.', '.$langs->trans("BankAccount").' : '.$object->getNomUrl(0, 'receipts');
  416. print load_fiche_titre($title, $mesprevnext, 'title_bank.png');
  417. //print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, 0, $nbtotalofrecords, 'title_bank.png', 0, '', '', 0, 1);
  418. print '<br>';
  419. print "<form method=\"post\" action=\"releve.php\">";
  420. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  421. print "<input type=\"hidden\" name=\"action\" value=\"add\">";
  422. print '<div class="div-table-responsive">';
  423. print '<table class="noborder" width="100%">';
  424. print '<tr class="liste_titre">';
  425. print '<td align="center">'.$langs->trans("DateOperationShort").'</td>';
  426. print '<td align="center">'.$langs->trans("DateValueShort").'</td>';
  427. print '<td>'.$langs->trans("Type").'</td>';
  428. print '<td>'.$langs->trans("Description").'</td>';
  429. print '<td align="right" width="60">'.$langs->trans("Debit").'</td>';
  430. print '<td align="right" width="60">'.$langs->trans("Credit").'</td>';
  431. print '<td align="right">'.$langs->trans("Balance").'</td>';
  432. print '<td>&nbsp;</td>';
  433. print "</tr>\n";
  434. // Calcul du solde de depart du releve
  435. $sql = "SELECT sum(b.amount) as amount";
  436. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  437. $sql.= " WHERE b.num_releve < '".$db->escape($numref)."'";
  438. $sql.= " AND b.fk_account = ".$object->id;
  439. $resql=$db->query($sql);
  440. if ($resql)
  441. {
  442. $obj=$db->fetch_object($resql);
  443. $total = $obj->amount;
  444. $db->free($resql);
  445. }
  446. // Recherche les ecritures pour le releve
  447. $sql = $sqlrequestforbankline;
  448. $result = $db->query($sql);
  449. if ($result)
  450. {
  451. $var=False;
  452. $numrows = $db->num_rows($result);
  453. $i = 0;
  454. // Ligne Solde debut releve
  455. print '<tr class="oddeven"><td colspan="3"></td>';
  456. print '<td colspan="3"><b>'.$langs->trans("InitialBankBalance")." :</b></td>";
  457. print '<td class="right"><b>'.price($total).'</b></td><td>&nbsp;</td>';
  458. print "</tr>\n";
  459. while ($i < $numrows)
  460. {
  461. $objp = $db->fetch_object($result);
  462. $total = $total + $objp->amount;
  463. print '<tr class="oddeven">';
  464. // Date operation
  465. print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->do),"day").'</td>';
  466. // Date de valeur
  467. print '<td align="center" valign="center" class="nowrap">';
  468. print dol_print_date($db->jdate($objp->dv),"day") .' ';
  469. print '<a href="releve.php?action=dvprev&amp;num='.$numref.'&amp;account='.$object->id.'&amp;dvid='.$objp->rowid.'">';
  470. print img_edit_remove() . "</a> ";
  471. print '<a href="releve.php?action=dvnext&amp;num='.$numref.'&amp;account='.$object->id.'&amp;dvid='.$objp->rowid.'">';
  472. print img_edit_add() ."</a>";
  473. print "</td>\n";
  474. print '<a class="ajax" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  475. // Type and num
  476. if ($objp->fk_type == 'SOLD') {
  477. $type_label='&nbsp;';
  478. } else {
  479. $type_label=($langs->trans("PaymentTypeShort".$objp->fk_type)!="PaymentTypeShort".$objp->fk_type)?$langs->trans("PaymentTypeShort".$objp->fk_type):$objp->fk_type;
  480. }
  481. $link='';
  482. if ($objp->fk_bordereau>0) {
  483. $remisestatic->id = $objp->fk_bordereau;
  484. $remisestatic->ref = $objp->ref;
  485. $link = ' '.$remisestatic->getNomUrl(1);
  486. }
  487. print '<td class="nowrap">'.$type_label.' '.($objp->num_chq?$objp->num_chq:'').$link.'</td>';
  488. // Description
  489. print '<td valign="center"><a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$object->id.'">';
  490. $reg=array();
  491. preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parenthese on tente recherche de traduction
  492. if ($reg[1] && $langs->trans($reg[1])!=$reg[1]) print $langs->trans($reg[1]);
  493. else print $objp->label;
  494. print '</a>';
  495. /*
  496. * Ajout les liens (societe, company...)
  497. */
  498. $newline=1;
  499. $links = $object->get_url($objp->rowid);
  500. foreach($links as $key=>$val)
  501. {
  502. if (! $newline) print ' - ';
  503. else print '<br>';
  504. if ($links[$key]['type']=='payment')
  505. {
  506. $paymentstatic->id=$links[$key]['url_id'];
  507. $paymentstatic->ref=$langs->trans("Payment");
  508. print ' '.$paymentstatic->getNomUrl(1);
  509. $newline=0;
  510. }
  511. elseif ($links[$key]['type']=='payment_supplier')
  512. {
  513. $paymentsupplierstatic->id=$links[$key]['url_id'];
  514. $paymentsupplierstatic->ref=$langs->trans("Payment");
  515. print ' '.$paymentsupplierstatic->getNomUrl(1);
  516. $newline=0;
  517. }
  518. elseif ($links[$key]['type']=='payment_sc')
  519. {
  520. print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$links[$key]['url_id'].'">';
  521. print ' '.img_object($langs->trans('ShowPayment'),'payment').' ';
  522. print $langs->trans("SocialContributionPayment");
  523. print '</a>';
  524. $newline=0;
  525. }
  526. elseif ($links[$key]['type']=='payment_vat')
  527. {
  528. $paymentvatstatic->id=$links[$key]['url_id'];
  529. $paymentvatstatic->ref=$langs->trans("Payment");
  530. print ' '.$paymentvatstatic->getNomUrl(1);
  531. }
  532. elseif ($links[$key]['type']=='payment_salary')
  533. {
  534. print '<a href="'.DOL_URL_ROOT.'/compta/salaries/card.php?id='.$links[$key]['url_id'].'">';
  535. print ' '.img_object($langs->trans('ShowPayment'),'payment').' ';
  536. print $langs->trans("Payment");
  537. print '</a>';
  538. $newline=0;
  539. }
  540. elseif ($links[$key]['type']=='banktransfert') {
  541. // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
  542. if ($objp->amount > 0)
  543. {
  544. $banklinestatic->fetch($links[$key]['url_id']);
  545. $bankstatic->id=$banklinestatic->fk_account;
  546. $bankstatic->label=$banklinestatic->bank_account_label;
  547. print ' ('.$langs->trans("from").' ';
  548. print $bankstatic->getNomUrl(1,'transactions');
  549. print ' '.$langs->trans("toward").' ';
  550. $bankstatic->id=$objp->bankid;
  551. $bankstatic->label=$objp->bankref;
  552. print $bankstatic->getNomUrl(1,'');
  553. print ')';
  554. }
  555. else
  556. {
  557. $bankstatic->id=$objp->bankid;
  558. $bankstatic->label=$objp->bankref;
  559. print ' ('.$langs->trans("from").' ';
  560. print $bankstatic->getNomUrl(1,'');
  561. print ' '.$langs->trans("toward").' ';
  562. $banklinestatic->fetch($links[$key]['url_id']);
  563. $bankstatic->id=$banklinestatic->fk_account;
  564. $bankstatic->label=$banklinestatic->bank_account_label;
  565. print $bankstatic->getNomUrl(1,'transactions');
  566. print ')';
  567. }
  568. }
  569. elseif ($links[$key]['type']=='company') {
  570. $societestatic->id = $links[$key]['url_id'];
  571. $societestatic->name = $links[$key]['label'];
  572. print $societestatic->getNomUrl(1, 'company', 24);
  573. $newline=0;
  574. }
  575. elseif ($links[$key]['type']=='member') {
  576. print '<a href="'.DOL_URL_ROOT.'/adherents/card.php?rowid='.$links[$key]['url_id'].'">';
  577. print img_object($langs->trans('ShowMember'),'user').' ';
  578. print $links[$key]['label'];
  579. print '</a>';
  580. $newline=0;
  581. }
  582. elseif ($links[$key]['type']=='user') {
  583. print '<a href="'.DOL_URL_ROOT.'/user/card.php?rowid='.$links[$key]['url_id'].'">';
  584. print img_object($langs->trans('ShowUser'),'user').' ';
  585. print $links[$key]['label'];
  586. print '</a>';
  587. $newline=0;
  588. }
  589. elseif ($links[$key]['type']=='sc') {
  590. print '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
  591. print img_object($langs->trans('ShowBill'),'bill').' ';
  592. print $langs->trans("SocialContribution");
  593. print '</a>';
  594. $newline=0;
  595. }
  596. else {
  597. print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
  598. print $links[$key]['label'];
  599. print '</a>';
  600. $newline=0;
  601. }
  602. }
  603. // Categories
  604. if ($ve)
  605. {
  606. $sql = "SELECT label";
  607. $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ as ct";
  608. $sql.= ", ".MAIN_DB_PREFIX."bank_class as cl";
  609. $sql.= " WHERE ct.rowid = cl.fk_categ";
  610. $sql.= " AND ct.entity = ".$conf->entity;
  611. $sql.= " AND cl.lineid = ".$objp->rowid;
  612. $resc = $db->query($sql);
  613. if ($resc)
  614. {
  615. $numc = $db->num_rows($resc);
  616. $ii = 0;
  617. if ($numc && ! $newline) print '<br>';
  618. while ($ii < $numc)
  619. {
  620. $objc = $db->fetch_object($resc);
  621. print "<br>-&nbsp;<i>$objc->label</i>";
  622. $ii++;
  623. }
  624. }
  625. else
  626. {
  627. dol_print_error($db);
  628. }
  629. }
  630. print "</td>";
  631. if ($objp->amount < 0)
  632. {
  633. $totald = $totald + abs($objp->amount);
  634. print '<td align="right" class="nowrap">'.price($objp->amount * -1)."</td><td>&nbsp;</td>\n";
  635. }
  636. else
  637. {
  638. $totalc = $totalc + abs($objp->amount);
  639. print '<td>&nbsp;</td><td align="right" class="nowrap">'.price($objp->amount)."</td>\n";
  640. }
  641. print '<td align="right" class="nowrap">'.price($total)."</td>\n";
  642. if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
  643. {
  644. 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).'">';
  645. print img_edit();
  646. print "</a></td>";
  647. }
  648. else
  649. {
  650. print "<td align=\"center\">&nbsp;</td>";
  651. }
  652. print "</tr>";
  653. $i++;
  654. }
  655. $db->free($result);
  656. }
  657. // Line Total
  658. 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>";
  659. // Line Balance
  660. print "\n<tr><td align=\"right\" colspan=\"3\">&nbsp;</td><td colspan=\"3\"><b>".$langs->trans("EndBankBalance")." :</b></td>";
  661. print '<td class="right"><b>'.price($total)."</b></td><td>&nbsp;</td>";
  662. print "</tr>\n";
  663. print "</table>";
  664. print "</div>";
  665. print "</form>\n";
  666. // Add a download button
  667. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) // Started a rewrite to make this feature more Dolibarr compliant. Still need dev to be completed.
  668. {
  669. // TODO Replace this with standard box to generate document.
  670. 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";
  671. }
  672. }
  673. llxFooter();
  674. $db->close();