Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c55ef764

Von Martin Helmling martin.helmling@octosoft.eu vor etwa 8 Jahren hinzugefügt

  • ID c55ef76464c63eb428f25d7849e6e23f549207a7
  • Vorgänger 40fc1b5c
  • Nachfolger 5eaed589

Bankimport: SEPA-Exporte werden manchmal nicht mehr erkannt

Wenn mehrere SEPA Anweisungen in einem Export sind, werden diese nicht gefunden
Nun bessere Implementierung

Nebenbei die Vorzeichen-Anzeige korrigiert

Unterschiede anzeigen:

SL/Controller/BankTransaction.pm
108 108

  
109 109
  my @all_open_invoices;
110 110
  # filter out invoices with less than 1 cent outstanding
111
  push @all_open_invoices, grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ar_invoices };
112
  push @all_open_invoices, grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ap_invoices };
111
  push @all_open_invoices, map { $_->{is_ar}=1 ; $_ } grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ar_invoices };
112
  push @all_open_invoices, map { $_->{is_ar}=0 ; $_ } grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ap_invoices };
113 113
  $main::lxdebug->message(LXDebug->DEBUG2(),"bank_account=".$::form->{filter}{bank_account}." invoices: ".scalar(@{ $all_open_ar_invoices }).
114 114
                              " + ".scalar(@{ $all_open_ap_invoices })." transactions=".scalar(@{ $bank_transactions }));
115 115

  
......
123 123
    $open_invoice->{skonto_type} = 'without_skonto';
