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