Revision 58d7ffe9
Von Jan Büren vor mehr als 2 Jahren hinzugefügt
| t/db_helper/payment.t | ||
|---|---|---|
| use strict;
 | ||
| use Test::More tests => 203;
 | ||
| use Test::More tests => 255;
 | ||
|  | ||
| use strict;
 | ||
|  | ||
| ... | ... | |
| Support::TestSetup::login();
 | ||
|  | ||
| init_state();
 | ||
|  | ||
| # test cases: without_skonto
 | ||
| test_default_invoice_one_item_19_without_skonto();
 | ||
| test_default_invoice_two_items_19_7_tax_with_skonto();
 | ||
| ... | ... | |
|     payment_id   => $payment_terms->id,
 | ||
|   );
 | ||
|  | ||
|   my $ap_transaction = new_ap_transaction();
 | ||
|  | ||
|   # default values
 | ||
|   my %params = ( chart_id => $bank_account->chart_id,
 | ||
|                  transdate => $transdate1,
 | ||
| ... | ... | |
|   $params{amount} = '6.96';
 | ||
|   $params{payment_type} = 'without_skonto';
 | ||
|  | ||
|   $invoice->pay_invoice( %params );
 | ||
|  | ||
|   my @ret = $invoice->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
|  | ||
|   my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($invoice->netamount,   5.85,      "${title}: netamount");
 | ||
|   is($invoice->amount,      6.96,      "${title}: amount");
 | ||
|   is($paid_amount,         -6.96,      "${title}: paid amount");
 | ||
|   is($number_of_payments,      1,      "${title}: 1 AR_paid booking");
 | ||
|   is($invoice->paid,        6.96,      "${title}: paid");
 | ||
|   is($total,                   0,      "${title}: even balance");
 | ||
|  | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|   is($invoice->paid,  $bank_amount->{return_bank_amount},      "${title}: paid eq invoice_amount");
 | ||
| }
 | ||
|  | ||
| sub test_default_invoice_one_item_19_without_skonto_overpaid {
 | ||
| ... | ... | |
|  | ||
|   $params{amount} = '16.96';
 | ||
|   $params{payment_type} = 'without_skonto';
 | ||
|   $invoice->pay_invoice( %params );
 | ||
|   my @ret = $invoice->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|  | ||
|   my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($exp_invoice_amount > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|   my $bt_invoice_amount = $exp_invoice_amount;
 | ||
|  | ||
|   $params{amount} = -10.00;
 | ||
|   @ret = $invoice->pay_invoice( %params );
 | ||
|  | ||
|   $bank_amount = shift @ret;
 | ||
|   $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($exp_invoice_amount < 0,  1,     "${title}: bank invoice_amount is negative");
 | ||
|   $bt_invoice_amount += $exp_invoice_amount;
 | ||
|  | ||
|   $params{amount} = '-10.00';
 | ||
|   $invoice->pay_invoice( %params );
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|   is($number_of_payments,      2,      "${title}: 1 AR_paid booking");
 | ||
|   is($invoice->paid,        6.96,      "${title}: paid");
 | ||
|   is($total,                   0,      "${title}: even balance");
 | ||
|   is($invoice->paid,        $bt_invoice_amount,      "${title}: invoice paid equals bt invoice_amount");
 | ||
|  | ||
| }
 | ||
|  | ||
| ... | ... | |
|   $params{payment_type} = 'with_skonto_pt';
 | ||
|   $params{amount}       = $invoice->amount_less_skonto;
 | ||
|  | ||
|   $invoice->pay_invoice( %params );
 | ||
|   my @ret = $invoice->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|   $params{payment_type} = 'with_skonto_pt';
 | ||
|   $params{amount}       = $invoice->amount_less_skonto;
 | ||
|  | ||
|   $invoice->pay_invoice( %params );
 | ||
|   my @ret = $invoice->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|   is($paid_amount,               -17.51,   "${title}: paid amount");
 | ||
|   is($invoice->paid,              17.51,   "${title}: paid");
 | ||
|   is($number_of_payments,             3,   "${title}: 3 AR_paid bookings");
 | ||
|   is($invoice->paid != $bank_amount->{return_bank_amount},   1,   "${title}: paid does not equal bank invoice_amount");
 | ||
|  | ||
| TODO: {
 | ||
|   local $TODO = "currently this test fails because the code writing the invoice is buggy, the calculation of skonto is correct";
 | ||
| ... | ... | |
|   $params{amount} = '19.44'; # pass full amount
 | ||
|   $params{payment_type} = 'without_skonto';
 | ||
|  | ||
|   $invoice->pay_invoice( %params );
 | ||
|   my @ret = $invoice->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|   is($invoice->paid,                 19.44,     "${title}: paid");
 | ||
|   is($number_of_payments,                1,     "${title}: 1 AR_paid bookings");
 | ||
|   is($total,                             0,     "${title}: even balance");
 | ||
|   is($invoice->paid,  $bank_amount->{return_bank_amount},  "${title}: paid equals bt.invoice_amount");
 | ||
| }
 | ||
|  | ||
| # test 4
 | ||
| ... | ... | |
|     payment_id   => $payment_terms->id,
 | ||
|   );
 | ||
