Revision 1c98ac62
Von Moritz Bunkus vor mehr als 4 Jahren hinzugefügt
SL/Controller/BankTransaction.pm | ||
---|---|---|
68 | 68 |
$self->report_generator_list_objects(report => $self->{report}, objects => $self->models->get); |
69 | 69 |
} |
70 | 70 |
|
71 |
sub action_list { |
|
72 |
my ($self) = @_; |
|
73 |
|
|
74 |
if (!$::form->{filter}{bank_account}) { |
|
75 |
flash('error', t8('No bank account chosen!')); |
|
76 |
$self->action_search; |
|
77 |
return; |
|
78 |
} |
|
71 |
sub gather_bank_transactions_and_proposals { |
|
72 |
my ($self, %params) = @_; |
|
79 | 73 |
|
80 |
my $sort_by = $::form->{sort_by} || 'transdate';
|
|
74 |
my $sort_by = $params{sort_by} || 'transdate';
|
|
81 | 75 |
$sort_by = 'transdate' if $sort_by eq 'proposal'; |
82 |
$sort_by .= $::form->{sort_dir} ? ' DESC' : ' ASC'; |
|
83 |
|
|
84 |
my $fromdate = $::locale->parse_date_to_object($::form->{filter}->{fromdate}); |
|
85 |
my $todate = $::locale->parse_date_to_object($::form->{filter}->{todate}); |
|
86 |
$todate->add( days => 1 ) if $todate; |
|
76 |
$sort_by .= $params{sort_dir} ? ' DESC' : ' ASC'; |
|
87 | 77 |
|
88 | 78 |
my @where = (); |
89 |
push @where, (transdate => { ge => $fromdate }) if ($fromdate); |
|
90 |
push @where, (transdate => { lt => $todate }) if ($todate); |
|
91 |
my $bank_account = SL::DB::Manager::BankAccount->find_by( id => $::form->{filter}{bank_account} ); |
|
79 |
push @where, (transdate => { ge => $params{fromdate} }) if $params{fromdate}; |
|
80 |
push @where, (transdate => { lt => $params{todate} }) if $params{todate}; |
|
92 | 81 |
# bank_transactions no younger than starting date, |
93 | 82 |
# including starting date (same search behaviour as fromdate) |
94 | 83 |
# but OPEN invoices to be matched may be from before |
95 |
if ( $bank_account->reconciliation_starting_date ) {
|
|
96 |
push @where, (transdate => { ge => $bank_account->reconciliation_starting_date });
|
|
84 |
if ( $params{bank_account}->reconciliation_starting_date ) {
|
|
85 |
push @where, (transdate => { ge => $params{bank_account}->reconciliation_starting_date });
|
|
97 | 86 |
}; |
98 | 87 |
|
99 | 88 |
my $bank_transactions = SL::DB::Manager::BankTransaction->get_all( |
... | ... | |
102 | 91 |
limit => 10000, |
103 | 92 |
where => [ |
104 | 93 |
amount => {ne => \'invoice_amount'}, |
105 |
local_bank_account_id => $::form->{filter}{bank_account},
|
|
94 |
local_bank_account_id => $params{bank_account}->id,
|
|
106 | 95 |
cleared => 0, |
107 | 96 |
@where |
108 | 97 |
], |
... | ... | |
117 | 106 |
with_objects => ['customer','payment_terms']); |
118 | 107 |
|
119 | 108 |
my $all_open_ap_invoices = SL::DB::Manager::PurchaseInvoice->get_all(where => [amount => { ne => \'paid' }], with_objects => ['vendor' ,'payment_terms']); |
120 |
my $all_open_sepa_export_items = SL::DB::Manager::SepaExportItem->get_all(where => [chart_id => $bank_account->chart_id ,
|
|
109 |
my $all_open_sepa_export_items = SL::DB::Manager::SepaExportItem->get_all(where => [chart_id => $params{bank_account}->chart_id ,
|
|
121 | 110 |
'sepa_export.executed' => 0, 'sepa_export.closed' => 0 ], with_objects => ['sepa_export']); |
122 | 111 |
|
123 | 112 |
my @all_open_invoices; |
... | ... | |
229 | 218 |
push @proposals, @otherproposals; |
230 | 219 |
|
231 | 220 |
# sort bank transaction proposals by quality (score) of proposal |
232 |
if ($::form->{sort_by} && $::form->{sort_by} eq 'proposal') {
|
|
233 |
my $dir = $::form->{sort_dir} ? 1 : -1;
|
|
221 |
if ($params{sort_by} && $params{sort_by} eq 'proposal') {
|
|
222 |
my $dir = $params{sort_dir} ? 1 : -1;
|
|
234 | 223 |
$bank_transactions = [ sort { ($a->{agreement} <=> $b->{agreement}) * $dir } @{ $bank_transactions } ]; |
235 | 224 |
} |
236 | 225 |
|
237 |
# for testing with t/bank/banktransaction.t : |
|
238 |
if ( $::form->{dont_render_for_test} ) { |
|
239 |
return ( $bank_transactions , \@proposals ); |
|
226 |
return ( $bank_transactions , \@proposals ); |
|
227 |
} |
|
228 |
|
|
229 |
sub action_list { |
|
230 |
my ($self) = @_; |
|
231 |
|
|
232 |
if (!$::form->{filter}{bank_account}) { |
|
233 |
flash('error', t8('No bank account chosen!')); |
|
234 |
$self->action_search; |
|
235 |
return; |
|
240 | 236 |
} |
241 | 237 |
|
238 |
my $bank_account = SL::DB::BankAccount->load_cached($::form->{filter}->{bank_account}); |
|
239 |
my $fromdate = $::locale->parse_date_to_object($::form->{filter}->{fromdate}); |
|
240 |
my $todate = $::locale->parse_date_to_object($::form->{filter}->{todate}); |
|
241 |
$todate->add( days => 1 ) if $todate; |
|
242 |
|
|
243 |
my ($bank_transactions, $proposals) = $self->gather_bank_transactions_and_proposals( |
|
244 |
bank_account => $bank_account, |
|
245 |
fromdate => $fromdate, |
|
246 |
todate => $todate, |
|
247 |
sort_by => $::form->{sort_by}, |
|
248 |
sort_dir => $::form->{sort_dir}, |
|
249 |
); |
|
250 |
|
|
242 | 251 |
$::request->layout->add_javascripts("kivi.BankTransaction.js"); |
243 | 252 |
$self->render('bank_transactions/list', |
244 | 253 |
title => t8('Bank transactions MT940'), |
245 | 254 |
BANK_TRANSACTIONS => $bank_transactions, |
246 |
PROPOSALS => \@proposals,
|
|
255 |
PROPOSALS => $proposals,
|
|
247 | 256 |
bank_account => $bank_account, |
248 |
ui_tab => scalar(@proposals) > 0?1:0,
|
|
257 |
ui_tab => scalar(@{ $proposals }) > 0 ? 1 : 0,
|
|
249 | 258 |
); |
250 | 259 |
} |
251 | 260 |
|
t/bank/bank_transactions.t | ||
---|---|---|
1022 | 1022 |
is($bt->invoice_amount , '0.00000' , "$testname: bt invoice amount was not assigned"); |
1023 | 1023 |
|
1024 | 1024 |
my $bt_controller = SL::Controller::BankTransaction->new; |
1025 |
$::form->{dont_render_for_test} = 1; |
|
1026 |
$::form->{filter}{bank_account} = $bank_account->id; |
|
1027 |
my ( $bt_transactions, $proposals ) = $bt_controller->action_list; |
|
1025 |
my ( $bt_transactions, $proposals ) = $bt_controller->gather_bank_transactions_and_proposals(bank_account => $bank_account); |
|
1028 | 1026 |
|
1029 | 1027 |
is(scalar(@$bt_transactions) , 1 , "$testname: one bank_transaction"); |
1030 | 1028 |
is($bt_transactions->[0]->{agreement}, 20 , "$testname: agreement == 20"); |
... | ... | |
1075 | 1073 |
is($sei->amount , '119.00000' , "$testname: sepa export amount ok"); |
1076 | 1074 |
|
1077 | 1075 |
my $bt_controller = SL::Controller::BankTransaction->new; |
1078 |
$::form->{dont_render_for_test} = 1; |
|
1079 |
$::form->{filter}{bank_account} = $bank_account->id; |
|
1080 |
my ( $bt_transactions, $proposals ) = $bt_controller->action_list; |
|
1076 |
my ( $bt_transactions, $proposals ) = $bt_controller->gather_bank_transactions_and_proposals(bank_account => $bank_account); |
|
1081 | 1077 |
|
1082 | 1078 |
is(scalar(@$bt_transactions) , 1 , "$testname: one bank_transaction"); |
1083 | 1079 |
is($bt_transactions->[0]->{agreement}, 25 , "$testname: agreement == 25"); |
... | ... | |
1143 | 1139 |
#nun sollten zwei gleichwertige Rechnungen $ar_transaction_1 und $ar_transaction_3 für $bt1 gefunden werden |
1144 | 1140 |
#aber es darf keine Proposals geben mit mehreren Rechnungen |
1145 | 1141 |
my $bt_controller = SL::Controller::BankTransaction->new; |
1146 |
$::form->{dont_render_for_test} = 1; |
|
1147 |
$::form->{filter}{bank_account} = $bank_account->id; |
|
1148 |
my ( $bt_transactions, $proposals ) = $bt_controller->action_list; |
|
1142 |
my ( $bt_transactions, $proposals ) = $bt_controller->gather_bank_transactions_and_proposals(bank_account => $bank_account); |
|
1149 | 1143 |
|
1150 | 1144 |
is(scalar(@$bt_transactions) , 2 , "$testname: two bank_transaction"); |
1151 | 1145 |
is(scalar(@$proposals) , 0 , "$testname: no proposals"); |
... | ... | |
1155 | 1149 |
# Jetzt gibt es zwei Kontobewegungen mit gleichen Punkten für eine Rechnung. |
1156 | 1150 |
# hier darf es auch keine Proposals geben |
1157 | 1151 |
|
1158 |
( $bt_transactions, $proposals ) = $bt_controller->action_list;
|
|
1152 |
( $bt_transactions, $proposals ) = $bt_controller->gather_bank_transactions_and_proposals(bank_account => $bank_account);
|
|
1159 | 1153 |
|
1160 | 1154 |
is(scalar(@$bt_transactions) , 2 , "$testname: two bank_transaction"); |
1161 | 1155 |
# odyn testfall - anforderungen so (noch) nicht in kivi |
... | ... | |
1166 | 1160 |
# hier darf es auch keine Proposals geben |
1167 | 1161 |
$bt3->update_attributes( purpose => "fuer Rechnung salesinv10000"); |
1168 | 1162 |
|
1169 |
( $bt_transactions, $proposals ) = $bt_controller->action_list;
|
|
1163 |
( $bt_transactions, $proposals ) = $bt_controller->gather_bank_transactions_and_proposals(bank_account => $bank_account);
|
|
1170 | 1164 |
|
1171 | 1165 |
is(scalar(@$bt_transactions) , 2 , "$testname: two bank_transaction"); |
1172 | 1166 |
# odyn testfall - anforderungen so (noch) nicht in kivi |
Auch abrufbar als: Unified diff
BankTransaction: Vorschlagslistencode aus action_list eigene Funktion verlagert