Revision 5a321e6b
Von Jan Büren vor fast 2 Jahren hinzugefügt
t/db_helper/payment.t | ||
---|---|---|
41 | 41 |
Support::TestSetup::login(); |
42 | 42 |
|
43 | 43 |
init_state(); |
44 |
|
|
45 | 44 |
# test cases: without_skonto |
46 | 45 |
test_default_invoice_one_item_19_without_skonto(); |
47 | 46 |
test_default_invoice_two_items_19_7_tax_with_skonto(); |
... | ... | |
1196 | 1195 |
is($invoice->taxincluded , 0 , 'ar transaction doesn\'t have taxincluded'); |
1197 | 1196 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_amount_chart->id, trans_id => $invoice->id)->amount, '100.00000', $ar_amount_chart->accno . ': has been converted for currency'); |
1198 | 1197 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_chart->id, trans_id => $invoice->id)->amount, '-119.00000', $ar_chart->accno . ': has been converted for currency'); |
1199 |
|
|
1200 | 1198 |
$invoice->pay_invoice(chart_id => $bank->id, |
1201 | 1199 |
amount => 50, # amount is in default currency -> should be 37.5 in CUR |
1202 | 1200 |
currency => 'CUR', |
1203 | 1201 |
transdate => $transdate1->to_kivitendo, |
1202 |
exchangerate => $exchangerate->sell, |
|
1204 | 1203 |
); |
1205 | 1204 |
$invoice->pay_invoice(chart_id => $bank->id, |
1206 | 1205 |
amount => 39.25, # amount is in default currency -> should be 29.44 in CUR |
1207 | 1206 |
currency => 'CUR', |
1208 | 1207 |
transdate => $transdate1->to_kivitendo, |
1208 |
exchangerate => $exchangerate->sell, |
|
1209 | 1209 |
); |
1210 |
# $invoice->pay_invoice(chart_id => $bank->id, |
|
1211 |
# amount => 30, |
|
1212 |
# transdate => $transdate2->to_kivitendo, |
|
1213 |
# ); |
|
1214 |
is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions (incl. fxtransactions)'); |
|
1210 |
$invoice->pay_invoice(chart_id => $bank->id, |
|
1211 |
amount => 29.75, |
|
1212 |
transdate => $transdate1->to_kivitendo, |
|
1213 |
currency => 'CUR', |
|
1214 |
exchangerate => $exchangerate->sell, |
|
1215 |
); |
|
1216 |
is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions'); |
|
1215 | 1217 |
is($invoice->paid, $invoice->amount, 'ar transaction paid = amount in default currency'); |
1216 |
};
|
|
1218 |
} |
|
1217 | 1219 |
|
1218 | 1220 |
sub test_ar_currency_tax_included { |
1219 | 1221 |
my $title = 'test_ar_currency_tax_included'; |
... | ... | |
1252 | 1254 |
amount => 89.25, |
1253 | 1255 |
currency => 'CUR', |
1254 | 1256 |
transdate => $transdate1->to_kivitendo, |
1257 |
exchangerate => $exchangerate->sell, |
|
1255 | 1258 |
); |
1256 | 1259 |
|
1257 | 1260 |
}; |
... | ... | |
1294 | 1297 |
amount => 50, |
1295 | 1298 |
currency => 'CUR', |
1296 | 1299 |
transdate => $transdate1->to_kivitendo, |
1300 |
exchangerate => $exchangerate->buy, |
|
1297 | 1301 |
); |
1298 | 1302 |
$invoice->pay_invoice(chart_id => $bank->id, |
1299 | 1303 |
amount => 39.25, |
1300 | 1304 |
currency => 'CUR', |
1301 | 1305 |
transdate => $transdate1->to_kivitendo, |
1306 |
exchangerate => $exchangerate->buy, |
|
1307 |
); |
|
1308 |
is($invoice->paid, 89.25, 'ap transaction paid = amount in default currency'); |
|
1309 |
$invoice->pay_invoice(chart_id => $bank->id, |
|
1310 |
amount => 22.31 * $exchangerate2->buy, # 22.31 in fx currency |
|
1311 |
currency => 'CUR', |
|
1312 |
transdate => $transdate2->to_kivitendo, |
|
1313 |
exchangerate => $exchangerate2->buy, |
|
1302 | 1314 |
); |
1303 |
is(scalar @{$invoice->transactions}, 9, 'ap transaction has 9 transactions (incl. fxtransactions)'); |
|
1315 |
|
|
1316 |
is(scalar @{$invoice->transactions}, 10, 'ap transaction has 10 transactions (including fx gain transaction)'); |
|
1304 | 1317 |
is($invoice->paid, $invoice->amount, 'ap transaction paid = amount in default currency'); |
1305 |
}; |
|
1318 |
|
|
1319 |
# check last booking fx rate decreased to 0.8 from 1.33333 |
|
1320 |
my $fxgain_chart = SL::DB::Manager::Chart->find_by(accno => '2660') or die "Can't find fxgain_chart in test"; |
|
1321 |
my $fx_gain_transactions = SL::DB::Manager::AccTransaction->get_all(where => |
|
1322 |
[ trans_id => $invoice->id, chart_id => $fxgain_chart->id ], |
|
1323 |
sort_by => ('acc_trans_id')); |
|
1324 |
|
|
1325 |
is($fx_gain_transactions->[0]->amount, '11.90000', "fx gain amount ok"); |
|
1326 |
|
|
1327 |
# check last bank transaction should be 22.31 * 0.8 |
|
1328 |
my $last_bank_transaction = SL::DB::Manager::AccTransaction->get_all(where => |
|
1329 |
[ trans_id => $invoice->id, chart_id => $bank->id, transdate => $transdate2 ], |
|
1330 |
sort_by => ('acc_trans_id')); |
|
1331 |
|
|
1332 |
is($last_bank_transaction->[0]->amount, '17.85000', "fx bank amount with fx gain ok"); |
|
1333 |
|
|
1334 |
|
|
1335 |
|
|
1336 |
} |
|
1306 | 1337 |
|
1307 | 1338 |
sub test_ap_currency_tax_included { |
1308 | 1339 |
my $title = 'test_ap_currency_tax_included'; |
... | ... | |
1342 | 1373 |
amount => 89.25, |
1343 | 1374 |
currency => 'CUR', |
1344 | 1375 |
transdate => $transdate1->to_kivitendo, |
1376 |
exchangerate => $exchangerate->sell, |
|
1345 | 1377 |
); |
1346 | 1378 |
|
1347 | 1379 |
}; |
... | ... | |
1381 | 1413 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_chart->id, trans_id => $invoice->id)->amount, '-119.00000', $title . " " . $ar_chart->accno . ': has been converted for currency'); |
1382 | 1414 |
|
1383 | 1415 |
$invoice->pay_invoice(chart_id => $bank->id, |
1384 |
amount => 123.45, |
|
1416 |
amount => 123.45 * $exchangerate2->sell,
|
|
1385 | 1417 |
currency => 'CUR', |
1386 | 1418 |
transdate => $transdate2->to_kivitendo, |
1419 |
exchangerate => $exchangerate2->sell, |
|
1387 | 1420 |
); |
1388 | 1421 |
$invoice->pay_invoice(chart_id => $bank->id, |
1389 |
amount => 15.30, |
|
1422 |
amount => 15.30 * $exchangerate3->sell,
|
|
1390 | 1423 |
currency => 'CUR', |
1391 | 1424 |
transdate => $transdate3->to_kivitendo, |
1425 |
exchangerate => $exchangerate3->sell, |
|
1392 | 1426 |
); |
1393 | 1427 |
$invoice->pay_invoice(chart_id => $bank->id, |
1394 |
amount => 10.00, |
|
1428 |
amount => 10.00 * $exchangerate4->sell,
|
|
1395 | 1429 |
currency => 'CUR', |
1396 | 1430 |
transdate => $transdate4->to_kivitendo, |
1431 |
exchangerate => $exchangerate4->sell, |
|
1397 | 1432 |
); |
1398 | 1433 |
# $invoice->pay_invoice(chart_id => $bank->id, |
1399 | 1434 |
# amount => 30, |
1400 | 1435 |
# transdate => $transdate2->to_kivitendo, |
1401 | 1436 |
# ); |
1402 |
my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id')); |
|
1403 |
is(scalar @{$fx_transactions}, 3, "$title: ar transaction has 3 fx transactions"); |
|
1404 |
is($fx_transactions->[0]->amount, '24.69000', "$title fx transactions 1: 123.45-(123.45*0.8) = 24.69"); |
|
1437 |
my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 0 ], sort_by => ('acc_trans_id')); |
|
1438 |
is(scalar @{$fx_transactions}, 11, "$title: ar transaction has 11 transaction"); |
|
1405 | 1439 |
|
1406 |
is(scalar @{$invoice->transactions}, 14, "$title ar transaction has 14 transactions (incl. fxtransactions and fx_gain)"); |
|
1407 | 1440 |
is($invoice->paid, $invoice->amount, "$title ar transaction paid = amount in default currency"); |
1408 | 1441 |
}; |
1409 | 1442 |
|
... | ... | |
1442 | 1475 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_chart->id, trans_id => $invoice->id)->amount, '119.00000', $ar_chart->accno . ': has been converted for currency'); |
1443 | 1476 |
|
1444 | 1477 |
$invoice->pay_invoice(chart_id => $bank->id, |
1445 |
amount => -123.45, |
|
1478 |
amount => -123.45 * $exchangerate2->sell,
|
|
1446 | 1479 |
currency => 'CUR', |
1447 | 1480 |
transdate => $transdate2->to_kivitendo, |
1481 |
exchangerate => $exchangerate2->sell, |
|
1448 | 1482 |
); |
1449 | 1483 |
$invoice->pay_invoice(chart_id => $bank->id, |
1450 |
amount => -25.30, |
|
1484 |
amount => -25.30 * $exchangerate2->sell,
|
|
1451 | 1485 |
currency => 'CUR', |
1452 | 1486 |
transdate => $transdate2->to_kivitendo, |
1487 |
exchangerate => $exchangerate2->sell, |
|
1453 | 1488 |
); |
1454 |
my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id')); |
|
1455 |
is(scalar @{$fx_transactions}, 2, 'ar transaction has 2 fx transactions'); |
|
1456 |
is($fx_transactions->[0]->amount, '-24.69000', 'fx transactions 1: 123.45-(123.45*0.8) = 24.69'); |
|
1489 |
#my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
|
|
1490 |
#is(scalar @{$fx_transactions}, 2, 'ar transaction has 2 fx transactions');
|
|
1491 |
#is($fx_transactions->[0]->amount, '-24.69000', 'fx transactions 1: 123.45-(123.45*0.8) = 24.69');
|
|
1457 | 1492 |
|
1458 |
is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions (incl. fxtransactions)');
|
|
1493 |
is(scalar @{$invoice->transactions}, 7, 'ar transaction has 7 transactions (no fxtransactions)');
|
|
1459 | 1494 |
is($invoice->paid, $invoice->amount, 'ar transaction paid = amount in default currency'); |
1460 | 1495 |
}; |
1461 | 1496 |
|
... | ... | |
1494 | 1529 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_chart->id, trans_id => $invoice->id)->amount, '119.00000', $ap_chart->accno . ': has been converted for currency'); |
1495 | 1530 |
|
1496 | 1531 |
$invoice->pay_invoice(chart_id => $bank->id, |
1497 |
amount => 10, |
|
1532 |
amount => 10 * $exchangerate2->sell,
|
|
1498 | 1533 |
currency => 'CUR', |
1499 | 1534 |
transdate => $transdate2->to_kivitendo, |
1535 |
exchangerate => $exchangerate2->sell, |
|
1500 | 1536 |
); |
1501 | 1537 |
$invoice->pay_invoice(chart_id => $bank->id, |
1502 |
amount => 123.45, |
|
1538 |
amount => 123.45 * $exchangerate3->sell,
|
|
1503 | 1539 |
currency => 'CUR', |
1504 | 1540 |
transdate => $transdate3->to_kivitendo, |
1541 |
exchangerate => $exchangerate3->sell, |
|
1505 | 1542 |
); |
1506 | 1543 |
$invoice->pay_invoice(chart_id => $bank->id, |
1507 |
amount => 15.30, |
|
1544 |
amount => 15.30 * $exchangerate4->sell,
|
|
1508 | 1545 |
currency => 'CUR', |
1509 | 1546 |
transdate => $transdate4->to_kivitendo, |
1547 |
exchangerate => $exchangerate4->sell, |
|
1510 | 1548 |
); |
1511 |
my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id')); |
|
1512 |
is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions"); |
|
1513 |
is($fx_transactions->[0]->amount, '-2.00000', "$title: fx transaction 1: 10.00-( 10.00*0.80000) = 2.00000"); |
|
1514 |
is($fx_transactions->[1]->amount, '68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511"); |
|
1515 |
is($fx_transactions->[2]->amount, '-3.40000', "$title: fx transaction 3: 15.30-(15.30 *0.77777) = 3.40012"); |
|
1549 |
#my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
|
|
1550 |
#is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions");
|
|
1551 |
#is($fx_transactions->[0]->amount, '-2.00000', "$title: fx transaction 1: 10.00-( 10.00*0.80000) = 2.00000");
|
|
1552 |
#is($fx_transactions->[1]->amount, '68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511");
|
|
1553 |
#is($fx_transactions->[2]->amount, '-3.40000', "$title: fx transaction 3: 15.30-(15.30 *0.77777) = 3.40012");
|
|
1516 | 1554 |
|
1517 | 1555 |
my $fx_loss_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, chart_id => $fxloss_chart->id ], sort_by => ('acc_trans_id')); |
1518 | 1556 |
my $fx_gain_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, chart_id => $fxgain_chart->id ], sort_by => ('acc_trans_id')); |
1519 | 1557 |
is($fx_gain_transactions->[0]->amount, '0.34000', "$title: fx gain amount ok"); |
1520 | 1558 |
is($fx_loss_transactions->[0]->amount, '-93.28000', "$title: fx loss amount ok"); |
1521 | 1559 |
|
1522 |
is(scalar @{$invoice->transactions}, 14, "$title: ap transaction has 14 transactions (incl. fxtransactions and gain_loss)");
|
|
1560 |
is(scalar @{$invoice->transactions}, 11, "$title: ap transaction has 11 transactions (no fxtransactions and gain_loss)");
|
|
1523 | 1561 |
is($invoice->paid, $invoice->amount, "$title: ap transaction paid = amount in default currency"); |
1524 | 1562 |
is(total_amount($invoice), 0, "$title: even balance"); |
1525 | 1563 |
}; |
... | ... | |
1527 | 1565 |
sub test_ap_currency_tax_not_included_and_payment_2_credit_note { |
1528 | 1566 |
my $title = 'test_ap_currency_tax_not_included_and_payment_2_credit_note'; |
1529 | 1567 |
|
1530 |
my $netamount = $::form->round_amount(-125 * $exchangerate2->sell,2); # 125.00 in CUR, 100.00 in EUR
|
|
1568 |
my $netamount = $::form->round_amount(-125 * $exchangerate2->buy, 2); # 125.00 in CUR, 100.00 in EUR
|
|
1531 | 1569 |
my $amount = $::form->round_amount($netamount * 1.19,2); # 148.75 in CUR, 119.00 in EUR |
1532 | 1570 |
my $invoice = SL::DB::PurchaseInvoice->new( |
1533 | 1571 |
invoice => 0, |
... | ... | |
1559 | 1597 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_chart->id, trans_id => $invoice->id)->amount, '-119.00000', $ap_chart->accno . ': has been converted for currency'); |
1560 | 1598 |
|
1561 | 1599 |
$invoice->pay_invoice(chart_id => $bank->id, |
1562 |
amount => -10, |
|
1600 |
amount => -10 * $exchangerate2->buy,
|
|
1563 | 1601 |
currency => 'CUR', |
1564 | 1602 |
transdate => $transdate2->to_kivitendo, |
1603 |
exchangerate => $exchangerate2->buy, |
|
1565 | 1604 |
); |
1566 | 1605 |
$invoice->pay_invoice(chart_id => $bank->id, |
1567 |
amount => -123.45, |
|
1606 |
amount => -123.45 * $exchangerate3->buy,
|
|
1568 | 1607 |
currency => 'CUR', |
1569 | 1608 |
transdate => $transdate3->to_kivitendo, |
1609 |
exchangerate => $exchangerate3->buy, |
|
1570 | 1610 |
); |
1571 | 1611 |
$invoice->pay_invoice(chart_id => $bank->id, |
1572 |
amount => -15.30, |
|
1612 |
amount => -15.30 * $exchangerate4->buy,
|
|
1573 | 1613 |
currency => 'CUR', |
1574 | 1614 |
transdate => $transdate4->to_kivitendo, |
1615 |
exchangerate => $exchangerate4->buy, |
|
1575 | 1616 |
); |
1576 |
my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id')); |
|
1577 |
is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions"); |
|
1578 |
is($fx_transactions->[0]->amount, '2.00000', "$title: fx transaction 1: 10.00-( 10.00*0.80000) = 2.00000"); |
|
1579 |
is($fx_transactions->[1]->amount, '-68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511"); |
|
1580 |
is($fx_transactions->[2]->amount, '3.40000', "$title: fx transaction 3: 15.30-(15.30 *0.77777) = 3.40012"); |
|
1617 |
#my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
|
|
1618 |
#is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions");
|
|
1619 |
#is($fx_transactions->[0]->amount, '2.00000', "$title: fx transaction 1: 10.00-( 10.00*0.80000) = 2.00000");
|
|
1620 |
#is($fx_transactions->[1]->amount, '-68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511");
|
|
1621 |
#is($fx_transactions->[2]->amount, '3.40000', "$title: fx transaction 3: 15.30-(15.30 *0.77777) = 3.40012");
|
|
1581 | 1622 |
|
1582 | 1623 |
my $fx_gain_loss_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, chart_id => $fxgain_chart->id ], sort_by => ('acc_trans_id')); |
1583 | 1624 |
is($fx_gain_loss_transactions->[0]->amount, '93.28000', "$title: fx gain loss amount ok"); |
1584 | 1625 |
|
1585 |
is(scalar @{$invoice->transactions}, 14, "$title: ap transaction has 14 transactions (incl. fxtransactions and gain_loss)");
|
|
1626 |
is(scalar @{$invoice->transactions}, 11, "$title: ap transaction has 11 transactions (no fxtransactions and gain_loss)");
|
|
1586 | 1627 |
is($invoice->paid, $invoice->amount, "$title: ap transaction paid = amount in default currency"); |
1587 | 1628 |
is(total_amount($invoice), 0, "$title: even balance"); |
1588 | 1629 |
}; |
Auch abrufbar als: Unified diff
Testfälle für payment angepasst