Revision 653af2fb
Von Jan Büren vor etwa 4 Jahren hinzugefügt
SL/DB/GLTransaction.pm | ||
---|---|---|
129 | 129 |
croak t8('You cannot use a negative amount with debit/credit!') if $amount < 0; |
130 | 130 |
|
131 | 131 |
require SL::DB::Tax; |
132 |
my $tax = SL::DB::Manager::Tax->find_by(id => $params{tax_id}) |
|
133 |
// croak "Can't find tax with id " . $params{tax_id}; |
|
132 |
|
|
133 |
my $ct = $chart->get_active_taxkey($self->deliverydate // $self->transdate); |
|
134 |
my $chart_tax = ref $ct eq 'SL::DB::TaxKey' ? $ct->tax : undef; |
|
135 |
|
|
136 |
my $tax = defined($params{tax_id}) ? SL::DB::Manager::Tax->find_by(id => $params{tax_id}) # 1. user param |
|
137 |
: ref $chart_tax eq 'SL::DB::Tax' ? $chart_tax # automatic tax |
|
138 |
: SL::DB::Manager::Tax->find_by(taxkey => 0, rate => 0.00); # no tax |
|
139 |
|
|
140 |
die "No valid tax found. User input:" . $params{tax_id} unless ref $tax eq 'SL::DB::Tax'; |
|
134 | 141 |
|
135 | 142 |
if ( $tax and $tax->rate != 0 ) { |
136 | 143 |
($netamount, $taxamount) = Form->calculate_tax($amount, $tax->rate, $self->taxincluded, $dec); |
... | ... | |
283 | 290 |
Adds an acc_trans entry to an existing GL transaction, depending on the tax it |
284 | 291 |
will also automatically create the tax entry. The GL transaction already needs |
285 | 292 |
to have certain values, e.g. transdate, taxincluded, ... |
293 |
Tax can be either set via the param tax_id or it will be set automatically |
|
294 |
depending on the chart configuration. If not set and no configuration is found |
|
295 |
no tax entry will be created (taxkey 0). |
|
286 | 296 |
|
287 | 297 |
Mandatory params are |
288 | 298 |
|
... | ... | |
290 | 300 |
|
291 | 301 |
=item * chart as an RDBO object |
292 | 302 |
|
293 |
=item * tax_id |
|
294 |
|
|
295 | 303 |
=item * either debit OR credit (positive values) |
296 | 304 |
|
297 | 305 |
=back |
t/gl/gl.t | ||
---|---|---|
1 | 1 |
use strict; |
2 |
use Test::More tests => 4;
|
|
2 |
use Test::More tests => 8;
|
|
3 | 3 |
|
4 | 4 |
use lib 't'; |
5 | 5 |
use Support::TestSetup; |
... | ... | |
257 | 257 |
"chart balances ok" |
258 | 258 |
); |
259 | 259 |
|
260 |
note "testing automatic tax 19%"; |
|
261 |
|
|
262 |
my $gl_transaction_7 = SL::DB::GLTransaction->new( |
|
263 |
reference => 'betriebsbedarf tax not included', |
|
264 |
description => 'bar', |
|
265 |
taxincluded => 0, |
|
266 |
transdate => DateTime->new(year => 2019, month => 12, day => 30), |
|
267 |
); |
|
268 |
|
|
269 |
$gl_transaction_7->add_chart_booking(%{$_}) foreach ( |
|
270 |
{ |
|
271 |
chart => $betriebsbedarf, |
|
272 |
debit => 100, |
|
273 |
}, |
|
274 |
{ |
|
275 |
chart => $betriebsbedarf, |
|
276 |
debit => 100, |
|
277 |
}, |
|
278 |
{ |
|
279 |
chart => $betriebsbedarf, |
|
280 |
debit => 100, |
|
281 |
tax_id => $tax_0->id, |
|
282 |
}, |
|
283 |
{ |
|
284 |
chart => $cash, |
|
285 |
credit => 338, |
|
286 |
}, |
|
287 |
); |
|
288 |
$gl_transaction_7->post; |
|
289 |
|
|
290 |
is(SL::DB::Manager::GLTransaction->get_all_count(), 9, "gl transactions created ok"); |
|
291 |
is_deeply(&get_account_balances, |
|
292 |
[ |
|
293 |
{ |
|
294 |
'accno' => '1000', |
|
295 |
'sum' => '1328.14000' |
|
296 |
}, |
|
297 |
{ |
|
298 |
'accno' => '1200', |
|
299 |
'sum' => '-100.00000' |
|
300 |
}, |
|
301 |
{ |
|
302 |
'accno' => '1571', |
|
303 |
'sum' => '-14.00000' |
|
304 |
}, |
|
305 |
{ |
|
306 |
'accno' => '1576', |
|
307 |
'sum' => '-114.02000' |
|
308 |
}, |
|
309 |
{ |
|
310 |
'accno' => '4980', |
|
311 |
'sum' => '-1100.12000' |
|
312 |
} |
|
313 |
], |
|
314 |
"chart balances ok" |
|
315 |
); |
|
316 |
|
|
317 |
note "testing automatic tax 16%"; |
|
318 |
|
|
319 |
my $gl_transaction_8 = SL::DB::GLTransaction->new( |
|
320 |
reference => 'betriebsbedarf tax not included', |
|
321 |
description => 'bar', |
|
322 |
taxincluded => 0, |
|
323 |
transdate => DateTime->new(year => 2020, month => 12, day => 31), |
|
324 |
); |
|
325 |
|
|
326 |
$gl_transaction_8->add_chart_booking(%{$_}) foreach ( |
|
327 |
{ |
|
328 |
chart => $betriebsbedarf, |
|
329 |
debit => 100, |
|
330 |
}, |
|
331 |
{ |
|
332 |
chart => $betriebsbedarf, |
|
333 |
debit => 100, |
|
334 |
}, |
|
335 |
{ |
|
336 |
chart => $betriebsbedarf, |
|
337 |
debit => 100, |
|
338 |
tax_id => $tax_0->id, |
|
339 |
}, |
|
340 |
{ |
|
341 |
chart => $cash, |
|
342 |
credit => 332, |
|
343 |
}, |
|
344 |
); |
|
345 |
$gl_transaction_8->post; |
|
346 |
|
|
347 |
is(SL::DB::Manager::GLTransaction->get_all_count(), 10, "gl transactions created ok"); |
|
348 |
is_deeply(&get_account_balances, |
|
349 |
[ |
|
350 |
{ |
|
351 |
'accno' => '1000', |
|
352 |
'sum' => '1660.14000' |
|
353 |
}, |
|
354 |
{ |
|
355 |
'accno' => '1200', |
|
356 |
'sum' => '-100.00000' |
|
357 |
}, |
|
358 |
{ |
|
359 |
'accno' => '1571', |
|
360 |
'sum' => '-14.00000' |
|
361 |
}, |
|
362 |
{ |
|
363 |
'accno' => '1575', |
|
364 |
'sum' => '-32.00000' |
|
365 |
}, |
|
366 |
{ |
|
367 |
'accno' => '1576', |
|
368 |
'sum' => '-114.02000' |
|
369 |
}, |
|
370 |
{ |
|
371 |
'accno' => '4980', |
|
372 |
'sum' => '-1400.12000' |
|
373 |
} |
|
374 |
], |
|
375 |
"chart balances ok" |
|
376 |
); |
|
377 |
|
|
260 | 378 |
done_testing; |
261 | 379 |
clear_up(); |
262 | 380 |
|
Auch abrufbar als: Unified diff
GLTransaction:: add_chart_booking um get_active_taxkey erweitert
Der Aufruf von add_chart_booking muss sich nicht mehr
darum kümmern welcher Steuerschlüssel gesetzt sein muss, wenn
er einfach nur den vorkonfigurierten Steuerschlüssel setzen will.
Dementsprechend ist param{tax_id} kein Pflichtparameter mehr.
POD ergänzt und mit Testfällen abgesichert (19% / 16% Fall).