Revision 65d8e1fe
Von Tamino Steinert vor etwa 1 Monat hinzugefügt
SL/Controller/Reclamation.pm | ||
---|---|---|
6 | 6 |
use SL::Helper::Flash qw(flash_later); |
7 | 7 |
use SL::HTML::Util; |
8 | 8 |
use SL::Presenter::Tag qw(select_tag hidden_tag div_tag); |
9 |
use SL::Presenter::ReclamationFilter qw(filter);
|
|
9 |
use SL::Presenter::Filter::Reclamation;
|
|
10 | 10 |
use SL::Locale::String qw(t8); |
11 | 11 |
use SL::SessionFile::Random; |
12 | 12 |
use SL::PriceSource; |
... | ... | |
216 | 216 |
sub action_list { |
217 | 217 |
my ($self) = @_; |
218 | 218 |
|
219 |
$::form->{filter} ||= {}; |
|
220 |
|
|
219 | 221 |
$self->_setup_search_action_bar; |
220 |
$self->prepare_report; |
|
222 |
my $report = $self->prepare_report;
|
|
221 | 223 |
$self->report_generator_list_objects( |
222 |
report => $self->{report},
|
|
224 |
report => $report,
|
|
223 | 225 |
objects => $self->models->get, |
224 | 226 |
options => { |
225 | 227 |
action_bar_additional_submit_values => { |
... | ... | |
1186 | 1188 |
closed => t8('Closed'), |
1187 | 1189 |
}, |
1188 | 1190 |
query => [ |
1189 |
SL::DB::Manager::Reclamation->type_filter($self->type),
|
|
1191 |
(record_type => $self->type),
|
|
1190 | 1192 |
(salesman_id => SL::DB::Manager::Employee->current->id) x ($self->reclamation->is_sales && !$::auth->assert('sales_all_edit', 1)), |
1191 | 1193 |
(employee_id => SL::DB::Manager::Employee->current->id) x ($self->reclamation->is_sales && !$::auth->assert('sales_all_edit', 1)), |
1192 | 1194 |
(employee_id => SL::DB::Manager::Employee->current->id) x (!$self->reclamation->is_sales && !$::auth->assert('purchase_all_edit', 1)), |
... | ... | |
1672 | 1674 |
my ($self) = @_; |
1673 | 1675 |
|
1674 | 1676 |
my $report = SL::ReportGenerator->new(\%::myconfig, $::form); |
1675 |
$report->{title} = t8('Sales Reclamations'); |
|
1676 |
if ($self->type eq PURCHASE_RECLAMATION_TYPE()){ |
|
1677 |
$report->{title} = t8('Purchase Reclamations'); |
|
1678 |
} |
|
1679 | 1677 |
|
1680 | 1678 |
$self->models->disable_plugin('paginated') if $report->{options}{output_format} =~ /^(pdf|csv)$/i; |
1681 | 1679 |
$self->models->add_additional_url_params(type => $self->type); |
... | ... | |
1683 | 1681 |
|
1684 | 1682 |
my $callback = $self->models->get_callback; |
1685 | 1683 |
|
1686 |
$self->{report} = $report; |
|
1687 |
|
|
1688 | 1684 |
# TODO: shipto_id is not linked to custom_shipto |
1689 | 1685 |
my @columns_order = qw( |
1690 | 1686 |
id |
... | ... | |
1892 | 1888 |
unless ($::form->{active_in_report}) { |
1893 | 1889 |
$::form->{active_in_report}->{$_} = 1 foreach @default_columns; |
1894 | 1890 |
} |
1891 |
|
|
1895 | 1892 |
$self->models->add_additional_url_params( |
1896 |
active_in_report => $::form->{active_in_report}); |
|
1897 |
map { $column_defs{$_}->{visible} = $::form->{active_in_report}->{"$_"} } |
|
1898 |
keys %column_defs; |
|
1893 |
active_in_report => $::form->{active_in_report} |
|
1894 |
); |
|
1895 |
|
|
1896 |
$column_defs{$_}->{visible} = $::form->{active_in_report}->{"$_"} || 0 |
|
1897 |
foreach keys %column_defs; |
|
1899 | 1898 |
|
1900 | 1899 |
## add cvars TODO: Add own cvars |
1901 | 1900 |
#my %cvar_column_defs = map { |
... | ... | |
1915 | 1914 |
# make all sortable |
1916 | 1915 |
my @sortable = keys %column_defs; |
1917 | 1916 |
|
1918 |
my $filter_html = SL::Presenter::ReclamationFilter::filter(
|
|
1917 |
my $filter_html = SL::Presenter::Filter::Reclamation::filter(
|
|
1919 | 1918 |
$::form->{filter}, $self->type, active_in_report => $::form->{active_in_report} |
1920 | 1919 |
); |
1921 | 1920 |
|
... | ... | |
1940 | 1939 |
$report->set_columns(%column_defs); |
1941 | 1940 |
$report->set_column_order(@columns_order); |
1942 | 1941 |
#$report->set_export_options(qw(list filter), @cvar_column_form_names); TODO: for cvars |
1943 |
$report->set_export_options(qw(list filter active_in_report));
|
|
1942 |
$report->set_export_options('list', qw(filter active_in_report));
|
|
1944 | 1943 |
$report->set_options_from_form; |
1945 | 1944 |
$self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable); |
1945 |
|
|
1946 |
return $report; |
|
1946 | 1947 |
} |
1947 | 1948 |
|
1948 | 1949 |
sub _setup_edit_action_bar { |
... | ... | |
2139 | 2140 |
$bar->add( |
2140 | 2141 |
action => [ |
2141 | 2142 |
t8('Update'), |
2142 |
submit => [ '#search_form', { action => 'Reclamation/list', type => $self->type } ],
|
|
2143 |
submit => [ '#filter_form', { action => 'Reclamation/list', type => $self->type } ],
|
|
2143 | 2144 |
accesskey => 'enter', |
2144 | 2145 |
], |
2145 | 2146 |
link => [ |
SL/Presenter/Filter.pm | ||
---|---|---|
1 |
package SL::Presenter::Filter; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use SL::Presenter::EscapedText qw(escape is_escaped); |
|
6 |
use SL::Presenter::Tag qw(html_tag input_tag select_tag date_tag checkbox_tag); |
|
7 |
use SL::Locale::String qw(t8); |
|
8 |
|
|
9 |
use Carp; |
|
10 |
use List::Util qw(min); |
|
11 |
use Params::Validate qw(:all); |
|
12 |
|
|
13 |
sub create_filter { |
|
14 |
validate_pos(@_, |
|
15 |
{ |
|
16 |
type => HASHREF, |
|
17 |
default => {}, |
|
18 |
callbacks => { |
|
19 |
has_all_keys => sub { |
|
20 |
foreach my $main_key (keys %{$_[0]}) { |
|
21 |
foreach my $sub_key (qw( |
|
22 |
position text input_type input_name |
|
23 |
)) { |
|
24 |
return die "Key '$sub_key' is missing under '$main_key'." |
|
25 |
unless exists $_[0]->{$main_key}->{$sub_key}; |
|
26 |
} |
|
27 |
} |
|
28 |
return 1; |
|
29 |
} |
|
30 |
}, |
|
31 |
}, |
|
32 |
(0) x (@_ - 1) # allow extra parameters |
|
33 |
); |
|
34 |
my $filter_elements = shift @_; |
|
35 |
my %params = validate_with( |
|
36 |
params => \@_, |
|
37 |
spec => { |
|
38 |
}, |
|
39 |
allow_extra => 1, |
|
40 |
); |
|
41 |
|
|
42 |
my @filter_element_params = |
|
43 |
sort { $a->{position} <=> $b->{position} } |
|
44 |
grep { $_->{active} } |
|
45 |
values %{$filter_elements}; |
|
46 |
|
|
47 |
my @filter_elements; |
|
48 |
for my $filter_element_param (@filter_element_params) { |
|
49 |
|
|
50 |
my $filter_element = _create_input_element($filter_element_param, %params); |
|
51 |
|
|
52 |
push @filter_elements, $filter_element; |
|
53 |
} |
|
54 |
|
|
55 |
my $filter_form_div = _create_filter_form(\@filter_elements, %params); |
|
56 |
|
|
57 |
is_escaped($filter_form_div); |
|
58 |
} |
|
59 |
|
|
60 |
sub _create_input_element { |
|
61 |
my $element_param = shift @_; |
|
62 |
my %params = validate_with( |
|
63 |
params => \@_, |
|
64 |
spec => { |
|
65 |
no_show => { |
|
66 |
type => BOOLEAN, |
|
67 |
default => 0 |
|
68 |
}, |
|
69 |
active_in_report => { |
|
70 |
type => HASHREF, |
|
71 |
default => {} |
|
72 |
}, |
|
73 |
}, |
|
74 |
allow_extra => 1, |
|
75 |
); |
|
76 |
|
|
77 |
my $element_th = html_tag('th', $element_param->{text}, align => 'right'); |
|
78 |
|
|
79 |
my $element_input = ''; |
|
80 |
|
|
81 |
if($element_param->{input_type} eq 'input_tag') { |
|
82 |
|
|
83 |
$element_input = input_tag($element_param->{input_name}, $element_param->{input_default}); |
|
84 |
|
|
85 |
} elsif ($element_param->{input_type} eq 'select_tag') { |
|
86 |
|
|
87 |
$element_input = select_tag($element_param->{input_name}, $element_param->{input_values}, default => $element_param->{input_default}) |
|
88 |
|
|
89 |
} elsif ($element_param->{input_type} eq 'yes_no_tag') { |
|
90 |
|
|
91 |
$element_input = select_tag($element_param->{input_name}, [ [ 1 => t8('Yes') ], [ 0 => t8('No') ] ], default => $element_param->{input_default}, with_empty => 1) |
|
92 |
|
|
93 |
} elsif($element_param->{input_type} eq 'date_tag') { |
|
94 |
|
|
95 |
my $after_input = |
|
96 |
html_tag('th', t8("After"), align => 'right') . |
|
97 |
html_tag('td', |
|
98 |
date_tag("filter." . $element_param->{input_name} . ":date::ge", $element_param->{input_default_ge}) |
|
99 |
) |
|
100 |
; |
|
101 |
my $before_input = |
|
102 |
html_tag('th', t8("Before"), align => 'right') . |
|
103 |
html_tag('td', |
|
104 |
date_tag("filter." . $element_param->{input_name} . ":date::le", $element_param->{input_default_le}) |
|
105 |
) |
|
106 |
; |
|
107 |
|
|
108 |
$element_input = |
|
109 |
html_tag('table', |
|
110 |
html_tag('tr', $after_input) |
|
111 |
. |
|
112 |
html_tag('tr', $before_input) |
|
113 |
) |
|
114 |
; |
|
115 |
} else { |
|
116 |
confess "unknown input_type " . $element_param->{input_type}; |
|
117 |
} |
|
118 |
|
|
119 |
my $element_input_td = html_tag('td', |
|
120 |
$element_input, |
|
121 |
nowrap => 1, |
|
122 |
); |
|
123 |
|
|
124 |
my $element_checkbox_td = ''; |
|
125 |
unless($params{no_show} || $element_param->{report_id} eq '') { |
|
126 |
my $checkbox = checkbox_tag( |
|
127 |
'active_in_report.' . $element_param->{report_id}, |
|
128 |
checked => $params{active_in_report}->{$element_param->{report_id}}, |
|
129 |
for_submit => 1 |
|
130 |
); |
|
131 |
$element_checkbox_td = html_tag('td', $checkbox); |
|
132 |
} |
|
133 |
|
|
134 |
return $element_th . $element_input_td . $element_checkbox_td; |
|
135 |
} |
|
136 |
|
|
137 |
sub _create_filter_form { |
|
138 |
my $ref_elements = shift @_; |
|
139 |
my %params = validate_with( |
|
140 |
params => \@_, |
|
141 |
spec => { |
|
142 |
}, |
|
143 |
allow_extra => 1, |
|
144 |
); |
|
145 |
|
|
146 |
my $filter_table = _create_input_div($ref_elements, %params); |
|
147 |
|
|
148 |
my $filter_form = html_tag('form', $filter_table, method => 'post', action => 'controller.pl', id => 'filter_form'); |
|
149 |
|
|
150 |
return $filter_form; |
|
151 |
} |
|
152 |
|
|
153 |
sub _create_input_div { |
|
154 |
my $ref_elements = shift @_; |
|
155 |
my %params = validate_with( |
|
156 |
params => \@_, |
|
157 |
spec => { |
|
158 |
count_columns => { |
|
159 |
type => SCALAR, |
|
160 |
default => 4, |
|
161 |
}, |
|
162 |
no_show => { |
|
163 |
type => BOOLEAN, |
|
164 |
default => 0, |
|
165 |
}, |
|
166 |
}, |
|
167 |
allow_extra => 1, |
|
168 |
); |
|
169 |
my @elements = @{$ref_elements}; |
|
170 |
|
|
171 |
my $div_columns = ""; |
|
172 |
|
|
173 |
my $elements_per_column = (int((scalar(@{$ref_elements}) - 1) / $params{count_columns}) + 1); |
|
174 |
for my $i (0 .. (min(scalar @elements, $params{count_columns}) - 1)) { |
|
175 |
|
|
176 |
my $rows = ""; |
|
177 |
for my $j (0 .. ($elements_per_column - 1) ) { |
|
178 |
my $idx = $elements_per_column * $i + $j; |
|
179 |
my $element = $elements[$idx]; |
|
180 |
$rows .= html_tag('tr', $element); |
|
181 |
|
|
182 |
} |
|
183 |
$div_columns .= html_tag('div', |
|
184 |
html_tag('table', |
|
185 |
html_tag('tr', |
|
186 |
html_tag('td') |
|
187 |
. html_tag('th', t8('Filter')) |
|
188 |
. ( $params{no_show} ? '' : html_tag('th', t8('Show')) ) |
|
189 |
) |
|
190 |
. $rows |
|
191 |
), |
|
192 |
style => "flex:1"); |
|
193 |
} |
|
194 |
|
|
195 |
my $input_div = html_tag('div', $div_columns, style => "display:flex;flex-wrap:wrap"); |
|
196 |
|
|
197 |
return $input_div; |
|
198 |
} |
|
199 |
|
|
200 |
1; |
|
201 |
|
|
202 |
__END__ |
|
203 |
|
|
204 |
=pod |
|
205 |
|
|
206 |
=encoding utf8 |
|
207 |
|
|
208 |
=head1 NAME |
|
209 |
|
|
210 |
SL::Presenter::Filter - Presenter module for a generic Filter. |
|
211 |
|
|
212 |
=head1 SYNOPSIS |
|
213 |
|
|
214 |
my $filter_elements = { |
|
215 |
id => { |
|
216 |
'position' => 1, |
|
217 |
'text' => t8("ID"), |
|
218 |
'input_type' => 'input_tag', |
|
219 |
'input_name' => 'filter.id:number', |
|
220 |
'input_default' => $::form->{filter}->{'id:number'}, |
|
221 |
'report_id' => 'id', |
|
222 |
'active' => 1, |
|
223 |
}, |
|
224 |
# ... |
|
225 |
}; |
|
226 |
|
|
227 |
my $filter_html = SL::Presenter::Filter::create_filter( |
|
228 |
$filter_elements, |
|
229 |
active_in_report => ['id'], |
|
230 |
); |
|
231 |
|
|
232 |
|
|
233 |
=head1 FUNCTIONS |
|
234 |
|
|
235 |
=over 4 |
|
236 |
|
|
237 |
=item C<create_filter $filter_elements, %params> |
|
238 |
|
|
239 |
Returns a rendered version (actually an instance of |
|
240 |
L<SL::Presenter::EscapedText>) of a filter form for reclamations of type |
|
241 |
C<$reclamation_type>. |
|
242 |
|
|
243 |
C<$filter_elements> is a hash reference with the values declaring which inputs |
|
244 |
to create. |
|
245 |
|
|
246 |
=over 2 |
|
247 |
|
|
248 |
FILTER ELEMENTS |
|
249 |
|
|
250 |
A filter element is a hash reference. Each filter has a unique key and can have |
|
251 |
entries for: |
|
252 |
|
|
253 |
=over 4 |
|
254 |
|
|
255 |
=item * position (mandatory) |
|
256 |
|
|
257 |
Is a number after which the elements are ordered. This can be a float. |
|
258 |
|
|
259 |
=item * text (mandatory) |
|
260 |
|
|
261 |
Is shown before the input field. |
|
262 |
|
|
263 |
=item * input_name (mandatory) |
|
264 |
|
|
265 |
C<input_name> is used to set the name of the field, which should match the |
|
266 |
filter syntax. |
|
267 |
|
|
268 |
=item * C<input_type> (mandatory) |
|
269 |
|
|
270 |
This must be C<input_tag>, C<select_tag>, C<yes_no_tag> or C<date_tag>. It sets |
|
271 |
the input type for the filter. |
|
272 |
|
|
273 |
=over 2 |
|
274 |
|
|
275 |
=item * C<input_tag> |
|
276 |
|
|
277 |
Creates a text input field. The default value of this field is set to the |
|
278 |
C<input_default> entry of the filter element. |
|
279 |
|
|
280 |
=item * C<select_tag> |
|
281 |
|
|
282 |
Creates a drop down field. C<input_values> is used to set the options. |
|
283 |
See L<SL::Presenter::Tag::select_tag> for more details. The default value |
|
284 |
of this field is set to the C<input_default> entry. |
|
285 |
|
|
286 |
=item * C<yes_no_tag> |
|
287 |
|
|
288 |
Creates a yes/no input field. The default value of this field is set to the |
|
289 |
C<input_default> entry. |
|
290 |
|
|
291 |
=item * C<date_tag> |
|
292 |
|
|
293 |
Creates two date input fields. One filters for after the date and the other |
|
294 |
filters for before the date. The default values of these fields are set to the |
|
295 |
C<input_default_ge> and C<input_default_le> entries of the filter element. |
|
296 |
For the first field ":date::ge" and for the second ":date::le" is added to the |
|
297 |
end of C<input_name>. |
|
298 |
|
|
299 |
=back |
|
300 |
|
|
301 |
=item * C<report_id> |
|
302 |
|
|
303 |
Is used to generate the id of the check box after the input field. The value of |
|
304 |
the check box can be found in the form under |
|
305 |
C<$::form-E<gt>{'active_in_report'}-E<gt>{report_id}>. |
|
306 |
|
|
307 |
=item * C<active> |
|
308 |
|
|
309 |
If falsish the element is ignored. |
|
310 |
|
|
311 |
=item * C<input_default>, C<input_default_ge>, C<input_default_le> |
|
312 |
|
|
313 |
Look at C<input_tag> to see how they are used. |
|
314 |
|
|
315 |
=back |
|
316 |
|
|
317 |
=back |
|
318 |
|
|
319 |
C<%params> can include: |
|
320 |
|
|
321 |
=over 2 |
|
322 |
|
|
323 |
=item * no_show |
|
324 |
|
|
325 |
If falsish (the default) then a check box is added after the input field. Which |
|
326 |
specifies whether the corresponding column appears in the report. The value of |
|
327 |
the check box can be changed by the user. |
|
328 |
|
|
329 |
=item * active_in_report |
|
330 |
|
|
331 |
If C<$params{no_show}> is falsish, this is used to set the values of the check |
|
332 |
boxes, after the input fields. This should be set to the C<active_in_report> |
|
333 |
value of the last C<$::form>. |
|
334 |
|
|
335 |
=back |
|
336 |
|
|
337 |
=back |
|
338 |
|
|
339 |
=head1 BUGS |
|
340 |
|
|
341 |
Nothing here yet. |
|
342 |
|
|
343 |
=head1 AUTHOR |
|
344 |
|
|
345 |
Tamino Steinert E<lt>tamino.steinert@tamino.stE<gt> |
|
346 |
|
|
347 |
=cut |
SL/Presenter/Filter/Reclamation.pm | ||
---|---|---|
1 |
package SL::Presenter::Filter::Reclamation; |
|
2 |
|
|
3 |
use parent SL::Presenter::Filter; |
|
4 |
|
|
5 |
use strict; |
|
6 |
|
|
7 |
use SL::Locale::String qw(t8); |
|
8 |
|
|
9 |
use Params::Validate qw(:all); |
|
10 |
|
|
11 |
sub get_default_filter_elements { |
|
12 |
my ($filter, $reclamation_type) = @_; |
|
13 |
|
|
14 |
my %default_filter_elements = ( # {{{ |
|
15 |
'reason_names' => { |
|
16 |
'position' => 1, |
|
17 |
'text' => t8("Reclamation Reason"), |
|
18 |
'input_type' => 'input_tag', |
|
19 |
'input_name' => 'filter.reclamation_items.reason.name:substr::ilike', |
|
20 |
'input_default' => $filter->{reclamation_items}->{reason}->{'name:substr::ilike'}, |
|
21 |
'active' => 1, |
|
22 |
}, |
|
23 |
'id' => { |
|
24 |
'position' => 2, |
|
25 |
'text' => t8("Reclamation ID"), |
|
26 |
'input_type' => 'input_tag', |
|
27 |
'input_name' => 'filter.id:number', |
|
28 |
'input_default' => $filter->{'id:number'}, |
|
29 |
'report_id' => 'id', |
|
30 |
'active' => 0, |
|
31 |
}, |
|
32 |
'record_number' => { |
|
33 |
'position' => 3, |
|
34 |
'text' => t8("Reclamation Number"), |
|
35 |
'input_type' => 'input_tag', |
|
36 |
'input_name' => 'filter.record_number:substr::ilike', |
|
37 |
'input_default' => $filter->{'record_number:substr::ilike'}, |
|
38 |
'report_id' => 'record_number', |
|
39 |
'active' => 1, |
|
40 |
}, |
|
41 |
'employee' => { |
|
42 |
'position' => 4, |
|
43 |
'text' => t8("Employee Name"), |
|
44 |
'input_type' => 'input_tag', |
|
45 |
'input_name' => 'filter.employee.name:substr::ilike', |
|
46 |
'input_default' => $filter->{employee}->{'name:substr::ilike'}, |
|
47 |
'report_id' => 'employee', |
|
48 |
'active' => 1, |
|
49 |
}, |
|
50 |
'salesman' => { |
|
51 |
'position' => 5, |
|
52 |
'text' => t8("Salesman Name"), |
|
53 |
'input_type' => 'input_tag', |
|
54 |
'input_name' => 'filter.salesman.name:substr::ilike', |
|
55 |
'input_default' => $filter->{salesman}->{'name:substr::ilike'}, |
|
56 |
'report_id' => 'salesman', |
|
57 |
'active' => 1, |
|
58 |
}, |
|
59 |
# 6,7 for Customer/Vendor |
|
60 |
'customer' => { |
|
61 |
'position' => 6, |
|
62 |
'text' => t8("Customer Name"), |
|
63 |
'input_type' => 'input_tag', |
|
64 |
'input_name' => 'filter.customer.name:substr::ilike', |
|
65 |
'input_default' => $filter->{customer}->{'name:substr::ilike'}, |
|
66 |
'report_id' => 'customer', |
|
67 |
'active' => ($reclamation_type eq 'sales_reclamation' ? 1 : 0), |
|
68 |
}, |
|
69 |
'vendor' => { |
|
70 |
'position' => 6, |
|
71 |
'text' => t8("Vendor Name"), |
|
72 |
'input_type' => 'input_tag', |
|
73 |
'input_name' => 'filter.vendor.name:substr::ilike', |
|
74 |
'input_default' => $filter->{vendor}->{'name:substr::ilike'}, |
|
75 |
'report_id' => 'vendor', |
|
76 |
'active' => ($reclamation_type eq 'purchase_reclamation' ? 1 : 0), |
|
77 |
}, |
|
78 |
'customer_number' => { |
|
79 |
'position' => 7, |
|
80 |
'text' => t8("Customer Number"), |
|
81 |
'input_type' => 'input_tag', |
|
82 |
'input_name' => 'filter.customer.customernumber:substr::ilike', |
|
83 |
'input_default' => $filter->{customer}->{'customernumber:substr::ilike'}, |
|
84 |
'active' => ($reclamation_type eq 'sales_reclamation' ? 1 : 0), |
|
85 |
}, |
|
86 |
'vendor_number' => { |
|
87 |
'position' => 7, |
|
88 |
'text' => t8("Vendor Number"), |
|
89 |
'input_type' => 'input_tag', |
|
90 |
'input_name' => 'filter.vendor.vendornumber:substr::ilike', |
|
91 |
'input_default' => $filter->{vendor}->{'vendornumber:substr::ilike'}, |
|
92 |
'active' => ($reclamation_type eq 'purchase_reclamation' ? 1 : 0), |
|
93 |
}, |
|
94 |
'contact_name' => { |
|
95 |
'position' => 8, |
|
96 |
'text' => t8("Contact Name"), |
|
97 |
'input_type' => 'input_tag', |
|
98 |
'input_name' => 'filter.contact.cp_name:substr::ilike', |
|
99 |
'input_default' => $filter->{contact}->{'cp_name:substr::ilike'}, |
|
100 |
'report_id' => 'contact', |
|
101 |
'active' => 1, |
|
102 |
}, |
|
103 |
'language_code' => { |
|
104 |
'position' => 9, |
|
105 |
'text' => t8("Language Code"), |
|
106 |
'input_type' => 'input_tag', |
|
107 |
'input_name' => 'filter.language.article_code:substr::ilike', |
|
108 |
'input_default' => $filter->{language}->{'article_code:substr::ilike'}, |
|
109 |
'report_id' => 'language', |
|
110 |
'active' => 1, |
|
111 |
}, |
|
112 |
'department_description' => { |
|
113 |
'position' => 10, |
|
114 |
'text' => t8("Department Description"), |
|
115 |
'input_type' => 'input_tag', |
|
116 |
'input_name' => 'filter.department.description:substr::ilike', |
|
117 |
'input_default' => $filter->{department}->{'description:substr::ilike'}, |
|
118 |
'report_id' => 'department', |
|
119 |
'active' => 1, |
|
120 |
}, |
|
121 |
'globalproject_projectnumber' => { |
|
122 |
'position' => 11, |
|
123 |
'text' => t8("Project Number"), |
|
124 |
'input_type' => 'input_tag', |
|
125 |
'input_name' => 'filter.globalproject.projectnumber:substr::ilike', |
|
126 |
'input_default' => $filter->{globalproject}->{'projectnumber:substr::ilike'}, |
|
127 |
'report_id' => 'globalproject', |
|
128 |
'active' => 1, |
|
129 |
}, |
|
130 |
'globalproject_description' => { |
|
131 |
'position' => 12, |
|
132 |
'text' => t8("Project Description"), |
|
133 |
'input_type' => 'input_tag', |
|
134 |
'input_name' => 'filter.globalproject.description:substr::ilike', |
|
135 |
'input_default' => $filter->{globalproject}->{'description:substr::ilike'}, |
|
136 |
'active' => 1, |
|
137 |
}, |
|
138 |
'cv_record_number' => { |
|
139 |
'position' => 13, |
|
140 |
'text' => ($reclamation_type eq 'sales_reclamation' |
|
141 |
? t8("Customer Record Number") |
|
142 |
: t8("Vendor Record Number") |
|
143 |
), |
|
144 |
'input_type' => 'input_tag', |
|
145 |
'input_name' => 'filter.cv_record_number:substr::ilike', |
|
146 |
'input_default' => $filter->{'cv_record_number:substr::ilike'}, |
|
147 |
'report_id' => 'cv_record_number', |
|
148 |
'active' => 1, |
|
149 |
}, |
|
150 |
'transaction_description' => { |
|
151 |
'position' => 14, |
|
152 |
'text' => t8("Description"), |
|
153 |
'input_type' => 'input_tag', |
|
154 |
'input_name' => 'filter.transaction_description:substr::ilike', |
|
155 |
'input_default' => $filter->{'transaction_description:substr::ilike'}, |
|
156 |
'report_id' => 'transaction_description', |
|
157 |
'active' => 1, |
|
158 |
}, |
|
159 |
'notes' => { |
|
160 |
'position' => 15, |
|
161 |
'text' => t8("Notes"), |
|
162 |
'input_type' => 'input_tag', |
|
163 |
'input_name' => 'filter.notes:substr::ilike', |
|
164 |
'input_default' => $filter->{'notes:substr::ilike'}, |
|
165 |
'report_id' => 'notes', |
|
166 |
'active' => 1, |
|
167 |
}, |
|
168 |
'intnotes' => { |
|
169 |
'position' => 16, |
|
170 |
'text' => t8("Internal Notes"), |
|
171 |
'input_type' => 'input_tag', |
|
172 |
'input_name' => 'filter.intnotes:substr::ilike', |
|
173 |
'input_default' => $filter->{'intnotes:substr::ilike'}, |
|
174 |
'report_id' => 'intnotes', |
|
175 |
'active' => 1, |
|
176 |
}, |
|
177 |
'shippingpoint' => { |
|
178 |
'position' => 17, |
|
179 |
'text' => t8("Shipping Point"), |
|
180 |
'input_type' => 'input_tag', |
|
181 |
'input_name' => 'filter.shippingpoint:substr::ilike', |
|
182 |
'input_default' => $filter->{'shippingpoint:substr::ilike'}, |
|
183 |
'report_id' => 'shippingpoint', |
|
184 |
'active' => 1, |
|
185 |
}, |
|
186 |
'shipvia' => { |
|
187 |
'position' => 18, |
|
188 |
'text' => t8("Ship via"), |
|
189 |
'input_type' => 'input_tag', |
|
190 |
'input_name' => 'filter.shipvia:substr::ilike', |
|
191 |
'input_default' => $filter->{'shipvia:substr::ilike'}, |
|
192 |
'report_id' => 'shipvia', |
|
193 |
'active' => 1, |
|
194 |
}, |
|
195 |
'amount' => { |
|
196 |
'position' => 19, |
|
197 |
'text' => t8("Total"), |
|
198 |
'input_type' => 'input_tag', |
|
199 |
'input_name' => 'filter.amount:number', |
|
200 |
'input_default' => $filter->{'amount:number'}, |
|
201 |
'report_id' => 'amount', |
|
202 |
'active' => 1, |
|
203 |
}, |
|
204 |
'netamount' => { |
|
205 |
'position' => 20, |
|
206 |
'text' => t8("Subtotal"), |
|
207 |
'input_type' => 'input_tag', |
|
208 |
'input_name' => 'filter.netamount:number', |
|
209 |
'input_default' => $filter->{'netamount:number'}, |
|
210 |
'report_id' => 'netamount', |
|
211 |
'active' => 1, |
|
212 |
}, |
|
213 |
'delivery_term_description' => { |
|
214 |
'position' => 21, |
|
215 |
'text' => t8("Delivery Terms"), |
|
216 |
'input_type' => 'input_tag', |
|
217 |
'input_name' => 'filter.delivery_term.description:substr::ilike', |
|
218 |
'input_default' => $filter->{delivery_term}->{'description:substr::ilike'}, |
|
219 |
'report_id' => 'delivery_term', |
|
220 |
'active' => 1, |
|
221 |
}, |
|
222 |
'payment_description' => { |
|
223 |
'position' => 22, |
|
224 |
'text' => t8("Payment Terms"), |
|
225 |
'input_type' => 'input_tag', |
|
226 |
'input_name' => 'filter.payment.description:substr::ilike', |
|
227 |
'input_default' => $filter->{payment}->{'description:substr::ilike'}, |
|
228 |
'report_id' => 'payment', |
|
229 |
'active' => 1, |
|
230 |
}, |
|
231 |
'currency_name' => { |
|
232 |
'position' => 23, |
|
233 |
'text' => t8("Currency"), |
|
234 |
'input_type' => 'input_tag', |
|
235 |
'input_name' => 'filter.currency.name:substr::ilike', |
|
236 |
'input_default' => $filter->{currency}->{'name:substr::ilike'}, |
|
237 |
'report_id' => 'currency', |
|
238 |
'active' => 1, |
|
239 |
}, |
|
240 |
'exchangerate' => { |
|
241 |
'position' => 24, |
|
242 |
'text' => t8("Exchangerate"), |
|
243 |
'input_type' => 'input_tag', |
|
244 |
'input_name' => 'filter.exchangerate:number', |
|
245 |
'input_default' => $filter->{'exchangerate:number'}, |
|
246 |
'report_id' => 'exchangerate', |
|
247 |
'active' => 1, |
|
248 |
}, |
|
249 |
'taxincluded' => { |
|
250 |
'position' => 25, |
|
251 |
'text' => t8("Tax Included"), |
|
252 |
'input_type' => 'yes_no_tag', |
|
253 |
'input_name' => 'filter.taxincluded', |
|
254 |
'input_default' => $filter->{taxincluded}, |
|
255 |
'report_id' => 'taxincluded', |
|
256 |
'active' => 1, |
|
257 |
}, |
|
258 |
'taxzone_description' => { |
|
259 |
'position' => 26, |
|
260 |
'text' => t8("Tax zone"), |
|
261 |
'input_type' => 'input_tag', |
|
262 |
'input_name' => 'filter.taxzone.description:substr::ilike', |
|
263 |
'input_default' => $filter->{taxzone}->{'description:substr::ilike'}, |
|
264 |
'report_id' => 'taxzone', |
|
265 |
'active' => 1, |
|
266 |
}, |
|
267 |
'tax_point' => { |
|
268 |
'position' => 27, |
|
269 |
'text' => t8("Tax point"), |
|
270 |
'input_type' => 'date_tag', |
|
271 |
'input_name' => 'tax_point', |
|
272 |
'input_default_ge' => $filter->{'tax_pont' . ':date::ge'}, |
|
273 |
'input_default_le' => $filter->{'tax_pont' . ':date::le'}, |
|
274 |
'report_id' => 'tax_point', |
|
275 |
'active' => 1, |
|
276 |
}, |
|
277 |
'reqdate' => { |
|
278 |
'position' => 28, |
|
279 |
'text' => t8("Deadline"), |
|
280 |
'input_type' => 'date_tag', |
|
281 |
'input_name' => 'reqdate', |
|
282 |
'input_default_ge' => $filter->{'reqdate' . ':date::ge'}, |
|
283 |
'input_default_le' => $filter->{'reqdate' . ':date::le'}, |
|
284 |
'report_id' => 'reqdate', |
|
285 |
'active' => 1, |
|
286 |
}, |
|
287 |
'transdate' => { |
|
288 |
'position' => 29, |
|
289 |
'text' => t8("Booking Date"), |
|
290 |
'input_type' => 'date_tag', |
|
291 |
'input_name' => 'transdate', |
|
292 |
'input_default_ge' => $filter->{'transdate' . ':date::ge'}, |
|
293 |
'input_default_le' => $filter->{'transdate' . ':date::le'}, |
|
294 |
'report_id' => 'transdate', |
|
295 |
'active' => 1, |
|
296 |
}, |
|
297 |
'itime' => { |
|
298 |
'position' => 30, |
|
299 |
'text' => t8("Creation Time"), |
|
300 |
'input_type' => 'date_tag', |
|
301 |
'input_name' => 'itime', |
|
302 |
'input_default_ge' => $filter->{'itime' . ':date::ge'}, |
|
303 |
'input_default_le' => $filter->{'itime' . ':date::le'}, |
|
304 |
'report_id' => 'itime', |
|
305 |
'active' => 1, |
|
306 |
}, |
|
307 |
'mtime' => { |
|
308 |
'position' => 31, |
|
309 |
'text' => t8("Last modification Time"), |
|
310 |
'input_type' => 'date_tag', |
|
311 |
'input_name' => 'mtime', |
|
312 |
'input_default_ge' => $filter->{'mtime' . ':date::ge'}, |
|
313 |
'input_default_le' => $filter->{'mtime' . ':date::le'}, |
|
314 |
'report_id' => 'mtime', |
|
315 |
'active' => 1, |
|
316 |
}, |
|
317 |
'delivered' => { |
|
318 |
'position' => 32, |
|
319 |
'text' => t8("Delivered"), |
|
320 |
'input_type' => 'yes_no_tag', |
|
321 |
'input_name' => 'filter.delivered', |
|
322 |
'input_default' => $filter->{delivered}, |
|
323 |
'report_id' => 'delivered', |
|
324 |
'active' => 1, |
|
325 |
}, |
|
326 |
'closed' => { |
|
327 |
'position' => 33, |
|
328 |
'text' => t8("Closed"), |
|
329 |
'input_type' => 'yes_no_tag', |
|
330 |
'input_name' => 'filter.closed', |
|
331 |
'input_default' => $filter->{closed}, |
|
332 |
'report_id' => 'closed', |
|
333 |
'active' => 1, |
|
334 |
}, |
|
335 |
); # }}} |
|
336 |
return \%default_filter_elements; |
|
337 |
} |
|
338 |
|
|
339 |
sub filter { |
|
340 |
my $filter = shift @_; |
|
341 |
die "filter has to be a hash ref" if ref $filter ne 'HASH'; |
|
342 |
my $reclamation_type = shift @_; |
|
343 |
my %params = validate_with( |
|
344 |
params => \@_, |
|
345 |
spec => { |
|
346 |
}, |
|
347 |
allow_extra => 1, |
|
348 |
); |
|
349 |
|
|
350 |
# combine default and param values for filter_element, |
|
351 |
# only replace the lowest occurrence |
|
352 |
my $filter_elements = get_default_filter_elements($filter, $reclamation_type); |
|
353 |
|
|
354 |
return SL::Presenter::Filter::create_filter($filter_elements, %params); |
|
355 |
} |
|
356 |
|
|
357 |
1; |
|
358 |
|
|
359 |
__END__ |
|
360 |
|
|
361 |
=pod |
|
362 |
|
|
363 |
=encoding utf8 |
|
364 |
|
|
365 |
=head1 NAME |
|
366 |
|
|
367 |
SL::Presenter::Filter::Reclamation - Presenter module for a generic Filter on |
|
368 |
Reclamation. |
|
369 |
|
|
370 |
=head1 SYNOPSIS |
|
371 |
|
|
372 |
# in Reclamation Controller |
|
373 |
my $filter_html = SL::Presenter::Filter::Reclamation::filter( |
|
374 |
$::form->{filter}, $self->type, active_in_report => $::form->{active_in_report} |
|
375 |
); |
|
376 |
|
|
377 |
|
|
378 |
=head1 FUNCTIONS |
|
379 |
|
|
380 |
=over 4 |
|
381 |
|
|
382 |
=item C<filter $filter, $reclamation_type, %params> |
|
383 |
|
|
384 |
Returns a rendered version (actually an instance of |
|
385 |
L<SL::Presenter::EscapedText>) of a filter form for reclamations of type |
|
386 |
C<$reclamation_type>. |
|
387 |
|
|
388 |
C<$filter> should be the C<filter> value of the last C<$::form>. This is used to |
|
389 |
get the previous values of the input fields. |
|
390 |
|
|
391 |
C<%params> fields get forwarded to C<SL::Presenter::Filter::create_filter>. |
|
392 |
|
|
393 |
=back |
|
394 |
|
|
395 |
=head1 BUGS |
|
396 |
|
|
397 |
Nothing here yet. |
|
398 |
|
|
399 |
=head1 AUTHOR |
|
400 |
|
|
401 |
Tamino Steinert E<lt>tamino.steinert@tamino.stE<gt> |
|
402 |
|
|
403 |
=cut |
SL/Presenter/ReclamationFilter.pm | ||
---|---|---|
1 |
package SL::Presenter::ReclamationFilter; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use SL::Presenter::EscapedText qw(escape is_escaped); |
|
6 |
use SL::Presenter::Tag qw(html_tag input_tag select_tag date_tag checkbox_tag); |
|
7 |
use SL::Locale::String qw(t8); |
|
8 |
|
|
9 |
use Exporter qw(import); |
|
10 |
our @EXPORT_OK = qw( |
|
11 |
filter |
|
12 |
); |
|
13 |
|
|
14 |
use Carp; |
|
15 |
|
|
16 |
sub filter { |
|
17 |
my ($filter, $reclamation_type, %params) = @_; |
|
18 |
|
|
19 |
$filter ||= undef; #filter should not be '' (empty string); |
|
20 |
my %default_filter_elements = ( # {{{ |
|
21 |
'reason_names' => { |
|
22 |
'position' => 1, |
|
23 |
'text' => t8("Reclamation Reason"), |
|
24 |
'input_type' => 'input_tag', |
|
25 |
'input_name' => 'filter.reclamation_items.reason.name:substr::ilike', |
|
26 |
'input_default' => $filter->{reclamation_items}->{reason}->{'name:substr::ilike'}, |
|
27 |
'active' => 1, |
|
28 |
}, |
|
29 |
'id' => { |
|
30 |
'position' => 2, |
|
31 |
'text' => t8("Reclamation ID"), |
|
32 |
'input_type' => 'input_tag', |
|
33 |
'input_name' => 'filter.id:number', |
|
34 |
'input_default' =>$filter->{'id:number'}, |
|
35 |
'report_id' => 'id', |
|
36 |
'active' => 0, |
|
37 |
}, |
|
38 |
'record_number' => { |
|
39 |
'position' => 3, |
|
40 |
'text' => t8("Reclamation Number"), |
|
41 |
'input_type' => 'input_tag', |
|
42 |
'input_name' => 'filter.record_number:substr::ilike', |
|
43 |
'input_default' =>$filter->{'record_number:substr::ilike'}, |
|
44 |
'report_id' => 'record_number', |
|
45 |
'active' => 1, |
|
46 |
}, |
|
47 |
'employee' => { |
|
48 |
'position' => 4, |
|
49 |
'text' => t8("Employee Name"), |
|
50 |
'input_type' => 'input_tag', |
|
51 |
'input_name' => 'filter.employee.name:substr::ilike', |
|
52 |
'input_default' =>$filter->{employee}->{'name:substr::ilike'}, |
|
53 |
'report_id' => 'employee', |
|
54 |
'active' => 1, |
|
55 |
}, |
|
56 |
'salesman' => { |
|
57 |
'position' => 5, |
|
58 |
'text' => t8("Salesman Name"), |
|
59 |
'input_type' => 'input_tag', |
|
60 |
'input_name' => 'filter.salesman.name:substr::ilike', |
|
61 |
'input_default' =>$filter->{salesman}->{'name:substr::ilike'}, |
|
62 |
'report_id' => 'salesman', |
|
63 |
'active' => 1, |
|
64 |
}, |
|
65 |
# 6,7 for Customer/Vendor |
|
66 |
'customer' => { |
|
67 |
'position' => 6, |
|
68 |
'text' => t8("Customer Name"), |
|
69 |
'input_type' => 'input_tag', |
|
70 |
'input_name' => 'filter.customer.name:substr::ilike', |
|
71 |
'input_default' => $filter->{customer}->{'name:substr::ilike'}, |
|
72 |
'report_id' => 'customer', |
|
73 |
'active' => ($reclamation_type eq 'sales_reclamation' ? 1 : 0), |
|
74 |
}, |
|
75 |
'vendor' => { |
|
76 |
'position' => 6, |
|
77 |
'text' => t8("Vendor Name"), |
|
78 |
'input_type' => 'input_tag', |
|
79 |
'input_name' => 'filter.vendor.name:substr::ilike', |
|
80 |
'input_default' => $filter->{vendor}->{'name:substr::ilike'}, |
|
81 |
'report_id' => 'vendor', |
|
82 |
'active' => ($reclamation_type eq 'purchase_reclamation' ? 1 : 0), |
|
83 |
}, |
|
84 |
'customer_number' => { |
|
85 |
'position' => 7, |
|
86 |
'text' => t8("Customer Number"), |
|
87 |
'input_type' => 'input_tag', |
|
88 |
'input_name' => 'filter.customer.customernumber:substr::ilike', |
|
89 |
'input_default' => $filter->{customer}->{'customernumber:substr::ilike'}, |
|
90 |
'active' => ($reclamation_type eq 'sales_reclamation' ? 1 : 0), |
|
91 |
}, |
|
92 |
'vendor_number' => { |
|
93 |
'position' => 7, |
|
94 |
'text' => t8("Vendor Number"), |
|
95 |
'input_type' => 'input_tag', |
|
96 |
'input_name' => 'filter.vendor.vendornumber:substr::ilike', |
|
97 |
'input_default' => $filter->{vendor}->{'vendornumber:substr::ilike'}, |
|
98 |
'active' => ($reclamation_type eq 'purchase_reclamation' ? 1 : 0), |
|
99 |
}, |
|
100 |
'contact_name' => { |
|
101 |
'position' => 8, |
|
102 |
'text' => t8("Contact Name"), |
|
103 |
'input_type' => 'input_tag', |
|
104 |
'input_name' => 'filter.contact.cp_name:substr::ilike', |
|
105 |
'input_default' =>$filter->{contact}->{'cp_name:substr::ilike'}, |
|
106 |
'report_id' => 'contact', |
|
107 |
'active' => 1, |
|
108 |
}, |
|
109 |
'language_code' => { |
|
110 |
'position' => 9, |
|
111 |
'text' => t8("Language Code"), |
|
112 |
'input_type' => 'input_tag', |
|
113 |
'input_name' => 'filter.language.article_code:substr::ilike', |
|
114 |
'input_default' =>$filter->{language}->{'article_code:substr::ilike'}, |
|
115 |
'report_id' => 'language', |
|
116 |
'active' => 1, |
|
117 |
}, |
|
118 |
'department_description' => { |
|
119 |
'position' => 10, |
|
120 |
'text' => t8("Department Description"), |
|
121 |
'input_type' => 'input_tag', |
|
122 |
'input_name' => 'filter.department.description:substr::ilike', |
|
123 |
'input_default' =>$filter->{department}->{'description:substr::ilike'}, |
|
124 |
'report_id' => 'department', |
|
125 |
'active' => 1, |
|
126 |
}, |
|
127 |
'globalproject_projectnumber' => { |
|
128 |
'position' => 11, |
|
129 |
'text' => t8("Project Number"), |
|
130 |
'input_type' => 'input_tag', |
|
131 |
'input_name' => 'filter.globalproject.projectnumber:substr::ilike', |
|
132 |
'input_default' =>$filter->{globalproject}->{'projectnumber:substr::ilike'}, |
|
133 |
'report_id' => 'globalproject', |
|
134 |
'active' => 1, |
|
135 |
}, |
|
136 |
'globalproject_description' => { |
|
137 |
'position' => 12, |
|
138 |
'text' => t8("Project Description"), |
|
139 |
'input_type' => 'input_tag', |
|
140 |
'input_name' => 'filter.globalproject.description:substr::ilike', |
|
141 |
'input_default' =>$filter->{globalproject}->{'description:substr::ilike'}, |
|
142 |
'active' => 1, |
|
143 |
}, |
|
144 |
'cv_record_number' => { |
|
145 |
'position' => 13, |
|
146 |
'text' => ($reclamation_type eq 'sales_reclamation' |
|
147 |
? t8("Customer Record Number") |
|
148 |
: t8("Vendor Record Number") |
|
149 |
), |
|
150 |
'input_type' => 'input_tag', |
|
151 |
'input_name' => 'filter.cv_record_number:substr::ilike', |
|
152 |
'input_default' => $filter->{'cv_record_number:substr::ilike'}, |
|
153 |
'report_id' => 'cv_record_number', |
|
154 |
'active' => 1, |
|
155 |
}, |
|
156 |
'transaction_description' => { |
|
157 |
'position' => 14, |
|
158 |
'text' => t8("Description"), |
|
159 |
'input_type' => 'input_tag', |
|
160 |
'input_name' => 'filter.transaction_description:substr::ilike', |
|
161 |
'input_default' =>$filter->{'transaction_description:substr::ilike'}, |
|
162 |
'report_id' => 'transaction_description', |
|
163 |
'active' => 1, |
|
164 |
}, |
|
165 |
'notes' => { |
|
166 |
'position' => 15, |
|
167 |
'text' => t8("Notes"), |
|
168 |
'input_type' => 'input_tag', |
|
169 |
'input_name' => 'filter.notes:substr::ilike', |
|
170 |
'input_default' =>$filter->{'notes:substr::ilike'}, |
|
171 |
'report_id' => 'notes', |
|
172 |
'active' => 1, |
|
173 |
}, |
|
174 |
'intnotes' => { |
|
175 |
'position' => 16, |
|
176 |
'text' => t8("Internal Notes"), |
|
177 |
'input_type' => 'input_tag', |
|
178 |
'input_name' => 'filter.intnotes:substr::ilike', |
|
179 |
'input_default' =>$filter->{'intnotes:substr::ilike'}, |
|
180 |
'report_id' => 'intnotes', |
|
181 |
'active' => 1, |
|
182 |
}, |
|
183 |
'shippingpoint' => { |
|
184 |
'position' => 17, |
|
185 |
'text' => t8("Shipping Point"), |
|
186 |
'input_type' => 'input_tag', |
|
187 |
'input_name' => 'filter.shippingpoint:substr::ilike', |
|
188 |
'input_default' =>$filter->{'shippingpoint:substr::ilike'}, |
|
189 |
'report_id' => 'shippingpoint', |
|
190 |
'active' => 1, |
|
191 |
}, |
|
192 |
'shipvia' => { |
|
193 |
'position' => 18, |
|
194 |
'text' => t8("Ship via"), |
|
195 |
'input_type' => 'input_tag', |
|
196 |
'input_name' => 'filter.shipvia:substr::ilike', |
|
197 |
'input_default' =>$filter->{'shipvia:substr::ilike'}, |
|
198 |
'report_id' => 'shipvia', |
|
199 |
'active' => 1, |
|
200 |
}, |
|
201 |
'amount' => { |
|
202 |
'position' => 19, |
|
203 |
'text' => t8("Total"), |
|
204 |
'input_type' => 'input_tag', |
|
205 |
'input_name' => 'filter.amount:number', |
|
206 |
'input_default' =>$filter->{'amount:number'}, |
|
207 |
'report_id' => 'amount', |
|
208 |
'active' => 1, |
|
209 |
}, |
|
210 |
'netamount' => { |
|
211 |
'position' => 20, |
|
212 |
'text' => t8("Subtotal"), |
|
213 |
'input_type' => 'input_tag', |
|
214 |
'input_name' => 'filter.netamount:number', |
|
215 |
'input_default' =>$filter->{'netamount:number'}, |
|
216 |
'report_id' => 'netamount', |
|
217 |
'active' => 1, |
|
218 |
}, |
|
219 |
'delivery_term_description' => { |
|
220 |
'position' => 21, |
|
221 |
'text' => t8("Delivery Terms"), |
|
222 |
'input_type' => 'input_tag', |
|
223 |
'input_name' => 'filter.delivery_term.description:substr::ilike', |
|
224 |
'input_default' =>$filter->{delivery_term}->{'description:substr::ilike'}, |
|
225 |
'report_id' => 'delivery_term', |
|
226 |
'active' => 1, |
|
227 |
}, |
|
228 |
'payment_description' => { |
|
229 |
'position' => 22, |
|
230 |
'text' => t8("Payment Terms"), |
|
231 |
'input_type' => 'input_tag', |
|
232 |
'input_name' => 'filter.payment.description:substr::ilike', |
|
233 |
'input_default' =>$filter->{payment}->{'description:substr::ilike'}, |
|
234 |
'report_id' => 'payment', |
|
235 |
'active' => 1, |
|
236 |
}, |
|
237 |
'currency_name' => { |
|
238 |
'position' => 23, |
|
239 |
'text' => t8("Currency"), |
|
240 |
'input_type' => 'input_tag', |
|
241 |
'input_name' => 'filter.currency.name:substr::ilike', |
|
242 |
'input_default' =>$filter->{currency}->{'name:substr::ilike'}, |
|
243 |
'report_id' => 'currency', |
|
244 |
'active' => 1, |
|
245 |
}, |
|
246 |
'exchangerate' => { |
|
247 |
'position' => 24, |
|
248 |
'text' => t8("Exchangerate"), |
|
249 |
'input_type' => 'input_tag', |
|
250 |
'input_name' => 'filter.exchangerate:number', |
|
251 |
'input_default' =>$filter->{'exchangerate:number'}, |
|
252 |
'report_id' => 'exchangerate', |
|
253 |
'active' => 1, |
|
254 |
}, |
|
255 |
'taxincluded' => { |
|
256 |
'position' => 25, |
|
257 |
'text' => t8("Tax Included"), |
|
258 |
'input_type' => 'yes_no_tag', |
|
259 |
'input_name' => 'filter.taxincluded', |
|
260 |
'input_default' =>$filter->{taxincluded}, |
|
261 |
'report_id' => 'taxincluded', |
|
262 |
'active' => 1, |
|
263 |
}, |
|
264 |
'taxzone_description' => { |
|
265 |
'position' => 26, |
|
266 |
'text' => t8("Tax zone"), |
|
267 |
'input_type' => 'input_tag', |
|
268 |
'input_name' => 'filter.taxzone.description:substr::ilike', |
|
269 |
'input_default' =>$filter->{taxzone}->{'description:substr::ilike'}, |
|
270 |
'report_id' => 'taxzone', |
|
271 |
'active' => 1, |
|
272 |
}, |
|
273 |
'tax_point' => { |
|
274 |
'position' => 27, |
|
275 |
'text' => t8("Tax point"), |
|
276 |
'input_type' => 'date_tag', |
|
277 |
'input_name' => 'tax_point', |
|
278 |
'input_default_ge' => $filter->{'tax_pont' . ':date::ge'}, |
|
279 |
'input_default_le' => $filter->{'tax_pont' . ':date::le'}, |
|
280 |
'report_id' => 'tax_point', |
|
281 |
'active' => 1, |
|
282 |
}, |
|
283 |
'reqdate' => { |
|
284 |
'position' => 28, |
|
285 |
'text' => t8("Deadline"), |
|
286 |
'input_type' => 'date_tag', |
|
287 |
'input_name' => 'reqdate', |
|
288 |
'input_default_ge' => $filter->{'reqdate' . ':date::ge'}, |
|
289 |
'input_default_le' => $filter->{'reqdate' . ':date::le'}, |
|
290 |
'report_id' => 'reqdate', |
|
291 |
'active' => 1, |
|
292 |
}, |
|
293 |
'transdate' => { |
|
294 |
'position' => 29, |
|
295 |
'text' => t8("Booking Date"), |
|
296 |
'input_type' => 'date_tag', |
|
297 |
'input_name' => 'transdate', |
|
298 |
'input_default_ge' => $filter->{'transdate' . ':date::ge'}, |
|
299 |
'input_default_le' => $filter->{'transdate' . ':date::le'}, |
|
300 |
'report_id' => 'transdate', |
|
301 |
'active' => 1, |
|
302 |
}, |
|
303 |
'itime' => { |
|
304 |
'position' => 30, |
|
305 |
'text' => t8("Creation Time"), |
|
306 |
'input_type' => 'date_tag', |
|
307 |
'input_name' => 'itime', |
|
308 |
'input_default_ge' => $filter->{'itime' . ':date::ge'}, |
|
309 |
'input_default_le' => $filter->{'itime' . ':date::le'}, |
|
310 |
'report_id' => 'itime', |
|
311 |
'active' => 1, |
|
312 |
}, |
|
313 |
'mtime' => { |
|
314 |
'position' => 31, |
|
315 |
'text' => t8("Last modification Time"), |
|
316 |
'input_type' => 'date_tag', |
|
317 |
'input_name' => 'mtime', |
|
318 |
'input_default_ge' => $filter->{'mtime' . ':date::ge'}, |
|
319 |
'input_default_le' => $filter->{'mtime' . ':date::le'}, |
|
320 |
'report_id' => 'mtime', |
|
321 |
'active' => 1, |
|
322 |
}, |
|
323 |
'delivered' => { |
|
324 |
'position' => 32, |
|
325 |
'text' => t8("Delivered"), |
|
326 |
'input_type' => 'yes_no_tag', |
|
327 |
'input_name' => 'filter.delivered', |
|
328 |
'input_default' =>$filter->{delivered}, |
|
329 |
'report_id' => 'delivered', |
|
330 |
'active' => 1, |
|
331 |
}, |
|
332 |
'closed' => { |
|
333 |
'position' => 33, |
|
334 |
'text' => t8("Closed"), |
|
335 |
'input_type' => 'yes_no_tag', |
|
336 |
'input_name' => 'filter.closed', |
|
337 |
'input_default' =>$filter->{closed}, |
|
338 |
'report_id' => 'closed', |
|
339 |
'active' => 1, |
|
340 |
}, |
|
341 |
); # }}} |
|
342 |
|
|
343 |
# combine default and param values for filter_element, |
|
344 |
# only replace the lowest occurrence |
|
345 |
my %filter_elements = %default_filter_elements; |
|
346 |
while(my ($key, $value) = each (%{$params{filter_elements}})) { |
|
347 |
if(exists $filter_elements{$key}) { |
|
348 |
$filter_elements{$key} = ({ |
|
349 |
%{$filter_elements{$key}}, |
|
350 |
%{$value}, |
|
351 |
}); |
|
352 |
} else { |
|
353 |
$filter_elements{$key} = $value; |
|
354 |
} |
|
355 |
} |
|
356 |
|
|
357 |
my @filter_element_params = |
|
358 |
sort { $a->{position} <=> $b->{position} } |
|
359 |
grep { $_->{active} } |
|
360 |
values %filter_elements; |
|
361 |
|
|
362 |
my @filter_elements; |
|
363 |
for my $filter_element_param (@filter_element_params) { |
|
364 |
unless($filter_element_param->{active}) { |
|
365 |
next; |
|
366 |
} |
|
367 |
|
|
368 |
my $filter_element = _create_input_element($filter_element_param, %params); |
|
369 |
|
|
370 |
push @filter_elements, $filter_element; |
|
371 |
} |
|
372 |
|
|
373 |
my $filter_form_div = _create_filter_form(\@filter_elements, %params); |
|
374 |
|
|
375 |
is_escaped($filter_form_div); |
|
376 |
} |
|
377 |
|
|
378 |
sub _create_input_element { |
|
379 |
my ($element_param, %params) = @_; |
|
380 |
|
|
381 |
my $element_th = html_tag('th', $element_param->{text}, align => 'right'); |
|
382 |
|
|
383 |
my $element_input = ''; |
|
384 |
|
|
385 |
if($element_param->{input_type} eq 'input_tag') { |
|
386 |
|
|
387 |
$element_input = input_tag($element_param->{input_name}, $element_param->{input_default}); |
|
388 |
|
|
389 |
} elsif ($element_param->{input_type} eq 'yes_no_tag') { |
|
390 |
|
|
391 |
$element_input = select_tag($element_param->{input_name}, [ [ 1 => t8('Yes') ], [ 0 => t8('No') ] ], default => $element_param->{input_default}, with_empty => 1) |
|
392 |
|
|
393 |
} elsif($element_param->{input_type} eq 'date_tag') { |
|
394 |
|
|
395 |
my $after_input = |
|
396 |
html_tag('th', t8("After"), align => 'right') . |
|
397 |
html_tag('td', |
|
398 |
date_tag("filter." . $element_param->{input_name} . ":date::ge", $element_param->{input_default_ge}) |
|
399 |
) |
|
400 |
; |
|
401 |
my $before_input = |
|
402 |
html_tag('th', t8("Before"), align => 'right') . |
|
403 |
html_tag('td', |
|
404 |
date_tag("filter." . $element_param->{input_name} . ":date::le", $element_param->{input_default_le}) |
|
405 |
) |
|
406 |
; |
|
407 |
|
|
408 |
$element_input = |
|
409 |
html_tag('table', |
|
410 |
html_tag('tr', $after_input) |
|
411 |
. |
|
412 |
html_tag('tr', $before_input) |
|
413 |
) |
|
414 |
; |
|
415 |
} |
|
416 |
|
|
417 |
my $element_input_td = html_tag('td', |
|
418 |
$element_input, |
|
419 |
nowrap => 1, |
|
420 |
); |
|
421 |
|
|
422 |
my $element_checkbox_td = ''; |
|
423 |
unless($params{no_show} || $element_param->{report_id} eq '') { |
|
424 |
my $checkbox = checkbox_tag('active_in_report.' . $element_param->{report_id}, checked => $params{active_in_report}->{$element_param->{report_id}}, for_submit => 1); |
|
425 |
$element_checkbox_td = html_tag('td', $checkbox); |
|
426 |
} |
|
427 |
|
|
428 |
return $element_th . $element_input_td . $element_checkbox_td; |
|
429 |
} |
|
430 |
|
|
431 |
sub _create_filter_form { |
|
432 |
my ($ref_elements, %params) = @_; |
|
433 |
|
|
434 |
my $filter_table = _create_input_div($ref_elements, %params); |
|
435 |
|
|
436 |
my $filter_form = html_tag('form', $filter_table, method => 'post', action => 'controller.pl', id => 'search_form'); |
|
437 |
|
|
438 |
return $filter_form; |
|
439 |
} |
|
440 |
|
|
441 |
sub _create_input_div { |
|
442 |
my ($ref_elements, %params) = @_; |
|
443 |
my @elements = @{$ref_elements}; |
|
444 |
|
|
445 |
my $div_columns = ""; |
|
446 |
|
|
447 |
$params{count_columns} ||= 4; |
|
448 |
my $elements_per_column = (int((scalar(@{$ref_elements}) - 1) / $params{count_columns}) + 1); |
|
449 |
for my $i (0 .. ($params{count_columns} - 1)) { |
|
450 |
|
|
451 |
my $rows = ""; |
|
452 |
for my $j (0 .. ($elements_per_column - 1) ) { |
|
453 |
my $idx = $elements_per_column * $i + $j; |
|
454 |
my $element = $elements[$idx]; |
|
455 |
$rows .= html_tag('tr', $element); |
|
456 |
|
|
457 |
} |
|
458 |
$div_columns .= html_tag('div', |
|
459 |
html_tag('table', |
|
460 |
html_tag('tr', |
|
461 |
html_tag('td') |
|
462 |
. html_tag('th', t8('Filter')) |
|
463 |
. ( $params{no_show} ? '' : html_tag('th', t8('Show')) ) |
|
464 |
) |
|
465 |
. $rows |
|
466 |
), |
|
467 |
style => "flex:1"); |
|
468 |
} |
|
469 |
|
|
470 |
my $input_div = html_tag('div', $div_columns, style => "display:flex;flex-wrap:wrap"); |
|
471 |
|
|
472 |
return $input_div; |
|
473 |
} |
|
474 |
|
|
475 |
1; |
|
476 |
|
|
477 |
__END__ |
|
478 |
|
|
479 |
=pod |
|
480 |
|
|
481 |
=encoding utf8 |
|
482 |
|
|
483 |
=head1 NAME |
|
484 |
|
|
485 |
SL::Presenter::ReclamationFilter - Presenter module for a generic Filter on |
|
486 |
Reclamation. |
|
487 |
|
|
488 |
=head1 SYNOPSIS |
|
489 |
|
|
490 |
# in Reclamation Controller |
|
491 |
my $filter_html = SL::Presenter::ReclamationFilter::filter( |
|
492 |
$::form->{filter}, $self->type, active_in_report => $::form->{active_in_report} |
|
493 |
); |
|
494 |
|
|
495 |
|
|
496 |
=head1 FUNCTIONS |
|
497 |
|
|
498 |
=over 4 |
|
499 |
|
|
500 |
=item C<filter $filter, $reclamation_type, %params> |
|
501 |
|
|
502 |
Returns a rendered version (actually an instance of |
|
503 |
L<SL::Presenter::EscapedText>) of a filter form for reclamations of type |
|
504 |
C<$reclamation_type>. |
|
505 |
|
|
506 |
C<$filter> should be the C<filter> value of the last C<$::form>. This is used to |
|
507 |
get the previous values of the input fields. |
|
508 |
|
|
509 |
C<%params> can include: |
|
510 |
|
|
511 |
=over 2 |
|
512 |
|
|
513 |
=item * no_show |
|
514 |
|
|
515 |
If falsish (the default) then a check box is added after the input field. Which |
|
516 |
specifies whether the corresponding column appears in the report. The value of |
|
517 |
the check box can be changed by the user. |
|
518 |
|
|
519 |
=item * active_in_report |
|
520 |
|
|
521 |
If C<$params{no_show}> is falsish, this is used to set the values of the check |
|
522 |
boxes, after the input fields. This can be set to the C<active_in_report> value |
|
523 |
of the last C<$::form>. |
|
524 |
|
|
525 |
=item * filter_elements |
|
526 |
|
|
527 |
Is combined with the default filter elements. This can be used to override |
|
528 |
default values of the filter elements or to add a new ones. |
|
529 |
|
|
530 |
#deactivate the id and record_number fields |
|
531 |
$params{filter_elements} = ({ |
|
532 |
id => {active => 0}, |
|
533 |
record_number => {active => 0} |
|
534 |
}); |
|
535 |
|
|
536 |
=back |
|
537 |
|
|
538 |
=back |
|
539 |
|
|
540 |
=head1 FILTER ELEMENTS |
|
541 |
|
|
542 |
A filter element is stored in and as a hash map. Each filter has a unique key |
|
543 |
and should have entries for: |
|
544 |
|
|
545 |
=over 4 |
|
546 |
|
|
547 |
=item * position |
|
548 |
|
|
549 |
Is a number after which the elements are ordered. This can be a float. |
|
550 |
|
|
551 |
=item * text |
|
552 |
|
|
553 |
Is shown before the input field. |
|
554 |
|
|
555 |
=item * input_type |
|
556 |
|
|
557 |
This must be C<input_tag>, C<yes_no_tag> or C<date_tag>. It sets the input type |
|
558 |
for the filter. |
|
559 |
|
|
560 |
=over 2 |
|
561 |
|
|
562 |
=item * input_tag |
|
563 |
|
|
564 |
Creates a text input field. The default value of this field is set to the |
|
565 |
C<input_default> entry of the filter element. C<input_name> is used to set the |
|
566 |
name of the field, which should match the filter syntax. |
|
567 |
|
|
568 |
=item * yes_no_tag |
|
569 |
|
|
570 |
Creates a yes/no input field. The default value of this field is set to the |
|
571 |
C<input_default> entry of the filter element. C<input_name> is used to set the |
|
572 |
name of the field, which should match the filter syntax. |
|
573 |
|
|
574 |
=item * date_tag |
|
575 |
|
|
576 |
Creates two date input fields. One filters for after the date and the other |
|
577 |
filters for before the date. The default values of these fields are set to the |
|
578 |
C<input_default_ge> and C<input_default_le> entries of the filter element. |
|
579 |
C<input_name> is used to set the names of these fields, which should match the |
|
580 |
filter syntax. For the first field ":date::ge" and for the second ":date::le" is |
|
581 |
added to the end of C<input_name>. |
|
582 |
|
|
583 |
=back |
|
584 |
|
|
585 |
=item * report_id |
|
586 |
|
|
587 |
Is used to generate the id of the check box after the input field. The value of |
|
588 |
the check box can be found in the form under |
|
589 |
C<$::form-E<gt>{'active_in_report'}-E<gt>{report_id}>. |
|
590 |
|
|
591 |
=item * active |
|
592 |
|
|
593 |
If falsish the element is ignored. |
|
594 |
|
|
595 |
=item * input_name, input_default, input_default_ge, input_default_le |
|
596 |
|
|
597 |
Look at I<input_tag> to see how they are used. |
|
598 |
|
|
599 |
=back |
|
600 |
|
|
601 |
=head1 BUGS |
|
602 |
|
|
603 |
Nothing here yet. |
|
604 |
|
|
605 |
=head1 AUTHOR |
|
606 |
|
|
607 |
Tamino Steinert E<lt>tamino.steinert@tamino.stE<gt> |
|
608 |
|
|
609 |
=cut |
Auch abrufbar als: Unified diff
S:Presenter:Filter: Separaten Presenter für komplexe Berichtsfilter