list.php 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  1. <?php
  2. /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
  4. * Copyright (C) 2013-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  5. * Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  6. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/accountancy/bookkeeping/list.php
  23. * \ingroup Accountancy (Double entries)
  24. * \brief List operation of book keeping
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyexport.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/lettering.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  37. // Load translation files required by the page
  38. $langs->loadLangs(array("accountancy", "compta"));
  39. $socid = GETPOST('socid', 'int');
  40. $action = GETPOST('action', 'aZ09');
  41. $massaction = GETPOST('massaction', 'alpha');
  42. $confirm = GETPOST('confirm', 'alpha');
  43. $toselect = GETPOST('toselect', 'array');
  44. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'bookkeepinglist';
  45. $search_mvt_num = GETPOST('search_mvt_num', 'int');
  46. $search_doc_type = GETPOST("search_doc_type", 'alpha');
  47. $search_doc_ref = GETPOST("search_doc_ref", 'alpha');
  48. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  49. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  50. $search_date_startday = GETPOST('search_date_startday', 'int');
  51. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  52. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  53. $search_date_endday = GETPOST('search_date_endday', 'int');
  54. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
  55. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  56. $search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
  57. $search_date_creation_startyear = GETPOST('search_date_creation_startyear', 'int');
  58. $search_date_creation_startmonth = GETPOST('search_date_creation_startmonth', 'int');
  59. $search_date_creation_startday = GETPOST('search_date_creation_startday', 'int');
  60. $search_date_creation_endyear = GETPOST('search_date_creation_endyear', 'int');
  61. $search_date_creation_endmonth = GETPOST('search_date_creation_endmonth', 'int');
  62. $search_date_creation_endday = GETPOST('search_date_creation_endday', 'int');
  63. $search_date_creation_start = dol_mktime(0, 0, 0, $search_date_creation_startmonth, $search_date_creation_startday, $search_date_creation_startyear);
  64. $search_date_creation_end = dol_mktime(23, 59, 59, $search_date_creation_endmonth, $search_date_creation_endday, $search_date_creation_endyear);
  65. $search_date_modification_startyear = GETPOST('search_date_modification_startyear', 'int');
  66. $search_date_modification_startmonth = GETPOST('search_date_modification_startmonth', 'int');
  67. $search_date_modification_startday = GETPOST('search_date_modification_startday', 'int');
  68. $search_date_modification_endyear = GETPOST('search_date_modification_endyear', 'int');
  69. $search_date_modification_endmonth = GETPOST('search_date_modification_endmonth', 'int');
  70. $search_date_modification_endday = GETPOST('search_date_modification_endday', 'int');
  71. $search_date_modification_start = dol_mktime(0, 0, 0, $search_date_modification_startmonth, $search_date_modification_startday, $search_date_modification_startyear);
  72. $search_date_modification_end = dol_mktime(23, 59, 59, $search_date_modification_endmonth, $search_date_modification_endday, $search_date_modification_endyear);
  73. $search_date_export_startyear = GETPOST('search_date_export_startyear', 'int');
  74. $search_date_export_startmonth = GETPOST('search_date_export_startmonth', 'int');
  75. $search_date_export_startday = GETPOST('search_date_export_startday', 'int');
  76. $search_date_export_endyear = GETPOST('search_date_export_endyear', 'int');
  77. $search_date_export_endmonth = GETPOST('search_date_export_endmonth', 'int');
  78. $search_date_export_endday = GETPOST('search_date_export_endday', 'int');
  79. $search_date_export_start = dol_mktime(0, 0, 0, $search_date_export_startmonth, $search_date_export_startday, $search_date_export_startyear);
  80. $search_date_export_end = dol_mktime(23, 59, 59, $search_date_export_endmonth, $search_date_export_endday, $search_date_export_endyear);
  81. $search_date_validation_startyear = GETPOST('search_date_validation_startyear', 'int');
  82. $search_date_validation_startmonth = GETPOST('search_date_validation_startmonth', 'int');
  83. $search_date_validation_startday = GETPOST('search_date_validation_startday', 'int');
  84. $search_date_validation_endyear = GETPOST('search_date_validation_endyear', 'int');
  85. $search_date_validation_endmonth = GETPOST('search_date_validation_endmonth', 'int');
  86. $search_date_validation_endday = GETPOST('search_date_validation_endday', 'int');
  87. $search_date_validation_start = dol_mktime(0, 0, 0, $search_date_validation_startmonth, $search_date_validation_startday, $search_date_validation_startyear);
  88. $search_date_validation_end = dol_mktime(23, 59, 59, $search_date_validation_endmonth, $search_date_validation_endday, $search_date_validation_endyear);
  89. $search_import_key = GETPOST("search_import_key", 'alpha');
  90. //var_dump($search_date_start);exit;
  91. if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) {
  92. $action = 'delbookkeepingyear';
  93. }
  94. if (GETPOST("button_export_file_x") || GETPOST("button_export_file.x") || GETPOST("button_export_file")) {
  95. $action = 'export_file';
  96. }
  97. $search_accountancy_code = GETPOST("search_accountancy_code");
  98. $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
  99. if ($search_accountancy_code_start == - 1) {
  100. $search_accountancy_code_start = '';
  101. }
  102. $search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha');
  103. if ($search_accountancy_code_end == - 1) {
  104. $search_accountancy_code_end = '';
  105. }
  106. $search_accountancy_aux_code = GETPOST("search_accountancy_aux_code", 'alpha');
  107. $search_accountancy_aux_code_start = GETPOST('search_accountancy_aux_code_start', 'alpha');
  108. if ($search_accountancy_aux_code_start == - 1) {
  109. $search_accountancy_aux_code_start = '';
  110. }
  111. $search_accountancy_aux_code_end = GETPOST('search_accountancy_aux_code_end', 'alpha');
  112. if ($search_accountancy_aux_code_end == - 1) {
  113. $search_accountancy_aux_code_end = '';
  114. }
  115. $search_mvt_label = GETPOST('search_mvt_label', 'alpha');
  116. $search_direction = GETPOST('search_direction', 'alpha');
  117. $search_debit = GETPOST('search_debit', 'alpha');
  118. $search_credit = GETPOST('search_credit', 'alpha');
  119. $search_ledger_code = GETPOST('search_ledger_code', 'array');
  120. $search_lettering_code = GETPOST('search_lettering_code', 'alpha');
  121. $search_not_reconciled = GETPOST('search_not_reconciled', 'alpha');
  122. // Load variable for pagination
  123. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  124. $sortfield = GETPOST('sortfield', 'aZ09comma');
  125. $sortorder = GETPOST('sortorder', 'aZ09comma');
  126. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  127. if (empty($page) || $page < 0) {
  128. $page = 0;
  129. }
  130. $offset = $limit * $page;
  131. $pageprev = $page - 1;
  132. $pagenext = $page + 1;
  133. if ($sortorder == "") {
  134. $sortorder = "ASC";
  135. }
  136. if ($sortfield == "") {
  137. $sortfield = "t.piece_num,t.rowid";
  138. }
  139. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  140. $object = new BookKeeping($db);
  141. $hookmanager->initHooks(array('bookkeepinglist'));
  142. $formaccounting = new FormAccounting($db);
  143. $form = new Form($db);
  144. if (!in_array($action, array('export_file', 'delmouv', 'delmouvconfirm')) && !GETPOSTISSET('begin') && !GETPOSTISSET('formfilteraction') && GETPOST('page', 'int') == '' && !GETPOST('noreset', 'int') && $user->rights->accounting->mouvements->export) {
  145. if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('restore_lastsearch_values') && !GETPOST('search_accountancy_code_start')) {
  146. $query = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
  147. $query .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."' limit 1";
  148. $res = $db->query($query);
  149. if ($res->num_rows > 0) {
  150. $fiscalYear = $db->fetch_object($res);
  151. $search_date_start = strtotime($fiscalYear->date_start);
  152. $search_date_end = strtotime($fiscalYear->date_end);
  153. } else {
  154. $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
  155. $year_start = dol_print_date(dol_now(), '%Y');
  156. if (dol_print_date(dol_now(), '%m') < $month_start) {
  157. $year_start--; // If current month is lower that starting fiscal month, we start last year
  158. }
  159. $year_end = $year_start + 1;
  160. $month_end = $month_start - 1;
  161. if ($month_end < 1) {
  162. $month_end = 12;
  163. $year_end--;
  164. }
  165. $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
  166. $search_date_end = dol_get_last_day($year_end, $month_end);
  167. }
  168. }
  169. }
  170. $arrayfields = array(
  171. 't.piece_num'=>array('label'=>$langs->trans("TransactionNumShort"), 'checked'=>1),
  172. 't.code_journal'=>array('label'=>$langs->trans("Codejournal"), 'checked'=>1),
  173. 't.doc_date'=>array('label'=>$langs->trans("Docdate"), 'checked'=>1),
  174. 't.doc_ref'=>array('label'=>$langs->trans("Piece"), 'checked'=>1),
  175. 't.numero_compte'=>array('label'=>$langs->trans("AccountAccountingShort"), 'checked'=>1),
  176. 't.subledger_account'=>array('label'=>$langs->trans("SubledgerAccount"), 'checked'=>1),
  177. 't.label_operation'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
  178. 't.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1),
  179. 't.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1),
  180. 't.lettering_code'=>array('label'=>$langs->trans("LetteringCode"), 'checked'=>1),
  181. 't.date_creation'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0),
  182. 't.tms'=>array('label'=>$langs->trans("DateModification"), 'checked'=>0),
  183. 't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>1),
  184. 't.date_validated'=>array('label'=>$langs->trans("DateValidationAndLock"), 'checked'=>1),
  185. 't.import_key'=>array('label'=>$langs->trans("ImportId"), 'checked'=>0, 'position'=>1100),
  186. );
  187. if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) {
  188. unset($arrayfields['t.lettering_code']);
  189. }
  190. $listofformat = AccountancyExport::getType();
  191. $formatexportset = $conf->global->ACCOUNTING_EXPORT_MODELCSV;
  192. if (empty($listofformat[$formatexportset])) {
  193. $formatexportset = 1;
  194. }
  195. $error = 0;
  196. if (empty($conf->accounting->enabled)) {
  197. accessforbidden();
  198. }
  199. if ($user->socid > 0) {
  200. accessforbidden();
  201. }
  202. if (empty($user->rights->accounting->mouvements->lire)) {
  203. accessforbidden();
  204. }
  205. /*
  206. * Actions
  207. */
  208. $param = '';
  209. if (GETPOST('cancel', 'alpha')) {
  210. $action = 'list'; $massaction = '';
  211. }
  212. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'preunlettering' && $massaction != 'predeletebookkeepingwriting') {
  213. $massaction = '';
  214. }
  215. $parameters = array('socid'=>$socid);
  216. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  217. if ($reshook < 0) {
  218. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  219. }
  220. if (empty($reshook)) {
  221. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  222. 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
  223. $search_mvt_num = '';
  224. $search_doc_type = '';
  225. $search_doc_ref = '';
  226. $search_doc_date = '';
  227. $search_accountancy_code = '';
  228. $search_accountancy_code_start = '';
  229. $search_accountancy_code_end = '';
  230. $search_accountancy_aux_code = '';
  231. $search_accountancy_aux_code_start = '';
  232. $search_accountancy_aux_code_end = '';
  233. $search_mvt_label = '';
  234. $search_direction = '';
  235. $search_ledger_code = array();
  236. $search_date_startyear = '';
  237. $search_date_startmonth = '';
  238. $search_date_startday = '';
  239. $search_date_endyear = '';
  240. $search_date_endmonth = '';
  241. $search_date_endday = '';
  242. $search_date_start = '';
  243. $search_date_end = '';
  244. $search_date_creation_startyear = '';
  245. $search_date_creation_startmonth = '';
  246. $search_date_creation_startday = '';
  247. $search_date_creation_endyear = '';
  248. $search_date_creation_endmonth = '';
  249. $search_date_creation_endday = '';
  250. $search_date_creation_start = '';
  251. $search_date_creation_end = '';
  252. $search_date_modification_startyear = '';
  253. $search_date_modification_startmonth = '';
  254. $search_date_modification_startday = '';
  255. $search_date_modification_endyear = '';
  256. $search_date_modification_endmonth = '';
  257. $search_date_modification_endday = '';
  258. $search_date_modification_start = '';
  259. $search_date_modification_end = '';
  260. $search_date_export_startyear = '';
  261. $search_date_export_startmonth = '';
  262. $search_date_export_startday = '';
  263. $search_date_export_endyear = '';
  264. $search_date_export_endmonth = '';
  265. $search_date_export_endday = '';
  266. $search_date_export_start = '';
  267. $search_date_export_end = '';
  268. $search_date_validation_startyear = '';
  269. $search_date_validation_startmonth = '';
  270. $search_date_validation_startday = '';
  271. $search_date_validation_endyear = '';
  272. $search_date_validation_endmonth = '';
  273. $search_date_validation_endday = '';
  274. $search_date_validation_start = '';
  275. $search_date_validation_end = '';
  276. $search_debit = '';
  277. $search_credit = '';
  278. $search_lettering_code = '';
  279. $search_not_reconciled = '';
  280. $search_import_key = '';
  281. $toselect = array();
  282. }
  283. // Must be after the remove filter action, before the export.
  284. $filter = array();
  285. if (!empty($search_date_start)) {
  286. $filter['t.doc_date>='] = $search_date_start;
  287. $tmp = dol_getdate($search_date_start);
  288. $param .= '&search_date_startmonth='.urlencode($tmp['mon']).'&search_date_startday='.urlencode($tmp['mday']).'&search_date_startyear='.urlencode($tmp['year']);
  289. }
  290. if (!empty($search_date_end)) {
  291. $filter['t.doc_date<='] = $search_date_end;
  292. $tmp = dol_getdate($search_date_end);
  293. $param .= '&search_date_endmonth='.urlencode($tmp['mon']).'&search_date_endday='.urlencode($tmp['mday']).'&search_date_endyear='.urlencode($tmp['year']);
  294. }
  295. if (!empty($search_doc_date)) {
  296. $filter['t.doc_date'] = $search_doc_date;
  297. $tmp = dol_getdate($search_doc_date);
  298. $param .= '&doc_datemonth='.urlencode($tmp['mon']).'&doc_dateday='.urlencode($tmp['mday']).'&doc_dateyear='.urlencode($tmp['year']);
  299. }
  300. if (!empty($search_doc_type)) {
  301. $filter['t.doc_type'] = $search_doc_type;
  302. $param .= '&search_doc_type='.urlencode($search_doc_type);
  303. }
  304. if (!empty($search_doc_ref)) {
  305. $filter['t.doc_ref'] = $search_doc_ref;
  306. $param .= '&search_doc_ref='.urlencode($search_doc_ref);
  307. }
  308. if (!empty($search_accountancy_code)) {
  309. $filter['t.numero_compte'] = $search_accountancy_code;
  310. $param .= '&search_accountancy_code='.urlencode($search_accountancy_code);
  311. }
  312. if (!empty($search_accountancy_code_start)) {
  313. $filter['t.numero_compte>='] = $search_accountancy_code_start;
  314. $param .= '&search_accountancy_code_start='.urlencode($search_accountancy_code_start);
  315. }
  316. if (!empty($search_accountancy_code_end)) {
  317. $filter['t.numero_compte<='] = $search_accountancy_code_end;
  318. $param .= '&search_accountancy_code_end='.urlencode($search_accountancy_code_end);
  319. }
  320. if (!empty($search_accountancy_aux_code_start)) {
  321. $filter['t.subledger_account>='] = $search_accountancy_aux_code_start;
  322. $param .= '&search_accountancy_aux_code_start='.urlencode($search_accountancy_aux_code_start);
  323. }
  324. if (!empty($search_accountancy_aux_code_end)) {
  325. $filter['t.subledger_account<='] = $search_accountancy_aux_code_end;
  326. $param .= '&search_accountancy_aux_code_end='.urlencode($search_accountancy_aux_code_end);
  327. }
  328. if (!empty($search_mvt_label)) {
  329. $filter['t.label_operation'] = $search_mvt_label;
  330. $param .= '&search_mvt_label='.urlencode($search_mvt_label);
  331. }
  332. if (!empty($search_direction)) {
  333. $filter['t.sens'] = $search_direction;
  334. $param .= '&search_direction='.urlencode($search_direction);
  335. }
  336. if (!empty($search_ledger_code)) {
  337. $filter['t.code_journal'] = $search_ledger_code;
  338. foreach ($search_ledger_code as $code) {
  339. $param .= '&search_ledger_code[]='.urlencode($code);
  340. }
  341. }
  342. if (!empty($search_mvt_num)) {
  343. $filter['t.piece_num'] = $search_mvt_num;
  344. $param .= '&search_mvt_num='.urlencode($search_mvt_num);
  345. }
  346. if (!empty($search_date_creation_start)) {
  347. $filter['t.date_creation>='] = $search_date_creation_start;
  348. $tmp = dol_getdate($search_date_creation_start);
  349. $param .= '&search_date_creation_startmonth='.urlencode($tmp['mon']).'&search_date_creation_startday='.urlencode($tmp['mday']).'&search_date_creation_startyear='.urlencode($tmp['year']);
  350. }
  351. if (!empty($search_date_creation_end)) {
  352. $filter['t.date_creation<='] = $search_date_creation_end;
  353. $tmp = dol_getdate($search_date_creation_end);
  354. $param .= '&search_date_creation_endmonth='.urlencode($tmp['mon']).'&search_date_creation_endday='.urlencode($tmp['mday']).'&search_date_creation_endyear='.urlencode($tmp['year']);
  355. }
  356. if (!empty($search_date_modification_start)) {
  357. $filter['t.tms>='] = $search_date_modification_start;
  358. $tmp = dol_getdate($search_date_modification_start);
  359. $param .= '&search_date_modification_startmonth='.urlencode($tmp['mon']).'&search_date_modification_startday='.urlencode($tmp['mday']).'&search_date_modification_startyear='.urlencode($tmp['year']);
  360. }
  361. if (!empty($search_date_modification_end)) {
  362. $filter['t.tms<='] = $search_date_modification_end;
  363. $tmp = dol_getdate($search_date_modification_end);
  364. $param .= '&search_date_modification_endmonth='.urlencode($tmp['mon']).'&search_date_modification_endday='.urlencode($tmp['mday']).'&search_date_modification_endyear='.urlencode($tmp['year']);
  365. }
  366. if (!empty($search_date_export_start)) {
  367. $filter['t.date_export>='] = $search_date_export_start;
  368. $tmp = dol_getdate($search_date_export_start);
  369. $param .= '&search_date_export_startmonth='.urlencode($tmp['mon']).'&search_date_export_startday='.urlencode($tmp['mday']).'&search_date_export_startyear='.urlencode($tmp['year']);
  370. }
  371. if (!empty($search_date_export_end)) {
  372. $filter['t.date_export<='] = $search_date_export_end;
  373. $tmp = dol_getdate($search_date_export_end);
  374. $param .= '&search_date_export_endmonth='.urlencode($tmp['mon']).'&search_date_export_endday='.urlencode($tmp['mday']).'&search_date_export_endyear='.urlencode($tmp['year']);
  375. }
  376. if (!empty($search_date_validation_start)) {
  377. $filter['t.date_validated>='] = $search_date_validation_start;
  378. $tmp = dol_getdate($search_date_validation_start);
  379. $param .= '&search_date_validation_startmonth='.urlencode($tmp['mon']).'&search_date_validation_startday='.urlencode($tmp['mday']).'&search_date_validation_startyear='.urlencode($tmp['year']);
  380. }
  381. if (!empty($search_date_validation_end)) {
  382. $filter['t.date_validated<='] = $search_date_validation_end;
  383. $tmp = dol_getdate($search_date_validation_end);
  384. $param .= '&search_date_validation_endmonth='.urlencode($tmp['mon']).'&search_date_validation_endday='.urlencode($tmp['mday']).'&search_date_validation_endyear='.urlencode($tmp['year']);
  385. }
  386. if (!empty($search_debit)) {
  387. $filter['t.debit'] = $search_debit;
  388. $param .= '&search_debit='.urlencode($search_debit);
  389. }
  390. if (!empty($search_credit)) {
  391. $filter['t.credit'] = $search_credit;
  392. $param .= '&search_credit='.urlencode($search_credit);
  393. }
  394. if (!empty($search_lettering_code)) {
  395. $filter['t.lettering_code'] = $search_lettering_code;
  396. $param .= '&search_lettering_code='.urlencode($search_lettering_code);
  397. }
  398. if (!empty($search_not_reconciled)) {
  399. $filter['t.reconciled_option'] = $search_not_reconciled;
  400. $param .= '&search_not_reconciled='.urlencode($search_not_reconciled);
  401. }
  402. if (!empty($search_import_key)) {
  403. $filter['t.import_key'] = $search_import_key;
  404. $param .= '&search_import_key='.urlencode($search_import_key);
  405. }
  406. //if ($action == 'delbookkeepingyearconfirm' && $user->rights->accounting->mouvements->supprimer_tous) {
  407. // $delmonth = GETPOST('delmonth', 'int');
  408. // $delyear = GETPOST('delyear', 'int');
  409. // if ($delyear == -1) {
  410. // $delyear = 0;
  411. // }
  412. // $deljournal = GETPOST('deljournal', 'alpha');
  413. // if ($deljournal == -1) {
  414. // $deljournal = 0;
  415. // }
  416. //
  417. // if (!empty($delmonth) || !empty($delyear) || !empty($deljournal)) {
  418. // $result = $object->deleteByYearAndJournal($delyear, $deljournal, '', ($delmonth > 0 ? $delmonth : 0));
  419. // if ($result < 0) {
  420. // setEventMessages($object->error, $object->errors, 'errors');
  421. // } else {
  422. // setEventMessages("RecordDeleted", null, 'mesgs');
  423. // }
  424. //
  425. // // Make a redirect to avoid to launch the delete later after a back button
  426. // header("Location: list.php".($param ? '?'.$param : ''));
  427. // exit;
  428. // } else {
  429. // setEventMessages("NoRecordDeleted", null, 'warnings');
  430. // }
  431. //}
  432. if ($action == 'setreexport') {
  433. $setreexport = GETPOST('value', 'int');
  434. if (!dolibarr_set_const($db, "ACCOUNTING_REEXPORT", $setreexport, 'yesno', 0, '', $conf->entity)) {
  435. $error++;
  436. }
  437. if (!$error) {
  438. if ($conf->global->ACCOUNTING_REEXPORT == 1) {
  439. setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsEnable"), null, 'mesgs');
  440. } else {
  441. setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsDisable"), null, 'mesgs');
  442. }
  443. } else {
  444. setEventMessages($langs->trans("Error"), null, 'errors');
  445. }
  446. }
  447. // Mass actions
  448. $objectclass = 'Bookkeeping';
  449. $objectlabel = 'Bookkeeping';
  450. $permissiontoread = $user->rights->societe->lire;
  451. $permissiontodelete = $user->rights->societe->supprimer;
  452. $permissiontoadd = $user->rights->societe->creer;
  453. $uploaddir = $conf->societe->dir_output;
  454. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  455. if (!$error && $action == 'deletebookkeepingwriting' && $confirm == "yes" && $user->rights->accounting->mouvements->supprimer) {
  456. $nbok = 0;
  457. foreach ($toselect as $toselectid) {
  458. $result = $object->fetch($toselectid);
  459. if ($result > 0 && (!isset($object->date_validation) || $object->date_validation === '')) {
  460. $result = $object->deleteMvtNum($object->piece_num);
  461. if ($result > 0) {
  462. $nbok++;
  463. } else {
  464. setEventMessages($object->error, $object->errors, 'errors');
  465. $error++;
  466. break;
  467. }
  468. } elseif ($result < 0) {
  469. setEventMessages($object->error, $object->errors, 'errors');
  470. $error++;
  471. break;
  472. }
  473. }
  474. // Message for elements well deleted
  475. if ($nbok > 1) {
  476. setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
  477. } elseif ($nbok > 0) {
  478. setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
  479. } elseif (!$error) {
  480. setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
  481. }
  482. if (!$error) {
  483. header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
  484. exit;
  485. }
  486. }
  487. // others mass actions
  488. if (!$error && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->rights->accounting->mouvements->creer) {
  489. if ($massaction == 'lettering') {
  490. $lettering = new Lettering($db);
  491. $nb_lettering = $lettering->bookkeepingLetteringAll($toselect);
  492. if ($nb_lettering < 0) {
  493. setEventMessages('', $lettering->errors, 'errors');
  494. $error++;
  495. $nb_lettering = max(0, abs($nb_lettering) - 2);
  496. } elseif ($nb_lettering == 0) {
  497. $nb_lettering = 0;
  498. setEventMessages($langs->trans('AccountancyNoLetteringModified'), array(), 'mesgs');
  499. }
  500. if ($nb_lettering == 1) {
  501. setEventMessages($langs->trans('AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs');
  502. } elseif ($nb_lettering > 1) {
  503. setEventMessages($langs->trans('AccountancyLetteringModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
  504. }
  505. if (!$error) {
  506. header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
  507. exit();
  508. }
  509. } elseif ($action == 'unlettering' && $confirm == "yes") {
  510. $lettering = new Lettering($db);
  511. $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
  512. if ($nb_lettering < 0) {
  513. setEventMessages('', $lettering->errors, 'errors');
  514. $error++;
  515. $nb_lettering = max(0, abs($nb_lettering) - 2);
  516. } elseif ($nb_lettering == 0) {
  517. $nb_lettering = 0;
  518. setEventMessages($langs->trans('AccountancyNoUnletteringModified'), array(), 'mesgs');
  519. }
  520. if ($nb_lettering == 1) {
  521. setEventMessages($langs->trans('AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs');
  522. } elseif ($nb_lettering > 1) {
  523. setEventMessages($langs->trans('AccountancyUnletteringModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
  524. }
  525. if (!$error) {
  526. header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
  527. exit();
  528. }
  529. }
  530. }
  531. }
  532. // Build and execute select (used by page and export action)
  533. // must de set after the action that set $filter
  534. // --------------------------------------------------------------------
  535. $sql = 'SELECT';
  536. $sql .= ' t.rowid,';
  537. $sql .= " t.doc_date,";
  538. $sql .= " t.doc_type,";
  539. $sql .= " t.doc_ref,";
  540. $sql .= " t.fk_doc,";
  541. $sql .= " t.fk_docdet,";
  542. $sql .= " t.thirdparty_code,";
  543. $sql .= " t.subledger_account,";
  544. $sql .= " t.subledger_label,";
  545. $sql .= " t.numero_compte,";
  546. $sql .= " t.label_compte,";
  547. $sql .= " t.label_operation,";
  548. $sql .= " t.debit,";
  549. $sql .= " t.credit,";
  550. $sql .= " t.lettering_code,";
  551. $sql .= " t.montant as amount,";
  552. $sql .= " t.sens,";
  553. $sql .= " t.fk_user_author,";
  554. $sql .= " t.import_key,";
  555. $sql .= " t.code_journal,";
  556. $sql .= " t.journal_label,";
  557. $sql .= " t.piece_num,";
  558. $sql .= " t.date_creation,";
  559. $sql .= " t.tms as date_modification,";
  560. $sql .= " t.date_export,";
  561. $sql .= " t.date_validated as date_validation,";
  562. $sql .= " t.import_key";
  563. $sql .= ' FROM '.MAIN_DB_PREFIX.$object->table_element.' as t';
  564. // Manage filter
  565. $sqlwhere = array();
  566. if (count($filter) > 0) {
  567. foreach ($filter as $key => $value) {
  568. if ($key == 't.doc_date') {
  569. $sqlwhere[] = $key."='".$db->idate($value)."'";
  570. } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') {
  571. $sqlwhere[] = $key."'".$db->idate($value)."'";
  572. } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') {
  573. $sqlwhere[] = $key."'".$db->escape($value)."'";
  574. } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') {
  575. $sqlwhere[] = $key.'='.((int) $value);
  576. } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') {
  577. $sqlwhere[] = $key." LIKE '".$db->escape($value)."%'";
  578. } elseif ($key == 't.subledger_account') {
  579. $sqlwhere[] = natural_search($key, $value, 0, 1);
  580. } elseif ($key == 't.date_creation>=' || $key == 't.date_creation<=') {
  581. $sqlwhere[] = $key."'".$db->idate($value)."'";
  582. } elseif ($key == 't.tms>=' || $key == 't.tms<=') {
  583. $sqlwhere[] = $key."'".$db->idate($value)."'";
  584. } elseif ($key == 't.date_export>=' || $key == 't.date_export<=') {
  585. $sqlwhere[] = $key."'".$db->idate($value)."'";
  586. } elseif ($key == 't.date_validated>=' || $key == 't.date_validated<=') {
  587. $sqlwhere[] = $key."'".$db->idate($value)."'";
  588. } elseif ($key == 't.credit' || $key == 't.debit') {
  589. $sqlwhere[] = natural_search($key, $value, 1, 1);
  590. } elseif ($key == 't.reconciled_option') {
  591. $sqlwhere[] = 't.lettering_code IS NULL';
  592. } elseif ($key == 't.code_journal' && !empty($value)) {
  593. $sqlwhere[] = natural_search("t.code_journal", join(',', $value), 3, 1);
  594. } else {
  595. $sqlwhere[] = natural_search($key, $value, 0, 1);
  596. }
  597. }
  598. }
  599. $sql .= ' WHERE t.entity IN ('.getEntity('accountancy').')';
  600. if (empty($conf->global->ACCOUNTING_REEXPORT)) {
  601. $sql .= " AND t.date_export IS NULL";
  602. }
  603. if (count($sqlwhere) > 0) {
  604. $sql .= ' AND '.implode(' AND ', $sqlwhere);
  605. }
  606. if (!empty($sortfield)) {
  607. $sql .= $db->order($sortfield, $sortorder);
  608. }
  609. //print $sql;
  610. // Export into a file with format defined into setup (FEC, CSV, ...)
  611. // Must be after definition of $sql
  612. if ($action == 'export_fileconfirm' && $user->rights->accounting->mouvements->export) {
  613. // TODO Replace the fetchAll to get all ->line followed by call to ->export(). It consumew too much memory on large export. Replace this with the query($sql) and loop on each line to export them.
  614. $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter, 'AND', (empty($conf->global->ACCOUNTING_REEXPORT) ? 0 : 1));
  615. if ($result < 0) {
  616. setEventMessages($object->error, $object->errors, 'errors');
  617. } else {
  618. // Export files
  619. $accountancyexport = new AccountancyExport($db);
  620. $accountancyexport->export($object->lines, $formatexportset);
  621. $notifiedexportdate = GETPOST('notifiedexportdate', 'alpha');
  622. $notifiedvalidationdate = GETPOST('notifiedvalidationdate', 'alpha');
  623. if (!empty($accountancyexport->errors)) {
  624. setEventMessages('', $accountancyexport->errors, 'errors');
  625. } elseif (!empty($notifiedexportdate) || !empty($notifiedvalidationdate)) {
  626. // Specify as export : update field date_export or date_validated
  627. $error = 0;
  628. $db->begin();
  629. if (is_array($object->lines)) {
  630. foreach ($object->lines as $movement) {
  631. $now = dol_now();
  632. $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping";
  633. $sql .= " SET";
  634. if (!empty($notifiedexportdate) && !empty($notifiedvalidationdate)) {
  635. $sql .= " date_export = '".$db->idate($now)."'";
  636. $sql .= ", date_validated = '".$db->idate($now)."'";
  637. } elseif (!empty($notifiedexportdate)) {
  638. $sql .= " date_export = '".$db->idate($now)."'";
  639. } elseif (!empty($notifiedvalidationdate)) {
  640. $sql .= " date_validated = '".$db->idate($now)."'";
  641. }
  642. $sql .= " WHERE rowid = ".((int) $movement->id);
  643. dol_syslog("/accountancy/bookkeeping/list.php Function export_file Specify movements as exported", LOG_DEBUG);
  644. $result = $db->query($sql);
  645. if (!$result) {
  646. $error++;
  647. break;
  648. }
  649. }
  650. }
  651. if (!$error) {
  652. $db->commit();
  653. // setEventMessages($langs->trans("AllExportedMovementsWereRecordedAsExportedOrValidated"), null, 'mesgs');
  654. } else {
  655. $error++;
  656. $db->rollback();
  657. setEventMessages($langs->trans("NotAllExportedMovementsCouldBeRecordedAsExportedOrValidated"), null, 'errors');
  658. }
  659. }
  660. exit;
  661. }
  662. }
  663. /*
  664. * View
  665. */
  666. $formother = new FormOther($db);
  667. $formfile = new FormFile($db);
  668. $title_page = $langs->trans("Operations").' - '.$langs->trans("Journals");
  669. // Count total nb of records
  670. $nbtotalofrecords = '';
  671. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  672. $resql = $db->query($sql);
  673. $nbtotalofrecords = $db->num_rows($resql);
  674. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  675. $page = 0;
  676. $offset = 0;
  677. }
  678. }
  679. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  680. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
  681. $num = $nbtotalofrecords;
  682. } else {
  683. $sql .= $db->plimit($limit + 1, $offset);
  684. $resql = $db->query($sql);
  685. if (!$resql) {
  686. dol_print_error($db);
  687. exit;
  688. }
  689. $num = $db->num_rows($resql);
  690. }
  691. $arrayofselected = is_array($toselect) ? $toselect : array();
  692. // Output page
  693. // --------------------------------------------------------------------
  694. llxHeader('', $title_page);
  695. $formconfirm = '';
  696. if ($action == 'export_file') {
  697. $form_question = array();
  698. // If 1 or not set, we check by default.
  699. $checked = (!isset($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE) || !empty($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE));
  700. $form_question['notifiedexportdate'] = array(
  701. 'name' => 'notifiedexportdate',
  702. 'type' => 'checkbox',
  703. 'label' => $langs->trans('NotifiedExportDate'),
  704. 'value' => (!empty($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE) ? 'false' : 'true'),
  705. );
  706. $form_question['separator'] = array('name'=>'separator', 'type'=>'separator');
  707. // If 0 or not set, we NOT check by default.
  708. $checked = (isset($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_VALIDATION_DATE) || !empty($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_VALIDATION_DATE));
  709. $form_question['notifiedvalidationdate'] = array(
  710. 'name' => 'notifiedvalidationdate',
  711. 'type' => 'checkbox',
  712. 'label' => $langs->trans('NotifiedValidationDate'),
  713. 'value' => $checked,
  714. );
  715. $form_question['separator2'] = array('name'=>'separator2', 'type'=>'separator');
  716. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', $langs->trans('ConfirmExportFile'), 'export_fileconfirm', $form_question, '', 1, 300, 600);
  717. }
  718. //if ($action == 'delbookkeepingyear') {
  719. // $form_question = array();
  720. // $delyear = GETPOST('delyear', 'int');
  721. // $deljournal = GETPOST('deljournal', 'alpha');
  722. //
  723. // if (empty($delyear)) {
  724. // $delyear = dol_print_date(dol_now(), '%Y');
  725. // }
  726. // $month_array = array();
  727. // for ($i = 1; $i <= 12; $i++) {
  728. // $month_array[$i] = $langs->trans("Month".sprintf("%02d", $i));
  729. // }
  730. // $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
  731. // $journal_array = $formaccounting->select_journal($deljournal, 'deljournal', '', 1, 1, 1, '', 0, 1);
  732. //
  733. // $form_question['delmonth'] = array(
  734. // 'name' => 'delmonth',
  735. // 'type' => 'select',
  736. // 'label' => $langs->trans('DelMonth'),
  737. // 'values' => $month_array,
  738. // 'morecss' => 'minwidth150',
  739. // 'default' => ''
  740. // );
  741. // $form_question['delyear'] = array(
  742. // 'name' => 'delyear',
  743. // 'type' => 'select',
  744. // 'label' => $langs->trans('DelYear'),
  745. // 'values' => $year_array,
  746. // 'default' => $delyear
  747. // );
  748. // $form_question['deljournal'] = array(
  749. // 'name' => 'deljournal',
  750. // 'type' => 'other', // We don't use select here, the journal_array is already a select html component
  751. // 'label' => $langs->trans('DelJournal'),
  752. // 'value' => $journal_array,
  753. // 'default' => $deljournal
  754. // );
  755. //
  756. // $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'delbookkeepingyearconfirm', $form_question, '', 1, 320);
  757. //}
  758. // Print form confirm
  759. print $formconfirm;
  760. //$param=''; param started before
  761. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  762. $param .= '&contextpage='.urlencode($contextpage);
  763. }
  764. if ($limit > 0 && $limit != $conf->liste_limit) {
  765. $param .= '&limit='.urlencode($limit);
  766. }
  767. // List of mass actions available
  768. $arrayofmassactions = array();
  769. /*
  770. if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->rights->accounting->mouvements->creer) {
  771. $arrayofmassactions['lettering'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('Lettering');
  772. $arrayofmassactions['preunlettering'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('Unlettering');
  773. }
  774. */
  775. if ($user->rights->accounting->mouvements->supprimer) {
  776. $arrayofmassactions['predeletebookkeepingwriting'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  777. }
  778. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('preunlettering', 'predeletebookkeepingwriting'))) {
  779. $arrayofmassactions = array();
  780. }
  781. $massactionbutton = $form->selectMassAction($massaction, $arrayofmassactions);
  782. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  783. print '<input type="hidden" name="token" value="'.newToken().'">';
  784. print '<input type="hidden" name="action" value="list">';
  785. if ($optioncss != '') {
  786. print '<input type="hidden" name="optioncss" value="'.urlencode($optioncss).'">';
  787. }
  788. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  789. print '<input type="hidden" name="sortfield" value="'.urlencode($sortfield).'">';
  790. print '<input type="hidden" name="sortorder" value="'.urlencode($sortorder).'">';
  791. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  792. if (count($filter)) {
  793. $buttonLabel = $langs->trans("ExportFilteredList");
  794. } else {
  795. $buttonLabel = $langs->trans("ExportList");
  796. }
  797. $parameters = array();
  798. $reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  799. if (empty($reshook)) {
  800. // Button re-export
  801. if (!empty($conf->global->ACCOUNTING_REEXPORT)) {
  802. $newcardbutton = '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=setreexport&token='.newToken().'&value=0'.($param ? '&'.$param : '').'">'.img_picto($langs->trans("Activated"), 'switch_on').'</a> ';
  803. } else {
  804. $newcardbutton = '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?action=setreexport&token='.newToken().'&value=1'.($param ? '&'.$param : '').'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a> ';
  805. }
  806. $newcardbutton .= '<span class="valignmiddle marginrightonly">'.$langs->trans("IncludeDocsAlreadyExported").'</span>';
  807. if (!empty($user->rights->accounting->mouvements->export)) {
  808. $newcardbutton .= dolGetButtonTitle($buttonLabel, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', 'fa fa-file-export paddingleft', $_SERVER["PHP_SELF"].'?action=export_file'.($param ? '&'.$param : ''), $user->rights->accounting->mouvements->export);
  809. }
  810. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
  811. $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly'));
  812. $newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?type=sub'.$param, '', 1, array('morecss' => 'marginleftonly'));
  813. $url = './card.php?action=create';
  814. if (!empty($socid)) {
  815. $url .= '&socid='.$socid;
  816. }
  817. $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', $url, '', $user->rights->accounting->mouvements->creer);
  818. }
  819. print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1);
  820. if ($massaction == 'preunlettering') {
  821. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnlettering"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unlettering", null, '', 0, 200, 500, 1);
  822. } elseif ($massaction == 'predeletebookkeepingwriting') {
  823. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeleteBookkeepingWriting"), $langs->trans("ConfirmMassDeleteBookkeepingWritingQuestion", count($toselect)), "deletebookkeepingwriting", null, '', 0, 200, 500, 1);
  824. }
  825. //$topicmail = "Information";
  826. //$modelmail = "accountingbookkeeping";
  827. //$objecttmp = new BookKeeping($db);
  828. //$trackid = 'bk'.$object->id;
  829. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  830. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  831. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  832. if ($massactionbutton && $contextpage != 'poslist') {
  833. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  834. }
  835. $parameters = array();
  836. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  837. if (empty($reshook)) {
  838. $moreforfilter .= $hookmanager->resPrint;
  839. } else {
  840. $moreforfilter = $hookmanager->resPrint;
  841. }
  842. print '<div class="div-table-responsive">';
  843. print '<table class="tagtable liste centpercent">';
  844. // Filters lines
  845. print '<tr class="liste_titre_filter">';
  846. // Movement number
  847. if (!empty($arrayfields['t.piece_num']['checked'])) {
  848. print '<td class="liste_titre"><input type="text" name="search_mvt_num" size="6" value="'.dol_escape_htmltag($search_mvt_num).'"></td>';
  849. }
  850. // Code journal
  851. if (!empty($arrayfields['t.code_journal']['checked'])) {
  852. print '<td class="liste_titre center">';
  853. print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1, 'small maxwidth150');
  854. print '</td>';
  855. }
  856. // Date document
  857. if (!empty($arrayfields['t.doc_date']['checked'])) {
  858. print '<td class="liste_titre center">';
  859. print '<div class="nowrap">';
  860. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  861. print '</div>';
  862. print '<div class="nowrap">';
  863. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  864. print '</div>';
  865. print '</td>';
  866. }
  867. // Ref document
  868. if (!empty($arrayfields['t.doc_ref']['checked'])) {
  869. print '<td class="liste_titre"><input type="text" name="search_doc_ref" size="8" value="'.dol_escape_htmltag($search_doc_ref).'"></td>';
  870. }
  871. // Accountancy account
  872. if (!empty($arrayfields['t.numero_compte']['checked'])) {
  873. print '<td class="liste_titre">';
  874. print '<div class="nowrap">';
  875. print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth150', 'account');
  876. print '</div>';
  877. print '<div class="nowrap">';
  878. print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth150', 'account');
  879. print '</div>';
  880. print '</td>';
  881. }
  882. // Subledger account
  883. if (!empty($arrayfields['t.subledger_account']['checked'])) {
  884. print '<td class="liste_titre">';
  885. // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not
  886. // use setup of keypress to select thirdparty and this hang browser on large database.
  887. if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
  888. print '<div class="nowrap">';
  889. //print $langs->trans('From').' ';
  890. print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', $langs->trans('From'), 'maxwidth250', 'subledgeraccount');
  891. print '</div>';
  892. print '<div class="nowrap">';
  893. print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', $langs->trans('to'), 'maxwidth250', 'subledgeraccount');
  894. print '</div>';
  895. } else {
  896. print '<input type="text" class="maxwidth75" name="search_accountancy_aux_code" value="'.$search_accountancy_aux_code.'">';
  897. }
  898. print '</td>';
  899. }
  900. // Label operation
  901. if (!empty($arrayfields['t.label_operation']['checked'])) {
  902. print '<td class="liste_titre">';
  903. print '<input type="text" size="7" class="flat" name="search_mvt_label" value="'.$search_mvt_label.'"/>';
  904. print '</td>';
  905. }
  906. // Debit
  907. if (!empty($arrayfields['t.debit']['checked'])) {
  908. print '<td class="liste_titre right">';
  909. print '<input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'">';
  910. print '</td>';
  911. }
  912. // Credit
  913. if (!empty($arrayfields['t.credit']['checked'])) {
  914. print '<td class="liste_titre right">';
  915. print '<input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'">';
  916. print '</td>';
  917. }
  918. // Lettering code
  919. if (!empty($arrayfields['t.lettering_code']['checked'])) {
  920. print '<td class="liste_titre center">';
  921. print '<input type="text" size="3" class="flat" name="search_lettering_code" value="'.$search_lettering_code.'"/>';
  922. print '<br><span class="nowrap"><input type="checkbox" name="search_not_reconciled" value="notreconciled"'.($search_not_reconciled == 'notreconciled' ? ' checked' : '').'>'.$langs->trans("NotReconciled").'</span>';
  923. print '</td>';
  924. }
  925. // Fields from hook
  926. $parameters = array('arrayfields'=>$arrayfields);
  927. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  928. print $hookmanager->resPrint;
  929. // Date creation
  930. if (!empty($arrayfields['t.date_creation']['checked'])) {
  931. print '<td class="liste_titre center">';
  932. print '<div class="nowrap">';
  933. print $form->selectDate($search_date_creation_start, 'search_date_creation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  934. print '</div>';
  935. print '<div class="nowrap">';
  936. print $form->selectDate($search_date_creation_end, 'search_date_creation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  937. print '</div>';
  938. print '</td>';
  939. }
  940. // Date modification
  941. if (!empty($arrayfields['t.tms']['checked'])) {
  942. print '<td class="liste_titre center">';
  943. print '<div class="nowrap">';
  944. print $form->selectDate($search_date_modification_start, 'search_date_modification_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  945. print '</div>';
  946. print '<div class="nowrap">';
  947. print $form->selectDate($search_date_modification_end, 'search_date_modification_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  948. print '</div>';
  949. print '</td>';
  950. }
  951. // Date export
  952. if (!empty($arrayfields['t.date_export']['checked'])) {
  953. print '<td class="liste_titre center">';
  954. print '<div class="nowrap">';
  955. print $form->selectDate($search_date_export_start, 'search_date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  956. print '</div>';
  957. print '<div class="nowrap">';
  958. print $form->selectDate($search_date_export_end, 'search_date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  959. print '</div>';
  960. print '</td>';
  961. }
  962. // Date validation
  963. if (!empty($arrayfields['t.date_validated']['checked'])) {
  964. print '<td class="liste_titre center">';
  965. print '<div class="nowrap">';
  966. print $form->selectDate($search_date_validation_start, 'search_date_validation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  967. print '</div>';
  968. print '<div class="nowrap">';
  969. print $form->selectDate($search_date_validation_end, 'search_date_validation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  970. print '</div>';
  971. print '</td>';
  972. }
  973. if (!empty($arrayfields['t.import_key']['checked'])) {
  974. print '<td class="liste_titre center">';
  975. print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
  976. print '</td>';
  977. }
  978. // Action column
  979. print '<td class="liste_titre center">';
  980. $searchpicto = $form->showFilterButtons();
  981. print $searchpicto;
  982. print '</td>';
  983. print "</tr>\n";
  984. print '<tr class="liste_titre">';
  985. if (!empty($arrayfields['t.piece_num']['checked'])) {
  986. print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, "", $sortfield, $sortorder);
  987. }
  988. if (!empty($arrayfields['t.code_journal']['checked'])) {
  989. print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, '', $sortfield, $sortorder, 'center ');
  990. }
  991. if (!empty($arrayfields['t.doc_date']['checked'])) {
  992. print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, '', $sortfield, $sortorder, 'center ');
  993. }
  994. if (!empty($arrayfields['t.doc_ref']['checked'])) {
  995. print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder);
  996. }
  997. if (!empty($arrayfields['t.numero_compte']['checked'])) {
  998. print_liste_field_titre($arrayfields['t.numero_compte']['label'], $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder);
  999. }
  1000. if (!empty($arrayfields['t.subledger_account']['checked'])) {
  1001. print_liste_field_titre($arrayfields['t.subledger_account']['label'], $_SERVER['PHP_SELF'], "t.subledger_account", "", $param, "", $sortfield, $sortorder);
  1002. }
  1003. if (!empty($arrayfields['t.label_operation']['checked'])) {
  1004. print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder);
  1005. }
  1006. if (!empty($arrayfields['t.debit']['checked'])) {
  1007. print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right ');
  1008. }
  1009. if (!empty($arrayfields['t.credit']['checked'])) {
  1010. print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right ');
  1011. }
  1012. if (!empty($arrayfields['t.lettering_code']['checked'])) {
  1013. print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center ');
  1014. }
  1015. // Hook fields
  1016. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1017. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1018. print $hookmanager->resPrint;
  1019. if (!empty($arrayfields['t.date_creation']['checked'])) {
  1020. print_liste_field_titre($arrayfields['t.date_creation']['label'], $_SERVER['PHP_SELF'], "t.date_creation", "", $param, '', $sortfield, $sortorder, 'center ');
  1021. }
  1022. if (!empty($arrayfields['t.tms']['checked'])) {
  1023. print_liste_field_titre($arrayfields['t.tms']['label'], $_SERVER['PHP_SELF'], "t.tms", "", $param, '', $sortfield, $sortorder, 'center ');
  1024. }
  1025. if (!empty($arrayfields['t.date_export']['checked'])) {
  1026. print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export", "", $param, '', $sortfield, $sortorder, 'center ');
  1027. }
  1028. if (!empty($arrayfields['t.date_validated']['checked'])) {
  1029. print_liste_field_titre($arrayfields['t.date_validated']['label'], $_SERVER['PHP_SELF'], "t.date_validated", "", $param, '', $sortfield, $sortorder, 'center ');
  1030. }
  1031. if (!empty($arrayfields['t.import_key']['checked'])) {
  1032. print_liste_field_titre($arrayfields['t.import_key']['label'], $_SERVER["PHP_SELF"], "t.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
  1033. }
  1034. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  1035. print "</tr>\n";
  1036. $line = new BookKeepingLine();
  1037. // Loop on record
  1038. // --------------------------------------------------------------------
  1039. $i = 0;
  1040. $totalarray = array();
  1041. while ($i < min($num, $limit)) {
  1042. $obj = $db->fetch_object($resql);
  1043. if (empty($obj)) {
  1044. break; // Should not happen
  1045. }
  1046. $line->id = $obj->rowid;
  1047. $line->doc_date = $db->jdate($obj->doc_date);
  1048. $line->doc_type = $obj->doc_type;
  1049. $line->doc_ref = $obj->doc_ref;
  1050. $line->fk_doc = $obj->fk_doc;
  1051. $line->fk_docdet = $obj->fk_docdet;
  1052. $line->thirdparty_code = $obj->thirdparty_code;
  1053. $line->subledger_account = $obj->subledger_account;
  1054. $line->subledger_label = $obj->subledger_label;
  1055. $line->numero_compte = $obj->numero_compte;
  1056. $line->label_compte = $obj->label_compte;
  1057. $line->label_operation = $obj->label_operation;
  1058. $line->debit = $obj->debit;
  1059. $line->credit = $obj->credit;
  1060. $line->montant = $obj->amount; // deprecated
  1061. $line->amount = $obj->amount;
  1062. $line->sens = $obj->sens;
  1063. $line->lettering_code = $obj->lettering_code;
  1064. $line->fk_user_author = $obj->fk_user_author;
  1065. $line->import_key = $obj->import_key;
  1066. $line->code_journal = $obj->code_journal;
  1067. $line->journal_label = $obj->journal_label;
  1068. $line->piece_num = $obj->piece_num;
  1069. $line->date_creation = $db->jdate($obj->date_creation);
  1070. $line->date_modification = $db->jdate($obj->date_modification);
  1071. $line->date_export = $db->jdate($obj->date_export);
  1072. $line->date_validation = $db->jdate($obj->date_validation);
  1073. $total_debit += $line->debit;
  1074. $total_credit += $line->credit;
  1075. print '<tr class="oddeven">';
  1076. // Piece number
  1077. if (!empty($arrayfields['t.piece_num']['checked'])) {
  1078. print '<td>';
  1079. $object->id = $line->id;
  1080. $object->piece_num = $line->piece_num;
  1081. print $object->getNomUrl(1, '', 0, '', 1);
  1082. print '</td>';
  1083. if (!$i) {
  1084. $totalarray['nbfield']++;
  1085. }
  1086. }
  1087. // Journal code
  1088. if (!empty($arrayfields['t.code_journal']['checked'])) {
  1089. $accountingjournal = new AccountingJournal($db);
  1090. $result = $accountingjournal->fetch('', $line->code_journal);
  1091. $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal);
  1092. print '<td class="center">'.$journaltoshow.'</td>';
  1093. if (!$i) {
  1094. $totalarray['nbfield']++;
  1095. }
  1096. }
  1097. // Document date
  1098. if (!empty($arrayfields['t.doc_date']['checked'])) {
  1099. print '<td class="center">'.dol_print_date($line->doc_date, 'day').'</td>';
  1100. if (!$i) {
  1101. $totalarray['nbfield']++;
  1102. }
  1103. }
  1104. // Document ref
  1105. if (!empty($arrayfields['t.doc_ref']['checked'])) {
  1106. if ($line->doc_type == 'customer_invoice') {
  1107. $langs->loadLangs(array('bills'));
  1108. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  1109. $objectstatic = new Facture($db);
  1110. $objectstatic->fetch($line->fk_doc);
  1111. //$modulepart = 'facture';
  1112. $filename = dol_sanitizeFileName($line->doc_ref);
  1113. $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
  1114. $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
  1115. $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  1116. } elseif ($line->doc_type == 'supplier_invoice') {
  1117. $langs->loadLangs(array('bills'));
  1118. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  1119. $objectstatic = new FactureFournisseur($db);
  1120. $objectstatic->fetch($line->fk_doc);
  1121. //$modulepart = 'invoice_supplier';
  1122. $filename = dol_sanitizeFileName($line->doc_ref);
  1123. $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
  1124. $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
  1125. $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir);
  1126. } elseif ($line->doc_type == 'expense_report') {
  1127. $langs->loadLangs(array('trips'));
  1128. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  1129. $objectstatic = new ExpenseReport($db);
  1130. $objectstatic->fetch($line->fk_doc);
  1131. //$modulepart = 'expensereport';
  1132. $filename = dol_sanitizeFileName($line->doc_ref);
  1133. $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
  1134. $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
  1135. $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  1136. } elseif ($line->doc_type == 'bank') {
  1137. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  1138. $objectstatic = new AccountLine($db);
  1139. $objectstatic->fetch($line->fk_doc);
  1140. } else {
  1141. // Other type
  1142. }
  1143. $labeltoshow = '';
  1144. $labeltoshowalt = '';
  1145. if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') {
  1146. $labeltoshow .= $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
  1147. $labeltoshow .= $documentlink;
  1148. $labeltoshowalt .= $objectstatic->ref;
  1149. } elseif ($line->doc_type == 'bank') {
  1150. $labeltoshow .= $objectstatic->getNomUrl(1);
  1151. $labeltoshowalt .= $objectstatic->ref;
  1152. $bank_ref = strstr($line->doc_ref, '-');
  1153. $labeltoshow .= " " . $bank_ref;
  1154. $labeltoshowalt .= " " . $bank_ref;
  1155. } else {
  1156. $labeltoshow .= $line->doc_ref;
  1157. $labeltoshowalt .= $line->doc_ref;
  1158. }
  1159. print '<td class="nowraponall tdoverflowmax200" title="'.dol_escape_htmltag($labeltoshowalt).'">';
  1160. print $labeltoshow;
  1161. print "</td>\n";
  1162. if (!$i) {
  1163. $totalarray['nbfield']++;
  1164. }
  1165. }
  1166. // Account number
  1167. if (!empty($arrayfields['t.numero_compte']['checked'])) {
  1168. print '<td>'.length_accountg($line->numero_compte).'</td>';
  1169. if (!$i) {
  1170. $totalarray['nbfield']++;
  1171. }
  1172. }
  1173. // Subledger account
  1174. if (!empty($arrayfields['t.subledger_account']['checked'])) {
  1175. print '<td>'.length_accounta($line->subledger_account).'</td>';
  1176. if (!$i) {
  1177. $totalarray['nbfield']++;
  1178. }
  1179. }
  1180. // Label operation
  1181. if (!empty($arrayfields['t.label_operation']['checked'])) {
  1182. print '<td class="small tdoverflowmax200" title="'.dol_escape_htmltag($line->label_operation).'">'.dol_escape_htmltag($line->label_operation).'</td>';
  1183. if (!$i) {
  1184. $totalarray['nbfield']++;
  1185. }
  1186. }
  1187. // Amount debit
  1188. if (!empty($arrayfields['t.debit']['checked'])) {
  1189. print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
  1190. if (!$i) {
  1191. $totalarray['nbfield']++;
  1192. }
  1193. if (!$i) {
  1194. $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit';
  1195. }
  1196. $totalarray['val']['totaldebit'] += $line->debit;
  1197. }
  1198. // Amount credit
  1199. if (!empty($arrayfields['t.credit']['checked'])) {
  1200. print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
  1201. if (!$i) {
  1202. $totalarray['nbfield']++;
  1203. }
  1204. if (!$i) {
  1205. $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit';
  1206. }
  1207. $totalarray['val']['totalcredit'] += $line->credit;
  1208. }
  1209. // Lettering code
  1210. if (!empty($arrayfields['t.lettering_code']['checked'])) {
  1211. print '<td class="center">'.$line->lettering_code.'</td>';
  1212. if (!$i) {
  1213. $totalarray['nbfield']++;
  1214. }
  1215. }
  1216. // Fields from hook
  1217. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1218. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1219. print $hookmanager->resPrint;
  1220. // Creation operation date
  1221. if (!empty($arrayfields['t.date_creation']['checked'])) {
  1222. print '<td class="center">'.dol_print_date($line->date_creation, 'dayhour').'</td>';
  1223. if (!$i) {
  1224. $totalarray['nbfield']++;
  1225. }
  1226. }
  1227. // Modification operation date
  1228. if (!empty($arrayfields['t.tms']['checked'])) {
  1229. print '<td class="center">'.dol_print_date($line->date_modification, 'dayhour').'</td>';
  1230. if (!$i) {
  1231. $totalarray['nbfield']++;
  1232. }
  1233. }
  1234. // Exported operation date
  1235. if (!empty($arrayfields['t.date_export']['checked'])) {
  1236. print '<td class="center nowraponall">'.dol_print_date($line->date_export, 'dayhour').'</td>';
  1237. if (!$i) {
  1238. $totalarray['nbfield']++;
  1239. }
  1240. }
  1241. // Validated operation date
  1242. if (!empty($arrayfields['t.date_validated']['checked'])) {
  1243. print '<td class="center nowraponall">'.dol_print_date($line->date_validation, 'dayhour').'</td>';
  1244. if (!$i) {
  1245. $totalarray['nbfield']++;
  1246. }
  1247. }
  1248. if (!empty($arrayfields['t.import_key']['checked'])) {
  1249. print '<td class="tdoverflowmax100">'.$obj->import_key."</td>\n";
  1250. if (!$i) {
  1251. $totalarray['nbfield']++;
  1252. }
  1253. }
  1254. // Action column
  1255. print '<td class="nowraponall center">';
  1256. if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1257. $selected = 0;
  1258. if (in_array($line->id, $arrayofselected)) {
  1259. $selected = 1;
  1260. }
  1261. print '<input id="cb'.$line->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$line->id.'"'.($selected ? ' checked="checked"' : '').' />';
  1262. }
  1263. print '</td>';
  1264. if (!$i) {
  1265. $totalarray['nbfield']++;
  1266. }
  1267. print "</tr>\n";
  1268. $i++;
  1269. }
  1270. // Show total line
  1271. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1272. print "</table>";
  1273. print '</div>';
  1274. // TODO Replace this with mass delete action
  1275. //if ($user->rights->accounting->mouvements->supprimer_tous) {
  1276. // print '<div class="tabsAction tabsActionNoBottom">'."\n";
  1277. // print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear&token='.newToken().($param ? '&'.$param : '').'">'.$langs->trans("DeleteMvt").'</a>';
  1278. // print '</div>';
  1279. //}
  1280. print '</form>';
  1281. // End of page
  1282. llxFooter();
  1283. $db->close();