|  | ||
|   $invoice->pay_invoice( amount       => '9.44',
 | ||
|                          payment_type => 'without_skonto',
 | ||
|                          chart_id     => $bank_account->chart_id,
 | ||
|                          transdate    => $transdate1,
 | ||
|                        );
 | ||
|   my @ret = $invoice->pay_invoice( amount       => '9.44',
 | ||
|                                    payment_type => 'without_skonto',
 | ||
|                                    chart_id     => $bank_account->chart_id,
 | ||
|                                    transdate    => $transdate1,
 | ||
|                                  );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $exp_invoice_amount = $invoice->amount > 0 ? 9.44 : 9.44 * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|   is($invoice->paid,             9.44,            "${title}: paid");
 | ||
|   is($number_of_payments,   1,                "${title}: 1 AR_paid bookings");
 | ||
|   is($total,                    0,                "${title}: even balance");
 | ||
|   is($invoice->paid,  $bank_amount->{return_bank_amount},  "${title}: paid equals bt.invoice_amount");
 | ||
| }
 | ||
|  | ||
| # test 5
 | ||
| ... | ... | |
|     invoiceitems => [ $item1, $item2 ],
 | ||
|     payment_id   => $payment_terms->id,
 | ||
|   );
 | ||
|  | ||
|   $invoice->pay_invoice( amount       => '9.44',
 | ||
|                          payment_type => 'without_skonto',
 | ||
|                          chart_id     => $bank_account->chart_id,
 | ||
|                          transdate    => $transdate1,
 | ||
|   my @ret;
 | ||
|   @ret = $invoice->pay_invoice( amount       => '9.44',
 | ||
|                                 payment_type => 'without_skonto',
 | ||
|                                 chart_id     => $bank_account->chart_id,
 | ||
|                                 transdate    => $transdate1,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice( amount       => '10.00',
 | ||
|                          chart_id     => $bank_account->chart_id,
 | ||
|                          transdate    => $transdate1,
 | ||
|  | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $exp_invoice_amount = $invoice->amount > 0 ? 9.44 : 9.44 * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|   my $bank_invoice_amount = $bank_amount->{return_bank_amount};
 | ||
|  | ||
|   @ret = $invoice->pay_invoice( amount       => '10.00',
 | ||
|                                chart_id     => $bank_account->chart_id,
 | ||
|                                transdate    => $transdate1,
 | ||
|                        );
 | ||
|   $bank_amount = shift @ret;
 | ||
|   $exp_invoice_amount = $invoice->amount > 0 ? 10 : 10 * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|   $bank_invoice_amount += $bank_amount->{return_bank_amount};
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|   is($invoice->paid,                    19.44,     "${title}: paid");
 | ||
|   is($number_of_payments,                   2,     "${title}: 2 AR_paid bookings");
 | ||
|   is($total,                                0,     "${title}: even balance");
 | ||
|   is($invoice->paid,   $bank_invoice_amount,       "${title}: paid eq bank invoice_amount");
 | ||
|  | ||
| }
 | ||
|  | ||
| ... | ... | |
|     payment_id   => $payment_terms->id,
 | ||
|   );
 | ||
|  | ||
|   $invoice->pay_invoice( amount       => '9.44',
 | ||
|                          payment_type => 'without_skonto',
 | ||
|                          chart_id     => $bank_account->chart_id,
 | ||
|                          transdate    => $transdate1,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice( amount       => '8.73',
 | ||
|                          payment_type => 'without_skonto',
 | ||
|                          chart_id     => $bank_account->chart_id,
 | ||
|                          transdate    => $transdate1,
 | ||
|                        );
 | ||
|   my (@ret, $bank_amount, $exp_invoice_amount);
 | ||
|   @ret = $invoice->pay_invoice( amount       => '9.44',
 | ||
|                                 payment_type => 'without_skonto',
 | ||
|                                 chart_id     => $bank_account->chart_id,
 | ||
|                                 transdate    => $transdate1,
 | ||
|                               );
 | ||
|   $bank_amount = shift @ret;
 | ||
|   my $amount = 9.44;
 | ||
|   $exp_invoice_amount = $invoice->amount > 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|  | ||
|   @ret = $invoice->pay_invoice( amount       => '8.73',
 | ||
|                                 payment_type => 'without_skonto',
 | ||
|                                 chart_id     => $bank_account->chart_id,
 | ||
|                                 transdate    => $transdate1,
 | ||
|                               );
 | ||
|   $bank_amount = shift @ret;
 | ||
|   $amount = 8.73;
 | ||
|   $exp_invoice_amount = $invoice->amount > 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|  | ||
|   # free_skonto does:
 | ||
|   #  my $open_amount = $payment_type eq 'with_skonto_pt' ? $invoice->amount_less_skonto : $invoice->open_amount;
 | ||
|   #  $open_amount    = abs($open_amount);
 | ||
|   #  $open_amount   -= $free_skonto_amount if ($payment_type eq 'free_skonto');
 | ||
|  | ||
|   $invoice->pay_invoice( skonto_amount => $invoice->open_amount,
 | ||
|   @ret = $invoice->pay_invoice( skonto_amount => $invoice->open_amount,
 | ||
|                          amount        => 0,
 | ||
|                          payment_type  => 'free_skonto',
 | ||
|                          chart_id      => $bank_account->chart_id,
 | ||
|                          transdate     => $transdate1,
 | ||
|                          bt_id         => $bt->id,
 | ||
|                        );
 | ||
|   $bank_amount = shift @ret;
 | ||
|   $amount = 0;
 | ||
|   $exp_invoice_amount = $invoice->amount < 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|  | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|     payment_id   => $payment_terms->id,
 | ||
|   );
 | ||
|  | ||
|   $invoice->pay_invoice( amount       => '19.42',
 | ||
|                          payment_type => 'without_skonto',
 | ||
|                          chart_id     => $bank_account->chart_id,
 | ||
|                          transdate    => $transdate1,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice( skonto_amount => $invoice->open_amount,
 | ||
|                          amount       => 0,
 | ||
|                          payment_type => 'free_skonto',
 | ||
|                          chart_id     => $bank_account->chart_id,
 | ||
|                          transdate    => $transdate1,
 | ||
|                          bt_id        => $bt->id,
 | ||
|                        );
 | ||
|   my (@ret, $bank_amount, $exp_invoice_amount);
 | ||
|   @ret = $invoice->pay_invoice( amount       => '19.42',
 | ||
|                                 payment_type => 'without_skonto',
 | ||
|                                 chart_id     => $bank_account->chart_id,
 | ||
|                                 transdate    => $transdate1,
 | ||
|                               );
 | ||
|   $bank_amount        = shift @ret;
 | ||
|   my $amount          = 19.42;
 | ||
|   $exp_invoice_amount = $invoice->amount > 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|  | ||
|   @ret = $invoice->pay_invoice( skonto_amount => $invoice->open_amount,
 | ||
|                                 amount       => 0,
 | ||
|                                 payment_type => 'free_skonto',
 | ||
|                                 chart_id     => $bank_account->chart_id,
 | ||
|                                 transdate    => $transdate1,
 | ||
|                                 bt_id        => $bt->id,
 | ||
|                               );
 | ||
|   $bank_amount        = shift @ret;
 | ||
|   $amount             = 0;
 | ||
|   $exp_invoice_amount = $invoice->amount < 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
|  | ||
| ... | ... | |
|     payment_id   => $payment_terms->id,
 | ||
|   );
 | ||
|  | ||
|   $invoice->pay_invoice( amount       => '19.42',
 | ||
|   my (@ret, $bank_amount, $exp_invoice_amount);
 | ||
|   @ret = $invoice->pay_invoice( amount       => '19.42',
 | ||
|                          payment_type => 'without_skonto',
 | ||
|                          chart_id     => $bank_account->chart_id,
 | ||
|                          transdate    => $transdate1,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice( skonto_amount => $invoice->open_amount,
 | ||
|   $bank_amount = shift @ret;
 | ||
|   my $amount = 19.42;
 | ||
|   $exp_invoice_amount = $invoice->amount > 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|  | ||
|   @ret = $invoice->pay_invoice( skonto_amount => $invoice->open_amount,
 | ||
|                          amount       => 0,
 | ||
|                          payment_type => 'free_skonto',
 | ||
|                          chart_id     => $bank_account->chart_id,
 | ||
|                          transdate    => $transdate1,
 | ||
|                          bt_id        => $bt->id,
 | ||
|                        );
 | ||
|   $bank_amount = shift @ret;
 | ||
|   $amount = 0;
 | ||
|   $exp_invoice_amount = $invoice->amount > 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} == 0,  1,     "${title}: bank invoice_amount is zero");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|  | ||
|   $params{amount}       = '2.32';
 | ||
|   $params{payment_type} = 'without_skonto';
 | ||
|   $invoice->pay_invoice( %params );
 | ||
|   my @ret = $invoice->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|  | ||
|  | ||
|   $params{amount}       = '3.81';
 | ||
|   $params{payment_type} = 'without_skonto';
 | ||
|   $invoice->pay_invoice( %params );
 | ||
|   @ret = $invoice->pay_invoice( %params );
 | ||
|   $bank_amount = shift @ret;
 | ||
|   $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|  | ||
|  | ||
|  | ||
|   $params{skonto_amount} = $invoice->open_amount; # set amount, otherwise previous 3.81 is used
 | ||
|   $params{amount}        = 0,
 | ||
|   $params{payment_type}  = 'free_skonto';
 | ||
|   $invoice->pay_invoice( %params );
 | ||
|   @ret = $invoice->pay_invoice( %params );
 | ||
|   $bank_amount = shift @ret;
 | ||
|   $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} == 0,  1,     "${title}: bank invoice_amount is zero");
 | ||
|  | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|  | ||
|   $params{amount}       = '6.95';
 | ||
|   $params{payment_type} = 'without_skonto';
 | ||
|   $invoice->pay_invoice( %params );
 | ||
|   my @ret = $invoice->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0,  1,     "${title}: bank invoice_amount is positive");
 | ||
