list.php 66 KB

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