Sammelcommit Bankerweiterung und Skonto
[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::LinkedRecords;
11 use SL::DB::Helper::Payment qw(:ALL);
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
49 sub items { goto &invoiceitems; }
50 sub add_items { goto &add_invoiceitems; }
51
52 sub items_sorted {
53   my ($self) = @_;
54
55   return [ sort {$a->position <=> $b->position } @{ $self->items } ];
56 }
57
58 sub is_sales {
59   # For compatibility with Order, DeliveryOrder
60   croak 'not an accessor' if @_ > 1;
61   return 0;
62 }
63
64 sub date {
65   goto &transdate;
66 }
67
68 sub reqdate {
69   goto &duedate;
70 }
71
72 sub customervendor {
73   goto &vendor;
74 }
75
76 sub abbreviation {
77   my $self = shift;
78
79   return t8('AP Transaction (abbreviation)') if !$self->invoice && !$self->storno;
80   return t8('AP Transaction (abbreviation)') . '(' . t8('Storno (one letter abbreviation)') . ')' if !$self->invoice && $self->storno;
81   return t8('Invoice (one letter abbreviation)'). '(' . t8('Storno (one letter abbreviation)') . ')' if $self->storno;
82   return t8('Invoice (one letter abbreviation)');
83
84 };
85
86 sub link {
87   my ($self) = @_;
88
89   my $html;
90   $html   = SL::Presenter->get->purchase_invoice($self, display => 'inline') if $self->invoice;
91   $html   = SL::Presenter->get->ap_transaction($self, display => 'inline') if !$self->invoice;
92
93   return $html;
94 }
95
96 1;