bankentries_list.php 70 KB

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