Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ba68038e

Von Kivitendo Admin vor fast 8 Jahren hinzugefügt

  • ID ba68038e4208fc04ad63cd783c527a15ab845026
  • Vorgänger 72e40323
  • Nachfolger 4291cf9e

Paymenthelper kann Fremdwährung mit Steuer inkl. und exkl.

Unterschiede anzeigen:

SL/DB/Helper/Payment.pm
29 29
  my $is_sales = ref($self) eq 'SL::DB::Invoice';
30 30
  my $mult = $is_sales ? 1 : -1;  # multiplier for getting the right sign depending on ar/ap
31 31

  
32
  my $paid_amount = 0; # the amount that will be later added to $self->paid
32
  my $paid_amount = 0; # the amount that will be later added to $self->paid, should be in default currency
33 33

  
34 34
  # default values if not set
35 35
  $params{payment_type} = 'without_skonto' unless $params{payment_type};
......
38 38
  # check for required parameters
39 39
  Common::check_params(\%params, qw(chart_id transdate));
40 40

  
41
  my $transdate_obj = $::locale->parse_date_to_object($params{transdate});
41
  my $transdate_obj;
42
  if (ref($params{transdate} eq 'DateTime')) {
43
    print "found transdate ref\n"; sleep 2;
44
    $transdate_obj = $params{transdate};
45
  } else {
46
   $transdate_obj = $::locale->parse_date_to_object($params{transdate});
47
  };
42 48
  croak t8('Illegal date') unless ref $transdate_obj;
43 49

  
44 50
  # check for closed period
......
52 58
    croak t8('Cannot post transaction above the maximum future booking date!') if $transdate_obj > DateTime->now->add( days => $::instance_conf->get_max_future_booking_interval );
53 59
  };
54 60

  
61
  # currency is either passed or use the invoice currency if it differs from the default currency
62
  my ($exchangerate,$currency);
63
  if ($params{currency} || $params{currency_id} || $self->currency_id != $::instance_conf->get_currency_id) {
64
    if ($params{currency} || $params{currency_id} ) { # currency was specified
65
      $currency = SL::DB::Manager::Currency->find_by(name => $params{currency}) || SL::DB::Manager::Currency->find_by(id => $params{currency_id});
66
    } else { # use invoice currency
67
      $currency = SL::DB::Manager::Currency->find_by(id => $self->currency_id);
68
    };
69
    die "no currency" unless $currency;
70
    if ($currency->id == $::instance_conf->get_currency_id) {
71
      $exchangerate = 1;
72
    } else {
73
      my $rate = SL::DB::Manager::Exchangerate->find_by(currency_id => $currency->id,
74
                                                        transdate   => $transdate_obj,
75
                                                       );
76
      if ($rate) {
77
        $exchangerate = $is_sales ? $rate->buy : $rate->sell;
78
      } else {
79
        die "No exchange rate for " . $transdate_obj->to_kivitendo;
80
      };
81
    };
82
  } else { # no currency param given or currency is the same as default_currency
83
    $exchangerate = 1;
84
  };
85

  
55 86
  # input checks:
