bankentries_list.php 75 KB

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