categories.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /* Copyright (C) 2016 Jamal Elbaz <jamelbaz@gmail.pro>
  3. * Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/accountancy/admin/categories.php
  20. * \ingroup Advanced accountancy
  21. * \brief Page to assign mass categories to accounts
  22. */
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  25. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancycategory.class.php';
  26. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  27. $error = 0;
  28. $langs->load("bills");
  29. $langs->load("accountancy");
  30. $mesg = '';
  31. $id = GETPOST('id', 'int');
  32. $rowid = GETPOST('rowid', 'int');
  33. $cancel = GETPOST('cancel');
  34. $action = GETPOST('action','aZ09');
  35. $cat_id = GETPOST('account_category');
  36. $selectcpt = GETPOST('cpt_bk', 'array');
  37. $cpt_id = GETPOST('cptid');
  38. if ($cat_id == 0) {
  39. $cat_id = null;
  40. }
  41. // Security check
  42. if (! empty($user->rights->accountancy->chartofaccount))
  43. {
  44. accessforbidden();
  45. }
  46. $accountingcategory = new AccountancyCategory($db);
  47. // si ajout de comptes
  48. if (! empty($selectcpt)) {
  49. $cpts = array ();
  50. foreach ( $selectcpt as $selectedoption ) {
  51. if (! array_key_exists($selectedoption, $cpts))
  52. $cpts[$selectedoption] = "'" . $selectedoption . "'";
  53. }
  54. $return= $accountingcategory->updateAccAcc($cat_id, $cpts);
  55. if ($return<0) {
  56. setEventMessages($langs->trans('errors'), $accountingcategory->errors, 'errors');
  57. } else {
  58. setEventMessages($langs->trans('Saved'), null, 'mesgs');
  59. }
  60. }
  61. if ($action == 'delete') {
  62. if ($cpt_id) {
  63. if ($accountingcategory->deleteCptCat($cpt_id)) {
  64. setEventMessages($langs->trans('CategoryDeleted'), null, 'mesgs');
  65. } else {
  66. setEventMessages($langs->trans('errors'), null, 'errors');
  67. }
  68. }
  69. }
  70. /*
  71. * View
  72. */
  73. $form = new Form($db);
  74. $formaccounting = new FormAccounting($db);
  75. llxheader('', $langs->trans('AccountAccounting'));
  76. print load_fiche_titre($langs->trans('AccountingCategory'));
  77. print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
  78. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  79. print '<input type="hidden" name="action" value="display">';
  80. dol_fiche_head();
  81. print '<table class="border" width="100%">';
  82. // Category
  83. print '<tr><td>' . $langs->trans("AccountingCategory") . '</td>';
  84. print '<td>';
  85. $formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0, 1);
  86. print '<input class="button" type="submit" value="' . $langs->trans("Select") . '">';
  87. print '</td></tr>';
  88. if (! empty($cat_id))
  89. {
  90. $return = $accountingcategory->getAccountsWithNoCategory($cat_id);
  91. if ($return < 0) {
  92. setEventMessages(null, $accountingcategory->errors, 'errors');
  93. }
  94. print '<tr><td>' . $langs->trans("AddAccountFromBookKeepingWithNoCategories") . '</td>';
  95. print '<td>';
  96. if (is_array($accountingcategory->lines_cptbk) && count($accountingcategory->lines_cptbk) > 0) {
  97. print '<select class="flat minwidth200" size="' . count($obj) . '" name="cpt_bk[]" multiple>';
  98. foreach ( $accountingcategory->lines_cptbk as $cpt ) {
  99. print '<option value="' . length_accountg($cpt->numero_compte) . '">' . length_accountg($cpt->numero_compte) . ' (' . $cpt->label_compte . ' ' . $cpt->doc_ref . ')</option>';
  100. }
  101. print '</select><br>';
  102. print '<input class="button" type="submit" id="" class="action-delete" value="' . $langs->trans("Add") . '"> ';
  103. }
  104. print '</td></tr>';
  105. }
  106. print '</table>';
  107. dol_fiche_end();
  108. print '</form>';
  109. if ($action == 'display' || $action == 'delete') {
  110. print "<table class='noborder' width='100%'>\n";
  111. print '<tr class="liste_titre">';
  112. print '<td class="liste_titre">'.$langs->trans("AccountAccounting")."</td>";
  113. print '<td class="liste_titre" colspan="2">'.$langs->trans("Label")."</td>";
  114. print "</tr>\n";
  115. if (! empty($cat_id)) {
  116. $return = $accountingcategory->display($cat_id);
  117. if ($return < 0) {
  118. setEventMessages(null, $accountingcategory->errors, 'errors');
  119. }
  120. if (is_array($accountingcategory->lines_display) && count($accountingcategory->lines_display) > 0) {
  121. foreach ( $accountingcategory->lines_display as $cpt ) {
  122. print '<tr class="oddeven">';
  123. print '<td>' . length_accountg($cpt->account_number) . '</td>';
  124. print '<td>' . $cpt->label . '</td>';
  125. print '<td align="right">';
  126. print "<a href= '".$_SERVER['PHP_SELF']."?action=delete&account_category=" . $cat_id . "&cptid=" . $cpt->rowid."'>";
  127. print img_delete($langs->trans("DeleteFromCat")).' ';
  128. print $langs->trans("DeleteFromCat")."</a>";
  129. print "</td>";
  130. print "</tr>\n";
  131. }
  132. }
  133. }
  134. print "</table>";
  135. }
  136. llxFooter();
  137. $db->close();