1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
4 package SL::DB::Invoice;
8 use List::Util qw(first);
10 use SL::DB::MetaSetup::Invoice;
11 use SL::DB::Manager::Invoice;
12 use SL::DB::Helper::LinkedRecords;
13 use SL::DB::Helper::PriceTaxCalculator;
15 __PACKAGE__->meta->add_relationship(
17 type => 'one to many',
18 class => 'SL::DB::InvoiceItem',
19 column_map => { id => 'trans_id' },
21 with_objects => [ 'part' ]
26 __PACKAGE__->meta->initialize;
30 sub items { goto &invoiceitems; }
32 # it is assumed, that ordnumbers are unique here.
33 sub first_order_by_ordnumber {
36 my $orders = SL::DB::Manager::Order->get_all(
38 ordnumber => $self->ordnumber,
43 return first { $_->is_type('sales_order') } @{ $orders };
46 sub abschlag_percentage {
48 my $order = $self->first_order_by_ordnumber or return;
49 my $order_amount = $order->netamount or return;
50 return $self->abschlag
51 ? $self->netamount / $order_amount
57 die 'not a setter method' if @_;
59 return $self->amount - $self->netamount;
62 __PACKAGE__->meta->make_attr_helpers(taxamount => 'numeric(15,5)');