1 package SL::DB::PurchaseInvoice;
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);
15 # The calculator hasn't been adjusted for purchase invoices yet.
16 # use SL::DB::Helper::PriceTaxCalculator;
18 __PACKAGE__->meta->add_relationship(
20 type => 'one to many',
21 class => 'SL::DB::InvoiceItem',
22 column_map => { id => 'trans_id' },
23 manager_args => { with_objects => [ 'part' ] }
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' ] }
32 type => 'many to many',
33 map_class => 'SL::DB::SepaExportItem',
35 map_to => 'sepa_export',
39 class => 'SL::DB::Shipto',
40 column_map => { id => 'trans_id' },
41 query_args => [ module => 'AP' ],
44 type => 'one to many',
45 class => 'SL::DB::AccTransaction',
46 column_map => { id => 'trans_id' },
47 manager_args => { with_objects => [ 'chart' ],
48 sort_by => 'acc_trans_id ASC' }
52 __PACKAGE__->meta->initialize;
54 __PACKAGE__->attr_html('notes');
55 __PACKAGE__->attr_sorted('items');
57 sub items { goto &invoiceitems; }
58 sub add_items { goto &add_invoiceitems; }
59 sub record_number { goto &invnumber; };
62 # For compatibility with Order, DeliveryOrder
63 croak 'not an accessor' if @_ > 1;
82 return t8('AP Transaction (abbreviation)') if !$self->invoice && !$self->storno;
83 return t8('AP Transaction (abbreviation)') . '(' . t8('Storno (one letter abbreviation)') . ')' if !$self->invoice && $self->storno;
84 return t8('Invoice (one letter abbreviation)'). '(' . t8('Storno (one letter abbreviation)') . ')' if $self->storno;
85 return t8('Invoice (one letter abbreviation)');
93 $html = SL::Presenter->get->purchase_invoice($self, display => 'inline') if $self->invoice;
94 $html = SL::Presenter->get->ap_transaction($self, display => 'inline') if !$self->invoice;
102 return 'ap_transaction' if !$self->invoice;
103 return 'purchase_invoice';
106 sub displayable_type {
109 return t8('AP Transaction') if $self->invoice_type eq 'ap_transaction';
110 return t8('Purchase Invoice');
113 sub displayable_name {
114 join ' ', grep $_, map $_[0]->$_, qw(displayable_type record_number);