bankentries_list.php 70 KB

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