Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 031566ec

Von Sven Schöling vor mehr als 6 Jahren hinzugefügt

  • ID 031566ec011c921c54d114a122181e2418025619
  • Vorgänger ce4ec1a8
  • Nachfolger 2a968d9a

BankTransaction/list: sepa_export_items mit partition_by splitten

Spart eine Doppelschleife

Conflicts:
SL/Controller/BankTransaction.pm

Unterschiede anzeigen:

SL/Controller/BankTransaction.pm
26 26
use SL::DB::SepaExportItem;
27 27
use SL::DBUtils qw(like);
28 28

  
29
use List::UtilsBy qw(partition_by);
29 30
use List::MoreUtils qw(any);
31
use List::MoreUtils qw(any none);
30 32
use List::Util qw(max);
31 33

  
32 34
use Rose::Object::MakeMethods::Generic
......
119 121
  push @all_open_invoices, map { $_->{is_ar}=0 ; $_ } grep { abs($_->amount - $_->paid) >= 0.01 } @{ $all_open_ap_invoices };
120 122

  
121 123
  my %sepa_exports;
124
  my %sepa_export_items_by_id = partition_by { $_->ar_id || $_->ap_id } @$all_open_sepa_export_items;
125

  
122 126
  # first collect sepa export items to open invoices
123 127
  foreach my $open_invoice (@all_open_invoices){
124 128
    $open_invoice->{realamount}  = $::form->format_amount(\%::myconfig,$open_invoice->amount,2);
125 129
    $open_invoice->{skonto_type} = 'without_skonto';
126
    foreach ( @{$all_open_sepa_export_items}) {
127
      if (($_->ap_id && $_->ap_id == $open_invoice->id) || ($_->ar_id && $_->ar_id == $open_invoice->id)) {
128
        my $factor                   = ($_->ar_id == $open_invoice->id ? 1 : -1);
129
        #$main::lxdebug->message(LXDebug->DEBUG2(),"sepa_exitem=".$_->id." for invoice ".$open_invoice->id." factor=".$factor);
130
        $open_invoice->{realamount}  = $::form->format_amount(\%::myconfig,$open_invoice->amount*$factor,2);
131
        $open_invoice->{skonto_type} = $_->payment_type;
132
        $sepa_exports{$_->sepa_export_id} ||= { count => 0, is_ar => 0, amount => 0, proposed => 0, invoices => [], item => $_ };
133
        $sepa_exports{$_->sepa_export_id}->{count}++;
134
        $sepa_exports{$_->sepa_export_id}->{is_ar}++ if  $_->ar_id == $open_invoice->id;
135
        $sepa_exports{$_->sepa_export_id}->{amount} += $_->amount * $factor;
136
        push @{ $sepa_exports{$_->sepa_export_id}->{invoices} }, $open_invoice;
137
      }
130
    foreach (@{ $sepa_export_items_by_id{ $open_invoice->id } || [] }) {
131
      my $factor                   = ($_->ar_id == $open_invoice->id ? 1 : -1);
132
      $open_invoice->{realamount}  = $::form->format_sellprice($open_invoice->amount*$factor);
133
      $open_invoice->{skonto_type} = $_->payment_type;
134
      $sepa_exports{$_->sepa_export_id} ||= { count => 0, is_ar => 0, amount => 0, proposed => 0, invoices => [], item => $_ };
135
      $sepa_exports{$_->sepa_export_id}->{count}++;
136
      $sepa_exports{$_->sepa_export_id}->{is_ar}++ if  $_->ar_id == $open_invoice->id;
137
      $sepa_exports{$_->sepa_export_id}->{amount} += $_->amount * $factor;
138
      push @{ $sepa_exports{$_->sepa_export_id}->{invoices} }, $open_invoice;
138 139
    }
139 140
  }
140 141

  

Auch abrufbar als: Unified diff