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