listbyaccount.php 53 KB

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