56 87
  if ( $params{'payment_type'} eq 'without_skonto' ) {
57 88
    croak "invalid amount for payment_type 'without_skonto': $params{'amount'}\n" unless abs($params{'amount'}) > 0;
......
83 114
  my $memo   = $params{'memo'}   || '';
84 115
  my $source = $params{'source'} || '';
85 116

  
86
  my $rounded_params_amount = _round( $params{amount} );
117
  my $rounded_params_amount = _round( $params{amount} ); # / $exchangerate);
87 118

  
88 119
  my $db = $self->db;
89 120
  $db->do_transaction(sub {
......
107 138
      $pay_amount = $self->amount_less_skonto if $params{payment_type} eq 'with_skonto_pt';
108 139

  
109 140
      # bank account and AR/AP
110
      $paid_amount += $pay_amount;
141
      $paid_amount += $pay_amount * $exchangerate;
142

  
143
      my $amount = (-1 * $pay_amount) * $mult;
144

  
111 145

  
112 146
      # total amount against bank, do we already know this by now?
113 147
      $new_acc_trans = SL::DB::AccTransaction->new(trans_id   => $self->id,
114 148
                                                   chart_id   => $account_bank->id,
115 149
                                                   chart_link => $account_bank->link,
116
                                                   amount     => (-1 * $pay_amount) * $mult,
150
                                                   amount     => $amount,
117 151
                                                   transdate  => $transdate_obj,
118 152
                                                   source     => $source,
119 153
                                                   memo       => $memo,
120 154
                                                   taxkey     => 0,
121 155
                                                   tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 0)->id);
122 156
      $new_acc_trans->save;
157

  
158
      # deal with fxtransaction
159
      if ( $self->currency_id != $::instance_conf->get_currency_id ) {
160
        my $fxamount = _round($amount - ($amount * $exchangerate));
161
        # print "amount: $amount, fxamount = $fxamount\n";
162
        # print "amount - (amount * exchangerate) = " . $amount . " - (" . $amount . " - " . $exchangerate . ")\n";
163
        $new_acc_trans = SL::DB::AccTransaction->new(trans_id       => $self->id,
164
                                                     chart_id       => $account_bank->id,
165
                                                     chart_link     => $account_bank->link,
166
                                                     amount         => $fxamount * -1,
167
                                                     transdate      => $transdate_obj,
168
                                                     source         => $source,
169
                                                     memo           => $memo,
170
                                                     taxkey         => 0,
171
                                                     fx_transaction => 1,
172
                                                     tax_id         => SL::DB::Manager::Tax->find_by(taxkey => 0)->id);
173
        $new_acc_trans->save;
174
      };
123 175
    };
124 176

  
125 177
    if ( $params{payment_type} eq 'difference_as_skonto' or $params{payment_type} eq 'with_skonto_pt' ) {
......
148 200
        my $amount = -1 * $skonto_booking->{skonto_amount};
149 201
        $new_acc_trans = SL::DB::AccTransaction->new(trans_id   => $self->id,
150 202
                                                     chart_id   => $skonto_booking->{'chart_id'},
151
                                                     chart_link => SL::DB::Manager::Chart->find_by(id => $skonto_booking->{'chart_id'})->{'link'},
203
                                                     chart_link => SL::DB::Manager::Chart->find_by(id => $skonto_booking->{'chart_id'})->link,
152 204
                                                     amount     => $amount * $mult,
153 205
                                                     transdate  => $transdate_obj,
154 206
                                                     source     => $params{source},
......
159 211
        $new_acc_trans->save;
160 212

  
161 213
        $reference_amount -= abs($amount);
162
        $paid_amount      += -1 * $amount;
214
        $paid_amount      += -1 * $amount * $exchangerate;
163 215
        $skonto_amount_check -= $skonto_booking->{'skonto_amount'};
164 216
      };
165 217
      if ( $params{payment_type} eq 'difference_as_skonto' ) {
......
186 238
    my $arap_booking= SL::DB::AccTransaction->new(trans_id   => $self->id,
187 239
                                                  chart_id   => $reference_account->id,
188 240
                                                  chart_link => $reference_account->link,
189
                                                  amount     => $arap_amount * $mult,
241
                                                  amount     => _round($arap_amount * $mult * $exchangerate),
190 242
                                                  transdate  => $transdate_obj,
191 243
                                                  source     => '', #$params{source},
192 244
                                                  taxkey     => 0,
193 245
                                                  tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 0)->id);
194 246
    $arap_booking->save;
195 247

  
196
    $self->paid($self->paid+$paid_amount) if $paid_amount;
248
    $self->paid($self->paid + _round($paid_amount)) if $paid_amount;
197 249
    $self->datepaid($transdate_obj);
198 250
    $self->save;
199 251

  
......
386 438
  # my $transactions = $self->transactions;
387 439
  foreach my $transaction (@{ $self->transactions }) {
388 440
    # find all transactions with an AR_amount or AP_amount link
389
    my $tax = SL::DB::Manager::Tax->get_first( where => [taxkey => $transaction->{taxkey}]);
441
    my $tax = SL::DB::Manager::Tax->get_first( where => [taxkey => $transaction->taxkey]);
390 442
    croak "no tax for taxkey " . $transaction->{taxkey} unless ref $tax;
391 443

  
392
    $transaction->{chartlinks} = { map { $_ => 1 } split(m/:/, $transaction->{chart_link}) };
444
    $transaction->{chartlinks} = { map { $_ => 1 } split(m/:/, $transaction->chart_link) };
393 445
    if ( $is_sales && $transaction->{chartlinks}->{AR_amount} ) {
394 446
      $skonto_configured = 0 unless $tax->skonto_sales_chart_id;
395 447
    } elsif ( !$is_sales && $transaction->{chartlinks}->{AP_amount}) {
......
717 769
                   payment_type  => 'with_skonto',
718 770
                  );
719 771

  
772
or in a certain currency:
773
  $ap->pay_invoice(chart_id      => $bank->chart_id,
774
                   amount        => 500,
775
                   currency      => 'USD',
776
                   transdate     => DateTime->now->to_kivitendo,
777
                   memo          => 'foobar',
778
                   source        => 'barfoo',
779
                   payment_type  => 'with_skonto',
780
                  );
781

  
720 782
Allowed payment types are:
721 783
  without_skonto with_skonto_pt difference_as_skonto
722 784

  
......
768 830

  
769 831
Skonto doesn't/shouldn't apply if the invoice contains credited items.
770 832

  
833
If no amount is given the whole open amout is paid.
834

  
835
If neither currency or currency_id are given as params, the currency of the
836
invoice is assumed to be the payment currency.
837

  
771 838
=item C<reference_account>
772 839

  
773 840
Returns a chart object which is the chart of the invoice with link AR or AP.
t/db_helper/payment.t
12 12

  
13 13
use SL::DB::Buchungsgruppe;
14 14
use SL::DB::Currency;
15
use SL::DB::Exchangerate;
15 16
use SL::DB::Customer;
16 17
use SL::DB::Vendor;
17 18
use SL::DB::Employee;
......
21 22
use SL::DB::TaxZone;
22 23
use SL::DB::BankAccount;
23 24
use SL::DB::PaymentTerm;
25
use Data::Dumper;
24 26

  
25
my ($customer, $vendor, $currency_id, @parts, $buchungsgruppe, $buchungsgruppe7, $unit, $employee, $tax, $tax7, $taxzone, $payment_terms, $bank_account);
27
my ($customer, $vendor, $currency_id, @parts, $buchungsgruppe, $buchungsgruppe7, $unit, $employee, $tax, $tax7, $tax_9, $taxzone, $payment_terms, $bank_account);
28
my ($transdate, $transdate2, $currency, $exchangerate, $exchangerate2);
29
my ($ar_chart,$bank,$ar_amount_chart, $ap_chart, $ap_amount_chart);
26 30

  
27 31
my $ALWAYS_RESET = 1;
28 32

  
......
39 43
  SL::DB::Manager::Vendor->delete_all(all => 1);
40 44
  SL::DB::Manager::BankAccount->delete_all(all => 1);
41 45
  SL::DB::Manager::PaymentTerm->delete_all(all => 1);
46
  SL::DB::Manager::Exchangerate->delete_all(all => 1);
47
  SL::DB::Manager::Currency->delete_all(where => [ name => 'CUR' ]);
42 48
};
43 49

  
44 50
sub reset_state {
......
50 56

  
51 57
  clear_up();
52 58

  
59
  $transdate  = DateTime->today;
60
  $transdate2 = DateTime->today->add(days => 1);
53 61

  
54 62
  $buchungsgruppe  = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%', %{ $params{buchungsgruppe} }) || croak "No accounting group";
55 63
  $buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%')                                || croak "No accounting group for 7\%";
......
58 66
  $tax             = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19, %{ $params{tax} })                           || croak "No tax";
59 67
  $tax7            = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07)                                              || croak "No tax for 7\%";
60 68
  $taxzone         = SL::DB::Manager::TaxZone->find_by( description => 'Inland')                                           || croak "No taxzone";
69
  $tax_9           = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19, %{ $params{tax} })                           || croak "No tax";
