PriceRule: customervendor accessor in Rechnungen
[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 );
35
36 __PACKAGE__->meta->initialize;
37
38 sub items { goto &invoiceitems; }
39 sub add_items { goto &add_invoiceitems; }
40
41 sub items_sorted {
42   my ($self) = @_;
43
44   return [ sort {$a->id <=> $b->id } @{ $self->items } ];
45 }
46
47 sub is_sales {
48   # For compatibility with Order, DeliveryOrder
49   croak 'not an accessor' if @_ > 1;
50   return 0;
51 }
52
53 sub date {
54   goto &transdate;
55 }
56
57 sub reqdate {
58   goto &duedate;
59 }
60
61 sub customervendor {
62   goto &vendor;
63 }
64
65 sub abbreviation {
66   my $self = shift;
67
68   return t8('AP Transaction (abbreviation)') if !$self->invoice && !$self->storno;
69   return t8('AP Transaction (abbreviation)') . '(' . t8('Storno (one letter abbreviation)') . ')' if !$self->invoice && $self->storno;
70   return t8('Invoice (one letter abbreviation)'). '(' . t8('Storno (one letter abbreviation)') . ')' if $self->storno;
71   return t8('Invoice (one letter abbreviation)');
72
73 }
74
75 1;