|  | ||
|   $params{skonto_amount} = $invoice->open_amount;
 | ||
|   $params{amount}        = 0,
 | ||
|   $params{payment_type} = 'free_skonto';
 | ||
|   $invoice->pay_invoice( %params );
 | ||
|   @ret = $invoice->pay_invoice( %params );
 | ||
|   $bank_amount = shift @ret;
 | ||
|   $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|  | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|  | ||
| # test 3 : two items, without skonto
 | ||
| sub test_default_ap_transaction_two_charts_19_7_without_skonto {
 | ||
|   my $title = 'default invoice, two items, 19/7% tax without skonto';
 | ||
|   my $title = 'default ap_transaction, two items, 19/7% tax without skonto';
 | ||
|  | ||
|   my $ap_transaction = new_ap_transaction();
 | ||
|  | ||
| ... | ... | |
|                  transdate => $transdate1,
 | ||
|                );
 | ||
|  | ||
|   $params{amount} = '226'; # pass full amount
 | ||
|   $params{amount} = 226; # pass full amount
 | ||
|   $params{payment_type} = 'without_skonto';
 | ||
|  | ||
|   $ap_transaction->pay_invoice( %params );
 | ||
|   my @ret = $ap_transaction->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $exp_invoice_amount = $ap_transaction->amount < 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} < 0,  1,     "${title}: bank invoice_amount is negative");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction);
 | ||
