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