Attribute Helper umgeschrieben.
[kivitendo-erp.git] / SL / DB / Order.pm
1 package SL::DB::Order;
2
3 use strict;
4
5 use SL::RecordLinks;
6
7 use SL::DB::MetaSetup::Order;
8 use SL::DB::Manager::Order;
9 use SL::DB::Invoice;
10
11 __PACKAGE__->meta->add_relationship(
12   orderitems => {
13     type         => 'one to many',
14     class        => 'SL::DB::OrderItem',
15     column_map   => { id => 'trans_id' },
16     manager_args => {
17       with_objects => [ 'part' ]
18     }
19   }
20 );
21
22 __PACKAGE__->meta->initialize;
23
24 # methods
25
26 sub type {
27   my $self = shift;
28
29   return 'sales_order'       if $self->customer_id && ! $self->quotation;
30   return 'purchase_order'    if $self->vendor_id   && ! $self->quotation;
31   return 'sales_quotation'   if $self->customer_id &&   $self->quotation;
32   return 'request_quotation' if $self->vendor_id   &&   $self->quotation;
33
34   return;
35 }
36
37 sub is_type {
38   return shift->type eq shift;
39 }
40
41 sub invoices {
42   my $self   = shift;
43   my %params = @_;
44
45   if ($self->quotation) {
46     return [];
47   } else {
48     return SL::DB::Manager::Invoice->get_all(
49       query => [
50         ordnumber => $self->ordnumber,
51         @{ $params{query} || [] },
52       ]
53     );
54   }
55 }
56
57 sub abschlag_invoices {
58   return shift()->invoices(query => [ abschlag => 1 ]);
59 }
60
61 sub end_invoice {
62   return shift()->invoices(query => [ abschlag => 0 ]);
63 }
64
65 1;
66
67 __END__
68
69 =head1 NAME
70
71 SL::DB::Order - Order Datenbank Objekt.
72
73 =head1 FUNCTIONS
74
75 =head2 type
76
77 Returns one of the following string types:
78
79 =over 4
80
81 =item saes_order
82
83 =item purchase_order
84
85 =item sales_quotation
86
87 =item request_quotation
88
89 =back
90
91 =head2 is_type TYPE
92
93 Rreturns true if the order is of the given type.
94
95 =head1 BUGS
96
97 Nothing here yet.
98
99 =head1 AUTHOR
100
101   Sven Schöling <s.schoeling@linet-services.de>
102
103 =cut