269 |
269 |
|
270 |
270 |
my %taxkeys = map { ($_->id => $_->get_taxkey(date => DateTime->today_local, is_sales => 1, taxzone => $invoice->taxzone_id)) } uniq map { $_->part } ($item1, $item2, $item3);
|
271 |
271 |
|
272 |
|
# this is how price_tax_calculator is implemented. It differs from
|
273 |
|
# the way sales_order / invoice - forms are calculating:
|
274 |
|
# linetotal = sellprice 5.55 * qty 1 * (1 - 0.05) = 5.2725; rounded 5.27
|
275 |
|
# linetotal = sellprice 5.50 * qty 1 * (1 - 0.05) = 5.225 rounded 5.23
|
276 |
|
# linetotal = sellprice 5.00 * qty 1 * (1 - 0.05) = 4.75; rounded 4.75
|
277 |
|
# ...
|
278 |
|
|
279 |
272 |
# item 1:
|
280 |
273 |
# discount = sellprice 5.55 * discount (0.05) = 0.2775; rounded 0.28
|
281 |
|
# sellprice = sellprice 5.55 - discount 0.28 = 5.27; rounded 5.27
|
282 |
|
# linetotal = sellprice 5.27 * qty 1 = 5.27; rounded 5.27
|
|
274 |
# linetotal = sellprice 5.55 * (1 - discount 0.05) * qty 1 = 5.2725; rounded 5.27
|
283 |
275 |
# 19%(5.27) = 1.0013; rounded = 1.00
|
284 |
276 |
# total rounded = 6.27
|
285 |
277 |
|
286 |
278 |
# lastcost 1.93 * qty 1 = 1.93; rounded 1.93
|
287 |
|
# line marge_total = 3.34
|
|
279 |
# line marge_total = 5.27 - 1.93 = 3.34
|
288 |
280 |
# line marge_percent = 63.3776091081594
|
289 |
281 |
|
290 |
282 |
# item 2:
|
291 |
283 |
# discount = sellprice 5.50 * discount 0.05 = 0.275; rounded 0.28
|
292 |
|
# sellprice = sellprice 5.50 - discount 0.28 = 5.22; rounded 5.22
|
293 |
|
# linetotal = sellprice 5.22 * qty 1 = 5.22; rounded 5.22
|
294 |
|
# 19%(5.22) = 0.9918; rounded = 0.99
|
295 |
|
# total rounded = 6.21
|
|
284 |
# linetotal = sellprice 5.50 * (1 - discount 0.05) * qty 1 = 5.225; rounded 5.23
|
|
285 |
# 19%(5.23) = .99370; rounded = 0.99
|
|
286 |
# total rounded = 6.22
|
296 |
287 |
|
297 |
288 |
# lastcost 1.93 * qty 1 = 1.93; rounded 1.93
|
298 |
|
# line marge_total = 5.22 - 1.93 = 3.29
|
299 |
|
# line marge_percent = 3.29/5.22 = 0.630268199233716
|
|
289 |
# line marge_total = 5.23 - 1.93 = 3.30
|
|
290 |
# line marge_percent = 3.30/5.23 = 0.630975143403442
|
300 |
291 |
|
301 |
292 |
# item 3:
|
302 |
|
# discount = sellprice 5.00 * discount 0.25 = 0.25; rounded 0.25
|
303 |
|
# sellprice = sellprice 5.00 - discount 0.25 = 4.75; rounded 4.75
|
304 |
|
# linetotal = sellprice 4.75 * qty 1 = 4.75; rounded 4.75
|
|
293 |
# discount = sellprice 5.00 * discount 0.05 = 0.05 = 0.25; rounded 0.25
|
|
294 |
# linetotal = sellprice 5.00 (1 - discount 0.05) * qty 1 = 4.75; rounded 4.75
|
305 |
295 |
# 19%(4.75) = 0.9025; rounded = 0.90
|
306 |
296 |
# total rounded = 5.65
|
307 |
297 |
|
308 |
298 |
# lastcost 1.93 * qty 1 = 1.93; rounded 1.93
|
309 |
|
# line marge_total = 2.82
|
310 |
|
# line marge_percent = 59.3684210526316
|
|
299 |
# line marge_total = 4.75 - 1.93 = 2.82
|
|
300 |
# line marge_percent = 2.82/4.75 = 59.3684210526316
|
311 |
301 |
|
312 |
302 |
my $title = 'default invoice, three items, sellprice, rounding, discount';
|
313 |
303 |
my %data = $invoice->calculate_prices_and_taxes;
|
... | ... | |
316 |
306 |
is($item1->marge_percent, 63.3776091081594, "${title}: item1 marge_percent");
|
317 |
307 |
is($item1->marge_price_factor, 1, "${title}: item1 marge_price_factor");
|
318 |
308 |
|
319 |
|
is($item2->marge_total, 3.29, "${title}: item2 marge_total");
|
320 |
|
is($item2->marge_percent, 63.0268199233716, "${title}: item2 marge_percent");
|
|
309 |
is($item2->marge_total, 3.30, "${title}: item2 marge_total");
|
|
310 |
is($item2->marge_percent, 63.0975143403442, "${title}: item2 marge_percent");
|
321 |
311 |
is($item2->marge_price_factor, 1, "${title}: item2 marge_price_factor");
|
322 |
312 |
|
323 |
313 |
is($item3->marge_total, 2.82, "${title}: item3 marge_total");
|
324 |
314 |
is($item3->marge_percent, 59.3684210526316, "${title}: item3 marge_percent");
|
325 |
315 |
is($item3->marge_price_factor, 1, "${title}: item3 marge_price_factor");
|
326 |
316 |
|
327 |
|
is($invoice->netamount, 5.27 + 5.22 + 4.75, "${title}: netamount");
|
|
317 |
is($invoice->netamount, 5.27 + 5.23 + 4.75, "${title}: netamount");
|
328 |
318 |
|
329 |
|
# 6.27 + 6.21 + 5.65 = 18.13
|
330 |
|
# 1.19*(5.27 + 5.22 + 4.75) = 18.1356; rounded 18.14
|
331 |
|
#is($invoice->amount, 6.27 + 6.21 + 5.65, "${title}: amount");
|
332 |
|
is($invoice->amount, 18.14, "${title}: amount");
|
|
319 |
# 6.27 + 6.22 + 5.65 = 18.14
|
|
320 |
# 1.19*(5.27 + 5.23 + 4.75) = 18.1475; rounded 18.15
|
|
321 |
#is($invoice->amount, 6.27 + 6.22 + 5.65, "${title}: amount");
|
|
322 |
is($invoice->amount, 18.15, "${title}: amount");
|
333 |
323 |
|
334 |
|
is($invoice->marge_total, 3.34 + 3.29 + 2.82, "${title}: marge_total");
|
335 |
|
is($invoice->marge_percent, 62.007874015748, "${title}: marge_percent");
|
|
324 |
is($invoice->marge_total, 3.34 + 3.30 + 2.82, "${title}: marge_total");
|
|
325 |
is($invoice->marge_percent, 62.0327868852459, "${title}: marge_percent");
|
336 |
326 |
|
337 |
327 |
is_deeply(\%data, {
|
338 |
328 |
allocated => {},
|
339 |
329 |
amounts => {
|
340 |
330 |
$buchungsgruppe->income_accno_id($taxzone) => {
|
341 |
|
amount => 15.24,
|
|
331 |
amount => 15.25,
|
342 |
332 |
tax_id => $tax->id,
|
343 |
333 |
taxkey => 3,
|
344 |
334 |
},
|
... | ... | |
354 |
344 |
items => [
|
355 |
345 |
{ linetotal => 5.27,
|
356 |
346 |
linetotal_cost => 1.93,
|
357 |
|
sellprice => 5.27,
|
|
347 |
sellprice => 5.55,
|
358 |
348 |
tax_amount => 1.0013,
|
359 |
349 |
taxkey_id => $taxkeys{$item1->parts_id}->id,
|
360 |
350 |
},
|
361 |
|
{ linetotal => 5.22,
|
|
351 |
{ linetotal => 5.23,
|
362 |
352 |
linetotal_cost => 1.93,
|
363 |
|
sellprice => 5.22,
|
364 |
|
tax_amount => 0.9918,
|
|
353 |
sellprice => 5.5,
|
|
354 |
tax_amount => 0.9937,
|
365 |
355 |
taxkey_id => $taxkeys{$item2->parts_id}->id,
|
366 |
356 |
},
|
367 |
357 |
{ linetotal => 4.75,
|
368 |
358 |
linetotal_cost => 1.93,
|
369 |
|
sellprice => 4.75,
|
|
359 |
sellprice => 5,
|
370 |
360 |
tax_amount => 0.9025,
|
371 |
361 |
taxkey_id => $taxkeys{$item3->parts_id}->id,
|
372 |
362 |
}
|
... | ... | |
430 |
420 |
items => [
|
431 |
421 |
{ linetotal => 3.49,
|
432 |
422 |
linetotal_cost => 0,
|
433 |
|
sellprice => 0.58,
|
|
423 |
sellprice => 0.6,
|
434 |
424 |
tax_amount => 0.6631,
|
435 |
425 |
taxkey_id => $taxkeys{$item->parts_id}->id,
|
436 |
426 |
},
|
437 |
427 |
],
|
|
428 |
rounding => 0,
|
438 |
429 |
}, "${title}: calculated data");
|
439 |
430 |
}
|
440 |
431 |
|
441 |
|
-
|