|   my $total = total_amount($ap_transaction);
 | ||
|  | ||
|   is($paid_amount,         226,     "${title}: paid amount");
 | ||
|   is($number_of_payments,    1,     "${title}: 1 AP_paid bookings");
 | ||
|   is($total,                 0,     "${title}: even balance");
 | ||
|   is($paid_amount,            226,     "${title}: paid amount");
 | ||
|   is($ap_transaction->paid,   226,     "${title}: ap.paid amount");
 | ||
|   is($number_of_payments,       1,     "${title}: 1 AP_paid bookings");
 | ||
|   is($total,                    0,     "${title}: even balance");
 | ||
|  | ||
| }
 | ||
|  | ||
| ... | ... | |
|   $params{amount}       = $ap_transaction->amount_less_skonto; # pass calculated skonto amount
 | ||
|   $params{payment_type} = 'with_skonto_pt';
 | ||
|  | ||
|   $ap_transaction->pay_invoice( %params );
 | ||
|   my @ret = $ap_transaction->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $exp_invoice_amount = $ap_transaction->amount < 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} < 0,  1,     "${title}: bank invoice_amount is negative");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction);
 | ||
|   my $total = total_amount($ap_transaction);
 | ||
|  | ||
|   is($paid_amount,         226,     "${title}: paid amount");
 | ||
|   is($number_of_payments,    3,     "${title}: 1 AP_paid bookings");
 | ||
|   is($total,                 0,     "${title}: even balance");
 | ||
|   is($paid_amount,                  226,     "${title}: paid amount");
 | ||
|   is($ap_transaction->paid,         226,     "${title}: paid amount");
 | ||
|   is($number_of_payments,             3,     "${title}: 1 AP_paid bookings");
 | ||
|   is($total,                          0,     "${title}: even balance");
 | ||
|  | ||
| }
 | ||
