Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 25230b8c

Von Jan Büren vor etwa 6 Jahren hinzugefügt

  • ID 25230b8c8a406c836091f135445f1e1a97dad549
  • Vorgänger 2eaabab4
  • Nachfolger 66135d67

BankTransaction(closed_period) Prüft Valutadatum gegen closedto

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 ...

Unterschiede anzeigen:

SL/Controller/BankTransaction.pm
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 {
......
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 {
......
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 };
SL/DB/BankTransaction.pm
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__
......
Returns the not open amount of this bank transaction.
Dies if the return amount is higher than the original amount.
=item C<closed_period>
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
t/bank/bank_transactions.t
use Test::More tests => 282;
use Test::More tests => 290;
use strict;
......
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;
......
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();
......
reset_state();
test_two_banktransactions();
# remove all created data at end of test
test_closedto();
clear_up();
done_testing();
......
# 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;

Auch abrufbar als: Unified diff