releve.php 26 KB

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