@@ -98,6 +98,9 @@ sub gather_bank_transactions_and_proposals {
98
98
@where
99
99
],
100
100
);
101
+
102
+ my $has_batch_transaction = (grep { $_ -> is_batch_transaction } @{ $bank_transactions }) ? 1 : undef ;
103
+
101
104
# credit notes have a negative amount, treat differently
102
105
my $all_open_ar_invoices = SL::DB::Manager::Invoice-> get_all(where => [ or => [ amount => { gt => \' paid' }, # '} make emacs happy
103
106
and => [ type => ' credit_note' ,
@@ -109,37 +112,39 @@ sub gather_bank_transactions_and_proposals {
109
112
110
113
my $all_open_ap_invoices = SL::DB::Manager::PurchaseInvoice-> get_all(where => [amount => { ne => \' paid' }], # '}] make emacs happy
111
114
with_objects => [' vendor' ,' payment_terms' ]);
112
- my $all_open_sepa_export_items = SL::DB::Manager::SepaExportItem-> get_all(where => [chart_id => $params {bank_account }-> chart_id ,
113
- ' sepa_export.executed' => 0,
114
- ' sepa_export.closed' => 0
115
- ],
116
- with_objects => [' sepa_export' ]);
117
115
118
116
my @all_open_invoices ;
119
117
# filter out invoices with less than 1 cent outstanding
120
118
push @all_open_invoices , map { $_ -> {is_ar }=1 ; $_ } grep { abs($_ -> amount - $_ -> paid) >= 0.01 } @{ $all_open_ar_invoices };
121
119
push @all_open_invoices , map { $_ -> {is_ar }=0 ; $_ } grep { abs($_ -> amount - $_ -> paid) >= 0.01 } @{ $all_open_ap_invoices };
122
120
123
- my %sepa_exports ;
124
- my %sepa_export_items_by_id = partition_by { $_ -> ar_id || $_ -> ap_id } @$all_open_sepa_export_items ;
125
-
126
- # first collect sepa export items to open invoices
127
- foreach my $open_invoice (@all_open_invoices ){
128
- $open_invoice -> {realamount } = $: :form-> format_amount(\%::myconfig ,$open_invoice -> amount,2);
129
- $open_invoice -> {skonto_type } = ' without_skonto' ;
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_amount(\%::myconfig ,$open_invoice -> amount*$factor ,2);
133
-
134
- $open_invoice -> {skonto_type } = $_ -> payment_type;
135
- $sepa_exports {$_ -> sepa_export_id} ||= { count => 0, is_ar => 0, amount => 0, proposed => 0, invoices => [], item => $_ };
136
- $sepa_exports {$_ -> sepa_export_id}-> {count }++;
137
- $sepa_exports {$_ -> sepa_export_id}-> {is_ar }++ if $_ -> ar_id == $open_invoice -> id;
138
- $sepa_exports {$_ -> sepa_export_id}-> {amount } += $_ -> amount * $factor ;
139
- push @{ $sepa_exports {$_ -> sepa_export_id}-> {invoices } }, $open_invoice ;
121
+
122
+ my (%sepa_exports , %sepa_export_items_by_id , $all_open_sepa_export_items );
123
+ if ($has_batch_transaction ) {
124
+ $all_open_sepa_export_items = SL::DB::Manager::SepaExportItem-> get_all(where => [chart_id => $params {bank_account }-> chart_id ,
125
+ ' sepa_export.executed' => 0,
126
+ ' sepa_export.closed' => 0
127
+ ],
128
+ with_objects => [' sepa_export' ]);
129
+ %sepa_export_items_by_id = partition_by { $_ -> ar_id || $_ -> ap_id } @$all_open_sepa_export_items ;
130
+
131
+ # first collect sepa export items to open invoices
132
+ foreach my $open_invoice (@all_open_invoices ){
133
+ $open_invoice -> {realamount } = $: :form-> format_amount(\%::myconfig ,$open_invoice -> amount,2);
134
+ $open_invoice -> {skonto_type } = ' without_skonto' ;
135
+ foreach (@{ $sepa_export_items_by_id { $open_invoice -> id } || [] }) {
136
+ my $factor = ($_ -> ar_id == $open_invoice -> id ? 1 : -1);
137
+ $open_invoice -> {realamount } = $: :form-> format_amount(\%::myconfig ,$open_invoice -> amount*$factor ,2);
138
+
139
+ $open_invoice -> {skonto_type } = $_ -> payment_type;
140
+ $sepa_exports {$_ -> sepa_export_id} ||= { count => 0, is_ar => 0, amount => 0, proposed => 0, invoices => [], item => $_ };
141
+ $sepa_exports {$_ -> sepa_export_id}-> {count }++;
142
+ $sepa_exports {$_ -> sepa_export_id}-> {is_ar }++ if $_ -> ar_id == $open_invoice -> id;
143
+ $sepa_exports {$_ -> sepa_export_id}-> {amount } += $_ -> amount * $factor ;
144
+ push @{ $sepa_exports {$_ -> sepa_export_id}-> {invoices } }, $open_invoice ;
145
+ }
140
146
}
141
147
}
142
-
143
148
# try to match each bank_transaction with each of the possible open invoices
144
149
# by awarding points
145
150
my @proposals ;
@@ -154,7 +159,7 @@ sub gather_bank_transactions_and_proposals {
154
159
155
160
$bt -> {remote_name } .= $bt -> {remote_name_1 } if $bt -> {remote_name_1 };
156
161
157
- if ( $bt -> is_batch_transaction ) {
162
+ if ($has_batch_transaction && $bt -> is_batch_transaction ) {
158
163
my $found =0;
159
164
foreach ( keys %sepa_exports ) {
160
165
if ( abs(($sepa_exports {$_ }-> {amount } * 1) - ($bt -> amount * 1)) < 0.01 ) {
0 commit comments