listbyaccount.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. <?php
  2. /* Copyright (C) 2016 Neil Orley <neil.orley@oeris.fr>
  3. * Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
  4. * Copyright (C) 2013-2020 Florian Henry <florian.henry@open-concept.pro>
  5. * Copyright (C) 2013-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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 <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/accountancy/bookkeeping/listbyaccount.php
  23. * \ingroup Accountancy (Double entries)
  24. * \brief List operation of ledger ordered by account number
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/lettering.class.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.formaccounting.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/lib/date.lib.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("accountancy", "compta"));
  37. $action = GETPOST('action', 'aZ09');
  38. $massaction = GETPOST('massaction', 'alpha');
  39. $confirm = GETPOST('confirm', 'alpha');
  40. $toselect = GETPOST('toselect', 'array');
  41. $type = GETPOST('type', 'alpha');
  42. if ($type == 'sub') {
  43. $context_default = 'bookkeepingbysubaccountlist';
  44. } else {
  45. $context_default = 'bookkeepingbyaccountlist';
  46. }
  47. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : $context_default;
  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_export_startyear = GETPOST('search_date_export_startyear', 'int');
  58. $search_date_export_startmonth = GETPOST('search_date_export_startmonth', 'int');
  59. $search_date_export_startday = GETPOST('search_date_export_startday', 'int');
  60. $search_date_export_endyear = GETPOST('search_date_export_endyear', 'int');
  61. $search_date_export_endmonth = GETPOST('search_date_export_endmonth', 'int');
  62. $search_date_export_endday = GETPOST('search_date_export_endday', 'int');
  63. $search_date_export_start = dol_mktime(0, 0, 0, $search_date_export_startmonth, $search_date_export_startday, $search_date_export_startyear);
  64. $search_date_export_end = dol_mktime(23, 59, 59, $search_date_export_endmonth, $search_date_export_endday, $search_date_export_endyear);
  65. $search_date_validation_startyear = GETPOST('search_date_validation_startyear', 'int');
  66. $search_date_validation_startmonth = GETPOST('search_date_validation_startmonth', 'int');
  67. $search_date_validation_startday = GETPOST('search_date_validation_startday', 'int');
  68. $search_date_validation_endyear = GETPOST('search_date_validation_endyear', 'int');
  69. $search_date_validation_endmonth = GETPOST('search_date_validation_endmonth', 'int');
  70. $search_date_validation_endday = GETPOST('search_date_validation_endday', 'int');
  71. $search_date_validation_start = dol_mktime(0, 0, 0, $search_date_validation_startmonth, $search_date_validation_startday, $search_date_validation_startyear);
  72. $search_date_validation_end = dol_mktime(23, 59, 59, $search_date_validation_endmonth, $search_date_validation_endday, $search_date_validation_endyear);
  73. $search_import_key = GETPOST("search_import_key", 'alpha');
  74. $search_accountancy_code = GETPOST("search_accountancy_code");
  75. $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
  76. if ($search_accountancy_code_start == - 1) {
  77. $search_accountancy_code_start = '';
  78. }
  79. $search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha');
  80. if ($search_accountancy_code_end == - 1) {
  81. $search_accountancy_code_end = '';
  82. }
  83. $search_doc_ref = GETPOST('search_doc_ref', 'alpha');
  84. $search_label_operation = GETPOST('search_label_operation', 'alpha');
  85. $search_mvt_num = GETPOST('search_mvt_num', 'int');
  86. $search_direction = GETPOST('search_direction', 'alpha');
  87. $search_ledger_code = GETPOST('search_ledger_code', 'array');
  88. $search_debit = GETPOST('search_debit', 'alpha');
  89. $search_credit = GETPOST('search_credit', 'alpha');
  90. $search_lettering_code = GETPOST('search_lettering_code', 'alpha');
  91. $search_not_reconciled = GETPOST('search_not_reconciled', 'alpha');
  92. if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) {
  93. $action = 'delbookkeepingyear';
  94. }
  95. // Load variable for pagination
  96. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  97. $sortfield = GETPOST('sortfield', 'aZ09comma');
  98. $sortorder = GETPOST('sortorder', 'aZ09comma');
  99. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  100. if (empty($page) || $page < 0) {
  101. $page = 0;
  102. }
  103. $offset = $limit * $page;
  104. $pageprev = $page - 1;
  105. $pagenext = $page + 1;
  106. if ($sortorder == "") {
  107. $sortorder = "ASC";
  108. }
  109. if ($sortfield == "") {
  110. $sortfield = "t.doc_date,t.rowid";
  111. }
  112. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  113. $object = new BookKeeping($db);
  114. $formfile = new FormFile($db);
  115. $hookmanager->initHooks(array($context_default));
  116. $formaccounting = new FormAccounting($db);
  117. $form = new Form($db);
  118. if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('search_date_startday') && !GETPOSTISSET('search_date_startmonth') && !GETPOSTISSET('search_date_starthour')) {
  119. $sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
  120. $sql .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'";
  121. $sql .= $db->plimit(1);
  122. $res = $db->query($sql);
  123. if ($res->num_rows > 0) {
  124. $fiscalYear = $db->fetch_object($res);
  125. $search_date_start = strtotime($fiscalYear->date_start);
  126. $search_date_end = strtotime($fiscalYear->date_end);
  127. } else {
  128. $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
  129. $year_start = dol_print_date(dol_now(), '%Y');
  130. if (dol_print_date(dol_now(), '%m') < $month_start) {
  131. $year_start--; // If current month is lower that starting fiscal month, we start last year
  132. }
  133. $year_end = $year_start + 1;
  134. $month_end = $month_start - 1;
  135. if ($month_end < 1) {
  136. $month_end = 12;
  137. $year_end--;
  138. }
  139. $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
  140. $search_date_end = dol_get_last_day($year_end, $month_end);
  141. }
  142. }
  143. $arrayfields = array(
  144. // 't.subledger_account'=>array('label'=>$langs->trans("SubledgerAccount"), 'checked'=>1),
  145. 't.piece_num'=>array('label'=>$langs->trans("TransactionNumShort"), 'checked'=>1),
  146. 't.code_journal'=>array('label'=>$langs->trans("Codejournal"), 'checked'=>1),
  147. 't.doc_date'=>array('label'=>$langs->trans("Docdate"), 'checked'=>1),
  148. 't.doc_ref'=>array('label'=>$langs->trans("Piece"), 'checked'=>1),
  149. 't.label_operation'=>array('label'=>$langs->trans("Label"), 'checked'=>1),
  150. 't.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1),
  151. 't.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1),
  152. 't.lettering_code'=>array('label'=>$langs->trans("LetteringCode"), 'checked'=>1),
  153. 't.date_export'=>array('label'=>$langs->trans("DateExport"), 'checked'=>1),
  154. 't.date_validated'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1),
  155. 't.import_key'=>array('label'=>$langs->trans("ImportId"), 'checked'=>0, 'position'=>1100),
  156. );
  157. if (empty($conf->global->ACCOUNTING_ENABLE_LETTERING)) {
  158. unset($arrayfields['t.lettering_code']);
  159. }
  160. if ($search_date_start && empty($search_date_startyear)) {
  161. $tmparray = dol_getdate($search_date_start);
  162. $search_date_startyear = $tmparray['year'];
  163. $search_date_startmonth = $tmparray['mon'];
  164. $search_date_startday = $tmparray['mday'];
  165. }
  166. if ($search_date_end && empty($search_date_endyear)) {
  167. $tmparray = dol_getdate($search_date_end);
  168. $search_date_endyear = $tmparray['year'];
  169. $search_date_endmonth = $tmparray['mon'];
  170. $search_date_endday = $tmparray['mday'];
  171. }
  172. if (empty($conf->accounting->enabled)) {
  173. accessforbidden();
  174. }
  175. if ($user->socid > 0) {
  176. accessforbidden();
  177. }
  178. if (empty($user->rights->accounting->mouvements->lire)) {
  179. accessforbidden();
  180. }
  181. /*
  182. * Action
  183. */
  184. $param = '';
  185. if (GETPOST('cancel', 'alpha')) {
  186. $action = 'list';
  187. $massaction = '';
  188. }
  189. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'preunlettering' && $massaction != 'predeletebookkeepingwriting') {
  190. $massaction = '';
  191. }
  192. $parameters = array('socid'=>$socid);
  193. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  194. if ($reshook < 0) {
  195. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  196. }
  197. if (empty($reshook)) {
  198. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  199. 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
  200. $search_doc_date = '';
  201. $search_accountancy_code = '';
  202. $search_accountancy_code_start = '';
  203. $search_accountancy_code_end = '';
  204. $search_label_account = '';
  205. $search_doc_ref = '';
  206. $search_label_operation = '';
  207. $search_mvt_num = '';
  208. $search_direction = '';
  209. $search_ledger_code = array();
  210. $search_date_start = '';
  211. $search_date_end = '';
  212. $search_date_startyear = '';
  213. $search_date_startmonth = '';
  214. $search_date_startday = '';
  215. $search_date_endyear = '';
  216. $search_date_endmonth = '';
  217. $search_date_endday = '';
  218. $search_date_export_start = '';
  219. $search_date_export_end = '';
  220. $search_date_export_startyear = '';
  221. $search_date_export_startmonth = '';
  222. $search_date_export_startday = '';
  223. $search_date_export_endyear = '';
  224. $search_date_export_endmonth = '';
  225. $search_date_export_endday = '';
  226. $search_date_validation_start = '';
  227. $search_date_validation_end = '';
  228. $search_date_validation_startyear = '';
  229. $search_date_validation_startmonth = '';
  230. $search_date_validation_startday = '';
  231. $search_date_validation_endyear = '';
  232. $search_date_validation_endmonth = '';
  233. $search_date_validation_endday = '';
  234. $search_debit = '';
  235. $search_credit = '';
  236. $search_lettering_code = '';
  237. $search_not_reconciled = '';
  238. $search_import_key = '';
  239. $toselect = array();
  240. }
  241. // Must be after the remove filter action, before the export.
  242. $filter = array();
  243. if (!empty($search_date_start)) {
  244. $filter['t.doc_date>='] = $search_date_start;
  245. $param .= '&search_date_startmonth='.$search_date_startmonth.'&search_date_startday='.$search_date_startday.'&search_date_startyear='.$search_date_startyear;
  246. }
  247. if (!empty($search_date_end)) {
  248. $filter['t.doc_date<='] = $search_date_end;
  249. $param .= '&search_date_endmonth='.$search_date_endmonth.'&search_date_endday='.$search_date_endday.'&search_date_endyear='.$search_date_endyear;
  250. }
  251. if (!empty($search_doc_date)) {
  252. $filter['t.doc_date'] = $search_doc_date;
  253. $param .= '&doc_datemonth='.GETPOST('doc_datemonth', 'int').'&doc_dateday='.GETPOST('doc_dateday', 'int').'&doc_dateyear='.GETPOST('doc_dateyear', 'int');
  254. }
  255. if (!empty($search_accountancy_code_start)) {
  256. if ($type == 'sub') {
  257. $filter['t.subledger_account>='] = $search_accountancy_code_start;
  258. } else {
  259. $filter['t.numero_compte>='] = $search_accountancy_code_start;
  260. }
  261. $param .= '&search_accountancy_code_start=' . urlencode($search_accountancy_code_start);
  262. }
  263. if (!empty($search_accountancy_code_end)) {
  264. if ($type == 'sub') {
  265. $filter['t.subledger_account<='] = $search_accountancy_code_end;
  266. } else {
  267. $filter['t.numero_compte<='] = $search_accountancy_code_end;
  268. }
  269. $param .= '&search_accountancy_code_end=' . urlencode($search_accountancy_code_end);
  270. }
  271. if (!empty($search_label_account)) {
  272. $filter['t.label_compte'] = $search_label_account;
  273. $param .= '&search_label_compte='.urlencode($search_label_account);
  274. }
  275. if (!empty($search_mvt_num)) {
  276. $filter['t.piece_num'] = $search_mvt_num;
  277. $param .= '&search_mvt_num='.urlencode($search_mvt_num);
  278. }
  279. if (!empty($search_doc_ref)) {
  280. $filter['t.doc_ref'] = $search_doc_ref;
  281. $param .= '&search_doc_ref='.urlencode($search_doc_ref);
  282. }
  283. if (!empty($search_label_operation)) {
  284. $filter['t.label_operation'] = $search_label_operation;
  285. $param .= '&search_label_operation='.urlencode($search_label_operation);
  286. }
  287. if (!empty($search_direction)) {
  288. $filter['t.sens'] = $search_direction;
  289. $param .= '&search_direction='.urlencode($search_direction);
  290. }
  291. if (!empty($search_ledger_code)) {
  292. $filter['t.code_journal'] = $search_ledger_code;
  293. foreach ($search_ledger_code as $code) {
  294. $param .= '&search_ledger_code[]='.urlencode($code);
  295. }
  296. }
  297. if (!empty($search_debit)) {
  298. $filter['t.debit'] = $search_debit;
  299. $param .= '&search_debit='.urlencode($search_debit);
  300. }
  301. if (!empty($search_credit)) {
  302. $filter['t.credit'] = $search_credit;
  303. $param .= '&search_credit='.urlencode($search_credit);
  304. }
  305. if (!empty($search_lettering_code)) {
  306. $filter['t.lettering_code'] = $search_lettering_code;
  307. $param .= '&search_lettering_code='.urlencode($search_lettering_code);
  308. }
  309. if (!empty($search_not_reconciled)) {
  310. $filter['t.reconciled_option'] = $search_not_reconciled;
  311. $param .= '&search_not_reconciled='.urlencode($search_not_reconciled);
  312. }
  313. if (!empty($search_date_export_start)) {
  314. $filter['t.date_export>='] = $search_date_export_start;
  315. $param .= '&search_date_export_startmonth='.$search_date_export_startmonth.'&search_date_export_startday='.$search_date_export_startday.'&search_date_export_startyear='.$search_date_export_startyear;
  316. }
  317. if (!empty($search_date_export_end)) {
  318. $filter['t.date_export<='] = $search_date_export_end;
  319. $param .= '&search_date_export_endmonth='.$search_date_export_endmonth.'&search_date_export_endday='.$search_date_export_endday.'&search_date_export_endyear='.$search_date_export_endyear;
  320. }
  321. if (!empty($search_date_validation_start)) {
  322. $filter['t.date_validated>='] = $search_date_validation_start;
  323. $param .= '&search_date_validation_startmonth='.$search_date_validation_startmonth.'&search_date_validation_startday='.$search_date_validation_startday.'&search_date_validation_startyear='.$search_date_validation_startyear;
  324. }
  325. if (!empty($search_date_validation_end)) {
  326. $filter['t.date_validated<='] = $search_date_validation_end;
  327. $param .= '&search_date_validation_endmonth='.$search_date_validation_endmonth.'&search_date_validation_endday='.$search_date_validation_endday.'&search_date_validation_endyear='.$search_date_validation_endyear;
  328. }
  329. if (!empty($search_import_key)) {
  330. $filter['t.import_key'] = $search_import_key;
  331. $param .= '&search_import_key='.urlencode($search_import_key);
  332. }
  333. // param with type of list
  334. $url_param = substr($param, 1); // remove first "&"
  335. if (!empty($type)) {
  336. $param = '&type='.$type.$param;
  337. }
  338. //if ($action == 'delbookkeepingyearconfirm' && $user->rights->accounting->mouvements->supprimer_tous) {
  339. // $delmonth = GETPOST('delmonth', 'int');
  340. // $delyear = GETPOST('delyear', 'int');
  341. // if ($delyear == -1) {
  342. // $delyear = 0;
  343. // }
  344. // $deljournal = GETPOST('deljournal', 'alpha');
  345. // if ($deljournal == -1) {
  346. // $deljournal = 0;
  347. // }
  348. //
  349. // if (!empty($delmonth) || !empty($delyear) || !empty($deljournal)) {
  350. // $result = $object->deleteByYearAndJournal($delyear, $deljournal, '', ($delmonth > 0 ? $delmonth : 0));
  351. // if ($result < 0) {
  352. // setEventMessages($object->error, $object->errors, 'errors');
  353. // } else {
  354. // setEventMessages("RecordDeleted", null, 'mesgs');
  355. // }
  356. //
  357. // // Make a redirect to avoid to launch the delete later after a back button
  358. // header("Location: ".$_SERVER["PHP_SELF"].($param ? '?'.$param : ''));
  359. // exit;
  360. // } else {
  361. // setEventMessages("NoRecordDeleted", null, 'warnings');
  362. // }
  363. //}
  364. // Mass actions
  365. $objectclass = 'Bookkeeping';
  366. $objectlabel = 'Bookkeeping';
  367. $permissiontoread = $user->rights->societe->lire;
  368. $permissiontodelete = $user->rights->societe->supprimer;
  369. $permissiontoadd = $user->rights->societe->creer;
  370. $uploaddir = $conf->societe->dir_output;
  371. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  372. if (!$error && $action == 'deletebookkeepingwriting' && $confirm == "yes" && $user->rights->accounting->mouvements->supprimer) {
  373. $nbok = 0;
  374. foreach ($toselect as $toselectid) {
  375. $result = $object->fetch($toselectid);
  376. if ($result > 0 && (!isset($object->date_validation) || $object->date_validation === '')) {
  377. $result = $object->deleteMvtNum($object->piece_num);
  378. if ($result > 0) {
  379. $nbok++;
  380. } else {
  381. setEventMessages($object->error, $object->errors, 'errors');
  382. $error++;
  383. break;
  384. }
  385. } elseif ($result < 0) {
  386. setEventMessages($object->error, $object->errors, 'errors');
  387. $error++;
  388. break;
  389. }
  390. }
  391. // Message for elements well deleted
  392. if ($nbok > 1) {
  393. setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
  394. } elseif ($nbok > 0) {
  395. setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
  396. } elseif (!$error) {
  397. setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
  398. }
  399. if (!$error) {
  400. header("Location: ".$_SERVER["PHP_SELF"]."?noreset=1".($param ? '&'.$param : ''));
  401. exit;
  402. }
  403. }
  404. // others mass actions
  405. if (!$error && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->rights->accounting->mouvements->creer) {
  406. if ($massaction == 'lettering') {
  407. $lettering = new Lettering($db);
  408. $nb_lettering = $lettering->bookkeepingLetteringAll($toselect);
  409. if ($nb_lettering < 0) {
  410. setEventMessages('', $lettering->errors, 'errors');
  411. $error++;
  412. $nb_lettering = max(0, abs($nb_lettering) - 2);
  413. } elseif ($nb_lettering == 0) {
  414. $nb_lettering = 0;
  415. setEventMessages($langs->trans('AccountancyNoLetteringModified'), array(), 'mesgs');
  416. }
  417. if ($nb_lettering == 1) {
  418. setEventMessages($langs->trans('AccountancyOneLetteringModifiedSuccessfully'), array(), 'mesgs');
  419. } elseif ($nb_lettering > 1) {
  420. setEventMessages($langs->trans('AccountancyLetteringModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
  421. }
  422. if (!$error) {
  423. header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
  424. exit();
  425. }
  426. } elseif ($action == 'unlettering' && $confirm == "yes") {
  427. $lettering = new Lettering($db);
  428. $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
  429. if ($nb_lettering < 0) {
  430. setEventMessages('', $lettering->errors, 'errors');
  431. $error++;
  432. $nb_lettering = max(0, abs($nb_lettering) - 2);
  433. } elseif ($nb_lettering == 0) {
  434. $nb_lettering = 0;
  435. setEventMessages($langs->trans('AccountancyNoUnletteringModified'), array(), 'mesgs');
  436. }
  437. if ($nb_lettering == 1) {
  438. setEventMessages($langs->trans('AccountancyOneUnletteringModifiedSuccessfully'), array(), 'mesgs');
  439. } elseif ($nb_lettering > 1) {
  440. setEventMessages($langs->trans('AccountancyUnletteringModifiedSuccessfully', $nb_lettering), array(), 'mesgs');
  441. }
  442. if (!$error) {
  443. header('Location: ' . $_SERVER['PHP_SELF'] . '?noreset=1' . $param);
  444. exit();
  445. }
  446. }
  447. }
  448. }
  449. /*
  450. * View
  451. */
  452. $formaccounting = new FormAccounting($db);
  453. $formfile = new FormFile($db);
  454. $formother = new FormOther($db);
  455. $form = new Form($db);
  456. $title_page = $langs->trans("Operations").' - '.$langs->trans("VueByAccountAccounting").' (';
  457. if ($type == 'sub') {
  458. $title_page .= $langs->trans("BookkeepingSubAccount");
  459. } else {
  460. $title_page .= $langs->trans("Bookkeeping");
  461. }
  462. $title_page .= ')';
  463. llxHeader('', $title_page);
  464. // List
  465. $nbtotalofrecords = '';
  466. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  467. if ($type == 'sub') {
  468. $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter, 'AND', 1);
  469. } else {
  470. $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter);
  471. }
  472. if ($nbtotalofrecords < 0) {
  473. setEventMessages($object->error, $object->errors, 'errors');
  474. }
  475. }
  476. if ($type == 'sub') {
  477. $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter, 'AND', 1);
  478. } else {
  479. $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter);
  480. }
  481. if ($result < 0) {
  482. setEventMessages($object->error, $object->errors, 'errors');
  483. }
  484. $arrayofselected = is_array($toselect) ? $toselect : array();
  485. $num = count($object->lines);
  486. ///if ($action == 'delbookkeepingyear') {
  487. // $form_question = array();
  488. // $delyear = GETPOST('delyear', 'int');
  489. // $deljournal = GETPOST('deljournal', 'alpha');
  490. //
  491. // if (empty($delyear)) {
  492. // $delyear = dol_print_date(dol_now(), '%Y');
  493. // }
  494. // $month_array = array();
  495. // for ($i = 1; $i <= 12; $i++) {
  496. // $month_array[$i] = $langs->trans("Month".sprintf("%02d", $i));
  497. // }
  498. // $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
  499. // $journal_array = $formaccounting->select_journal($deljournal, 'deljournal', '', 1, 1, 1, '', 0, 1);
  500. //
  501. // $form_question['delmonth'] = array(
  502. // 'name' => 'delmonth',
  503. // 'type' => 'select',
  504. // 'label' => $langs->trans('DelMonth'),
  505. // 'values' => $month_array,
  506. // 'default' => ''
  507. // );
  508. // $form_question['delyear'] = array(
  509. // 'name' => 'delyear',
  510. // 'type' => 'select',
  511. // 'label' => $langs->trans('DelYear'),
  512. // 'values' => $year_array,
  513. // 'default' => $delyear
  514. // );
  515. // $form_question['deljournal'] = array(
  516. // 'name' => 'deljournal',
  517. // 'type' => 'other', // We don't use select here, the journal_array is already a select html component
  518. // 'label' => $langs->trans('DelJournal'),
  519. // 'value' => $journal_array,
  520. // 'default' => $deljournal
  521. // );
  522. //
  523. // $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'delbookkeepingyearconfirm', $form_question, '', 1, 300);
  524. //}
  525. // Print form confirm
  526. print $formconfirm;
  527. // List of mass actions available
  528. $arrayofmassactions = array();
  529. if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->rights->accounting->mouvements->creer) {
  530. $arrayofmassactions['lettering'] = img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans('Lettering');
  531. $arrayofmassactions['preunlettering'] = img_picto('', 'uncheck', 'class="pictofixedwidth"') . $langs->trans('Unlettering');
  532. }
  533. if ($user->rights->accounting->mouvements->supprimer) {
  534. $arrayofmassactions['predeletebookkeepingwriting'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  535. }
  536. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('preunlettering', 'predeletebookkeepingwriting'))) {
  537. $arrayofmassactions = array();
  538. }
  539. $massactionbutton = $form->selectMassAction($massaction, $arrayofmassactions);
  540. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  541. print '<input type="hidden" name="token" value="'.newToken().'">';
  542. print '<input type="hidden" name="action" value="list">';
  543. if ($optioncss != '') {
  544. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  545. }
  546. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  547. print '<input type="hidden" name="type" value="'.$type.'">';
  548. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  549. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  550. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  551. $parameters = array();
  552. $reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  553. if (empty($reshook)) {
  554. $newcardbutton = dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param);
  555. if ($type == 'sub') {
  556. $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly'));
  557. $newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?type=sub&' . $url_param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
  558. } else {
  559. $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected'));
  560. $newcardbutton .= dolGetButtonTitle($langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?type=sub&' . $url_param, '', 1, array('morecss' => 'marginleftonly'));
  561. }
  562. $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?action=create');
  563. }
  564. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  565. $param .= '&contextpage='.urlencode($contextpage);
  566. }
  567. if ($limit > 0 && $limit != $conf->liste_limit) {
  568. $param .= '&limit='.urlencode($limit);
  569. }
  570. print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $result, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1);
  571. if ($massaction == 'preunlettering') {
  572. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassUnlettering"), $langs->trans("ConfirmMassUnletteringQuestion", count($toselect)), "unlettering", null, '', 0, 200, 500, 1);
  573. } elseif ($massaction == 'predeletebookkeepingwriting') {
  574. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeleteBookkeepingWriting"), $langs->trans("ConfirmMassDeleteBookkeepingWritingQuestion", count($toselect)), "deletebookkeepingwriting", null, '', 0, 200, 500, 1);
  575. }
  576. //DeleteMvt=Supprimer des lignes d'opérations de la comptabilité
  577. //DelMonth=Mois à effacer
  578. //DelYear=Année à supprimer
  579. //DelJournal=Journal à supprimer
  580. //ConfirmDeleteMvt=Cette action supprime les lignes des opérations pour l'année/mois et/ou pour le journal sélectionné (au moins un critère est requis). Vous devrez utiliser de nouveau la fonctionnalité '%s' pour retrouver vos écritures dans la comptabilité.
  581. //ConfirmDeleteMvtPartial=Cette action supprime l'écriture de la comptabilité (toutes les lignes opérations liées à une même écriture seront effacées).
  582. //$topicmail = "Information";
  583. //$modelmail = "accountingbookkeeping";
  584. //$objecttmp = new BookKeeping($db);
  585. //$trackid = 'bk'.$object->id;
  586. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  587. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  588. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  589. if ($massactionbutton && $contextpage != 'poslist') {
  590. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  591. }
  592. // Reverse sort order
  593. if (preg_match('/^asc/i', $sortorder)) {
  594. $sortorder = "asc";
  595. } else {
  596. $sortorder = "desc";
  597. }
  598. // Warning to explain why list of record is not consistent with the other list view (missing a lot of lines)
  599. if ($type == 'sub') {
  600. print info_admin($langs->trans("WarningRecordWithoutSubledgerAreExcluded"));
  601. }
  602. $moreforfilter = '';
  603. // Accountancy account
  604. $moreforfilter .= '<div class="divsearchfield">';
  605. $moreforfilter .= $langs->trans('AccountAccounting').': ';
  606. $moreforfilter .= '<div class="nowrap inline-block">';
  607. if ($type == 'sub') {
  608. $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), 'maxwidth200');
  609. } else {
  610. $moreforfilter .= $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth200');
  611. }
  612. $moreforfilter .= ' ';
  613. if ($type == 'sub') {
  614. $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), 'maxwidth200');
  615. } else {
  616. $moreforfilter .= $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth200');
  617. }
  618. $moreforfilter .= '</div>';
  619. $moreforfilter .= '</div>';
  620. $parameters = array();
  621. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  622. if (empty($reshook)) {
  623. $moreforfilter .= $hookmanager->resPrint;
  624. } else {
  625. $moreforfilter = $hookmanager->resPrint;
  626. }
  627. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  628. print $moreforfilter;
  629. print '</div>';
  630. print '<div class="div-table-responsive">';
  631. print '<table class="tagtable liste centpercent">';
  632. // Filters lines
  633. print '<tr class="liste_titre_filter">';
  634. // Movement number
  635. if (!empty($arrayfields['t.piece_num']['checked'])) {
  636. print '<td class="liste_titre"><input type="text" name="search_mvt_num" size="6" value="'.dol_escape_htmltag($search_mvt_num).'"></td>';
  637. }
  638. // Code journal
  639. if (!empty($arrayfields['t.code_journal']['checked'])) {
  640. print '<td class="liste_titre center">';
  641. print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1);
  642. print '</td>';
  643. }
  644. // Date document
  645. if (!empty($arrayfields['t.doc_date']['checked'])) {
  646. print '<td class="liste_titre center">';
  647. print '<div class="nowrap">';
  648. print $form->selectDate($search_date_start, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  649. print '</div>';
  650. print '<div class="nowrap">';
  651. print $form->selectDate($search_date_end, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  652. print '</div>';
  653. print '</td>';
  654. }
  655. // Ref document
  656. if (!empty($arrayfields['t.doc_ref']['checked'])) {
  657. print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"/></td>';
  658. }
  659. // Label operation
  660. if (!empty($arrayfields['t.label_operation']['checked'])) {
  661. print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_label_operation" value="'.dol_escape_htmltag($search_label_operation).'"/></td>';
  662. }
  663. // Debit
  664. if (!empty($arrayfields['t.debit']['checked'])) {
  665. print '<td class="liste_titre right"><input type="text" class="flat" name="search_debit" size="4" value="'.dol_escape_htmltag($search_debit).'"></td>';
  666. }
  667. // Credit
  668. if (!empty($arrayfields['t.credit']['checked'])) {
  669. print '<td class="liste_titre right"><input type="text" class="flat" name="search_credit" size="4" value="'.dol_escape_htmltag($search_credit).'"></td>';
  670. }
  671. // Lettering code
  672. if (!empty($arrayfields['t.lettering_code']['checked'])) {
  673. print '<td class="liste_titre center">';
  674. print '<input type="text" size="3" class="flat" name="search_lettering_code" value="'.$search_lettering_code.'"/>';
  675. print '<br><span class="nowrap"><input type="checkbox" name="search_not_reconciled" value="notreconciled"'.($search_not_reconciled == 'notreconciled' ? ' checked' : '').'>'.$langs->trans("NotReconciled").'</span>';
  676. print '</td>';
  677. }
  678. // Date export
  679. if (!empty($arrayfields['t.date_export']['checked'])) {
  680. print '<td class="liste_titre center">';
  681. print '<div class="nowrap">';
  682. print $form->selectDate($search_date_export_start, 'search_date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  683. print '</div>';
  684. print '<div class="nowrap">';
  685. print $form->selectDate($search_date_export_end, 'search_date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  686. print '</div>';
  687. print '</td>';
  688. }
  689. // Date validation
  690. if (!empty($arrayfields['t.date_validated']['checked'])) {
  691. print '<td class="liste_titre center">';
  692. print '<div class="nowrap">';
  693. print $form->selectDate($search_date_validation_start, 'search_date_validation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  694. print '</div>';
  695. print '<div class="nowrap">';
  696. print $form->selectDate($search_date_validation_end, 'search_date_validation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  697. print '</div>';
  698. print '</td>';
  699. }
  700. if (!empty($arrayfields['t.import_key']['checked'])) {
  701. print '<td class="liste_titre center">';
  702. print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
  703. print '</td>';
  704. }
  705. // Fields from hook
  706. $parameters = array('arrayfields'=>$arrayfields);
  707. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  708. print $hookmanager->resPrint;
  709. // Action column
  710. print '<td class="liste_titre center">';
  711. $searchpicto = $form->showFilterButtons();
  712. print $searchpicto;
  713. print '</td>';
  714. print "</tr>\n";
  715. print '<tr class="liste_titre">';
  716. if (!empty($arrayfields['t.piece_num']['checked'])) {
  717. print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, '', $sortfield, $sortorder);
  718. }
  719. if (!empty($arrayfields['t.code_journal']['checked'])) {
  720. print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, '', $sortfield, $sortorder, 'center ');
  721. }
  722. if (!empty($arrayfields['t.doc_date']['checked'])) {
  723. print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, '', $sortfield, $sortorder, 'center ');
  724. }
  725. if (!empty($arrayfields['t.doc_ref']['checked'])) {
  726. print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder);
  727. }
  728. if (!empty($arrayfields['t.label_operation']['checked'])) {
  729. print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder);
  730. }
  731. if (!empty($arrayfields['t.debit']['checked'])) {
  732. print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right ');
  733. }
  734. if (!empty($arrayfields['t.credit']['checked'])) {
  735. print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right ');
  736. }
  737. if (!empty($arrayfields['t.lettering_code']['checked'])) {
  738. print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center ');
  739. }
  740. if (!empty($arrayfields['t.date_export']['checked'])) {
  741. print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export", "", $param, '', $sortfield, $sortorder, 'center ');
  742. }
  743. if (!empty($arrayfields['t.date_validated']['checked'])) {
  744. print_liste_field_titre($arrayfields['t.date_validated']['label'], $_SERVER['PHP_SELF'], "t.date_validated", "", $param, '', $sortfield, $sortorder, 'center ');
  745. }
  746. if (!empty($arrayfields['t.import_key']['checked'])) {
  747. print_liste_field_titre($arrayfields['t.import_key']['label'], $_SERVER["PHP_SELF"], "t.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
  748. }
  749. // Hook fields
  750. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  751. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  752. print $hookmanager->resPrint;
  753. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  754. print "</tr>\n";
  755. $total_debit = 0;
  756. $total_credit = 0;
  757. $sous_total_debit = 0;
  758. $sous_total_credit = 0;
  759. $displayed_account_number = null; // Start with undefined to be able to distinguish with empty
  760. // Loop on record
  761. // --------------------------------------------------------------------
  762. $i = 0;
  763. $totalarray = array();
  764. while ($i < min($num, $limit)) {
  765. $line = $object->lines[$i];
  766. $total_debit += $line->debit;
  767. $total_credit += $line->credit;
  768. if ($type == 'sub') {
  769. $accountg = length_accounta($line->subledger_account);
  770. } else {
  771. $accountg = length_accountg($line->numero_compte);
  772. }
  773. //if (empty($accountg)) $accountg = '-';
  774. $colspan = 0; // colspan before field 'label of operation'
  775. $colspanend = 3; // colspan after debit/credit
  776. if (!empty($arrayfields['t.piece_num']['checked'])) { $colspan++; }
  777. if (!empty($arrayfields['t.code_journal']['checked'])) { $colspan++; }
  778. if (!empty($arrayfields['t.doc_date']['checked'])) { $colspan++; }
  779. if (!empty($arrayfields['t.doc_ref']['checked'])) { $colspan++; }
  780. if (!empty($arrayfields['t.label_operation']['checked'])) { $colspan++; }
  781. if (!empty($arrayfields['t.date_export']['checked'])) { $colspanend++; }
  782. if (!empty($arrayfields['t.date_validating']['checked'])) { $colspanend++; }
  783. if (!empty($arrayfields['t.lettering_code']['checked'])) { $colspanend++; }
  784. // Is it a break ?
  785. if ($accountg != $displayed_account_number || !isset($displayed_account_number)) {
  786. // Show a subtotal by accounting account
  787. if (isset($displayed_account_number)) {
  788. print '<tr class="liste_total">';
  789. if ($type == 'sub') {
  790. print '<td class="right" colspan="' . $colspan . '">' . $langs->trans("TotalForAccount") . ' ' . length_accounta($displayed_account_number) . ':</td>';
  791. } else {
  792. print '<td class="right" colspan="' . $colspan . '">' . $langs->trans("TotalForAccount") . ' ' . length_accountg($displayed_account_number) . ':</td>';
  793. }
  794. print '<td class="nowrap right">'.price($sous_total_debit).'</td>';
  795. print '<td class="nowrap right">'.price($sous_total_credit).'</td>';
  796. print '<td colspan="'.$colspanend.'"></td>';
  797. print '</tr>';
  798. // Show balance of last shown account
  799. $balance = $sous_total_debit - $sous_total_credit;
  800. print '<tr class="liste_total">';
  801. print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
  802. if ($balance > 0) {
  803. print '<td class="nowraponall right">';
  804. print price($sous_total_debit - $sous_total_credit);
  805. print '</td>';
  806. print '<td></td>';
  807. } else {
  808. print '<td></td>';
  809. print '<td class="nowraponall right">';
  810. print price($sous_total_credit - $sous_total_debit);
  811. print '</td>';
  812. }
  813. print '<td colspan="'.$colspanend.'"></td>';
  814. print '</tr>';
  815. }
  816. // Show the break account
  817. print '<tr class="trforbreak">';
  818. print '<td colspan="'.($totalarray['nbfield'] ? $totalarray['nbfield'] : count($arrayfields)+1).'" class="tdforbreak">';
  819. if ($type == 'sub') {
  820. if ($line->subledger_account != "" && $line->subledger_account != '-1') {
  821. print $line->subledger_label . ' : ' . length_accounta($line->subledger_account);
  822. } else {
  823. // Should not happen: subledger account must be null or a non empty value
  824. print '<span class="error">' . $langs->trans("Unknown");
  825. if ($line->subledger_label) {
  826. print ' (' . $line->subledger_label . ')';
  827. $htmltext = 'EmptyStringForSubledgerAccountButSubledgerLabelDefined';
  828. } else {
  829. $htmltext = 'EmptyStringForSubledgerAccountAndSubledgerLabel';
  830. }
  831. print $form->textwithpicto('', $htmltext);
  832. print '</span>';
  833. }
  834. } else {
  835. if ($line->numero_compte != "" && $line->numero_compte != '-1') {
  836. print length_accountg($line->numero_compte) . ' : ' . $object->get_compte_desc($line->numero_compte);
  837. } else {
  838. print '<span class="error">' . $langs->trans("Unknown") . '</span>';
  839. }
  840. }
  841. print '</td>';
  842. print '</tr>';
  843. $displayed_account_number = $accountg;
  844. //if (empty($displayed_account_number)) $displayed_account_number='-';
  845. $sous_total_debit = 0;
  846. $sous_total_credit = 0;
  847. $colspan = 0;
  848. }
  849. print '<tr class="oddeven">';
  850. // Piece number
  851. if (!empty($arrayfields['t.piece_num']['checked'])) {
  852. print '<td>';
  853. $object->id = $line->id;
  854. $object->piece_num = $line->piece_num;
  855. print $object->getNomUrl(1, '', 0, '', 1);
  856. print '</td>';
  857. if (!$i) {
  858. $totalarray['nbfield']++;
  859. }
  860. }
  861. // Journal code
  862. if (!empty($arrayfields['t.code_journal']['checked'])) {
  863. $accountingjournal = new AccountingJournal($db);
  864. $result = $accountingjournal->fetch('', $line->code_journal);
  865. $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal);
  866. print '<td class="center">'.$journaltoshow.'</td>';
  867. if (!$i) {
  868. $totalarray['nbfield']++;
  869. }
  870. }
  871. // Document date
  872. if (!empty($arrayfields['t.doc_date']['checked'])) {
  873. print '<td class="center">'.dol_print_date($line->doc_date, 'day').'</td>';
  874. if (!$i) {
  875. $totalarray['nbfield']++;
  876. }
  877. }
  878. // Document ref
  879. if (!empty($arrayfields['t.doc_ref']['checked'])) {
  880. if ($line->doc_type == 'customer_invoice') {
  881. $langs->loadLangs(array('bills'));
  882. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  883. $objectstatic = new Facture($db);
  884. $objectstatic->fetch($line->fk_doc);
  885. //$modulepart = 'facture';
  886. $filename = dol_sanitizeFileName($line->doc_ref);
  887. $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
  888. $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
  889. $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  890. } elseif ($line->doc_type == 'supplier_invoice') {
  891. $langs->loadLangs(array('bills'));
  892. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  893. $objectstatic = new FactureFournisseur($db);
  894. $objectstatic->fetch($line->fk_doc);
  895. //$modulepart = 'invoice_supplier';
  896. $filename = dol_sanitizeFileName($line->doc_ref);
  897. $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
  898. $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
  899. $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir);
  900. } elseif ($line->doc_type == 'expense_report') {
  901. $langs->loadLangs(array('trips'));
  902. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  903. $objectstatic = new ExpenseReport($db);
  904. $objectstatic->fetch($line->fk_doc);
  905. //$modulepart = 'expensereport';
  906. $filename = dol_sanitizeFileName($line->doc_ref);
  907. $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($line->doc_ref);
  908. $urlsource = $_SERVER['PHP_SELF'].'?id='.$objectstatic->id;
  909. $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  910. } elseif ($line->doc_type == 'bank') {
  911. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  912. $objectstatic = new AccountLine($db);
  913. $objectstatic->fetch($line->fk_doc);
  914. } else {
  915. // Other type
  916. }
  917. print '<td class="maxwidth400">';
  918. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  919. // Picto + Ref
  920. print '<td class="nobordernopadding">';
  921. if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') {
  922. print $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
  923. print $documentlink;
  924. } elseif ($line->doc_type == 'bank') {
  925. print $objectstatic->getNomUrl(1);
  926. $bank_ref = strstr($line->doc_ref, '-');
  927. print " " . $bank_ref;
  928. } else {
  929. print $line->doc_ref;
  930. }
  931. print '</td></tr></table>';
  932. print "</td>\n";
  933. if (!$i) {
  934. $totalarray['nbfield']++;
  935. }
  936. }
  937. // Label operation
  938. if (!empty($arrayfields['t.label_operation']['checked'])) {
  939. // Affiche un lien vers la facture client/fournisseur
  940. $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref);
  941. print strlen(length_accounta($line->subledger_account)) == 0 ? '<td>'.$line->label_operation.'</td>' : '<td>'.$line->label_operation.'<br><span style="font-size:0.8em">('.length_accounta($line->subledger_account).')</span></td>';
  942. if (!$i) {
  943. $totalarray['nbfield']++;
  944. }
  945. }
  946. // Amount debit
  947. if (!empty($arrayfields['t.debit']['checked'])) {
  948. print '<td class="right nowraponall amount">'.($line->debit ? price($line->debit) : '').'</td>';
  949. if (!$i) {
  950. $totalarray['nbfield']++;
  951. }
  952. if (!$i) {
  953. $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit';
  954. }
  955. $totalarray['val']['totaldebit'] += $line->debit;
  956. }
  957. // Amount credit
  958. if (!empty($arrayfields['t.credit']['checked'])) {
  959. print '<td class="right nowraponall amount">'.($line->credit ? price($line->credit) : '').'</td>';
  960. if (!$i) {
  961. $totalarray['nbfield']++;
  962. }
  963. if (!$i) {
  964. $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit';
  965. }
  966. $totalarray['val']['totalcredit'] += $line->credit;
  967. }
  968. // Lettering code
  969. if (!empty($arrayfields['t.lettering_code']['checked'])) {
  970. print '<td class="center">'.$line->lettering_code.'</td>';
  971. if (!$i) {
  972. $totalarray['nbfield']++;
  973. }
  974. }
  975. // Exported operation date
  976. if (!empty($arrayfields['t.date_export']['checked'])) {
  977. print '<td class="center">'.dol_print_date($line->date_export, 'dayhour').'</td>';
  978. if (!$i) {
  979. $totalarray['nbfield']++;
  980. }
  981. }
  982. // Validated operation date
  983. if (!empty($arrayfields['t.date_validated']['checked'])) {
  984. print '<td class="center">'.dol_print_date($line->date_validation, 'dayhour').'</td>';
  985. if (!$i) {
  986. $totalarray['nbfield']++;
  987. }
  988. }
  989. if (!empty($arrayfields['t.import_key']['checked'])) {
  990. print '<td class="tdoverflowmax100">'.$line->import_key."</td>\n";
  991. if (!$i) {
  992. $totalarray['nbfield']++;
  993. }
  994. }
  995. // Fields from hook
  996. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$line);
  997. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  998. print $hookmanager->resPrint;
  999. // Action column
  1000. print '<td class="nowraponall center">';
  1001. 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
  1002. $selected = 0;
  1003. if (in_array($line->id, $arrayofselected)) {
  1004. $selected = 1;
  1005. }
  1006. print '<input id="cb' . $line->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $line->id . '"' . ($selected ? ' checked="checked"' : '') . ' />';
  1007. }
  1008. print '</td>';
  1009. if (!$i) {
  1010. $totalarray['nbfield']++;
  1011. }
  1012. // Comptabilise le sous-total
  1013. $sous_total_debit += $line->debit;
  1014. $sous_total_credit += $line->credit;
  1015. print "</tr>\n";
  1016. $i++;
  1017. }
  1018. if ($num > 0 && $colspan > 0) {
  1019. print '<tr class="liste_total">';
  1020. print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("TotalForAccount").' '.$accountg.':</td>';
  1021. print '<td class="nowrap right">'.price($sous_total_debit).'</td>';
  1022. print '<td class="nowrap right">'.price($sous_total_credit).'</td>';
  1023. print '<td colspan="'.$colspanend.'"></td>';
  1024. print '</tr>';
  1025. // Show balance of last shown account
  1026. $balance = $sous_total_debit - $sous_total_credit;
  1027. print '<tr class="liste_total">';
  1028. print '<td class="right" colspan="'.$colspan.'">'.$langs->trans("Balance").':</td>';
  1029. if ($balance > 0) {
  1030. print '<td class="nowraponall right">';
  1031. print price($sous_total_debit - $sous_total_credit);
  1032. print '</td>';
  1033. print '<td></td>';
  1034. } else {
  1035. print '<td></td>';
  1036. print '<td class="nowraponall right">';
  1037. print price($sous_total_credit - $sous_total_debit);
  1038. print '</td>';
  1039. }
  1040. print '<td colspan="'.$colspanend.'"></td>';
  1041. print '</tr>';
  1042. }
  1043. // Show total line
  1044. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1045. print "</table>";
  1046. print '</div>';
  1047. // TODO Replace this with mass delete action
  1048. //if ($user->rights->accounting->mouvements->supprimer_tous) {
  1049. // print '<div class="tabsAction tabsActionNoBottom">'."\n";
  1050. // print '<a class="butActionDelete" name="button_delmvt" href="'.$_SERVER["PHP_SELF"].'?action=delbookkeepingyear&token='.newToken().($param ? '&'.$param : '').'">'.$langs->trans("DeleteMvt").'</a>';
  1051. // print '</div>';
  1052. //}
  1053. print '</form>';
  1054. // End of page
  1055. llxFooter();
  1056. $db->close();