70
  # $tax7            = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07)                                              || croak "No tax for 7\%";
61 71

  
62 72
  $currency_id     = $::instance_conf->get_currency_id;
63 73

  
74
  $currency = SL::DB::Currency->new(name => 'CUR')->save;
75
  $exchangerate  = SL::DB::Exchangerate->new(transdate   => $transdate,
76
                                             buy         => '1.33333',
77
                                             sell        => '1.33333',
78
                                             currency_id => $currency->id,
79
                                            )->save;
80
  $exchangerate2 = SL::DB::Exchangerate->new(transdate   => $transdate2,
81
                                             buy         => '1.55555',
82
                                             sell        => '1.55555',
83
                                             currency_id => $currency->id,
84
                                            )->save;
85

  
64 86
  $customer     = SL::DB::Customer->new(
65 87
    name        => 'Test Customer',
66 88
    currency_id => $currency_id,
......
135 157
    %{ $params{part4} }
136 158
  )->save;
137 159

  
160
  $ar_chart        = SL::DB::Manager::Chart->find_by( accno => '1400' ); # Forderungen
161
  $ap_chart        = SL::DB::Manager::Chart->find_by( accno => '1600' ); # Verbindlichkeiten
162
  $bank            = SL::DB::Manager::Chart->find_by( accno => '1200' ); # Bank
