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;
 
  13 __PACKAGE__->meta->add_relationship(
 
  15     type         => 'one to many',
 
  16     class        => 'SL::DB::InvoiceItem',
 
  17     column_map   => { id => 'trans_id' },
 
  19       with_objects => [ 'part' ]
 
  24 __PACKAGE__->meta->initialize;
 
  28 # it is assumed, that ordnumbers are unique here.
 
  29 sub first_order_by_ordnumber {
 
  32   my $orders = SL::DB::Manager::Order->get_all(
 
  34       ordnumber => $self->ordnumber,
 
  39   return first { $_->is_type('sales_order') } @{ $orders };
 
  42 sub abschlag_percentage {
 
  44   my $order        = $self->first_order_by_ordnumber or return;
 
  45   my $order_amount = $order->netamount               or return;
 
  46   return $self->abschlag
 
  47     ? $self->netamount / $order_amount
 
  53   die 'not a setter method' if @_;
 
  55   return $self->amount - $self->netamount;
 
  58 __PACKAGE__->meta->make_attr_helpers(taxamount => 'numeric(15,5)');