Revision 9e481f80
Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt
SL/Controller/BankTransaction.pm | ||
---|---|---|
85 | 85 |
push @where, (transdate => { ge => $bank_account->reconciliation_starting_date }); |
86 | 86 |
}; |
87 | 87 |
|
88 |
my $bank_transactions = SL::DB::Manager::BankTransaction->get_all(where => [ amount => {ne => \'invoice_amount'}, |
|
89 |
local_bank_account_id => $::form->{filter}{bank_account}, |
|
90 |
@where ], |
|
91 |
with_objects => [ 'local_bank_account', 'currency' ], |
|
92 |
sort_by => $sort_by, limit => 10000); |
|
88 |
my $bank_transactions = SL::DB::Manager::BankTransaction->get_all( |
|
89 |
with_objects => [ 'local_bank_account', 'currency' ], |
|
90 |
sort_by => $sort_by, |
|
91 |
limit => 10000, |
|
92 |
where => [ |
|
93 |
amount => {ne => \'invoice_amount'}, |
|
94 |
local_bank_account_id => $::form->{filter}{bank_account}, |
|
95 |
@where |
|
96 |
], |
|
97 |
); |
|
93 | 98 |
|
94 |
my $all_open_ar_invoices = SL::DB::Manager::Invoice->get_all(where => [amount => { gt => \'paid' }], with_objects => 'customer'); |
|
99 |
my $all_open_ar_invoices = SL::DB::Manager::Invoice ->get_all(where => [amount => { gt => \'paid' }], with_objects => 'customer');
|
|
95 | 100 |
my $all_open_ap_invoices = SL::DB::Manager::PurchaseInvoice->get_all(where => [amount => { gt => \'paid' }], with_objects => 'vendor'); |
96 | 101 |
|
97 | 102 |
my @all_open_invoices; |
... | ... | |
146 | 151 |
# * there must be only one exact match |
147 | 152 |
# * depending on whether sales or purchase the amount has to have the correct sign (so Gutschriften don't work?) |
148 | 153 |
my $proposal_threshold = 5; |
149 |
my @proposals = grep { $_->{agreement} >= $proposal_threshold |
|
150 |
and 1 == scalar @{ $_->{proposals} } |
|
151 |
and (@{ $_->{proposals} }[0]->is_sales ? abs(@{ $_->{proposals} }[0]->amount - $_->amount) < 0.01 : abs(@{ $_->{proposals} }[0]->amount + $_->amount) < 0.01) } @{ $bank_transactions }; |
|
154 |
my @proposals = grep { |
|
155 |
($_->{agreement} >= $proposal_threshold) |
|
156 |
&& (1 == scalar @{ $_->{proposals} }) |
|
157 |
&& (@{ $_->{proposals} }[0]->is_sales ? abs(@{ $_->{proposals} }[0]->amount - $_->amount) < 0.01 |
|
158 |
: abs(@{ $_->{proposals} }[0]->amount + $_->amount) < 0.01) |
|
159 |
} @{ $bank_transactions }; |
|
152 | 160 |
|
153 | 161 |
# sort bank transaction proposals by quality (score) of proposal |
154 | 162 |
$bank_transactions = [ sort { $a->{agreement} <=> $b->{agreement} } @{ $bank_transactions } ] if $::form->{sort_by} eq 'proposal' and $::form->{sort_dir} == 1; |
... | ... | |
167 | 175 |
|
168 | 176 |
$self->{transaction} = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id}); |
169 | 177 |
|
170 |
$self->render('bank_transactions/assign_invoice', { layout => 0 }, |
|
171 |
title => t8('Assign invoice'),); |
|
178 |
$self->render('bank_transactions/assign_invoice', |
|
179 |
{ layout => 0 }, |
|
180 |
title => t8('Assign invoice'),); |
|
172 | 181 |
} |
173 | 182 |
|
174 | 183 |
sub action_create_invoice { |
... | ... | |
196 | 205 |
@filtered_drafts = grep { $_->{vendor_id} == $vendor_of_transaction->id } @filtered_drafts if $use_vendor_filter; |
197 | 206 |
|
198 | 207 |
my $all_vendors = SL::DB::Manager::Vendor->get_all(); |
199 |
|
|
200 |
$self->render('bank_transactions/create_invoice', { layout => 0 }, |
|
201 |
title => t8('Create invoice'), |
|
202 |
DRAFTS => \@filtered_drafts, |
|
203 |
vendor_id => $use_vendor_filter ? $vendor_of_transaction->id : undef, |
|
204 |
vendor_name => $use_vendor_filter ? $vendor_of_transaction->name : undef, |
|
205 |
ALL_VENDORS => $all_vendors, |
|
206 |
limit => $myconfig{vclimit}, |
|
207 |
callback => $self->url_for(action => 'list', |
|
208 |
my $callback = $self->url_for(action => 'list', |
|
208 | 209 |
'filter.bank_account' => $::form->{filter}->{bank_account}, |
209 | 210 |
'filter.todate' => $::form->{filter}->{todate}, |
210 |
'filter.fromdate' => $::form->{filter}->{fromdate}), |
|
211 |
); |
|
211 |
'filter.fromdate' => $::form->{filter}->{fromdate}); |
|
212 |
|
|
213 |
$self->render( |
|
214 |
'bank_transactions/create_invoice', |
|
215 |
{ layout => 0 }, |
|
216 |
title => t8('Create invoice'), |
|
217 |
DRAFTS => \@filtered_drafts, |
|
218 |
vendor_id => $use_vendor_filter ? $vendor_of_transaction->id : undef, |
|
219 |
vendor_name => $use_vendor_filter ? $vendor_of_transaction->name : undef, |
|
220 |
ALL_VENDORS => $all_vendors, |
|
221 |
limit => $myconfig{vclimit}, |
|
222 |
callback => $callback, |
|
223 |
); |
|
212 | 224 |
} |
213 | 225 |
|
214 | 226 |
sub action_ajax_payment_suggestion { |
... | ... | |
227 | 239 |
|
228 | 240 |
my $html; |
229 | 241 |
$html .= SL::Presenter->input_tag('invoice_ids.' . $::form->{bt_id} . '[]', $::form->{prop_id} , type => 'hidden'); |
230 |
# better in template code - but how to ajax this |
|
231 |
$html .= SL::Presenter->escape(t8('Invno.') . ': ' . $invoice->invnumber . ' '); |
|
242 |
$html .= SL::Presenter->escape(t8('Invno.') . ': ' . $invoice->invnumber . ' '); |
|
232 | 243 |
$html .= SL::Presenter->escape(t8('Open amount') . ': ' . $::form->format_amount(\%::myconfig, $invoice->open_amount, 2) . ' '); |
233 |
$html .= SL::Presenter->select_tag('invoice_skontos.' . $::form->{bt_id} . '[]', \@select_options, |
|
234 |
value_key => 'payment_type', |
|
235 |
title_key => 'display' ) if @select_options; |
|
244 |
$html .= SL::Presenter->select_tag('invoice_skontos.' . $::form->{bt_id} . '[]', |
|
245 |
\@select_options, |
|
246 |
value_key => 'payment_type', |
|
247 |
title_key => 'display' ) |
|
248 |
if @select_options; |
|
236 | 249 |
$html .= '<a href=# onclick="delete_invoice(' . $::form->{bt_id} . ',' . $::form->{prop_id} . ');">x</a>'; |
237 | 250 |
$html = SL::Presenter->html_tag('div', $html, id => $::form->{bt_id} . '.' . $::form->{prop_id}); |
238 | 251 |
|
... | ... | |
242 | 255 |
sub action_filter_drafts { |
243 | 256 |
my ($self) = @_; |
244 | 257 |
|
245 |
$self->{transaction} = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id}); |
|
258 |
$self->{transaction} = SL::DB::Manager::BankTransaction->find_by(id => $::form->{bt_id});
|
|
246 | 259 |
my $vendor_of_transaction = SL::DB::Manager::Vendor->find_by(account_number => $self->{transaction}->{remote_account_number}); |
247 | 260 |
|
248 |
my $drafts = SL::DB::Manager::Draft->get_all(with_objects => 'employee'); |
|
261 |
my $drafts = SL::DB::Manager::Draft->get_all(with_objects => 'employee');
|
|
249 | 262 |
|
250 | 263 |
my @filtered_drafts; |
251 | 264 |
|
252 | 265 |
foreach my $draft ( @{ $drafts } ) { |
253 | 266 |
my $draft_as_object = YAML::Load($draft->form); |
254 | 267 |
next unless $draft_as_object->{vendor_id}; # we cannot filter for vendor name, if this is a gl draft |
255 |
my $vendor = SL::DB::Manager::Vendor->find_by(id => $draft_as_object->{vendor_id}); |
|
256 |
$draft->{vendor} = $vendor->name; |
|
268 |
|
|
269 |
my $vendor = SL::DB::Manager::Vendor->find_by(id => $draft_as_object->{vendor_id}); |
|
270 |
$draft->{vendor} = $vendor->name; |
|
257 | 271 |
$draft->{vendor_id} = $vendor->id; |
272 |
|
|
258 | 273 |
push @filtered_drafts, $draft; |
259 | 274 |
} |
260 | 275 |
|
261 | 276 |
my $vendor_name = $::form->{vendor}; |
262 |
my $vendor_id = $::form->{vendor_id}; |
|
277 |
my $vendor_id = $::form->{vendor_id};
|
|
263 | 278 |
|
264 | 279 |
#Filter drafts |
265 |
@filtered_drafts = grep { $_->{vendor_id} == $vendor_id } @filtered_drafts if $vendor_id; |
|
266 |
@filtered_drafts = grep { $_->{vendor} =~ /$vendor_name/i } @filtered_drafts if $vendor_name; |
|
280 |
@filtered_drafts = grep { $_->{vendor_id} == $vendor_id } @filtered_drafts if $vendor_id;
|
|
281 |
@filtered_drafts = grep { $_->{vendor} =~ /$vendor_name/i } @filtered_drafts if $vendor_name;
|
|
267 | 282 |
|
268 | 283 |
my $output = $self->render( |
269 |
'bank_transactions/filter_drafts',
|
|
270 |
{ output => 0 },
|
|
271 |
DRAFTS => \@filtered_drafts,
|
|
272 |
);
|
|
284 |
'bank_transactions/filter_drafts', |
|
285 |
{ output => 0 },
|
|
286 |
DRAFTS => \@filtered_drafts, |
|
287 |
); |
|
273 | 288 |
|
274 | 289 |
my %result = ( count => 0, html => $output ); |
275 | 290 |
|
... | ... | |
319 | 334 |
}; |
320 | 335 |
} |
321 | 336 |
|
322 |
my $all_open_ar_invoices = SL::DB::Manager::Invoice->get_all(where => \@where_sale, with_objects => 'customer');
|
|
337 |
my $all_open_ar_invoices = SL::DB::Manager::Invoice ->get_all(where => \@where_sale, with_objects => 'customer');
|
|
323 | 338 |
my $all_open_ap_invoices = SL::DB::Manager::PurchaseInvoice->get_all(where => \@where_purchase, with_objects => 'vendor'); |
324 | 339 |
|
325 | 340 |
my @all_open_invoices = @{ $all_open_ar_invoices }; |
... | ... | |
329 | 344 |
@all_open_invoices = sort { $a->id <=> $b->id } @all_open_invoices; |
330 | 345 |
|
331 | 346 |
my $output = $self->render( |
332 |
'bank_transactions/add_list',
|
|
333 |
{ output => 0 },
|
|
334 |
INVOICES => \@all_open_invoices,
|
|
335 |
);
|
|
347 |
'bank_transactions/add_list', |
|
348 |
{ output => 0 },
|
|
349 |
INVOICES => \@all_open_invoices, |
|
350 |
); |
|
336 | 351 |
|
337 | 352 |
my %result = ( count => 0, html => $output ); |
338 | 353 |
|
... | ... | |
348 | 363 |
push @selected_invoices, $invoice_object; |
349 | 364 |
} |
350 | 365 |
|
351 |
$self->render('bank_transactions/invoices', { layout => 0 }, |
|
352 |
INVOICES => \@selected_invoices, |
|
353 |
bt_id => $::form->{bt_id} ); |
|
366 |
$self->render( |
|
367 |
'bank_transactions/invoices', |
|
368 |
{ layout => 0 }, |
|
369 |
INVOICES => \@selected_invoices, |
|
370 |
bt_id => $::form->{bt_id}, |
|
371 |
); |
|
354 | 372 |
} |
355 | 373 |
|
356 | 374 |
sub action_save_invoices { |
... | ... | |
418 | 436 |
}; |
419 | 437 |
if ($amount_of_transaction == 0) { |
420 | 438 |
flash('warning', $::locale->text('There are invoices which could not be paid by bank transaction #1 (Account number: #2, bank code: #3)!', |
421 |
$bank_transaction->purpose,
|
|
422 |
$bank_transaction->remote_account_number,
|
|
423 |
$bank_transaction->remote_bank_code));
|
|
439 |
$bank_transaction->purpose, |
|
440 |
$bank_transaction->remote_account_number, |
|
441 |
$bank_transaction->remote_bank_code)); |
|
424 | 442 |
last; |
425 | 443 |
} |
426 | 444 |
# pay invoice or go to the next bank transaction if the amount is not sufficiently high |
... | ... | |
451 | 469 |
|
452 | 470 |
# Record a record link from the bank transaction to the invoice |
453 | 471 |
my @props = ( |
454 |
from_table => 'bank_transactions',
|
|
455 |
from_id => $bt_id,
|
|
456 |
to_table => $invoice->is_sales ? 'ar' : 'ap',
|
|
457 |
to_id => $invoice->id,
|
|
458 |
);
|
|
472 |
from_table => 'bank_transactions', |
|
473 |
from_id => $bt_id, |
|
474 |
to_table => $invoice->is_sales ? 'ar' : 'ap', |
|
475 |
to_id => $invoice->id, |
|
476 |
); |
|
459 | 477 |
|
460 | 478 |
SL::DB::RecordLink->new(@props)->save; |
461 | 479 |
|
... | ... | |
467 | 485 |
# moved the execution and the check for sepa_export into a method, |
468 | 486 |
# this isn't part of a transaction, though |
469 | 487 |
$seis->[0]->set_executed if $invoice->id == $seis->[0]->arap_id; |
470 |
};
|
|
471 |
};
|
|
488 |
} |
|
489 |
} |
|
472 | 490 |
|
473 | 491 |
} |
474 | 492 |
$bank_transaction->save; |
... | ... | |
504 | 522 |
|
505 | 523 |
#create record link |
506 | 524 |
my @props = ( |
507 |
from_table => 'bank_transactions',
|
|
508 |
from_id => $bt_id,
|
|
509 |
to_table => $arap->is_sales ? 'ar' : 'ap',
|
|
510 |
to_id => $arap->id,
|
|
511 |
);
|
|
525 |
from_table => 'bank_transactions', |
|
526 |
from_id => $bt_id, |
|
527 |
to_table => $arap->is_sales ? 'ar' : 'ap', |
|
528 |
to_id => $arap->id, |
|
529 |
); |
|
512 | 530 |
|
513 | 531 |
SL::DB::RecordLink->new(@props)->save; |
514 | 532 |
|
... | ... | |
520 | 538 |
# moved the execution and the check for sepa_export into a method, |
521 | 539 |
# this isn't part of a transaction, though |
522 | 540 |
$seis->[0]->set_executed if $arap->id == $seis->[0]->arap_id; |
523 |
};
|
|
524 |
};
|
|
541 |
} |
|
542 |
} |
|
525 | 543 |
} |
526 | 544 |
|
527 | 545 |
flash('ok', t8('#1 proposal(s) saved.', scalar @{ $::form->{proposal_ids} })); |
... | ... | |
548 | 566 |
my @filter_strings; |
549 | 567 |
|
550 | 568 |
my @filters = ( |
551 |
[ $filter->{"transdate:date::ge"}, $::locale->text('Transdate') . " " . $::locale->text('From Date') ], |
|
552 |
[ $filter->{"transdate:date::le"}, $::locale->text('Transdate') . " " . $::locale->text('To Date') ], |
|
553 |
[ $filter->{"valutadate:date::ge"}, $::locale->text('Valutadate') . " " . $::locale->text('From Date') ], |
|
554 |
[ $filter->{"valutadate:date::le"}, $::locale->text('Valutadate') . " " . $::locale->text('To Date') ], |
|
555 |
[ $filter->{"amount:number"}, $::locale->text('Amount') ], |
|
556 |
[ $filter->{"bank_account_id:integer"}, $::locale->text('Local bank account') ], |
|
569 |
[ $filter->{"transdate:date::ge"}, $::locale->text('Transdate') . " " . $::locale->text('From Date') ],
|
|
570 |
[ $filter->{"transdate:date::le"}, $::locale->text('Transdate') . " " . $::locale->text('To Date') ],
|
|
571 |
[ $filter->{"valutadate:date::ge"}, $::locale->text('Valutadate') . " " . $::locale->text('From Date') ],
|
|
572 |
[ $filter->{"valutadate:date::le"}, $::locale->text('Valutadate') . " " . $::locale->text('To Date') ],
|
|
573 |
[ $filter->{"amount:number"}, $::locale->text('Amount') ],
|
|
574 |
[ $filter->{"bank_account_id:integer"}, $::locale->text('Local bank account') ],
|
|
557 | 575 |
); |
558 | 576 |
|
559 | 577 |
for (@filters) { |
... | ... | |
575 | 593 |
my @sortable = qw(local_bank_name transdate valudate remote_name remote_account_number remote_bank_code amount purpose local_account_number local_bank_code); |
576 | 594 |
|
577 | 595 |
my %column_defs = ( |
578 |
transdate => { sub => sub { $_[0]->transdate_as_date } }, |
|
579 |
valutadate => { sub => sub { $_[0]->valutadate_as_date } }, |
|
596 |
transdate => { sub => sub { $_[0]->transdate_as_date } },
|
|
597 |
valutadate => { sub => sub { $_[0]->valutadate_as_date } },
|
|
580 | 598 |
remote_name => { }, |
581 | 599 |
remote_account_number => { }, |
582 | 600 |
remote_bank_code => { }, |
583 |
amount => { sub => sub { $_[0]->amount_as_number }, |
|
601 |
amount => { sub => sub { $_[0]->amount_as_number },
|
|
584 | 602 |
align => 'right' }, |
585 |
invoice_amount => { sub => sub { $_[0]->invoice_amount_as_number }, |
|
603 |
invoice_amount => { sub => sub { $_[0]->invoice_amount_as_number },
|
|
586 | 604 |
align => 'right' }, |
587 |
invoices => { sub => sub { $_[0]->linked_invoices } }, |
|
588 |
currency => { sub => sub { $_[0]->currency->name } }, |
|
605 |
invoices => { sub => sub { $_[0]->linked_invoices } },
|
|
606 |
currency => { sub => sub { $_[0]->currency->name } },
|
|
589 | 607 |
purpose => { }, |
590 |
local_account_number => { sub => sub { $_[0]->local_bank_account->account_number } }, |
|
591 |
local_bank_code => { sub => sub { $_[0]->local_bank_account->bank_code } }, |
|
592 |
local_bank_name => { sub => sub { $_[0]->local_bank_account->name } }, |
|
608 |
local_account_number => { sub => sub { $_[0]->local_bank_account->account_number } },
|
|
609 |
local_bank_code => { sub => sub { $_[0]->local_bank_account->bank_code } },
|
|
610 |
local_bank_name => { sub => sub { $_[0]->local_bank_account->name } },
|
|
593 | 611 |
id => {}, |
594 | 612 |
); |
595 | 613 |
|
... | ... | |
639 | 657 |
|
640 | 658 |
SL::Controller::Helper::GetModels->new( |
641 | 659 |
controller => $self, |
642 |
sorted => { |
|
660 |
sorted => {
|
|
643 | 661 |
_default => { |
644 |
by => 'transdate',
|
|
645 |
dir => 0, # 1 = ASC, 0 = DESC : default sort is newest at top
|
|
662 |
by => 'transdate', |
|
663 |
dir => 0, # 1 = ASC, 0 = DESC : default sort is newest at top |
|
646 | 664 |
}, |
647 | 665 |
transdate => t8('Transdate'), |
648 | 666 |
remote_name => t8('Remote name'), |
Auch abrufbar als: Unified diff
S:C:BankTransaction: Kosmetik für bessere Lesbarkeit (Einrückung, Anordnung…)