bankentries_list.php 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764
  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("Conciliated"), '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&amp;sortorder=asc,asc,asc&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&amp;sortorder=asc,asc,asc&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')).'</div>';
  895. //$moreforfilter .= ' - ';
  896. $moreforfilter .= '<div class="nowrap inline-block">'.$form->selectDate($search_dt_end, 'search_end_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')).'</div>';
  897. $moreforfilter .= '</div>';
  898. $moreforfilter .= '<div class="divsearchfield">';
  899. $moreforfilter .= $langs->trans('DateValueShort').' ';
  900. $moreforfilter .= ($conf->browser->layout == 'phone' ? '<br>' : ' ');
  901. $moreforfilter .= '<div class="nowrap inline-block">';
  902. $moreforfilter .= $form->selectDate($search_dv_start, 'search_start_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')).'</div>';
  903. //$moreforfilter .= ' - ';
  904. $moreforfilter .= '<div class="nowrap inline-block">'.$form->selectDate($search_dv_end, 'search_end_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')).'</div>';
  905. $moreforfilter .= '</div>';
  906. if (!empty($conf->categorie->enabled)) {
  907. // Categories
  908. if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
  909. $langs->load('categories');
  910. // Bank line
  911. $moreforfilter .= '<div class="divsearchfield">';
  912. $tmptitle = $langs->trans('RubriquesTransactions');
  913. $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, $search_bid, 'parent', null, null, 1);
  914. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_bid', $cate_arbo, $search_bid, $tmptitle, 0, 0, '', 0, 0, 0, '', '', 1);
  915. $moreforfilter .= '</div>';
  916. }
  917. }
  918. $parameters = array();
  919. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  920. if (empty($reshook)) {
  921. $moreforfilter .= $hookmanager->resPrint;
  922. } else {
  923. $moreforfilter = $hookmanager->resPrint;
  924. }
  925. if ($moreforfilter) {
  926. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  927. print $moreforfilter;
  928. print '</div>'."\n";
  929. }
  930. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  931. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  932. // When action is 'reconcile', we force to have the column num_releve always enabled (otherwise we can't make reconciliation).
  933. if ($action == 'reconcile') {
  934. $arrayfields['b.num_releve']['checked'] = 1;
  935. }
  936. print '<div class="div-table-responsive">';
  937. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  938. print '<tr class="liste_titre_filter">';
  939. if (!empty($arrayfields['b.rowid']['checked'])) {
  940. print '<td class="liste_titre">';
  941. print '<input type="text" class="flat" name="search_ref" size="2" value="'.dol_escape_htmltag($search_ref).'">';
  942. print '</td>';
  943. }
  944. if (!empty($arrayfields['b.label']['checked'])) {
  945. print '<td class="liste_titre">';
  946. print '<input type="text" class="flat maxwidth100" name="search_description" value="'.dol_escape_htmltag($search_description).'">';
  947. print '</td>';
  948. }
  949. if (!empty($arrayfields['b.dateo']['checked'])) {
  950. print '<td class="liste_titre">&nbsp;</td>';
  951. }
  952. if (!empty($arrayfields['b.datev']['checked'])) {
  953. print '<td class="liste_titre">&nbsp;</td>';
  954. }
  955. if (!empty($arrayfields['type']['checked'])) {
  956. print '<td class="liste_titre" align="center">';
  957. $form->select_types_paiements(empty($search_type) ? '' : $search_type, 'search_type', '', 2, 1, 1, 0, 1, 'maxwidth100');
  958. print '</td>';
  959. }
  960. if (!empty($arrayfields['b.num_chq']['checked'])) {
  961. // Numero
  962. 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>';
  963. }
  964. if (!empty($arrayfields['bu.label']['checked'])) {
  965. print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_thirdparty" value="'.dol_escape_htmltag($search_thirdparty_user).'"></td>';
  966. }
  967. if (!empty($arrayfields['ba.ref']['checked'])) {
  968. print '<td class="liste_titre">';
  969. $form->select_comptes($search_account, 'search_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''), 0, 'maxwidth100');
  970. print '</td>';
  971. }
  972. if (!empty($arrayfields['b.debit']['checked'])) {
  973. print '<td class="liste_titre right">';
  974. print '<input type="text" class="flat width50" name="search_debit" value="'.dol_escape_htmltag($search_debit).'">';
  975. print '</td>';
  976. }
  977. if (!empty($arrayfields['b.credit']['checked'])) {
  978. print '<td class="liste_titre right">';
  979. print '<input type="text" class="flat width50" name="search_credit" value="'.dol_escape_htmltag($search_credit).'">';
  980. print '</td>';
  981. }
  982. if (!empty($arrayfields['balancebefore']['checked'])) {
  983. print '<td class="liste_titre right">';
  984. $htmltext = $langs->trans("BalanceVisibilityDependsOnSortAndFilters", $langs->transnoentitiesnoconv("DateValue"));
  985. print $form->textwithpicto('', $htmltext, 1);
  986. print '</td>';
  987. }
  988. if (!empty($arrayfields['balance']['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. // Numero statement
  995. if (!empty($arrayfields['b.num_releve']['checked'])) {
  996. 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>';
  997. }
  998. // Conciliated
  999. if (!empty($arrayfields['b.conciliated']['checked'])) {
  1000. print '<td class="liste_titre" align="center">';
  1001. print $form->selectyesno('search_conciliated', $search_conciliated, 1, false, 1, 1);
  1002. print '</td>';
  1003. }
  1004. // Actions and select
  1005. print '<td class="liste_titre" align="middle">';
  1006. $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
  1007. print $searchpicto;
  1008. print '</td>';
  1009. print "</tr>\n";
  1010. // Fields title
  1011. print '<tr class="liste_titre">';
  1012. if (!empty($arrayfields['b.rowid']['checked'])) {
  1013. print_liste_field_titre($arrayfields['b.rowid']['label'], $_SERVER['PHP_SELF'], 'b.rowid', '', $param, '', $sortfield, $sortorder);
  1014. }
  1015. if (!empty($arrayfields['b.label']['checked'])) {
  1016. print_liste_field_titre($arrayfields['b.label']['label'], $_SERVER['PHP_SELF'], 'b.label', '', $param, '', $sortfield, $sortorder);
  1017. }
  1018. if (!empty($arrayfields['b.dateo']['checked'])) {
  1019. print_liste_field_titre($arrayfields['b.dateo']['label'], $_SERVER['PHP_SELF'], 'b.dateo', '', $param, '', $sortfield, $sortorder, "center ");
  1020. }
  1021. if (!empty($arrayfields['b.datev']['checked'])) {
  1022. print_liste_field_titre($arrayfields['b.datev']['label'], $_SERVER['PHP_SELF'], 'b.datev,b.dateo,b.rowid', '', $param, 'align="center"', $sortfield, $sortorder);
  1023. }
  1024. if (!empty($arrayfields['type']['checked'])) {
  1025. print_liste_field_titre($arrayfields['type']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'align="center"', $sortfield, $sortorder);
  1026. }
  1027. if (!empty($arrayfields['b.num_chq']['checked'])) {
  1028. print_liste_field_titre($arrayfields['b.num_chq']['label'], $_SERVER['PHP_SELF'], 'b.num_chq', '', $param, '', $sortfield, $sortorder, "center ");
  1029. }
  1030. if (!empty($arrayfields['bu.label']['checked'])) {
  1031. print_liste_field_titre($arrayfields['bu.label']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  1032. }
  1033. if (!empty($arrayfields['ba.ref']['checked'])) {
  1034. print_liste_field_titre($arrayfields['ba.ref']['label'], $_SERVER['PHP_SELF'], 'ba.ref', '', $param, '', $sortfield, $sortorder);
  1035. }
  1036. if (!empty($arrayfields['b.debit']['checked'])) {
  1037. print_liste_field_titre($arrayfields['b.debit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, "right ");
  1038. }
  1039. if (!empty($arrayfields['b.credit']['checked'])) {
  1040. print_liste_field_titre($arrayfields['b.credit']['label'], $_SERVER['PHP_SELF'], 'b.amount', '', $param, '', $sortfield, $sortorder, "right ");
  1041. }
  1042. if (!empty($arrayfields['balancebefore']['checked'])) {
  1043. print_liste_field_titre($arrayfields['balancebefore']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, "right ");
  1044. }
  1045. if (!empty($arrayfields['balance']['checked'])) {
  1046. print_liste_field_titre($arrayfields['balance']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, "right ");
  1047. }
  1048. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1049. print_liste_field_titre($arrayfields['b.num_releve']['label'], $_SERVER['PHP_SELF'], 'b.num_releve', '', $param, '', $sortfield, $sortorder, "center ");
  1050. }
  1051. if (!empty($arrayfields['b.conciliated']['checked'])) {
  1052. print_liste_field_titre($arrayfields['b.conciliated']['label'], $_SERVER['PHP_SELF'], 'b.rappro', '', $param, '', $sortfield, $sortorder, "center ");
  1053. }
  1054. // Extra fields
  1055. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1056. // Hook fields
  1057. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1058. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1059. print $hookmanager->resPrint;
  1060. // Actions and select
  1061. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  1062. print "</tr>\n";
  1063. $balance = 0; // For balance
  1064. $balancebefore = 0; // For balance
  1065. $balancecalculated = false;
  1066. $posconciliatecol = 0;
  1067. $cachebankaccount = array();
  1068. // Loop on each record
  1069. $sign = 1;
  1070. while ($i < min($num, $limit)) {
  1071. $objp = $db->fetch_object($resql);
  1072. $links = $bankaccountstatic->get_url($objp->rowid);
  1073. // If we are in a situation where we need/can show balance, we calculate the start of balance
  1074. if (!$balancecalculated && (!empty($arrayfields['balancebefore']['checked']) || !empty($arrayfields['balance']['checked'])) && ($mode_balance_ok || $search_conciliated === '0')) {
  1075. if (!$search_account) {
  1076. dol_print_error('', 'account is not defined but $mode_balance_ok is true');
  1077. exit;
  1078. }
  1079. // Loop on each record before
  1080. $sign = 1;
  1081. $i = 0;
  1082. $sqlforbalance = 'SELECT SUM(b.amount) as previoustotal';
  1083. $sqlforbalance .= " FROM ";
  1084. $sqlforbalance .= " ".MAIN_DB_PREFIX."bank_account as ba,";
  1085. $sqlforbalance .= " ".MAIN_DB_PREFIX."bank as b";
  1086. $sqlforbalance .= " WHERE b.fk_account = ba.rowid";
  1087. $sqlforbalance .= " AND ba.entity IN (".getEntity('bank_account').")";
  1088. $sqlforbalance .= " AND b.fk_account = ".((int) $search_account);
  1089. $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."))))";
  1090. $resqlforbalance = $db->query($sqlforbalance);
  1091. //print $sqlforbalance;
  1092. if ($resqlforbalance) {
  1093. $objforbalance = $db->fetch_object($resqlforbalance);
  1094. if ($objforbalance) {
  1095. // If sort is desc,desc,desc then total of previous date + amount is the balancebefore of the previous line before the line to show
  1096. if ($sortfield == 'b.datev,b.dateo,b.rowid' && ($sortorder == 'desc' || $sortorder == 'desc,desc' || $sortorder == 'desc,desc,desc')) {
  1097. $balancebefore = $objforbalance->previoustotal + ($sign * $objp->amount);
  1098. } else {
  1099. // If sort is asc,asc,asc then total of previous date is balance of line before the next line to show
  1100. $balance = $objforbalance->previoustotal;
  1101. }
  1102. }
  1103. } else {
  1104. dol_print_error($db);
  1105. }
  1106. $balancecalculated = true;
  1107. // Output a line with start balance
  1108. if ($user->rights->banque->consolidate && $action == 'reconcile') {
  1109. $tmpnbfieldbeforebalance = 0;
  1110. $tmpnbfieldafterbalance = 0;
  1111. $balancefieldfound = 0;
  1112. foreach ($arrayfields as $key => $val) {
  1113. if ($key == 'balancebefore' || $key == 'balance') {
  1114. $balancefieldfound++;
  1115. continue;
  1116. }
  1117. if (!empty($arrayfields[$key]['checked'])) {
  1118. if (!$balancefieldfound) {
  1119. $tmpnbfieldbeforebalance++;
  1120. } else {
  1121. $tmpnbfieldafterbalance++;
  1122. }
  1123. }
  1124. }
  1125. // Extra fields
  1126. $element = 'banktransaction';
  1127. if (is_array($extrafields->attributes[$element]['label']) && count($extrafields->attributes[$element]['label'])) {
  1128. foreach ($extrafields->attributes[$element]['label'] as $key => $val) {
  1129. if (!empty($arrayfields["ef.".$key]['checked'])) {
  1130. if (!empty($arrayfields[$key]['checked'])) {
  1131. if (!$balancefieldfound) {
  1132. $tmpnbfieldbeforebalance++;
  1133. } else {
  1134. $tmpnbfieldafterbalance++;
  1135. }
  1136. }
  1137. }
  1138. }
  1139. }
  1140. print '<tr class="oddeven trforbreak">';
  1141. if ($tmpnbfieldbeforebalance) {
  1142. print '<td colspan="'.$tmpnbfieldbeforebalance.'">';
  1143. print '&nbsp;';
  1144. print '</td>';
  1145. }
  1146. if (!empty($arrayfields['balancebefore']['checked'])) {
  1147. print '<td class="right">';
  1148. if ($search_conciliated !== '0') {
  1149. print price(price2num($balance, 'MT'), 1, $langs);
  1150. }
  1151. print '</td>';
  1152. }
  1153. if (!empty($arrayfields['balance']['checked'])) {
  1154. print '<td class="right">';
  1155. if ($search_conciliated !== '0') {
  1156. print price(price2num($balance, 'MT'), 1, $langs);
  1157. }
  1158. print '</td>';
  1159. }
  1160. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1161. print '<td class="center">';
  1162. print '<input type="checkbox" id="selectAll" title="'.dol_escape_htmltag($langs->trans("SelectAll")).'" />';
  1163. print ' <script type="text/javascript">
  1164. $("input#selectAll").change(function() {
  1165. $("input[type=checkbox][name^=rowid]").prop("checked", $(this).is(":checked"));
  1166. });
  1167. </script>';
  1168. print '</td>';
  1169. }
  1170. print '<td colspan="'.($tmpnbfieldafterbalance + 1).'">';
  1171. print '&nbsp;';
  1172. print '</td>';
  1173. print '</tr>';
  1174. }
  1175. }
  1176. if ($sortfield == 'b.datev,b.dateo,b.rowid' && ($sortorder == 'desc' || $sortorder == 'desc,desc' || $sortorder == 'desc,desc,desc')) {
  1177. $balance = price2num($balancebefore, 'MT'); // balance = balancebefore of previous line (sort is desc)
  1178. $balancebefore = price2num($balancebefore - ($sign * $objp->amount), 'MT');
  1179. } else {
  1180. $balancebefore = price2num($balance, 'MT'); // balancebefore = balance of previous line (sort is asc)
  1181. $balance = price2num($balance + ($sign * $objp->amount), 'MT');
  1182. }
  1183. if (empty($cachebankaccount[$objp->bankid])) {
  1184. $bankaccounttmp = new Account($db);
  1185. $bankaccounttmp->fetch($objp->bankid);
  1186. $cachebankaccount[$objp->bankid] = $bankaccounttmp;
  1187. $bankaccount = $bankaccounttmp;
  1188. } else {
  1189. $bankaccount = $cachebankaccount[$objp->bankid];
  1190. }
  1191. if (empty($conf->global->BANK_COLORIZE_MOVEMENT)) {
  1192. $backgroundcolor = "class='oddeven'";
  1193. } else {
  1194. if ($objp->amount < 0) {
  1195. $color = '#' . getDolGlobalString('BANK_COLORIZE_MOVEMENT_COLOR1', 'fca955');
  1196. $backgroundcolor = 'style="background: '.$color.';"';
  1197. } else {
  1198. $color = '#' . getDolGlobalString('BANK_COLORIZE_MOVEMENT_COLOR2', '7fdb86');
  1199. $backgroundcolor = 'style="background: '.$color.';"';
  1200. }
  1201. }
  1202. $banklinestatic->id = $objp->rowid;
  1203. $banklinestatic->ref = $objp->rowid;
  1204. print '<tr class="oddeven" '.$backgroundcolor.'>';
  1205. // Ref
  1206. if (!empty($arrayfields['b.rowid']['checked'])) {
  1207. print '<td class="nowrap left">';
  1208. print $banklinestatic->getNomUrl(1);
  1209. print '</td>';
  1210. if (!$i) {
  1211. $totalarray['nbfield']++;
  1212. }
  1213. }
  1214. // Description
  1215. if (!empty($arrayfields['b.label']['checked'])) {
  1216. $labeltoshow = '';
  1217. $titletoshow = '';
  1218. $reg = array();
  1219. preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthee on tente recherche de traduction
  1220. if (!empty($reg[1]) && $langs->trans($reg[1]) != $reg[1]) {
  1221. $labeltoshow = $langs->trans($reg[1]);
  1222. } else {
  1223. if ($objp->label == '(payment_salary)') {
  1224. $labeltoshow = dol_trunc($langs->trans("SalaryPayment", 40));
  1225. } else {
  1226. $labeltoshow = dol_escape_htmltag($objp->label);
  1227. $titletoshow = $objp->label;
  1228. }
  1229. }
  1230. print '<td class="tdoverflowmax300"'.($titletoshow ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>';
  1231. print $labeltoshow; // Already escaped
  1232. // Add info about links after description
  1233. $cachebankaccount = array();
  1234. foreach ($links as $key => $val) {
  1235. print '<!-- '.$links[$key]['type'].' -->';
  1236. if ($links[$key]['type'] == 'withdraw') {
  1237. $banktransferstatic->id = $links[$key]['url_id'];
  1238. $banktransferstatic->ref = $links[$key]['label'];
  1239. print ' '.$banktransferstatic->getNomUrl(0);
  1240. } elseif ($links[$key]['type'] == 'payment') {
  1241. $paymentstatic->id = $links[$key]['url_id'];
  1242. $paymentstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment
  1243. $paymentstatic->date = $db->jdate($objp->do);
  1244. print ' '.$paymentstatic->getNomUrl(2);
  1245. } elseif ($links[$key]['type'] == 'payment_supplier') {
  1246. $paymentsupplierstatic->id = $links[$key]['url_id'];
  1247. $paymentsupplierstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment
  1248. print ' '.$paymentsupplierstatic->getNomUrl(2);
  1249. } elseif ($links[$key]['type'] == 'payment_sc') {
  1250. $paymentscstatic->id = $links[$key]['url_id'];
  1251. $paymentscstatic->ref = $links[$key]['url_id'];
  1252. $paymentscstatic->label = $links[$key]['label'];
  1253. print ' '.$paymentscstatic->getNomUrl(2);
  1254. } elseif ($links[$key]['type'] == 'payment_vat') {
  1255. $paymentvatstatic->id = $links[$key]['url_id'];
  1256. $paymentvatstatic->ref = $links[$key]['url_id'];
  1257. print ' '.$paymentvatstatic->getNomUrl(2);
  1258. } elseif ($links[$key]['type'] == 'payment_salary') {
  1259. $paymentsalstatic->id = $links[$key]['url_id'];
  1260. $paymentsalstatic->ref = $links[$key]['url_id'];
  1261. $paymentsalstatic->label = $links[$key]['label'];
  1262. print ' '.$paymentsalstatic->getNomUrl(2);
  1263. } elseif ($links[$key]['type'] == 'payment_loan') {
  1264. print '<a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$links[$key]['url_id'].'">';
  1265. print ' '.img_object($langs->trans('ShowPayment'), 'payment').' ';
  1266. print '</a>';
  1267. } elseif ($links[$key]['type'] == 'payment_donation') {
  1268. $paymentdonationstatic->id = $links[$key]['url_id'];
  1269. $paymentdonationstatic->ref = $links[$key]['url_id'];
  1270. print ' '.$paymentdonationstatic->getNomUrl(2);
  1271. } elseif ($links[$key]['type'] == 'payment_expensereport') {
  1272. $paymentexpensereportstatic->id = $links[$key]['url_id'];
  1273. $paymentexpensereportstatic->ref = $links[$key]['url_id'];
  1274. print ' '.$paymentexpensereportstatic->getNomUrl(2);
  1275. } elseif ($links[$key]['type'] == 'payment_various') {
  1276. $paymentvariousstatic->id = $links[$key]['url_id'];
  1277. $paymentvariousstatic->ref = $links[$key]['url_id'];
  1278. print ' '.$paymentvariousstatic->getNomUrl(2);
  1279. } elseif ($links[$key]['type'] == 'banktransfert') {
  1280. // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
  1281. if ($objp->amount > 0) {
  1282. $banklinestatic->fetch($links[$key]['url_id']);
  1283. $bankstatic->id = $banklinestatic->fk_account;
  1284. $bankstatic->label = $banklinestatic->bank_account_ref;
  1285. print ' ('.$langs->trans("TransferFrom").' ';
  1286. print $bankstatic->getNomUrl(1, 'transactions');
  1287. print ' '.$langs->trans("toward").' ';
  1288. $bankstatic->id = $objp->bankid;
  1289. $bankstatic->label = $objp->bankref;
  1290. print $bankstatic->getNomUrl(1, '');
  1291. print ')';
  1292. } else {
  1293. $bankstatic->id = $objp->bankid;
  1294. $bankstatic->label = $objp->bankref;
  1295. print ' ('.$langs->trans("TransferFrom").' ';
  1296. print $bankstatic->getNomUrl(1, '');
  1297. print ' '.$langs->trans("toward").' ';
  1298. $banklinestatic->fetch($links[$key]['url_id']);
  1299. $bankstatic->id = $banklinestatic->fk_account;
  1300. $bankstatic->label = $banklinestatic->bank_account_ref;
  1301. print $bankstatic->getNomUrl(1, 'transactions');
  1302. print ')';
  1303. }
  1304. //var_dump($links);
  1305. } elseif ($links[$key]['type'] == 'company') {
  1306. } elseif ($links[$key]['type'] == 'user') {
  1307. } elseif ($links[$key]['type'] == 'member') {
  1308. } elseif ($links[$key]['type'] == 'sc') {
  1309. } elseif ($links[$key]['type'] == 'vat') {
  1310. } elseif ($links[$key]['type'] == 'salary') {
  1311. // Information is already shown using the payment_salary link. No need of this link.
  1312. } else {
  1313. // Show link with label $links[$key]['label']
  1314. if (!empty($objp->label) && !empty($links[$key]['label'])) {
  1315. print ' - ';
  1316. }
  1317. print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
  1318. if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
  1319. // Label generique car entre parentheses. On l'affiche en le traduisant
  1320. if ($reg[1] == 'paiement') {
  1321. $reg[1] = 'Payment';
  1322. }
  1323. print ' '.$langs->trans($reg[1]);
  1324. } else {
  1325. print ' '.$links[$key]['label'];
  1326. }
  1327. print '</a>';
  1328. }
  1329. }
  1330. print '</td>';
  1331. if (!$i) {
  1332. $totalarray['nbfield']++;
  1333. }
  1334. }
  1335. // Date ope
  1336. if (!empty($arrayfields['b.dateo']['checked'])) {
  1337. print '<td align="center" class="nowrap">';
  1338. print '<span class="spanforajaxedit" id="dateoperation_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->do), "day")."</span>";
  1339. print '&nbsp;';
  1340. print '<span class="inline-block">';
  1341. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=doprev&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1342. print img_edit_remove()."</a> ";
  1343. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=donext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1344. print img_edit_add()."</a>";
  1345. print '</span>';
  1346. print "</td>\n";
  1347. if (!$i) {
  1348. $totalarray['nbfield']++;
  1349. }
  1350. }
  1351. // Date value
  1352. if (!empty($arrayfields['b.datev']['checked'])) {
  1353. print '<td align="center" class="nowrap">';
  1354. print '<span class="spanforajaxedit" id="datevalue_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->dv), "day")."</span>";
  1355. print '&nbsp;';
  1356. print '<span class="inline-block">';
  1357. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=dvprev&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1358. print img_edit_remove()."</a> ";
  1359. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&amp;account='.$objp->bankid.'&amp;rowid='.$objp->rowid.'">';
  1360. print img_edit_add()."</a>";
  1361. print '</span>';
  1362. print "</td>\n";
  1363. if (!$i) {
  1364. $totalarray['nbfield']++;
  1365. }
  1366. }
  1367. // Payment type
  1368. if (!empty($arrayfields['type']['checked'])) {
  1369. print '<td align="center" class="nowrap">';
  1370. $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);
  1371. if ($labeltype == 'SOLD') {
  1372. print '&nbsp;'; //$langs->trans("InitialBankBalance");
  1373. } else {
  1374. print $labeltype;
  1375. }
  1376. print "</td>\n";
  1377. if (!$i) {
  1378. $totalarray['nbfield']++;
  1379. }
  1380. }
  1381. // Num cheque
  1382. if (!empty($arrayfields['b.num_chq']['checked'])) {
  1383. print '<td class="nowrap" align="center">'.($objp->num_chq ? dol_escape_htmltag($objp->num_chq) : "")."</td>\n";
  1384. if (!$i) {
  1385. $totalarray['nbfield']++;
  1386. }
  1387. }
  1388. // Third party
  1389. if (!empty($arrayfields['bu.label']['checked'])) {
  1390. print '<td class="tdoverflowmax150">';
  1391. $companylinked_id = 0;
  1392. $userlinked_id = 0;
  1393. //payment line type to define user display and user or company linked
  1394. foreach ($links as $key => $value) {
  1395. if ($links[$key]['type'] == 'payment_sc') {
  1396. $type_link = 'payment_sc';
  1397. }
  1398. if ($links[$key]['type'] == 'payment_salary') {
  1399. $type_link = 'payment_salary';
  1400. }
  1401. if ($links[$key]['type'] == 'company') {
  1402. $companylinked_id = $links[$key]['url_id'];
  1403. }
  1404. if ($links[$key]['type'] == 'user') {
  1405. $userlinked_id = $links[$key]['url_id'];
  1406. }
  1407. }
  1408. if ($companylinked_id) {
  1409. // TODO Add a cache of loaded companies here ?
  1410. $companystatic->fetch($companylinked_id);
  1411. print $companystatic->getNomUrl(1);
  1412. } elseif ($userlinked_id &&
  1413. (($type_link == 'payment_salary' && !empty($user->rights->salaries->read))
  1414. || ($type_link == 'payment_sc' && !empty($user->rights->tax->charges->lire)))) {
  1415. // Get object user from cache or load it
  1416. if (!empty($conf->cache['user'][$userlinked_id])) {
  1417. $tmpuser = $conf->cache['user'][$userlinked_id];
  1418. } else {
  1419. $tmpuser = new User($db);
  1420. $tmpuser->fetch($userlinked_id);
  1421. $conf->cache['user'][$userlinked_id] = $tmpuser;
  1422. }
  1423. print $tmpuser->getNomUrl(1);
  1424. } else {
  1425. print '&nbsp;';
  1426. }
  1427. print '</td>';
  1428. if (!$i) {
  1429. $totalarray['nbfield']++;
  1430. }
  1431. }
  1432. // Bank account
  1433. if (!empty($arrayfields['ba.ref']['checked'])) {
  1434. print '<td class="nowrap">';
  1435. print $bankaccount->getNomUrl(1);
  1436. print "</td>\n";
  1437. if (!$i) {
  1438. $totalarray['nbfield']++;
  1439. }
  1440. }
  1441. // Debit
  1442. if (!empty($arrayfields['b.debit']['checked'])) {
  1443. print '<td class="nowrap right"><span class="amount">';
  1444. if ($objp->amount < 0) {
  1445. print price($objp->amount * -1);
  1446. $totalarray['totaldeb'] += $objp->amount;
  1447. }
  1448. print "</span></td>\n";
  1449. if (!$i) {
  1450. $totalarray['nbfield']++;
  1451. }
  1452. if (!$i) {
  1453. $totalarray['totaldebfield'] = $totalarray['nbfield'];
  1454. }
  1455. }
  1456. // Credit
  1457. if (!empty($arrayfields['b.credit']['checked'])) {
  1458. print '<td class="nowrap right"><span class="amount">';
  1459. if ($objp->amount > 0) {
  1460. print price($objp->amount);
  1461. $totalarray['totalcred'] += $objp->amount;
  1462. }
  1463. print "</span></td>\n";
  1464. if (!$i) {
  1465. $totalarray['nbfield']++;
  1466. }
  1467. if (!$i) {
  1468. $totalarray['totalcredfield'] = $totalarray['nbfield'];
  1469. }
  1470. }
  1471. // Balance before
  1472. if (!empty($arrayfields['balancebefore']['checked'])) {
  1473. if ($mode_balance_ok) {
  1474. if ($balancebefore >= 0) {
  1475. print '<td class="nowrap right">&nbsp;'.price($balancebefore).'</td>';
  1476. } else {
  1477. print '<td class="error nowrap right">&nbsp;'.price($balancebefore).'</td>';
  1478. }
  1479. } else {
  1480. print '<td class="right">-</td>';
  1481. }
  1482. if (!$i) {
  1483. $totalarray['nbfield']++;
  1484. }
  1485. }
  1486. // Balance after
  1487. if (!empty($arrayfields['balance']['checked'])) {
  1488. if ($mode_balance_ok) {
  1489. if ($balance >= 0) {
  1490. print '<td class="nowrap right">&nbsp;'.price($balance).'</td>';
  1491. } else {
  1492. print '<td class="error nowrap right">&nbsp;'.price($balance).'</td>';
  1493. }
  1494. } else {
  1495. print '<td class="right">-</td>';
  1496. }
  1497. if (!$i) {
  1498. $totalarray['nbfield']++;
  1499. }
  1500. }
  1501. if (!empty($arrayfields['b.num_releve']['checked'])) {
  1502. print '<td class="nowraponall" align="center">';
  1503. // Transaction reconciliated or edit link
  1504. if ($bankaccount->canBeConciliated() > 0) {
  1505. if ($objp->num_releve) {
  1506. 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>';
  1507. }
  1508. if (!$objp->conciliated && $action == 'reconcile') {
  1509. if ($objp->num_releve) {
  1510. print '&nbsp;';
  1511. }
  1512. print '<input class="flat" name="rowid['.$objp->rowid.']" type="checkbox" value="'.$objp->rowid.'" size="1"'.(!empty($_POST['rowid'][$objp->rowid]) ? ' checked' : '').'>';
  1513. }
  1514. }
  1515. print '</td>';
  1516. if (!$i) {
  1517. $totalarray['nbfield']++;
  1518. $posconciliatecol = $totalarray['nbfield'];
  1519. }
  1520. }
  1521. if (!empty($arrayfields['b.conciliated']['checked'])) {
  1522. print '<td class="nowraponall" align="center">';
  1523. print yn($objp->conciliated);
  1524. print '</td>';
  1525. if (!$i) {
  1526. $totalarray['nbfield']++;
  1527. }
  1528. }
  1529. // Action edit/delete and select
  1530. print '<td class="nowraponall" align="center">';
  1531. // Transaction reconciliated or edit link
  1532. if ($objp->conciliated && $bankaccount->canBeConciliated() > 0) { // If line not conciliated and account can be conciliated
  1533. 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.'">';
  1534. print img_edit();
  1535. print '</a>';
  1536. } else {
  1537. if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
  1538. 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.'">';
  1539. print img_edit();
  1540. print '</a>';
  1541. } else {
  1542. 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.'">';
  1543. print img_view();
  1544. print '</a>';
  1545. }
  1546. if ($bankaccount->canBeConciliated() > 0 && empty($objp->conciliated)) {
  1547. if ($db->jdate($objp->dv) < ($now - $conf->bank->rappro->warning_delay)) {
  1548. print ' '.img_warning($langs->trans("ReconciliationLate"));
  1549. }
  1550. }
  1551. if ($user->rights->banque->modifier) {
  1552. print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&rowid='.$objp->rowid.'&page='.$page.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').'">';
  1553. print img_delete('', 'class="marginleftonly"');
  1554. print '</a>';
  1555. }
  1556. }
  1557. // Action column
  1558. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1559. $selected = 0;
  1560. if (in_array($obj->rowid, $arrayofselected)) {
  1561. $selected = 1;
  1562. }
  1563. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1564. }
  1565. print '</td>';
  1566. if (!$i) {
  1567. $totalarray['nbfield']++;
  1568. }
  1569. print "</tr>";
  1570. $i++;
  1571. }
  1572. // Show total line
  1573. if (isset($totalarray['totaldebfield']) || isset($totalarray['totalcredfield'])) {
  1574. print '<tr class="liste_total">';
  1575. $i = 0;
  1576. while ($i < $totalarray['nbfield']) {
  1577. $i++;
  1578. if ($i == 1) {
  1579. if ($num < $limit && empty($offset)) {
  1580. print '<td class="left">'.$langs->trans("Total").'</td>';
  1581. } else {
  1582. print '<td class="left tdoverflowmax50" title="'.$langs->trans("Totalforthispage").'">'.$langs->trans("Totalforthispage").'</td>';
  1583. }
  1584. } elseif ($totalarray['totaldebfield'] == $i) {
  1585. print '<td class="right"><span class="amount">'.price(-1 * $totalarray['totaldeb']).'</span></td>';
  1586. } elseif ($totalarray['totalcredfield'] == $i) {
  1587. print '<td class="right"><span class="amount">'.price($totalarray['totalcred']).'</span></td>';
  1588. } elseif ($i == $posconciliatecol) {
  1589. print '<td class="center">';
  1590. if ($user->rights->banque->consolidate && $action == 'reconcile') {
  1591. print '<input class="button" name="confirm_reconcile" type="submit" value="'.$langs->trans("Conciliate").'">';
  1592. }
  1593. print '</td>';
  1594. } else {
  1595. print '<td></td>';
  1596. }
  1597. }
  1598. print '</tr>';
  1599. }
  1600. // If no record found
  1601. if ($num == 0) {
  1602. $colspan = 1;
  1603. foreach ($arrayfields as $key => $val) {
  1604. if (!empty($val['checked'])) {
  1605. $colspan++;
  1606. }
  1607. }
  1608. print '<tr><td colspan="'.($colspan + 1).'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  1609. }
  1610. print "</table>";
  1611. print "</div>";
  1612. print '</form>';
  1613. $db->free($resql);
  1614. } else {
  1615. dol_print_error($db);
  1616. }
  1617. // End of page
  1618. llxFooter();
  1619. $db->close();