Sonderbehandlung im template
[kivitendo-erp.git] / SL / DB / DeliveryOrder.pm
1 package SL::DB::DeliveryOrder;
2
3 use strict;
4
5 use Carp;
6
7 use SL::DB::MetaSetup::DeliveryOrder;
8 use SL::DB::Manager::DeliveryOrder;
9 use SL::DB::Helper::LinkedRecords;
10 use SL::DB::Helper::TransNumberGenerator;
11 use SL::DB::Order;
12
13 use List::Util qw(first);
14
15 __PACKAGE__->meta->add_relationship(orderitems => { type         => 'one to many',
16                                                     class        => 'SL::DB::DeliveryOrderItem',
17                                                     column_map   => { id => 'delivery_order_id' },
18                                                     manager_args => { with_objects => [ 'part' ] }
19                                                   },
20                                    );
21
22 __PACKAGE__->meta->initialize;
23
24 # methods
25
26 sub items { goto &orderitems; }
27
28 sub sales_order {
29   my $self   = shift;
30   my %params = @_;
31
32   my $orders = SL::DB::Manager::Order->get_all(
33     query => [
34       ordnumber => $self->ordnumber,
35       @{ $params{query} || [] },
36     ],
37   );
38
39   return first { $_->is_type('sales_order') } @{ $orders };
40 }
41
42 sub type {
43   return shift->customer_id ? 'sales_delivery_order' : 'purchase_delivery_order';
44 }
45
46 sub displayable_state {
47   my ($self) = @_;
48
49   return join '; ',
50     ($self->closed    ? $::locale->text('closed')    : $::locale->text('open')),
51     ($self->delivered ? $::locale->text('delivered') : $::locale->text('not delivered'));
52 }
53
54 1;