1 | <?php |
||
2 | /* Copyright (C) 2013-2014 Olivier Geffroy <[email protected]> |
||
3 | * Copyright (C) 2013-2017 Alexandre Spangaro <[email protected]> |
||
4 | * Copyright (C) 2014 Florian Henry <[email protected]> |
||
5 | * Copyright (C) 2018 Frédéric France <[email protected]> |
||
6 | * |
||
7 | * This program is free software; you can redistribute it and/or modify |
||
8 | * it under the terms of the GNU General Public License as published by |
||
9 | * the Free Software Foundation; either version 3 of the License, or |
||
10 | * (at your option) any later version. |
||
11 | * |
||
12 | * This program is distributed in the hope that it will be useful, |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | * GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License |
||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
19 | */ |
||
20 | |||
21 | /** |
||
22 | * \file htdocs/accountancy/admin/importaccounts.php |
||
23 | * \ingroup Advanced accountancy |
||
24 | * \brief Page import accounting account |
||
25 | */ |
||
26 | |||
27 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
||
28 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
||
29 | require DOL_BASE_PATH . '/main.inc.php'; |
||
30 | require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; |
||
31 | require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php'; |
||
32 | require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; |
||
33 | |||
34 | // Load translation files required by the page |
||
35 | $langs->loadLangs(array("compta","bills","accountancy")); |
||
36 | |||
37 | // Security check |
||
38 | if (! $user->admin) |
||
39 | accessforbidden(); |
||
40 | |||
41 | $limit = GETPOST('limit','int')?GETPOST('limit','int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); |
||
42 | $sortfield = GETPOST("sortfield",'alpha'); |
||
43 | $sortorder = GETPOST("sortorder",'alpha'); |
||
44 | $page = GETPOST("page",'int'); |
||
45 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 |
||
46 | $offset = $limit * $page; |
||
47 | $pageprev = $page - 1; |
||
48 | $pagenext = $page + 1; |
||
49 | |||
50 | |||
51 | |||
52 | |||
53 | /* |
||
54 | * View |
||
55 | */ |
||
56 | |||
57 | llxHeader('', $langs->trans("ImportAccount")); |
||
58 | |||
59 | $to_import = GETPOST("mesCasesCochees"); |
||
60 | |||
61 | if ($_POST["action"] == 'import') { |
||
62 | print '<div><font color="red">' . $langs->trans("Processing") . '...</font></div>'; |
||
63 | if (is_array($to_import) && count($to_import) > 0) { |
||
64 | print '<div><font color="red">' . count($to_import) . ' ' . $langs->trans("SelectedLines") . '</font></div>'; |
||
65 | $sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS; |
||
66 | |||
67 | $result = $db->query($sql); |
||
68 | if ($result && ($db->num_rows($result) > 0)) { |
||
69 | |||
70 | $obj = $db->fetch_object($result); |
||
71 | |||
72 | $cpt = 0; |
||
73 | foreach ( $to_import as $maLigneCochee ) { |
||
74 | |||
75 | $accounting = new AccountingAccount($db); |
||
76 | |||
77 | $monLabel = (string) GETPOST('label' . $maLigneCochee); |
||
78 | $monParentAccount = (string) GETPOST('AccountParent' . $maLigneCochee); |
||
79 | $monType = (string) GETPOST('pcgType' . $maLigneCochee); |
||
80 | $monSubType = (string) GETPOST('pcgSubType' . $maLigneCochee); |
||
81 | |||
82 | $accounting->fk_pcg_version = $obj->pcg_version; |
||
83 | $accounting->account_number = $maLigneCochee; |
||
84 | $accounting->label = $monLabel; |
||
85 | $accounting->account_parent = $monParentAccount; |
||
0 ignored issues
–
show
|
|||
86 | $accounting->pcg_type = $monType; |
||
87 | $accounting->pcg_subtype = $monSubType; |
||
88 | $accounting->active = 1; |
||
89 | |||
90 | $result = $accounting->create($user); |
||
91 | if ($result > 0) { |
||
92 | setEventMessages($langs->trans("AccountingAccountAdd"), null, 'mesgs'); |
||
93 | } else { |
||
94 | setEventMessages($accounting->error, $accounting->errors, 'errors'); |
||
95 | } |
||
96 | $cpt ++; |
||
97 | } |
||
98 | } else { |
||
99 | setEventMessages($langs->trans('AccountPlanNotFoundCheckSetting'), null, 'errors'); |
||
100 | } |
||
101 | } else { |
||
102 | print '<div><font color="red">' . $langs->trans("AnyLineImport") . '</font></div>'; |
||
103 | } |
||
104 | print '<div><font color="red">' . $langs->trans("EndProcessing") . '</font></div>'; |
||
105 | } |
||
106 | |||
107 | // list accounting account from product |
||
108 | |||
109 | $sql = "(SELECT p.rowid as product_id, p.accountancy_code_sell as accounting "; |
||
110 | $sql .= " FROM " . MAIN_DB_PREFIX . "product as p "; |
||
111 | $sql .= " WHERE p.accountancy_code_sell >=0"; |
||
112 | $sql .= " GROUP BY accounting "; |
||
113 | $sql .= ")"; |
||
114 | $sql .= "UNION ALL(SELECT p.rowid as product_id, p.accountancy_code_buy as accounting "; |
||
115 | $sql .= " FROM " . MAIN_DB_PREFIX . "product as p "; |
||
116 | $sql .= " WHERE p.accountancy_code_buy >=0"; |
||
117 | $sql .= " GROUP BY accounting "; |
||
118 | $sql .= ") "; |
||
119 | $sql .= " ORDER BY accounting DESC " . $db->plimit($limit + 1, $offset); |
||
120 | |||
121 | dol_syslog('accountancy/admin/importaccounts.php:: $sql=' . $sql); |
||
122 | $result = $db->query($sql); |
||
123 | if ($result) { |
||
124 | $num_lines = $db->num_rows($result); |
||
125 | $i = 0; |
||
126 | print_barre_liste($langs->trans("ImportAccount"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num_lines); |
||
127 | |||
128 | print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n"; |
||
129 | print '<input type="hidden" name="action" value="import">'; |
||
130 | |||
131 | print '<table class="noborder" width="100%">'; |
||
132 | print '<tr class="liste_titre"><td>' . $langs->trans("AccountAccouting") . '</td>'; |
||
133 | print '<td>' . $langs->trans("label") . '</td>'; |
||
134 | print '<td>' . $langs->trans("Accountparent") . '</td>'; |
||
135 | print '<td>' . $langs->trans("Pcgtype") . '</td>'; |
||
136 | print '<td>' . $langs->trans("Pcgsubtype") . '</td>'; |
||
137 | print '<td align="center">' . $langs->trans("Import") . '</td>'; |
||
138 | print '</tr>'; |
||
139 | |||
140 | $form = new Form($db); |
||
141 | $formaccounting = new FormAccounting($db); |
||
142 | |||
143 | while ( $i < min($num_lines, $limit) ) { |
||
144 | $objp = $db->fetch_object($result); |
||
145 | print '<tr class="oddeven">'; |
||
146 | |||
147 | print '<td align="left">'; |
||
148 | print $objp->accounting; |
||
149 | print '</td>'; |
||
150 | |||
151 | print '<td align="left">'; |
||
152 | print '<input name="label" size="30" value="">'; |
||
153 | print '</td>'; |
||
154 | |||
155 | // Colonne choix du compte |
||
156 | print '<td>'; |
||
157 | print $formaccounting->select_account($accounting->account_parent, 'AccountParent'); |
||
158 | print '</td>'; |
||
159 | |||
160 | print '<td>'; |
||
161 | print '<input type="text" name="pcgType" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$accounting->pcg_type).'">'; |
||
162 | print '</td>'; |
||
163 | |||
164 | print '<td>'; |
||
165 | print '<input type="text" name="pcgSubType" value="'.dol_escape_htmltag(isset($_POST['pcg_subtype'])?GETPOST('pcg_subtype','alpha'):$accounting->pcg_subtype).'">'; |
||
166 | print '</td>'; |
||
167 | |||
168 | // Colonne choix ligne a ventiler |
||
169 | $checked = ('label' == 'O') ? ' checked' : ''; |
||
170 | |||
171 | print '<td align="center">'; |
||
172 | print '<input type="checkbox" name="mesCasesCochees[]" ' . $checked . ' value="' . $objp->accounting . '"/>'; |
||
173 | print '</td>'; |
||
174 | |||
175 | print '</tr>'; |
||
176 | $i ++; |
||
177 | } |
||
178 | |||
179 | print '<tr><td colspan="8"> </td></tr><tr><td colspan="8" align="center"><input type="submit" class="butAction" value="' . $langs->trans("Import") . '"></td></tr>'; |
||
180 | |||
181 | print '</table>'; |
||
182 | print '</form>'; |
||
183 | } else { |
||
184 | print $db->error(); |
||
185 | } |
||
186 | |||
187 | // End of page |
||
188 | llxFooter(); |
||
189 | $db->close(); |
||
190 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.