163
  $ar_amount_chart = SL::DB::Manager::Chart->find_by( accno => '8400' ); # Erlöse
164
  $ap_amount_chart = SL::DB::Manager::Chart->find_by( accno => '3400' ); # Wareneingang 19%
165

  
138 166
  $reset_state_counter++;
139 167
}
140 168

  
......
179 207
    # %params,
180 208
  )->save;
181 209

  
182
  my $today = DateTime->today_local->to_kivitendo;
183 210
  my $expense_chart  = SL::DB::Manager::Chart->find_by(accno => '3400');
184 211
  my $expense_chart_booking= SL::DB::AccTransaction->new(
185 212
                                        trans_id   => $purchase_invoice->id,
186 213
                                        chart_id   => $expense_chart->id,
187 214
                                        chart_link => $expense_chart->link,
188 215
                                        amount     => '-100',
189
                                        transdate  => $today,
216
                                        transdate  => $transdate,
190 217
                                        source     => '',
191 218
                                        taxkey     => 9,
192 219
                                        tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 9)->id);
......
198 225
                                        chart_id   => $tax_chart->id,
199 226
                                        chart_link => $tax_chart->link,
200 227
                                        amount     => '-19',
201
                                        transdate  => $today,
228
                                        transdate  => $transdate,
202 229
                                        source     => '',
203 230
                                        taxkey     => 0,
204 231
                                        tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 9)->id);
......
209 236
                                        chart_id   => $expense_chart->id,
210 237
                                        chart_link => $expense_chart->link,
211 238
                                        amount     => '-100',
212
                                        transdate  => $today,
239
                                        transdate  => $transdate,
213 240
                                        source     => '',
214 241
                                        taxkey     => 8,
215 242
                                        tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 8)->id);
......
222 249
                                         chart_id   => $tax_chart->id,
223 250
                                         chart_link => $tax_chart->link,
224 251
                                         amount     => '-7',
225
                                         transdate  => $today,
252
                                         transdate  => $transdate,
226 253
                                         source     => '',
227 254
                                         taxkey     => 0,
228 255
                                         tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 8)->id);
......
232 259
                                                chart_id   => $arap_chart->id,
233 260
                                                chart_link => $arap_chart->link,
234 261
                                                amount     => '226',
235
                                                transdate  => $today,
262
                                                transdate  => $transdate,
236 263
                                                source     => '',
237 264
                                                taxkey     => 0,
238 265
                                                tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 0)->id);
