);
SL::DB::RecordLink->new(@props)->save;
+
+ # "close" a sepa_export_item if it exists
+ # currently only works, if there is only exactly one open sepa_export_item
+ if ( my $seis = $invoice->find_sepa_export_items({ executed => 0 }) ) {
+ if ( scalar @$seis == 1 ) {
+ # moved the execution and the check for sepa_export into a method,
+ # this isn't part of a transaction, though
+ $seis->[0]->set_executed if $invoice->id == $seis->[0]->arap_id;
+ };
+ };
+
}
$bank_transaction->save;
}
remote_account_number => 3,
skonto_exact_amount => 5,
wrong_sign => -1,
+ sepa_export_item => 5,
);
my ($agreement,$rule_matches);
#search invoice number in purpose
my $invnumber = $invoice->invnumber;
- # invnumbernhas to have at least 3 characters
+ # invnumber has to have at least 3 characters
my $squashed_purpose = $self->purpose;
$squashed_purpose =~ s/ //g;
if (length($invnumber) > 4 && $squashed_purpose =~ /$invnumber/ && $invoice->is_sales){
};
};
+ # if there is exactly one non-executed sepa_export_item for the invoice
+ if ( my $seis = $invoice->find_sepa_export_items({ executed => 0 }) ) {
+ if ( scalar @$seis == 1 ) {
+ my $sei = $seis->[0];
+
+ # test for amount and id matching only, sepa transfer date and bank
+ # transaction date needn't match
+ my $arap = $invoice->is_sales ? 'ar' : 'ap';
+ if ( abs($self->amount) == ($sei->amount)
+ && $invoice->id == $sei->arap_id
+ ) {
+ $agreement += $points{sepa_export_item};
+ $rule_matches .= 'sepa_export_item(' . $points{'sepa_export_item'} . ') ';
+ };
+ } else {
+ # zero or more than one sepa_export_item, do nothing for this invoice
+ # zero: do nothing, no sepa_export_item exists, no match
+ # more than one: does this ever apply? Currently you can't create sepa
+ # exports for invoices that already have a non-executed sepa_export
+ };
+ };
+
return ($agreement,$rule_matches);
};
package SL::DB::SepaExportItem;
use strict;
+use SL::DB::SepaExport;
use SL::DB::MetaSetup::SepaExportItem;
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;