Bankerweiterung - Zwischenstand, erster Entwurf
[kivitendo-erp.git] / SL / DB / AccTransaction.pm
1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
3
4 package SL::DB::AccTransaction;
5
6 use strict;
7
8 use SL::DB::MetaSetup::AccTransaction;
9
10 use SL::DB::GLTransaction;
11 require SL::DB::Invoice;
12 require SL::DB::PurchaseInvoice;
13
14 __PACKAGE__->meta->add_relationship(
15   ar => {
16     type         => 'many to one',
17     class        => 'SL::DB::Invoice',
18     column_map   => { trans_id => 'id' },
19   },
20   ap => {
21     type         => 'many to one',
22     class        => 'SL::DB::PurchaseInvoice',
23     column_map   => { trans_id => 'id' },
24   },
25   gl => {
26     type         => 'many to one',
27     class        => 'SL::DB::GLTransaction',
28     column_map   => { trans_id => 'id' },
29   },
30 );
31
32 __PACKAGE__->meta->initialize;
33
34 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
35 __PACKAGE__->meta->make_manager_class;
36
37 sub record {
38   my ($self) = @_;
39
40   my @classes = qw(Invoice PurchaseInvoice GLTransaction);
41
42   foreach my $class ( @classes ) {
43     $class = 'SL::DB::' . $class;
44     my $record = $class->new(id => $self->trans_id);
45     return $record if $record->load(speculative => 1);
46   };
47
48 };
49
50 sub get_transaction {
51   my ($self) = @_;
52
53   my $transaction = SL::DB::Manager::GLTransaction->find_by(id => $self->trans_id);
54   $transaction = SL::DB::Manager::Invoice->find_by(id => $self->trans_id)         if not defined $transaction;
55   $transaction = SL::DB::Manager::PurchaseInvoice->find_by(id => $self->trans_id) if not defined $transaction;
56
57   return $transaction;
58 }
59
60 1;
61 __END__
62
63 =pod
64
65 =encoding utf8
66
67 =head1 NAME
68
69 SL::DB::AccTransaction: Rose model for transactions (table "acc_trans")
70
71 =head1 FUNCTIONS
72
73 =over 4
74
75 =item C<record>
76
77 Returns the ar, ap or gl object of the current acc_trans object.
78
79 Example:
80   my $acc_trans = SL::DB::Manager::AccTransaction->find_by( trans_id => '427' );
81   my $record = $acc_trans->record;
82
83 Each acc_trans entry is associated with an ar, ap or gl record. If we only have
84 an acc_trans object, and we want to find out which kind of record it belongs
85 to, we have to look for its trans_id in the tables ar, ap and gl. C<record>
86 does this for you and returns an Invoice, PurchaseInvoice or GLTransaction
87 object.
88
89 We use the Rose::DB::Object load function with the C<speculative> parameter for
90 each record type, which returns true if the load was successful, so we don't
91 bother to check the ref of the object.
92
93 =back
94
95 =head1 BUGS
96
97 Nothing here yet.
98
99 =head1 AUTHOR
100
101 G. Richardson E<lt>information@kivitendo-premium.deE<gt>
102
103 =cut