listbyaccount.php 55 KB

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