categories.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /* Copyright (C) 2016 Jamal Elbaz <jamelbaz@gmail.pro>
  3. * Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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. // Load translation files required by the page
  29. $langs->loadLangs(array("bills","accountancy"));
  30. $mesg = '';
  31. $id = GETPOST('id', 'int');
  32. $rowid = GETPOST('rowid', 'int');
  33. $cancel = GETPOST('cancel','alpha');
  34. $action = GETPOST('action','aZ09');
  35. $cat_id = GETPOST('account_category','int');
  36. $selectcpt = GETPOST('cpt_bk', 'array');
  37. $cpt_id = GETPOST('cptid','int');
  38. if ($cat_id == 0) {
  39. $cat_id = null;
  40. }
  41. // Security check
  42. if (empty($user->rights->accounting->chartofaccount))
  43. {
  44. accessforbidden();
  45. }
  46. $accountingcategory = new AccountancyCategory($db);
  47. /*
  48. * Actions
  49. */
  50. // si ajout de comptes
  51. if (! empty($selectcpt)) {
  52. $cpts = array ();
  53. foreach ( $selectcpt as $selectedoption ) {
  54. if (! array_key_exists($selectedoption, $cpts))
  55. $cpts[$selectedoption] = "'" . $selectedoption . "'";
  56. }
  57. $return= $accountingcategory->updateAccAcc($cat_id, $cpts);
  58. if ($return<0) {
  59. setEventMessages($langs->trans('errors'), $accountingcategory->errors, 'errors');
  60. } else {
  61. setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
  62. }
  63. }
  64. if ($action == 'delete') {
  65. if ($cpt_id) {
  66. if ($accountingcategory->deleteCptCat($cpt_id)) {
  67. setEventMessages($langs->trans('CategoryDeleted'), null, 'mesgs');
  68. } else {
  69. setEventMessages($langs->trans('errors'), null, 'errors');
  70. }
  71. }
  72. }
  73. /*
  74. * View
  75. */
  76. $form = new Form($db);
  77. $formaccounting = new FormAccounting($db);
  78. llxheader('', $langs->trans('AccountingCategory'));
  79. $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  80. print load_fiche_titre($langs->trans('AccountingCategory'), $linkback);
  81. print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
  82. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  83. print '<input type="hidden" name="action" value="display">';
  84. dol_fiche_head();
  85. print '<table class="border" width="100%">';
  86. // Select the category
  87. print '<tr><td class="titlefield">' . $langs->trans("AccountingCategory") . '</td>';
  88. print '<td>';
  89. $formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0, 1);
  90. print '<input class="button" type="submit" value="' . $langs->trans("Select") . '">';
  91. print '</td></tr>';
  92. // Select the accounts
  93. if (! empty($cat_id))
  94. {
  95. $return = $accountingcategory->getAccountsWithNoCategory($cat_id);
  96. if ($return < 0) {
  97. setEventMessages(null, $accountingcategory->errors, 'errors');
  98. }
  99. print '<tr><td>' . $langs->trans("AddAccountFromBookKeepingWithNoCategories") . '</td>';
  100. print '<td>';
  101. $arraykeyvalue=array();
  102. foreach($accountingcategory->lines_cptbk as $key => $val)
  103. {
  104. $arraykeyvalue[length_accountg($val->numero_compte)] = length_accountg($val->numero_compte) . ' (' . $val->label_compte . ($val->doc_ref?' '.$val->doc_ref:'').')';
  105. }
  106. if (is_array($accountingcategory->lines_cptbk) && count($accountingcategory->lines_cptbk) > 0) {
  107. print $form->multiselectarray('cpt_bk', $arraykeyvalue, GETPOST('cpt_bk', 'array'), null, null, null, null, "90%");
  108. print '<br>';
  109. /*print '<select class="flat minwidth200" size="8" name="cpt_bk[]" multiple>';
  110. foreach ( $accountingcategory->lines_cptbk as $cpt ) {
  111. print '<option value="' . length_accountg($cpt->numero_compte) . '">' . length_accountg($cpt->numero_compte) . ' (' . $cpt->label_compte . ' ' . $cpt->doc_ref . ')</option>';
  112. }
  113. print '</select><br>';
  114. print ajax_combobox('cpt_bk');
  115. */
  116. print '<input class="button" type="submit" id="" class="action-delete" value="' . $langs->trans("Add") . '"> ';
  117. }
  118. print '</td></tr>';
  119. }
  120. print '</table>';
  121. dol_fiche_end();
  122. print '</form>';
  123. if ($action == 'display' || $action == 'delete') {
  124. print "<table class='noborder' width='100%'>\n";
  125. print '<tr class="liste_titre">';
  126. print '<td class="liste_titre">'.$langs->trans("AccountAccounting")."</td>";
  127. print '<td class="liste_titre" colspan="2">'.$langs->trans("Label")."</td>";
  128. print "</tr>\n";
  129. if (! empty($cat_id)) {
  130. $return = $accountingcategory->display($cat_id); // This load ->lines_display
  131. if ($return < 0) {
  132. setEventMessages(null, $accountingcategory->errors, 'errors');
  133. }
  134. if (is_array($accountingcategory->lines_display) && count($accountingcategory->lines_display) > 0) {
  135. foreach ( $accountingcategory->lines_display as $cpt ) {
  136. print '<tr class="oddeven">';
  137. print '<td>' . length_accountg($cpt->account_number) . '</td>';
  138. print '<td>' . $cpt->label . '</td>';
  139. print '<td class="right">';
  140. print "<a href= '".$_SERVER['PHP_SELF']."?action=delete&account_category=" . $cat_id . "&cptid=" . $cpt->rowid."'>";
  141. print img_delete($langs->trans("DeleteFromCat")).' ';
  142. print $langs->trans("DeleteFromCat")."</a>";
  143. print "</td>";
  144. print "</tr>\n";
  145. }
  146. }
  147. }
  148. print "</table>";
  149. }
  150. // End of page
  151. llxFooter();
  152. $db->close();