From 25230b8c8a406c836091f135445f1e1a97dad549 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Tue, 5 Mar 2019 13:36:19 +0100 Subject: [PATCH] =?utf8?q?BankTransaction(closed=5Fperiod)=20Pr=C3=BCft=20?= =?utf8?q?Valutadatum=20gegen=20closedto?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Gibt 1 (wahr) zurück falls das Valutadatum der Bankbewegung innerhalb einer geschloßenen Periode ist. Andernfalls 0. POD, Test und 2 Stellen im Controller geändert. Offen: Payment-Helper, der sollte allerdings nichts über den Zustand der Bankbewegung wissen müssen ... --- SL/Controller/BankTransaction.pm | 12 +++++++---- SL/DB/BankTransaction.pm | 19 +++++++++++++++++ t/bank/bank_transactions.t | 35 ++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/SL/Controller/BankTransaction.pm b/SL/Controller/BankTransaction.pm index 655aebcc9..c7215b21c 100644 --- a/SL/Controller/BankTransaction.pm +++ b/SL/Controller/BankTransaction.pm @@ -561,6 +561,13 @@ sub save_single_bank_transaction { my $bank_transaction = $data{bank_transaction}; + if ($bank_transaction->closed_period) { + return { + %data, + result => 'error', + message => $::locale->text('Cannot post payment for a closed period!'), + }; + } my (@warnings); my $worker = sub { @@ -729,13 +736,13 @@ sub action_unlink_bank_transaction { croak("No bank transaction ids") unless scalar @{ $::form->{ids}} > 0; - my $closedto = $::locale->parse_date_to_object($::instance_conf->get_closedto); my $success_count; foreach my $bt_id (@{ $::form->{ids}} ) { my $bank_transaction = SL::DB::Manager::BankTransaction->find_by(id => $bt_id); croak("No valid bank transaction found") unless (ref($bank_transaction) eq 'SL::DB::BankTransaction'); + croak t8('Cannot unlink payment for a closed period!') if $bank_transaction->closed_period; # everything in one transaction my $rez = $bank_transaction->db->with_transaction(sub { @@ -747,15 +754,12 @@ sub action_unlink_bank_transaction { foreach my $acc_trans_id_entry (@{ SL::DB::Manager::BankTransactionAccTrans->get_all(where => [bank_transaction_id => $bt_id ] )}) { my $acc_trans = SL::DB::Manager::AccTransaction->get_all(where => [acc_trans_id => $acc_trans_id_entry->acc_trans_id]); - # check closedto for acc trans entries - croak t8('Cannot unlink payment for a closed period!') if (ref $closedto && grep { $_->transdate < $closedto } @{ $acc_trans } ); # save trans_id and type die "no type" unless ($acc_trans_id_entry->ar_id || $acc_trans_id_entry->ap_id || $acc_trans_id_entry->gl_id); $trans_ids{$acc_trans_id_entry->ar_id} = 'ar' if $acc_trans_id_entry->ar_id; $trans_ids{$acc_trans_id_entry->ap_id} = 'ap' if $acc_trans_id_entry->ap_id; $trans_ids{$acc_trans_id_entry->gl_id} = 'gl' if $acc_trans_id_entry->gl_id; - # 2. all good -> ready to delete acc_trans and bt_acc link $acc_trans_id_entry->delete; $_->delete for @{ $acc_trans }; diff --git a/SL/DB/BankTransaction.pm b/SL/DB/BankTransaction.pm index 9c5b56056..e2ddede4e 100644 --- a/SL/DB/BankTransaction.pm +++ b/SL/DB/BankTransaction.pm @@ -297,6 +297,20 @@ sub not_assigned_amount { return $not_assigned_amount; } +sub closed_period { + my ($self) = @_; + + # check for closed period + croak t8('Illegal date') unless ref $self->valutadate eq 'DateTime'; + + + my $closedto = $::locale->parse_date_to_object($::instance_conf->get_closedto); + if ( ref $closedto && $self->valutadate < $closedto ) { + return 1; + } else { + return 0; + } +} 1; __END__ @@ -354,6 +368,11 @@ Usage: Returns the not open amount of this bank transaction. Dies if the return amount is higher than the original amount. +=item C + +Returns 1 if the bank transaction valutadate is in a closed period, 0 if the +valutadate of the bank transaction is not in a closed period. + =back =head1 AUTHOR diff --git a/t/bank/bank_transactions.t b/t/bank/bank_transactions.t index 067270b7b..aaff649bb 100644 --- a/t/bank/bank_transactions.t +++ b/t/bank/bank_transactions.t @@ -1,4 +1,4 @@ -use Test::More tests => 282; +use Test::More tests => 290; use strict; @@ -15,6 +15,7 @@ use SL::DB::BankTransactionAccTrans; use SL::DB::Buchungsgruppe; use SL::DB::Currency; use SL::DB::Customer; +use SL::DB::Default; use SL::DB::Vendor; use SL::DB::Invoice; use SL::DB::Unit; @@ -92,7 +93,6 @@ test_two_neg_ap_transaction(); test_one_inv_and_two_invoices_with_skonto_exact(); test_bt_error(); test_full_workflow_ar_multiple_inv_skonto_reconciliate_and_undo(); - reset_state(); test_sepa_export(); @@ -101,6 +101,7 @@ test_bt_rule1(); reset_state(); test_two_banktransactions(); # remove all created data at end of test +test_closedto(); clear_up(); done_testing(); @@ -1171,6 +1172,36 @@ sub test_two_banktransactions { # is(scalar(@$proposals) , 1 , "$testname: one proposal"); }; +sub test_closedto { + + my $testname = 'closedto'; + + my $ar_transaction_1 = test_ar_transaction(invnumber => 'salesinv10000' , amount => 2912.00 ); + my $bt1 = create_bank_transaction(record => $ar_transaction_1, + amount => $ar_transaction_1->amount, + purpose => "Rechnung10000 beinahe", + bank_chart_id => $bank->id, + ) or die "Couldn't create bank_transaction"; + + $bt1->valutadate(DateTime->new(year => 2019, month => 12, day => 30)); + $bt1->save(); + + is($bt1->closed_period, 0, "$testname undefined closedto"); + + my $defaults = SL::DB::Manager::Default->get_all(limit => 1)->[0]; + $defaults->closedto(DateTime->new(year => 2019, month => 12, day => 30)); + $defaults->save(); + $::instance_conf->reload->data; + $bt1->load(); + is($bt1->closed_period, 1, "$testname defined and same date closedto"); + + $bt1->valutadate(DateTime->new(year => 2019, month => 12, day => 31)); + $bt1->save(); + $bt1->load(); + + is($bt1->closed_period, 0, "$testname defined closedto and next date valuta"); + +} 1; -- 2.20.1