Objektmethode date für GLTransaction
[kivitendo-erp.git] / SL / DB / GLTransaction.pm
1 package SL::DB::GLTransaction;
2
3 use strict;
4
5 use SL::DB::MetaSetup::GLTransaction;
6 use SL::Locale::String qw(t8);
7 use List::Util qw(sum);
8
9 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
10 __PACKAGE__->meta->make_manager_class;
11
12 __PACKAGE__->meta->add_relationship(
13   transactions   => {
14     type         => 'one to many',
15     class        => 'SL::DB::AccTransaction',
16     column_map   => { id => 'trans_id' },
17     manager_args => {
18       with_objects => [ 'chart' ],
19       sort_by      => 'acc_trans_id ASC',
20     },
21   },
22 );
23
24 __PACKAGE__->meta->initialize;
25
26 sub abbreviation {
27   my $self = shift;
28
29   my $abbreviation = $::locale->text('GL Transaction (abbreviation)');
30   $abbreviation   .= "(" . $::locale->text('Storno (one letter abbreviation)') . ")" if $self->storno;
31   return $abbreviation;
32 }
33
34 sub displayable_type {
35   return t8('GL Transaction');
36 }
37
38 sub oneline_summary {
39   my ($self) = @_;
40   my $amount =  sum map { $_->amount if $_->amount > 0 } @{$self->transactions};
41   $amount = $::form->format_amount(\%::myconfig, $amount, 2);
42   return sprintf("%s: %s %s %s (%s)", $self->abbreviation, $self->description, $self->reference, $amount, $self->transdate->to_kivitendo);
43 }
44
45 sub link {
46   my ($self) = @_;
47
48   my $html;
49   $html   = $self->presenter->gl_transaction(display => 'inline');
50
51   return $html;
52 }
53
54 sub invnumber {
55   return $_[0]->reference;
56 }
57
58 sub date { goto &gldate }
59
60 1;