SL::Dev::Payment create_bank_transaction nutzt param bank_chart_id
authorG. Richardson <information@kivitendo-premium.de>
Wed, 1 Feb 2017 09:55:07 +0000 (10:55 +0100)
committerG. Richardson <information@kivitendo-premium.de>
Wed, 1 Feb 2017 12:13:06 +0000 (13:13 +0100)
SL/Dev/Payment.pm
t/bank/bank_transactions.t

index bce5c0f..4e567e2 100644 (file)
@@ -49,8 +49,8 @@ sub create_bank_transaction {
  my $amount = (delete $params{amount} || $record->amount) * $multiplier;
 
  my $bank_chart;
- if ( $params{chart_id} ) {
-   $bank_chart = SL::DB::Manager::Chart->find_by(chart_id => $params{chart_id}) or die "Can't find bank chart";
+ if ( $params{bank_chart_id} ) {
+   $bank_chart = SL::DB::Manager::Chart->find_by(id => delete $params{bank_chart_id}) or die "Can't find bank chart";
  } elsif ( $::instance_conf->get_ar_paid_accno_id ) {
    $bank_chart   = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_ar_paid_accno_id);
  } else {
@@ -99,14 +99,20 @@ Example:
 
 =head2 C<create_bank_transaction %PARAMS>
 
+Create a bank transaction that matches an existing invoice record, e.g. to be able to
+test the point system.
+
 Required params: record  (an SL::DB::Invoice or SL::DB::PurchaseInvoice object)
 
+Optional params: bank_chart_id : the chart id of a configured bank account
+                 amount        : the amount of the bank transaction
 
-$params{amount} should always be relative to the absolute amount of the invoice, i.e. use positive
-values for sales and purchases.
+If no bank_chart_id is given, it tries to find a chart via defaults
+(ar_paid_accno_id) or by searching for the chart named "Bank". The chart must
+be connected to an existing BankAccount.
 
-Create a bank transaction that matches an existing invoice record, e.g. to be able to
-test the point system.
+Param amount should always be relative to the absolute amount of the invoice, i.e. use positive
+values for sales and purchases.
 
 Example:
   my $payment_terms = SL::Dev::Record::create_payment_terms;
index fa00def..76efaaa 100644 (file)
@@ -231,8 +231,9 @@ sub test_skonto_exact {
                                         payment_id => $payment_terms->id,
                                        );
 
-  my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction,
-                                                     amount => $ar_transaction->amount_less_skonto
+  my $bt = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction,
+                                                     bank_chart_id => $bank->id,
+                                                     amount        => $ar_transaction->amount_less_skonto
                                                     ) or die "Couldn't create bank_transaction";
 
   $::form->{invoice_ids} = {
@@ -260,9 +261,10 @@ sub test_two_invoices {
   my $ar_transaction_1 = test_ar_transaction(invnumber => 'salesinv_1');
   my $ar_transaction_2 = test_ar_transaction(invnumber => 'salesinv_2');
 
-  my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction_1,
-                                                     amount => ($ar_transaction_1->amount + $ar_transaction_2->amount),
-                                                     purpose => "Rechnungen " . $ar_transaction_1->invnumber . " und " . $ar_transaction_2->invnumber,
+  my $bt = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction_1,
+                                                     amount        => ($ar_transaction_1->amount + $ar_transaction_2->amount),
+                                                     purpose       => "Rechnungen " . $ar_transaction_1->invnumber . " und " . $ar_transaction_2->invnumber,
+                                                     bank_chart_id => $bank->id,
                                                     ) or die "Couldn't create bank_transaction";
 
   $::form->{invoice_ids} = {
@@ -291,8 +293,9 @@ sub test_overpayment {
   $ar_transaction = test_ar_transaction(invnumber => 'salesinv overpaid');
 
   # amount 135 > 119
-  my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction,
-                                                     amount => 135
+  my $bt = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction,
+                                                     bank_chart_id => $bank->id,
+                                                     amount        => 135
                                                     ) or die "Couldn't create bank_transaction";
 
   $::form->{invoice_ids} = {
@@ -321,12 +324,14 @@ sub test_overpayment_with_partialpayment {
 
   $ar_transaction = test_ar_transaction(invnumber => 'salesinv overpaid partial');
 
-  my $bt_1 = SL::Dev::Payment::create_bank_transaction(record    => $ar_transaction,
-                                                       amount    =>  10
+  my $bt_1 = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction,
+                                                       bank_chart_id => $bank->id,
+                                                       amount        =>  10
                                                       ) or die "Couldn't create bank_transaction";
-  my $bt_2 = SL::Dev::Payment::create_bank_transaction(record    => $ar_transaction,
-                                                       amount    => 119,
-                                                       transdate => DateTime->today->add(days => 5),
+  my $bt_2 = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction,
+                                                       amount        => 119,
+                                                       transdate     => DateTime->today->add(days => 5),
+                                                       bank_chart_id => $bank->id,
                                                       ) or die "Couldn't create bank_transaction";
 
   $::form->{invoice_ids} = {
@@ -358,8 +363,9 @@ sub test_partial_payment {
   $ar_transaction = test_ar_transaction(invnumber => 'salesinv partial payment');
 
   # amount 100 < 119
-  my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction,
-                                                     amount => 100
+  my $bt = SL::Dev::Payment::create_bank_transaction(record        => $ar_transaction,
+                                                     bank_chart_id => $bank->id,
+                                                     amount        => 100
                                                     ) or die "Couldn't create bank_transaction";
 
   $::form->{invoice_ids} = {