dolibarr 18.0.6
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 * Copyright (C) 2022 Laurent Destailleur <eldy@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
31
32$error = 0;
33
34// Load translation files required by the page
35$langs->loadLangs(array("bills", "accountancy", "compta"));
36
37$id = GETPOST('id', 'int');
38$cancel = GETPOST('cancel', 'alpha');
39$action = GETPOST('action', 'aZ09');
40$cat_id = GETPOST('account_category', 'int');
41$selectcpt = GETPOST('cpt_bk', 'array');
42$cpt_id = GETPOST('cptid', 'int');
43
44if ($cat_id == 0) {
45 $cat_id = null;
46}
47
48// Load variable for pagination
49$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
50$sortfield = GETPOST('sortfield', 'aZ09comma');
51$sortorder = GETPOST('sortorder', 'aZ09comma');
52$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
53if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
54 // If $page is not defined, or '' or -1 or if we click on clear filters
55 $page = 0;
56}
57$offset = $limit * $page;
58$pageprev = $page - 1;
59$pagenext = $page + 1;
60
61if (empty($sortfield)) {
62 $sortfield = 'account_number';
63}
64if (empty($sortorder)) {
65 $sortorder = 'ASC';
66}
67
68// Security check
69if (!$user->hasRight('accounting', 'chartofaccount')) {
71}
72
73$accountingcategory = new AccountancyCategory($db);
74
75
76/*
77 * Actions
78 */
79
80// If we add account
81if (!empty($selectcpt)) {
82 $cpts = array();
83 foreach ($selectcpt as $selectedoption) {
84 if (!array_key_exists($selectedoption, $cpts)) {
85 $cpts[$selectedoption] = "'".$selectedoption."'";
86 }
87 }
88
89 $return = $accountingcategory->updateAccAcc($cat_id, $cpts);
90
91 if ($return < 0) {
92 setEventMessages($langs->trans('errors'), $accountingcategory->errors, 'errors');
93 } else {
94 setEventMessages($langs->trans('RecordModifiedSuccessfully'), null, 'mesgs');
95 }
96}
97
98if ($action == 'delete') {
99 if ($cpt_id) {
100 if ($accountingcategory->deleteCptCat($cpt_id)) {
101 setEventMessages($langs->trans('AccountRemovedFromGroup'), null, 'mesgs');
102 } else {
103 setEventMessages($langs->trans('errors'), null, 'errors');
104 }
105 }
106}
107
108
109/*
110 * View
111 */
112
113$form = new Form($db);
114$formaccounting = new FormAccounting($db);
115
116llxheader('', $langs->trans('AccountingCategory'));
117
118$linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
119$titlepicto = 'setup';
120
121print load_fiche_titre($langs->trans('AccountingCategory'), $linkback, $titlepicto);
122
123print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
124print '<input type="hidden" name="token" value="'.newToken().'">';
125print '<input type="hidden" name="action" value="display">';
126
127print dol_get_fiche_head();
128
129print '<table class="border centpercent">';
130
131// Select the category
132print '<tr><td class="titlefield">'.$langs->trans("AccountingCategory").'</td>';
133print '<td>';
134$s = $formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0, 0);
135if ($formaccounting->nbaccounts_category <= 0) {
136 print '<span class="opacitymedium">'.$s.'</span>';
137} else {
138 print '<input type="submit" class="button small" value="'.$langs->trans("Select").'">';
139}
140print '</td></tr>';
141
142print '</table>';
143
144print dol_get_fiche_end();
145
146
147// Select the accounts
148if (!empty($cat_id)) {
149 $return = $accountingcategory->getAccountsWithNoCategory($cat_id);
150 if ($return < 0) {
151 setEventMessages(null, $accountingcategory->errors, 'errors');
152 }
153 print '<br>';
154
155 $arraykeyvalue = array();
156 foreach ($accountingcategory->lines_cptbk as $key => $val) {
157 $doc_ref = !empty($val->doc_ref) ? $val->doc_ref : '';
158 $arraykeyvalue[length_accountg($val->numero_compte)] = length_accountg($val->numero_compte) . ' - ' . $val->label_compte . ($doc_ref ? ' '.$doc_ref : '');
159 }
160
161 if (is_array($accountingcategory->lines_cptbk) && count($accountingcategory->lines_cptbk) > 0) {
162 print img_picto($langs->trans("AccountingAccount"), 'accounting_account', 'class="pictofixedwith"');
163 print $form->multiselectarray('cpt_bk', $arraykeyvalue, GETPOST('cpt_bk', 'array'), null, null, '', 0, "80%", '', '', $langs->transnoentitiesnoconv("AddAccountFromBookKeepingWithNoCategories"));
164 print '<input type="submit" class="button button-add small" id="" class="action-delete" value="'.$langs->trans("Add").'"> ';
165 }
166}
167
168print '</form>';
169
170
171if ((empty($action) || $action == 'display' || $action == 'delete') && $cat_id > 0) {
172 $param = 'account_category='.((int) $cat_id);
173
174 print '<br>';
175 print '<table class="noborder centpercent">'."\n";
176 print '<tr class="liste_titre">';
177 print getTitleFieldOfList('AccountAccounting', 0, $_SERVER['PHP_SELF'], 'account_number', '', $param, '', $sortfield, $sortorder, '')."\n";
178 print getTitleFieldOfList('Label', 0, $_SERVER['PHP_SELF'], 'label', '', $param, '', $sortfield, $sortorder, '')."\n";
179 print getTitleFieldOfList('', 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '')."\n";
180 print '</tr>'."\n";
181
182 if (!empty($cat_id)) {
183 $return = $accountingcategory->display($cat_id); // This load ->lines_display
184 if ($return < 0) {
185 setEventMessages(null, $accountingcategory->errors, 'errors');
186 }
187
188 if (is_array($accountingcategory->lines_display) && count($accountingcategory->lines_display) > 0) {
189 $accountingcategory->lines_display = dol_sort_array($accountingcategory->lines_display, $sortfield, $sortorder, -1, 0, 1);
190
191 foreach ($accountingcategory->lines_display as $cpt) {
192 print '<tr class="oddeven">';
193 print '<td>'.length_accountg($cpt->account_number).'</td>';
194 print '<td>'.$cpt->label.'</td>';
195 print '<td class="right">';
196 print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&account_category='.$cat_id.'&cptid='.$cpt->rowid.'">';
197 print $langs->trans("DeleteFromCat");
198 print img_picto($langs->trans("DeleteFromCat"), 'unlink', 'class="paddingleft"');
199 print "</a>";
200 print "</td>";
201 print "</tr>\n";
202 }
203 } else {
204 print '<tr><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
205 }
206 }
207
208 print "</table>";
209}
210
211// End of page
212llxFooter();
213$db->close();
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage categories of an accounting account.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.