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