ab1bd49576c455e1b1eeca07cf0d9d0b545de4f4
[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::DB::Helper::Payment qw(:ALL);
13 use SL::Locale::String qw(t8);
14
15 # The calculator hasn't been adjusted for purchase invoices yet.
16 # use SL::DB::Helper::PriceTaxCalculator;
17
18 __PACKAGE__->meta->add_relationship(
19   invoiceitems   => {
20     type         => 'one to many',
21     class        => 'SL::DB::InvoiceItem',
22     column_map   => { id => 'trans_id' },
23     manager_args => { with_objects => [ 'part' ] }
24   },
25   sepa_export_items => {
26     type            => 'one to many',
27     class           => 'SL::DB::SepaExportItem',
28     column_map      => { id => 'ap_id' },
29     manager_args    => { with_objects => [ 'sepa_export' ] }
30   },
31   custom_shipto     => {
32     type            => 'one to one',
33     class           => 'SL::DB::Shipto',
34     column_map      => { id => 'trans_id' },
35     query_args      => [ module => 'AP' ],
36   },
37   transactions   => {
38     type         => 'one to many',
39     class        => 'SL::DB::AccTransaction',
40     column_map   => { id => 'trans_id' },
41     manager_args => { with_objects => [ 'chart' ],
42                       sort_by      => 'acc_trans_id ASC' }
43   },
44 );
45
46 __PACKAGE__->meta->initialize;
47
48 __PACKAGE__->attr_html('notes');
49 __PACKAGE__->attr_sorted('items');
50
51 sub items { goto &invoiceitems; }
52 sub add_items { goto &add_invoiceitems; }
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 sub link {
83   my ($self) = @_;
84
85   my $html;
86   $html   = SL::Presenter->get->purchase_invoice($self, display => 'inline') if $self->invoice;
87   $html   = SL::Presenter->get->ap_transaction($self, display => 'inline') if !$self->invoice;
88
89   return $html;
90 }
91
92 1;