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