categories.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/accountancy/admin/categories.php
  20. * \ingroup Accountancy (Double entries)
  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. 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. }
  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('RecordModifiedSuccessfully'), null, 'mesgs');
  62. }
  63. }
  64. if ($action == 'delete') {
  65. if ($cpt_id) {
  66. if ($accountingcategory->deleteCptCat($cpt_id)) {
  67. setEventMessages($langs->trans('AccountRemovedFromGroup'), 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="'.newToken().'">';
  83. print '<input type="hidden" name="action" value="display">';
  84. print dol_get_fiche_head();
  85. print '<table class="border centpercent">';
  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. $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. $arraykeyvalue[length_accountg($val->numero_compte)] = length_accountg($val->numero_compte).' ('.$val->label_compte.($val->doc_ref ? ' '.$val->doc_ref : '').')';
  103. }
  104. if (is_array($accountingcategory->lines_cptbk) && count($accountingcategory->lines_cptbk) > 0) {
  105. print $form->multiselectarray('cpt_bk', $arraykeyvalue, GETPOST('cpt_bk', 'array'), null, null, null, null, "90%");
  106. print '<br>';
  107. /*print '<select class="flat minwidth200" size="8" name="cpt_bk[]" multiple>';
  108. foreach ( $accountingcategory->lines_cptbk as $cpt ) {
  109. print '<option value="' . length_accountg($cpt->numero_compte) . '">' . length_accountg($cpt->numero_compte) . ' (' . $cpt->label_compte . ' ' . $cpt->doc_ref . ')</option>';
  110. }
  111. print '</select><br>';
  112. print ajax_combobox('cpt_bk');
  113. */
  114. print '<input class="button" type="submit" id="" class="action-delete" value="'.$langs->trans("Add").'"> ';
  115. }
  116. print '</td></tr>';
  117. }
  118. print '</table>';
  119. print dol_get_fiche_end();
  120. print '</form>';
  121. if ($action == 'display' || $action == 'delete') {
  122. print "<table class='noborder' width='100%'>\n";
  123. print '<tr class="liste_titre">';
  124. print '<td class="liste_titre">'.$langs->trans("AccountAccounting")."</td>";
  125. print '<td class="liste_titre" colspan="2">'.$langs->trans("Label")."</td>";
  126. print "</tr>\n";
  127. if (!empty($cat_id)) {
  128. $return = $accountingcategory->display($cat_id); // This load ->lines_display
  129. if ($return < 0) {
  130. setEventMessages(null, $accountingcategory->errors, 'errors');
  131. }
  132. if (is_array($accountingcategory->lines_display) && count($accountingcategory->lines_display) > 0) {
  133. foreach ($accountingcategory->lines_display as $cpt) {
  134. print '<tr class="oddeven">';
  135. print '<td>'.length_accountg($cpt->account_number).'</td>';
  136. print '<td>'.$cpt->label.'</td>';
  137. print '<td class="right">';
  138. print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&account_category='.$cat_id.'&cptid='.$cpt->rowid.'">';
  139. print $langs->trans("DeleteFromCat");
  140. print img_picto($langs->trans("DeleteFromCat"), 'unlink', 'class="paddingleft"');
  141. print "</a>";
  142. print "</td>";
  143. print "</tr>\n";
  144. }
  145. }
  146. }
  147. print "</table>";
  148. }
  149. // End of page
  150. llxFooter();
  151. $db->close();