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