list.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  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-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  5. * Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  6. * Copyright (C) 2018 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 <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/accountancy/bookkeeping/list.php
  23. * \ingroup Advanced accountancy
  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/bookkeeping.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("accountancy"));
  36. $action = GETPOST('action', 'aZ09');
  37. $search_mvt_num = GETPOST('search_mvt_num', 'int');
  38. $search_doc_type = GETPOST("search_doc_type", 'alpha');
  39. $search_doc_ref = GETPOST("search_doc_ref", 'alpha');
  40. $search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int'));
  41. $search_date_end = dol_mktime(0, 0, 0, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int'));
  42. $search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
  43. $search_date_creation_start = dol_mktime(0, 0, 0, GETPOST('date_creation_startmonth', 'int'), GETPOST('date_creation_startday', 'int'), GETPOST('date_creation_startyear', 'int'));
  44. $search_date_creation_end = dol_mktime(0, 0, 0, GETPOST('date_creation_endmonth', 'int'), GETPOST('date_creation_endday', 'int'), GETPOST('date_creation_endyear', 'int'));
  45. $search_date_modification_start = dol_mktime(0, 0, 0, GETPOST('date_modification_startmonth', 'int'), GETPOST('date_modification_startday', 'int'), GETPOST('date_modification_startyear', 'int'));
  46. $search_date_modification_end = dol_mktime(0, 0, 0, GETPOST('date_modification_endmonth', 'int'), GETPOST('date_modification_endday', 'int'), GETPOST('date_modification_endyear', 'int'));
  47. //var_dump($search_date_start);exit;
  48. if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) {
  49. $action = 'delbookkeepingyear';
  50. }
  51. if (GETPOST("button_export_file_x") || GETPOST("button_export_file.x") || GETPOST("button_export_file")) {
  52. $action = 'export_file';
  53. }
  54. $search_accountancy_code = GETPOST("search_accountancy_code");
  55. $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
  56. if ($search_accountancy_code_start == - 1) {
  57. $search_accountancy_code_start = '';
  58. }
  59. $search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha');
  60. if ($search_accountancy_code_end == - 1) {
  61. $search_accountancy_code_end = '';
  62. }
  63. $search_accountancy_aux_code = GETPOST("search_accountancy_aux_code");
  64. $search_accountancy_aux_code_start = GETPOST('search_accountancy_aux_code_start', 'alpha');
  65. if ($search_accountancy_aux_code_start == - 1) {
  66. $search_accountancy_aux_code_start = '';
  67. }
  68. $search_accountancy_aux_code_end = GETPOST('search_accountancy_aux_code_end', 'alpha');
  69. if ($search_accountancy_aux_code_end == - 1) {
  70. $search_accountancy_aux_code_end = '';
  71. }
  72. $search_mvt_label = GETPOST('search_mvt_label', 'alpha');
  73. $search_direction = GETPOST('search_direction', 'alpha');
  74. $search_debit = GETPOST('search_debit', 'alpha');
  75. $search_credit = GETPOST('search_credit', 'alpha');
  76. $search_ledger_code = GETPOST('search_ledger_code', 'alpha');
  77. $search_lettering_code = GETPOST('search_lettering_code', 'alpha');
  78. // Load variable for pagination
  79. $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  80. $sortfield = GETPOST('sortfield', 'alpha');
  81. $sortorder = GETPOST('sortorder', 'alpha');
  82. $page = GETPOST('page','int');
  83. if (empty($page) || $page < 0) { $page = 0; }
  84. $offset = $limit * $page;
  85. $pageprev = $page - 1;
  86. $pagenext = $page + 1;
  87. if ($sortorder == "") $sortorder = "ASC";
  88. if ($sortfield == "") $sortfield = "t.piece_num,t.rowid";
  89. $object = new BookKeeping($db);
  90. $formaccounting = new FormAccounting($db);
  91. $formother = new FormOther($db);
  92. $form = new Form($db);
  93. if (! in_array($action, array('export_file', 'delmouv', 'delmouvconfirm')) && ! isset($_POST['begin']) && ! isset($_GET['begin']) && ! isset($_POST['formfilteraction']) && GETPOST('page','int') == '' && ! GETPOST('noreset','int'))
  94. {
  95. if (empty($search_date_start) && empty($search_date_end) && ! GETPOSTISSET('restore_lastsearch_values'))
  96. {
  97. $query = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
  98. $query.= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."' limit 1";
  99. $res = $db->query($query);
  100. if ($res->num_rows > 0) {
  101. $fiscalYear = $db->fetch_object($res);
  102. $search_date_start = strtotime($fiscalYear->date_start);
  103. $search_date_end = strtotime($fiscalYear->date_end);
  104. } else {
  105. $month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
  106. $year_start = dol_print_date(dol_now(), '%Y');
  107. if (dol_print_date(dol_now(), '%m') < $month_start) $year_start--; // If current month is lower that starting fiscal month, we start last year
  108. $year_end = $year_start + 1;
  109. $month_end = $month_start - 1;
  110. if ($month_end < 1)
  111. {
  112. $month_end = 12;
  113. $year_end--;
  114. }
  115. $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
  116. $search_date_end = dol_get_last_day($year_end, $month_end);
  117. }
  118. }
  119. }
  120. $arrayfields=array(
  121. 't.piece_num'=>array('label'=>$langs->trans("TransactionNumShort"), 'checked'=>1),
  122. 't.doc_date'=>array('label'=>$langs->trans("Docdate"), 'checked'=>1),
  123. 't.doc_ref'=>array('label'=>$langs->trans("Piece"), 'checked'=>1),
  124. 't.numero_compte'=>array('label'=>$langs->trans("AccountAccountingShort"), 'checked'=>1),
  125. 't.subledger_account'=>array('label'=>$langs->trans("SubledgerAccount"), 'checked'=>1),
  126. 't.label_operation'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
  127. 't.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1),
  128. 't.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1),
  129. 't.lettering_code'=>array('label'=>$langs->trans("LetteringCode"), 'checked'=>1),
  130. 't.code_journal'=>array('label'=>$langs->trans("Codejournal"), 'checked'=>1),
  131. 't.date_creation'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0),
  132. 't.tms'=>array('label'=>$langs->trans("DateModification"), 'checked'=>0),
  133. );
  134. if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) unset($arrayfields['t.lettering_code']);
  135. /*
  136. * Actions
  137. */
  138. if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
  139. if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  140. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  141. 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
  142. {
  143. $search_mvt_num = '';
  144. $search_doc_type = '';
  145. $search_doc_ref = '';
  146. $search_doc_date = '';
  147. $search_accountancy_code = '';
  148. $search_accountancy_code_start = '';
  149. $search_accountancy_code_end = '';
  150. $search_accountancy_aux_code = '';
  151. $search_accountancy_aux_code_start = '';
  152. $search_accountancy_aux_code_end = '';
  153. $search_mvt_label = '';
  154. $search_direction = '';
  155. $search_ledger_code = '';
  156. $search_date_start = '';
  157. $search_date_end = '';
  158. $search_date_creation_start = '';
  159. $search_date_creation_end = '';
  160. $search_date_modification_start = '';
  161. $search_date_modification_end = '';
  162. $search_debit = '';
  163. $search_credit = '';
  164. $search_lettering_code = '';
  165. }
  166. // Must be after the remove filter action, before the export.
  167. $param = '';
  168. $filter = array ();
  169. if (! empty($search_date_start)) {
  170. $filter['t.doc_date>='] = $search_date_start;
  171. $tmp=dol_getdate($search_date_start);
  172. $param .= '&search_date_startmonth=' . $tmp['mon'] . '&search_date_startday=' . $tmp['mday'] . '&search_date_startyear=' . $tmp['year'];
  173. }
  174. if (! empty($search_date_end)) {
  175. $filter['t.doc_date<='] = $search_date_end;
  176. $tmp=dol_getdate($search_date_end);
  177. $param .= '&search_date_endmonth=' . $tmp['mon'] . '&search_date_endday=' . $tmp['mday'] . '&search_date_endyear=' . $tmp['year'];
  178. }
  179. if (! empty($search_doc_date)) {
  180. $filter['t.doc_date'] = $search_doc_date;
  181. $tmp=dol_getdate($search_doc_date);
  182. $param .= '&doc_datemonth=' . $tmp['mon'] . '&doc_dateday=' . $tmp['mday'] . '&doc_dateyear=' . $tmp['year'];
  183. }
  184. if (! empty($search_doc_type)) {
  185. $filter['t.doc_type'] = $search_doc_type;
  186. $param .= '&search_doc_type=' . urlencode($search_doc_type);
  187. }
  188. if (! empty($search_doc_ref)) {
  189. $filter['t.doc_ref'] = $search_doc_ref;
  190. $param .= '&search_doc_ref=' . urlencode($search_doc_ref);
  191. }
  192. if (! empty($search_accountancy_code)) {
  193. $filter['t.numero_compte'] = $search_accountancy_code;
  194. $param .= '&search_accountancy_code=' . urlencode($search_accountancy_code);
  195. }
  196. if (! empty($search_accountancy_code_start)) {
  197. $filter['t.numero_compte>='] = $search_accountancy_code_start;
  198. $param .= '&search_accountancy_code_start=' . urlencode($search_accountancy_code_start);
  199. }
  200. if (! empty($search_accountancy_code_end)) {
  201. $filter['t.numero_compte<='] = $search_accountancy_code_end;
  202. $param .= '&search_accountancy_code_end=' . urlencode($search_accountancy_code_end);
  203. }
  204. if (! empty($search_accountancy_aux_code)) {
  205. $filter['t.subledger_account'] = $search_accountancy_aux_code;
  206. $param .= '&search_accountancy_aux_code=' . urlencode($search_accountancy_aux_code);
  207. }
  208. if (! empty($search_accountancy_aux_code_start)) {
  209. $filter['t.subledger_account>='] = $search_accountancy_aux_code_start;
  210. $param .= '&search_accountancy_aux_code_start=' . urlencode($search_accountancy_aux_code_start);
  211. }
  212. if (! empty($search_accountancy_aux_code_end)) {
  213. $filter['t.subledger_account<='] = $search_accountancy_aux_code_end;
  214. $param .= '&search_accountancy_aux_code_end=' . urlencode($search_accountancy_aux_code_end);
  215. }
  216. if (! empty($search_mvt_label)) {
  217. $filter['t.label_operation'] = $search_mvt_label;
  218. $param .= '&search_mvt_label=' . urlencode($search_mvt_label);
  219. }
  220. if (! empty($search_direction)) {
  221. $filter['t.sens'] = $search_direction;
  222. $param .= '&search_direction=' . urlencode($search_direction);
  223. }
  224. if (! empty($search_ledger_code)) {
  225. $filter['t.code_journal'] = $search_ledger_code;
  226. $param .= '&search_ledger_code=' . urlencode($search_ledger_code);
  227. }
  228. if (! empty($search_mvt_num)) {
  229. $filter['t.piece_num'] = $search_mvt_num;
  230. $param .= '&search_mvt_num=' . urlencode($search_mvt_num);
  231. }
  232. if (! empty($search_date_creation_start)) {
  233. $filter['t.date_creation>='] = $search_date_creation_start;
  234. $tmp=dol_getdate($search_date_creation_start);
  235. $param .= '&date_creation_startmonth=' . $tmp['mon'] . '&date_creation_startday=' . $tmp['mday'] . '&date_creation_startyear=' . $tmp['year'];
  236. }
  237. if (! empty($search_date_creation_end)) {
  238. $filter['t.date_creation<='] = $search_date_creation_end;
  239. $tmp=dol_getdate($search_date_creation_end);
  240. $param .= '&date_creation_endmonth=' . $tmp['mon'] . '&date_creation_endday=' . $tmp['mday'] . '&date_creation_endyear=' . $tmp['year'];
  241. }
  242. if (! empty($search_date_modification_start)) {
  243. $filter['t.tms>='] = $search_date_modification_start;
  244. $tmp=dol_getdate($search_date_modification_start);
  245. $param .= '&date_modification_startmonth=' . $tmp['mon'] . '&date_modification_startday=' . $tmp['mday'] . '&date_modification_startyear=' . $tmp['year'];
  246. }
  247. if (! empty($search_date_modification_end)) {
  248. $filter['t.tms<='] = $search_date_modification_end;
  249. $tmp=dol_getdate($search_date_modification_end);
  250. $param .= '&date_modification_endmonth=' . $tmp['mon'] . '&date_modification_endday=' . $tmp['mday'] . '&date_modification_endyear=' . $tmp['year'];
  251. }
  252. if (! empty($search_debit)) {
  253. $filter['t.debit'] = $search_debit;
  254. $param .= '&search_debit=' . urlencode($search_debit);
  255. }
  256. if (! empty($search_credit)) {
  257. $filter['t.credit'] = $search_credit;
  258. $param .= '&search_credit=' . urlencode($search_credit);
  259. }
  260. if (! empty($search_lettering_code)) {
  261. $filter['t.lettering_code'] = $search_lettering_code;
  262. $param .= '&search_lettering_code=' . urlencode($search_lettering_code);
  263. }
  264. if ($action == 'delbookkeeping') {
  265. $import_key = GETPOST('importkey', 'alpha');
  266. if (! empty($import_key)) {
  267. $result = $object->deleteByImportkey($import_key);
  268. if ($result < 0) {
  269. setEventMessages($object->error, $object->errors, 'errors');
  270. }
  271. Header("Location: list.php");
  272. exit();
  273. }
  274. }
  275. if ($action == 'delbookkeepingyearconfirm') {
  276. $delyear = GETPOST('delyear', 'int');
  277. if ($delyear==-1) {
  278. $delyear=0;
  279. }
  280. $deljournal = GETPOST('deljournal','alpha');
  281. if ($deljournal==-1) {
  282. $deljournal=0;
  283. }
  284. if (! empty($delyear) || ! empty($deljournal))
  285. {
  286. $result = $object->deleteByYearAndJournal($delyear,$deljournal);
  287. if ($result < 0) {
  288. setEventMessages($object->error, $object->errors, 'errors');
  289. }
  290. else
  291. {
  292. setEventMessages("RecordDeleted", null, 'mesgs');
  293. }
  294. Header("Location: list.php");
  295. exit;
  296. }
  297. else
  298. {
  299. setEventMessages("NoRecordDeleted", null, 'warnings');
  300. Header("Location: list.php");
  301. exit;
  302. }
  303. }
  304. if ($action == 'delmouvconfirm') {
  305. $mvt_num = GETPOST('mvt_num', 'int');
  306. if (! empty($mvt_num)) {
  307. $result = $object->deleteMvtNum($mvt_num);
  308. if ($result < 0) {
  309. setEventMessages($object->error, $object->errors, 'errors');
  310. }
  311. else
  312. {
  313. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  314. }
  315. Header("Location: list.php?noreset=1".($param?'&'.$param:''));
  316. exit;
  317. }
  318. }
  319. // Export into a file with format defined into setup (FEC, CSV, ...)
  320. if ($action == 'export_file') {
  321. $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter);
  322. if ($result < 0)
  323. {
  324. setEventMessages($object->error, $object->errors, 'errors');
  325. }
  326. else
  327. {
  328. $accountancyexport = new AccountancyExport($db);
  329. $accountancyexport->export($object->lines);
  330. if (!empty($accountancyexport->errors))
  331. {
  332. setEventMessages('', $accountancyexport->errors, 'errors');
  333. }
  334. exit;
  335. }
  336. }
  337. /*
  338. * View
  339. */
  340. $title_page = $langs->trans("Bookkeeping");
  341. llxHeader('', $title_page);
  342. // List
  343. $nbtotalofrecords = '';
  344. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  345. $nbtotalofrecords = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter);
  346. if ($nbtotalofrecords < 0) {
  347. setEventMessages($object->error, $object->errors, 'errors');
  348. }
  349. }
  350. // TODO Do not use this
  351. $result = $object->fetchAll($sortorder, $sortfield, $limit, $offset, $filter);
  352. if ($result < 0) {
  353. setEventMessages($object->error, $object->errors, 'errors');
  354. }
  355. $num=count($object->lines);
  356. if ($action == 'delmouv') {
  357. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?mvt_num='.GETPOST('mvt_num').$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvtPartial'), 'delmouvconfirm', '', 0, 1);
  358. print $formconfirm;
  359. }
  360. if ($action == 'delbookkeepingyear') {
  361. $form_question = array ();
  362. $delyear = GETPOST('delyear');
  363. $deljournal = GETPOST('deljournal');
  364. if (empty($delyear)) {
  365. $delyear = dol_print_date(dol_now(), '%Y');
  366. }
  367. $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
  368. $journal_array = $formaccounting->select_journal($deljournal, 'deljournal', '', 1, 1, 1, '', 0, 1);
  369. $form_question['delyear'] = array (
  370. 'name' => 'delyear',
  371. 'type' => 'select',
  372. 'label' => $langs->trans('DelYear'),
  373. 'values' => $year_array,
  374. 'default' => $delyear
  375. );
  376. $form_question['deljournal'] = array (
  377. 'name' => 'deljournal',
  378. 'type' => 'other', // We don't use select here, the journal_array is already a select html component
  379. 'label' => $langs->trans('DelJournal'),
  380. 'value' => $journal_array,
  381. 'default' => $deljournal
  382. );
  383. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delbookkeepingyearconfirm', $form_question, 0, 1, 250);
  384. print $formconfirm;
  385. }
  386. //$param=''; param started before
  387. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  388. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  389. print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '">';
  390. print '<input type="hidden" name="action" value="list">';
  391. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  392. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  393. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  394. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  395. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  396. print '<input type="hidden" name="page" value="'.$page.'">';
  397. $listofformat=AccountancyExport::getType();
  398. $button = '<a class="butAction" name="button_export_file" href="'.$_SERVER["PHP_SELF"].'?action=export_file'.($param?'&'.$param:'').'">';
  399. if (count($filter)) $button.= $langs->trans("ExportFilteredList");
  400. else $button.= $langs->trans("ExportList");
  401. //$button.=' ('.$listofformat[$conf->global->ACCOUNTING_EXPORT_MODELCSV].')';
  402. $button.= '</a>';
  403. $groupby = ' <a class="nohover marginrightonly" href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param.'">' . $langs->trans("GroupByAccountAccounting") . '</a>';
  404. $newcardbutton = '<a class="butActionNew" href="./card.php?action=create"><span class="valignmiddle">' . $langs->trans("NewAccountingMvt").'</span>';
  405. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  406. $newcardbutton.= '</a>';
  407. print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $button, $result, $nbtotalofrecords, 'title_accountancy', 0, $groupby.$newcardbutton, '', $limit);
  408. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  409. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  410. if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  411. print '<div class="div-table-responsive">';
  412. print '<table class="tagtable liste" width="100%">';
  413. // Filters lines
  414. print '<tr class="liste_titre_filter">';
  415. // Movement number
  416. if (! empty($arrayfields['t.piece_num']['checked']))
  417. {
  418. print '<td class="liste_titre"><input type="text" name="search_mvt_num" size="6" value="' . dol_escape_htmltag($search_mvt_num) . '"></td>';
  419. }
  420. // Date document
  421. if (! empty($arrayfields['t.doc_date']['checked']))
  422. {
  423. print '<td class="liste_titre center">';
  424. print '<div class="nowrap">';
  425. print $langs->trans('From') . ' ';
  426. print $form->selectDate($search_date_start?$search_date_start:-1, 'search_date_start', 0, 0, 1);
  427. print '</div>';
  428. print '<div class="nowrap">';
  429. print $langs->trans('to') . ' ';
  430. print $form->selectDate($search_date_end?$search_date_end:-1, 'search_date_end', 0, 0, 1);
  431. print '</div>';
  432. print '</td>';
  433. }
  434. // Ref document
  435. if (! empty($arrayfields['t.doc_ref']['checked']))
  436. {
  437. print '<td class="liste_titre"><input type="text" name="search_doc_ref" size="8" value="' . dol_escape_htmltag($search_doc_ref) . '"></td>';
  438. }
  439. // Accountancy account
  440. if (! empty($arrayfields['t.numero_compte']['checked']))
  441. {
  442. print '<td class="liste_titre">';
  443. print '<div class="nowrap">';
  444. print $langs->trans('From').' ';
  445. print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, 'maxwidth200');
  446. print '</div>';
  447. print '<div class="nowrap">';
  448. print $langs->trans('to').' ';
  449. print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, 'maxwidth200');
  450. print '</div>';
  451. print '</td>';
  452. }
  453. // Subledger account
  454. if (! empty($arrayfields['t.subledger_account']['checked']))
  455. {
  456. print '<td class="liste_titre">';
  457. print '<div class="nowrap">';
  458. print $langs->trans('From').' ';
  459. // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not
  460. // use setup of keypress to select thirdparty and this hang browser on large database.
  461. if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX))
  462. {
  463. print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1);
  464. }
  465. else
  466. {
  467. print '<input type="text" name="search_accountancy_aux_code_start" value="'.$search_accountancy_aux_code_start.'">';
  468. }
  469. print '</div>';
  470. print '<div class="nowrap">';
  471. print $langs->trans('to').' ';
  472. // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not
  473. // use setup of keypress to select thirdparty and this hang browser on large database.
  474. if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX))
  475. {
  476. print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1);
  477. }
  478. else
  479. {
  480. print '<input type="text" name="search_accountancy_aux_code_end" value="'.$search_accountancy_aux_code_end.'">';
  481. }
  482. print '</div>';
  483. print '</td>';
  484. }
  485. // Label operation
  486. if (! empty($arrayfields['t.label_operation']['checked']))
  487. {
  488. print '<td class="liste_titre">';
  489. print '<input type="text" size="7" class="flat" name="search_mvt_label" value="' . $search_mvt_label . '"/>';
  490. print '</td>';
  491. }
  492. // Debit
  493. if (! empty($arrayfields['t.debit']['checked']))
  494. {
  495. print '<td class="liste_titre" align="right">';
  496. print '<input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'">';
  497. print '</td>';
  498. }
  499. // Credit
  500. if (! empty($arrayfields['t.credit']['checked']))
  501. {
  502. print '<td class="liste_titre" align="right">';
  503. print '<input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'">';
  504. print '</td>';
  505. }
  506. // Lettering code
  507. if (! empty($arrayfields['t.lettering_code']['checked']))
  508. {
  509. print '<td class="liste_titre center">';
  510. print '<input type="text" size="3" class="flat" name="search_lettering_code" value="' . $search_lettering_code . '"/>';
  511. print '</td>';
  512. }
  513. // Code journal
  514. if (! empty($arrayfields['t.code_journal']['checked']))
  515. {
  516. print '<td class="liste_titre center"><input type="text" name="search_ledger_code" size="3" value="' . $search_ledger_code . '"></td>';
  517. }
  518. // Date creation
  519. if (! empty($arrayfields['t.date_creation']['checked']))
  520. {
  521. print '<td class="liste_titre center">';
  522. print '<div class="nowrap">';
  523. print $langs->trans('From') . ' ';
  524. print $form->selectDate($search_date_creation_start, 'date_creation_start', 0, 0, 1);
  525. print '</div>';
  526. print '<div class="nowrap">';
  527. print $langs->trans('to') . ' ';
  528. print $form->selectDate($search_date_creation_end, 'date_creation_end', 0, 0, 1);
  529. print '</div>';
  530. print '</td>';
  531. }
  532. // Date modification
  533. if (! empty($arrayfields['t.tms']['checked']))
  534. {
  535. print '<td class="liste_titre center">';
  536. print '<div class="nowrap">';
  537. print $langs->trans('From') . ' ';
  538. print $form->selectDate($search_date_modification_start, 'date_modification_start', 0, 0, 1);
  539. print '</div>';
  540. print '<div class="nowrap">';
  541. print $langs->trans('to') . ' ';
  542. print $form->selectDate($search_date_modification_end, 'date_modification_end', 0, 0, 1);
  543. print '</div>';
  544. print '</td>';
  545. }
  546. // Action column
  547. print '<td class="liste_titre center">';
  548. $searchpicto=$form->showFilterButtons();
  549. print $searchpicto;
  550. print '</td>';
  551. print "</tr>\n";
  552. print '<tr class="liste_titre">';
  553. if (! empty($arrayfields['t.piece_num']['checked'])) print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, "", $sortfield, $sortorder);
  554. if (! empty($arrayfields['t.doc_date']['checked'])) print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, 'align="center"', $sortfield, $sortorder);
  555. if (! empty($arrayfields['t.doc_ref']['checked'])) print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder);
  556. if (! empty($arrayfields['t.numero_compte']['checked'])) print_liste_field_titre($arrayfields['t.numero_compte']['label'], $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder);
  557. if (! empty($arrayfields['t.subledger_account']['checked'])) print_liste_field_titre($arrayfields['t.subledger_account']['label'], $_SERVER['PHP_SELF'], "t.subledger_account", "", $param, "", $sortfield, $sortorder);
  558. if (! empty($arrayfields['t.label_operation']['checked'])) print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder);
  559. if (! empty($arrayfields['t.debit']['checked'])) print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, 'align="right"', $sortfield, $sortorder);
  560. if (! empty($arrayfields['t.credit']['checked'])) print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, 'align="right"', $sortfield, $sortorder);
  561. if (! empty($arrayfields['t.lettering_code']['checked'])) print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, 'align="center"', $sortfield, $sortorder);
  562. if (! empty($arrayfields['t.code_journal']['checked'])) print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, 'align="center"', $sortfield, $sortorder);
  563. if (! empty($arrayfields['t.date_creation']['checked'])) print_liste_field_titre($arrayfields['t.date_creation']['label'], $_SERVER['PHP_SELF'], "t.date_creation", "", $param, 'align="center"', $sortfield, $sortorder);
  564. if (! empty($arrayfields['t.tms']['checked'])) print_liste_field_titre($arrayfields['t.tms']['label'], $_SERVER['PHP_SELF'], "t.tms", "", $param, 'align="center"', $sortfield, $sortorder);
  565. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  566. print "</tr>\n";
  567. if ($num > 0)
  568. {
  569. $i=0;
  570. $totalarray=array();
  571. while ($i < min($num, $limit))
  572. {
  573. $line = $object->lines[$i];
  574. $total_debit += $line->debit;
  575. $total_credit += $line->credit;
  576. print '<tr class="oddeven">';
  577. // Piece number
  578. if (! empty($arrayfields['t.piece_num']['checked']))
  579. {
  580. print '<td>';
  581. $object->id = $line->id;
  582. $object->piece_num = $line->piece_num;
  583. print $object->getNomUrl(1,'',0,'',1);
  584. print '</td>';
  585. if (! $i) $totalarray['nbfield']++;
  586. }
  587. // Document date
  588. if (! empty($arrayfields['t.doc_date']['checked']))
  589. {
  590. print '<td align="center">' . dol_print_date($line->doc_date, 'day') . '</td>';
  591. if (! $i) $totalarray['nbfield']++;
  592. }
  593. // Document ref
  594. if (! empty($arrayfields['t.doc_ref']['checked']))
  595. {
  596. print '<td class="nowrap">' . $line->doc_ref . '</td>';
  597. if (! $i) $totalarray['nbfield']++;
  598. }
  599. // Account number
  600. if (! empty($arrayfields['t.numero_compte']['checked']))
  601. {
  602. print '<td>' . length_accountg($line->numero_compte) . '</td>';
  603. if (! $i) $totalarray['nbfield']++;
  604. }
  605. // Subledger account
  606. if (! empty($arrayfields['t.subledger_account']['checked']))
  607. {
  608. print '<td>' . length_accounta($line->subledger_account) . '</td>';
  609. if (! $i) $totalarray['nbfield']++;
  610. }
  611. // Label operation
  612. if (! empty($arrayfields['t.label_operation']['checked']))
  613. {
  614. print '<td>' . $line->label_operation . '</td>';
  615. if (! $i) $totalarray['nbfield']++;
  616. }
  617. // Amount debit
  618. if (! empty($arrayfields['t.debit']['checked']))
  619. {
  620. print '<td class="right">' . ($line->debit ? price($line->debit) : ''). '</td>';
  621. if (! $i) $totalarray['nbfield']++;
  622. if (! $i) $totalarray['totaldebitfield']=$totalarray['nbfield'];
  623. $totalarray['totaldebit'] += $line->debit;
  624. }
  625. // Amount credit
  626. if (! empty($arrayfields['t.credit']['checked']))
  627. {
  628. print '<td class="right">' . ($line->credit ? price($line->credit) : '') . '</td>';
  629. if (! $i) $totalarray['nbfield']++;
  630. if (! $i) $totalarray['totalcreditfield']=$totalarray['nbfield'];
  631. $totalarray['totalcredit'] += $line->credit;
  632. }
  633. // Lettering code
  634. if (! empty($arrayfields['t.lettering_code']['checked']))
  635. {
  636. print '<td align="center">' . $line->lettering_code . '</td>';
  637. if (! $i) $totalarray['nbfield']++;
  638. }
  639. // Journal code
  640. if (! empty($arrayfields['t.code_journal']['checked']))
  641. {
  642. $accountingjournal = new AccountingJournal($db);
  643. $result = $accountingjournal->fetch('',$line->code_journal);
  644. $journaltoshow = (($result > 0)?$accountingjournal->getNomUrl(0,0,0,'',0) : $line->code_journal);
  645. print '<td align="center">' . $journaltoshow . '</td>';
  646. if (! $i) $totalarray['nbfield']++;
  647. }
  648. // Creation operation date
  649. if (! empty($arrayfields['t.date_creation']['checked']))
  650. {
  651. print '<td align="center">' . dol_print_date($line->date_creation, 'dayhour') . '</td>';
  652. if (! $i) $totalarray['nbfield']++;
  653. }
  654. // Modification operation date
  655. if (! empty($arrayfields['t.tms']['checked']))
  656. {
  657. print '<td align="center">' . dol_print_date($line->date_modification, 'dayhour') . '</td>';
  658. if (! $i) $totalarray['nbfield']++;
  659. }
  660. // Action column
  661. print '<td align="center" class="nowraponall">';
  662. print '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?piece_num=' . $line->piece_num . $param . '&page=' . $page . ($sortfield ? '&sortfield='.$sortfield : '') . ($sortorder ? '&sortorder='.$sortorder : '') . '">' . img_edit() . '</a>&nbsp;';
  663. print '<a href="' . $_SERVER['PHP_SELF'] . '?action=delmouv&mvt_num=' . $line->piece_num . $param . '&page=' . $page . ($sortfield ? '&sortfield='.$sortfield : '') . ($sortorder ? '&sortorder='.$sortorder : '') . '">' . img_delete() . '</a>';
  664. print '</td>';
  665. if (! $i) $totalarray['nbfield']++;
  666. print "</tr>\n";
  667. $i++;
  668. }
  669. // Show total line
  670. if (isset($totalarray['totaldebitfield']) || isset($totalarray['totalcreditfield']))
  671. {
  672. $i=0;
  673. print '<tr class="liste_total">';
  674. while ($i < $totalarray['nbfield'])
  675. {
  676. $i++;
  677. if ($i == 1)
  678. {
  679. if ($num < $limit && empty($offset)) print '<td class="left">'.$langs->trans("Total").'</td>';
  680. else print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
  681. }
  682. elseif ($totalarray['totaldebitfield'] == $i) print '<td class="right">'.price($totalarray['totaldebit']).'</td>';
  683. elseif ($totalarray['totalcreditfield'] == $i) print '<td class="right">'.price($totalarray['totalcredit']).'</td>';
  684. else print '<td></td>';
  685. }
  686. print '</tr>';
  687. }
  688. }
  689. print "</table>";
  690. print '</div>';
  691. // TODO Replace this with mass delete action
  692. print '<div class="tabsAction tabsActionNoBottom">' . "\n";
  693. print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear'.($param?'&'.$param:'').'">' . $langs->trans("DeleteMvt") . '</a>';
  694. print '</div>';
  695. print '</form>';
  696. // End of page
  697. llxFooter();
  698. $db->close();