Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / SL / DB / SepaExportItem.pm
index b75e053..0bcab3e 100644 (file)
@@ -1,6 +1,7 @@
 package SL::DB::SepaExportItem;
 
 use strict;
+use SL::DB::SepaExport;
 
 use SL::DB::MetaSetup::SepaExportItem;
 
@@ -20,4 +21,28 @@ sub compare_to {
   return $result || ($self->sepa_export_id <=> $other->sepa_export_id) || ($self->id <=> $other->id);
 }
 
+sub set_executed {
+  my ($self) = @_;
+
+  $self->executed(1); # does execution date also need to be set?
+  $self->save;
+  # if all the sepa_export_items in the sepa_export are closed (executed), close the sepa_export
+  if ( SL::DB::Manager::SepaExportItem->get_all_count( where => [ sepa_export_id => $self->sepa_export_id, executed => 0] ) == 0 ) {
+    my $sepa_export = SL::DB::Manager::SepaExport->find_by(id => $self->sepa_export_id);
+    $sepa_export->executed(1);
+    $sepa_export->closed(1);
+    $sepa_export->save(changes_only=>1);
+  };
+};
+
+
+sub arap_id {
+  my ($self) = @_;
+  if ( $self->ar_id ) {
+    return $self->ar_id;
+  } else {
+    return $self->ap_id;
+  };
+};
+
 1;