19d8483ec15fa9da62a610bbf3cf26e66433e5c7
[kivitendo-erp.git] / SL / Presenter / Order.pm
1 package SL::Presenter::Order;
2
3 use strict;
4
5 use parent qw(Exporter);
6
7 use Exporter qw(import);
8 our @EXPORT = qw(sales_quotation sales_order request_quotation purchase_order);
9
10 use Carp;
11
12 sub sales_quotation {
13   my ($self, $order, %params) = @_;
14
15   return _oe_record($self, $order, 'sales_quotation', %params);
16 }
17
18 sub sales_order {
19   my ($self, $order, %params) = @_;
20
21   return _oe_record($self, $order, 'sales_order', %params);
22 }
23
24 sub request_quotation {
25   my ($self, $order, %params) = @_;
26
27   return _oe_record($self, $order, 'request_quotation', %params);
28 }
29
30 sub purchase_order {
31   my ($self, $order, %params) = @_;
32
33   return _oe_record($self, $order, 'purchase_order', %params);
34 }
35
36 sub _oe_record {
37   my ($self, $order, $type, %params) = @_;
38
39   $params{display} ||= 'inline';
40
41   croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
42
43   my $number_method = $order->quotation ? 'quonumber' : 'ordnumber';
44
45   my $text = join '', (
46     $params{no_link} ? '' : '<a href="oe.pl?action=edit&amp;type=' . $type . '&amp;id=' . $self->escape($order->id) . '">',
47     $self->escape($order->$number_method),
48     $params{no_link} ? '' : '</a>',
49   );
50   return $self->escaped_text($text);
51 }
52
53 1;
54
55
56 __END__
57
58 =pod
59
60 =encoding utf8
61
62 =head1 NAME
63
64 SL::Presenter::Order - Presenter module for Rose::DB objects for sales
65 quotations, sales orders, requests for quotations and purchase orders
66
67 =head1 SYNOPSIS
68
69   # Sales quotations:
70   my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('sales_quotation') ]);
71   my $html   = SL::Presenter->get->sales_quotation($object, display => 'inline');
72
73   # Sales orders:
74   my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('sales_order') ]);
75   my $html   = SL::Presenter->get->sales_order($object, display => 'inline');
76
77   # Requests for quotations:
78   my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('request_quotation') ]);
79   my $html   = SL::Presenter->get->request_quotation($object, display => 'inline');
80
81   # Purchase orders:
82   my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('purchase_order') ]);
83   my $html   = SL::Presenter->get->purchase_order($object, display => 'inline');
84
85 =head1 FUNCTIONS
86
87 =over 4
88
89 =item C<sales_quotation $object, %params>
90
91 Returns a rendered version (actually an instance of
92 L<SL::Presenter::EscapedText>) of the sales quotation object
93 C<$object>.
94
95 C<%params> can include:
96
97 =over 2
98
99 =item * display
100
101 Either C<inline> (the default) or C<table-cell>. At the moment both
102 representations are identical and produce the objects's
103 quotation number linked to the corresponding 'edit' action.
104
105 =item * no_link
106
107 If falsish (the default) then the order number will be linked to the
108 "edit quotation" dialog from the sales menu.
109
110 =back
111
112 =item C<sales_order $object, %params>
113
114 Returns a rendered version (actually an instance of
115 L<SL::Presenter::EscapedText>) of the sales order object C<$object>.
116
117 C<%params> can include:
118
119 =over 2
120
121 =item * display
122
123 Either C<inline> (the default) or C<table-cell>. At the moment both
124 representations are identical and produce the objects's
125 order number linked to the corresponding 'edit' action.
126
127 =item * no_link
128
129 If falsish (the default) then the  order number will be linked
130 to the "edit order" dialog from the sales menu.
131
132 =back
133
134 =item C<request_quotation $object, %params>
135
136 Returns a rendered version (actually an instance of
137 L<SL::Presenter::EscapedText>) of the request for quotation object
138 C<$object>.
139
140 C<%params> can include:
141
142 =over 2
143
144 =item * display
145
146 Either C<inline> (the default) or C<table-cell>. At the moment both
147 representations are identical and produce the objects's
148 quotation number linked to the corresponding 'edit' action.
149
150 =item * no_link
151
152 If falsish (the default) then the order number will be linked to the
153 "edit request for quotation" dialog from the purchase menu.
154
155 =back
156
157 =item C<purchase_order $object, %params>
158
159 Returns a rendered version (actually an instance of
160 L<SL::Presenter::EscapedText>) of the purchase order object
161 C<$object>.
162
163 C<%params> can include:
164
165 =over 2
166
167 =item * display
168
169 Either C<inline> (the default) or C<table-cell>. At the moment both
170 representations are identical and produce the objects's
171 order number linked to the corresponding 'edit' action.
172
173 =item * no_link
174
175 If falsish (the default) then the  order number will be linked
176 to the "edit order" dialog from the purchase menu.
177
178 =back
179
180 =back
181
182 =head1 BUGS
183
184 Nothing here yet.
185
186 =head1 AUTHOR
187
188 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
189
190 =cut