......
623 650

  
624 651
}
625 652

  
626
sub  test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto_2cent() {
653
sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto_2cent() {
627 654
  reset_state() if $ALWAYS_RESET;
628 655

  
629 656
  # if there are two cents left there will be two skonto bookings, 1 cent each
......
998 1025
  is($total,                 0,     "${title}: even balance: this will fail due to rounding error in invoice post, not the skonto");
999 1026
}
1000 1027

  
1028
sub test_ar_currency_tax_not_included_and_payment {
1029
  my $netamount = $::form->round_amount(75 * $exchangerate->sell,2); #  75 in CUR, 100.00 in EUR
1030
  my $amount    = $::form->round_amount($netamount * 1.19,2);        # 100 in CUR, 119.00 in EUR
1031
  my $invoice   = SL::DB::Invoice->new(
1032
      invoice      => 0,
1033
      amount       => $amount,
1034
      netamount    => $netamount,
1035
      transdate    => $transdate,
1036
      taxincluded  => 0,
1037
      customer_id  => $customer->id,
1038
      taxzone_id   => $customer->taxzone_id,
1039
      currency_id  => $currency->id,
1040
      transactions => [],
1041
      notes        => 'test_ar_currency_tax_not_included_and_payment',
1042
  );
1043
  $invoice->add_ar_amount_row(
1044
    amount     => $invoice->netamount,
1045
    chart      => $ar_amount_chart,
1046
    tax_id     => $tax->id,
1047
  );
1048

  
1049
  $invoice->create_ar_row(chart => $ar_chart);
1050
  $invoice->save;
1051

  
1052
  is(SL::DB::Manager::Invoice->get_all_count(where => [ invoice => 0 ]), 1, 'there is one ar transaction');
1053
  is($invoice->currency_id , $currency->id , 'currency_id has been saved');
1054
  is($invoice->netamount   , 100           , 'ar amount has been converted');
1055
  is($invoice->amount      , 119           , 'ar amount has been converted');
1056
  is($invoice->taxincluded ,   0           , 'ar transaction doesn\'t have taxincluded');
1057
  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');
1058
  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');
1059

  
1060
  $invoice->pay_invoice(chart_id   => $bank->id,
1061
                        amount     => 50,
1062
                        currency   => 'CUR',
1063
                        transdate  => $transdate->to_kivitendo,
1064
                       );
1065
  $invoice->pay_invoice(chart_id   => $bank->id,
1066
                        amount     => 39.25,
1067
                        currency   => 'CUR',
1068
                        transdate  => $transdate->to_kivitendo,
1069
                       );
1070
  # $invoice->pay_invoice(chart_id   => $bank->id,
1071
  #                       amount     => 30,
1072
  #                       transdate  => $transdate2->to_kivitendo,
1073
  #                      );
1074
  is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions (incl. fxtransactions)');
1075
  is($invoice->paid, $invoice->amount, 'ar transaction paid = amount in default currency');
1076
};
1077

  
1078
sub test_ar_currency_tax_included {
1079
  # we want the acc_trans amount to be 100
1080
  my $amount    = $::form->round_amount(75 * $exchangerate->sell * 1.19);
1081
  my $netamount = $::form->round_amount($amount / 1.19,2);
1082
  my $invoice = SL::DB::Invoice->new(
1083
      invoice      => 0,
1084
      amount       => 119, #$amount,
1085
      netamount    => 100, #$netamount,
1086
      transdate    => $transdate,
1087
      taxincluded  => 1,
1088
      customer_id  => $customer->id,
1089
      taxzone_id   => $customer->taxzone_id,
1090
      currency_id  => $currency->id,
1091
      notes        => 'test_ar_currency_tax_included',
1092
      transactions => [],
1093
  );
1094
  $invoice->add_ar_amount_row( # should take care of taxincluded
1095
    amount     => $invoice->amount, # tax included in local currency
1096
    chart      => $ar_amount_chart,
1097
    tax_id     => $tax->id,
1098
  );
1099

  
1100
  $invoice->create_ar_row( chart => $ar_chart );
1101
  $invoice->save;
1102
  is(SL::DB::Manager::Invoice->get_all_count(where => [ invoice => 0 ]), 2, 'there are now two ar transactions');
1103
  is($invoice->currency_id , $currency->id , 'currency_id has been saved');
1104
  is($invoice->amount      , $amount       , 'amount ok');
1105
  is($invoice->netamount   , $netamount    , 'netamount ok');
1106
  is($invoice->taxincluded , 1             , 'ar transaction has taxincluded');
1107
  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');
1108
  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');
1109
  $invoice->pay_invoice(chart_id   => $bank->id,
1110
                        amount     => 89.25,
1111
                        currency   => 'CUR',
1112
                        transdate  => $transdate->to_kivitendo,
1113
                       );
1114

  
1115
};
1116

  
1117
sub test_ap_currency_tax_not_included_and_payment {
1118
  my $netamount = $::form->round_amount(75 * $exchangerate->sell,2); #  75 in CUR, 100.00 in EUR
1119
  my $amount    = $::form->round_amount($netamount * 1.19,2);        # 100 in CUR, 119.00 in EUR
1120
  my $invoice   = SL::DB::PurchaseInvoice->new(
1121
      invoice      => 0,
1122
      invnumber    => 'test_ap_currency_tax_not_included_and_payment',
1123
      amount       => $amount,
1124
      netamount    => $netamount,
1125
      transdate    => $transdate,
1126
      taxincluded  => 0,
1127
      vendor_id    => $vendor->id,
1128
      taxzone_id   => $vendor->taxzone_id,
1129
      currency_id  => $currency->id,
1130
      transactions => [],
1131
      notes        => 'test_ap_currency_tax_not_included_and_payment',
1132
  );
1133
  $invoice->add_ap_amount_row(
1134
    amount     => $invoice->netamount,
1135
    chart      => $ap_amount_chart,
1136
    tax_id     => $tax_9->id,
1137
  );
1138

  
1139
  $invoice->create_ap_row(chart => $ap_chart);
1140
  $invoice->save;
1141

  
1142
  is($invoice->currency_id, $currency->id, 'currency_id has been saved');
1143
  is($invoice->netamount, 100, 'ap amount has been converted');
1144
  is($invoice->amount, 119, 'ap amount has been converted');
1145
  is($invoice->taxincluded, 0, 'ap transaction doesn\'t have taxincluded');
1146
  is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_amount_chart->id, trans_id => $invoice->id)->amount, '-100.00000', $ap_amount_chart->accno . ': has been converted for currency');
