categories.php 5.8 KB

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