dolibarr  9.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 Alexandre Spangaro <aspangaro@zendsi.com>
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 <http://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 $mesg = '';
36 $id = GETPOST('id', 'int');
37 $rowid = GETPOST('rowid', '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 (empty($user->rights->accounting->chartofaccount))
50 {
52 }
53 
54 $accountingcategory = new AccountancyCategory($db);
55 
56 
57 /*
58  * Actions
59  */
60 
61 // si ajout de comptes
62 if (! empty($selectcpt)) {
63  $cpts = array ();
64  foreach ( $selectcpt as $selectedoption ) {
65  if (! array_key_exists($selectedoption, $cpts))
66  $cpts[$selectedoption] = "'" . $selectedoption . "'";
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('SetupSaved'), null, 'mesgs');
75  }
76 }
77 if ($action == 'delete') {
78  if ($cpt_id) {
79  if ($accountingcategory->deleteCptCat($cpt_id)) {
80  setEventMessages($langs->trans('CategoryDeleted'), null, 'mesgs');
81  } else {
82  setEventMessages($langs->trans('errors'), null, 'errors');
83  }
84  }
85 }
86 
87 
88 /*
89  * View
90  */
91 
92 $form = new Form($db);
93 $formaccounting = new FormAccounting($db);
94 
95 llxheader('', $langs->trans('AccountingCategory'));
96 
97 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
98 
99 print load_fiche_titre($langs->trans('AccountingCategory'), $linkback);
100 
101 print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
102 print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
103 print '<input type="hidden" name="action" value="display">';
104 
106 
107 print '<table class="border" width="100%">';
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 class="button" type="submit" value="' . $langs->trans("Select") . '">';
114 print '</td></tr>';
115 
116 // Select the accounts
117 if (! empty($cat_id))
118 {
119  $return = $accountingcategory->getAccountsWithNoCategory($cat_id);
120  if ($return < 0) {
121  setEventMessages(null, $accountingcategory->errors, 'errors');
122  }
123  print '<tr><td>' . $langs->trans("AddAccountFromBookKeepingWithNoCategories") . '</td>';
124  print '<td>';
125 
126  $arraykeyvalue=array();
127  foreach($accountingcategory->lines_cptbk as $key => $val)
128  {
129  $arraykeyvalue[length_accountg($val->numero_compte)] = length_accountg($val->numero_compte) . ' (' . $val->label_compte . ($val->doc_ref?' '.$val->doc_ref:'').')';
130  }
131 
132  if (is_array($accountingcategory->lines_cptbk) && count($accountingcategory->lines_cptbk) > 0) {
133 
134  print $form->multiselectarray('cpt_bk', $arraykeyvalue, GETPOST('cpt_bk', 'array'), null, null, null, null, "90%");
135  print '<br>';
136  /*print '<select class="flat minwidth200" size="8" name="cpt_bk[]" multiple>';
137  foreach ( $accountingcategory->lines_cptbk as $cpt ) {
138  print '<option value="' . length_accountg($cpt->numero_compte) . '">' . length_accountg($cpt->numero_compte) . ' (' . $cpt->label_compte . ' ' . $cpt->doc_ref . ')</option>';
139  }
140  print '</select><br>';
141  print ajax_combobox('cpt_bk');
142  */
143  print '<input class="button" type="submit" id="" class="action-delete" value="' . $langs->trans("Add") . '"> ';
144  }
145  print '</td></tr>';
146 }
147 
148 print '</table>';
149 
150 dol_fiche_end();
151 
152 print '</form>';
153 
154 
155 if ($action == 'display' || $action == 'delete') {
156 
157  print "<table class='noborder' width='100%'>\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 align="right">';
175  print "<a href= '".$_SERVER['PHP_SELF']."?action=delete&account_category=" . $cat_id . "&cptid=" . $cpt->rowid."'>";
176  print img_delete($langs->trans("DeleteFromCat")).' ';
177  print $langs->trans("DeleteFromCat")."</a>";
178  print "</td>";
179  print "</tr>\n";
180  }
181  }
182  }
183 
184  print "</table>";
185 }
186 
187 // End of page
188 llxFooter();
189 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage categories of an accounting account.
img_delete($titlealt='default', $other='class="pictodelete"')
Show delete logo.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage generation of HTML components for accounting management.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.