dolibarr  17.0.3
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
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
30 require_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 
44 if ($cat_id == 0) {
45  $cat_id = null;
46 }
47 
48 // Security check
49 if (!$user->hasRight('accounting', 'chartofaccount')) {
51 }
52 
53 $accountingcategory = new AccountancyCategory($db);
54 
55 
56 /*
57  * Actions
58  */
59 
60 // If we add account
61 if (!empty($selectcpt)) {
62  $cpts = array();
63  foreach ($selectcpt as $selectedoption) {
64  if (!array_key_exists($selectedoption, $cpts)) {
65  $cpts[$selectedoption] = "'".$selectedoption."'";
66  }
67  }
68 
69  $return = $accountingcategory->updateAccAcc($cat_id, $cpts);
70 
71  if ($return < 0) {
72  setEventMessages($langs->trans('errors'), $accountingcategory->errors, 'errors');
73  } else {
74  setEventMessages($langs->trans('RecordModifiedSuccessfully'), null, 'mesgs');
75  }
76 }
77 
78 if ($action == 'delete') {
79  if ($cpt_id) {
80  if ($accountingcategory->deleteCptCat($cpt_id)) {
81  setEventMessages($langs->trans('AccountRemovedFromGroup'), null, 'mesgs');
82  } else {
83  setEventMessages($langs->trans('errors'), null, 'errors');
84  }
85  }
86 }
87 
88 
89 /*
90  * View
91  */
92 
93 $form = new Form($db);
94 $formaccounting = new FormAccounting($db);
95 
96 llxheader('', $langs->trans('AccountingCategory'));
97 
98 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
99 $titlepicto = 'setup';
100 
101 print load_fiche_titre($langs->trans('AccountingCategory'), $linkback, $titlepicto);
102 
103 print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
104 print '<input type="hidden" name="token" value="'.newToken().'">';
105 print '<input type="hidden" name="action" value="display">';
106 
107 print dol_get_fiche_head();
108 
109 print '<table class="border centpercent">';
110 
111 // Select the category
112 print '<tr><td class="titlefield">'.$langs->trans("AccountingCategory").'</td>';
113 print '<td>';
114 $formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0, 0);
115 print '<input type="submit" class="button small" value="'.$langs->trans("Select").'">';
116 print '</td></tr>';
117 
118 print '</table>';
119 
120 print dol_get_fiche_end();
121 
122 
123 // Select the accounts
124 if (!empty($cat_id)) {
125  $return = $accountingcategory->getAccountsWithNoCategory($cat_id);
126  if ($return < 0) {
127  setEventMessages(null, $accountingcategory->errors, 'errors');
128  }
129  print '<br>';
130 
131  $arraykeyvalue = array();
132  foreach ($accountingcategory->lines_cptbk as $key => $val) {
133  $doc_ref = !empty($val->doc_ref) ? $val->doc_ref : '';
134  $arraykeyvalue[length_accountg($val->numero_compte)] = length_accountg($val->numero_compte) . ' - ' . $val->label_compte . ($doc_ref ? ' '.$doc_ref : '');
135  }
136 
137  if (is_array($accountingcategory->lines_cptbk) && count($accountingcategory->lines_cptbk) > 0) {
138  print img_picto($langs->trans("AccountingAccount"), 'accounting_account', 'class="pictofixedwith"');
139  print $form->multiselectarray('cpt_bk', $arraykeyvalue, GETPOST('cpt_bk', 'array'), null, null, '', 0, "80%", '', '', $langs->transnoentitiesnoconv("AddAccountFromBookKeepingWithNoCategories"));
140  //print '<br>';
141  /*print '<select class="flat minwidth200" size="8" name="cpt_bk[]" multiple>';
142  foreach ( $accountingcategory->lines_cptbk as $cpt ) {
143  print '<option value="' . length_accountg($cpt->numero_compte) . '">' . length_accountg($cpt->numero_compte) . ' (' . $cpt->label_compte . ' ' . $cpt->doc_ref . ')</option>';
144  }
145  print '</select><br>';
146  print ajax_combobox('cpt_bk');
147  */
148  print '<input type="submit" class="button button-add small" id="" class="action-delete" value="'.$langs->trans("Add").'"> ';
149  }
150 }
151 
152 print '</form>';
153 
154 
155 if ($action == 'display' || $action == 'delete') {
156  print '<br>';
157  print '<table class="noborder centpercent">'."\n";
158  print '<tr class="liste_titre">';
159  print '<td class="liste_titre">'.$langs->trans("AccountAccounting")."</td>";
160  print '<td class="liste_titre" colspan="2">'.$langs->trans("Label")."</td>";
161  print "</tr>\n";
162 
163  if (!empty($cat_id)) {
164  $return = $accountingcategory->display($cat_id); // This load ->lines_display
165  if ($return < 0) {
166  setEventMessages(null, $accountingcategory->errors, 'errors');
167  }
168 
169  if (is_array($accountingcategory->lines_display) && count($accountingcategory->lines_display) > 0) {
170  foreach ($accountingcategory->lines_display as $cpt) {
171  print '<tr class="oddeven">';
172  print '<td>'.length_accountg($cpt->account_number).'</td>';
173  print '<td>'.$cpt->label.'</td>';
174  print '<td class="right">';
175  print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&account_category='.$cat_id.'&cptid='.$cpt->rowid.'">';
176  print $langs->trans("DeleteFromCat");
177  print img_picto($langs->trans("DeleteFromCat"), 'unlink', 'class="paddingleft"');
178  print "</a>";
179  print "</td>";
180  print "</tr>\n";
181  }
182  } else {
183  print '<tr><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
184  }
185  }
186 
187  print "</table>";
188 }
189 
190 // End of page
191 llxFooter();
192 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5360
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:520
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:143
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:4024
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:1858
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11290
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2054
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8465
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1120