dolibarr  7.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 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 $langs->load("bills");
33 $langs->load("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');
41 $selectcpt = GETPOST('cpt_bk', 'array');
42 $cpt_id = GETPOST('cptid');
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 // si ajout de comptes
57 if (! empty($selectcpt)) {
58  $cpts = array ();
59  foreach ( $selectcpt as $selectedoption ) {
60  if (! array_key_exists($selectedoption, $cpts))
61  $cpts[$selectedoption] = "'" . $selectedoption . "'";
62  }
63 
64  $return= $accountingcategory->updateAccAcc($cat_id, $cpts);
65 
66  if ($return<0) {
67  setEventMessages($langs->trans('errors'), $accountingcategory->errors, 'errors');
68  } else {
69  setEventMessages($langs->trans('Saved'), null, 'mesgs');
70  }
71 }
72 if ($action == 'delete') {
73  if ($cpt_id) {
74  if ($accountingcategory->deleteCptCat($cpt_id)) {
75  setEventMessages($langs->trans('CategoryDeleted'), null, 'mesgs');
76  } else {
77  setEventMessages($langs->trans('errors'), null, 'errors');
78  }
79  }
80 }
81 
82 
83 /*
84  * View
85  */
86 $form = new Form($db);
87 $formaccounting = new FormAccounting($db);
88 
89 llxheader('', $langs->trans('AccountingCategory'));
90 
91 $linkback = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories_list.php?search_country_id='.$mysoc->country_id.'">'.$langs->trans("BackToList").'</a>';
92 
93 print load_fiche_titre($langs->trans('AccountingCategory'), $linkback);
94 
95 print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
96 print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
97 print '<input type="hidden" name="action" value="display">';
98 
100 
101 print '<table class="border" width="100%">';
102 // Category
103 print '<tr><td class="titlefield">' . $langs->trans("AccountingCategory") . '</td>';
104 print '<td>';
105 $formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0, 1);
106 print '<input class="button" type="submit" value="' . $langs->trans("Select") . '">';
107 print '</td></tr>';
108 
109 if (! empty($cat_id))
110 {
111  $return = $accountingcategory->getAccountsWithNoCategory($cat_id);
112  if ($return < 0) {
113  setEventMessages(null, $accountingcategory->errors, 'errors');
114  }
115  print '<tr><td>' . $langs->trans("AddAccountFromBookKeepingWithNoCategories") . '</td>';
116  print '<td>';
117 
118  $arraykeyvalue=array();
119  foreach($accountingcategory->lines_cptbk as $key => $val)
120  {
121  $arraykeyvalue[length_accountg($val->numero_compte)] = length_accountg($val->numero_compte) . ' (' . $val->label_compte . ($val->doc_ref?' '.$val->doc_ref:'').')';
122  }
123 
124  if (is_array($accountingcategory->lines_cptbk) && count($accountingcategory->lines_cptbk) > 0) {
125 
126  print $form->multiselectarray('cpt_bk', $arraykeyvalue, GETPOST('cpt_bk', 'array'), null, null, null, null, "90%");
127  print '<br>';
128  /*print '<select class="flat minwidth200" size="8" name="cpt_bk[]" multiple>';
129  foreach ( $accountingcategory->lines_cptbk as $cpt ) {
130  print '<option value="' . length_accountg($cpt->numero_compte) . '">' . length_accountg($cpt->numero_compte) . ' (' . $cpt->label_compte . ' ' . $cpt->doc_ref . ')</option>';
131  }
132  print '</select><br>';
133  print ajax_combobox('cpt_bk');
134  */
135  print '<input class="button" type="submit" id="" class="action-delete" value="' . $langs->trans("Add") . '"> ';
136  }
137  print '</td></tr>';
138 }
139 
140 print '</table>';
141 
142 dol_fiche_end();
143 
144 print '</form>';
145 
146 
147 if ($action == 'display' || $action == 'delete') {
148 
149  print "<table class='noborder' width='100%'>\n";
150  print '<tr class="liste_titre">';
151  print '<td class="liste_titre">'.$langs->trans("AccountAccounting")."</td>";
152  print '<td class="liste_titre" colspan="2">'.$langs->trans("Label")."</td>";
153  print "</tr>\n";
154 
155  if (! empty($cat_id)) {
156  $return = $accountingcategory->display($cat_id);
157  if ($return < 0) {
158  setEventMessages(null, $accountingcategory->errors, 'errors');
159  }
160 
161  if (is_array($accountingcategory->lines_display) && count($accountingcategory->lines_display) > 0) {
162  foreach ( $accountingcategory->lines_display as $cpt ) {
163  print '<tr class="oddeven">';
164  print '<td>' . length_accountg($cpt->account_number) . '</td>';
165  print '<td>' . $cpt->label . '</td>';
166  print '<td align="right">';
167  print "<a href= '".$_SERVER['PHP_SELF']."?action=delete&account_category=" . $cat_id . "&cptid=" . $cpt->rowid."'>";
168  print img_delete($langs->trans("DeleteFromCat")).' ';
169  print $langs->trans("DeleteFromCat")."</a>";
170  print "</td>";
171  print "</tr>\n";
172  }
173  }
174  }
175 
176  print "</table>";
177 }
178 
179 llxFooter();
180 
181 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
if(empty($reshook)) $form
View.
Definition: perms.php:103
Class to manage categories of an accounting account.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
print
Draft customers invoices.
Definition: index.php:91
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) ...