Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[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 $link_start = '';
46   my $link_end   = '';
47   unless ($params{no_link}) {
48     my $action  = $::instance_conf->get_feature_experimental_order
49                 ? 'controller.pl?action=Order/edit'
50                 : 'oe.pl?action=edit';
51     $link_start = '<a href="' . $action . '&amp;type=' . $type . '&amp;id=' . escape($order->id) . '">';
52     $link_end   = '</a>';
53   }
54
55   my $text = join '', ($link_start, escape($order->$number_method), $link_end);
56
57   is_escaped($text);
58 }
59
60 1;
61
62
63 __END__
64
65 =pod
66
67 =encoding utf8
68
69 =head1 NAME
70
71 SL::Presenter::Order - Presenter module for Rose::DB objects for sales
72 quotations, sales orders, requests for quotations and purchase orders
73
74 =head1 SYNOPSIS
75
76   # Sales quotations:
77   my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('sales_quotation') ]);
78   my $html   = SL::Presenter::Order::sales_quotation($object, display => 'inline');
79
80   # Sales orders:
81   my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('sales_order') ]);
82   my $html   = SL::Presenter::Order::sales_order($object, display => 'inline');
83
84   # Requests for quotations:
85   my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('request_quotation') ]);
86   my $html   = SL::Presenter::Order::request_quotation($object, display => 'inline');
87
88   # Purchase orders:
89   my $object = SL::DB::Manager::Order->get_first(where => [ SL::DB::Manager::Order->type_filter('purchase_order') ]);
90   my $html   = SL::Presenter::Order::purchase_order($object, display => 'inline');
91
92 =head1 FUNCTIONS
93
94 =over 4
95
96 =item C<sales_quotation $object, %params>
97
98 Returns a rendered version (actually an instance of
99 L<SL::Presenter::EscapedText>) of the sales quotation object
100 C<$object>.
101
102 C<%params> can include:
103
104 =over 2
105
106 =item * display
107
108 Either C<inline> (the default) or C<table-cell>. At the moment both
109 representations are identical and produce the objects's
110 quotation number linked to the corresponding 'edit' action.
111
112 =item * no_link
113
114 If falsish (the default) then the order number will be linked to the
115 "edit quotation" dialog from the sales menu.
116
117 =back
118
119 =item C<sales_order $object, %params>
120
121 Returns a rendered version (actually an instance of
122 L<SL::Presenter::EscapedText>) of the sales order object C<$object>.
123
124 C<%params> can include:
125
126 =over 2
127
128 =item * display
129
130 Either C<inline> (the default) or C<table-cell>. At the moment both
131 representations are identical and produce the objects's
132 order number linked to the corresponding 'edit' action.
133
134 =item * no_link
135
136 If falsish (the default) then the  order number will be linked
137 to the "edit order" dialog from the sales menu.
138
139 =back
140
141 =item C<request_quotation $object, %params>
142
143 Returns a rendered version (actually an instance of
144 L<SL::Presenter::EscapedText>) of the request for quotation object
145 C<$object>.
146
147 C<%params> can include:
148
149 =over 2
150
151 =item * display
152
153 Either C<inline> (the default) or C<table-cell>. At the moment both
154 representations are identical and produce the objects's
155 quotation number linked to the corresponding 'edit' action.
156
157 =item * no_link
158
159 If falsish (the default) then the order number will be linked to the
160 "edit request for quotation" dialog from the purchase menu.
161
162 =back
163
164 =item C<purchase_order $object, %params>
165
166 Returns a rendered version (actually an instance of
167 L<SL::Presenter::EscapedText>) of the purchase order object
168 C<$object>.
169
170 C<%params> can include:
171
172 =over 2
173
174 =item * display
175
176 Either C<inline> (the default) or C<table-cell>. At the moment both
177 representations are identical and produce the objects's
178 order number linked to the corresponding 'edit' action.
179
180 =item * no_link
181
182 If falsish (the default) then the  order number will be linked
183 to the "edit order" dialog from the purchase menu.
184
185 =back
186
187 =back
188
189 =head1 BUGS
190
191 Nothing here yet.
192
193 =head1 AUTHOR
194
195 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
196
197 =cut