bankentries_list.php 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831
  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='.((int) $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='.((int) $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 (!getDolGlobalInt('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. $texttoshow = $langs->trans("InputReceiptNumber").': ';
  738. $yyyy = dol_substr($langs->transnoentitiesnoconv("Year"), 0, 1).substr($langs->transnoentitiesnoconv("Year"), 0, 1).substr($langs->transnoentitiesnoconv("Year"), 0, 1).substr($langs->transnoentitiesnoconv("Year"), 0, 1);
  739. $mm = dol_substr($langs->transnoentitiesnoconv("Month"), 0, 1).substr($langs->transnoentitiesnoconv("Month"), 0, 1);
  740. $dd = dol_substr($langs->transnoentitiesnoconv("Day"), 0, 1).substr($langs->transnoentitiesnoconv("Day"), 0, 1);
  741. $placeholder = $yyyy.$mm;
  742. $placeholder .= ' '.$langs->trans("or").' ';
  743. $placeholder .= $yyyy.$mm.$dd;
  744. if (!$placeholder) {
  745. $texttoshow .= $langs->trans("InputReceiptNumberBis");
  746. }
  747. print $texttoshow;
  748. print '<input class="flat width175" pattern="[0-9]+" title="'.dol_escape_htmltag($texttoshow.($placeholder ? ': '.$placeholder : '')).'" id="num_releve" name="num_releve" placeholder="'.dol_escape_htmltag($placeholder).'" type="text" value="'.(GETPOST('num_releve', 'int') ? GETPOST('num_releve', 'int') : '').'">'; // The only default value is value we just entered
  749. print '</div>';
  750. if (is_array($options) && count($options)) {
  751. print $langs->trans("EventualyAddCategory").': ';
  752. print Form::selectarray('cat', $options, GETPOST('cat'), 1);
  753. }
  754. print '<br><div style="margin-top: 5px;"><span class="opacitymedium">'.$langs->trans("ThenCheckLinesAndConciliate").'</span> ';
  755. print '<input class="button" name="confirm_savestatement" type="submit" value="'.$langs->trans("SaveStatementOnly").'">';
  756. print ' '.$langs->trans("or").' ';
  757. print '<input class="button" name="confirm_reconcile" type="submit" value="'.$langs->trans("Conciliate").'">';
  758. print ' '.$langs->trans("or").' ';
  759. print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
  760. print '</div>';
  761. // Show last bank statements
  762. $nbmax = 12; // We show last 12 receipts (so we can have more than one year)
  763. $liste = "";
  764. $sql = "SELECT DISTINCT num_releve FROM ".MAIN_DB_PREFIX."bank";
  765. $sql .= " WHERE fk_account = ".((int) $object->id)." AND num_releve IS NOT NULL";
  766. $sql .= $db->order("num_releve", "DESC");
  767. $sql .= $db->plimit($nbmax + 1);
  768. print '<br>';
  769. print $langs->trans("LastAccountStatements").' : ';
  770. $resqlr = $db->query($sql);
  771. if ($resqlr) {
  772. $numr = $db->num_rows($resqlr);
  773. $i = 0;
  774. $last_ok = 0;
  775. while (($i < $numr) && ($i < $nbmax)) {
  776. $objr = $db->fetch_object($resqlr);
  777. if (!$last_ok) {
  778. $last_releve = $objr->num_releve;
  779. $last_ok = 1;
  780. }
  781. $i++;
  782. $liste = '<a href="'.DOL_URL_ROOT.'/compta/bank/releve.php?account='.$id.'&amp;num='.$objr->num_releve.'">'.$objr->num_releve.'</a> &nbsp; '.$liste;
  783. }
  784. if ($numr >= $nbmax) {
  785. $liste = "... &nbsp; ".$liste;
  786. }
  787. print $liste;
  788. if ($numr <= 0) {
  789. print '<b>'.$langs->trans("None").'</b>';
  790. }
  791. } else {
  792. dol_print_error($db);
  793. }
  794. // Using BANK_REPORT_LAST_NUM_RELEVE to automatically report last num (or not)
  795. if (!empty($conf->global->BANK_REPORT_LAST_NUM_RELEVE)) {
  796. print '
  797. <script type="text/javascript">
  798. $("#num_releve").val("' . $last_releve.'");
  799. </script>
  800. ';
  801. }
  802. print '<br><br>';
  803. }
  804. // Form to add a transaction with no invoice
  805. if (!empty($user->rights->banque->modifier) && $action == 'addline' && !empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) {
  806. print load_fiche_titre($langs->trans("AddBankRecordLong"), '', '');
  807. print '<table class="noborder centpercent">';
  808. print '<tr class="liste_titre">';
  809. print '<td>'.$langs->trans("Description").'</td>';
  810. print '<td>'.$langs->trans("Date").'</td>';
  811. print '<td>&nbsp;</td>';
  812. print '<td>'.$langs->trans("Type").'</td>';
  813. print '<td>'.$langs->trans("Numero").'</td>';
  814. print '<td class=right>'.$langs->trans("BankAccount").'</td>';
  815. print '<td class=right>'.$langs->trans("Debit").'</td>';
  816. print '<td class=right>'.$langs->trans("Credit").'</td>';
  817. /*if (isModEnabled('accounting'))
  818. {
  819. print '<td class="center">';
  820. print $langs->trans("AccountAccounting");
  821. print '</td>';
  822. }*/
  823. print '<td align="center">&nbsp;</td>';
  824. print '</tr>';
  825. print '<tr>';
  826. print '<td>';
  827. print '<input name="label" class="flat minwidth200" type="text" value="'.GETPOST("label", "alpha").'">';
  828. if (is_array($options) && count($options)) {
  829. print '<br>'.$langs->trans("Rubrique").': ';
  830. print Form::selectarray('cat1', $options, GETPOST('cat1'), 1);
  831. }
  832. print '</td>';
  833. print '<td class="nowrap">';
  834. print $form->selectDate(empty($dateop) ?-1 : $dateop, 'op', 0, 0, 0, 'transaction');
  835. print '</td>';
  836. print '<td>&nbsp;</td>';
  837. print '<td class="nowrap">';
  838. $form->select_types_paiements((GETPOST('operation') ?GETPOST('operation') : ($object->courant == Account::TYPE_CASH ? 'LIQ' : '')), 'operation', '1,2', 2, 1);
  839. print '</td>';
  840. print '<td>';
  841. print '<input name="num_chq" class="flat" type="text" size="4" value="'.GETPOST("num_chq", "alpha").'">';
  842. print '</td>';
  843. //if (! $search_account > 0)
  844. //{
  845. print '<td class=right>';
  846. $form->select_comptes(GETPOST('add_account', 'int') ?GETPOST('add_account', 'int') : $search_account, 'add_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''));
  847. print '</td>';
  848. //}
  849. print '<td class="right"><input name="adddebit" class="flat" type="text" size="4" value="'.GETPOST("adddebit", "alpha").'"></td>';
  850. print '<td class="right"><input name="addcredit" class="flat" type="text" size="4" value="'.GETPOST("addcredit", "alpha").'"></td>';
  851. /*if (isModEnabled('accounting'))
  852. {
  853. print '<td class="center">';
  854. print $formaccounting->select_account($search_accountancy_code, 'search_accountancy_code', 1, null, 1, 1, '');
  855. print '</td>';
  856. }*/
  857. print '<td class="center">';
  858. print '<input type="submit" name="save" class="button buttongen marginbottomonly button-add" value="'.$langs->trans("Add").'"><br>';
  859. print '<input type="submit" name="cancel" class="button buttongen marginbottomonly button-cancel" value="'.$langs->trans("Cancel").'">';
  860. print '</td></tr>';
  861. print '</table>';
  862. print '<br>';
  863. }
  864. // Code to adjust value date with plus and less picto using an Ajax call instead of a full reload of page
  865. $urlajax = DOL_URL_ROOT.'/core/ajax/bankconciliate.php?token='.currentToken();
  866. print '
  867. <script type="text/javascript">
  868. $(function() {
  869. $("a.ajaxforbankoperationchange").each(function(){
  870. var current = $(this);
  871. current.click(function()
  872. {
  873. var url = "'.$urlajax.'&"+current.attr("href").split("?")[1];
  874. $.get(url, function(data)
  875. {
  876. console.log(url)
  877. console.log(data)
  878. current.parent().parent().find(".spanforajaxedit").replaceWith(data);
  879. });
  880. return false;
  881. });
  882. });
  883. });
  884. </script>
  885. ';
  886. $i = 0;
  887. // Title
  888. $bankcateg = new BankCateg($db);
  889. $newcardbutton = '';
  890. if ($action != 'addline' && $action != 'reconcile') {
  891. if (empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) {
  892. if (empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) { // Default is to record miscellaneous direct entries using miscellaneous payments
  893. $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);
  894. } else // If direct entries is not done using miscellaneous payments
  895. {
  896. $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&token='.newToken().'&page='.$page.$param, '', $user->rights->banque->modifier);
  897. }
  898. } else {
  899. $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&token='.newToken().'&page='.$page.$param, '', -1);
  900. }
  901. }
  902. $morehtml = '';
  903. /*$morehtml = '<div class="inline-block '.(($buttonreconcile || $newcardbutton) ? 'marginrightonly' : '').'">';
  904. $morehtml .= '<label for="pageplusone">'.$langs->trans("Page")."</label> "; // ' Page ';
  905. $morehtml .= '<input type="text" name="pageplusone" id="pageplusone" class="flat right width25 pageplusone" value="'.($page + 1).'">';
  906. $morehtml .= '/'.$nbtotalofpages.' ';
  907. $morehtml .= '</div>';
  908. */
  909. if ($action != 'addline' && $action != 'reconcile') {
  910. $morehtml .= $buttonreconcile;
  911. }
  912. $morehtml .= '<!-- Add New button -->'.$newcardbutton;
  913. $picto = 'bank_account';
  914. if ($id > 0 || !empty($ref)) {
  915. $picto = '';
  916. }
  917. print_barre_liste($langs->trans("BankTransactions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit, 0, 0, 1);
  918. // We can add page now to param
  919. if ($page != '') {
  920. $param .= '&page='.urlencode($page);
  921. }
  922. $moreforfilter = '';
  923. $moreforfilter .= '<div class="divsearchfield">';
  924. $moreforfilter .= $langs->trans('DateOperationShort');
  925. $moreforfilter .= ($conf->browser->layout == 'phone' ? '<br>' : ' ');
  926. $moreforfilter .= '<div class="nowrap inline-block">';
  927. $moreforfilter .= $form->selectDate($search_dt_start, 'search_start_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  928. $moreforfilter .= '</div>';
  929. $moreforfilter .= ($conf->browser->layout == 'phone' ? '' : ' ');
  930. $moreforfilter .= '<div class="nowrap inline-block">';
  931. $moreforfilter .= $form->selectDate($search_dt_end, 'search_end_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  932. $moreforfilter .= '</div>';
  933. $moreforfilter .= '</div>';
  934. $moreforfilter .= '<div class="divsearchfield">';
  935. $moreforfilter .= $langs->trans('DateValueShort');
  936. $moreforfilter .= ($conf->browser->layout == 'phone' ? '<br>' : ' ');
  937. $moreforfilter .= '<div class="nowrap inline-block">';
  938. $moreforfilter .= $form->selectDate($search_dv_start, 'search_start_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  939. $moreforfilter .= '</div>';
  940. $moreforfilter .= ($conf->browser->layout == 'phone' ? '' : ' ');
  941. $moreforfilter .= '<div class="nowrap inline-block">';
  942. $moreforfilter .= $form->selectDate($search_dv_end, 'search_end_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  943. $moreforfilter .= '</div>';
  944. $moreforfilter .= '</div>';
  945. if (isModEnabled('categorie')) {
  946. // Categories
  947. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  948. $langs->load('categories');
  949. // Bank line
  950. $moreforfilter .= '<div class="divsearchfield">';
  951. $tmptitle = $langs->trans('RubriquesTransactions');
  952. $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, $search_bid, 'parent', null, null, 1);
  953. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_bid', $cate_arbo, $search_bid, $tmptitle, 0, 0, '', 0, 0, 0, '', '', 1);
  954. $moreforfilter .= '</div>';
  955. }
  956. }
  957. $parameters = array();
  958. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  959. if (empty($reshook)) {
  960. $moreforfilter .= $hookmanager->resPrint;
  961. } else {
  962. $moreforfilter = $hookmanager->resPrint;
  963. }
  964. if ($moreforfilter) {
  965. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  966. print $moreforfilter;
  967. print '</div>'."\n";
  968. }
  969. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  970. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  971. // When action is 'reconcile', we force to have the column num_releve always enabled (otherwise we can't make reconciliation).
  972. if ($action == 'reconcile') {
  973. $arrayfields['b.num_releve']['checked'] = 1;
  974. }
  975. print '<div class="div-table-responsive">';
  976. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  977. print '<tr class="liste_titre_filter">';
  978. if (!empty($arrayfields['b.rowid']['checked'])) {
  979. print '<td class="liste_titre">';
  980. print '<input type="text" class="flat" name="search_ref" size="2" value="'.dol_escape_htmltag($search_ref).'">';
  981. print '</td>';
  982. }
  983. if (!empty($arrayfields['b.label']['checked'])) {
  984. print '<td class="liste_titre">';
  985. print '<input type="text" class="flat maxwidth100" name="search_description" value="'.dol_escape_htmltag($search_description).'">';
  986. print '</td>';
  987. }
  988. if (!empty($arrayfields['b.dateo']['checked'])) {
  989. print '<td class="liste_titre">&nbsp;</td>';
  990. }
  991. if (!empty($arrayfields['b.datev']['checked'])) {
  992. print '<td class="liste_titre">&nbsp;</td>';
  993. }
  994. if (!empty($arrayfields['type']['checked'])) {
  995. print '<td class="liste_titre" align="center">';
  996. print $form->select_types_paiements(empty($search_type) ? '' : $search_type, 'search_type', '', 2, 1, 1, 0, 1, 'maxwidth100', 1);
  997. print '</td>';
  998. }
  999. // Numero
  1000. if (!empty($arrayfields['b.num_chq']['checked'])) {
  1001. 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>';
  1002. }
  1003. // Checked
  1004. if (!empty($arrayfields['bu.label']['checked'])) {
  1005. print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_thirdparty" value="'.dol_escape_htmltag($search_thirdparty_user).'"></td>';
  1006. }
  1007. // Ref
  1008. if (!empty($arrayfields['ba.ref']['checked'])) {
  1009. print '<td class="liste_titre">';
  1010. $form->select_comptes($search_account, 'search_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''), 0, 'maxwidth100');
  1011. print '</td>';
  1012. }
  1013. // Debit
  1014. if (!empty($arrayfields['b.debit']['checked'])) {
  1015. print '<td class="liste_titre right">';
  1016. print '<input type="text" class="flat width50" name="search_debit" value="'.dol_escape_htmltag($search_debit).'">';
  1017. print '</td>';
  1018. }
  1019. // Credit
  1020. if (!empty($arrayfields['b.credit']['checked'])) {
  1021. print '<td class="liste_titre right">';
  1022. print '<input type="text" class="flat width50" name="search_credit" value="'.dol_escape_htmltag($search_credit).'">';
  1023. print '</td>';
  1024. }
  1025. // Balance before
  1026. if (!empty($arrayfields['balancebefore']['checked'])) {
  1027. print '<td class="liste_titre right">';
  1028. $htmltext = $langs->trans("BalanceVisibilityDependsOnSortAndFilters", $langs->transnoentitiesnoconv("DateValue"));
  1029. print $form->textwithpicto('', $htmltext, 1);
  1030. print '</td>';
  1031. }
  1032. // Balance
  1033. if (!empty($arrayfields['balance']['checked'])) {
  1034. print '<td class="liste_titre right">';
  1035. $htmltext = $langs->trans("BalanceVisibilityDependsOnSortAndFilters", $langs->transnoentitiesnoconv("DateValue"));
  1036. print $form->textwithpicto('', $htmltext, 1);
  1037. print '</td>';
  1038. }
  1039. // Numero statement
  1040. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1041. 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>';
  1042. }
  1043. // Conciliated
  1044. if (!empty($arrayfields['b.conciliated']['checked'])) {
  1045. print '<td class="liste_titre center parentonrightofpage">';
  1046. print $form->selectyesno('search_conciliated', $search_conciliated, 1, false, 1, 1, 'search_status onrightofpage maxwidth75');
  1047. print '</td>';
  1048. }
  1049. // Bordereau
  1050. if (!empty($arrayfields['b.fk_bordereau']['checked'])) {
  1051. 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>';
  1052. }
  1053. // Actions and select
  1054. print '<td class="liste_titre" align="middle">';
  1055. $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
  1056. print $searchpicto;
  1057. print '</td>';
  1058. print "</tr>\n";
  1059. // Fields title
  1060. print '<tr class="liste_titre">';
  1061. if (!empty($arrayfields['b.rowid']['checked'])) {
  1062. print_liste_field_titre($arrayfields['b.rowid']['label'], $_SERVER['PHP_SELF'], 'b.rowid', '', $param, '', $sortfield, $sortorder);
  1063. }
  1064. if (!empty($arrayfields['b.label']['checked'])) {
  1065. print_liste_field_titre($arrayfields['b.label']['label'], $_SERVER['PHP_SELF'], 'b.label', '', $param, '', $sortfield, $sortorder);
  1066. }
  1067. if (!empty($arrayfields['b.dateo']['checked'])) {
  1068. print_liste_field_titre($arrayfields['b.dateo']['label'], $_SERVER['PHP_SELF'], 'b.dateo', '', $param, '', $sortfield, $sortorder, "center ");
  1069. }
  1070. if (!empty($arrayfields['b.datev']['checked'])) {
  1071. print_liste_field_titre($arrayfields['b.datev']['label'], $_SERVER['PHP_SELF'], 'b.datev,b.dateo,b.rowid', '', $param, 'align="center"', $sortfield, $sortorder);
  1072. }
  1073. if (!empty($arrayfields['type']['checked'])) {
  1074. print_liste_field_titre($arrayfields['type']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'align="center"', $sortfield, $sortorder);
  1075. }
  1076. if (!empty($arrayfields['b.num_chq']['checked'])) {
  1077. print_liste_field_titre($arrayfields['b.num_chq']['label'], $_SERVER['PHP_SELF'], 'b.num_chq', '', $param, '', $sortfield, $sortorder, "center ");
  1078. }
  1079. if (!empty($arrayfields['bu.label']['checked'])) {
  1080. print_liste_field_titre($arrayfields['bu.label']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  1081. }
  1082. if (!empty($arrayfields['ba.ref']['checked'])) {
  1083. print_liste_field_titre($arrayfields['ba.ref']['label'], $_SERVER['PHP_SELF'], 'ba.ref', '', $param, '', $sortfield, $sortorder);
  1084. }
  1085. if (!empty($arrayfields['b.debit']['checked'])) {
  1086. print_liste_field_titre($arrayfields['b.debit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, "right ");
  1087. }
  1088. if (!empty($arrayfields['b.credit']['checked'])) {
  1089. print_liste_field_titre($arrayfields['b.credit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, "right ");
  1090. }
  1091. if (!empty($arrayfields['balancebefore']['checked'])) {
  1092. print_liste_field_titre($arrayfields['balancebefore']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, "right ");
  1093. }
  1094. if (!empty($arrayfields['balance']['checked'])) {
  1095. print_liste_field_titre($arrayfields['balance']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, "right ");
  1096. }
  1097. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1098. print_liste_field_titre($arrayfields['b.num_releve']['label'], $_SERVER['PHP_SELF'], 'b.num_releve', '', $param, '', $sortfield, $sortorder, "center ");
  1099. }
  1100. if (!empty($arrayfields['b.conciliated']['checked'])) {
  1101. print_liste_field_titre($arrayfields['b.conciliated']['label'], $_SERVER['PHP_SELF'], 'b.rappro', '', $param, '', $sortfield, $sortorder, "center ");
  1102. }
  1103. if (!empty($arrayfields['b.fk_bordereau']['checked'])) {
  1104. print_liste_field_titre($arrayfields['b.fk_bordereau']['label'], $_SERVER['PHP_SELF'], 'b.fk_bordereau', '', $param, '', $sortfield, $sortorder, "center ");
  1105. }
  1106. // Extra fields
  1107. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1108. // Hook fields
  1109. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1110. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1111. print $hookmanager->resPrint;
  1112. // Actions and select
  1113. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  1114. print "</tr>\n";
  1115. $balance = 0; // For balance
  1116. $balancebefore = 0; // For balance
  1117. $balancecalculated = false;
  1118. $posconciliatecol = 0;
  1119. $cachebankaccount = array();
  1120. // Loop on each record
  1121. $sign = 1;
  1122. while ($i < min($num, $limit)) {
  1123. $objp = $db->fetch_object($resql);
  1124. $links = $bankaccountstatic->get_url($objp->rowid);
  1125. // If we are in a situation where we need/can show balance, we calculate the start of balance
  1126. if (!$balancecalculated && (!empty($arrayfields['balancebefore']['checked']) || !empty($arrayfields['balance']['checked'])) && ($mode_balance_ok || $search_conciliated === '0')) {
  1127. if (!$search_account) {
  1128. dol_print_error('', 'account is not defined but $mode_balance_ok is true');
  1129. exit;
  1130. }
  1131. // Loop on each record before
  1132. $sign = 1;
  1133. $i = 0;
  1134. $sqlforbalance = 'SELECT SUM(b.amount) as previoustotal';
  1135. $sqlforbalance .= " FROM ";
  1136. $sqlforbalance .= " ".MAIN_DB_PREFIX."bank_account as ba,";
  1137. $sqlforbalance .= " ".MAIN_DB_PREFIX."bank as b";
  1138. $sqlforbalance .= " WHERE b.fk_account = ba.rowid";
  1139. $sqlforbalance .= " AND ba.entity IN (".getEntity('bank_account').")";
  1140. $sqlforbalance .= " AND b.fk_account = ".((int) $search_account);
  1141. $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."))))";
  1142. $resqlforbalance = $db->query($sqlforbalance);
  1143. //print $sqlforbalance;
  1144. if ($resqlforbalance) {
  1145. $objforbalance = $db->fetch_object($resqlforbalance);
  1146. if ($objforbalance) {
  1147. // If sort is desc,desc,desc then total of previous date + amount is the balancebefore of the previous line before the line to show
  1148. if ($sortfield == 'b.datev,b.dateo,b.rowid' && ($sortorder == 'desc' || $sortorder == 'desc,desc' || $sortorder == 'desc,desc,desc')) {
  1149. $balancebefore = $objforbalance->previoustotal + ($sign * $objp->amount);
  1150. } else {
  1151. // If sort is asc,asc,asc then total of previous date is balance of line before the next line to show
  1152. $balance = $objforbalance->previoustotal;
  1153. }
  1154. }
  1155. } else {
  1156. dol_print_error($db);
  1157. }
  1158. $balancecalculated = true;
  1159. // Output a line with start balance
  1160. if ($user->rights->banque->consolidate && $action == 'reconcile') {
  1161. $tmpnbfieldbeforebalance = 0;
  1162. $tmpnbfieldafterbalance = 0;
  1163. $balancefieldfound = 0;
  1164. foreach ($arrayfields as $key => $val) {
  1165. if ($key == 'balancebefore' || $key == 'balance') {
  1166. $balancefieldfound++;
  1167. continue;
  1168. }
  1169. if (!empty($arrayfields[$key]['checked'])) {
  1170. if (!$balancefieldfound) {
  1171. $tmpnbfieldbeforebalance++;
  1172. } else {
  1173. $tmpnbfieldafterbalance++;
  1174. }
  1175. }
  1176. }
  1177. // Extra fields
  1178. $element = 'banktransaction';
  1179. if (!empty($extrafields->attributes[$element]['label']) && is_array($extrafields->attributes[$element]['label']) && count($extrafields->attributes[$element]['label'])) {
  1180. foreach ($extrafields->attributes[$element]['label'] as $key => $val) {
  1181. if (!empty($arrayfields["ef.".$key]['checked'])) {
  1182. if (!empty($arrayfields[$key]['checked'])) {
  1183. if (!$balancefieldfound) {
  1184. $tmpnbfieldbeforebalance++;
  1185. } else {
  1186. $tmpnbfieldafterbalance++;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. }
  1192. print '<tr class="oddeven trforbreak">';
  1193. if ($tmpnbfieldbeforebalance) {
  1194. print '<td colspan="'.$tmpnbfieldbeforebalance.'">';
  1195. print '&nbsp;';
  1196. print '</td>';
  1197. }
  1198. if (!empty($arrayfields['balancebefore']['checked'])) {
  1199. print '<td class="right">';
  1200. if ($search_conciliated !== '0') {
  1201. print price(price2num($balance, 'MT'), 1, $langs);
  1202. }
  1203. print '</td>';
  1204. }
  1205. if (!empty($arrayfields['balance']['checked'])) {
  1206. print '<td class="right">';
  1207. if ($search_conciliated !== '0') {
  1208. print price(price2num($balance, 'MT'), 1, $langs);
  1209. }
  1210. print '</td>';
  1211. }
  1212. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1213. print '<td class="center">';
  1214. print '<input type="checkbox" id="selectAll" title="'.dol_escape_htmltag($langs->trans("SelectAll")).'" />';
  1215. print ' <script type="text/javascript">
  1216. $("input#selectAll").change(function() {
  1217. $("input[type=checkbox][name^=rowid]").prop("checked", $(this).is(":checked"));
  1218. });
  1219. </script>';
  1220. print '</td>';
  1221. }
  1222. print '<td colspan="'.($tmpnbfieldafterbalance + 1).'">';
  1223. print '&nbsp;';
  1224. print '</td>';
  1225. print '</tr>';
  1226. }
  1227. }
  1228. if ($sortfield == 'b.datev,b.dateo,b.rowid' && ($sortorder == 'desc' || $sortorder == 'desc,desc' || $sortorder == 'desc,desc,desc')) {
  1229. $balance = price2num($balancebefore, 'MT'); // balance = balancebefore of previous line (sort is desc)
  1230. $balancebefore = price2num($balancebefore - ($sign * $objp->amount), 'MT');
  1231. } else {
  1232. $balancebefore = price2num($balance, 'MT'); // balancebefore = balance of previous line (sort is asc)
  1233. $balance = price2num($balance + ($sign * $objp->amount), 'MT');
  1234. }
  1235. if (empty($cachebankaccount[$objp->bankid])) {
  1236. $bankaccounttmp = new Account($db);
  1237. $bankaccounttmp->fetch($objp->bankid);
  1238. $cachebankaccount[$objp->bankid] = $bankaccounttmp;
  1239. $bankaccount = $bankaccounttmp;
  1240. } else {
  1241. $bankaccount = $cachebankaccount[$objp->bankid];
  1242. }
  1243. if (empty($conf->global->BANK_COLORIZE_MOVEMENT)) {
  1244. $backgroundcolor = "class='oddeven'";
  1245. } else {
  1246. if ($objp->amount < 0) {
  1247. $color = '#' . getDolGlobalString('BANK_COLORIZE_MOVEMENT_COLOR1', 'fca955');
  1248. $backgroundcolor = 'style="background: '.$color.';"';
  1249. } else {
  1250. $color = '#' . getDolGlobalString('BANK_COLORIZE_MOVEMENT_COLOR2', '7fdb86');
  1251. $backgroundcolor = 'style="background: '.$color.';"';
  1252. }
  1253. }
  1254. $banklinestatic->id = $objp->rowid;
  1255. $banklinestatic->ref = $objp->rowid;
  1256. print '<tr class="oddeven" '.$backgroundcolor.'>';
  1257. // Ref
  1258. if (!empty($arrayfields['b.rowid']['checked'])) {
  1259. print '<td class="nowrap left">';
  1260. print $banklinestatic->getNomUrl(1);
  1261. print '</td>';
  1262. if (!$i) {
  1263. $totalarray['nbfield']++;
  1264. }
  1265. }
  1266. // Description
  1267. if (!empty($arrayfields['b.label']['checked'])) {
  1268. $labeltoshow = '';
  1269. $titletoshow = '';
  1270. $reg = array();
  1271. preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthee on tente recherche de traduction
  1272. if (!empty($reg[1]) && $langs->trans($reg[1]) != $reg[1]) {
  1273. $labeltoshow = $langs->trans($reg[1]);
  1274. } else {
  1275. if ($objp->label == '(payment_salary)') {
  1276. $labeltoshow = $langs->trans("SalaryPayment");
  1277. } else {
  1278. $labeltoshow = dol_escape_htmltag($objp->label);
  1279. $titletoshow = $objp->label;
  1280. }
  1281. }
  1282. print '<td class="tdoverflowmax250"'.($titletoshow ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>';
  1283. // Add info about links after description
  1284. $cachebankaccount = array();
  1285. foreach ($links as $key => $val) {
  1286. print '<!-- '.$links[$key]['type'].' -->';
  1287. if ($links[$key]['type'] == 'withdraw') {
  1288. $banktransferstatic->id = $links[$key]['url_id'];
  1289. $banktransferstatic->ref = $links[$key]['label'];
  1290. print $banktransferstatic->getNomUrl(0).' ';
  1291. } elseif ($links[$key]['type'] == 'payment') {
  1292. $paymentstatic->id = $links[$key]['url_id'];
  1293. $paymentstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment
  1294. $paymentstatic->date = $db->jdate($objp->do);
  1295. print $paymentstatic->getNomUrl(2).' ';
  1296. } elseif ($links[$key]['type'] == 'payment_supplier') {
  1297. $paymentsupplierstatic->id = $links[$key]['url_id'];
  1298. $paymentsupplierstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment
  1299. print $paymentsupplierstatic->getNomUrl(2).' ';
  1300. } elseif ($links[$key]['type'] == 'payment_sc') {
  1301. $paymentscstatic->id = $links[$key]['url_id'];
  1302. $paymentscstatic->ref = $links[$key]['url_id'];
  1303. $paymentscstatic->label = $links[$key]['label'];
  1304. print $paymentscstatic->getNomUrl(2).' ';
  1305. } elseif ($links[$key]['type'] == 'payment_vat') {
  1306. $paymentvatstatic->id = $links[$key]['url_id'];
  1307. $paymentvatstatic->ref = $links[$key]['url_id'];
  1308. print $paymentvatstatic->getNomUrl(2).' ';
  1309. } elseif ($links[$key]['type'] == 'payment_salary') {
  1310. $paymentsalstatic->id = $links[$key]['url_id'];
  1311. $paymentsalstatic->ref = $links[$key]['url_id'];
  1312. $paymentsalstatic->label = $links[$key]['label'];
  1313. print $paymentsalstatic->getNomUrl(2).' ';
  1314. } elseif ($links[$key]['type'] == 'payment_loan') {
  1315. print '<a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$links[$key]['url_id'].'">';
  1316. print ' '.img_object($langs->trans('ShowPayment'), 'payment').' ';
  1317. print '</a> ';
  1318. } elseif ($links[$key]['type'] == 'payment_donation') {
  1319. $paymentdonationstatic->id = $links[$key]['url_id'];
  1320. $paymentdonationstatic->ref = $links[$key]['url_id'];
  1321. print $paymentdonationstatic->getNomUrl(2).' ';
  1322. } elseif ($links[$key]['type'] == 'payment_expensereport') {
  1323. $paymentexpensereportstatic->id = $links[$key]['url_id'];
  1324. $paymentexpensereportstatic->ref = $links[$key]['url_id'];
  1325. print $paymentexpensereportstatic->getNomUrl(2).' ';
  1326. } elseif ($links[$key]['type'] == 'payment_various') {
  1327. $paymentvariousstatic->id = $links[$key]['url_id'];
  1328. $paymentvariousstatic->ref = $links[$key]['url_id'];
  1329. print $paymentvariousstatic->getNomUrl(2).' ';
  1330. } elseif ($links[$key]['type'] == 'banktransfert') {
  1331. // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
  1332. if ($objp->amount > 0) {
  1333. $banklinestatic->fetch($links[$key]['url_id']);
  1334. $bankstatic->id = $banklinestatic->fk_account;
  1335. $bankstatic->label = $banklinestatic->bank_account_ref;
  1336. print $langs->trans("TransferFrom").' ';
  1337. print $bankstatic->getNomUrl(1, 'transactions');
  1338. print ' '.$langs->trans("toward").' ';
  1339. $bankstatic->id = $objp->bankid;
  1340. $bankstatic->label = $objp->bankref;
  1341. print $bankstatic->getNomUrl(1, '');
  1342. print ' - ';
  1343. } else {
  1344. $bankstatic->id = $objp->bankid;
  1345. $bankstatic->label = $objp->bankref;
  1346. print $langs->trans("TransferFrom").' ';
  1347. print $bankstatic->getNomUrl(1, '');
  1348. print ' '.$langs->trans("toward").' ';
  1349. $banklinestatic->fetch($links[$key]['url_id']);
  1350. $bankstatic->id = $banklinestatic->fk_account;
  1351. $bankstatic->label = $banklinestatic->bank_account_ref;
  1352. print $bankstatic->getNomUrl(1, 'transactions');
  1353. print ' - ';
  1354. }
  1355. //var_dump($links);
  1356. } elseif ($links[$key]['type'] == 'company') {
  1357. } elseif ($links[$key]['type'] == 'user') {
  1358. } elseif ($links[$key]['type'] == 'member') {
  1359. } elseif ($links[$key]['type'] == 'sc') {
  1360. } elseif ($links[$key]['type'] == 'vat') {
  1361. } elseif ($links[$key]['type'] == 'salary') {
  1362. // Information is already shown using the payment_salary link. No need of this link.
  1363. } else {
  1364. // Show link with label $links[$key]['label']
  1365. print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
  1366. if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
  1367. // Label generique car entre parentheses. On l'affiche en le traduisant
  1368. if ($reg[1] == 'paiement') {
  1369. $reg[1] = 'Payment';
  1370. }
  1371. print $langs->trans($reg[1]);
  1372. } else {
  1373. print $links[$key]['label'];
  1374. }
  1375. print '</a>'.($labeltoshow ? ' - ' : '');
  1376. }
  1377. }
  1378. print $labeltoshow; // Already escaped
  1379. print '</td>';
  1380. if (!$i) {
  1381. $totalarray['nbfield']++;
  1382. }
  1383. }
  1384. // Date ope
  1385. if (!empty($arrayfields['b.dateo']['checked'])) {
  1386. print '<td align="center" class="nowrap">';
  1387. print '<span class="spanforajaxedit" id="dateoperation_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->do), "day")."</span>";
  1388. print '&nbsp;';
  1389. print '<span class="inline-block">';
  1390. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=doprev&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1391. print img_edit_remove()."</a> ";
  1392. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=donext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1393. print img_edit_add()."</a>";
  1394. print '</span>';
  1395. print "</td>\n";
  1396. if (!$i) {
  1397. $totalarray['nbfield']++;
  1398. }
  1399. }
  1400. // Date value
  1401. if (!empty($arrayfields['b.datev']['checked'])) {
  1402. print '<td align="center" class="nowrap">';
  1403. print '<span class="spanforajaxedit" id="datevalue_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->dv), "day")."</span>";
  1404. print '&nbsp;';
  1405. print '<span class="inline-block">';
  1406. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=dvprev&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1407. print img_edit_remove()."</a> ";
  1408. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1409. print img_edit_add()."</a>";
  1410. print '</span>';
  1411. print "</td>\n";
  1412. if (!$i) {
  1413. $totalarray['nbfield']++;
  1414. }
  1415. }
  1416. // Payment type
  1417. if (!empty($arrayfields['type']['checked'])) {
  1418. print '<td class="tdoverflowmax100 center">';
  1419. $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);
  1420. if ($labeltype == 'SOLD') {
  1421. print '&nbsp;'; //$langs->trans("InitialBankBalance");
  1422. } else {
  1423. print $labeltype;
  1424. }
  1425. print "</td>\n";
  1426. if (!$i) {
  1427. $totalarray['nbfield']++;
  1428. }
  1429. }
  1430. // Num cheque
  1431. if (!empty($arrayfields['b.num_chq']['checked'])) {
  1432. print '<td class="nowrap" align="center">'.($objp->num_chq ? dol_escape_htmltag($objp->num_chq) : "")."</td>\n";
  1433. if (!$i) {
  1434. $totalarray['nbfield']++;
  1435. }
  1436. }
  1437. // Third party
  1438. if (!empty($arrayfields['bu.label']['checked'])) {
  1439. print '<td class="tdoverflowmax150">';
  1440. $companylinked_id = 0;
  1441. $userlinked_id = 0;
  1442. $type_link = "";
  1443. //payment line type to define user display and user or company linked
  1444. foreach ($links as $key => $value) {
  1445. if ($links[$key]['type'] == 'payment_sc') {
  1446. $type_link = 'payment_sc';
  1447. }
  1448. if ($links[$key]['type'] == 'payment_salary') {
  1449. $type_link = 'payment_salary';
  1450. }
  1451. if ($links[$key]['type'] == 'company') {
  1452. $companylinked_id = $links[$key]['url_id'];
  1453. }
  1454. if ($links[$key]['type'] == 'user') {
  1455. $userlinked_id = $links[$key]['url_id'];
  1456. }
  1457. }
  1458. if ($companylinked_id) {
  1459. // TODO Add a cache of loaded companies here ?
  1460. $companystatic->fetch($companylinked_id);
  1461. print $companystatic->getNomUrl(1);
  1462. } elseif ($userlinked_id &&
  1463. (($type_link == 'payment_salary' && !empty($user->rights->salaries->read))
  1464. || ($type_link == 'payment_sc' && !empty($user->rights->tax->charges->lire)))) {
  1465. // Get object user from cache or load it
  1466. if (!empty($conf->cache['user'][$userlinked_id])) {
  1467. $tmpuser = $conf->cache['user'][$userlinked_id];
  1468. } else {
  1469. $tmpuser = new User($db);
  1470. $tmpuser->fetch($userlinked_id);
  1471. $conf->cache['user'][$userlinked_id] = $tmpuser;
  1472. }
  1473. print $tmpuser->getNomUrl(1);
  1474. } else {
  1475. print '&nbsp;';
  1476. }
  1477. print '</td>';
  1478. if (!$i) {
  1479. $totalarray['nbfield']++;
  1480. }
  1481. }
  1482. // Bank account
  1483. if (!empty($arrayfields['ba.ref']['checked'])) {
  1484. print '<td class="nowrap">';
  1485. print $bankaccount->getNomUrl(1);
  1486. print "</td>\n";
  1487. if (!$i) {
  1488. $totalarray['nbfield']++;
  1489. }
  1490. }
  1491. // Debit
  1492. if (!empty($arrayfields['b.debit']['checked'])) {
  1493. print '<td class="nowrap right"><span class="amount">';
  1494. if ($objp->amount < 0) {
  1495. print price($objp->amount * -1);
  1496. $totalarray['totaldeb'] += $objp->amount;
  1497. }
  1498. print "</span></td>\n";
  1499. if (!$i) {
  1500. $totalarray['nbfield']++;
  1501. }
  1502. if (!$i) {
  1503. $totalarray['totaldebfield'] = $totalarray['nbfield'];
  1504. }
  1505. }
  1506. // Credit
  1507. if (!empty($arrayfields['b.credit']['checked'])) {
  1508. print '<td class="nowrap right"><span class="amount">';
  1509. if ($objp->amount > 0) {
  1510. print price($objp->amount);
  1511. $totalarray['totalcred'] += $objp->amount;
  1512. }
  1513. print "</span></td>\n";
  1514. if (!$i) {
  1515. $totalarray['nbfield']++;
  1516. }
  1517. if (!$i) {
  1518. $totalarray['totalcredfield'] = $totalarray['nbfield'];
  1519. }
  1520. }
  1521. // Balance before
  1522. if (!empty($arrayfields['balancebefore']['checked'])) {
  1523. if ($mode_balance_ok) {
  1524. if ($balancebefore >= 0) {
  1525. print '<td class="nowrap right">&nbsp;'.price($balancebefore).'</td>';
  1526. } else {
  1527. print '<td class="error nowrap right">&nbsp;'.price($balancebefore).'</td>';
  1528. }
  1529. } else {
  1530. print '<td class="right">-</td>';
  1531. }
  1532. if (!$i) {
  1533. $totalarray['nbfield']++;
  1534. }
  1535. }
  1536. // Balance after
  1537. if (!empty($arrayfields['balance']['checked'])) {
  1538. if ($mode_balance_ok) {
  1539. if ($balance >= 0) {
  1540. print '<td class="nowrap right">&nbsp;'.price($balance).'</td>';
  1541. } else {
  1542. print '<td class="error nowrap right">&nbsp;'.price($balance).'</td>';
  1543. }
  1544. } else {
  1545. print '<td class="right">-</td>';
  1546. }
  1547. if (!$i) {
  1548. $totalarray['nbfield']++;
  1549. }
  1550. }
  1551. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1552. print '<td class="nowraponall" align="center">';
  1553. // Transaction reconciliated or edit link
  1554. if ($bankaccount->canBeConciliated() > 0) {
  1555. if ($objp->num_releve) {
  1556. 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>';
  1557. }
  1558. if (!$objp->conciliated && $action == 'reconcile') {
  1559. if ($objp->num_releve) {
  1560. print '&nbsp;';
  1561. }
  1562. print '<input class="flat" name="rowid['.$objp->rowid.']" type="checkbox" value="'.$objp->rowid.'" size="1"'.(!empty($_POST['rowid'][$objp->rowid]) ? ' checked' : '').'>';
  1563. }
  1564. }
  1565. print '</td>';
  1566. if (!$i) {
  1567. $totalarray['nbfield']++;
  1568. $posconciliatecol = $totalarray['nbfield'];
  1569. }
  1570. }
  1571. if (!empty($arrayfields['b.conciliated']['checked'])) {
  1572. print '<td class="nowraponall" align="center">';
  1573. print yn($objp->conciliated);
  1574. print '</td>';
  1575. if (!$i) {
  1576. $totalarray['nbfield']++;
  1577. }
  1578. }
  1579. if (!empty($arrayfields['b.fk_bordereau']['checked'])) {
  1580. $bordereaustatic->fetch($objp->fk_bordereau);
  1581. print '<td class="nowraponall" align="center">';
  1582. print $bordereaustatic->getNomUrl();
  1583. print '</td>';
  1584. if (!$i) {
  1585. $totalarray['nbfield']++;
  1586. }
  1587. }
  1588. // Action edit/delete and select
  1589. print '<td class="nowraponall" align="center">';
  1590. // Transaction reconciliated or edit link
  1591. if ($objp->conciliated && $bankaccount->canBeConciliated() > 0) { // If line not conciliated and account can be conciliated
  1592. 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.'">';
  1593. print img_edit();
  1594. print '</a>';
  1595. } else {
  1596. if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
  1597. 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.'">';
  1598. print img_edit();
  1599. print '</a>';
  1600. } else {
  1601. 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.'">';
  1602. print img_view();
  1603. print '</a>';
  1604. }
  1605. if ($bankaccount->canBeConciliated() > 0 && empty($objp->conciliated)) {
  1606. if ($db->jdate($objp->dv) < ($now - $conf->bank->rappro->warning_delay)) {
  1607. print ' '.img_warning($langs->trans("ReconciliationLate"));
  1608. }
  1609. }
  1610. if ($user->rights->banque->modifier) {
  1611. print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&rowid='.$objp->rowid.'&page='.$page.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').'">';
  1612. print img_delete('', 'class="marginleftonly"');
  1613. print '</a>';
  1614. }
  1615. }
  1616. // Action column
  1617. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1618. $selected = 0;
  1619. if (in_array($obj->rowid, $arrayofselected)) {
  1620. $selected = 1;
  1621. }
  1622. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1623. }
  1624. print '</td>';
  1625. if (!$i) {
  1626. $totalarray['nbfield']++;
  1627. }
  1628. print "</tr>";
  1629. $i++;
  1630. }
  1631. // Show total line
  1632. if (isset($totalarray['totaldebfield']) || isset($totalarray['totalcredfield'])) {
  1633. print '<tr class="liste_total">';
  1634. $i = 0;
  1635. while ($i < $totalarray['nbfield']) {
  1636. $i++;
  1637. if ($i == 1) {
  1638. if ($num < $limit && empty($offset)) {
  1639. print '<td class="left">'.$langs->trans("Total").'</td>';
  1640. } else {
  1641. print '<td class="left tdoverflowmax50" title="'.$langs->trans("Totalforthispage").'">'.$langs->trans("Totalforthispage").'</td>';
  1642. }
  1643. } elseif ($totalarray['totaldebfield'] == $i) {
  1644. print '<td class="right"><span class="amount">'.price(-1 * $totalarray['totaldeb']).'</span></td>';
  1645. } elseif ($totalarray['totalcredfield'] == $i) {
  1646. print '<td class="right"><span class="amount">'.price($totalarray['totalcred']).'</span></td>';
  1647. } elseif ($i == $posconciliatecol) {
  1648. print '<td class="center">';
  1649. if ($user->rights->banque->consolidate && $action == 'reconcile') {
  1650. print '<input class="button" name="confirm_reconcile" type="submit" value="'.$langs->trans("Conciliate").'">';
  1651. }
  1652. print '</td>';
  1653. } else {
  1654. print '<td></td>';
  1655. }
  1656. }
  1657. print '</tr>';
  1658. }
  1659. // If no record found
  1660. if ($num == 0) {
  1661. $colspan = 1;
  1662. foreach ($arrayfields as $key => $val) {
  1663. if (!empty($val['checked'])) {
  1664. $colspan++;
  1665. }
  1666. }
  1667. print '<tr><td colspan="'.($colspan + 1).'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  1668. }
  1669. print "</table>";
  1670. print "</div>";
  1671. print '</form>';
  1672. $db->free($resql);
  1673. } else {
  1674. dol_print_error($db);
  1675. }
  1676. // End of page
  1677. llxFooter();
  1678. $db->close();