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