|  | ||
| ... | ... | |
|  | ||
|   # check whether unrounded amounts passed via $params{amount} are rounded for without_skonto case
 | ||
|   my $ap_transaction = new_ap_transaction();
 | ||
|   $ap_transaction->pay_invoice(
 | ||
|                           amount       => ( $ap_transaction->amount / 3 * 2),
 | ||
|                           payment_type => 'without_skonto',
 | ||
|                           chart_id     => $bank_account->chart_id,
 | ||
|                           transdate    => $transdate1,
 | ||
|                          );
 | ||
|   my @ret = $ap_transaction->pay_invoice(
 | ||
|                                          amount       => ( $ap_transaction->amount / 3 * 2),
 | ||
|                                          payment_type => 'without_skonto',
 | ||
|                                          chart_id     => $bank_account->chart_id,
 | ||
|                                          transdate    => $transdate1,
 | ||
|                                         );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $amount      = $::form->round_amount( $ap_transaction->amount / 3 * 2, 2);
 | ||
|   my $exp_invoice_amount = $ap_transaction->amount < 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} < 0,  1,     "${title}: bank invoice_amount is negative");
 | ||
|  | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction);
 | ||
|   my $total = total_amount($ap_transaction);
 | ||
|  | ||
|   is($paid_amount,         150.67,   "${title}: paid amount");
 | ||
|   is($number_of_payments,       1,   "${title}: 1 AP_paid bookings");
 | ||
|   is($total,                    0,   "${title}: even balance");
 | ||
|   is($paid_amount,                  150.67,   "${title}: paid amount");
 | ||
|   is($ap_transaction->paid,         150.67,   "${title}: paid amount");
 | ||
|   is($number_of_payments,                1,   "${title}: 1 AP_paid bookings");
 | ||
|   is($total,                             0,   "${title}: even balance");
 | ||
| };
 | ||
|  | ||
|  | ||
| ... | ... | |
|   my $ap_transaction = new_ap_transaction();
 | ||
|  | ||
|   # pay 2/3 and 1/5, leaves 3.83% to be used as Skonto
 | ||
|   $ap_transaction->pay_invoice(
 | ||
|   my @ret = $ap_transaction->pay_invoice(
 | ||
|                           amount       => ( $ap_transaction->amount / 3 * 2),
 | ||
|                           payment_type => 'without_skonto',
 | ||
|                           chart_id     => $bank_account->chart_id,
 | ||
|                           transdate    => $transdate1,
 | ||
|                          );
 | ||
|   $ap_transaction->pay_invoice(
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $amount      = $::form->round_amount( $ap_transaction->amount / 3 * 2, 2);
 | ||
|   my $exp_invoice_amount = $ap_transaction->amount < 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} < 0,  1,     "${title}: bank invoice_amount is negative");
 | ||
|  | ||
|   @ret = $ap_transaction->pay_invoice(
 | ||
|                           amount       => ( $ap_transaction->amount / 5 ),
 | ||
|                           payment_type => 'without_skonto',
 | ||
|                           chart_id     => $bank_account->chart_id,
 | ||
|                           transdate    => $transdate1,
 | ||
|                          );
 | ||
|   $ap_transaction->pay_invoice(
 | ||
|   $bank_amount = shift @ret;
 | ||
|   $amount      =  $ap_transaction->amount / 5;
 | ||
|   $exp_invoice_amount = $ap_transaction->amount < 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} < 0, 1,     "${title}: invoice_amount negative");
 | ||
|  | ||
|   @ret = $ap_transaction->pay_invoice(
 | ||
|                           payment_type => 'free_skonto',
 | ||
|                           skonto_amount => $ap_transaction->open_amount,
 | ||
|                           amount       => 0,
 | ||
| ... | ... | |
|                           transdate    => $transdate1,
 | ||
|                           bt_id        => $bt->id,
 | ||
|                          );
 | ||
|   $bank_amount = shift @ret;
 | ||
|   $amount      = 0;
 | ||
|   $exp_invoice_amount = $ap_transaction->amount < 0 ? $amount : $amount * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($ap_transaction);
 | ||
|   my $total = total_amount($ap_transaction);
 | ||
|  | ||
|   is($paid_amount,         226, "${title}: paid amount");
 | ||
|   is($number_of_payments,    4, "${title}: 4 AP_paid bookings");
 | ||
|   is($total,                 0, "${title}: even balance");
 | ||
|   is($paid_amount,                  226, "${title}: paid amount");
 | ||
|   is($ap_transaction->paid,         226, "${title}: ap.paid amount");
 | ||
|   is($number_of_payments,             4, "${title}: 4 AP_paid bookings");
 | ||
|   is($total,                          0, "${title}: even balance");
 | ||
