Auslesen der Standardwährung
[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   periodic_invoices_config => {
22     type                   => 'one to one',
23     class                  => 'SL::DB::PeriodicInvoicesConfig',
24     column_map             => { id => 'oe_id' },
25   },
26   periodic_invoices        => {
27     type                   => 'one to many',
28     class                  => 'SL::DB::PeriodicInvoice',
29     column_map             => { id => 'oe_id' },
30   },
31 );
32
33 __PACKAGE__->meta->initialize;
34
35 # methods
36
37 sub items { goto &orderitems; }
38
39 sub type {
40   my $self = shift;
41
42   return 'sales_order'       if $self->customer_id && ! $self->quotation;
43   return 'purchase_order'    if $self->vendor_id   && ! $self->quotation;
44   return 'sales_quotation'   if $self->customer_id &&   $self->quotation;
45   return 'request_quotation' if $self->vendor_id   &&   $self->quotation;
46
47   return;
48 }
49
50 sub is_type {
51   return shift->type eq shift;
52 }
53
54 sub invoices {
55   my $self   = shift;
56   my %params = @_;
57
58   if ($self->quotation) {
59     return [];
60   } else {
61     return SL::DB::Manager::Invoice->get_all(
62       query => [
63         ordnumber => $self->ordnumber,
64         @{ $params{query} || [] },
65       ]
66     );
67   }
68 }
69
70 sub abschlag_invoices {
71   return shift()->invoices(query => [ abschlag => 1 ]);
72 }
73
74 sub end_invoice {
75   return shift()->invoices(query => [ abschlag => 0 ]);
76 }
77
78 1;
79
80 __END__
81
82 =head1 NAME
83
84 SL::DB::Order - Order Datenbank Objekt.
85
86 =head1 FUNCTIONS
87
88 =head2 type
89
90 Returns one of the following string types:
91
92 =over 4
93
94 =item saes_order
95
96 =item purchase_order
97
98 =item sales_quotation
99
100 =item request_quotation
101
102 =back
103
104 =head2 is_type TYPE
105
106 Rreturns true if the order is of the given type.
107
108 =head1 BUGS
109
110 Nothing here yet.
111
112 =head1 AUTHOR
113
114 Sven Schöling <s.schoeling@linet-services.de>
115
116 =cut