OrderController Typo
[kivitendo-erp.git] / SL / Controller / BankTransaction.pm
index 60879a1..3d98e9f 100644 (file)
@@ -98,6 +98,7 @@ sub action_list {
     where        => [
       amount                => {ne => \'invoice_amount'},
       local_bank_account_id => $::form->{filter}{bank_account},
+      cleared               => 0,
       @where
     ],
   );
@@ -233,7 +234,7 @@ sub action_list {
 
   # for testing with t/bank/banktransaction.t :
   if ( $::form->{dont_render_for_test} ) {
-    return $bank_transactions;
+    return ( $bank_transactions , \@proposals );
   }
 
   $::request->layout->add_javascripts("kivi.BankTransaction.js");
@@ -293,7 +294,6 @@ sub action_create_invoice {
     TEMPLATES_GL => $use_vendor_filter && @{ $templates_ap } ? undef : $templates_gl,
     TEMPLATES_AP => $templates_ap,
     vendor_name  => $use_vendor_filter && @{ $templates_ap } ? $vendor_of_transaction->name : undef,
-    BT_ID        => $::form->{bt_id},
   );
 }
 
@@ -655,22 +655,21 @@ sub save_single_bank_transaction {
                               memo         => $memo,
                               transdate    => $bank_transaction->transdate->to_kivitendo);
       } else {
-        # use the whole amount of the bank transaction for the invoice, overpay the invoice if necessary
-
-        # this catches credit_notes and negative sales invoices
-        if ( $invoice->is_sales && $invoice->amount < 0 ) {
-          # $invoice->open_amount     is negative for credit_notes
-          # $bank_transaction->amount is negative for outgoing transactions
-          # so $amount_of_transaction is negative but needs positive
-          $amount_of_transaction *= -1;
-
-        } elsif (!$invoice->is_sales && $invoice->invoice_type =~ m/ap_transaction|purchase_invoice/) {
-          # $invoice->open_amount may be negative for ap_transaction but may be positiv for negativ ap_transaction
-          # if $invoice->open_amount is negative $bank_transaction->amount is positve
-          # if $invoice->open_amount is positive $bank_transaction->amount is negative
-          # but amount of transaction is for both positive
-          $amount_of_transaction *= -1 if $invoice->open_amount == - $amount_of_transaction;
-        }
+      # use the whole amount of the bank transaction for the invoice, overpay the invoice if necessary
+
+        # $invoice->open_amount     is negative for credit_notes
+        # $bank_transaction->amount is negative for outgoing transactions
+        # so $amount_of_transaction is negative but needs positive
+        # $invoice->open_amount may be negative for ap_transaction but may be positiv for negative ap_transaction
+        # if $invoice->open_amount is negative $bank_transaction->amount is positve
+        # if $invoice->open_amount is positive $bank_transaction->amount is negative
+        # but amount of transaction is for both positive
+
+        $amount_of_transaction *= -1 if ($invoice->amount < 0);
+
+        # if we have a skonto case - the last invoice needs skonto
+        $amount_of_transaction = $invoice->amount_less_skonto if ($payment_type eq 'with_skonto_pt');
+
 
         my $overpaid_amount = $amount_of_transaction - $invoice->open_amount;
         $invoice->pay_invoice(chart_id     => $bank_transaction->local_bank_account->chart_id,
@@ -881,7 +880,7 @@ sub load_ap_record_template_url {
 }
 
 sub load_gl_record_template_url {
-  my ($self, $template, $bt_id) = @_;
+  my ($self, $template) = @_;
 
   return $self->url_for(
     controller                           => 'gl.pl',
@@ -891,6 +890,7 @@ sub load_gl_record_template_url {
     'form_defaults.transdate'            => $self->transaction->transdate_as_date,
     'form_defaults.callback'             => $self->callback,
     'form_defaults.bt_id'                => $self->transaction->id,
+    'form_defaults.bt_chart_id'          => $self->transaction->local_bank_account->chart->id,
   );
 }
 
@@ -948,16 +948,10 @@ invoice objects).
 This method cannot handle already partly assigned bank transactions, i.e.
 a bank transaction that has a invoice_amount <> 0 but not the fully
 transaction amount (invoice_amount == amount).
-Currently this state is impossible from the point of the user interface,
-but for double safety and further reliance posting an bank_transaction
-where some invoice_amount is already assigned or a RecordLink from
-bank to document exists will not be accepted.
 
 If the amount of the bank transaction is higher than the sum of
 the assigned invoices (1 .. n) the last invoice will be overpayed.
 
-Therefore this function implements not all valid uses cases.
-
 The whole function is wrapped in a database transaction. If an
 exception occurs the bank transaction is not posted at all. The same
 is true if the code detects an error during the execution, e.g. a bank