Revision 357d134d
Von Niclas Zimmermann vor etwa 12 Jahren hinzugefügt
SL/AP.pm | ||
---|---|---|
209 | 209 |
# insert detail records in acc_trans |
210 | 210 |
$query = |
211 | 211 |
qq|INSERT INTO acc_trans | . |
212 |
qq| (trans_id, chart_id, amount, transdate, project_id, taxkey)| . |
|
212 |
qq| (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)| .
|
|
213 | 213 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . |
214 |
qq| ?, ?, ?, ?)|; |
|
214 |
qq| ?, ?, ?, ?, (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
|
|
215 | 215 |
@values = ($form->{id}, $form->{AP_amounts}{"amount_$i"}, |
216 | 216 |
$form->{"amount_$i"}, conv_date($form->{transdate}), |
217 |
$project_id, $form->{"taxkey_$i"}); |
|
217 |
$project_id, $form->{"taxkey_$i"}, $form->{AP_amounts}{"amount_$i"}, conv_date($form->{transdate}));
|
|
218 | 218 |
do_query($form, $dbh, $query, @values); |
219 | 219 |
|
220 | 220 |
if ($form->{"tax_$i"} != 0) { |
221 | 221 |
# insert detail records in acc_trans |
222 | 222 |
$query = |
223 | 223 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, | . |
224 |
qq| project_id, taxkey) | . |
|
224 |
qq| project_id, taxkey, tax_id) | .
|
|
225 | 225 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . |
226 |
qq| ?, ?, ?, ?)|; |
|
226 |
qq| ?, ?, ?, ?, (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
|
|
227 | 227 |
@values = ($form->{id}, $form->{AP_amounts}{"tax_$i"}, |
228 | 228 |
$form->{"tax_$i"}, conv_date($form->{transdate}), |
229 |
$project_id, $form->{"taxkey_$i"}); |
|
229 |
$project_id, $form->{"taxkey_$i"}, $form->{AP_amounts}{"tax_$i"}, conv_date($form->{transdate}));
|
|
230 | 230 |
do_query($form, $dbh, $query, @values); |
231 | 231 |
} |
232 | 232 |
|
... | ... | |
235 | 235 |
|
236 | 236 |
# add payables |
237 | 237 |
$query = |
238 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) | . |
|
238 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) | .
|
|
239 | 239 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, | . |
240 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
240 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?),| . |
|
241 |
qq| (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
241 | 242 |
@values = ($form->{id}, $form->{AP_amounts}{payables}, $form->{payables}, |
242 |
conv_date($form->{transdate}), $form->{AP_amounts}{payables}); |
|
243 |
conv_date($form->{transdate}), $form->{AP_amounts}{payables}, $form->{AP_amounts}{payables}, conv_date($form->{transdate}));
|
|
243 | 244 |
do_query($form, $dbh, $query, @values); |
244 | 245 |
} |
245 | 246 |
|
... | ... | |
283 | 284 |
2); |
284 | 285 |
if ($form->{payables}) { |
285 | 286 |
$query = |
286 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) | . |
|
287 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id) | .
|
|
287 | 288 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, | . |
288 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
289 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?),| . |
|
290 |
qq| (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
289 | 291 |
@values = ($form->{id}, $form->{AP_payables}, $amount, |
290 | 292 |
conv_date($form->{"datepaid_$i"}), $project_id, |
291 |
$form->{AP_payables}); |
|
293 |
$form->{AP_payables}, $form->{AP_payables}, conv_date($form->{"datepaid_$i"}));
|
|
292 | 294 |
do_query($form, $dbh, $query, @values); |
293 | 295 |
} |
294 | 296 |
$form->{payables} = $amount; |
... | ... | |
296 | 298 |
# add payment |
297 | 299 |
my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); |
298 | 300 |
$query = |
299 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey) | . |
|
301 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id) | .
|
|
300 | 302 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, | . |
301 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
303 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?), | . |
|
304 |
qq| (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
302 | 305 |
@values = ($form->{id}, $form->{"AP_paid_account_$i"}, $form->{"paid_$i"}, |
303 | 306 |
conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, |
304 |
$form->{"memo_$i"}, $project_id, $form->{"AP_paid_account_$i"}); |
|
307 |
$form->{"memo_$i"}, $project_id, $form->{"AP_paid_account_$i"}, |
|
308 |
$form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"})); |
|
305 | 309 |
do_query($form, $dbh, $query, @values); |
306 | 310 |
|
307 | 311 |
# add exchange rate difference |
... | ... | |
310 | 314 |
($form->{"exchangerate_$i"} - 1), 2); |
311 | 315 |
if ($amount != 0) { |
312 | 316 |
$query = |
313 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) | . |
|
317 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) | .
|
|
314 | 318 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | . |
315 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
319 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?), | . |
|
320 |
qq| (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
316 | 321 |
@values = ($form->{id}, $form->{"AP_paid_account_$i"}, $amount, |
317 | 322 |
conv_date($form->{"datepaid_$i"}), $project_id, |
318 |
$form->{"AP_paid_account_$i"}); |
|
323 |
$form->{"AP_paid_account_$i"}, |
|
324 |
$form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"})); |
|
319 | 325 |
do_query($form, $dbh, $query, @values); |
320 | 326 |
} |
321 | 327 |
|
... | ... | |
327 | 333 |
|
328 | 334 |
if ($amount != 0) { |
329 | 335 |
$query = |
330 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) | . |
|
336 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) | .
|
|
331 | 337 |
qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | . |
332 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
338 |
qq| (SELECT taxkey_id FROM chart WHERE accno = ?)| . |
|
339 |
qq| (SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
333 | 340 |
@values = ($form->{id}, ($amount > 0) ? |
334 | 341 |
$form->{fxgain_accno} : $form->{fxloss_accno}, |
335 | 342 |
$amount, conv_date($form->{"datepaid_$i"}), $project_id, |
336 | 343 |
($amount > 0) ? |
337 |
$form->{fxgain_accno} : $form->{fxloss_accno}); |
|
344 |
$form->{fxgain_accno} : $form->{fxloss_accno}, |
|
345 |
($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}, conv_date($form->{"datepaid_$i"})); |
|
338 | 346 |
do_query($form, $dbh, $query, @values); |
339 | 347 |
} |
340 | 348 |
|
SL/AR.pm | ||
---|---|---|
172 | 172 |
my $project_id = conv_i($form->{"project_id_$i"}); |
173 | 173 |
|
174 | 174 |
# insert detail records in acc_trans |
175 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) |
|
176 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; |
|
175 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)
|
|
176 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|;
|
|
177 | 177 |
@values = (conv_i($form->{id}), $form->{AR_amounts}{"amount_$i"}, conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), $project_id, |
178 |
conv_i($form->{"taxkey_$i"})); |
|
178 |
conv_i($form->{"taxkey_$i"}), conv_i($form->{"tax_id_$i"}));
|
|
179 | 179 |
do_query($form, $dbh, $query, @values); |
180 | 180 |
|
181 | 181 |
if ($form->{"tax_$i"} != 0) { |
182 | 182 |
# insert detail records in acc_trans |
183 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) |
|
184 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; |
|
183 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)
|
|
184 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|;
|
|
185 | 185 |
@values = (conv_i($form->{id}), $form->{AR_amounts}{"tax_$i"}, conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), $project_id, |
186 |
conv_i($form->{"taxkey_$i"})); |
|
186 |
conv_i($form->{"taxkey_$i"}), conv_i($form->{"tax_id_$i"}));
|
|
187 | 187 |
do_query($form, $dbh, $query, @values); |
188 | 188 |
} |
189 | 189 |
} |
190 | 190 |
} |
191 | 191 |
|
192 | 192 |
# add recievables |
193 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) |
|
194 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
195 |
@values = (conv_i($form->{id}), $form->{AR_amounts}{receivables}, conv_i($form->{receivables}), conv_date($form->{transdate}), $form->{AR_amounts}{receivables}); |
|
193 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) |
|
194 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), |
|
195 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
196 |
@values = (conv_i($form->{id}), $form->{AR_amounts}{receivables}, conv_i($form->{receivables}), conv_date($form->{transdate}), |
|
197 |
$form->{AR_amounts}{receivables}, $form->{AR_amounts}{receivables}, conv_date($form->{transdate})); |
|
196 | 198 |
do_query($form, $dbh, $query, @values); |
197 | 199 |
|
198 | 200 |
} else { |
... | ... | |
229 | 231 |
|
230 | 232 |
if ($amount != 0) { |
231 | 233 |
# add receivable |
232 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) |
|
233 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
234 |
@values = (conv_i($form->{id}), $form->{AR}{receivables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{receivables}); |
|
234 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id) |
|
235 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), |
|
236 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
237 |
@values = (conv_i($form->{id}), $form->{AR}{receivables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{receivables}, $form->{AR}{receivables}, conv_date($form->{"datepaid_$i"})); |
|
235 | 238 |
do_query($form, $dbh, $query, @values); |
236 | 239 |
} |
237 | 240 |
|
... | ... | |
240 | 243 |
my $project_id = conv_i($form->{"paid_project_id_$i"}); |
241 | 244 |
my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); |
242 | 245 |
$amount = $form->{"paid_$i"} * -1; |
243 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey) |
|
244 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
245 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"}); |
|
246 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id) |
|
247 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), |
|
248 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
249 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"}, |
|
250 |
$form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"})); |
|
246 | 251 |
do_query($form, $dbh, $query, @values); |
247 | 252 |
|
248 | 253 |
# exchangerate difference for payment |
249 | 254 |
$amount = $form->round_amount( $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) * -1, 2); |
250 | 255 |
|
251 | 256 |
if ($amount != 0) { |
252 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) |
|
253 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
254 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{"paid_$i"}); |
|
257 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) |
|
258 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?), |
|
259 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
260 |
@values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{"paid_$i"}, |
|
261 |
$form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"})); |
|
255 | 262 |
do_query($form, $dbh, $query, @values); |
256 | 263 |
} |
257 | 264 |
|
... | ... | |
260 | 267 |
|
261 | 268 |
if ($amount != 0) { |
262 | 269 |
my $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}; |
263 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) |
|
264 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; |
|
265 |
@values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno); |
|
270 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) |
|
271 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?), |
|
272 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
273 |
@values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno, $accno, conv_date($form->{"datepaid_$i"})); |
|
266 | 274 |
do_query($form, $dbh, $query, @values); |
267 | 275 |
} |
268 | 276 |
} |
SL/DB/Helper/PriceTaxCalculator.pm | ||
---|---|---|
119 | 119 |
$self->netamount($self->netamount + $sellprice * $item->qty / $item->price_factor); |
120 | 120 |
|
121 | 121 |
my $chart = $item->part->get_chart(type => $data->{is_sales} ? 'income' : 'expense', taxzone => $self->taxzone_id); |
122 |
$data->{amounts}->{ $chart->id } ||= { taxkey => $taxkey->taxkey_id, amount => 0 }; |
|
122 |
$data->{amounts}->{ $chart->id } ||= { taxkey => $taxkey->taxkey_id, tax_id => $taxkey->tax_id, amount => 0 };
|
|
123 | 123 |
$data->{amounts}->{ $chart->id }->{amount} += $linetotal; |
124 | 124 |
|
125 | 125 |
push @{ $data->{assembly_items} }, []; |
SL/DB/Invoice.pm | ||
---|---|---|
188 | 188 |
sub _post_add_acctrans { |
189 | 189 |
my ($self, $entries) = @_; |
190 | 190 |
|
191 |
my $default_tax_id = SL::DB::Manager::Tax->find_by(taxkey => 0)->id; |
|
192 |
|
|
191 | 193 |
while (my ($chart_id, $spec) = each %{ $entries }) { |
192 |
$spec = { taxkey => 0, amount => $spec } unless ref $spec; |
|
194 |
$spec = { taxkey => 0, tax_id => $default_tax_id, amount => $spec } unless ref $spec;
|
|
193 | 195 |
SL::DB::AccTransaction->new(trans_id => $self->id, |
194 | 196 |
chart_id => $chart_id, |
195 | 197 |
amount => $spec->{amount}, |
198 |
tax_id => $spec->{tax_id}, |
|
196 | 199 |
taxkey => $spec->{taxkey}, |
197 | 200 |
project_id => $self->globalproject_id, |
198 | 201 |
transdate => $self->transdate)->save; |
SL/DB/MetaSetup/AccTransaction.pm | ||
---|---|---|
26 | 26 |
taxkey => { type => 'integer' }, |
27 | 27 |
itime => { type => 'timestamp', default => 'now()' }, |
28 | 28 |
mtime => { type => 'timestamp' }, |
29 |
tax_id => { type => 'integer', not_null => 1 }, |
|
29 | 30 |
], |
30 | 31 |
|
31 | 32 |
primary_key_columns => [ 'acc_trans_id' ], |
32 | 33 |
|
33 |
allow_inline_column_values => 1, |
|
34 |
|
|
35 | 34 |
foreign_keys => [ |
36 | 35 |
chart => { |
37 | 36 |
class => 'SL::DB::Chart', |
SL/GL.pm | ||
---|---|---|
159 | 159 |
if ($amount != 0) { |
160 | 160 |
$query = |
161 | 161 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
162 |
source, memo, project_id, taxkey, ob_transaction, cb_transaction) |
|
162 |
source, memo, project_id, taxkey, ob_transaction, cb_transaction, tax_id)
|
|
163 | 163 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), |
164 |
?, ?, ?, ?, ?, ?, ?, ?)|; |
|
164 |
?, ?, ?, ?, ?, ?, ?, ?, ?)|;
|
|
165 | 165 |
@values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{transdate}), |
166 |
$form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f'); |
|
166 |
$form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f', conv_i($form->{"tax_id_$i"}));
|
|
167 | 167 |
do_query($form, $dbh, $query, @values); |
168 | 168 |
} |
169 | 169 |
|
... | ... | |
171 | 171 |
# add taxentry |
172 | 172 |
$query = |
173 | 173 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
174 |
source, memo, project_id, taxkey) |
|
174 |
source, memo, project_id, taxkey, tax_id)
|
|
175 | 175 |
VALUES (?, (SELECT chart_id FROM tax WHERE id = ?), |
176 |
?, ?, ?, ?, ?, ?)|; |
|
176 |
?, ?, ?, ?, ?, ?, ?)|;
|
|
177 | 177 |
@values = (conv_i($form->{id}), conv_i($form->{"tax_id_$i"}), |
178 | 178 |
$tax, conv_date($form->{transdate}), $form->{"source_$i"}, |
179 |
$form->{"memo_$i"}, $project_id, $taxkey); |
|
179 |
$form->{"memo_$i"}, $project_id, $taxkey, conv_i($form->{"tax_id_$i"}));
|
|
180 | 180 |
do_query($form, $dbh, $query, @values); |
181 | 181 |
} |
182 | 182 |
} |
SL/IR.pm | ||
---|---|---|
269 | 269 |
|
270 | 270 |
# allocated >= 0 |
271 | 271 |
# add entry for inventory, this one is for the sold item |
272 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?))|; |
|
273 |
@values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}); |
|
272 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?), |
|
273 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
274 |
@values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{inventory_accno_id}, $ref->{transdate}); |
|
274 | 275 |
do_query($form, $dbh, $query, @values); |
275 | 276 |
|
276 | 277 |
# add expense |
277 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?))|; |
|
278 |
@values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}); |
|
278 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?), |
|
279 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
280 |
@values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}, $ref->{expense_accno_id}, $ref->{transdate}); |
|
279 | 281 |
do_query($form, $dbh, $query, @values); |
280 | 282 |
} |
281 | 283 |
}; |
... | ... | |
478 | 480 |
|
479 | 481 |
next if $payments_only || !$form->{amount}{$trans_id}{$accno}; |
480 | 482 |
|
481 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
483 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id)
|
|
482 | 484 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, |
483 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
|
485 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?, |
|
486 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
484 | 487 |
@values = ($trans_id, $accno, $form->{amount}{$trans_id}{$accno}, |
485 |
conv_date($form->{invdate}), $accno, $project_id); |
|
488 |
conv_date($form->{invdate}), $accno, $project_id, $accno, conv_date($form->{invdate}));
|
|
486 | 489 |
do_query($form, $dbh, $query, @values); |
487 | 490 |
} |
488 | 491 |
} |
... | ... | |
517 | 520 |
|
518 | 521 |
# record AP |
519 | 522 |
if ($form->{amount}{ $form->{id} }{ $form->{AP} } != 0) { |
520 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
523 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id)
|
|
521 | 524 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, |
522 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
|
525 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?, |
|
526 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
523 | 527 |
@values = (conv_i($form->{id}), $form->{AP}, $amount, |
524 |
$form->{"datepaid_$i"}, $form->{AP}, $project_id); |
|
528 |
$form->{"datepaid_$i"}, $form->{AP}, $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}));
|
|
525 | 529 |
do_query($form, $dbh, $query, @values); |
526 | 530 |
} |
527 | 531 |
|
... | ... | |
529 | 533 |
my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); |
530 | 534 |
|
531 | 535 |
$query = |
532 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id) |
|
536 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id, tax_id)
|
|
533 | 537 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, |
534 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
|
538 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?, |
|
539 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
535 | 540 |
@values = (conv_i($form->{id}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"}, |
536 |
$gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id); |
|
541 |
$gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id, $accno, conv_date($form->{"datepaid_$i"}));
|
|
537 | 542 |
do_query($form, $dbh, $query, @values); |
538 | 543 |
|
539 | 544 |
$exchangerate = 0; |
... | ... | |
571 | 576 |
$form->{fx}{$accno}{$transdate} = $form->round_amount($form->{fx}{$accno}{$transdate}, 2); |
572 | 577 |
next if ($form->{fx}{$accno}{$transdate} == 0); |
573 | 578 |
|
574 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id) |
|
575 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', 0, ?)|; |
|
576 |
@values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id); |
|
579 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id, tax_id) |
|
580 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', 0, ?, |
|
581 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|; |
|
582 |
@values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id, $accno, $form->{fx}{$accno}{$transdate}); |
|
577 | 583 |
do_query($form, $dbh, $query, @values); |
578 | 584 |
} |
579 | 585 |
} |
SL/IS.pm | ||
---|---|---|
818 | 818 |
|
819 | 819 |
$project_id = conv_i($form->{"globalproject_id"}); |
820 | 820 |
|
821 |
my $taxdate = $form->{deliverydate} ? $form->{deliverydate} : $form->{invdate}; |
|
822 |
|
|
821 | 823 |
foreach my $trans_id (keys %{ $form->{amount_cogs} }) { |
822 | 824 |
foreach my $accno (keys %{ $form->{amount_cogs}{$trans_id} }) { |
823 | 825 |
next unless ($form->{expense_inventory} =~ /\Q$accno\E/); |
... | ... | |
826 | 828 |
|
827 | 829 |
if (!$payments_only && ($form->{amount_cogs}{$trans_id}{$accno} != 0)) { |
828 | 830 |
$query = |
829 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
830 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 0, ?)|; |
|
831 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
|
|
832 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?)|;
|
|
831 | 833 |
@values = (conv_i($trans_id), $accno, $form->{amount_cogs}{$trans_id}{$accno}, conv_date($form->{invdate}), conv_i($project_id)); |
832 | 834 |
do_query($form, $dbh, $query, @values); |
833 | 835 |
$form->{amount_cogs}{$trans_id}{$accno} = 0; |
... | ... | |
839 | 841 |
|
840 | 842 |
if (!$payments_only && ($form->{amount_cogs}{$trans_id}{$accno} != 0)) { |
841 | 843 |
$query = |
842 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
843 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 0, ?)|; |
|
844 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
|
|
845 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?)|;
|
|
844 | 846 |
@values = (conv_i($trans_id), $accno, $form->{amount_cogs}{$trans_id}{$accno}, conv_date($form->{invdate}), conv_i($project_id)); |
845 | 847 |
do_query($form, $dbh, $query, @values); |
846 | 848 |
} |
... | ... | |
855 | 857 |
|
856 | 858 |
if (!$payments_only && ($form->{amount}{$trans_id}{$accno} != 0)) { |
857 | 859 |
$query = |
858 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
860 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
|
|
859 | 861 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, |
862 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), |
|
860 | 863 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
861 |
@values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_i($project_id)); |
|
864 |
@values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_i($project_id));
|
|
862 | 865 |
do_query($form, $dbh, $query, @values); |
863 | 866 |
$form->{amount}{$trans_id}{$accno} = 0; |
864 | 867 |
} |
... | ... | |
869 | 872 |
|
870 | 873 |
if (!$payments_only && ($form->{amount}{$trans_id}{$accno} != 0)) { |
871 | 874 |
$query = |
872 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
875 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
|
|
873 | 876 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, |
877 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), |
|
874 | 878 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
875 |
@values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_i($project_id)); |
|
879 |
@values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_i($project_id));
|
|
876 | 880 |
do_query($form, $dbh, $query, @values); |
877 | 881 |
} |
878 | 882 |
} |
... | ... | |
918 | 922 |
|
919 | 923 |
if ($form->{amount}{ $form->{id} }{ $form->{AR} } != 0) { |
920 | 924 |
$query = |
921 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id) |
|
925 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
|
|
922 | 926 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, |
927 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), |
|
923 | 928 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
924 |
@values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, $project_id); |
|
929 |
@values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, conv_date($taxdate), $form->{AR}, $project_id);
|
|
925 | 930 |
do_query($form, $dbh, $query, @values); |
926 | 931 |
} |
927 | 932 |
|
... | ... | |
930 | 935 |
my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); |
931 | 936 |
|
932 | 937 |
$query = |
933 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id) |
|
938 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, tax_id, taxkey, project_id)
|
|
934 | 939 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, |
940 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), |
|
935 | 941 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
936 | 942 |
@values = (conv_i($form->{"id"}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"}, |
937 |
$gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id); |
|
943 |
$gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($taxdate), $accno, $project_id);
|
|
938 | 944 |
do_query($form, $dbh, $query, @values); |
939 | 945 |
|
940 | 946 |
# exchangerate difference |
... | ... | |
974 | 980 |
if ( $form->{fx}{$accno}{$transdate} != 0 ) { |
975 | 981 |
|
976 | 982 |
$query = |
977 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id) |
|
983 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, tax_id, taxkey, project_id)
|
|
978 | 984 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', |
979 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
|
980 |
@values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_i($project_id)); |
|
985 |
(SELECT tax_id FROM taxkeys WHERE taxkey_id= (SELECT taxkey_id FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1), |
|
986 |
(SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; |
|
987 |
@values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_date($taxdate), $accno, conv_i($project_id)); |
|
981 | 988 |
do_query($form, $dbh, $query, @values); |
982 | 989 |
} |
983 | 990 |
} |
sql/Pg-upgrade2/add_tax_id_to_acc_trans.sql | ||
---|---|---|
1 |
-- @tag: add_tax_id_to_acc_trans |
|
2 |
-- @description: Neue Spalte tax_id in der acc_trans |
|
3 |
-- @depends: release_2_7_0 |
|
4 |
|
|
5 |
--Neue Spalte tax_id in acc_trans: |
|
6 |
ALTER TABLE acc_trans ADD tax_id integer; |
|
7 |
|
|
8 |
--Spalte mit Werten füllen: |
|
9 |
UPDATE acc_trans ac SET tax_id= |
|
10 |
(select tk.tax_id from taxkeys tk |
|
11 |
where tk.taxkey_id=ac.taxkey |
|
12 |
AND tk.startdate <= COALESCE( |
|
13 |
(select ar.deliverydate from ar where ar.id=ac.trans_id), |
|
14 |
(select ar.transdate from ar where ar.id=ac.trans_id), |
|
15 |
(select ap.transdate from ap where ap.id=ac.trans_id), |
|
16 |
(select gl.transdate from gl where gl.id=ac.trans_id), |
|
17 |
ac.transdate ) |
|
18 |
order by startdate desc limit 1); |
|
19 |
|
|
20 |
--Spalten, die noch null sind (nur bei Einträgen möglich, wo auch taxkey null ist) |
|
21 |
UPDATE acc_trans SET tax_id=0 where tax_id is null; |
|
22 |
|
|
23 |
--tax_id als Pflichtfeld definieren: |
|
24 |
ALTER TABLE acc_trans ALTER tax_id SET NOT NULL; |
|
25 |
|
Auch abrufbar als: Unified diff
tax_id in acc_trans
Dieser Commit enthält das Update-Script um eine neue Spalte Namens
'tax_id' in die Tabelle 'acc_trans' einzufügen. Diese Spalte ist
ein Pflichtfeld.
Das Pflichtfeld wird jetzt immer geschrieben bei:
-VK-Rechnungen (auch automatisch erzeugten)
-EK-Rechnungen
-Kreditorenbuchungen
-Debitorenbuchungen
-Dialogbuchungen
Durch das Feld 'tax_id' können in der Tabelle tax der
Steuerschlüssel und der Steuersatz ausgelesen werden.
In diesem Commit wird allerdings der Wert in tax_id nur geschrieben,
im Moment wird er noch nirgendwo ausgelesen.