bankentries_list.php 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2012 Vinícius Nogueira <viniciusvgn@gmail.com>
  6. * Copyright (C) 2014 Florian Henry <florian.henry@open-cooncept.pro>
  7. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  8. * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2017-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  10. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  11. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  12. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/compta/bank/bankentries_list.php
  29. * \ingroup banque
  30. * \brief List of bank transactions
  31. */
  32. // Load Dolibarr environment
  33. require '../../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
  48. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  50. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  51. require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
  52. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
  53. require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
  54. require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  55. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
  56. // Load translation files required by the page
  57. $langs->loadLangs(array("banks", "bills", "categories", "companies", "margins", "salaries", "loan", "donations", "trips", "members", "compta", "accountancy"));
  58. $id = GETPOST('id', 'int');
  59. $ref = GETPOST('ref', 'alpha');
  60. $action = GETPOST('action', 'aZ09');
  61. $cancel = GETPOST('cancel', 'alpha');
  62. $confirm = GETPOST('confirm', 'alpha');
  63. $contextpage = 'banktransactionlist'.(empty($object->ref) ? '' : '-'.$object->id);
  64. $massaction = GETPOST('massaction', 'alpha');
  65. $optioncss = GETPOST('optioncss', 'aZ09');
  66. // Security check
  67. $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
  68. $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
  69. if ($fieldvalue) {
  70. if ($user->socid) {
  71. $socid = $user->socid;
  72. }
  73. $result = restrictedArea($user, 'banque', $fieldvalue, 'bank_account&bank_account', '', '', $fieldtype);
  74. } else {
  75. if ($user->socid) {
  76. $socid = $user->socid;
  77. }
  78. $result = restrictedArea($user, 'banque');
  79. }
  80. $dateop = dol_mktime(12, 0, 0, GETPOST("opmonth", 'int'), GETPOST("opday", 'int'), GETPOST("opyear", 'int'));
  81. $search_debit = GETPOST("search_debit", 'alpha');
  82. $search_credit = GETPOST("search_credit", 'alpha');
  83. $search_type = GETPOST("search_type", 'alpha');
  84. $search_account = GETPOST("search_account", 'int') ?GETPOST("search_account", 'int') : GETPOST("account", 'int');
  85. $search_accountancy_code = GETPOST('search_accountancy_code', 'alpha') ?GETPOST('search_accountancy_code', 'alpha') : GETPOST('accountancy_code', 'alpha');
  86. $search_bid = GETPOST("search_bid", "int") ?GETPOST("search_bid", "int") : GETPOST("bid", "int");
  87. $search_ref = GETPOST('search_ref', 'alpha');
  88. $search_description = GETPOST("search_description", 'alpha');
  89. $search_dt_start = dol_mktime(0, 0, 0, GETPOST('search_start_dtmonth', 'int'), GETPOST('search_start_dtday', 'int'), GETPOST('search_start_dtyear', 'int'));
  90. $search_dt_end = dol_mktime(0, 0, 0, GETPOST('search_end_dtmonth', 'int'), GETPOST('search_end_dtday', 'int'), GETPOST('search_end_dtyear', 'int'));
  91. $search_dv_start = dol_mktime(0, 0, 0, GETPOST('search_start_dvmonth', 'int'), GETPOST('search_start_dvday', 'int'), GETPOST('search_start_dvyear', 'int'));
  92. $search_dv_end = dol_mktime(0, 0, 0, GETPOST('search_end_dvmonth', 'int'), GETPOST('search_end_dvday', 'int'), GETPOST('search_end_dvyear', 'int'));
  93. $search_thirdparty_user = GETPOST("search_thirdparty", 'alpha') ?GETPOST("search_thirdparty", 'alpha') : GETPOST("thirdparty", 'alpha');
  94. $search_req_nb = GETPOST("req_nb", 'alpha');
  95. $search_num_releve = GETPOST("search_num_releve", 'alpha');
  96. $search_conciliated = GETPOST("search_conciliated", 'int');
  97. $search_fk_bordereau = GETPOST("search_fk_bordereau", 'int');
  98. $optioncss = GETPOST('optioncss', 'alpha');
  99. $toselect = GETPOST('toselect', 'array');
  100. $num_releve = GETPOST("num_releve", "alpha");
  101. if (empty($dateop)) {
  102. $dateop = -1;
  103. }
  104. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  105. $sortfield = GETPOST('sortfield', 'aZ09comma');
  106. $sortorder = GETPOST('sortorder', 'aZ09comma');
  107. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  108. $pageplusone = GETPOST("pageplusone", 'int');
  109. if ($pageplusone) {
  110. $page = $pageplusone - 1;
  111. }
  112. if (empty($page) || $page == -1) {
  113. $page = 0;
  114. } // If $page is not defined, or '' or -1
  115. $offset = $limit * $page;
  116. $pageprev = $page - 1;
  117. $pagenext = $page + 1;
  118. if (!$sortorder) {
  119. $sortorder = 'desc,desc,desc';
  120. }
  121. if (!$sortfield) {
  122. $sortfield = 'b.datev,b.dateo,b.rowid';
  123. }
  124. $object = new Account($db);
  125. if ($id > 0 || !empty($ref)) {
  126. $result = $object->fetch($id, $ref);
  127. $search_account = $object->id; // Force the search field on id of account
  128. if (!($object->id > 0)) {
  129. $langs->load("errors");
  130. print($langs->trans('ErrorRecordNotFound'));
  131. exit;
  132. }
  133. }
  134. $mode_balance_ok = false;
  135. //if (($sortfield == 'b.datev' || $sortfield == 'b.datev,b.dateo,b.rowid')) // TODO Manage balance when account not selected
  136. if (($sortfield == 'b.datev' || $sortfield == 'b.datev,b.dateo,b.rowid')) {
  137. $sortfield = 'b.datev,b.dateo,b.rowid';
  138. if ($id > 0 || !empty($ref) || $search_account > 0) {
  139. $mode_balance_ok = true;
  140. }
  141. }
  142. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  143. $hookmanager->initHooks(array('banktransactionlist', $contextpage));
  144. $extrafields = new ExtraFields($db);
  145. // fetch optionals attributes and labels
  146. $extrafields->fetch_name_optionals_label('banktransaction');
  147. $search_array_options = $extrafields->getOptionalsFromPost('banktransaction', '', 'search_');
  148. $arrayfields = array(
  149. 'b.rowid'=>array('label'=>$langs->trans("Ref"), 'checked'=>1,'position'=>10),
  150. 'b.label'=>array('label'=>$langs->trans("Description"), 'checked'=>1,'position'=>20),
  151. 'b.dateo'=>array('label'=>$langs->trans("DateOperationShort"), 'checked'=>1,'position'=>30),
  152. 'b.datev'=>array('label'=>$langs->trans("DateValueShort"), 'checked'=>1,'position'=>40),
  153. 'type'=>array('label'=>$langs->trans("Type"), 'checked'=>1,'position'=>50),
  154. 'b.num_chq'=>array('label'=>$langs->trans("Numero"), 'checked'=>1,'position'=>60),
  155. 'bu.label'=>array('label'=>$langs->trans("ThirdParty").'/'.$langs->trans("User"), 'checked'=>1, 'position'=>70),
  156. 'ba.ref'=>array('label'=>$langs->trans("BankAccount"), 'checked'=>(($id > 0 || !empty($ref)) ? 0 : 1), 'position'=>80),
  157. 'b.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1, 'position'=>90),
  158. 'b.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1, 'position'=>100),
  159. 'balancebefore'=>array('label'=>$langs->trans("BalanceBefore"), 'checked'=>0, 'position'=>110),
  160. 'balance'=>array('label'=>$langs->trans("Balance"), 'checked'=>1, 'position'=>120),
  161. 'b.num_releve'=>array('label'=>$langs->trans("AccountStatement"), 'checked'=>1, 'position'=>130),
  162. 'b.conciliated'=>array('label'=>$langs->trans("BankLineReconciled"), 'enabled'=> $object->rappro, 'checked'=>($action == 'reconcile' ? 1 : 0), 'position'=>140),
  163. 'b.fk_bordereau'=>array('label'=>$langs->trans("ChequeNumber"), 'checked'=>0, 'position'=>150),
  164. );
  165. // Extra fields
  166. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  167. $object->fields = dol_sort_array($object->fields, 'position');
  168. $arrayfields = dol_sort_array($arrayfields, 'position');
  169. /*
  170. * Actions
  171. */
  172. if (GETPOST('cancel', 'alpha')) {
  173. $action = 'list';
  174. $massaction = '';
  175. }
  176. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  177. $massaction = '';
  178. }
  179. $parameters = array();
  180. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  181. if ($reshook < 0) {
  182. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  183. }
  184. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  185. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  186. $search_dt_start = '';
  187. $search_dt_end = '';
  188. $search_dv_start = '';
  189. $search_dv_end = '';
  190. $search_type = "";
  191. $search_debit = "";
  192. $search_credit = "";
  193. $search_bid = "";
  194. $search_ref = "";
  195. $search_req_nb = '';
  196. $search_description = '';
  197. $search_thirdparty_user = '';
  198. $search_num_releve = '';
  199. $search_conciliated = '';
  200. $search_fk_bordereau = '';
  201. $toselect = array();
  202. $search_account = "";
  203. if ($id > 0 || !empty($ref)) {
  204. $search_account = $object->id;
  205. }
  206. }
  207. if (empty($reshook)) {
  208. $objectclass = 'Account';
  209. $objectlabel = 'BankTransaction';
  210. $permissiontoread = !empty($user->rights->banque->lire);
  211. $permissiontodelete = !empty($user->rights->banque->modifier);
  212. $uploaddir = $conf->bank->dir_output;
  213. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  214. }
  215. $rowids = GETPOST('rowid', 'array');
  216. // Conciliation
  217. if ((GETPOST('confirm_savestatement', 'alpha') || GETPOST('confirm_reconcile', 'alpha'))
  218. && (GETPOST("num_releve", "alpha") || !empty($rowids))
  219. && !empty($user->rights->banque->consolidate)
  220. && (!GETPOSTISSET('pageplusone') || (GETPOST('pageplusone') == GETPOST('pageplusoneold')))) {
  221. $error = 0;
  222. // Definition, nettoyage parametres
  223. $num_releve = GETPOST("num_releve", "alpha");
  224. if ($num_releve) {
  225. $bankline = new AccountLine($db);
  226. $rowids = GETPOST('rowid', 'array');
  227. if (!empty($rowids) && is_array($rowids)) {
  228. foreach ($rowids as $row) {
  229. if ($row > 0) {
  230. $result = $bankline->fetch($row);
  231. $bankline->num_releve = $num_releve; // GETPOST("num_releve");
  232. $result = $bankline->update_conciliation($user, GETPOST("cat"), GETPOST('confirm_reconcile', 'alpha') ? 1 : 0); // If we confirm_reconcile, we set flag 'rappro' to 1.
  233. if ($result < 0) {
  234. setEventMessages($bankline->error, $bankline->errors, 'errors');
  235. $error++;
  236. break;
  237. }
  238. }
  239. }
  240. } else {
  241. $error++;
  242. $langs->load("errors");
  243. setEventMessages($langs->trans("NoRecordSelected"), null, 'errors');
  244. }
  245. } else {
  246. $error++;
  247. $langs->load("errors");
  248. setEventMessages($langs->trans("ErrorPleaseTypeBankTransactionReportName"), null, 'errors');
  249. }
  250. if (!$error) {
  251. $param = 'action=reconcile&contextpage=banktransactionlist&id='.((int) $id).'&search_account='.((int) $id);
  252. if ($page) {
  253. $param .= '&page='.urlencode($page);
  254. }
  255. if ($offset) {
  256. $param .= '&offset='.urlencode($offset);
  257. }
  258. if ($limit) {
  259. $param .= '&limit='.urlencode($limit);
  260. }
  261. if ($search_conciliated != '' && $search_conciliated != '-1') {
  262. $param .= '&search_conciliated='.urlencode($search_conciliated);
  263. }
  264. if ($search_thirdparty_user) {
  265. $param .= '&search_thirdparty='.urlencode($search_thirdparty_user);
  266. }
  267. if ($search_num_releve) {
  268. $param .= '&search_num_releve='.urlencode($search_num_releve);
  269. }
  270. if ($search_description) {
  271. $param .= '&search_description='.urlencode($search_description);
  272. }
  273. if (dol_strlen($search_dt_start) > 0) {
  274. $param .= '&search_start_dtmonth='.GETPOST('search_start_dtmonth', 'int').'&search_start_dtday='.GETPOST('search_start_dtday', 'int').'&search_start_dtyear='.GETPOST('search_start_dtyear', 'int');
  275. }
  276. if (dol_strlen($search_dt_end) > 0) {
  277. $param .= '&search_end_dtmonth='.GETPOST('search_end_dtmonth', 'int').'&search_end_dtday='.GETPOST('search_end_dtday', 'int').'&search_end_dtyear='.GETPOST('search_end_dtyear', 'int');
  278. }
  279. if (dol_strlen($search_dv_start) > 0) {
  280. $param .= '&search_start_dvmonth='.GETPOST('search_start_dvmonth', 'int').'&search_start_dvday='.GETPOST('search_start_dvday', 'int').'&search_start_dvyear='.GETPOST('search_start_dvyear', 'int');
  281. }
  282. if (dol_strlen($search_dv_end) > 0) {
  283. $param .= '&search_end_dvmonth='.GETPOST('search_end_dvmonth', 'int').'&search_end_dvday='.GETPOST('search_end_dvday', 'int').'&search_end_dvyear='.GETPOST('search_end_dvyear', 'int');
  284. }
  285. if ($search_type) {
  286. $param .= '&search_type='.urlencode($search_type);
  287. }
  288. if ($search_debit) {
  289. $param .= '&search_debit='.urlencode($search_debit);
  290. }
  291. if ($search_credit) {
  292. $param .= '&search_credit='.urlencode($search_credit);
  293. }
  294. $param .= '&sortfield='.urlencode($sortfield).'&sortorder='.urlencode($sortorder);
  295. header('Location: '.$_SERVER["PHP_SELF"].'?'.$param); // To avoid to submit twice and allow the back button
  296. exit;
  297. }
  298. }
  299. if (GETPOST('save') && !$cancel && !empty($user->rights->banque->modifier)) {
  300. $error = 0;
  301. if (price2num(GETPOST("addcredit")) > 0) {
  302. $amount = price2num(GETPOST("addcredit"));
  303. } else {
  304. $amount = - price2num(GETPOST("adddebit"));
  305. }
  306. $operation = GETPOST("operation", 'alpha');
  307. $num_chq = GETPOST("num_chq", 'alpha');
  308. $label = GETPOST("label", 'alpha');
  309. $cat1 = GETPOST("cat1", 'alpha');
  310. $bankaccountid = $id;
  311. if (GETPOST('add_account', 'int') > 0) {
  312. $bankaccountid = GETPOST('add_account', 'int');
  313. }
  314. if (!$dateop) {
  315. $error++;
  316. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  317. }
  318. if (!$operation) {
  319. $error++;
  320. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
  321. }
  322. if (!$label) {
  323. $error++;
  324. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
  325. }
  326. if (!$amount) {
  327. $error++;
  328. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
  329. }
  330. if (!($bankaccountid > 0)) {
  331. $error++;
  332. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
  333. }
  334. /*if (isModEnabled('accounting') && (empty($search_accountancy_code) || $search_accountancy_code == '-1'))
  335. {
  336. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
  337. $error++;
  338. }*/
  339. if (!$error && !empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) {
  340. $objecttmp = new Account($db);
  341. $objecttmp->fetch($bankaccountid);
  342. $insertid = $objecttmp->addline($dateop, $operation, $label, $amount, $num_chq, ($cat1 > 0 ? $cat1 : 0), $user, '', '', $search_accountancy_code);
  343. if ($insertid > 0) {
  344. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  345. header("Location: ".$_SERVER['PHP_SELF'].($id ? "?id=".$id : ''));
  346. exit;
  347. } else {
  348. setEventMessages($object->error, $object->errors, 'errors');
  349. }
  350. } else {
  351. $action = 'addline';
  352. }
  353. }
  354. if ($action == 'confirm_delete' && $confirm == 'yes' && !empty($user->rights->banque->modifier)) {
  355. $accline = new AccountLine($db);
  356. $result = $accline->fetch(GETPOST("rowid", "int"));
  357. $result = $accline->delete($user);
  358. if ($result <= 0) {
  359. setEventMessages($accline->error, $accline->errors, 'errors');
  360. } else {
  361. setEventMessages('RecordDeleted', null, 'mesgs');
  362. }
  363. }
  364. /*
  365. * View
  366. */
  367. $form = new Form($db);
  368. $formother = new FormOther($db);
  369. $formaccounting = new FormAccounting($db);
  370. $companystatic = new Societe($db);
  371. $bankaccountstatic = new Account($db);
  372. $userstatic= new User($db);
  373. $banktransferstatic = new BonPrelevement($db);
  374. $societestatic = new Societe($db);
  375. $userstatic = new User($db);
  376. $chargestatic = new ChargeSociales($db);
  377. $loanstatic = new Loan($db);
  378. $memberstatic = new Adherent($db);
  379. $donstatic = new Don($db);
  380. $paymentstatic = new Paiement($db);
  381. $paymentsupplierstatic = new PaiementFourn($db);
  382. $paymentscstatic = new PaymentSocialContribution($db);
  383. $paymentvatstatic = new PaymentVAT($db);
  384. $paymentsalstatic = new PaymentSalary($db);
  385. $paymentdonationstatic = new PaymentDonation($db);
  386. $paymentvariousstatic = new PaymentVarious($db);
  387. $paymentexpensereportstatic = new PaymentExpenseReport($db);
  388. $bankstatic = new Account($db);
  389. $banklinestatic = new AccountLine($db);
  390. $bordereaustatic = new RemiseCheque($db);
  391. $now = dol_now();
  392. // Must be before button action
  393. $param = '';
  394. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  395. $param .= '&contextpage='.urlencode($contextpage);
  396. }
  397. if ($limit > 0 && $limit != $conf->liste_limit) {
  398. $param .= '&limit='.urlencode($limit);
  399. }
  400. if ($id > 0) {
  401. $param .= '&id='.urlencode($id);
  402. }
  403. if (!empty($ref)) {
  404. $param .= '&ref='.urlencode($ref);
  405. }
  406. if (!empty($search_ref)) {
  407. $param .= '&search_ref='.urlencode($search_ref);
  408. }
  409. if (!empty($search_description)) {
  410. $param .= '&search_description='.urlencode($search_description);
  411. }
  412. if (!empty($search_type)) {
  413. $param .= '&type='.urlencode($search_type);
  414. }
  415. if (!empty($search_thirdparty_user)) {
  416. $param .= '&search_thirdparty='.urlencode($search_thirdparty_user);
  417. }
  418. if (!empty($search_debit)) {
  419. $param .= '&search_debit='.urlencode($search_debit);
  420. }
  421. if (!empty($search_credit)) {
  422. $param .= '&search_credit='.urlencode($search_credit);
  423. }
  424. if ($search_account > 0) {
  425. $param .= '&search_account='.urlencode($search_account);
  426. }
  427. if (!empty($search_num_releve)) {
  428. $param .= '&search_num_releve='.urlencode($search_num_releve);
  429. }
  430. if ($search_conciliated != '' && $search_conciliated != '-1') {
  431. $param .= '&search_conciliated='.urlencode($search_conciliated);
  432. }
  433. if ($search_fk_bordereau > 0) {
  434. $param .= '$&search_fk_bordereau='.urlencode($search_fk_bordereau);
  435. }
  436. if ($search_bid > 0) {
  437. $param .= '&search_bid='.urlencode($search_bid);
  438. }
  439. if (dol_strlen($search_dt_start) > 0) {
  440. $param .= '&search_start_dtmonth='.GETPOST('search_start_dtmonth', 'int').'&search_start_dtday='.GETPOST('search_start_dtday', 'int').'&search_start_dtyear='.GETPOST('search_start_dtyear', 'int');
  441. }
  442. if (dol_strlen($search_dt_end) > 0) {
  443. $param .= '&search_end_dtmonth='.GETPOST('search_end_dtmonth', 'int').'&search_end_dtday='.GETPOST('search_end_dtday', 'int').'&search_end_dtyear='.GETPOST('search_end_dtyear', 'int');
  444. }
  445. if (dol_strlen($search_dv_start) > 0) {
  446. $param .= '&search_start_dvmonth='.GETPOST('search_start_dvmonth', 'int').'&search_start_dvday='.GETPOST('search_start_dvday', 'int').'&search_start_dvyear='.GETPOST('search_start_dvyear', 'int');
  447. }
  448. if (dol_strlen($search_dv_end) > 0) {
  449. $param .= '&search_end_dvmonth='.GETPOST('search_end_dvmonth', 'int').'&search_end_dvday='.GETPOST('search_end_dvday', 'int').'&search_end_dvyear='.GETPOST('search_end_dvyear', 'int');
  450. }
  451. if ($search_req_nb) {
  452. $param .= '&req_nb='.urlencode($search_req_nb);
  453. }
  454. if (GETPOST("search_thirdparty", 'int')) {
  455. $param .= '&thirdparty='.urlencode(GETPOST("search_thirdparty", 'int'));
  456. }
  457. if ($optioncss != '') {
  458. $param .= '&optioncss='.urlencode($optioncss);
  459. }
  460. if ($action == 'reconcile') {
  461. $param .= '&action=reconcile';
  462. }
  463. $totalarray = array(
  464. 'nbfield' => 0,
  465. 'totalcred' => 0,
  466. 'totaldeb' => 0,
  467. );
  468. // Add $param from extra fields
  469. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  470. $options = array();
  471. $buttonreconcile = '';
  472. $morehtmlref = '';
  473. if ($id > 0 || !empty($ref)) {
  474. $title = $object->ref.' - '.$langs->trans("Transactions");
  475. } else {
  476. $title = $langs->trans("BankTransactions");
  477. }
  478. $help_url = '';
  479. llxHeader('', $title, $help_url, '', 0, 0, array(), array(), $param);
  480. if ($id > 0 || !empty($ref)) {
  481. // Load bank groups
  482. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
  483. $bankcateg = new BankCateg($db);
  484. foreach ($bankcateg->fetchAll() as $bankcategory) {
  485. $options[$bankcategory->id] = $bankcategory->label;
  486. }
  487. // Bank card
  488. $head = bank_prepare_head($object);
  489. print dol_get_fiche_head($head, 'journal', $langs->trans("FinancialAccount"), 0, 'account');
  490. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  491. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  492. print dol_get_fiche_end();
  493. /*
  494. * Buttons actions
  495. */
  496. if ($action != 'reconcile') {
  497. if ($object->canBeConciliated() > 0) {
  498. $allowautomaticconciliation = false; // TODO
  499. $titletoconciliatemanual = $langs->trans("Conciliate");
  500. $titletoconciliateauto = $langs->trans("Conciliate");
  501. if ($allowautomaticconciliation) {
  502. $titletoconciliatemanual .= ' ('.$langs->trans("Manual").')';
  503. $titletoconciliateauto .= ' ('.$langs->trans("Auto").')';
  504. }
  505. // If not cash account and can be reconciliate
  506. if ($user->rights->banque->consolidate) {
  507. $newparam = $param;
  508. $newparam = preg_replace('/search_conciliated=\d+/i', '', $newparam);
  509. $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.'">'.$titletoconciliatemanual.'</a>';
  510. } else {
  511. $buttonreconcile = '<a class="butActionRefused" style="margin-bottom: 5px !important; margin-top: 5px !important" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$titletoconciliatemanual.'</a>';
  512. }
  513. if ($allowautomaticconciliation) {
  514. // If not cash account and can be reconciliate
  515. if ($user->rights->banque->consolidate) {
  516. $newparam = $param;
  517. $newparam = preg_replace('/search_conciliated=\d+/i', '', $newparam);
  518. $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>';
  519. } else {
  520. $buttonreconcile .= ' <a class="butActionRefused" style="margin-bottom: 5px !important; margin-top: 5px !important" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$titletoconciliateauto.'</a>';
  521. }
  522. }
  523. }
  524. }
  525. }
  526. $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro as conciliated, b.num_releve, b.num_chq,";
  527. $sql .= " b.fk_account, b.fk_type, b.fk_bordereau,";
  528. $sql .= " ba.rowid as bankid, ba.ref as bankref";
  529. // Add fields from extrafields
  530. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  531. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  532. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  533. }
  534. }
  535. // Add fields from hooks
  536. $parameters = array();
  537. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  538. $sql .= $hookmanager->resPrint;
  539. $sql .= " FROM ";
  540. if ($search_bid > 0) {
  541. $sql .= MAIN_DB_PREFIX."bank_class as l,";
  542. }
  543. $sql .= " ".MAIN_DB_PREFIX."bank_account as ba,";
  544. $sql .= " ".MAIN_DB_PREFIX."bank as b";
  545. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  546. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (b.rowid = ef.fk_object)";
  547. }
  548. $sql .= " WHERE b.fk_account = ba.rowid";
  549. $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
  550. if ($search_account > 0) {
  551. $sql .= " AND b.fk_account = ".((int) $search_account);
  552. }
  553. // Search period criteria
  554. if (dol_strlen($search_dt_start) > 0) {
  555. $sql .= " AND b.dateo >= '".$db->idate($search_dt_start)."'";
  556. }
  557. if (dol_strlen($search_dt_end) > 0) {
  558. $sql .= " AND b.dateo <= '".$db->idate($search_dt_end)."'";
  559. }
  560. // Search period criteria
  561. if (dol_strlen($search_dv_start) > 0) {
  562. $sql .= " AND b.datev >= '".$db->idate($search_dv_start)."'";
  563. }
  564. if (dol_strlen($search_dv_end) > 0) {
  565. $sql .= " AND b.datev <= '".$db->idate($search_dv_end)."'";
  566. }
  567. if ($search_ref) {
  568. $sql .= natural_search("b.rowid", $search_ref, 1);
  569. }
  570. if ($search_req_nb) {
  571. $sql .= natural_search("b.num_chq", $search_req_nb);
  572. }
  573. if ($search_num_releve) {
  574. $sql .= natural_search("b.num_releve", $search_num_releve);
  575. }
  576. if ($search_conciliated != '' && $search_conciliated != '-1') {
  577. $sql .= " AND b.rappro = ".((int) $search_conciliated);
  578. }
  579. if ($search_fk_bordereau > 0) {
  580. $sql .= " AND b.fk_bordereau = " . ((int) $search_fk_bordereau);
  581. }
  582. if ($search_thirdparty_user) {
  583. $sql.= " AND (b.rowid IN ";
  584. $sql.= " ( SELECT bu.fk_bank FROM ".MAIN_DB_PREFIX."bank_url AS bu";
  585. $sql.= " JOIN ".MAIN_DB_PREFIX."bank AS b2 ON b2.rowid = bu.fk_bank";
  586. $sql.= " JOIN ".MAIN_DB_PREFIX."user AS subUser ON (bu.type = 'user' AND bu.url_id = subUser.rowid)";
  587. $sql.= " WHERE ". natural_search(array("subUser.firstname", "subUser.lastname"), $search_thirdparty_user, '', 1).")";
  588. $sql.= " OR b.rowid IN ";
  589. $sql.= " ( SELECT bu.fk_bank FROM ".MAIN_DB_PREFIX."bank_url AS bu";
  590. $sql.= " JOIN ".MAIN_DB_PREFIX."bank AS b2 ON b2.rowid = bu.fk_bank";
  591. $sql.= " JOIN ".MAIN_DB_PREFIX."societe AS subSoc ON (bu.type = 'company' AND bu.url_id = subSoc.rowid)";
  592. $sql.= " WHERE ". natural_search(array("subSoc.nom"), $search_thirdparty_user, '', 1);
  593. $sql.= "))";
  594. }
  595. if ($search_description) {
  596. $search_description_to_use = $search_description;
  597. $arrayoffixedlabels = array(
  598. 'payment_salary',
  599. 'CustomerInvoicePayment', 'CustomerInvoicePaymentBack',
  600. 'SupplierInvoicePayment', 'SupplierInvoicePaymentBack',
  601. 'DonationPayment',
  602. 'ExpenseReportPayment',
  603. 'SocialContributionPayment',
  604. 'SubscriptionPayment',
  605. 'WithdrawalPayment'
  606. );
  607. foreach ($arrayoffixedlabels as $keyforlabel) {
  608. $translatedlabel = $langs->transnoentitiesnoconv($keyforlabel);
  609. if (preg_match('/'.$search_description.'/i', $translatedlabel)) {
  610. $search_description_to_use .= "|".$keyforlabel;
  611. }
  612. }
  613. $sql .= natural_search("b.label", $search_description_to_use); // Warning some text are just translation keys, not translated strings
  614. }
  615. if ($search_bid > 0) {
  616. $sql .= " AND b.rowid = l.lineid AND l.fk_categ = ".((int) $search_bid);
  617. }
  618. if (!empty($search_type)) {
  619. $sql .= " AND b.fk_type = '".$db->escape($search_type)."'";
  620. }
  621. // Search criteria amount
  622. if ($search_debit) {
  623. $sql .= natural_search('ABS(b.amount)', $search_debit, 1);
  624. $sql .= ' AND b.amount <= 0';
  625. }
  626. if ($search_credit) {
  627. $sql .= natural_search('b.amount', $search_credit, 1);
  628. $sql .= ' AND b.amount >= 0';
  629. }
  630. // Add where from extra fields
  631. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  632. // Add where from hooks
  633. $parameters = array();
  634. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  635. $sql .= $hookmanager->resPrint;
  636. $sql .= $db->order($sortfield, $sortorder);
  637. $nbtotalofrecords = '';
  638. $nbtotalofpages = 0;
  639. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  640. $result = $db->query($sql);
  641. $nbtotalofrecords = $db->num_rows($result);
  642. $nbtotalofpages = ceil($nbtotalofrecords / $limit);
  643. }
  644. if (($id > 0 || !empty($ref)) && ((string) $page == '')) {
  645. // We open a list of transaction of a dedicated account and no page was set by defaut
  646. // We force on last page.
  647. $page = ($nbtotalofpages - 1);
  648. $offset = $limit * $page;
  649. if ($page < 0) {
  650. $page = 0;
  651. }
  652. }
  653. if ($page >= $nbtotalofpages) {
  654. // If we made a search and result has low page than the page number we were on
  655. $page = ($nbtotalofpages - 1);
  656. $offset = $limit * $page;
  657. if ($page < 0) {
  658. $page = 0;
  659. }
  660. }
  661. // If not account defined $mode_balance_ok=false
  662. if (empty($search_account)) {
  663. $mode_balance_ok = false;
  664. }
  665. // If a search is done $mode_balance_ok=false
  666. if (!empty($search_ref)) {
  667. $mode_balance_ok = false;
  668. }
  669. if (!empty($search_description)) {
  670. $mode_balance_ok = false;
  671. }
  672. if (!empty($search_type)) {
  673. $mode_balance_ok = false;
  674. }
  675. if (!empty($search_debit)) {
  676. $mode_balance_ok = false;
  677. }
  678. if (!empty($search_credit)) {
  679. $mode_balance_ok = false;
  680. }
  681. if (!empty($search_thirdparty_user)) {
  682. $mode_balance_ok = false;
  683. }
  684. if ($search_conciliated != '' && $search_conciliated != '-1') {
  685. $mode_balance_ok = false;
  686. }
  687. if (!empty($search_num_releve)) {
  688. $mode_balance_ok = false;
  689. }
  690. if (!empty($search_fk_bordereau)) {
  691. $mode_balance_ok = false;
  692. }
  693. $sql .= $db->plimit($limit + 1, $offset);
  694. //print $sql;
  695. dol_syslog('compta/bank/bankentries_list.php', LOG_DEBUG);
  696. $resql = $db->query($sql);
  697. if ($resql) {
  698. $num = $db->num_rows($resql);
  699. $arrayofselected = (!empty($toselect) && is_array($toselect)) ? $toselect : array();
  700. // List of mass actions available
  701. $arrayofmassactions = array(
  702. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  703. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  704. );
  705. //if ($user->rights->bank->supprimer) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  706. if (in_array($massaction, array('presend', 'predelete'))) {
  707. $arrayofmassactions = array();
  708. }
  709. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  710. // Confirmation delete
  711. if ($action == 'delete') {
  712. $text = $langs->trans('ConfirmDeleteTransaction');
  713. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&rowid='.GETPOST("rowid", 'int'), $langs->trans('DeleteTransaction'), $text, 'confirm_delete', null, '', 1);
  714. }
  715. // Lines of title fields
  716. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="search_form">'."\n";
  717. if ($optioncss != '') {
  718. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  719. }
  720. print '<input type="hidden" name="token" value="'.newToken().'">';
  721. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  722. print '<input type="hidden" name="action" value="'.($action != 'delete' ? $action : 'search').'">';
  723. if (!empty($view)) {
  724. print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
  725. }
  726. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  727. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  728. print '<input type="hidden" name="page" value="'.$page.'">';
  729. print '<input type="hidden" name="id" value="'.$id.'">';
  730. print '<input type="hidden" name="ref" value="'.$ref.'">';
  731. if (GETPOST('bid')) {
  732. print '<input type="hidden" name="bid" value="'.GETPOST("bid", 'int').'">';
  733. }
  734. // Form to reconcile
  735. if ($user->rights->banque->consolidate && $action == 'reconcile') {
  736. print '<div class="valignmiddle inline-block" style="padding-right: 20px;">';
  737. print '<strong>'.$langs->trans("InputReceiptNumber").'</strong>: ';
  738. print '<input class="flat" id="num_releve" name="num_releve" type="text" value="'.(GETPOST('num_releve') ?GETPOST('num_releve') : '').'" size="10">'; // The only default value is value we just entered
  739. print '</div>';
  740. if (is_array($options) && count($options)) {
  741. print $langs->trans("EventualyAddCategory").': ';
  742. print Form::selectarray('cat', $options, GETPOST('cat'), 1);
  743. }
  744. print '<br><div style="margin-top: 5px;"><span class="opacitymedium">'.$langs->trans("ThenCheckLinesAndConciliate").'</span> ';
  745. print '<input class="button" name="confirm_savestatement" type="submit" value="'.$langs->trans("SaveStatementOnly").'">';
  746. print ' '.$langs->trans("or").' ';
  747. print '<input class="button" name="confirm_reconcile" type="submit" value="'.$langs->trans("Conciliate").'">';
  748. print ' '.$langs->trans("or").' ';
  749. print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
  750. print '</div>';
  751. // Show last bank statements
  752. $nbmax = 12; // We show last 12 receipts (so we can have more than one year)
  753. $liste = "";
  754. $sql = "SELECT DISTINCT num_releve FROM ".MAIN_DB_PREFIX."bank";
  755. $sql .= " WHERE fk_account = ".((int) $object->id)." AND num_releve IS NOT NULL";
  756. $sql .= $db->order("num_releve", "DESC");
  757. $sql .= $db->plimit($nbmax + 1);
  758. print '<br>';
  759. print $langs->trans("LastAccountStatements").' : ';
  760. $resqlr = $db->query($sql);
  761. if ($resqlr) {
  762. $numr = $db->num_rows($resqlr);
  763. $i = 0;
  764. $last_ok = 0;
  765. while (($i < $numr) && ($i < $nbmax)) {
  766. $objr = $db->fetch_object($resqlr);
  767. if (!$last_ok) {
  768. $last_releve = $objr->num_releve;
  769. $last_ok = 1;
  770. }
  771. $i++;
  772. $liste = '<a href="'.DOL_URL_ROOT.'/compta/bank/releve.php?account='.$id.'&amp;num='.$objr->num_releve.'">'.$objr->num_releve.'</a> &nbsp; '.$liste;
  773. }
  774. if ($numr >= $nbmax) {
  775. $liste = "... &nbsp; ".$liste;
  776. }
  777. print $liste;
  778. if ($numr <= 0) {
  779. print '<b>'.$langs->trans("None").'</b>';
  780. }
  781. } else {
  782. dol_print_error($db);
  783. }
  784. // Using BANK_REPORT_LAST_NUM_RELEVE to automatically report last num (or not)
  785. if (!empty($conf->global->BANK_REPORT_LAST_NUM_RELEVE)) {
  786. print '
  787. <script type="text/javascript">
  788. $("#num_releve").val("' . $last_releve.'");
  789. </script>
  790. ';
  791. }
  792. print '<br><br>';
  793. }
  794. // Form to add a transaction with no invoice
  795. if (!empty($user->rights->banque->modifier) && $action == 'addline' && !empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) {
  796. print load_fiche_titre($langs->trans("AddBankRecordLong"), '', '');
  797. print '<table class="noborder centpercent">';
  798. print '<tr class="liste_titre">';
  799. print '<td>'.$langs->trans("Description").'</td>';
  800. print '<td>'.$langs->trans("Date").'</td>';
  801. print '<td>&nbsp;</td>';
  802. print '<td>'.$langs->trans("Type").'</td>';
  803. print '<td>'.$langs->trans("Numero").'</td>';
  804. print '<td class=right>'.$langs->trans("BankAccount").'</td>';
  805. print '<td class=right>'.$langs->trans("Debit").'</td>';
  806. print '<td class=right>'.$langs->trans("Credit").'</td>';
  807. /*if (isModEnabled('accounting'))
  808. {
  809. print '<td class="center">';
  810. print $langs->trans("AccountAccounting");
  811. print '</td>';
  812. }*/
  813. print '<td align="center">&nbsp;</td>';
  814. print '</tr>';
  815. print '<tr>';
  816. print '<td>';
  817. print '<input name="label" class="flat minwidth200" type="text" value="'.GETPOST("label", "alpha").'">';
  818. if (is_array($options) && count($options)) {
  819. print '<br>'.$langs->trans("Rubrique").': ';
  820. print Form::selectarray('cat1', $options, GETPOST('cat1'), 1);
  821. }
  822. print '</td>';
  823. print '<td class="nowrap">';
  824. print $form->selectDate(empty($dateop) ?-1 : $dateop, 'op', 0, 0, 0, 'transaction');
  825. print '</td>';
  826. print '<td>&nbsp;</td>';
  827. print '<td class="nowrap">';
  828. $form->select_types_paiements((GETPOST('operation') ?GETPOST('operation') : ($object->courant == Account::TYPE_CASH ? 'LIQ' : '')), 'operation', '1,2', 2, 1);
  829. print '</td>';
  830. print '<td>';
  831. print '<input name="num_chq" class="flat" type="text" size="4" value="'.GETPOST("num_chq", "alpha").'">';
  832. print '</td>';
  833. //if (! $search_account > 0)
  834. //{
  835. print '<td class=right>';
  836. $form->select_comptes(GETPOST('add_account', 'int') ?GETPOST('add_account', 'int') : $search_account, 'add_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''));
  837. print '</td>';
  838. //}
  839. print '<td class="right"><input name="adddebit" class="flat" type="text" size="4" value="'.GETPOST("adddebit", "alpha").'"></td>';
  840. print '<td class="right"><input name="addcredit" class="flat" type="text" size="4" value="'.GETPOST("addcredit", "alpha").'"></td>';
  841. /*if (isModEnabled('accounting'))
  842. {
  843. print '<td class="center">';
  844. print $formaccounting->select_account($search_accountancy_code, 'search_accountancy_code', 1, null, 1, 1, '');
  845. print '</td>';
  846. }*/
  847. print '<td class="center">';
  848. print '<input type="submit" name="save" class="button buttongen marginbottomonly button-add" value="'.$langs->trans("Add").'"><br>';
  849. print '<input type="submit" name="cancel" class="button buttongen marginbottomonly button-cancel" value="'.$langs->trans("Cancel").'">';
  850. print '</td></tr>';
  851. print '</table>';
  852. print '<br>';
  853. }
  854. // Code to adjust value date with plus and less picto using an Ajax call instead of a full reload of page
  855. $urlajax = DOL_URL_ROOT.'/core/ajax/bankconciliate.php?token='.currentToken();
  856. print '
  857. <script type="text/javascript">
  858. $(function() {
  859. $("a.ajaxforbankoperationchange").each(function(){
  860. var current = $(this);
  861. current.click(function()
  862. {
  863. var url = "'.$urlajax.'&"+current.attr("href").split("?")[1];
  864. $.get(url, function(data)
  865. {
  866. console.log(url)
  867. console.log(data)
  868. current.parent().parent().find(".spanforajaxedit").replaceWith(data);
  869. });
  870. return false;
  871. });
  872. });
  873. });
  874. </script>
  875. ';
  876. $i = 0;
  877. // Title
  878. $bankcateg = new BankCateg($db);
  879. $newcardbutton = '';
  880. if ($action != 'addline' && $action != 'reconcile') {
  881. if (empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) {
  882. if (empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) { // Default is to record miscellaneous direct entries using miscellaneous payments
  883. $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create&accountid='.urlencode($search_account).'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.urlencode($search_account)), '', $user->rights->banque->modifier);
  884. } else // If direct entries is not done using miscellaneous payments
  885. {
  886. $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&token='.newToken().'&page='.$page.$param, '', $user->rights->banque->modifier);
  887. }
  888. } else {
  889. $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&token='.newToken().'&page='.$page.$param, '', -1);
  890. }
  891. }
  892. $morehtml = '';
  893. /*$morehtml = '<div class="inline-block '.(($buttonreconcile || $newcardbutton) ? 'marginrightonly' : '').'">';
  894. $morehtml .= '<label for="pageplusone">'.$langs->trans("Page")."</label> "; // ' Page ';
  895. $morehtml .= '<input type="text" name="pageplusone" id="pageplusone" class="flat right width25 pageplusone" value="'.($page + 1).'">';
  896. $morehtml .= '/'.$nbtotalofpages.' ';
  897. $morehtml .= '</div>';
  898. */
  899. if ($action != 'addline' && $action != 'reconcile') {
  900. $morehtml .= $buttonreconcile;
  901. }
  902. $morehtml .= '<!-- Add New button -->'.$newcardbutton;
  903. $picto = 'bank_account';
  904. if ($id > 0 || !empty($ref)) {
  905. $picto = '';
  906. }
  907. print_barre_liste($langs->trans("BankTransactions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit, 0, 0, 1);
  908. // We can add page now to param
  909. if ($page != '') {
  910. $param .= '&page='.urlencode($page);
  911. }
  912. $moreforfilter = '';
  913. $moreforfilter .= '<div class="divsearchfield">';
  914. $moreforfilter .= $langs->trans('DateOperationShort');
  915. $moreforfilter .= ($conf->browser->layout == 'phone' ? '<br>' : ' ');
  916. $moreforfilter .= '<div class="nowrap inline-block">';
  917. $moreforfilter .= $form->selectDate($search_dt_start, 'search_start_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  918. $moreforfilter .= '</div>';
  919. $moreforfilter .= ($conf->browser->layout == 'phone' ? '' : ' ');
  920. $moreforfilter .= '<div class="nowrap inline-block">';
  921. $moreforfilter .= $form->selectDate($search_dt_end, 'search_end_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  922. $moreforfilter .= '</div>';
  923. $moreforfilter .= '</div>';
  924. $moreforfilter .= '<div class="divsearchfield">';
  925. $moreforfilter .= $langs->trans('DateValueShort');
  926. $moreforfilter .= ($conf->browser->layout == 'phone' ? '<br>' : ' ');
  927. $moreforfilter .= '<div class="nowrap inline-block">';
  928. $moreforfilter .= $form->selectDate($search_dv_start, 'search_start_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  929. $moreforfilter .= '</div>';
  930. $moreforfilter .= ($conf->browser->layout == 'phone' ? '' : ' ');
  931. $moreforfilter .= '<div class="nowrap inline-block">';
  932. $moreforfilter .= $form->selectDate($search_dv_end, 'search_end_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  933. $moreforfilter .= '</div>';
  934. $moreforfilter .= '</div>';
  935. if (isModEnabled('categorie')) {
  936. // Categories
  937. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  938. $langs->load('categories');
  939. // Bank line
  940. $moreforfilter .= '<div class="divsearchfield">';
  941. $tmptitle = $langs->trans('RubriquesTransactions');
  942. $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, $search_bid, 'parent', null, null, 1);
  943. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_bid', $cate_arbo, $search_bid, $tmptitle, 0, 0, '', 0, 0, 0, '', '', 1);
  944. $moreforfilter .= '</div>';
  945. }
  946. }
  947. $parameters = array();
  948. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  949. if (empty($reshook)) {
  950. $moreforfilter .= $hookmanager->resPrint;
  951. } else {
  952. $moreforfilter = $hookmanager->resPrint;
  953. }
  954. if ($moreforfilter) {
  955. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  956. print $moreforfilter;
  957. print '</div>'."\n";
  958. }
  959. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  960. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  961. // When action is 'reconcile', we force to have the column num_releve always enabled (otherwise we can't make reconciliation).
  962. if ($action == 'reconcile') {
  963. $arrayfields['b.num_releve']['checked'] = 1;
  964. }
  965. print '<div class="div-table-responsive">';
  966. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  967. print '<tr class="liste_titre_filter">';
  968. if (!empty($arrayfields['b.rowid']['checked'])) {
  969. print '<td class="liste_titre">';
  970. print '<input type="text" class="flat" name="search_ref" size="2" value="'.dol_escape_htmltag($search_ref).'">';
  971. print '</td>';
  972. }
  973. if (!empty($arrayfields['b.label']['checked'])) {
  974. print '<td class="liste_titre">';
  975. print '<input type="text" class="flat maxwidth100" name="search_description" value="'.dol_escape_htmltag($search_description).'">';
  976. print '</td>';
  977. }
  978. if (!empty($arrayfields['b.dateo']['checked'])) {
  979. print '<td class="liste_titre">&nbsp;</td>';
  980. }
  981. if (!empty($arrayfields['b.datev']['checked'])) {
  982. print '<td class="liste_titre">&nbsp;</td>';
  983. }
  984. if (!empty($arrayfields['type']['checked'])) {
  985. print '<td class="liste_titre" align="center">';
  986. print $form->select_types_paiements(empty($search_type) ? '' : $search_type, 'search_type', '', 2, 1, 1, 0, 1, 'maxwidth100', 1);
  987. print '</td>';
  988. }
  989. // Numero
  990. if (!empty($arrayfields['b.num_chq']['checked'])) {
  991. print '<td class="liste_titre" align="center"><input type="text" class="flat" name="req_nb" value="'.dol_escape_htmltag($search_req_nb).'" size="2"></td>';
  992. }
  993. // Checked
  994. if (!empty($arrayfields['bu.label']['checked'])) {
  995. print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_thirdparty" value="'.dol_escape_htmltag($search_thirdparty_user).'"></td>';
  996. }
  997. // Ref
  998. if (!empty($arrayfields['ba.ref']['checked'])) {
  999. print '<td class="liste_titre">';
  1000. $form->select_comptes($search_account, 'search_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''), 0, 'maxwidth100');
  1001. print '</td>';
  1002. }
  1003. // Debit
  1004. if (!empty($arrayfields['b.debit']['checked'])) {
  1005. print '<td class="liste_titre right">';
  1006. print '<input type="text" class="flat width50" name="search_debit" value="'.dol_escape_htmltag($search_debit).'">';
  1007. print '</td>';
  1008. }
  1009. // Credit
  1010. if (!empty($arrayfields['b.credit']['checked'])) {
  1011. print '<td class="liste_titre right">';
  1012. print '<input type="text" class="flat width50" name="search_credit" value="'.dol_escape_htmltag($search_credit).'">';
  1013. print '</td>';
  1014. }
  1015. // Balance before
  1016. if (!empty($arrayfields['balancebefore']['checked'])) {
  1017. print '<td class="liste_titre right">';
  1018. $htmltext = $langs->trans("BalanceVisibilityDependsOnSortAndFilters", $langs->transnoentitiesnoconv("DateValue"));
  1019. print $form->textwithpicto('', $htmltext, 1);
  1020. print '</td>';
  1021. }
  1022. // Balance
  1023. if (!empty($arrayfields['balance']['checked'])) {
  1024. print '<td class="liste_titre right">';
  1025. $htmltext = $langs->trans("BalanceVisibilityDependsOnSortAndFilters", $langs->transnoentitiesnoconv("DateValue"));
  1026. print $form->textwithpicto('', $htmltext, 1);
  1027. print '</td>';
  1028. }
  1029. // Numero statement
  1030. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1031. print '<td class="liste_titre" align="center"><input type="text" class="flat" name="search_num_releve" value="'.dol_escape_htmltag($search_num_releve).'" size="3"></td>';
  1032. }
  1033. // Conciliated
  1034. if (!empty($arrayfields['b.conciliated']['checked'])) {
  1035. print '<td class="liste_titre center parentonrightofpage">';
  1036. print $form->selectyesno('search_conciliated', $search_conciliated, 1, false, 1, 1, 'search_status onrightofpage maxwidth75');
  1037. print '</td>';
  1038. }
  1039. // Bordereau
  1040. if (!empty($arrayfields['b.fk_bordereau']['checked'])) {
  1041. print '<td class="liste_titre" align="center"><input type="text" class="flat" name="search_fk_bordereau" value="'.dol_escape_htmltag($search_fk_bordereau).'" size="3"></td>';
  1042. }
  1043. // Actions and select
  1044. print '<td class="liste_titre" align="middle">';
  1045. $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
  1046. print $searchpicto;
  1047. print '</td>';
  1048. print "</tr>\n";
  1049. // Fields title
  1050. print '<tr class="liste_titre">';
  1051. if (!empty($arrayfields['b.rowid']['checked'])) {
  1052. print_liste_field_titre($arrayfields['b.rowid']['label'], $_SERVER['PHP_SELF'], 'b.rowid', '', $param, '', $sortfield, $sortorder);
  1053. }
  1054. if (!empty($arrayfields['b.label']['checked'])) {
  1055. print_liste_field_titre($arrayfields['b.label']['label'], $_SERVER['PHP_SELF'], 'b.label', '', $param, '', $sortfield, $sortorder);
  1056. }
  1057. if (!empty($arrayfields['b.dateo']['checked'])) {
  1058. print_liste_field_titre($arrayfields['b.dateo']['label'], $_SERVER['PHP_SELF'], 'b.dateo', '', $param, '', $sortfield, $sortorder, "center ");
  1059. }
  1060. if (!empty($arrayfields['b.datev']['checked'])) {
  1061. print_liste_field_titre($arrayfields['b.datev']['label'], $_SERVER['PHP_SELF'], 'b.datev,b.dateo,b.rowid', '', $param, 'align="center"', $sortfield, $sortorder);
  1062. }
  1063. if (!empty($arrayfields['type']['checked'])) {
  1064. print_liste_field_titre($arrayfields['type']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'align="center"', $sortfield, $sortorder);
  1065. }
  1066. if (!empty($arrayfields['b.num_chq']['checked'])) {
  1067. print_liste_field_titre($arrayfields['b.num_chq']['label'], $_SERVER['PHP_SELF'], 'b.num_chq', '', $param, '', $sortfield, $sortorder, "center ");
  1068. }
  1069. if (!empty($arrayfields['bu.label']['checked'])) {
  1070. print_liste_field_titre($arrayfields['bu.label']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  1071. }
  1072. if (!empty($arrayfields['ba.ref']['checked'])) {
  1073. print_liste_field_titre($arrayfields['ba.ref']['label'], $_SERVER['PHP_SELF'], 'ba.ref', '', $param, '', $sortfield, $sortorder);
  1074. }
  1075. if (!empty($arrayfields['b.debit']['checked'])) {
  1076. print_liste_field_titre($arrayfields['b.debit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, "right ");
  1077. }
  1078. if (!empty($arrayfields['b.credit']['checked'])) {
  1079. print_liste_field_titre($arrayfields['b.credit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, "right ");
  1080. }
  1081. if (!empty($arrayfields['balancebefore']['checked'])) {
  1082. print_liste_field_titre($arrayfields['balancebefore']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, "right ");
  1083. }
  1084. if (!empty($arrayfields['balance']['checked'])) {
  1085. print_liste_field_titre($arrayfields['balance']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, "right ");
  1086. }
  1087. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1088. print_liste_field_titre($arrayfields['b.num_releve']['label'], $_SERVER['PHP_SELF'], 'b.num_releve', '', $param, '', $sortfield, $sortorder, "center ");
  1089. }
  1090. if (!empty($arrayfields['b.conciliated']['checked'])) {
  1091. print_liste_field_titre($arrayfields['b.conciliated']['label'], $_SERVER['PHP_SELF'], 'b.rappro', '', $param, '', $sortfield, $sortorder, "center ");
  1092. }
  1093. if (!empty($arrayfields['b.fk_bordereau']['checked'])) {
  1094. print_liste_field_titre($arrayfields['b.fk_bordereau']['label'], $_SERVER['PHP_SELF'], 'b.fk_bordereau', '', $param, '', $sortfield, $sortorder, "center ");
  1095. }
  1096. // Extra fields
  1097. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1098. // Hook fields
  1099. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1100. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1101. print $hookmanager->resPrint;
  1102. // Actions and select
  1103. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  1104. print "</tr>\n";
  1105. $balance = 0; // For balance
  1106. $balancebefore = 0; // For balance
  1107. $balancecalculated = false;
  1108. $posconciliatecol = 0;
  1109. $cachebankaccount = array();
  1110. // Loop on each record
  1111. $sign = 1;
  1112. while ($i < min($num, $limit)) {
  1113. $objp = $db->fetch_object($resql);
  1114. $links = $bankaccountstatic->get_url($objp->rowid);
  1115. // If we are in a situation where we need/can show balance, we calculate the start of balance
  1116. if (!$balancecalculated && (!empty($arrayfields['balancebefore']['checked']) || !empty($arrayfields['balance']['checked'])) && ($mode_balance_ok || $search_conciliated === '0')) {
  1117. if (!$search_account) {
  1118. dol_print_error('', 'account is not defined but $mode_balance_ok is true');
  1119. exit;
  1120. }
  1121. // Loop on each record before
  1122. $sign = 1;
  1123. $i = 0;
  1124. $sqlforbalance = 'SELECT SUM(b.amount) as previoustotal';
  1125. $sqlforbalance .= " FROM ";
  1126. $sqlforbalance .= " ".MAIN_DB_PREFIX."bank_account as ba,";
  1127. $sqlforbalance .= " ".MAIN_DB_PREFIX."bank as b";
  1128. $sqlforbalance .= " WHERE b.fk_account = ba.rowid";
  1129. $sqlforbalance .= " AND ba.entity IN (".getEntity('bank_account').")";
  1130. $sqlforbalance .= " AND b.fk_account = ".((int) $search_account);
  1131. $sqlforbalance .= " AND (b.datev < '".$db->idate($db->jdate($objp->dv))."' OR (b.datev = '".$db->idate($db->jdate($objp->dv))."' AND (b.dateo < '".$db->idate($db->jdate($objp->do))."' OR (b.dateo = '".$db->idate($db->jdate($objp->do))."' AND b.rowid < ".$objp->rowid."))))";
  1132. $resqlforbalance = $db->query($sqlforbalance);
  1133. //print $sqlforbalance;
  1134. if ($resqlforbalance) {
  1135. $objforbalance = $db->fetch_object($resqlforbalance);
  1136. if ($objforbalance) {
  1137. // If sort is desc,desc,desc then total of previous date + amount is the balancebefore of the previous line before the line to show
  1138. if ($sortfield == 'b.datev,b.dateo,b.rowid' && ($sortorder == 'desc' || $sortorder == 'desc,desc' || $sortorder == 'desc,desc,desc')) {
  1139. $balancebefore = $objforbalance->previoustotal + ($sign * $objp->amount);
  1140. } else {
  1141. // If sort is asc,asc,asc then total of previous date is balance of line before the next line to show
  1142. $balance = $objforbalance->previoustotal;
  1143. }
  1144. }
  1145. } else {
  1146. dol_print_error($db);
  1147. }
  1148. $balancecalculated = true;
  1149. // Output a line with start balance
  1150. if ($user->rights->banque->consolidate && $action == 'reconcile') {
  1151. $tmpnbfieldbeforebalance = 0;
  1152. $tmpnbfieldafterbalance = 0;
  1153. $balancefieldfound = 0;
  1154. foreach ($arrayfields as $key => $val) {
  1155. if ($key == 'balancebefore' || $key == 'balance') {
  1156. $balancefieldfound++;
  1157. continue;
  1158. }
  1159. if (!empty($arrayfields[$key]['checked'])) {
  1160. if (!$balancefieldfound) {
  1161. $tmpnbfieldbeforebalance++;
  1162. } else {
  1163. $tmpnbfieldafterbalance++;
  1164. }
  1165. }
  1166. }
  1167. // Extra fields
  1168. $element = 'banktransaction';
  1169. if (!empty($extrafields->attributes[$element]['label']) && is_array($extrafields->attributes[$element]['label']) && count($extrafields->attributes[$element]['label'])) {
  1170. foreach ($extrafields->attributes[$element]['label'] as $key => $val) {
  1171. if (!empty($arrayfields["ef.".$key]['checked'])) {
  1172. if (!empty($arrayfields[$key]['checked'])) {
  1173. if (!$balancefieldfound) {
  1174. $tmpnbfieldbeforebalance++;
  1175. } else {
  1176. $tmpnbfieldafterbalance++;
  1177. }
  1178. }
  1179. }
  1180. }
  1181. }
  1182. print '<tr class="oddeven trforbreak">';
  1183. if ($tmpnbfieldbeforebalance) {
  1184. print '<td colspan="'.$tmpnbfieldbeforebalance.'">';
  1185. print '&nbsp;';
  1186. print '</td>';
  1187. }
  1188. if (!empty($arrayfields['balancebefore']['checked'])) {
  1189. print '<td class="right">';
  1190. if ($search_conciliated !== '0') {
  1191. print price(price2num($balance, 'MT'), 1, $langs);
  1192. }
  1193. print '</td>';
  1194. }
  1195. if (!empty($arrayfields['balance']['checked'])) {
  1196. print '<td class="right">';
  1197. if ($search_conciliated !== '0') {
  1198. print price(price2num($balance, 'MT'), 1, $langs);
  1199. }
  1200. print '</td>';
  1201. }
  1202. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1203. print '<td class="center">';
  1204. print '<input type="checkbox" id="selectAll" title="'.dol_escape_htmltag($langs->trans("SelectAll")).'" />';
  1205. print ' <script type="text/javascript">
  1206. $("input#selectAll").change(function() {
  1207. $("input[type=checkbox][name^=rowid]").prop("checked", $(this).is(":checked"));
  1208. });
  1209. </script>';
  1210. print '</td>';
  1211. }
  1212. print '<td colspan="'.($tmpnbfieldafterbalance + 1).'">';
  1213. print '&nbsp;';
  1214. print '</td>';
  1215. print '</tr>';
  1216. }
  1217. }
  1218. if ($sortfield == 'b.datev,b.dateo,b.rowid' && ($sortorder == 'desc' || $sortorder == 'desc,desc' || $sortorder == 'desc,desc,desc')) {
  1219. $balance = price2num($balancebefore, 'MT'); // balance = balancebefore of previous line (sort is desc)
  1220. $balancebefore = price2num($balancebefore - ($sign * $objp->amount), 'MT');
  1221. } else {
  1222. $balancebefore = price2num($balance, 'MT'); // balancebefore = balance of previous line (sort is asc)
  1223. $balance = price2num($balance + ($sign * $objp->amount), 'MT');
  1224. }
  1225. if (empty($cachebankaccount[$objp->bankid])) {
  1226. $bankaccounttmp = new Account($db);
  1227. $bankaccounttmp->fetch($objp->bankid);
  1228. $cachebankaccount[$objp->bankid] = $bankaccounttmp;
  1229. $bankaccount = $bankaccounttmp;
  1230. } else {
  1231. $bankaccount = $cachebankaccount[$objp->bankid];
  1232. }
  1233. if (empty($conf->global->BANK_COLORIZE_MOVEMENT)) {
  1234. $backgroundcolor = "class='oddeven'";
  1235. } else {
  1236. if ($objp->amount < 0) {
  1237. $color = '#' . getDolGlobalString('BANK_COLORIZE_MOVEMENT_COLOR1', 'fca955');
  1238. $backgroundcolor = 'style="background: '.$color.';"';
  1239. } else {
  1240. $color = '#' . getDolGlobalString('BANK_COLORIZE_MOVEMENT_COLOR2', '7fdb86');
  1241. $backgroundcolor = 'style="background: '.$color.';"';
  1242. }
  1243. }
  1244. $banklinestatic->id = $objp->rowid;
  1245. $banklinestatic->ref = $objp->rowid;
  1246. print '<tr class="oddeven" '.$backgroundcolor.'>';
  1247. // Ref
  1248. if (!empty($arrayfields['b.rowid']['checked'])) {
  1249. print '<td class="nowrap left">';
  1250. print $banklinestatic->getNomUrl(1);
  1251. print '</td>';
  1252. if (!$i) {
  1253. $totalarray['nbfield']++;
  1254. }
  1255. }
  1256. // Description
  1257. if (!empty($arrayfields['b.label']['checked'])) {
  1258. $labeltoshow = '';
  1259. $titletoshow = '';
  1260. $reg = array();
  1261. preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthee on tente recherche de traduction
  1262. if (!empty($reg[1]) && $langs->trans($reg[1]) != $reg[1]) {
  1263. $labeltoshow = $langs->trans($reg[1]);
  1264. } else {
  1265. if ($objp->label == '(payment_salary)') {
  1266. $labeltoshow = $langs->trans("SalaryPayment");
  1267. } else {
  1268. $labeltoshow = dol_escape_htmltag($objp->label);
  1269. $titletoshow = $objp->label;
  1270. }
  1271. }
  1272. print '<td class="tdoverflowmax250"'.($titletoshow ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>';
  1273. // Add info about links after description
  1274. $cachebankaccount = array();
  1275. foreach ($links as $key => $val) {
  1276. print '<!-- '.$links[$key]['type'].' -->';
  1277. if ($links[$key]['type'] == 'withdraw') {
  1278. $banktransferstatic->id = $links[$key]['url_id'];
  1279. $banktransferstatic->ref = $links[$key]['label'];
  1280. print $banktransferstatic->getNomUrl(0).' ';
  1281. } elseif ($links[$key]['type'] == 'payment') {
  1282. $paymentstatic->id = $links[$key]['url_id'];
  1283. $paymentstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment
  1284. $paymentstatic->date = $db->jdate($objp->do);
  1285. print $paymentstatic->getNomUrl(2).' ';
  1286. } elseif ($links[$key]['type'] == 'payment_supplier') {
  1287. $paymentsupplierstatic->id = $links[$key]['url_id'];
  1288. $paymentsupplierstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment
  1289. print $paymentsupplierstatic->getNomUrl(2).' ';
  1290. } elseif ($links[$key]['type'] == 'payment_sc') {
  1291. $paymentscstatic->id = $links[$key]['url_id'];
  1292. $paymentscstatic->ref = $links[$key]['url_id'];
  1293. $paymentscstatic->label = $links[$key]['label'];
  1294. print $paymentscstatic->getNomUrl(2).' ';
  1295. } elseif ($links[$key]['type'] == 'payment_vat') {
  1296. $paymentvatstatic->id = $links[$key]['url_id'];
  1297. $paymentvatstatic->ref = $links[$key]['url_id'];
  1298. print $paymentvatstatic->getNomUrl(2).' ';
  1299. } elseif ($links[$key]['type'] == 'payment_salary') {
  1300. $paymentsalstatic->id = $links[$key]['url_id'];
  1301. $paymentsalstatic->ref = $links[$key]['url_id'];
  1302. $paymentsalstatic->label = $links[$key]['label'];
  1303. print $paymentsalstatic->getNomUrl(2).' ';
  1304. } elseif ($links[$key]['type'] == 'payment_loan') {
  1305. print '<a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$links[$key]['url_id'].'">';
  1306. print ' '.img_object($langs->trans('ShowPayment'), 'payment').' ';
  1307. print '</a> ';
  1308. } elseif ($links[$key]['type'] == 'payment_donation') {
  1309. $paymentdonationstatic->id = $links[$key]['url_id'];
  1310. $paymentdonationstatic->ref = $links[$key]['url_id'];
  1311. print $paymentdonationstatic->getNomUrl(2).' ';
  1312. } elseif ($links[$key]['type'] == 'payment_expensereport') {
  1313. $paymentexpensereportstatic->id = $links[$key]['url_id'];
  1314. $paymentexpensereportstatic->ref = $links[$key]['url_id'];
  1315. print $paymentexpensereportstatic->getNomUrl(2).' ';
  1316. } elseif ($links[$key]['type'] == 'payment_various') {
  1317. $paymentvariousstatic->id = $links[$key]['url_id'];
  1318. $paymentvariousstatic->ref = $links[$key]['url_id'];
  1319. print $paymentvariousstatic->getNomUrl(2).' ';
  1320. } elseif ($links[$key]['type'] == 'banktransfert') {
  1321. // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
  1322. if ($objp->amount > 0) {
  1323. $banklinestatic->fetch($links[$key]['url_id']);
  1324. $bankstatic->id = $banklinestatic->fk_account;
  1325. $bankstatic->label = $banklinestatic->bank_account_ref;
  1326. print $langs->trans("TransferFrom").' ';
  1327. print $bankstatic->getNomUrl(1, 'transactions');
  1328. print ' '.$langs->trans("toward").' ';
  1329. $bankstatic->id = $objp->bankid;
  1330. $bankstatic->label = $objp->bankref;
  1331. print $bankstatic->getNomUrl(1, '');
  1332. print ' - ';
  1333. } else {
  1334. $bankstatic->id = $objp->bankid;
  1335. $bankstatic->label = $objp->bankref;
  1336. print $langs->trans("TransferFrom").' ';
  1337. print $bankstatic->getNomUrl(1, '');
  1338. print ' '.$langs->trans("toward").' ';
  1339. $banklinestatic->fetch($links[$key]['url_id']);
  1340. $bankstatic->id = $banklinestatic->fk_account;
  1341. $bankstatic->label = $banklinestatic->bank_account_ref;
  1342. print $bankstatic->getNomUrl(1, 'transactions');
  1343. print ' - ';
  1344. }
  1345. //var_dump($links);
  1346. } elseif ($links[$key]['type'] == 'company') {
  1347. } elseif ($links[$key]['type'] == 'user') {
  1348. } elseif ($links[$key]['type'] == 'member') {
  1349. } elseif ($links[$key]['type'] == 'sc') {
  1350. } elseif ($links[$key]['type'] == 'vat') {
  1351. } elseif ($links[$key]['type'] == 'salary') {
  1352. // Information is already shown using the payment_salary link. No need of this link.
  1353. } else {
  1354. // Show link with label $links[$key]['label']
  1355. print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
  1356. if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
  1357. // Label generique car entre parentheses. On l'affiche en le traduisant
  1358. if ($reg[1] == 'paiement') {
  1359. $reg[1] = 'Payment';
  1360. }
  1361. print $langs->trans($reg[1]);
  1362. } else {
  1363. print $links[$key]['label'];
  1364. }
  1365. print '</a>'.($labeltoshow ? ' - ' : '');
  1366. }
  1367. }
  1368. print $labeltoshow; // Already escaped
  1369. print '</td>';
  1370. if (!$i) {
  1371. $totalarray['nbfield']++;
  1372. }
  1373. }
  1374. // Date ope
  1375. if (!empty($arrayfields['b.dateo']['checked'])) {
  1376. print '<td align="center" class="nowrap">';
  1377. print '<span class="spanforajaxedit" id="dateoperation_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->do), "day")."</span>";
  1378. print '&nbsp;';
  1379. print '<span class="inline-block">';
  1380. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=doprev&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1381. print img_edit_remove()."</a> ";
  1382. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=donext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1383. print img_edit_add()."</a>";
  1384. print '</span>';
  1385. print "</td>\n";
  1386. if (!$i) {
  1387. $totalarray['nbfield']++;
  1388. }
  1389. }
  1390. // Date value
  1391. if (!empty($arrayfields['b.datev']['checked'])) {
  1392. print '<td align="center" class="nowrap">';
  1393. print '<span class="spanforajaxedit" id="datevalue_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->dv), "day")."</span>";
  1394. print '&nbsp;';
  1395. print '<span class="inline-block">';
  1396. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=dvprev&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1397. print img_edit_remove()."</a> ";
  1398. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1399. print img_edit_add()."</a>";
  1400. print '</span>';
  1401. print "</td>\n";
  1402. if (!$i) {
  1403. $totalarray['nbfield']++;
  1404. }
  1405. }
  1406. // Payment type
  1407. if (!empty($arrayfields['type']['checked'])) {
  1408. print '<td class="tdoverflowmax100 center">';
  1409. $labeltype = ($langs->trans("PaymentTypeShort".$objp->fk_type) != "PaymentTypeShort".$objp->fk_type) ? $langs->trans("PaymentTypeShort".$objp->fk_type) : $langs->getLabelFromKey($db, $objp->fk_type, 'c_paiement', 'code', 'libelle', '', 1);
  1410. if ($labeltype == 'SOLD') {
  1411. print '&nbsp;'; //$langs->trans("InitialBankBalance");
  1412. } else {
  1413. print $labeltype;
  1414. }
  1415. print "</td>\n";
  1416. if (!$i) {
  1417. $totalarray['nbfield']++;
  1418. }
  1419. }
  1420. // Num cheque
  1421. if (!empty($arrayfields['b.num_chq']['checked'])) {
  1422. print '<td class="nowrap" align="center">'.($objp->num_chq ? dol_escape_htmltag($objp->num_chq) : "")."</td>\n";
  1423. if (!$i) {
  1424. $totalarray['nbfield']++;
  1425. }
  1426. }
  1427. // Third party
  1428. if (!empty($arrayfields['bu.label']['checked'])) {
  1429. print '<td class="tdoverflowmax150">';
  1430. $companylinked_id = 0;
  1431. $userlinked_id = 0;
  1432. $type_link = "";
  1433. //payment line type to define user display and user or company linked
  1434. foreach ($links as $key => $value) {
  1435. if ($links[$key]['type'] == 'payment_sc') {
  1436. $type_link = 'payment_sc';
  1437. }
  1438. if ($links[$key]['type'] == 'payment_salary') {
  1439. $type_link = 'payment_salary';
  1440. }
  1441. if ($links[$key]['type'] == 'company') {
  1442. $companylinked_id = $links[$key]['url_id'];
  1443. }
  1444. if ($links[$key]['type'] == 'user') {
  1445. $userlinked_id = $links[$key]['url_id'];
  1446. }
  1447. }
  1448. if ($companylinked_id) {
  1449. // TODO Add a cache of loaded companies here ?
  1450. $companystatic->fetch($companylinked_id);
  1451. print $companystatic->getNomUrl(1);
  1452. } elseif ($userlinked_id &&
  1453. (($type_link == 'payment_salary' && !empty($user->rights->salaries->read))
  1454. || ($type_link == 'payment_sc' && !empty($user->rights->tax->charges->lire)))) {
  1455. // Get object user from cache or load it
  1456. if (!empty($conf->cache['user'][$userlinked_id])) {
  1457. $tmpuser = $conf->cache['user'][$userlinked_id];
  1458. } else {
  1459. $tmpuser = new User($db);
  1460. $tmpuser->fetch($userlinked_id);
  1461. $conf->cache['user'][$userlinked_id] = $tmpuser;
  1462. }
  1463. print $tmpuser->getNomUrl(1);
  1464. } else {
  1465. print '&nbsp;';
  1466. }
  1467. print '</td>';
  1468. if (!$i) {
  1469. $totalarray['nbfield']++;
  1470. }
  1471. }
  1472. // Bank account
  1473. if (!empty($arrayfields['ba.ref']['checked'])) {
  1474. print '<td class="nowrap">';
  1475. print $bankaccount->getNomUrl(1);
  1476. print "</td>\n";
  1477. if (!$i) {
  1478. $totalarray['nbfield']++;
  1479. }
  1480. }
  1481. // Debit
  1482. if (!empty($arrayfields['b.debit']['checked'])) {
  1483. print '<td class="nowrap right"><span class="amount">';
  1484. if ($objp->amount < 0) {
  1485. print price($objp->amount * -1);
  1486. $totalarray['totaldeb'] += $objp->amount;
  1487. }
  1488. print "</span></td>\n";
  1489. if (!$i) {
  1490. $totalarray['nbfield']++;
  1491. }
  1492. if (!$i) {
  1493. $totalarray['totaldebfield'] = $totalarray['nbfield'];
  1494. }
  1495. }
  1496. // Credit
  1497. if (!empty($arrayfields['b.credit']['checked'])) {
  1498. print '<td class="nowrap right"><span class="amount">';
  1499. if ($objp->amount > 0) {
  1500. print price($objp->amount);
  1501. $totalarray['totalcred'] += $objp->amount;
  1502. }
  1503. print "</span></td>\n";
  1504. if (!$i) {
  1505. $totalarray['nbfield']++;
  1506. }
  1507. if (!$i) {
  1508. $totalarray['totalcredfield'] = $totalarray['nbfield'];
  1509. }
  1510. }
  1511. // Balance before
  1512. if (!empty($arrayfields['balancebefore']['checked'])) {
  1513. if ($mode_balance_ok) {
  1514. if ($balancebefore >= 0) {
  1515. print '<td class="nowrap right">&nbsp;'.price($balancebefore).'</td>';
  1516. } else {
  1517. print '<td class="error nowrap right">&nbsp;'.price($balancebefore).'</td>';
  1518. }
  1519. } else {
  1520. print '<td class="right">-</td>';
  1521. }
  1522. if (!$i) {
  1523. $totalarray['nbfield']++;
  1524. }
  1525. }
  1526. // Balance after
  1527. if (!empty($arrayfields['balance']['checked'])) {
  1528. if ($mode_balance_ok) {
  1529. if ($balance >= 0) {
  1530. print '<td class="nowrap right">&nbsp;'.price($balance).'</td>';
  1531. } else {
  1532. print '<td class="error nowrap right">&nbsp;'.price($balance).'</td>';
  1533. }
  1534. } else {
  1535. print '<td class="right">-</td>';
  1536. }
  1537. if (!$i) {
  1538. $totalarray['nbfield']++;
  1539. }
  1540. }
  1541. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1542. print '<td class="nowraponall" align="center">';
  1543. // Transaction reconciliated or edit link
  1544. if ($bankaccount->canBeConciliated() > 0) {
  1545. if ($objp->num_releve) {
  1546. print '<a href="releve.php?num='.urlencode($objp->num_releve).'&account='.urlencode($objp->bankid).'&save_lastsearch_values=1">'.dol_escape_htmltag($objp->num_releve).'</a>';
  1547. }
  1548. if (!$objp->conciliated && $action == 'reconcile') {
  1549. if ($objp->num_releve) {
  1550. print '&nbsp;';
  1551. }
  1552. print '<input class="flat" name="rowid['.$objp->rowid.']" type="checkbox" value="'.$objp->rowid.'" size="1"'.(!empty($_POST['rowid'][$objp->rowid]) ? ' checked' : '').'>';
  1553. }
  1554. }
  1555. print '</td>';
  1556. if (!$i) {
  1557. $totalarray['nbfield']++;
  1558. $posconciliatecol = $totalarray['nbfield'];
  1559. }
  1560. }
  1561. if (!empty($arrayfields['b.conciliated']['checked'])) {
  1562. print '<td class="nowraponall" align="center">';
  1563. print yn($objp->conciliated);
  1564. print '</td>';
  1565. if (!$i) {
  1566. $totalarray['nbfield']++;
  1567. }
  1568. }
  1569. if (!empty($arrayfields['b.fk_bordereau']['checked'])) {
  1570. $bordereaustatic->fetch($objp->fk_bordereau);
  1571. print '<td class="nowraponall" align="center">';
  1572. print $bordereaustatic->getNomUrl();
  1573. print '</td>';
  1574. if (!$i) {
  1575. $totalarray['nbfield']++;
  1576. }
  1577. }
  1578. // Action edit/delete and select
  1579. print '<td class="nowraponall" align="center">';
  1580. // Transaction reconciliated or edit link
  1581. if ($objp->conciliated && $bankaccount->canBeConciliated() > 0) { // If line not conciliated and account can be conciliated
  1582. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/compta/bank/line.php?save_lastsearch_values=1&rowid='.$objp->rowid.($object->id > 0 ? '&account='.$object->id : '').'&page='.$page.'">';
  1583. print img_edit();
  1584. print '</a>';
  1585. } else {
  1586. if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
  1587. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/compta/bank/line.php?save_lastsearch_values=1&rowid='.$objp->rowid.($object->id > 0 ? '&account='.$object->id : '').'&page='.$page.'">';
  1588. print img_edit();
  1589. print '</a>';
  1590. } else {
  1591. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/compta/bank/line.php?save_lastsearch_values=1&rowid='.$objp->rowid.($object->id > 0 ? '&account='.$object->id : '').'&page='.$page.'">';
  1592. print img_view();
  1593. print '</a>';
  1594. }
  1595. if ($bankaccount->canBeConciliated() > 0 && empty($objp->conciliated)) {
  1596. if ($db->jdate($objp->dv) < ($now - $conf->bank->rappro->warning_delay)) {
  1597. print ' '.img_warning($langs->trans("ReconciliationLate"));
  1598. }
  1599. }
  1600. if ($user->rights->banque->modifier) {
  1601. print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&rowid='.$objp->rowid.'&page='.$page.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').'">';
  1602. print img_delete('', 'class="marginleftonly"');
  1603. print '</a>';
  1604. }
  1605. }
  1606. // Action column
  1607. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1608. $selected = 0;
  1609. if (in_array($obj->rowid, $arrayofselected)) {
  1610. $selected = 1;
  1611. }
  1612. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1613. }
  1614. print '</td>';
  1615. if (!$i) {
  1616. $totalarray['nbfield']++;
  1617. }
  1618. print "</tr>";
  1619. $i++;
  1620. }
  1621. // Show total line
  1622. if (isset($totalarray['totaldebfield']) || isset($totalarray['totalcredfield'])) {
  1623. print '<tr class="liste_total">';
  1624. $i = 0;
  1625. while ($i < $totalarray['nbfield']) {
  1626. $i++;
  1627. if ($i == 1) {
  1628. if ($num < $limit && empty($offset)) {
  1629. print '<td class="left">'.$langs->trans("Total").'</td>';
  1630. } else {
  1631. print '<td class="left tdoverflowmax50" title="'.$langs->trans("Totalforthispage").'">'.$langs->trans("Totalforthispage").'</td>';
  1632. }
  1633. } elseif ($totalarray['totaldebfield'] == $i) {
  1634. print '<td class="right"><span class="amount">'.price(-1 * $totalarray['totaldeb']).'</span></td>';
  1635. } elseif ($totalarray['totalcredfield'] == $i) {
  1636. print '<td class="right"><span class="amount">'.price($totalarray['totalcred']).'</span></td>';
  1637. } elseif ($i == $posconciliatecol) {
  1638. print '<td class="center">';
  1639. if ($user->rights->banque->consolidate && $action == 'reconcile') {
  1640. print '<input class="button" name="confirm_reconcile" type="submit" value="'.$langs->trans("Conciliate").'">';
  1641. }
  1642. print '</td>';
  1643. } else {
  1644. print '<td></td>';
  1645. }
  1646. }
  1647. print '</tr>';
  1648. }
  1649. // If no record found
  1650. if ($num == 0) {
  1651. $colspan = 1;
  1652. foreach ($arrayfields as $key => $val) {
  1653. if (!empty($val['checked'])) {
  1654. $colspan++;
  1655. }
  1656. }
  1657. print '<tr><td colspan="'.($colspan + 1).'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  1658. }
  1659. print "</table>";
  1660. print "</div>";
  1661. print '</form>';
  1662. $db->free($resql);
  1663. } else {
  1664. dol_print_error($db);
  1665. }
  1666. // End of page
  1667. llxFooter();
  1668. $db->close();