3245e4b91fa25f85335d08ef7f326530c5038388
[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 # The calculator hasn't been adjusted for purchase invoices yet.
11 # use SL::DB::Helper::PriceTaxCalculator;
12
13 __PACKAGE__->meta->add_relationship(
14   invoiceitems   => {
15     type         => 'one to many',
16     class        => 'SL::DB::InvoiceItem',
17     column_map   => { id => 'trans_id' },
18     manager_args => { with_objects => [ 'part' ] }
19   },
20   sepa_export_items => {
21     type            => 'one to many',
22     class           => 'SL::DB::SepaExportItem',
23     column_map      => { id => 'ap_id' },
24     manager_args    => { with_objects => [ 'sepa_export' ] }
25   },
26   custom_shipto     => {
27     type            => 'one to one',
28     class           => 'SL::DB::Shipto',
29     column_map      => { id => 'trans_id' },
30     query_args      => [ module => 'AP' ],
31   },
32 );
33
34 __PACKAGE__->meta->initialize;
35
36 sub items { goto &invoiceitems; }
37 sub add_items { goto &add_invoiceitems; }
38
39 sub items_sorted {
40   my ($self) = @_;
41
42   return [ sort {$a->id <=> $b->id } @{ $self->items } ];
43 }
44
45 sub is_sales {
46   # For compatibility with Order, DeliveryOrder
47   croak 'not an accessor' if @_ > 1;
48   return 0;
49 }
50
51 sub date {
52   goto &transdate;
53 }
54
55 1;