listbyaccount.php 14 KB

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