releve.php 30 KB

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