|  | ||
| }
 | ||
|  | ||
| ... | ... | |
|   $params{amount} = $invoice->amount_less_skonto;
 | ||
|   $params{payment_type} = 'with_skonto_pt';
 | ||
|  | ||
|   $invoice->pay_invoice( %params );
 | ||
|   my @ret = $invoice->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|   my $exp_invoice_amount = $invoice->amount > 0 ? $params{amount} : $params{amount} * -1;
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} > 0, 1,     "${title}: invoice_amount positive");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
| ... | ... | |
|   my $title = 'test_ar_currency_tax_not_included_and_payment_2';
 | ||
|  | ||
|   my $netamount = $::form->round_amount(75 * $exchangerate->sell,2); #  75 in CUR, 100.00 in EUR
 | ||
|   my $amount    = $::form->round_amount($netamount * 1.19,2);        # 100 in CUR, 119.00 in EUR
 | ||
|   my $amount    = $::form->round_amount($netamount * 1.19,2);        # 100 in EUR, 119.00 in EUR incl. tax
 | ||
|   my $invoice   = SL::DB::Invoice->new(
 | ||
|       invoice      => 0,
 | ||
|       amount       => $amount,
 | ||
| ... | ... | |
|   is($invoice->taxincluded ,   0           , 'ar transaction doesn\'t have taxincluded');
 | ||
|   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');
 | ||
|   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');
 | ||
|  | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 50,
 | ||
|                         amount     => 50,     # amount is in default currency -> should be 37.5 in CUR
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate1->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate->sell,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 39.25,
 | ||
|                         amount     => 39.25,  # amount is in default currency -> should be 29.44 in CUR
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate1->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate->sell,
 | ||
|                        );
 | ||
|   # $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|   #                       amount     => 30,
 | ||
|   #                       transdate  => $transdate2->to_kivitendo,
 | ||
|   #                      );
 | ||
|   is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions (incl. fxtransactions)');
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 29.75,
 | ||
|                         transdate  => $transdate1->to_kivitendo,
 | ||
|                         currency   => 'CUR',
 | ||
|                         exchangerate => $exchangerate->sell,
 | ||
|                         );
 | ||
|   is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions');
 | ||
|   is($invoice->paid, $invoice->amount, 'ar transaction paid = amount in default currency');
 | ||
| };
 | ||
| }
 | ||
|  | ||
| sub test_ar_currency_tax_included {
 | ||
|   my $title = 'test_ar_currency_tax_included';
 | ||
| ... | ... | |
|                         amount     => 89.25,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate1->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate->sell,
 | ||
|                        );
 | ||
|  | ||
| };
 | ||
| ... | ... | |
|                         amount     => 50,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate1->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate->buy,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 39.25,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate1->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate->buy,
 | ||
|                        );
 | ||
|   is($invoice->paid, 89.25, 'ap transaction paid = amount in default currency');
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 22.31 * $exchangerate2->buy,  # 22.31 in fx currency
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate2->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate2->buy,
 | ||
|                        );
 | ||
|   is(scalar @{$invoice->transactions}, 9, 'ap transaction has 9 transactions (incl. fxtransactions)');
 | ||
|  | ||
|   is(scalar @{$invoice->transactions}, 10, 'ap transaction has 10 transactions (including fx gain transaction)');
 | ||
|   is($invoice->paid, $invoice->amount, 'ap transaction paid = amount in default currency');
 | ||
| };
 | ||
|  | ||
|   # check last booking fx rate decreased to 0.8 from 1.33333
 | ||
|   my $fxgain_chart         = SL::DB::Manager::Chart->find_by(accno => '2660') or die "Can't find fxgain_chart in test";
 | ||
|   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'));
 | ||
|  | ||
|   is($fx_gain_transactions->[0]->amount,   '11.90000', "fx gain amount ok");
 | ||
|  | ||
|   # check last bank transaction should be 22.31 * 0.8
 | ||
|   my $last_bank_transaction = SL::DB::Manager::AccTransaction->get_all(where =>
 | ||
|                                 [ trans_id => $invoice->id, chart_id => $bank->id, transdate => $transdate2 ],
 | ||
|                                   sort_by => ('acc_trans_id'));
 | ||
|  | ||
|   is($last_bank_transaction->[0]->amount, '17.85000', "fx bank amount with fx gain ok");
 | ||
|  | ||
|  | ||
|  | ||
| }
 | ||
|  | ||
| sub test_ap_currency_tax_included {
 | ||
|   my $title = 'test_ap_currency_tax_included';
 | ||
| ... | ... | |
|                         amount     => 89.25,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate1->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate->sell,
 | ||
|                        );
 | ||
