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