|
# This file has been auto-generated only because it didn't exist.
|
|
# Feel free to modify it at will; it will not be overwritten automatically.
|
|
|
|
package SL::DB::BankTransaction;
|
|
|
|
use strict;
|
|
|
|
use SL::DB::MetaSetup::BankTransaction;
|
|
use SL::DB::Manager::BankTransaction;
|
|
use SL::DB::Helper::LinkedRecords;
|
|
use Carp;
|
|
|
|
require SL::DB::Invoice;
|
|
require SL::DB::PurchaseInvoice;
|
|
|
|
__PACKAGE__->meta->initialize;
|
|
|
|
|
|
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
|
|
#__PACKAGE__->meta->make_manager_class;
|
|
|
|
sub compare_to {
|
|
my ($self, $other) = @_;
|
|
|
|
return 1 if $self->transdate && !$other->transdate;
|
|
return -1 if !$self->transdate && $other->transdate;
|
|
|
|
my $result = 0;
|
|
$result = $self->transdate <=> $other->transdate if $self->transdate;
|
|
return $result || ($self->id <=> $other->id);
|
|
}
|
|
|
|
sub linked_invoices {
|
|
my ($self) = @_;
|
|
|
|
#my $record_links = $self->linked_records(direction => 'both');
|
|
|
|
my @linked_invoices;
|
|
|
|
my $record_links = SL::DB::Manager::RecordLink->get_all(where => [ from_table => 'bank_transactions', from_id => $self->id ]);
|
|
"BankTransaction.pm.html#L303" data-txt="303">
|
next unless length($bankword)>2;
|
|
if ( $namestring =~ /\b$bankword\b/i ) {
|
|
$match++;
|
|
};
|
|
};
|
|
return $match;
|
|
};
|
|
|
|
|
|
sub not_assigned_amount {
|
|
my ($self) = @_;
|
|
|
|
my $not_assigned_amount = $self->amount - $self->invoice_amount;
|
|
die ("undefined state") if (abs($not_assigned_amount) > abs($self->amount));
|
|
|
|
return $not_assigned_amount;
|
|
|
|
}
|
|
sub closed_period {
|
|
my ($self) = @_;
|
|
|
|
# check for closed period
|
|
croak t8('Illegal date') unless ref $self->valutadate eq 'DateTime';
|
|
|
|
|
|
my $closedto = $::locale->parse_date_to_object($::instance_conf->get_closedto);
|
|
if ( ref $closedto && $self->valutadate < $closedto ) {
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
1;
|
|
|
|
__END__
|
|
|
|
=pod
|
|
|
|
=head1 NAME
|
|
|
|
SL::DB::BankTransaction
|
|
|
|
=head1 FUNCTIONS
|
|
|
|
=over 4
|
|
|
|
=item C<get_agreement_with_invoice $invoice>
|
|
|
|
Using a point system this function checks whether the bank transaction matches
|
|
an invoices, using a variety of tests, such as
|
|
|
|
=over 2
|
|
|
|
=item * amount
|
|
|
|
=item * amount_less_skonto
|
|
|
|
=item * payment date
|
|
|
|
=item * invoice number in purpose
|
|
|
|
=item * customer or vendor name in purpose
|
|
|
|
=item * account number matches account number of customer or vendor
|
|
|
|
=back
|
|
|
|
The total number of points, and the rules that matched, are returned.
|
|
|
|
Example:
|
|
my $bt = SL::DB::Manager::BankTransaction->find_by(id => 522);
|
|
my $invoice = SL::DB::Manager::Invoice->find_by(invnumber => '198');
|
|
my ($agreement,rule_matches) = $bt->get_agreement_with_invoice($invoice);
|
|
|
|
=item C<linked_invoices>
|
|
|
|
Returns an array of record objects (invoices, debit, credit or gl objects)
|
|
which are linked for this bank transaction.
|
|
|
|
Returns an empty array ref if no links are found.
|
|
Usage:
|
|
croak("No linked records at all") unless @{ $bt->linked_invoices() };
|
|
|
|
|
|
=item C<not_assigned_amount>
|
|
|
|
Returns the not open amount of this bank transaction.
|
|
Dies if the return amount is higher than the original amount.
|
|