|  | ||
| };
 | ||
| ... | ... | |
|   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');
 | ||
|  | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 123.45,
 | ||
|                         amount     => 123.45 * $exchangerate2->sell,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate2->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate2->sell,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 15.30,
 | ||
|                         amount     => 15.30 * $exchangerate3->sell,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate3->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate3->sell,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 10.00,
 | ||
|                         amount     => 10.00 * $exchangerate4->sell,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate4->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate4->sell,
 | ||
|                        );
 | ||
|   # $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|   #                       amount     => 30,
 | ||
|   #                       transdate  => $transdate2->to_kivitendo,
 | ||
|   #                      );
 | ||
|   my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
 | ||
|   is(scalar @{$fx_transactions}, 3, "$title: ar transaction has 3 fx transactions");
 | ||
|   is($fx_transactions->[0]->amount, '24.69000', "$title fx transactions 1: 123.45-(123.45*0.8) = 24.69");
 | ||
|   my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 0 ], sort_by => ('acc_trans_id'));
 | ||
|   is(scalar @{$fx_transactions}, 11, "$title: ar transaction has 11 transaction");
 | ||
|  | ||
|   is(scalar @{$invoice->transactions}, 14, "$title ar transaction has 14 transactions (incl. fxtransactions and fx_gain)");
 | ||
|   is($invoice->paid, $invoice->amount, "$title ar transaction paid = amount in default currency");
 | ||
| };
 | ||
|  | ||
| ... | ... | |
|   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');
 | ||
|  | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => -123.45,
 | ||
|                         amount     => -123.45 * $exchangerate2->sell,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate2->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate2->sell,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => -25.30,
 | ||
|                         amount     => -25.30 * $exchangerate2->sell,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate2->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate2->sell,
 | ||
|                        );
 | ||
|   my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
 | ||
|   is(scalar @{$fx_transactions}, 2, 'ar transaction has 2 fx transactions');
 | ||
|   is($fx_transactions->[0]->amount, '-24.69000', 'fx transactions 1: 123.45-(123.45*0.8) = 24.69');
 | ||
|   #my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
 | ||
|   #is(scalar @{$fx_transactions}, 2, 'ar transaction has 2 fx transactions');
 | ||
|   #is($fx_transactions->[0]->amount, '-24.69000', 'fx transactions 1: 123.45-(123.45*0.8) = 24.69');
 | ||
|  | ||
|   is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions (incl. fxtransactions)');
 | ||
|   is(scalar @{$invoice->transactions}, 7, 'ar transaction has 7 transactions (no fxtransactions)');
 | ||
|   is($invoice->paid, $invoice->amount, 'ar transaction paid = amount in default currency');
 | ||
| };
 | ||
|  | ||
| ... | ... | |
|   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');
 | ||
|  | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 10,
 | ||
|                         amount     => 10 * $exchangerate2->sell,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate2->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate2->sell,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 123.45,
 | ||
|                         amount     => 123.45 * $exchangerate3->sell,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate3->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate3->sell,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => 15.30,
 | ||
|                         amount     => 15.30 * $exchangerate4->sell,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate4->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate4->sell,
 | ||
|                        );
 | ||
|   my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
 | ||
|   is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions");
 | ||
|   is($fx_transactions->[0]->amount,  '-2.00000', "$title: fx transaction 1:  10.00-( 10.00*0.80000) =   2.00000");
 | ||
|   is($fx_transactions->[1]->amount,  '68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511");
 | ||
|   is($fx_transactions->[2]->amount,  '-3.40000', "$title: fx transaction 3:  15.30-(15.30 *0.77777) =   3.40012");
 | ||
|   #my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
 | ||
|   #is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions");
 | ||
|   #is($fx_transactions->[0]->amount,  '-2.00000', "$title: fx transaction 1:  10.00-( 10.00*0.80000) =   2.00000");
 | ||
|   #is($fx_transactions->[1]->amount,  '68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511");
 | ||
|   #is($fx_transactions->[2]->amount,  '-3.40000', "$title: fx transaction 3:  15.30-(15.30 *0.77777) =   3.40012");
 | ||
|  | ||
|   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'));
 | ||
|   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'));
 | ||
|   is($fx_gain_transactions->[0]->amount,   '0.34000', "$title: fx gain amount ok");
 | ||
|   is($fx_loss_transactions->[0]->amount, '-93.28000', "$title: fx loss amount ok");
 | ||
|  | ||
|   is(scalar @{$invoice->transactions}, 14, "$title: ap transaction has 14 transactions (incl. fxtransactions and gain_loss)");
 | ||
|   is(scalar @{$invoice->transactions}, 11, "$title: ap transaction has 11 transactions (no fxtransactions and gain_loss)");
 | ||
|   is($invoice->paid, $invoice->amount, "$title: ap transaction paid = amount in default currency");
 | ||
|   is(total_amount($invoice), 0,   "$title: even balance");
 | ||
| };
 | ||
