listbyaccount.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <?php
  2. /*
  3. * Copyright (C) 2016 Neil Orley <neil.orley@oeris.fr> largely based on the great work of :
  4. * - Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
  5. * - Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
  6. * - Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  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 <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/accountancy/bookkeeping/listbyaccount.php
  23. * \ingroup Advanced accountancy
  24. * \brief List operation of book keeping ordered by account number
  25. */
  26. require '../../main.inc.php';
  27. // Class
  28. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  29. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  32. // Langs
  33. $langs->load("accountancy");
  34. $page = GETPOST("page");
  35. $sortorder = GETPOST("sortorder");
  36. $sortfield = GETPOST("sortfield");
  37. $action = GETPOST('action', 'alpha');
  38. $search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
  39. $search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));
  40. $search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
  41. $search_accountancy_code = GETPOST("search_accountancy_code");
  42. $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
  43. if ($search_accountancy_code_start == - 1) {
  44. $search_accountancy_code_start = '';
  45. }
  46. $search_label_account = GETPOST('search_label_account', 'alpha');
  47. $search_mvt_label = GETPOST('search_mvt_label', 'alpha');
  48. $search_direction = GETPOST('search_direction', 'alpha');
  49. $search_ledger_code = GETPOST('search_ledger_code', 'alpha');
  50. // Load variable for pagination
  51. $limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  52. $sortfield = GETPOST('sortfield', 'alpha');
  53. $sortorder = GETPOST('sortorder', 'alpha');
  54. $page = GETPOST('page','int');
  55. if ($page < 0) { $page = 0; }
  56. $offset = $limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. if ($sortorder == "") $sortorder = "ASC";
  60. if ($sortfield == "") $sortfield = "t.rowid";
  61. if (empty($search_date_start)) $search_date_start = dol_mktime(0, 0, 0, 1, 1, dol_print_date(dol_now(), '%Y'));
  62. if (empty($search_date_end)) $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_print_date(dol_now(), '%Y'));
  63. $object = new BookKeeping($db);
  64. $formaccounting = new FormAccounting($db);
  65. $formother = new FormOther($db);
  66. $form = new Form($db);
  67. $options = '';
  68. $filter = array ();
  69. if (! empty($search_date_start)) {
  70. $filter['t.doc_date>='] = $search_date_start;
  71. $options .= '&amp;date_startmonth=' . GETPOST('date_startmonth', 'int') . '&amp;date_startday=' . GETPOST('date_startday', 'int') . '&amp;date_startyear=' . GETPOST('date_startyear', 'int');
  72. }
  73. if (! empty($search_date_end)) {
  74. $filter['t.doc_date<='] = $search_date_end;
  75. $options .= '&amp;date_endmonth=' . GETPOST('date_endmonth', 'int') . '&amp;date_endday=' . GETPOST('date_endday', 'int') . '&amp;date_endyear=' . GETPOST('date_endyear', 'int');
  76. }
  77. if (! empty($search_doc_date)) {
  78. $filter['t.doc_date'] = $search_doc_date;
  79. $options .= '&amp;doc_datemonth=' . GETPOST('doc_datemonth', 'int') . '&amp;doc_dateday=' . GETPOST('doc_dateday', 'int') . '&amp;doc_dateyear=' . GETPOST('doc_dateyear', 'int');
  80. }
  81. if (!GETPOST("button_removefilter_x") && !GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  82. {
  83. if (! empty($search_accountancy_code_start)) {
  84. $filter['t.numero_compte'] = $search_accountancy_code_start;
  85. $options .= '&amp;search_accountancy_code_start=' . $search_accountancy_code_start;
  86. }
  87. if (! empty($search_label_account)) {
  88. $filter['t.label_compte'] = $search_label_account;
  89. $options .= '&amp;search_label_account=' . $search_label_account;
  90. }
  91. if (! empty($search_mvt_label)) {
  92. $filter['t.label_compte'] = $search_mvt_label;
  93. $options .= '&amp;search_mvt_label=' . $search_mvt_label;
  94. }
  95. if (! empty($search_direction)) {
  96. $filter['t.sens'] = $search_direction;
  97. $options .= '&amp;search_direction=' . $search_direction;
  98. }
  99. if (! empty($search_ledger_code)) {
  100. $filter['t.code_journal'] = $search_ledger_code;
  101. $options .= '&amp;search_ledger_code=' . $search_ledger_code;
  102. }
  103. }
  104. /*
  105. * Action
  106. */
  107. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
  108. {
  109. $search_doc_date = '';
  110. $search_accountancy_code = '';
  111. $search_accountancy_code_start = '';
  112. $search_label_account = '';
  113. $search_mvt_label = '';
  114. $search_direction = '';
  115. $search_ledger_code = '';
  116. }
  117. if ($action == 'delmouvconfirm') {
  118. $mvt_num = GETPOST('mvt_num', 'int');
  119. if (! empty($mvt_num)) {
  120. $result = $object->deleteMvtNum($mvt_num);
  121. if ($result < 0) {
  122. setEventMessages($object->error, $object->errors, 'errors');
  123. }
  124. Header("Location: listbyaccount.php");
  125. exit();
  126. }
  127. }
  128. /*
  129. * View
  130. */
  131. $title_page = $langs->trans("Bookkeeping") . ' ' . strtolower($langs->trans("By")) . ' ' . $langs->trans("AccountAccounting");
  132. llxHeader('', $title_page);
  133. // List
  134. $nbtotalofrecords = '';
  135. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  136. $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter);
  137. if ($nbtotalofrecords < 0) {
  138. setEventMessages($object->error, $object->errors, 'errors');
  139. }
  140. }
  141. $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter);
  142. if ($result < 0) {
  143. setEventMessages($object->error, $object->errors, 'errors');
  144. }
  145. $nbtotalofrecords = $result;
  146. if ($action == 'delmouv') {
  147. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?mvt_num=' . GETPOST('mvt_num'), $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delmouvconfirm', '', 0, 1);
  148. print $formconfirm;
  149. }
  150. if ($action == 'delbookkeepingyear') {
  151. $form_question = array ();
  152. $delyear = GETPOST('delyear');
  153. if (empty($delyear)) {
  154. $delyear = dol_print_date(dol_now(), '%Y');
  155. }
  156. $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
  157. $form_question['delyear'] = array (
  158. 'name' => 'delyear',
  159. 'type' => 'select',
  160. 'label' => $langs->trans('DelYear'),
  161. 'values' => $year_array,
  162. 'default' => $delyear
  163. );
  164. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delbookkeepingyearconfirm', $form_question, 0, 1, 250);
  165. print $formconfirm;
  166. }
  167. print '<form method="GET" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '">';
  168. $viewflat = ' <a class="nohover" href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php">' . $langs->trans("ViewFlatList") . '</a>';
  169. print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords,'title_accountancy',0,$viewflat,'',$limit);
  170. // Reverse sort order
  171. if ( preg_match('/^asc/i', $sortorder) )
  172. $sortorder = "asc";
  173. else
  174. $sortorder = "desc";
  175. print '<div class="tabsAction">' . "\n";
  176. print '<div class="inline-block divButAction"><a class="butAction" href="./card.php?action=create">' . $langs->trans("NewAccountingMvt") . '</a></div>';
  177. print '</div>';
  178. print '<table class="noborder" width="100%">';
  179. print '<tr class="liste_titre">';
  180. print '<td class="liste_titre">' . $object->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, '') . '</td>';
  181. print '<td class="liste_titre"></td>';
  182. print '<td class="liste_titre" align="center">';
  183. print $langs->trans('From') . ': ';
  184. print $form->select_date($search_date_start, 'date_start', 0, 0, 1);
  185. print '<br>';
  186. print $langs->trans('to') . ': ';
  187. print $form->select_date($search_date_end, 'date_end', 0, 0, 1);
  188. print '</td>';
  189. print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_mvt_label" value="' . $search_mvt_label . '"/></td>';
  190. print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_label_account" value="' . $search_label_account . '"/></td>';
  191. print '<td class="liste_titre">&nbsp;</td>';
  192. print '<td class="liste_titre">&nbsp;</td>';
  193. print '<td class="liste_titre" align="right"><input type="text" name="search_ledger_code" size="3" value="' . $search_ledger_code . '"></td>';
  194. print '<td class="liste_titre" align="right" colspan="2">';
  195. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  196. print $searchpicto;
  197. print '</td>';
  198. print '<tr class="liste_titre">';
  199. print_liste_field_titre($langs->trans("AccountAccountingShort"), $_SERVER['PHP_SELF']);
  200. print_liste_field_titre($langs->trans("TransactionNumShort"), $_SERVER['PHP_SELF'], "t.piece_num", "", $options, 'align="right"', $sortfield, $sortorder);
  201. print_liste_field_titre($langs->trans("Docdate"), $_SERVER['PHP_SELF'], "t.doc_date", "", $options, 'align="center"', $sortfield, $sortorder);
  202. print_liste_field_titre($langs->trans("Docref"), $_SERVER['PHP_SELF'], "t.doc_ref", "", $options, "", $sortfield, $sortorder);
  203. print_liste_field_titre($langs->trans("Label"));
  204. print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder);
  205. print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder);
  206. print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="right"', $sortfield, $sortorder);
  207. print_liste_field_titre('', $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder);
  208. print "</tr>\n";
  209. print '</tr>';
  210. $var = True;
  211. $total_debit = 0;
  212. $total_credit = 0;
  213. $sous_total_debit = 0;
  214. $sous_total_credit = 0;
  215. $displayed_account_number = null; // Start with undefined to be able to distinguish with empty
  216. foreach ( $object->lines as $line ) {
  217. $total_debit += $line->debit;
  218. $total_credit += $line->credit;
  219. $accountg = length_accountg($line->numero_compte);
  220. //if (empty($accountg)) $accountg = '-';
  221. // Is it a break ?
  222. if ($accountg != $displayed_account_number || ! isset($displayed_account_number)) {
  223. // Affiche un Sous-Total par compte comptable
  224. if (isset($displayed_account_number)) {
  225. print '<tr class="liste_total"><td align="right" colspan="5">'.$langs->trans("SubTotal").':</td><td class="nowrap" align="right">'.price($sous_total_debit).'</td><td class="nowrap" align="right">'.price($sous_total_credit).'</td>';
  226. print "<td>&nbsp;</td>\n";
  227. print "<td>&nbsp;</td>\n";
  228. print '</tr>';
  229. }
  230. // Show the break account
  231. $colspan = 9;
  232. print "<tr>";
  233. print '<td colspan="'.$colspan.'" style="font-weight:bold; border-bottom: 1pt solid black;">';
  234. if (! empty($line->numero_compte) && $line->numero_compte != '-1') print length_accountg($line->numero_compte) . ' : ' . $object->get_compte_desc($line->numero_compte);
  235. else print '<span class="error">'.$langs->trans("Unknown").'</span>';
  236. print '</td>';
  237. print '</tr>';
  238. $displayed_account_number = $accountg;
  239. //if (empty($displayed_account_number)) $displayed_account_number='-';
  240. $sous_total_debit = 0;
  241. $sous_total_credit = 0;
  242. }
  243. print '<tr class="oddeven">';
  244. print '<td>&nbsp;</td>';
  245. print '<td align="right"><a href="./card.php?piece_num=' . $line->piece_num . '">'.$line->piece_num.'</a></td>';
  246. print '<td align="center">' . dol_print_date($line->doc_date, 'day') . '</td>';
  247. // TODO Add a link according to doc_type and fk_doc
  248. print '<td class="nowrap">';
  249. //if ($line->doc_type == 'supplier_invoice')
  250. //if ($line->doc_type == 'customer_invoice')
  251. print $line->doc_ref;
  252. print '</td>';
  253. // Affiche un lien vers la facture client/fournisseur
  254. $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref);
  255. print strlen(length_accounta($line->code_tiers)) == 0 ? '<td>' . $line->label_compte . '</td>' : '<td>' . $line->label_compte . '<br /><span style="font-size:0.8em">(' . length_accounta($line->code_tiers) . ')</span></td>';
  256. print '<td align="right">' . price($line->debit) . '</td>';
  257. print '<td align="right">' . price($line->credit) . '</td>';
  258. print '<td align="center">' . $line->code_journal . '</td>';
  259. print '<td align="center">';
  260. print '<a href="./card.php?piece_num=' . $line->piece_num . '">' . img_edit() . '</a>&nbsp;';
  261. print '<a href="' . $_SERVER['PHP_SELF'] . '?action=delmouv&mvt_num=' . $line->piece_num . $options . '&page=' . $page . '">' . img_delete() . '</a>';
  262. print '</td>';
  263. print "</tr>\n";
  264. // Comptabilise le sous-total
  265. $sous_total_debit += $line->debit;
  266. $sous_total_credit += $line->credit;
  267. }
  268. // Affiche un Sous-Total du dernier compte comptable affiché
  269. print '<tr class="liste_total">';
  270. print '<td align="right" colspan="5">'.$langs->trans("SubTotal").':</td><td class="nowrap" align="right">'.price($sous_total_debit).'</td><td class="nowrap" align="right">'.price($sous_total_credit).'</td>';
  271. print "<td>&nbsp;</td>\n";
  272. print "<td>&nbsp;</td>\n";
  273. print '</tr>';
  274. // Affiche le Total
  275. print '<tr class="liste_total">';
  276. print '<td align="right" colspan="5">'.$langs->trans("Total").':</td>';
  277. print '<td align="right">';
  278. print price($total_debit);
  279. print '</td>';
  280. print '<td align="right">';
  281. print price($total_credit);
  282. print '</td>';
  283. print '<td colspan="2"></td>';
  284. print '</tr>';
  285. print "</table>";
  286. print '</form>';
  287. llxFooter();
  288. $db->close();