dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
33
42$error = 0;
43
44// Load translation files required by the page
45$langs->loadLangs(array("bills", "accountancy", "compta"));
46
47$id = GETPOSTINT('id');
48$cancel = GETPOST('cancel', 'alpha');
49$action = GETPOST('action', 'aZ09');
50$cat_id = GETPOSTINT('account_category');
51$selectcpt = GETPOST('cpt_bk', 'array');
52$cpt_id = GETPOSTINT('cptid');
53
54if ($cat_id == 0) {
55 $cat_id = null;
56}
57
58// Load variable for pagination
59$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
60$sortfield = GETPOST('sortfield', 'aZ09comma');
61$sortorder = GETPOST('sortorder', 'aZ09comma');
62$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
63if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
64 // If $page is not defined, or '' or -1 or if we click on clear filters
65 $page = 0;
66}
67$offset = $limit * $page;
68$pageprev = $page - 1;
69$pagenext = $page + 1;
70
71if (empty($sortfield)) {
72 $sortfield = 'account_number';
73}
74if (empty($sortorder)) {
75 $sortorder = 'ASC';
76}
77
78// Security check
79if (!$user->hasRight('accounting', 'chartofaccount')) {
81}
82
83$accountingcategory = new AccountancyCategory($db);
84
85
86/*
87 * Actions
88 */
89
90// If we add account
91if (!empty($selectcpt)) {
92 $cpts = array();
93 foreach ($selectcpt as $selectedoption) {
94 if (!array_key_exists($selectedoption, $cpts)) {
95 $cpts[$selectedoption] = "'".$selectedoption."'";
96 }
97 }
98
99 $return = $accountingcategory->updateAccAcc($cat_id, $cpts);
100
101 if ($return < 0) {
102 setEventMessages($langs->trans('errors'), $accountingcategory->errors, 'errors');
103 } else {
104 setEventMessages($langs->trans('RecordModifiedSuccessfully'), null, 'mesgs');
105 }
106}
107
108if ($action == 'delete') {
109 if ($cpt_id) {
110 if ($accountingcategory->deleteCptCat($cpt_id)) {
111 setEventMessages($langs->trans('AccountRemovedFromGroup'), null, 'mesgs');
112 } else {
113 setEventMessages($langs->trans('errors'), null, 'errors');
114 }
115 }
116}
117
118
119/*
120 * View
121 */
122
123$form = new Form($db);
124$formaccounting = new FormAccounting($db);
125
126$title= $langs->trans('AccountingCategory');
127$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
128
129llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_categories');
130
131$linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
132$titlepicto = 'setup';
133
134print load_fiche_titre($langs->trans('AccountingCategory'), $linkback, $titlepicto);
135
136print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
137print '<input type="hidden" name="token" value="'.newToken().'">';
138print '<input type="hidden" name="action" value="display">';
139
140print dol_get_fiche_head();
141
142print '<table class="border centpercent">';
143
144// Select the category
145print '<tr><td class="titlefield">'.$langs->trans("AccountingCategory").'</td>';
146print '<td>';
147$s = $formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0, 0);
148if ($formaccounting->nbaccounts_category <= 0) {
149 print '<span class="opacitymedium">'.$s.'</span>';
150} else {
151 print $s;
152 print '<input type="submit" class="button small" value="'.$langs->trans("Select").'">';
153}
154print '</td></tr>';
155
156print '</table>';
157
158print dol_get_fiche_end();
159
160
161// Select the accounts
162if (!empty($cat_id)) {
163 $return = $accountingcategory->getAccountsWithNoCategory($cat_id);
164 if ($return < 0) {
165 setEventMessages(null, $accountingcategory->errors, 'errors');
166 }
167 print '<br>';
168
169 $arraykeyvalue = array();
170 foreach ($accountingcategory->lines_cptbk as $key => $val) {
171 $doc_ref = !empty($val->doc_ref) ? $val->doc_ref : '';
172 $arraykeyvalue[length_accountg($val->numero_compte)] = length_accountg($val->numero_compte) . ' - ' . $val->label_compte . ($doc_ref ? ' '.$doc_ref : '');
173 }
174
175 if (is_array($accountingcategory->lines_cptbk) && count($accountingcategory->lines_cptbk) > 0) {
176 print img_picto($langs->trans("AccountingAccount"), 'accounting_account', 'class="pictofixedwidth"');
177 print $form->multiselectarray('cpt_bk', $arraykeyvalue, GETPOST('cpt_bk', 'array'), 0, 0, '', 0, "80%", '', '', $langs->transnoentitiesnoconv("AddAccountFromBookKeepingWithNoCategories"));
178 print '<input type="submit" class="button button-add small" id="" class="action-delete" value="'.$langs->trans("Add").'"> ';
179 }
180}
181
182print '</form>';
183
184
185if ((empty($action) || $action == 'display' || $action == 'delete') && $cat_id > 0) {
186 $param = 'account_category='.((int) $cat_id);
187
188 print '<br>';
189 print '<table class="noborder centpercent">'."\n";
190 print '<tr class="liste_titre">';
191 print getTitleFieldOfList('AccountAccounting', 0, $_SERVER['PHP_SELF'], 'account_number', '', $param, '', $sortfield, $sortorder, '')."\n";
192 print getTitleFieldOfList('Label', 0, $_SERVER['PHP_SELF'], 'label', '', $param, '', $sortfield, $sortorder, '')."\n";
193 print getTitleFieldOfList('', 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '')."\n";
194 print '</tr>'."\n";
195
196 if (!empty($cat_id)) {
197 $return = $accountingcategory->display($cat_id); // This load ->lines_display
198 if ($return < 0) {
199 setEventMessages(null, $accountingcategory->errors, 'errors');
200 }
201
202 if (is_array($accountingcategory->lines_display) && count($accountingcategory->lines_display) > 0) {
203 $accountingcategory->lines_display = dol_sort_array($accountingcategory->lines_display, $sortfield, $sortorder, -1, 0, 1);
204
205 foreach ($accountingcategory->lines_display as $cpt) {
206 print '<tr class="oddeven">';
207 print '<td>'.length_accountg($cpt->account_number).'</td>';
208 print '<td>'.$cpt->label.'</td>';
209 print '<td class="right">';
210 print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&account_category='.$cat_id.'&cptid='.$cpt->rowid.'">';
211 print $langs->trans("DeleteFromCat");
212 print img_picto($langs->trans("DeleteFromCat"), 'unlink', 'class="paddingleft"');
213 print "</a>";
214 print "</td>";
215 print "</tr>\n";
216 }
217 } else {
218 print '<tr><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
219 }
220 }
221
222 print "</table>";
223}
224
225// End of page
226llxFooter();
227$db->close();
$id
Definition account.php:48
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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
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.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.