1147
  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');
1148

  
1149
  $invoice->pay_invoice(chart_id   => $bank->id,
1150
                        amount     => 50,
1151
                        currency   => 'CUR',
1152
                        transdate  => $transdate->to_kivitendo,
1153
                       );
1154
  $invoice->pay_invoice(chart_id   => $bank->id,
1155
                        amount     => 39.25,
1156
                        currency   => 'CUR',
1157
                        transdate  => $transdate->to_kivitendo,
1158
                       );
1159
  # $invoice->pay_invoice(chart_id   => $bank->id,
1160
  #                       amount     => 30,
1161
  #                       transdate  => $transdate2->to_kivitendo,
1162
  #                      );
1163
  is(scalar @{$invoice->transactions}, 9, 'ap transaction has 9 transactions (incl. fxtransactions)');
1164
  is($invoice->paid, $invoice->amount, 'ap transaction paid = amount in default currency');
1165
};
1166

  
1167
sub test_ap_currency_tax_included {
1168
  # we want the acc_trans amount to be 100
1169
  my $amount    = $::form->round_amount(75 * $exchangerate->sell * 1.19);
1170
  my $netamount = $::form->round_amount($amount / 1.19,2);
1171
  my $invoice = SL::DB::PurchaseInvoice->new(
1172
      invoice      => 0,
1173
      amount       => 119, #$amount,
1174
      netamount    => 100, #$netamount,
1175
      transdate    => $transdate,
1176
      taxincluded  => 1,
1177
      vendor_id    => $vendor->id,
1178
      taxzone_id   => $vendor->taxzone_id,
1179
      currency_id  => $currency->id,
1180
      notes        => 'test_ap_currency_tax_included',
1181
      invnumber    => 'test_ap_currency_tax_included',
1182
      transactions => [],
1183
  );
1184
  $invoice->add_ap_amount_row( # should take care of taxincluded
1185
    amount     => $invoice->amount, # tax included in local currency
1186
    chart      => $ap_amount_chart,
1187
    tax_id     => $tax_9->id,
1188
  );
1189

  
1190
  $invoice->create_ap_row( chart => $ap_chart );
1191
  $invoice->save;
1192
  is($invoice->currency_id , $currency->id , 'currency_id has been saved');
1193
  is($invoice->amount      , $amount       , 'amount ok');
1194
  is($invoice->netamount   , $netamount    , 'netamount ok');
1195
  is($invoice->taxincluded , 1             , 'ap transaction has taxincluded');
1196
  is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_amount_chart->id, trans_id => $invoice->id)->amount, '-100.00000', $ap_amount_chart->accno . ': has been converted for currency');
1197
  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');
1198

  
1199
  $invoice->pay_invoice(chart_id   => $bank->id,
1200
                        amount     => 89.25,
1201
                        currency   => 'CUR',
1202
                        transdate  => $transdate->to_kivitendo,
1203
                       );
1204

  
1205
};
1206

  
1001 1207
Support::TestSetup::login();
1002 1208
 # die;
1003 1209

  
......
1027 1233
 test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_tax_included();
1028 1234
 test_default_invoice_two_items_19_7_tax_with_skonto_tax_included();
1029 1235

  
1236
# test payment of ar and ap transactions with currency and tax included/not included
1237
 test_ar_currency_tax_not_included_and_payment();
1238
 test_ar_currency_tax_included();
1239
 test_ap_currency_tax_not_included_and_payment();
1240
 test_ap_currency_tax_included();
1241

  
1030 1242
# remove all created data at end of test
1031 1243
clear_up();
1032 1244

  

Auch abrufbar als: Unified diff