Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 25230b8c

Von Jan Büren vor etwa 5 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
561 561

  
562 562
  my $bank_transaction = $data{bank_transaction};
563 563

  
564
  if ($bank_transaction->closed_period) {
565
    return {
566
      %data,
567
      result => 'error',
568
      message => $::locale->text('Cannot post payment for a closed period!'),
569
    };
570
  }
564 571
  my (@warnings);
565 572

  
566 573
  my $worker = sub {
......
729 736

  
730 737
  croak("No bank transaction ids") unless scalar @{ $::form->{ids}} > 0;
731 738

  
732
  my $closedto = $::locale->parse_date_to_object($::instance_conf->get_closedto);
733 739
  my $success_count;
734 740

  
735 741
  foreach my $bt_id (@{ $::form->{ids}} )  {
736 742

  
737 743
    my $bank_transaction = SL::DB::Manager::BankTransaction->find_by(id => $bt_id);
738 744
    croak("No valid bank transaction found") unless (ref($bank_transaction)  eq 'SL::DB::BankTransaction');
745
    croak t8('Cannot unlink payment for a closed period!') if $bank_transaction->closed_period;
739 746

  
740 747
    # everything in one transaction
741 748
    my $rez = $bank_transaction->db->with_transaction(sub {
......
747 754
      foreach my $acc_trans_id_entry (@{ SL::DB::Manager::BankTransactionAccTrans->get_all(where => [bank_transaction_id => $bt_id ] )}) {
748 755

  
749 756
        my $acc_trans = SL::DB::Manager::AccTransaction->get_all(where => [acc_trans_id => $acc_trans_id_entry->acc_trans_id]);
750
        # check closedto for acc trans entries
751
        croak t8('Cannot unlink payment for a closed period!') if (ref $closedto && grep { $_->transdate < $closedto } @{ $acc_trans } );
752 757

  
753 758
        # save trans_id and type
754 759
        die "no type" unless ($acc_trans_id_entry->ar_id || $acc_trans_id_entry->ap_id || $acc_trans_id_entry->gl_id);
755 760
        $trans_ids{$acc_trans_id_entry->ar_id} = 'ar' if $acc_trans_id_entry->ar_id;
756 761
        $trans_ids{$acc_trans_id_entry->ap_id} = 'ap' if $acc_trans_id_entry->ap_id;
757 762
        $trans_ids{$acc_trans_id_entry->gl_id} = 'gl' if $acc_trans_id_entry->gl_id;
758

  
759 763
        # 2. all good -> ready to delete acc_trans and bt_acc link
760 764
        $acc_trans_id_entry->delete;
761 765
        $_->delete for @{ $acc_trans };
SL/DB/BankTransaction.pm
297 297
  return $not_assigned_amount;
298 298

  
299 299
}
300
sub closed_period {
301
  my ($self) = @_;
302

  
303
  # check for closed period
304
  croak t8('Illegal date') unless ref $self->valutadate eq 'DateTime';
305

  
306

  
307
  my $closedto = $::locale->parse_date_to_object($::instance_conf->get_closedto);
308
  if ( ref $closedto && $self->valutadate < $closedto ) {
309
    return 1;
310
  } else {
311
    return 0;
312
  }
313
}
300 314
1;
301 315

  
302 316
__END__
......
354 368
Returns the not open amount of this bank transaction.
355 369
Dies if the return amount is higher than the original amount.
356 370

  
371
=item C<closed_period>
372

  
373
Returns 1 if the bank transaction valutadate is in a closed period, 0 if the
374
valutadate of the bank transaction is not in a closed period.
375

  
357 376
=back
358 377

  
359 378
=head1 AUTHOR
t/bank/bank_transactions.t
1
use Test::More tests => 282;
1
use Test::More tests => 290;
2 2

  
3 3
use strict;
4 4

  
......
15 15
use SL::DB::Buchungsgruppe;
16 16
use SL::DB::Currency;
17 17
use SL::DB::Customer;
18
use SL::DB::Default;
18 19
use SL::DB::Vendor;
19 20
use SL::DB::Invoice;
20 21
use SL::DB::Unit;
......
92 93
test_one_inv_and_two_invoices_with_skonto_exact();
93 94
test_bt_error();
94 95
test_full_workflow_ar_multiple_inv_skonto_reconciliate_and_undo();
95

  
96 96
reset_state();
97 97
test_sepa_export();
98 98

  
......
101 101
reset_state();
102 102
test_two_banktransactions();
103 103
# remove all created data at end of test
104
test_closedto();
104 105
clear_up();
105 106

  
106 107
done_testing();
......
1171 1172
  # is(scalar(@$proposals)         , 1  , "$testname: one proposal");
1172 1173

  
1173 1174
};
1175
sub test_closedto {
1176

  
1177
  my $testname = 'closedto';
1178

  
1179
  my $ar_transaction_1 = test_ar_transaction(invnumber => 'salesinv10000' , amount => 2912.00 );
1180
  my $bt1 = create_bank_transaction(record        => $ar_transaction_1,
1181
                                    amount        => $ar_transaction_1->amount,
1182
                                    purpose       => "Rechnung10000 beinahe",
1183
                                    bank_chart_id => $bank->id,
1184
                                  ) or die "Couldn't create bank_transaction";
1185

  
1186
  $bt1->valutadate(DateTime->new(year => 2019, month => 12, day => 30));
1187
  $bt1->save();
1188

  
1189
  is($bt1->closed_period, 0, "$testname undefined closedto");
1190

  
1191
  my $defaults = SL::DB::Manager::Default->get_all(limit => 1)->[0];
1192
  $defaults->closedto(DateTime->new(year => 2019, month => 12, day => 30));
1193
  $defaults->save();
1194
  $::instance_conf->reload->data;
1195
  $bt1->load();
1174 1196

  
1197
  is($bt1->closed_period, 1, "$testname defined and same date closedto");
1198

  
1199
  $bt1->valutadate(DateTime->new(year => 2019, month => 12, day => 31));
1200
  $bt1->save();
1201
  $bt1->load();
1202

  
1203
  is($bt1->closed_period, 0, "$testname defined closedto and next date valuta");
1204

  
1205
}
1175 1206

  
1176 1207
1;

Auch abrufbar als: Unified diff