"Kontoauszug verbuchen - SEPA-Zahlungen berücksichtigen und schließen
[kivitendo-erp.git] / SL / DB / SepaExportItem.pm
1 package SL::DB::SepaExportItem;
2
3 use strict;
4 use SL::DB::SepaExport;
5
6 use SL::DB::MetaSetup::SepaExportItem;
7
8 __PACKAGE__->meta->initialize;
9
10 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
11 __PACKAGE__->meta->make_manager_class;
12
13 sub compare_to {
14   my ($self, $other) = @_;
15
16   return  1 if  $self->execution_date && !$other->execution_date;
17   return -1 if !$self->execution_date &&  $other->execution_date;
18
19   my $result = 0;
20   $result    = $self->execution_date <=> $other->execution_date if $self->execution_date;
21   return $result || ($self->sepa_export_id <=> $other->sepa_export_id) || ($self->id <=> $other->id);
22 }
23
24 sub set_executed {
25   my ($self) = @_;
26
27   $self->executed(1); # does execution date also need to be set?
28   $self->save;
29   # if all the sepa_export_items in the sepa_export are closed (executed), close the sepa_export
30   if ( SL::DB::Manager::SepaExportItem->get_all_count( where => [ sepa_export_id => $self->sepa_export_id, executed => 0] ) == 0 ) {
31     my $sepa_export = SL::DB::Manager::SepaExport->find_by(id => $self->sepa_export_id);
32     $sepa_export->executed(1);
33     $sepa_export->closed(1);
34     $sepa_export->save(changes_only=>1);
35   };
36 };
37
38
39 sub arap_id {
40   my ($self) = @_;
41   if ( $self->ar_id ) {
42     return $self->ar_id;
43   } else {
44     return $self->ap_id;
45   };
46 };
47
48 1;