dolibarr  16.0.5
categories.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2016 Jamal Elbaz <jamelbaz@gmail.pro>
3  * Copyright (C) 2017-2022 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 
25 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
29 
30 $error = 0;
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("bills", "accountancy"));
34 
35 $id = GETPOST('id', 'int');
36 $cancel = GETPOST('cancel', 'alpha');
37 $action = GETPOST('action', 'aZ09');
38 $cat_id = GETPOST('account_category', 'int');
39 $selectcpt = GETPOST('cpt_bk', 'array');
40 $cpt_id = GETPOST('cptid', 'int');
41 
42 if ($cat_id == 0) {
43  $cat_id = null;
44 }
45 
46 // Security check
47 if (empty($user->rights->accounting->chartofaccount)) {
49 }
50 
51 $accountingcategory = new AccountancyCategory($db);
52 
53 
54 /*
55  * Actions
56  */
57 
58 // If we add account
59 if (!empty($selectcpt)) {
60  $cpts = array();
61  foreach ($selectcpt as $selectedoption) {
62  if (!array_key_exists($selectedoption, $cpts)) {
63  $cpts[$selectedoption] = "'".$selectedoption."'";
64  }
65  }
66 
67  $return = $accountingcategory->updateAccAcc($cat_id, $cpts);
68 
69  if ($return < 0) {
70  setEventMessages($langs->trans('errors'), $accountingcategory->errors, 'errors');
71  } else {
72  setEventMessages($langs->trans('RecordModifiedSuccessfully'), null, 'mesgs');
73  }
74 }
75 
76 if ($action == 'delete') {
77  if ($cpt_id) {
78  if ($accountingcategory->deleteCptCat($cpt_id)) {
79  setEventMessages($langs->trans('AccountRemovedFromGroup'), null, 'mesgs');
80  } else {
81  setEventMessages($langs->trans('errors'), null, 'errors');
82  }
83  }
84 }
85 
86 
87 /*
88  * View
89  */
90 
91 $form = new Form($db);
92 $formaccounting = new FormAccounting($db);
93 
94 llxheader('', $langs->trans('AccountingCategory'));
95 
96 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
97 $titlepicto = 'setup';
98 
99 print load_fiche_titre($langs->trans('AccountingCategory'), $linkback, $titlepicto);
100 
101 print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
102 print '<input type="hidden" name="token" value="'.newToken().'">';
103 print '<input type="hidden" name="action" value="display">';
104 
105 print dol_get_fiche_head();
106 
107 print '<table class="border centpercent">';
108 
109 // Select the category
110 print '<tr><td class="titlefield">'.$langs->trans("AccountingCategory").'</td>';
111 print '<td>';
112 $formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0, 1);
113 print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
114 print '</td></tr>';
115 
116 // Select the accounts
117 if (!empty($cat_id)) {
118  $return = $accountingcategory->getAccountsWithNoCategory($cat_id);
119  if ($return < 0) {
120  setEventMessages(null, $accountingcategory->errors, 'errors');
121  }
122  print '<tr><td>'.$langs->trans("AddAccountFromBookKeepingWithNoCategories").'</td>';
123  print '<td>';
124 
125  $arraykeyvalue = array();
126  foreach ($accountingcategory->lines_cptbk as $key => $val) {
127  $doc_ref = !empty($val->doc_ref) ? $val->doc_ref : '';
128  $arraykeyvalue[length_accountg($val->numero_compte)] = length_accountg($val->numero_compte) . ' - ' . $val->label_compte . ($doc_ref ? ' '.$doc_ref : '');
129  }
130 
131  if (is_array($accountingcategory->lines_cptbk) && count($accountingcategory->lines_cptbk) > 0) {
132  print $form->multiselectarray('cpt_bk', $arraykeyvalue, GETPOST('cpt_bk', 'array'), null, null, null, null, "90%");
133  print '<br>';
134  /*print '<select class="flat minwidth200" size="8" name="cpt_bk[]" multiple>';
135  foreach ( $accountingcategory->lines_cptbk as $cpt ) {
136  print '<option value="' . length_accountg($cpt->numero_compte) . '">' . length_accountg($cpt->numero_compte) . ' (' . $cpt->label_compte . ' ' . $cpt->doc_ref . ')</option>';
137  }
138  print '</select><br>';
139  print ajax_combobox('cpt_bk');
140  */
141  print '<input type="submit" class="button button-add" id="" class="action-delete" value="'.$langs->trans("Add").'"> ';
142  }
143  print '</td></tr>';
144 }
145 
146 print '</table>';
147 
148 print dol_get_fiche_end();
149 
150 print '</form>';
151 
152 
153 if ($action == 'display' || $action == 'delete') {
154  print "<table class='noborder' width='100%'>\n";
155  print '<tr class="liste_titre">';
156  print '<td class="liste_titre">'.$langs->trans("AccountAccounting")."</td>";
157  print '<td class="liste_titre" colspan="2">'.$langs->trans("Label")."</td>";
158  print "</tr>\n";
159 
160  if (!empty($cat_id)) {
161  $return = $accountingcategory->display($cat_id); // This load ->lines_display
162  if ($return < 0) {
163  setEventMessages(null, $accountingcategory->errors, 'errors');
164  }
165 
166  if (is_array($accountingcategory->lines_display) && count($accountingcategory->lines_display) > 0) {
167  foreach ($accountingcategory->lines_display as $cpt) {
168  print '<tr class="oddeven">';
169  print '<td>'.length_accountg($cpt->account_number).'</td>';
170  print '<td>'.$cpt->label.'</td>';
171  print '<td class="right">';
172  print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&account_category='.$cat_id.'&cptid='.$cpt->rowid.'">';
173  print $langs->trans("DeleteFromCat");
174  print img_picto($langs->trans("DeleteFromCat"), 'unlink', 'class="paddingleft"');
175  print "</a>";
176  print "</td>";
177  print "</tr>\n";
178  }
179  }
180  }
181 
182  print "</table>";
183 }
184 
185 // End of page
186 llxFooter();
187 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
AccountancyCategory
Class to manage categories of an accounting account.
Definition: accountancycategory.class.php:32
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
length_accountg
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
Definition: accounting.lib.php:94
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933