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