Revision a00ef54b
Von Moritz Bunkus vor fast 18 Jahren hinzugefügt
SL/AM.pm | ||
---|---|---|
45 | 45 |
|
46 | 46 |
my ($self, $myconfig, $form) = @_; |
47 | 47 |
|
48 |
$form->{id} = "NULL" unless ($form->{id}); |
|
49 |
|
|
50 | 48 |
# connect to database |
51 | 49 |
my $dbh = $form->dbconnect($myconfig); |
52 |
my $query = qq?SELECT c.accno, c.description, c.charttype, c.gifi_accno, |
|
53 |
c.category,c.link, tk.taxkey_id, tk.pos_ustva, tk.tax_id,tk.tax_id||'--'||tk.taxkey_id AS tax, tk.startdate, c.pos_bilanz, c.pos_eur, c.new_chart_id, c.valid_from, c.pos_bwa |
|
54 |
FROM chart c LEFT JOIN taxkeys tk |
|
55 |
ON (c.id=tk.chart_id AND tk.id = (SELECT id from taxkeys where taxkeys.chart_id =c.id AND startdate<=current_date ORDER BY startdate desc LIMIT 1)) |
|
56 |
WHERE c.id = $form->{id}?; |
|
57 |
|
|
50 |
my $query = |
|
51 |
qq!SELECT c.accno, c.description, c.charttype, c.gifi_accno, c.category,! . |
|
52 |
qq! c.link, c.pos_bilanz, c.pos_eur, c.new_chart_id, c.valid_from, ! . |
|
53 |
qq! c.pos_bwa, ! . |
|
54 |
qq! tk.taxkey_id, tk.pos_ustva, tk.tax_id, ! . |
|
55 |
qq! tk.tax_id || '--' || tk.taxkey_id AS tax, tk.startdate ! . |
|
56 |
qq!FROM chart c ! . |
|
57 |
qq!LEFT JOIN taxkeys tk ! . |
|
58 |
qq!ON (c.id=tk.chart_id AND tk.id = ! . |
|
59 |
qq! (SELECT id FROM taxkeys ! . |
|
60 |
qq! WHERE taxkeys.chart_id = c.id AND startdate <= current_date ! . |
|
61 |
qq! ORDER BY startdate DESC LIMIT 1)) ! . |
|
62 |
qq!WHERE c.id = ?!; |
|
58 | 63 |
|
59 | 64 |
my $sth = $dbh->prepare($query); |
60 |
$sth->execute || $form->dberror($query);
|
|
65 |
$sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})");
|
|
61 | 66 |
|
62 | 67 |
my $ref = $sth->fetchrow_hashref(NAME_lc); |
63 | 68 |
|
... | ... | |
93 | 98 |
|
94 | 99 |
$sth->finish; |
95 | 100 |
if ($form->{id}) { |
96 |
|
|
97 |
$where = " WHERE link='$form->{link}'"; |
|
98 |
|
|
99 |
|
|
100 | 101 |
# get new accounts |
101 | 102 |
$query = qq|SELECT id, accno,description |
102 |
FROM chart $where|;
|
|
103 |
FROM chart WHERE link = ?|;
|
|
103 | 104 |
$sth = $dbh->prepare($query); |
104 |
$sth->execute || $form->dberror($query);
|
|
105 |
$sth->execute($form->{link}) || $form->dberror($query . " ($form->{link})");
|
|
105 | 106 |
|
107 |
$form->{NEWACCOUNT} = []; |
|
106 | 108 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
107 | 109 |
push @{ $form->{NEWACCOUNT} }, $ref; |
108 | 110 |
} |
... | ... | |
111 | 113 |
} |
112 | 114 |
# check if we have any transactions |
113 | 115 |
$query = qq|SELECT a.trans_id FROM acc_trans a |
114 |
WHERE a.chart_id = $form->{id}|;
|
|
116 |
WHERE a.chart_id = ?|;
|
|
115 | 117 |
$sth = $dbh->prepare($query); |
116 |
$sth->execute || $form->dberror($query);
|
|
118 |
$sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})");
|
|
117 | 119 |
|
118 | 120 |
($form->{orphaned}) = $sth->fetchrow_array; |
119 | 121 |
$form->{orphaned} = !$form->{orphaned}; |
... | ... | |
123 | 125 |
$form->{new_chart_valid} = 0; |
124 | 126 |
if ($form->{new_chart_id}) { |
125 | 127 |
$query = qq|SELECT current_date-valid_from FROM chart |
126 |
WHERE id = $form->{id}|; |
|
127 |
$sth = $dbh->prepare($query); |
|
128 |
$sth->execute || $form->dberror($query); |
|
129 |
|
|
130 |
my ($count) = $sth->fetchrow_array; |
|
128 |
WHERE id = ?|; |
|
129 |
my ($count) = selectrow_query($form, $dbh, $query, $form->{id}); |
|
131 | 130 |
if ($count >=0) { |
132 | 131 |
$form->{new_chart_valid} = 1; |
133 | 132 |
} |
... | ... | |
167 | 166 |
} |
168 | 167 |
chop $form->{link}; |
169 | 168 |
|
170 |
# if we have an id then replace the old record |
|
171 |
$form->{description} =~ s/\'/\'\'/g; |
|
172 |
|
|
173 | 169 |
# strip blanks from accno |
174 | 170 |
map { $form->{$_} =~ s/ //g; } qw(accno); |
175 | 171 |
|
... | ... | |
179 | 175 |
$form->{id} = ""; |
180 | 176 |
} |
181 | 177 |
|
182 |
map({ $form->{$_} = "NULL" unless ($form->{$_}); }
|
|
183 |
qw(pos_ustva pos_bwa pos_bilanz pos_eur new_chart_id)); |
|
184 |
my($tax_id, $taxkey) = split /--/, $form->{tax};
|
|
185 |
$form->{valid_from} = ($form->{valid_from}) ? "'$form->{valid_from}'" : "NULL";
|
|
186 |
my $startdate = ($form->{startdate}) ? "'$form->{startdate}'" : "'1970-01-01'"; |
|
178 |
my @values;
|
|
179 |
|
|
180 |
my ($tax_id, $taxkey) = split(/--/, $form->{tax});
|
|
181 |
my $startdate = $form->{startdate} ? $form->{startdate} : "1970-01-01";
|
|
182 |
|
|
187 | 183 |
if ($form->{id} && $form->{orphaned}) { |
188 | 184 |
$query = qq|UPDATE chart SET |
189 |
accno = '$form->{accno}', |
|
190 |
description = '$form->{description}', |
|
191 |
charttype = '$form->{charttype}', |
|
192 |
gifi_accno = '$form->{gifi_accno}', |
|
193 |
category = '$form->{category}', |
|
194 |
link = '$form->{link}', |
|
195 |
taxkey_id = $taxkey, |
|
196 |
pos_ustva = $form->{pos_ustva}, |
|
197 |
pos_bwa = $form->{pos_bwa}, |
|
198 |
pos_bilanz = $form->{pos_bilanz}, |
|
199 |
pos_eur = $form->{pos_eur}, |
|
200 |
new_chart_id = $form->{new_chart_id}, |
|
201 |
valid_from = $form->{valid_from} |
|
202 |
WHERE id = $form->{id}|; |
|
185 |
accno = ?, description = ?, charttype = ?, |
|
186 |
gifi_accno = ?, category = ?, link = ?, |
|
187 |
taxkey_id = ?, |
|
188 |
pos_ustva = ?, pos_bwa = ?, pos_bilanz = ?, |
|
189 |
pos_eur = ?, new_chart_id = ?, valid_from = ? |
|
190 |
WHERE id = ?|; |
|
191 |
@values = ($form->{accno}, $form->{description}, $form->{charttype}, |
|
192 |
$form->{gifi_accno}, $form->{category}, $form->{link}, |
|
193 |
conv_i($taxkey), |
|
194 |
conv_i($form->{pos_ustva}), conv_i($form->{pos_bwa}), |
|
195 |
conv_i($form->{pos_bilanz}), conv_i($form->{pos_eur}), |
|
196 |
conv_i($form->{new_chart_id}), |
|
197 |
conv_date($form->{valid_from}), |
|
198 |
$form->{id}); |
|
199 |
|
|
203 | 200 |
} elsif ($form->{id} && !$form->{new_chart_valid}) { |
204 |
$query = qq|UPDATE chart SET
|
|
205 |
new_chart_id = $form->{new_chart_id},
|
|
206 |
valid_from = $form->{valid_from}
|
|
207 |
WHERE id = $form->{id}|;
|
|
201 |
$query = qq|UPDATE chart SET new_chart_id = ?, valid_from = ?
|
|
202 |
WHERE id = ?|;
|
|
203 |
@values = (conv_i($form->{new_chart_id}), conv_date($form->{valid_from}),
|
|
204 |
$form->{id});
|
|
208 | 205 |
} else { |
209 |
|
|
210 | 206 |
$query = qq|INSERT INTO chart |
211 |
(accno, description, charttype, gifi_accno, category, link, taxkey_id, pos_ustva, pos_bwa, pos_bilanz,pos_eur, new_chart_id, valid_from) |
|
212 |
VALUES ('$form->{accno}', '$form->{description}', |
|
213 |
'$form->{charttype}', '$form->{gifi_accno}', |
|
214 |
'$form->{category}', '$form->{link}', $taxkey, $form->{pos_ustva}, $form->{pos_bwa}, $form->{pos_bilanz}, $form->{pos_eur}, $form->{new_chart_id}, $form->{valid_from})|; |
|
207 |
(accno, description, charttype, |
|
208 |
gifi_accno, category, link, |
|
209 |
taxkey_id, |
|
210 |
pos_ustva, pos_bwa, pos_bilanz, pos_eur, |
|
211 |
new_chart_id, valid_from) |
|
212 |
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|; |
|
213 |
@values = ($form->{accno}, $form->{description}, $form->{charttype}, |
|
214 |
$form->{gifi_accno}, $form->{category}, $form->{link}, |
|
215 |
conv_i($taxkey), |
|
216 |
conv_i($form->{pos_ustva}), conv_i($form->{pos_bwa}), |
|
217 |
conv_i($form->{pos_bilanz}), conv_i($form->{pos_eur}), |
|
218 |
conv_i($form->{new_chart_id}), |
|
219 |
conv_date($form->{valid_from})); |
|
220 |
|
|
215 | 221 |
} |
216 |
$dbh->do($query) || $form->dberror($query);
|
|
222 |
do_query($form, $dbh, $query, @values);
|
|
217 | 223 |
|
218 | 224 |
#Save Taxes |
219 | 225 |
if (!$form->{id}) { |
220 |
$query = qq|INSERT INTO taxkeys (chart_id,tax_id,taxkey_id, pos_ustva, startdate) VALUES ((SELECT id FROM chart where accno='$form->{accno}'), $tax_id, $taxkey,$form->{pos_ustva}, $startdate)|; |
|
221 |
$dbh->do($query) || $form->dberror($query); |
|
226 |
$query = |
|
227 |
qq|INSERT INTO taxkeys | . |
|
228 |
qq|(chart_id, tax_id, taxkey_id, pos_ustva, startdate) | . |
|
229 |
qq|VALUES ((SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?)|; |
|
230 |
do_query($form, $dbh, $query, |
|
231 |
$form->{accno}, conv_i($tax_id), conv_i($taxkey), |
|
232 |
conv_i($form->{pos_ustva}), conv_date($startdate)); |
|
233 |
|
|
222 | 234 |
} else { |
223 |
$query = qq|DELETE FROM taxkeys WHERE chart_id=$form->{id} AND tax_id=$tax_id|; |
|
224 |
$dbh->do($query) || $form->dberror($query); |
|
225 |
$query = qq|INSERT INTO taxkeys (chart_id,tax_id,taxkey_id, pos_ustva, startdate) VALUES ($form->{id}, $tax_id, $taxkey,$form->{pos_ustva}, $startdate)|; |
|
226 |
$dbh->do($query) || $form->dberror($query); |
|
227 |
} |
|
235 |
$query = qq|DELETE FROM taxkeys WHERE chart_id = ? AND tax_id = ?|; |
|
236 |
do_query($form, $dbh, $query, $form->{id}, conv_i($tax_id)); |
|
228 | 237 |
|
229 |
# if ($form->{IC_taxpart} || $form->{IC_taxservice} || $form->{CT_tax}) { |
|
230 |
# |
|
231 |
# my $chart_id = $form->{id}; |
|
232 |
# |
|
233 |
# unless ($form->{id}) { |
|
234 |
# |
|
235 |
# # get id from chart |
|
236 |
# $query = qq|SELECT c.id |
|
237 |
# FROM chart c |
|
238 |
# WHERE c.accno = '$form->{accno}'|; |
|
239 |
# $sth = $dbh->prepare($query); |
|
240 |
# $sth->execute || $form->dberror($query); |
|
241 |
# |
|
242 |
# ($chart_id) = $sth->fetchrow_array; |
|
243 |
# $sth->finish; |
|
244 |
# } |
|
245 |
# |
|
246 |
# # add account if it doesn't exist in tax |
|
247 |
# $query = qq|SELECT t.chart_id |
|
248 |
# FROM tax t |
|
249 |
# WHERE t.chart_id = $chart_id|; |
|
250 |
# $sth = $dbh->prepare($query); |
|
251 |
# $sth->execute || $form->dberror($query); |
|
252 |
# |
|
253 |
# my ($tax_id) = $sth->fetchrow_array; |
|
254 |
# $sth->finish; |
|
255 |
# |
|
256 |
# # add tax if it doesn't exist |
|
257 |
# unless ($tax_id) { |
|
258 |
# $query = qq|INSERT INTO tax (chart_id, rate) |
|
259 |
# VALUES ($chart_id, 0)|; |
|
260 |
# $dbh->do($query) || $form->dberror($query); |
|
261 |
# } |
|
262 |
# } else { |
|
263 |
# |
|
264 |
# # remove tax |
|
265 |
# if ($form->{id}) { |
|
266 |
# $query = qq|DELETE FROM tax |
|
267 |
# WHERE chart_id = $form->{id}|; |
|
268 |
# $dbh->do($query) || $form->dberror($query); |
|
269 |
# } |
|
270 |
# } |
|
238 |
$query = |
|
239 |
qq|INSERT INTO taxkeys | . |
|
240 |
qq|(chart_id, tax_id, taxkey_id, pos_ustva, startdate) | . |
|
241 |
qq|VALUES (?, ?, ?, ?, ?)|; |
|
242 |
do_query($form, $dbh, $query, |
|
243 |
$form->{id}, conv_i($tax_id), conv_i($taxkey), |
|
244 |
conv_i($form->{pos_ustva}), conv_date($startdate)); |
|
245 |
} |
|
271 | 246 |
|
272 | 247 |
# commit |
273 | 248 |
my $rc = $dbh->commit; |
... | ... | |
287 | 262 |
my $dbh = $form->dbconnect_noauto($myconfig); |
288 | 263 |
|
289 | 264 |
my $query = qq|SELECT count(*) FROM acc_trans a |
290 |
WHERE a.chart_id = $form->{id}|; |
|
291 |
my $sth = $dbh->prepare($query); |
|
292 |
$sth->execute || $form->dberror($query); |
|
265 |
WHERE a.chart_id = ?|; |
|
266 |
my ($count) = selectrow_query($form, $dbh, $query, $form->{id}); |
|
293 | 267 |
|
294 |
if ($sth->fetchrow_array) { |
|
295 |
$sth->finish; |
|
268 |
if ($count) { |
|
296 | 269 |
$dbh->disconnect; |
297 | 270 |
$main::lxdebug->leave_sub(); |
298 | 271 |
return; |
299 | 272 |
} |
300 |
$sth->finish; |
|
301 |
|
|
302 |
# delete chart of account record |
|
303 |
$query = qq|DELETE FROM chart |
|
304 |
WHERE id = $form->{id}|; |
|
305 |
$dbh->do($query) || $form->dberror($query); |
|
306 | 273 |
|
307 | 274 |
# set inventory_accno_id, income_accno_id, expense_accno_id to defaults |
308 |
$query = qq|UPDATE parts |
|
309 |
SET inventory_accno_id = |
|
310 |
(SELECT inventory_accno_id FROM defaults) |
|
311 |
WHERE inventory_accno_id = $form->{id}|; |
|
312 |
$dbh->do($query) || $form->dberror($query); |
|
313 |
|
|
314 |
$query = qq|UPDATE parts |
|
315 |
SET income_accno_id = |
|
316 |
(SELECT income_accno_id FROM defaults) |
|
317 |
WHERE income_accno_id = $form->{id}|; |
|
318 |
$dbh->do($query) || $form->dberror($query); |
|
319 |
|
|
320 |
$query = qq|UPDATE parts |
|
321 |
SET expense_accno_id = |
|
322 |
(SELECT expense_accno_id FROM defaults) |
|
323 |
WHERE expense_accno_id = $form->{id}|; |
|
324 |
$dbh->do($query) || $form->dberror($query); |
|
275 |
foreach my $type (qw(inventory income expense)) { |
|
276 |
$query = |
|
277 |
qq|UPDATE parts | . |
|
278 |
qq|SET ${type}_accno_id = (SELECT ${type}_accno_id FROM defaults) | . |
|
279 |
qq|WHERE ${type}_accno_id = ?|; |
|
280 |
do_query($form, $dbh, $query, $form->{id}); |
|
281 |
} |
|
325 | 282 |
|
326 | 283 |
foreach my $table (qw(partstax customertax vendortax tax)) { |
327 | 284 |
$query = qq|DELETE FROM $table |
328 |
WHERE chart_id = $form->{id}|;
|
|
329 |
$dbh->do($query) || $form->dberror($query);
|
|
285 |
WHERE chart_id = ?|;
|
|
286 |
do_query($form, $dbh, $query, $form->{id});
|
|
330 | 287 |
} |
331 | 288 |
|
289 |
# delete chart of account record |
|
290 |
$query = qq|DELETE FROM chart |
|
291 |
WHERE id = ?|; |
|
292 |
do_query($form, $dbh, $query, $form->{id}); |
|
293 |
|
|
332 | 294 |
# commit and redirect |
333 | 295 |
my $rc = $dbh->commit; |
334 | 296 |
$dbh->disconnect; |
... | ... | |
348 | 310 |
|
349 | 311 |
my $query = qq|SELECT accno, description |
350 | 312 |
FROM gifi |
351 |
ORDER BY accno|;
|
|
313 |
ORDER BY accno|;
|
|
352 | 314 |
|
353 | 315 |
$sth = $dbh->prepare($query); |
354 | 316 |
$sth->execute || $form->dberror($query); |
Auch abrufbar als: Unified diff
Verhinderung von SQL injection durch Verwndung von parametrisierten Abfragen.