| ... | ... | |
| sub test_ap_currency_tax_not_included_and_payment_2_credit_note {
 | ||
|   my $title = 'test_ap_currency_tax_not_included_and_payment_2_credit_note';
 | ||
|  | ||
|   my $netamount = $::form->round_amount(-125 * $exchangerate2->sell,2); # 125.00 in CUR, 100.00 in EUR
 | ||
|   my $netamount = $::form->round_amount(-125 * $exchangerate2->buy, 2); # 125.00 in CUR, 100.00 in EUR
 | ||
|   my $amount    = $::form->round_amount($netamount * 1.19,2);          # 148.75 in CUR, 119.00 in EUR
 | ||
|   my $invoice   = SL::DB::PurchaseInvoice->new(
 | ||
|       invoice      => 0,
 | ||
| ... | ... | |
|   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');
 | ||
|  | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => -10,
 | ||
|                         amount     => -10 * $exchangerate2->buy,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate2->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate2->buy,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => -123.45,
 | ||
|                         amount     => -123.45 * $exchangerate3->buy,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate3->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate3->buy,
 | ||
|                        );
 | ||
|   $invoice->pay_invoice(chart_id   => $bank->id,
 | ||
|                         amount     => -15.30,
 | ||
|                         amount     => -15.30 * $exchangerate4->buy,
 | ||
|                         currency   => 'CUR',
 | ||
|                         transdate  => $transdate4->to_kivitendo,
 | ||
|                         exchangerate => $exchangerate4->buy,
 | ||
|                        );
 | ||
|   my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
 | ||
|   is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions");
 | ||
|   is($fx_transactions->[0]->amount,   '2.00000', "$title: fx transaction 1:  10.00-( 10.00*0.80000) =   2.00000");
 | ||
|   is($fx_transactions->[1]->amount, '-68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511");
 | ||
|   is($fx_transactions->[2]->amount,   '3.40000', "$title: fx transaction 3:  15.30-(15.30 *0.77777) =   3.40012");
 | ||
|   #my $fx_transactions = SL::DB::Manager::AccTransaction->get_all(where => [ trans_id => $invoice->id, fx_transaction => 1 ], sort_by => ('acc_trans_id'));
 | ||
|   #is(scalar @{$fx_transactions}, 3, "$title: ap transaction has 3 fx transactions");
 | ||
|   #is($fx_transactions->[0]->amount,   '2.00000', "$title: fx transaction 1:  10.00-( 10.00*0.80000) =   2.00000");
 | ||
|   #is($fx_transactions->[1]->amount, '-68.59000', "$title: fx transaction 2: 123.45-(123.45*1.55557) = -68.58511");
 | ||
|   #is($fx_transactions->[2]->amount,   '3.40000', "$title: fx transaction 3:  15.30-(15.30 *0.77777) =   3.40012");
 | ||
|  | ||
|   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'));
 | ||
|   is($fx_gain_loss_transactions->[0]->amount, '93.28000', "$title: fx gain loss amount ok");
 | ||
|  | ||
|   is(scalar @{$invoice->transactions}, 14, "$title: ap transaction has 14 transactions (incl. fxtransactions and gain_loss)");
 | ||
|   is(scalar @{$invoice->transactions}, 11, "$title: ap transaction has 11 transactions (no fxtransactions and gain_loss)");
 | ||
|   is($invoice->paid, $invoice->amount, "$title: ap transaction paid = amount in default currency");
 | ||
|   is(total_amount($invoice), 0,   "$title: even balance");
 | ||
| };
 | ||
| ... | ... | |
|  | ||
|   $params{amount}       = $invoice->amount,
 | ||
|  | ||
|   $invoice->pay_invoice( %params );
 | ||
|   my @ret = $invoice->pay_invoice( %params );
 | ||
|   my $bank_amount = shift @ret;
 | ||
|  | ||
|   my $exp_invoice_amount =  $params{amount};
 | ||
|   is($bank_amount->{return_bank_amount}, $exp_invoice_amount,      "${title}: invoice_amount");
 | ||
|   is($bank_amount->{return_bank_amount} < 0,  1,     "${title}: bank invoice_amount is negative (credit note)");
 | ||
|  | ||
|   my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
 | ||
|   my $total = total_amount($invoice);
 | ||
Auch abrufbar als: Unified diff
Testfälle für payment angepasst