ar/ap/gl - neues Relationship "transactions"
[kivitendo-erp.git] / SL / DB / PurchaseInvoice.pm
1 package SL::DB::PurchaseInvoice;
2
3 use strict;
4
5 use Carp;
6
7 use SL::DB::MetaSetup::PurchaseInvoice;
8 use SL::DB::Manager::PurchaseInvoice;
9 use SL::DB::Helper::LinkedRecords;
10 use SL::Locale::String qw(t8);
11
12 # The calculator hasn't been adjusted for purchase invoices yet.
13 # use SL::DB::Helper::PriceTaxCalculator;
14
15 __PACKAGE__->meta->add_relationship(
16   invoiceitems   => {
17     type         => 'one to many',
18     class        => 'SL::DB::InvoiceItem',
19     column_map   => { id => 'trans_id' },
20     manager_args => { with_objects => [ 'part' ] }
21   },
22   sepa_export_items => {
23     type            => 'one to many',
24     class           => 'SL::DB::SepaExportItem',
25     column_map      => { id => 'ap_id' },
26     manager_args    => { with_objects => [ 'sepa_export' ] }
27   },
28   custom_shipto     => {
29     type            => 'one to one',
30     class           => 'SL::DB::Shipto',
31     column_map      => { id => 'trans_id' },
32     query_args      => [ module => 'AP' ],
33   },
34   transactions   => {
35     type         => 'one to many',
36     class        => 'SL::DB::AccTransaction',
37     column_map   => { id => 'trans_id' },
38     manager_args => { with_objects => [ 'chart' ],
39                       sort_by      => 'acc_trans_id ASC' }
40   },
41 );
42
43 __PACKAGE__->meta->initialize;
44
45 sub items { goto &invoiceitems; }
46 sub add_items { goto &add_invoiceitems; }
47
48 sub items_sorted {
49   my ($self) = @_;
50
51   return [ sort {$a->position <=> $b->position } @{ $self->items } ];
52 }
53
54 sub is_sales {
55   # For compatibility with Order, DeliveryOrder
56   croak 'not an accessor' if @_ > 1;
57   return 0;
58 }
59
60 sub date {
61   goto &transdate;
62 }
63
64 sub reqdate {
65   goto &duedate;
66 }
67
68 sub customervendor {
69   goto &vendor;
70 }
71
72 sub abbreviation {
73   my $self = shift;
74
75   return t8('AP Transaction (abbreviation)') if !$self->invoice && !$self->storno;
76   return t8('AP Transaction (abbreviation)') . '(' . t8('Storno (one letter abbreviation)') . ')' if !$self->invoice && $self->storno;
77   return t8('Invoice (one letter abbreviation)'). '(' . t8('Storno (one letter abbreviation)') . ')' if $self->storno;
78   return t8('Invoice (one letter abbreviation)');
79
80 }
81
82 1;