releve.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 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. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  8. * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/compta/bank/releve.php
  25. * \ingroup banque
  26. * \brief Page to show a bank statement report
  27. */
  28. // Load Dolibarr environment
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
  44. //show files
  45. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  46. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  47. // Load translation files required by the page
  48. $langs->loadLangs(array("banks", "categories", "companies", "bills", "trips", "donations", "loan", "salaries"));
  49. $action = GETPOST('action', 'aZ09');
  50. $id = GETPOST('account', 'int') ? GETPOST('account', 'int') : GETPOST('id', 'int');
  51. $ref = GETPOST('ref', 'alpha');
  52. $dvid = GETPOST('dvid', 'alpha');
  53. $numref = GETPOST('num', 'alpha');
  54. $ve = GETPOST("ve", 'alpha');
  55. $brref = GETPOST('brref', 'alpha');
  56. $oldbankreceipt = GETPOST('oldbankreceipt', 'alpha');
  57. $newbankreceipt = GETPOST('newbankreceipt', 'alpha');
  58. $rel = GETPOST("rel", 'alphanohtml');
  59. $backtopage = GETPOST('backtopage', 'alpha');
  60. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  61. $hookmanager->initHooks(array('bankaccountstatement', 'globalcard'));
  62. // Security check
  63. $fieldid = (!empty($ref) ? $ref : $id);
  64. $fieldname = (!empty($ref) ? 'ref' : 'rowid');
  65. if ($user->socid) {
  66. $socid = $user->socid;
  67. }
  68. $result = restrictedArea($user, 'banque', $fieldid, 'bank_account', '', '', $fieldname);
  69. if ($user->rights->banque->consolidate && $action == 'dvnext' && !empty($dvid)) {
  70. $al = new AccountLine($db);
  71. $al->datev_next($dvid);
  72. }
  73. if ($user->rights->banque->consolidate && $action == 'dvprev' && !empty($dvid)) {
  74. $al = new AccountLine($db);
  75. $al->datev_previous($dvid);
  76. }
  77. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  78. $sortfield = GETPOST('sortfield', 'aZ09comma');
  79. $sortorder = GETPOST('sortorder', 'aZ09comma');
  80. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  81. $pageplusone = GETPOST("pageplusone", 'int');
  82. if ($pageplusone) {
  83. $page = $pageplusone - 1;
  84. }
  85. if (empty($page) || $page == -1) {
  86. $page = 0;
  87. } // If $page is not defined, or '' or -1
  88. $offset = $limit * $page;
  89. $pageprev = $page - 1;
  90. $pagenext = $page + 1;
  91. if (!$sortorder) {
  92. $sortorder = "ASC";
  93. }
  94. if (!$sortfield) {
  95. $sortfield = "s.nom";
  96. }
  97. $object = new Account($db);
  98. if ($id > 0 || !empty($ref)) {
  99. $result = $object->fetch($id, $ref);
  100. $account = $object->id; // Force the search field on id of account
  101. }
  102. // Initialize technical object to manage context to save list fields
  103. $contextpage = 'banktransactionlist'.(empty($object->ref) ? '' : '-'.$object->id);
  104. // Define number of receipt to show (current, previous or next one ?)
  105. $found = false;
  106. if ($rel == 'prev') {
  107. // Recherche valeur pour num = numero releve precedent
  108. $sql = "SELECT DISTINCT(b.num_releve) as num";
  109. $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
  110. $sql .= " WHERE b.num_releve < '".$db->escape($numref)."'";
  111. $sql .= " AND b.fk_account = ".((int) $object->id);
  112. $sql .= " ORDER BY b.num_releve DESC";
  113. dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
  114. $resql = $db->query($sql);
  115. if ($resql) {
  116. $numrows = $db->num_rows($resql);
  117. if ($numrows > 0) {
  118. $obj = $db->fetch_object($resql);
  119. $numref = $obj->num;
  120. $found = true;
  121. }
  122. }
  123. } elseif ($rel == 'next') {
  124. // Recherche valeur pour num = numero releve precedent
  125. $sql = "SELECT DISTINCT(b.num_releve) as num";
  126. $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
  127. $sql .= " WHERE b.num_releve > '".$db->escape($numref)."'";
  128. $sql .= " AND b.fk_account = ".((int) $object->id);
  129. $sql .= " ORDER BY b.num_releve ASC";
  130. dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
  131. $resql = $db->query($sql);
  132. if ($resql) {
  133. $numrows = $db->num_rows($resql);
  134. if ($numrows > 0) {
  135. $obj = $db->fetch_object($resql);
  136. $numref = $obj->num;
  137. $found = true;
  138. }
  139. }
  140. } else {
  141. // On veut le releve num
  142. $found = true;
  143. }
  144. $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
  145. $sql .= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
  146. $sql .= " b.fk_bordereau,";
  147. $sql .= " bc.ref,";
  148. $sql .= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel";
  149. $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
  150. $sql .= ", ".MAIN_DB_PREFIX."bank as b";
  151. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bordereau_cheque as bc ON bc.rowid=b.fk_bordereau';
  152. $sql .= " WHERE b.num_releve='".$db->escape($numref)."'";
  153. if (empty($numref)) {
  154. $sql .= " OR b.num_releve is null";
  155. }
  156. $sql .= " AND b.fk_account = ".((int) $object->id);
  157. $sql .= " AND b.fk_account = ba.rowid";
  158. $sql .= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
  159. $sqlrequestforbankline = $sql;
  160. /*
  161. * Actions
  162. */
  163. if ($action == 'confirm_editbankreceipt' && !empty($oldbankreceipt) && !empty($newbankreceipt)) {
  164. // TODO Add a test to check newbankreceipt does not exists yet
  165. $sqlupdate = "UPDATE ".MAIN_DB_PREFIX."bank SET num_releve = '".$db->escape($newbankreceipt)."'";
  166. $sqlupdate .= " WHERE num_releve = '".$db->escape($oldbankreceipt)."' AND fk_account = ".((int) $id);
  167. $result = $db->query($sqlupdate);
  168. if ($result < 0) {
  169. dol_print_error($db);
  170. }
  171. $action = 'view';
  172. }
  173. /*
  174. * View
  175. */
  176. $form = new Form($db);
  177. $societestatic = new Societe($db);
  178. $chargestatic = new ChargeSociales($db);
  179. $memberstatic = new Adherent($db);
  180. $paymentstatic = new Paiement($db);
  181. $paymentsupplierstatic = new PaiementFourn($db);
  182. $paymentvatstatic = new Tva($db);
  183. $bankstatic = new Account($db);
  184. $banklinestatic = new AccountLine($db);
  185. $remisestatic = new RemiseCheque($db);
  186. $paymentdonationstatic = new PaymentDonation($db);
  187. $paymentloanstatic = new PaymentLoan($db);
  188. $paymentvariousstatic = new PaymentVarious($db);
  189. // Must be before button action
  190. $param = '';
  191. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  192. $param .= '&contextpage='.$contextpage;
  193. }
  194. if ($limit > 0 && $limit != $conf->liste_limit) {
  195. $param .= '&limit='.$limit;
  196. }
  197. if ($id > 0) {
  198. $param .= '&id='.urlencode($id);
  199. }
  200. if (empty($numref)) {
  201. $title = $object->ref.' - '.$langs->trans("AccountStatements");
  202. $helpurl = "";
  203. } else {
  204. $title = $langs->trans("FinancialAccount").' - '.$langs->trans("AccountStatements");
  205. $helpurl = "";
  206. }
  207. llxHeader('', $title, $helpurl);
  208. if (empty($numref)) {
  209. $sortfield = 'numr';
  210. $sortorder = 'DESC';
  211. // List of all standing receipts
  212. $sql = "SELECT DISTINCT(b.num_releve) as numr";
  213. $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
  214. $sql .= " WHERE b.fk_account = ".((int) $object->id);
  215. $sql .= $db->order($sortfield, $sortorder);
  216. // Count total nb of records
  217. $totalnboflines = 0;
  218. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  219. $result = $db->query($sql);
  220. $totalnboflines = $db->num_rows($result);
  221. }
  222. $sql .= $db->plimit($conf->liste_limit + 1, $offset);
  223. $result = $db->query($sql);
  224. if ($result) {
  225. $numrows = $db->num_rows($result);
  226. $i = 0;
  227. // Onglets
  228. $head = bank_prepare_head($object);
  229. print dol_get_fiche_head($head, 'statement', $langs->trans("FinancialAccount"), 0, 'account');
  230. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  231. $morehtmlref = '';
  232. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  233. print dol_get_fiche_end();
  234. print '<div class="tabsAction">';
  235. if ($object->canBeConciliated() > 0) {
  236. $allowautomaticconciliation = false; // TODO
  237. $titletoconciliatemanual = $langs->trans("Conciliate");
  238. $titletoconciliateauto = $langs->trans("Conciliate");
  239. if ($allowautomaticconciliation) {
  240. $titletoconciliatemanual .= ' ('.$langs->trans("Manual").')';
  241. $titletoconciliateauto .= ' ('.$langs->trans("Auto").')';
  242. }
  243. // If not cash account and can be reconciliate
  244. if ($user->rights->banque->consolidate) {
  245. $buttonreconcile = '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?action=reconcile&sortfield=b.datev,b.dateo,b.rowid&sortorder=asc,asc,asc&search_conciliated=0&search_account='.$id.$param.'">'.$titletoconciliatemanual.'</a>';
  246. } else {
  247. $buttonreconcile = '<a class="butActionRefused classfortooltip" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$titletoconciliatemanual.'</a>';
  248. }
  249. if ($allowautomaticconciliation) {
  250. // If not cash account and can be reconciliate
  251. if ($user->rights->banque->consolidate) {
  252. $newparam = $param;
  253. $newparam = preg_replace('/search_conciliated=\d+/i', '', $newparam);
  254. $buttonreconcile .= ' <a class="butAction" style="margin-bottom: 5px !important; margin-top: 5px !important" href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?action=reconcile&sortfield=b.datev,b.dateo,b.rowid&sortorder=asc,asc,asc&search_conciliated=0'.$newparam.'">'.$titletoconciliateauto.'</a>';
  255. } else {
  256. $buttonreconcile .= ' <a class="butActionRefused" style="margin-bottom: 5px !important; margin-top: 5px !important" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$titletoconciliateauto.'</a>';
  257. }
  258. }
  259. print $buttonreconcile;
  260. }
  261. print '</div>';
  262. print_barre_liste('', $page, $_SERVER["PHP_SELF"], "&account=".$object->id, $sortfield, $sortorder, '', $numrows, $totalnboflines, '');
  263. print '<form name="aaa" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  264. print '<input type="hidden" name="token" value="'.newToken().'">';
  265. print '<input type="hidden" name="action" value="confirm_editbankreceipt">';
  266. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  267. print '<input type="hidden" name="account" value="'.$object->id.'">';
  268. print '<input type="hidden" name="page" value="'.$page.'">';
  269. print '<table class="noborder centpercent">';
  270. print '<tr class="liste_titre">';
  271. print '<td>'.$langs->trans("Ref").'</td>';
  272. print '<td class="right">'.$langs->trans("InitialBankBalance").'</td>';
  273. print '<td class="right">'.$langs->trans("EndBankBalance").'</td>';
  274. print '<td></td>';
  275. print '</tr>';
  276. $balancestart = array();
  277. $content = array();
  278. while ($i < min($numrows, $conf->liste_limit)) {
  279. $objp = $db->fetch_object($result);
  280. if (!isset($objp->numr)) {
  281. //
  282. } else {
  283. print '<tr class="oddeven">';
  284. print '<td>';
  285. if ($action != 'editbankreceipt' || $objp->numr != $brref) {
  286. print '<a href="releve.php?num='.$objp->numr.'&account='.$object->id.'">'.$objp->numr.'</a>';
  287. } else {
  288. print '<input type="hidden" name="oldbankreceipt" value="'.$objp->numr.'">';
  289. print '<input type="text" name="newbankreceipt" value="'.$objp->numr.'">';
  290. print '<input type="submit" class="button small" name="actionnewbankreceipt" value="'.$langs->trans("Rename").'">';
  291. print '<input type="submit" class="button button-cancel small" name="cancel" value="'.$langs->trans("Cancel").'">';
  292. }
  293. print '</td>';
  294. // Calculate start amount
  295. $sql = "SELECT sum(b.amount) as amount";
  296. $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
  297. $sql .= " WHERE b.num_releve < '".$db->escape($objp->numr)."'";
  298. $sql .= " AND b.fk_account = ".((int) $object->id);
  299. $resql = $db->query($sql);
  300. if ($resql) {
  301. $obj = $db->fetch_object($resql);
  302. $balancestart[$objp->numr] = $obj->amount;
  303. $db->free($resql);
  304. }
  305. print '<td class="right"><span class="amount">'.price($balancestart[$objp->numr], '', $langs, 1, -1, -1, empty($object->currency_code)?$conf->currency:$object->currency_code).'</span></td>';
  306. // Calculate end amount
  307. $sql = "SELECT sum(b.amount) as amount";
  308. $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
  309. $sql .= " WHERE b.num_releve = '".$db->escape($objp->numr)."'";
  310. $sql .= " AND b.fk_account = ".((int) $object->id);
  311. $resql = $db->query($sql);
  312. if ($resql) {
  313. $obj = $db->fetch_object($resql);
  314. $content[$objp->numr] = $obj->amount;
  315. $db->free($resql);
  316. }
  317. print '<td class="right"><span class="amount">'.price(($balancestart[$objp->numr] + $content[$objp->numr]), '', $langs, 1, -1, -1, empty($object->currency_code)?$conf->currency:$object->currency_code).'</span></td>';
  318. print '<td class="center">';
  319. if ($user->rights->banque->consolidate && $action != 'editbankreceipt') {
  320. print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?account='.$object->id.($page > 0 ? '&page='.$page : '').'&action=editbankreceipt&token='.newToken().'&brref='.urlencode($objp->numr).'">'.img_edit().'</a>';
  321. }
  322. print '</td>';
  323. print '</tr>'."\n";
  324. }
  325. $i++;
  326. }
  327. print "</table>\n";
  328. print '</form>';
  329. print "\n</div>\n";
  330. } else {
  331. dol_print_error($db);
  332. }
  333. } else {
  334. /**
  335. * Show list of record into a bank statement
  336. */
  337. // Onglets
  338. $head = account_statement_prepare_head($object, $numref);
  339. print dol_get_fiche_head($head, 'statement', $langs->trans("AccountStatement"), -1, 'account');
  340. $morehtmlright = '';
  341. $morehtmlright .= '<div class="pagination"><ul>';
  342. $morehtmlright .= '<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>';
  343. $morehtmlright .= '<li class="pagination"><span class="active">'.$langs->trans("AccountStatement")." ".$numref.'</span></li>';
  344. $morehtmlright .= '<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>';
  345. $morehtmlright .= '</ul></div>';
  346. $title = $langs->trans("AccountStatement").' '.$numref.' - '.$langs->trans("BankAccount").' '.$object->getNomUrl(1, 'receipts');
  347. print load_fiche_titre($title, $morehtmlright, '');
  348. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  349. print '<input type="hidden" name="token" value="'.newToken().'">';
  350. print '<input type="hidden" name="action" value="add">';
  351. print '<div class="div-table-responsive">';
  352. print '<table class="noborder centpercent">';
  353. print '<tr class="liste_titre">';
  354. print '<td class="center">'.$langs->trans("DateOperationShort").'</td>';
  355. print '<td class="center">'.$langs->trans("DateValueShort").'</td>';
  356. print '<td>'.$langs->trans("Type").'</td>';
  357. print '<td>'.$langs->trans("Description").'</td>';
  358. print '<td class="right" width="60">'.$langs->trans("Debit").'</td>';
  359. print '<td class="right" width="60">'.$langs->trans("Credit").'</td>';
  360. print '<td class="right">'.$langs->trans("Balance").'</td>';
  361. print '<td>&nbsp;</td>';
  362. print "</tr>\n";
  363. // Calcul du solde de depart du releve
  364. $sql = "SELECT sum(b.amount) as amount";
  365. $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
  366. $sql .= " WHERE b.num_releve < '".$db->escape($numref)."'";
  367. $sql .= " AND b.fk_account = ".((int) $object->id);
  368. $resql = $db->query($sql);
  369. if ($resql) {
  370. $obj = $db->fetch_object($resql);
  371. $total = $obj->amount;
  372. $db->free($resql);
  373. }
  374. // Recherche les ecritures pour le releve
  375. $sql = $sqlrequestforbankline;
  376. $result = $db->query($sql);
  377. if ($result) {
  378. $numrows = $db->num_rows($result);
  379. $i = 0;
  380. // Ligne Solde debut releve
  381. print '<tr class="oddeven"><td colspan="3"></td>';
  382. print '<td colspan="3"><b>'.$langs->trans("InitialBankBalance")." :</b></td>";
  383. print '<td class="right"><b>'.price($total).'</b></td><td>&nbsp;</td>';
  384. print "</tr>\n";
  385. while ($i < $numrows) {
  386. $objp = $db->fetch_object($result);
  387. $total = $total + $objp->amount;
  388. print '<tr class="oddeven">';
  389. // Date operation
  390. print '<td class="nowrap center">'.dol_print_date($db->jdate($objp->do), "day").'</td>';
  391. // Date de valeur
  392. print '<td valign="center" class="center nowrap">';
  393. print '<span class="spanforajaxedit">'.dol_print_date($db->jdate($objp->dv), "day").'</span>';
  394. print '&nbsp;';
  395. print '<span class="inline-block">';
  396. print '<a class="ajaxforbankoperationchange reposition" href="'.$_SERVER['PHP_SELF'].'?action=dvprev&amp;num='.$numref.'&amp;account='.$object->id.'&amp;rowid='.$objp->rowid.'&amp;dvid='.$objp->rowid.'">';
  397. print img_edit_remove()."</a> ";
  398. print '<a class="ajaxforbankoperationchange reposition" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;num='.$numref.'&amp;account='.$object->id.'&amp;rowid='.$objp->rowid.'&amp;dvid='.$objp->rowid.'">';
  399. print img_edit_add()."</a>";
  400. print '</span>';
  401. print "</td>\n";
  402. // Type and num
  403. if ($objp->fk_type == 'SOLD') {
  404. $type_label = '&nbsp;';
  405. } else {
  406. $type_label = ($langs->trans("PaymentTypeShort".$objp->fk_type) != "PaymentTypeShort".$objp->fk_type) ? $langs->trans("PaymentTypeShort".$objp->fk_type) : $objp->fk_type;
  407. }
  408. $link = '';
  409. if ($objp->fk_bordereau > 0) {
  410. $remisestatic->id = $objp->fk_bordereau;
  411. $remisestatic->ref = $objp->ref;
  412. $link = ' '.$remisestatic->getNomUrl(1);
  413. }
  414. print '<td class="nowrap">'.$type_label.' '.($objp->num_chq ? $objp->num_chq : '').$link.'</td>';
  415. // Description
  416. print '<td valign="center">';
  417. print '<a href="'.DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$objp->rowid.'&account='.$object->id.'">';
  418. $reg = array();
  419. preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthese on tente recherche de traduction
  420. if ($reg[1] && $langs->trans($reg[1]) != $reg[1]) {
  421. print $langs->trans($reg[1]);
  422. } else {
  423. print $objp->label;
  424. }
  425. print '</a>';
  426. /*
  427. * Add links under the label (link to payment, company, user, social contribution...)
  428. */
  429. $newline = 1;
  430. $links = $object->get_url($objp->rowid);
  431. foreach ($links as $key => $val) {
  432. if (!$newline) {
  433. print ' - ';
  434. } else {
  435. print '<br>';
  436. }
  437. if ($links[$key]['type'] == 'payment') {
  438. $paymentstatic->id = $links[$key]['url_id'];
  439. $paymentstatic->ref = $langs->trans("Payment");
  440. print ' '.$paymentstatic->getNomUrl(1);
  441. $newline = 0;
  442. } elseif ($links[$key]['type'] == 'payment_supplier') {
  443. $paymentsupplierstatic->id = $links[$key]['url_id'];
  444. $paymentsupplierstatic->ref = $langs->trans("Payment");
  445. print ' '.$paymentsupplierstatic->getNomUrl(1);
  446. $newline = 0;
  447. } elseif ($links[$key]['type'] == 'payment_sc') {
  448. print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$links[$key]['url_id'].'">';
  449. print ' '.img_object($langs->trans('ShowPayment'), 'payment').' ';
  450. print $langs->trans("SocialContributionPayment");
  451. print '</a>';
  452. $newline = 0;
  453. } elseif ($links[$key]['type'] == 'payment_vat') {
  454. $paymentvatstatic->id = $links[$key]['url_id'];
  455. $paymentvatstatic->ref = $langs->trans("Payment");
  456. print ' '.$paymentvatstatic->getNomUrl(1);
  457. } elseif ($links[$key]['type'] == 'payment_salary') {
  458. print '<a href="'.DOL_URL_ROOT.'/salaries/card.php?id='.$links[$key]['url_id'].'">';
  459. print ' '.img_object($langs->trans('ShowPayment'), 'payment').' ';
  460. print $langs->trans("Payment");
  461. print '</a>';
  462. $newline = 0;
  463. } elseif ($links[$key]['type'] == 'payment_donation') {
  464. $paymentdonationstatic->id = $links[$key]['url_id'];
  465. $paymentdonationstatic->ref = $langs->trans("Payment");
  466. print ' '.$paymentdonationstatic->getNomUrl(1);
  467. $newline = 0;
  468. } elseif ($links[$key]['type'] == 'payment_loan') {
  469. $paymentloanstatic->id = $links[$key]['url_id'];
  470. $paymentloanstatic->ref = $langs->trans("Payment");
  471. print ' '.$paymentloanstatic->getNomUrl(1);
  472. $newline = 0;
  473. } elseif ($links[$key]['type'] == 'payment_various') {
  474. $paymentvariousstatic->id = $links[$key]['url_id'];
  475. $paymentvariousstatic->ref = $langs->trans("Payment");
  476. print ' '.$paymentvariousstatic->getNomUrl(1);
  477. $newline = 0;
  478. } elseif ($links[$key]['type'] == 'banktransfert') {
  479. // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
  480. if ($objp->amount > 0) {
  481. $banklinestatic->fetch($links[$key]['url_id']);
  482. $bankstatic->id = $banklinestatic->fk_account;
  483. $bankstatic->label = $banklinestatic->bank_account_label;
  484. print ' ('.$langs->trans("from").' ';
  485. print $bankstatic->getNomUrl(1, 'transactions');
  486. print ' '.$langs->trans("toward").' ';
  487. $bankstatic->id = $objp->bankid;
  488. $bankstatic->label = $objp->bankref;
  489. print $bankstatic->getNomUrl(1, '');
  490. print ')';
  491. } else {
  492. $bankstatic->id = $objp->bankid;
  493. $bankstatic->label = $objp->bankref;
  494. print ' ('.$langs->trans("from").' ';
  495. print $bankstatic->getNomUrl(1, '');
  496. print ' '.$langs->trans("toward").' ';
  497. $banklinestatic->fetch($links[$key]['url_id']);
  498. $bankstatic->id = $banklinestatic->fk_account;
  499. $bankstatic->label = $banklinestatic->bank_account_label;
  500. print $bankstatic->getNomUrl(1, 'transactions');
  501. print ')';
  502. }
  503. } elseif ($links[$key]['type'] == 'company') {
  504. $societestatic->id = $links[$key]['url_id'];
  505. $societestatic->name = $links[$key]['label'];
  506. print $societestatic->getNomUrl(1, 'company', 24);
  507. $newline = 0;
  508. } elseif ($links[$key]['type'] == 'member') {
  509. print '<a href="'.DOL_URL_ROOT.'/adherents/card.php?rowid='.$links[$key]['url_id'].'">';
  510. print img_object($langs->trans('ShowMember'), 'user').' ';
  511. print $links[$key]['label'];
  512. print '</a>';
  513. $newline = 0;
  514. } elseif ($links[$key]['type'] == 'user') {
  515. print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$links[$key]['url_id'].'">';
  516. print img_object($langs->trans('ShowUser'), 'user').' ';
  517. print $links[$key]['label'];
  518. print '</a>';
  519. $newline = 0;
  520. } elseif ($links[$key]['type'] == 'sc') {
  521. print '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
  522. print img_object($langs->trans('ShowBill'), 'bill').' ';
  523. print $langs->trans("SocialContribution");
  524. print '</a>';
  525. $newline = 0;
  526. } else {
  527. print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
  528. print $links[$key]['label'];
  529. print '</a>';
  530. $newline = 0;
  531. }
  532. }
  533. // Categories
  534. if ($ve) {
  535. $sql = "SELECT label";
  536. $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ as ct";
  537. $sql .= ", ".MAIN_DB_PREFIX."bank_class as cl";
  538. $sql .= " WHERE ct.rowid = cl.fk_categ";
  539. $sql .= " AND ct.entity = ".((int) $conf->entity);
  540. $sql .= " AND cl.lineid = ".((int) $objp->rowid);
  541. $resc = $db->query($sql);
  542. if ($resc) {
  543. $numc = $db->num_rows($resc);
  544. $ii = 0;
  545. if ($numc && !$newline) {
  546. print '<br>';
  547. }
  548. while ($ii < $numc) {
  549. $objc = $db->fetch_object($resc);
  550. print "<br>-&nbsp;<i>".$objc->label."</i>";
  551. $ii++;
  552. }
  553. } else {
  554. dol_print_error($db);
  555. }
  556. }
  557. print "</td>";
  558. if ($objp->amount < 0) {
  559. $totald = $totald + abs($objp->amount);
  560. print '<td class="nowrap right">'.price($objp->amount * -1)."</td><td>&nbsp;</td>\n";
  561. } else {
  562. $totalc = $totalc + abs($objp->amount);
  563. print '<td>&nbsp;</td><td class="nowrap right">'.price($objp->amount)."</td>\n";
  564. }
  565. print '<td class="nowrap right">'.price(price2num($total, 'MT'))."</td>\n";
  566. if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
  567. print '<td class="center"><a class="editfielda reposition" href="'.DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$objp->rowid.'&account='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?account='.$object->id.'&num='.$numref).'">';
  568. print img_edit();
  569. print "</a></td>";
  570. } else {
  571. print "<td class=\"center\">&nbsp;</td>";
  572. }
  573. print "</tr>";
  574. $i++;
  575. }
  576. $db->free($result);
  577. }
  578. // Line Total
  579. print "\n".'<tr class="liste_total"><td class="right" colspan="4">'.$langs->trans("Total")." :</td><td class=\"right\">".price($totald)."</td><td class=\"right\">".price($totalc)."</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
  580. // Line Balance
  581. print "\n<tr>";
  582. print "<td class=\"right\" colspan=\"3\">&nbsp;</td><td colspan=\"3\"><b>".$langs->trans("EndBankBalance")." :</b></td>";
  583. print '<td class="right"><b>'.price(price2num($total, 'MT'))."</b></td><td>&nbsp;</td>";
  584. print "</tr>\n";
  585. print "</table>";
  586. // Code to adjust value date with plus and less picto using an Ajax call instead of a full reload of page
  587. $urlajax = DOL_URL_ROOT.'/core/ajax/bankconciliate.php?token='.currentToken();
  588. print '
  589. <script type="text/javascript">
  590. $(function() {
  591. $("a.ajaxforbankoperationchange").each(function(){
  592. var current = $(this);
  593. current.click(function()
  594. {
  595. console.log("We click on ajaxforbankoperationchange");
  596. var url = "'.$urlajax.'&"+current.attr("href").split("?")[1];
  597. $.get(url, function(data)
  598. {
  599. console.log(url)
  600. console.log(data)
  601. current.parent().parent().find(".spanforajaxedit").replaceWith(data);
  602. });
  603. return false;
  604. });
  605. });
  606. });
  607. </script>
  608. ';
  609. print "</div>";
  610. print "</form>\n";
  611. }
  612. // End of page
  613. llxFooter();
  614. $db->close();