124 124
    foreach ( @{$all_open_sepa_export_items}) {
125 125
      if ( $_->ap_id == $open_invoice->id ||  $_->ar_id == $open_invoice->id ) {
126
        #$main::lxdebug->message(LXDebug->DEBUG2(),"exitem=".$_->id." for invoice ".$open_invoice->id);
126
        my $factor = ( $_->ar_id == $open_invoice->id>0?1:-1);
127
        $open_invoice->{realamount}  = $::form->format_amount(\%::myconfig,$open_invoice->amount*$factor,2);
128
        $main::lxdebug->message(LXDebug->DEBUG2(),"exitem=".$_->id." for invoice ".$open_invoice->id." factor=".$factor);
127 129
        $open_invoice->{sepa_export_item} = $_ ;
128 130
        $open_invoice->{skonto_type} = $_->payment_type;
129 131
        $sepa_exports{$_->sepa_export_id} ||= { count => 0, is_ar => 0, amount => 0, proposed => 0, invoices => [], item => $_ };
130 132
        $sepa_exports{$_->sepa_export_id}->{count}++ ;
131 133
        $sepa_exports{$_->sepa_export_id}->{is_ar}++ if  $_->ar_id == $open_invoice->id;
132
        $sepa_exports{$_->sepa_export_id}->{amount} += $_->amount;
134
        $sepa_exports{$_->sepa_export_id}->{amount} += $_->amount * $factor;
133 135
        push ( @{ $sepa_exports{$_->sepa_export_id}->{invoices}} , $open_invoice );
134 136
        #$main::lxdebug->message(LXDebug->DEBUG2(),"amount for export id ".$_->sepa_export_id." = ".
135 137
        #                          $sepa_exports{$_->sepa_export_id}->{amount}." count = ".
......
158 160

  
159 161
    if ( $self->is_collective_transaction($bt) ) {
160 162
      foreach ( keys  %sepa_exports) {
161
        my $factor = ($sepa_exports{$_}->{is_ar}>0?1:-1);
162
        #$main::lxdebug->message(LXDebug->DEBUG2(),"Exp ID=".$_." factor=".$factor." compare sum amount ".($sepa_exports{$_}->{amount} *1) ." == ".($bt->amount * $factor));
163
        if ( $bt->transactioncode eq '191' && ($sepa_exports{$_}->{amount} * 1) eq ($bt->amount * $factor) ) {
163
        #$main::lxdebug->message(LXDebug->DEBUG2(),"Exp ID=".$_." compare sum amount ".($sepa_exports{$_}->{amount} *1) ." == ".($bt->amount * 1));
164
        if ( $bt->transactioncode eq '191' && ($sepa_exports{$_}->{amount} * 1) eq ($bt->amount * 1) ) {
164 165
          ## jupp
165 166
          $bt->{proposals} = $sepa_exports{$_}->{invoices} ;
167
          $bt->{agreement}    = 20;
168
          $bt->{rule_matches} = 'sepa_export_item(20)';
166 169
          $sepa_exports{$_}->{proposed}=1;
167 170
          #$main::lxdebug->message(LXDebug->DEBUG2(),"has ".scalar($bt->{proposals})." invoices");
168 171
          push(@proposals, $bt);
......
172 175
    }
173 176
    next unless $bt->{remote_name};  # bank has no name, usually fees, use create invoice to assign
174 177

  
175
    foreach ( keys %sepa_exports) {
176
      my $factor = ($sepa_exports{$_}->{is_ar}>0?1:-1);
177
      #$main::lxdebug->message(LXDebug->DEBUG2(),"exp count=".$sepa_exports{$_}->{count}." factor=".$factor." proposed=".$sepa_exports{$_}->{proposed});
178
      if ( $sepa_exports{$_}->{count} == 1 ) {
179
        my $oinvoice = @{ $sepa_exports{$_}->{invoices}}[0];
180
        my $eitem = $sepa_exports{$_}->{item};
181
        $eitem->amount($eitem->amount*1);
182
        #$main::lxdebug->message(LXDebug->DEBUG2(),"remote account '".$bt->{remote_account_number}."' bt_amount=". ($bt->amount * $factor));
183
        #$main::lxdebug->message(LXDebug->DEBUG2(),"compare with   '".$eitem->vc_iban."' amount=".$eitem->amount);
184
        if ( $bt->{remote_account_number} eq $eitem->vc_iban && $eitem->amount eq ($bt->amount * $factor)) {
185
          ## jupp
186
          $bt->{proposals} = $sepa_exports{$_}->{invoices} ;
187
          #$main::lxdebug->message(LXDebug->DEBUG2(),"found invoice");
188
          $sepa_exports{$_}->{proposed}=1;
189
          push(@proposals, $bt);
190
          next;
178
    foreach ( @{$all_open_sepa_export_items}) {
179
      last if scalar (@all_sepa_invoices) == 0;
180
      foreach my $open_invoice (@all_sepa_invoices){
181
        if ( $_->ap_id == $open_invoice->id ||  $_->ar_id == $open_invoice->id ) {
182
          #$main::lxdebug->message(LXDebug->DEBUG2(),"exitem2=".$_->id." for invoice ".$open_invoice->id);
183
          my $factor = ( $_->ar_id == $open_invoice->id?1:-1);
184
          $_->amount($_->amount*1);
185
          #$main::lxdebug->message(LXDebug->DEBUG2(),"remote account '".$bt->{remote_account_number}."' bt_amount=". ($bt->amount * $factor));
186
          #$main::lxdebug->message(LXDebug->DEBUG2(),"compare with   '".$_->vc_iban."'    amount=".$_->amount);
187
          if ( $bt->{remote_account_number} eq $_->vc_iban && $_->amount eq ($bt->amount * $factor)) {
188
            push ($bt->{proposals},$open_invoice );
189
            $bt->{agreement}    = 20;
190
            $bt->{rule_matches} = 'sepa_export_item(20)';
191
            #$main::lxdebug->message(LXDebug->DEBUG2(),"found invoice");
192
            @all_sepa_invoices = grep { $_ != $open_invoice } @all_sepa_invoices;
193
            last;
194
          }
191 195
        }
192
     }
196
      }
193 197
    }
194 198

  
195 199
    # try to match the current $bt to each of the open_invoices, saving the
......
203 207

  
204 208
    foreach my $open_invoice (@all_open_invoices){
205 209
      ($open_invoice->{agreement}, $open_invoice->{rule_matches}) = $bt->get_agreement_with_invoice($open_invoice);
206
      #  $main::lxdebug->message(LXDebug->DEBUG2(),"agreement=".$open_invoice->{agreement}." rules matches=".$open_invoice->{rule_matches});
210
      $open_invoice->{realamount} = $::form->format_amount(\%::myconfig,$open_invoice->amount*($open_invoice->{is_ar}?1:-1),2);
211
       # $main::lxdebug->message(LXDebug->DEBUG2(),"agreement=".$open_invoice->{agreement}." rules matches=".$open_invoice->{rule_matches});
207 212
    };
208 213

  
209 214
    my $agreement = 15;
templates/webpages/bank_transactions/tabs/all.html
93 93
      [% FOREACH prop = bt.proposals %]
94 94
        <div name='[% prop.id %]'>
95 95
         <a href=# onclick="add_invoices('[% bt.id %]', '[% prop.id %]', '[% HTML.escape(prop.invnumber) %]');"
96
            title="<table><tr><th></th><th>[% 'Suggested invoice' | $T8 %][% IF !prop.is_sales %] ([% 'AP' | $T8 %])[% END %]</th><th>[% 'Bank transaction' | $T8 %]</th></tr><tr><th>[% 'Amount' | $T8 %]</th><td>[% LxERP.format_amount(prop.amount, 2) %] ([% 'open' | $T8 %]: [% LxERP.format_amount(prop.open_amount, 2) %])</td><td>[% LxERP.format_amount(bt.absamount, 2) %]</td></tr>[% IF prop.skonto_date %]<tr><th>[% 'Payment terms' | $T8 %]</th><td>[% LxERP.format_amount(prop.amount_less_skonto, 2) %] [% 'until' | $T8 %] [% HTML.escape(prop.skonto_date.to_kivitendo) %] ([% prop.percent_skonto * 100 %] %)</td><td></td></tr>[% END %]<tr><th>[% 'Customer/Vendor' | $T8 %]</th><td>[% HTML.escape(prop.customer.displayable_name) %][% HTML.escape(prop.vendor.displayable_name) %]</td><td>[% HTML.escape(bt.remote_name) %]</td></tr><tr><th>[% 'Invoice Date' | $T8 %]</th><td>[% HTML.escape(prop.transdate_as_date) %]</td><td>[% HTML.escape(bt.transdate_as_date) %] ([% HTML.escape(bt.transdate.utc_rd_days - prop.transdate.utc_rd_days) %])</td></tr><tr><th>[% 'Invoice Number' | $T8 %]</th><td>[% HTML.escape(prop.invnumber) %]</td><td>[% HTML.escape(bt.purpose) %]</td></tr></table>"
96
            title="<table><tr><th></th><th>[% 'Suggested invoice' | $T8 %][% IF !prop.is_sales %] ([% 'AP' | $T8 %])[% END %]</th><th>[% 'Bank transaction' | $T8 %]</th></tr><tr><th>[% 'Amount' | $T8 %]</th><td>[% prop.realamount %] ([% 'open' | $T8 %]: [% LxERP.format_amount(prop.open_amount, 2) %])</td><td>[% LxERP.format_amount(bt.amount, 2) %]</td></tr>[% IF prop.skonto_date %]<tr><th>[% 'Payment terms' | $T8 %]</th><td>[% LxERP.format_amount(prop.amount_less_skonto, 2) %] [% 'until' | $T8 %] [% HTML.escape(prop.skonto_date.to_kivitendo) %] ([% prop.percent_skonto * 100 %] %)</td><td></td></tr>[% END %]<tr><th>[% 'Customer/Vendor' | $T8 %]</th><td>[% HTML.escape(prop.customer.displayable_name) %][% HTML.escape(prop.vendor.displayable_name) %]</td><td>[% HTML.escape(bt.remote_name) %]</td></tr><tr><th>[% 'Invoice Date' | $T8 %]</th><td>[% HTML.escape(prop.transdate_as_date) %]</td><td>[% HTML.escape(bt.transdate_as_date) %] ([% HTML.escape(bt.transdate.utc_rd_days - prop.transdate.utc_rd_days) %])</td></tr><tr><th>[% 'Invoice Number' | $T8 %]</th><td>[% HTML.escape(prop.invnumber) %]</td><td>[% HTML.escape(bt.purpose) %]</td></tr></table>"
97 97
              class="[% IF bt.agreement >= 5 %]green[% ELSIF bt.agreement < 5 and bt.agreement >= 3 %]orange[% ELSE %]red[% END %] tooltipster-html">&larr;[% HTML.escape(prop.invnumber)%]</a></div>
98 98
      [% END %]
99 99
     </td>

Auch abrufbar als: Unified diff