Payment Helper setzt $self->transactions zurück
[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 use Rose::DB::Object::Helpers qw(has_loaded_related forget_related);
15
16 # The calculator hasn't been adjusted for purchase invoices yet.
17 # use SL::DB::Helper::PriceTaxCalculator;
18
19 __PACKAGE__->meta->add_relationship(
20   invoiceitems   => {
21     type         => 'one to many',
22     class        => 'SL::DB::InvoiceItem',
23     column_map   => { id => 'trans_id' },
24     manager_args => { with_objects => [ 'part' ] }
25   },
26   sepa_export_items => {
27     type            => 'one to many',
28     class           => 'SL::DB::SepaExportItem',
29     column_map      => { id => 'ap_id' },
30     manager_args    => { with_objects => [ 'sepa_export' ] }
31   },
32   sepa_exports      => {
33     type            => 'many to many',
34     map_class       => 'SL::DB::SepaExportItem',
35     map_from        => 'ap',
36     map_to          => 'sepa_export',
37   },
38   custom_shipto     => {
39     type            => 'one to one',
40     class           => 'SL::DB::Shipto',
41     column_map      => { id => 'trans_id' },
42     query_args      => [ module => 'AP' ],
43   },
44   transactions   => {
45     type         => 'one to many',
46     class        => 'SL::DB::AccTransaction',
47     column_map   => { id => 'trans_id' },
48     manager_args => { with_objects => [ 'chart' ],
49                       sort_by      => 'acc_trans_id ASC' }
50   },
51 );
52
53 __PACKAGE__->meta->initialize;
54
55 __PACKAGE__->attr_html('notes');
56 __PACKAGE__->attr_sorted('items');
57
58 sub items { goto &invoiceitems; }
59 sub add_items { goto &add_invoiceitems; }
60 sub record_number { goto &invnumber; };
61
62 sub is_sales {
63   # For compatibility with Order, DeliveryOrder
64   croak 'not an accessor' if @_ > 1;
65   return 0;
66 }
67
68 sub date {
69   goto &transdate;
70 }
71
72 sub reqdate {
73   goto &duedate;
74 }
75
76 sub customervendor {
77   goto &vendor;
78 }
79
80 sub abbreviation {
81   my $self = shift;
82
83   return t8('AP Transaction (abbreviation)') if !$self->invoice && !$self->storno;
84   return t8('AP Transaction (abbreviation)') . '(' . t8('Storno (one letter abbreviation)') . ')' if !$self->invoice && $self->storno;
85   return t8('Invoice (one letter abbreviation)'). '(' . t8('Storno (one letter abbreviation)') . ')' if $self->storno;
86   return t8('Invoice (one letter abbreviation)');
87
88 };
89
90 sub link {
91   my ($self) = @_;
92
93   my $html;
94   $html   = SL::Presenter->get->purchase_invoice($self, display => 'inline') if $self->invoice;
95   $html   = SL::Presenter->get->ap_transaction($self, display => 'inline') if !$self->invoice;
96
97   return $html;
98 }
99
100 sub invoice_type {
101   my ($self) = @_;
102
103   return 'ap_transaction' if !$self->invoice;
104   return 'purchase_invoice';
105 }
106
107 sub displayable_type {
108   my ($self) = @_;
109
110   return t8('AP Transaction')    if $self->invoice_type eq 'ap_transaction';
111   return t8('Purchase Invoice');
112 }
113
114 sub displayable_name {
115   join ' ', grep $_, map $_[0]->$_, qw(displayable_type record_number);
116 };
117
118 1;