list.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. /**
  21. * \file htdocs/accountancy/bookkeeping/list.php
  22. * \ingroup Advanced accountancy
  23. * \brief List operation of book keeping
  24. */
  25. require '../../main.inc.php';
  26. // Class
  27. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  28. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  31. // Langs
  32. $langs->load("accountancy");
  33. $page = GETPOST("page");
  34. $sortorder = GETPOST("sortorder");
  35. $sortfield = GETPOST("sortfield");
  36. $action = GETPOST('action', 'alpha');
  37. $search_mvt_num = GETPOST('search_mvt_num', 'int');
  38. $search_doc_type = GETPOST("search_doc_type");
  39. $search_doc_ref = GETPOST("search_doc_ref");
  40. $search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
  41. $search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));
  42. $search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
  43. if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt")) {
  44. $action = 'delbookkeepingyear';
  45. }
  46. if (GETPOST("button_export_csv_x") || GETPOST("button_export_csv")) {
  47. $action = 'export_csv';
  48. }
  49. $search_accountancy_code = GETPOST("search_accountancy_code");
  50. $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
  51. if ($search_accountancy_code_start == - 1) {
  52. $search_accountancy_code_start = '';
  53. }
  54. $search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha');
  55. if ($search_accountancy_code_end == - 1) {
  56. $search_accountancy_code_end = '';
  57. }
  58. $search_accountancy_aux_code = GETPOST("search_accountancy_aux_code");
  59. $search_accountancy_aux_code_start = GETPOST('search_accountancy_aux_code_start', 'alpha');
  60. if ($search_accountancy_aux_code_start == - 1) {
  61. $search_accountancy_aux_code_start = '';
  62. }
  63. $search_accountancy_aux_code_end = GETPOST('search_accountancy_aux_code_end', 'alpha');
  64. if ($search_accountancy_aux_code_end == - 1) {
  65. $search_accountancy_aux_code_end = '';
  66. }
  67. $search_mvt_label = GETPOST('search_mvt_label', 'alpha');
  68. $search_direction = GETPOST('search_direction', 'alpha');
  69. $search_ledger_code = GETPOST('search_ledger_code', 'alpha');
  70. $limit = GETPOST('limit') ? GETPOST('limit', 'int') : $conf->liste_limit;
  71. $offset = $limit * $page;
  72. $object = new BookKeeping($db);
  73. $formventilation = new FormVentilation($db);
  74. $formother = new FormOther($db);
  75. $form = new Form($db);
  76. if (empty($search_date_start)) {
  77. $search_date_start = dol_mktime(0, 0, 0, 1, 1, dol_print_date(dol_now(), '%Y'));
  78. $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_print_date(dol_now(), '%Y'));
  79. }
  80. if ($sortorder == "")
  81. $sortorder = "ASC";
  82. if ($sortfield == "")
  83. $sortfield = "t.rowid";
  84. $options = '';
  85. $filter = array ();
  86. if (! empty($search_date_start)) {
  87. $filter['t.doc_date>='] = $search_date_start;
  88. $options .= '&amp;date_startmonth=' . GETPOST('date_startmonth', 'int') . '&amp;date_startday=' . GETPOST('date_startday', 'int') . '&amp;date_startyear=' . GETPOST('date_startyear', 'int');
  89. }
  90. if (! empty($search_date_end)) {
  91. $filter['t.doc_date<='] = $search_date_end;
  92. $options .= '&amp;date_endmonth=' . GETPOST('date_endmonth', 'int') . '&amp;date_endday=' . GETPOST('date_endday', 'int') . '&amp;date_endyear=' . GETPOST('date_endyear', 'int');
  93. }
  94. if (! empty($search_doc_type)) {
  95. $filter['t.doc_type'] = $search_doc_type;
  96. $options .= '&amp;search_doc_type=' . $search_doc_type;
  97. }
  98. if (! empty($search_doc_date)) {
  99. $filter['t.doc_date'] = $search_doc_date;
  100. $options .= '&amp;doc_datemonth=' . GETPOST('doc_datemonth', 'int') . '&amp;doc_dateday=' . GETPOST('doc_dateday', 'int') . '&amp;doc_dateyear=' . GETPOST('doc_dateyear', 'int');
  101. }
  102. if (! empty($search_doc_ref)) {
  103. $filter['t.doc_ref'] = $search_doc_ref;
  104. $options .= '&amp;search_doc_ref=' . $search_doc_ref;
  105. }
  106. if (! empty($search_accountancy_code)) {
  107. $filter['t.numero_compte'] = $search_accountancy_code;
  108. $options .= '&amp;search_accountancy_code=' . $search_accountancy_code;
  109. }
  110. if (! empty($search_accountancy_code_start)) {
  111. $filter['t.numero_compte>='] = $search_accountancy_code_start;
  112. $options .= '&amp;search_accountancy_code_start=' . $search_accountancy_code_start;
  113. }
  114. if (! empty($search_accountancy_code_end)) {
  115. $filter['t.numero_compte<='] = $search_accountancy_code_end;
  116. $options .= '&amp;search_accountancy_code_end=' . $search_accountancy_code_end;
  117. }
  118. if (! empty($search_accountancy_aux_code)) {
  119. $filter['t.code_tiers'] = $search_accountancy_aux_code;
  120. $options .= '&amp;search_accountancy_aux_code=' . $search_accountancy_aux_code;
  121. }
  122. if (! empty($search_accountancy_aux_code_start)) {
  123. $filter['t.code_tiers>='] = $search_accountancy_aux_code_start;
  124. $options .= '&amp;search_accountancy_aux_code_start=' . $search_accountancy_aux_code_start;
  125. }
  126. if (! empty($search_accountancy_aux_code_end)) {
  127. $filter['t.code_tiers<='] = $search_accountancy_aux_code_end;
  128. $options .= '&amp;search_accountancy_aux_code_end=' . $search_accountancy_aux_code_end;
  129. }
  130. if (! empty($search_mvt_label)) {
  131. $filter['t.label_compte'] = $search_mvt_label;
  132. $options .= '&amp;search_mvt_label=' . $search_mvt_label;
  133. }
  134. if (! empty($search_direction)) {
  135. $filter['t.sens'] = $search_direction;
  136. $options .= '&amp;search_direction=' . $search_direction;
  137. }
  138. if (! empty($search_ledger_code)) {
  139. $filter['t.code_journal'] = $search_ledger_code;
  140. $options .= '&amp;search_ledger_code=' . $search_ledger_code;
  141. }
  142. if (! empty($search_mvt_num)) {
  143. $filter['t.piece_num'] = $search_mvt_num;
  144. $options .= '&amp;search_mvt_num=' . $search_mvt_num;
  145. }
  146. /*
  147. * Action
  148. */
  149. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  150. {
  151. $search_mvt_num = '';
  152. $search_doc_type = '';
  153. $search_doc_ref = '';
  154. $search_doc_date = '';
  155. $search_accountancy_code = '';
  156. $search_accountancy_code_start = '';
  157. $search_accountancy_code_end = '';
  158. $search_accountancy_aux_code = '';
  159. $search_accountancy_aux_code_start = '';
  160. $search_accountancy_aux_code_end = '';
  161. $search_mvt_label = '';
  162. $search_direction = '';
  163. $search_ledger_code = '';
  164. $search_date_start = '';
  165. $search_date_end = '';
  166. }
  167. if ($action == 'delbookkeeping') {
  168. $import_key = GETPOST('importkey', 'alpha');
  169. if (! empty($import_key)) {
  170. $result = $object->deleteByImportkey($import_key);
  171. if ($result < 0) {
  172. setEventMessages($object->error, $object->errors, 'errors');
  173. }
  174. Header("Location: list.php");
  175. exit();
  176. }
  177. }
  178. if ($action == 'delbookkeepingyearconfirm') {
  179. $delyear = GETPOST('delyear', 'int');
  180. if ($delyear==-1) {
  181. $delyear=0;
  182. }
  183. $deljournal = GETPOST('deljournal','alpha');
  184. if ($deljournal==-1) {
  185. $deljournal=0;
  186. }
  187. if (! empty($delyear) || ! empty($deljournal)) {
  188. $result = $object->deleteByYearAndJournal($delyear,$deljournal);
  189. if ($result < 0) {
  190. setEventMessages($object->error, $object->errors, 'errors');
  191. }
  192. Header("Location: list.php");
  193. exit;
  194. }
  195. }
  196. if ($action == 'delmouvconfirm') {
  197. $mvt_num = GETPOST('mvt_num', 'int');
  198. if (! empty($mvt_num)) {
  199. $result = $object->deleteMvtNum($mvt_num);
  200. if ($result < 0) {
  201. setEventMessages($object->error, $object->errors, 'errors');
  202. }
  203. Header("Location: list.php");
  204. exit;
  205. }
  206. }
  207. if ($action == 'export_csv') {
  208. include DOL_DOCUMENT_ROOT . '/accountancy/class/accountancyexport.class.php';
  209. $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter);
  210. if ($result < 0)
  211. {
  212. setEventMessages($object->error, $object->errors, 'errors');
  213. }
  214. else
  215. {
  216. $accountancyexport = new AccountancyExport($db);
  217. $accountancyexport->export($object->lines);
  218. if (!empty($accountancyexport->errors)) {
  219. setEventMessages('', $accountancyexport->errors, 'errors');
  220. }
  221. exit;
  222. }
  223. }
  224. /*
  225. * View
  226. */
  227. $title_page = $langs->trans("Bookkeeping") . ' ' . dol_print_date($search_date_start) . '-' . dol_print_date($search_date_end);
  228. llxHeader('', $title_page);
  229. // List
  230. $nbtotalofrecords = 0;
  231. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  232. $nbtotalofrecords = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter);
  233. if ($nbtotalofrecords < 0) {
  234. setEventMessages($object->error, $object->errors, 'errors');
  235. }
  236. }
  237. $result = $object->fetchAll($sortorder, $sortfield, $limit, $offset, $filter);
  238. if ($result < 0) {
  239. setEventMessages($object->error, $object->errors, 'errors');
  240. }
  241. if ($action == 'delmouv') {
  242. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?mvt_num=' . GETPOST('mvt_num'), $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delmouvconfirm', '', 0, 1);
  243. print $formconfirm;
  244. }
  245. if ($action == 'delbookkeepingyear') {
  246. $form_question = array ();
  247. $delyear = GETPOST('delyear');
  248. $deljournal = GETPOST('deljournal');
  249. if (empty($delyear)) {
  250. $delyear = dol_print_date(dol_now(), '%Y');
  251. }
  252. $year_array = $formventilation->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
  253. $journal_array = $formventilation->selectjournal_accountancy_bookkepping($deljournal, 'deljournal', 0, 'array');
  254. $form_question['delyear'] = array (
  255. 'name' => 'delyear',
  256. 'type' => 'select',
  257. 'label' => $langs->trans('DelYear'),
  258. 'values' => $year_array,
  259. 'default' => $delyear
  260. );
  261. $form_question['deljournal'] = array (
  262. 'name' => 'deljournal',
  263. 'type' => 'select',
  264. 'label' => $langs->trans('DelJournal'),
  265. 'values' => $journal_array,
  266. 'default' => $deljournal
  267. );
  268. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delbookkeepingyearconfirm', $form_question, 0, 1);
  269. print $formconfirm;
  270. }
  271. print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords);
  272. print '<form method="GET" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '">';
  273. print '<div class="tabsAction">' . "\n";
  274. print '<div class="inline-block divButAction"><a class="butAction" href="./listbyaccount.php">' . $langs->trans("Bookkeeping") . ' ' . strtolower($langs->trans("By")) . ' ' . strtolower($langs->trans("AccountAccounting")) . '</a></div>';
  275. print '<div class="inline-block divButAction"><input type="submit" name="button_delmvt" class="butAction" value="' . $langs->trans("DelBookKeeping") . '" /></div>';
  276. print '<div class="inline-block divButAction"><a class="butAction" href="./card.php?action=create">' . $langs->trans("NewAccountingMvt") . '</a></div>';
  277. print '<div class="inline-block divButAction"><input type="submit" name="button_export_csv" class="butAction" value="' . $langs->trans("Export") . '" /></div>';
  278. print '</div>';
  279. print '<table class="noborder" width="100%">';
  280. print '<tr class="liste_titre">';
  281. print_liste_field_titre($langs->trans("NumPiece"), $_SERVER['PHP_SELF'], "t.piece_num", "", $options, "", $sortfield, $sortorder);
  282. print_liste_field_titre($langs->trans("Docdate"), $_SERVER['PHP_SELF'], "t.doc_date", "", $options, "", $sortfield, $sortorder);
  283. print_liste_field_titre($langs->trans("Docref"), $_SERVER['PHP_SELF'], "t.doc_ref", "", $options, "", $sortfield, $sortorder);
  284. print_liste_field_titre($langs->trans("AccountAccountingShort"), $_SERVER['PHP_SELF'], "t.numero_compte", "", $options, "", $sortfield, $sortorder);
  285. print_liste_field_titre($langs->trans("Code_tiers"), $_SERVER['PHP_SELF'], "t.code_tiers", "", $options, "", $sortfield, $sortorder);
  286. print_liste_field_titre($langs->trans("Labelcompte"), $_SERVER['PHP_SELF'], "bk_label_compte", "", $options, "", $sortfield, $sortorder);
  287. print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder);
  288. print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder);
  289. print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="center"', $sortfield, $sortorder);
  290. print_liste_field_titre($langs->trans("Action"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder);
  291. print "</tr>\n";
  292. print '<tr class="liste_titre">';
  293. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="GET">';
  294. print '<td><input type="text" name="search_mvt_num" size="6" value="' . $search_mvt_num . '"></td>';
  295. print '<td class="liste_titre">';
  296. print $langs->trans('From') . ': ';
  297. print $form->select_date($search_date_start, 'date_start', 0, 0, 1);
  298. print '<br>';
  299. print $langs->trans('to') . ': ';
  300. print $form->select_date($search_date_end, 'date_end', 0, 0, 1);
  301. print '</td>';
  302. print '<td><input type="text" name="search_doc_ref" size="8" value="' . $search_doc_ref . '"></td>';
  303. print '<td>';
  304. print $langs->trans('From');
  305. print $formventilation->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, '');
  306. print '<br>';
  307. print $langs->trans('to');
  308. print $formventilation->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, '');
  309. print '</td>';
  310. print '<td>';
  311. print $langs->trans('From');
  312. print $formventilation->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1);
  313. print '<br>';
  314. print $langs->trans('to');
  315. print $formventilation->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1);
  316. print '</td>';
  317. print '<td class="liste_titre">';
  318. print '<input type="text" size="7" class="flat" name="search_mvt_label" value="' . $search_mvt_label . '"/>';
  319. print '</td>';
  320. print '<td>&nbsp;</td>';
  321. print '<td>&nbsp;</td>';
  322. print '<td align="right"><input type="text" name="search_ledger_code" size="3" value="' . $search_ledger_code . '"></td>';
  323. print '<td align="right" colspan="2" class="liste_titre">';
  324. $searchpitco=$form->showFilterAndCheckAddButtons(0);
  325. print $searchpitco;
  326. print '</td>';
  327. print '</tr>';
  328. $var = True;
  329. $total_debit = 0;
  330. $total_credit = 0;
  331. foreach ( $object->lines as $line ) {
  332. $var = ! $var;
  333. $total_debit += $line->debit;
  334. $total_credit += $line->credit;
  335. print '<tr'. $bc[$var].'>';
  336. print '<td><a href="./card.php?piece_num=' . $line->piece_num . '">' . $line->piece_num . '</a></td>';
  337. print '<td align="center">' . dol_print_date($line->doc_date, 'day') . '</td>';
  338. print '<td>' . $line->doc_ref . '</td>';
  339. print '<td>' . length_accountg($line->numero_compte) . '</td>';
  340. print '<td>' . length_accounta($line->code_tiers) . '</td>';
  341. print '<td>' . $line->label_compte . '</td>';
  342. print '<td align="right">' . price($line->debit) . '</td>';
  343. print '<td align="right">' . price($line->credit) . '</td>';
  344. print '<td align="center">' . $line->code_journal . '</td>';
  345. print '<td align="center">';
  346. print '<a href="./card.php?piece_num=' . $line->piece_num . '">' . img_edit() . '</a>&nbsp;';
  347. print '<a href="' . $_SERVER['PHP_SELF'] . '?action=delmouv&mvt_num=' . $line->piece_num . $options . '&page=' . $page . '">' . img_delete() . '</a>';
  348. print '</td>';
  349. print "</tr>\n";
  350. }
  351. print '<tr class="liste_total">';
  352. print '<td colspan="6"></td>';
  353. print '<td align="right">';
  354. print price($total_debit);
  355. print '</td>';
  356. print '<td align="right">';
  357. print price($total_credit);
  358. print '</td>';
  359. print '<td colspan="2"></td>';
  360. print '</tr>';
  361. print "</table>";
  362. print '</form>';
  363. llxFooter();
  364. $db->close();