/
categories.php
168 lines (136 loc) · 5.07 KB
/
categories.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/* Copyright (C) 2016 Jamal Elbaz <jamelbaz@gmail.pro>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/accountancy/admin/categories.php
* \ingroup Advanced accountancy
* \brief Page to assign mass categories to accounts
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancycategory.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
$error = 0;
// Langs
$langs->load("bills");
$langs->load("accountancy");
$mesg = '';
$action = GETPOST('action');
$cat_id = GETPOST('account_category');
$selectcpt = GETPOST('cpt_bk', 'array');
$cpt_id = GETPOST('cptid');
if ($cat_id == 0) {
$cat_id = null;
}
$id = GETPOST('id', 'int');
$rowid = GETPOST('rowid', 'int');
$cancel = GETPOST('cancel');
// Security check
if (! empty($user->rights->accountancy->chartofaccount))
{
accessforbidden();
}
$AccCat = new AccountancyCategory($db);
// si ajout de comptes
if (! empty($selectcpt)) {
$cpts = array ();
foreach ( $selectcpt as $selectedOption ) {
if (! array_key_exists($selectedOption, $cpts))
$cpts[$selectedOption] = "'" . $selectedOption . "'";
}
$return= $AccCat->updateAccAcc($cat_id, $cpts);
if ($return<0) {
setEventMessages($langs->trans('errors'), $AccCat->errors, 'errors');
} else {
setEventMessages($langs->trans('Saved'), null, 'mesgs');
}
}
if ($action == 'delete') {
if ($cpt_id) {
if ($AccCat->deleteCptCat($cpt_id)) {
setEventMessages($langs->trans('Deleted'), null, 'mesgs');
} else {
setEventMessages($langs->trans('errors'), null, 'errors');
}
}
}
/*
* View
*/
llxheader('', $langs->trans('AccountAccounting'));
$formaccounting = new FormAccounting($db);
$form = new Form($db);
print load_fiche_titre($langs->trans('AccountingCategory'));
print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="display">';
dol_fiche_head();
print '<table class="border" width="100%">';
// Category
print '<tr><td>' . $langs->trans("AccountingCategory") . '</td>';
print '<td>';
$formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0, 1);
print '<input class="button" type="submit" value="' . $langs->trans("Select") . '">';
print '</td></tr>';
if (! empty($cat_id))
{
$return = $AccCat->getAccountsWithNoCategory($cat_id);
if ($return < 0) {
setEventMessages(null, $AccCat->errors, 'errors');
}
print '<tr><td>' . $langs->trans("AddCompteFromBK") . '</td>';
print '<td>';
if (is_array($AccCat->lines_cptbk) && count($AccCat->lines_cptbk) > 0) {
print '<select class="flat minwidth200" size="' . count($obj) . '" name="cpt_bk[]" multiple>';
foreach ( $AccCat->lines_cptbk as $cpt ) {
print '<option value="' . length_accountg($cpt->numero_compte) . '">' . length_accountg($cpt->numero_compte) . ' (' . $cpt->label_compte . ' ' . $cpt->doc_ref . ')</option>';
}
print '</select><br><input class="button" type="submit" id="" class="action-delete" value="' . $langs->trans("Add") . '"> ';
}
print '</td></tr>';
}
print '</table>';
dol_fiche_end();
print '</form>';
if ($action == 'display' || $action == 'delete') {
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><th class="liste_titre">' . $langs->trans("AccountAccounting") . '</th><th class="liste_titre">' . $langs->trans("Description") . '</th><th class="liste_titre" width="60" align="center">Action</th></tr>';
if (! empty($cat_id)) {
$return = $AccCat->display($cat_id);
if ($return < 0) {
setEventMessages(null, $AccCat->errors, 'errors');
}
$j = 1;
if (is_array($AccCat->lines_display) && count($AccCat->lines_display) > 0) {
foreach ( $AccCat->lines_display as $cpt ) {
$var = ! $var;
print '<tr ' . $bc[$var] . '>';
print '<td>' . length_accountg($cpt->account_number) . '</td>';
print '<td>' . $cpt->label . '</td>';
print $form->formconfirm($_SERVER["PHP_SELF"] . "?account_category=$cat_id&cptid=" . $cpt->rowid, $langs->trans("DeleteCptCategory"), $langs->trans("ConfirmDeleteCptCategory"), "delete", '', 0, "action-delete" . $j);
print '<td>';
//print img_delete();
print '<input class="button" type="button" id="action-delete' . $j . '" value="' . $langs->trans("Delete") . '">';
print '</td>';
print "</tr>\n";
$j ++;
}
}
}
print "</table>";
}
llxFooter();
$db->close();