sub object_class { 'SL::DB::PriceRule' }
__PACKAGE__->make_manager_methods;
+__PACKAGE__->add_filter_specs(
+ has_item_type => sub {
+ my ($key, $values, $prefix) = @_;
+ return unless @$values;
+
+ my $each_type = "SELECT DISTINCT price_rules_id FROM price_rule_items WHERE type = %s";
+ my $sub_query = join ' INTERSECT ', map { sprintf $each_type, $::form->get_standard_dbh->quote($_) } @$values;
+ return or => [ ${prefix} . 'id' => [ \$sub_query ] ];
+ },
+ item_type_matches => sub {
+ my ($key, $values, $prefix) = @_;
+ return unless @$values;
+ return unless 'HASH' eq ref $values->[0];
+ return unless grep $_, values %{ $values->[0] };
+
+ my $each_type = "SELECT DISTINCT price_rules_id FROM price_rule_items WHERE type = %s AND (%s)";
+ my $sub_query = join ' INTERSECT ', map {
+ sprintf $each_type, $::form->get_standard_dbh->quote($_), SL::DB::Manager::PriceRuleItem->filter_match($_, $values->[0]{$_})
+ } grep { $values->[0]{$_} } keys %{ $values->[0] };
+ return or => [ ${prefix} . 'id' => [ \$sub_query ] ];
+ },
+);
sub get_matching_filter {
my ($class, %params) = @_;
[ map { [ $_, $types{$_}{description} ] } grep { $types{$_}{$vc} } map { $_ } @types ];
}
+sub get_type {
+ $types{$_[1]}
+}
+
+sub filter_match {
+ my ($self, $type, $value) = @_;
+
+ my $type_def = $types{$type};
+
+ if (!$type_def->{ops}) {
+ my $evalue = $::form->get_standard_dbh->quote($value);
+ return "value_$type_def->{data_type} = $evalue";
+ } elsif ($type_def->{ops} eq 'date') {
+ my $date_value = $::form->get_standard_dbh->quote(DateTime->from_kivitendo($value));
+ return "
+ (value_$type_def->{data_type} > $date_value AND op = 'lt') OR
+ (value_$type_def->{data_type} < $date_value AND op = 'gt') OR
+ (value_$type_def->{data_type} = $date_value AND op = 'eq')
+ ";
+ } elsif ($type_def->{ops} eq 'num') {
+ my $num_value = $::form->get_standard_dbh->quote($::form->parse_amount(\%::myconfig, $value));
+ return "
+ (value_$type_def->{data_type} >= $num_value AND op = 'le') OR
+ (value_$type_def->{data_type} <= $num_value AND op = 'ge') OR
+ (value_$type_def->{data_type} = $num_value AND op = 'eq')
+ ";
+ }
+}
+
+
1;
<div class='filter_toggle' style='display:none'>
<a href='#' onClick='javascript:$(".filter_toggle").toggle()'>[% 'Hide Filter' | $T8 %]</a>
<table id='filter_table'>
- <tr>
<tr>
<th align="right">[% 'Description' | $T8 %]</th>
- <td>[% L.input_tag('filter.name:substr::ilike', filter.name_substr__ilike, size = 20) %]</td>
+ <td>[% L.input_tag('filter.name:substr::ilike', filter.name_substr__ilike, size = 20, style='width: 300px') %]</td>
+ </tr>
+ <tr>
+ <th align="right">[% 'Part' | $T8 %]</th>
+ <td>[% L.part_picker('filter.item_type_matches[].part', FORM.filter.item_type_matches.0.part, style='width: 300px') %]</td>
+ </tr>
+[%- IF SELF.vc == 'customer' %]
+ <tr>
+ <th align="right">[% 'Customer' | $T8 %]</th>
+ <td>[% L.customer_vendor_picker('filter.item_type_matches[].customer', FORM.filter.item_type_matches.0.customer, type='customer', style='width: 300px') %]</td>
+ </tr>
+[%- END %]
+[%- IF SELF.vc == 'vendor' %]
+ <tr>
+ <th align="right">[% 'Vendor' | $T8 %]</th>
+ <td>[% L.customer_vendor_picker('filter.item_type_matches[].vendor', FORM.filter.item_type_matches.0.vendor, type='vendor', style='width: 300px') %]</td>
+ </tr>
+[%- END %]
+ <tr>
+ <th align="right">[% 'Business' | $T8 %]</th>
+ <td>[% L.select_tag('filter.item_type_matches[].business', SELF.businesses, title_key='description', default=FORM.filter.item_type_matches.0.business, with_empty=1, style='width: 300px') %]</td>
+ </tr>
+ <tr>
+ <th align="right">[% 'Group' | $T8 %]</th>
+ <td>[% L.select_tag('filter.item_type_matches[].partsgroup', SELF.partsgroups, title_key='partsgroup', default=FORM.filter.item_type_matches.0.partsgroup, with_empty=1, style='width: 300px') %]</td>
+ </tr>
+ <tr>
+ <th align="right">[% 'Qty' | $T8 %]</th>
+ <td>[% L.input_tag('filter.item_type_matches[].qty', FORM.filter.item_type_matches.0.qty, style='width: 300px') %]</td>
+ </tr>
+ <tr>
+ <th align="right">[% 'Reqdate' | $T8 %]</th>
+ <td>[% L.date_tag('filter.item_type_matches[].reqdate', FORM.filter.item_type_matches.0.reqdate, style='width: 300px') %]</td>
+ </tr>
+ <tr>
+ <th align="right">[% 'Transdate' | $T8 %]</th>
+ <td>[% L.date_tag('filter.item_type_matches[].transdate', FORM.filter.item_type_matches.0.transdate, style='width: 300px') %]</td>
+ </tr>
+ <tr>
+ <th align="right">[% 'Pricegroup' | $T8 %]</th>
+ <td>[% L.select_tag('filter.item_type_matches[].pricegroup', SELF.pricegroups, default=FORM.filter.item_type_matches.0.pricegroup, title_key='pricegroup', with_empty=1, style='width: 300px') %]<br>
+ </td>
</tr>
<tr>
<th align="right">[% 'Price' | $T8 %]</th>
- <td>[% L.input_tag('filter.price:number', filter.price_number, size=20) %]</td>
+ <td>[% L.input_tag('filter.price:number', filter.price_number, size=20, style='width: 300px') %]</td>
</tr>
<tr>
<th align="right">[% 'Discount' | $T8 %]</th>
- <td>[% L.input_tag('filter.discount:number', filter.discount_number, size=20) %]</td>
+ <td>[% L.input_tag('filter.discount:number', filter.discount_number, size=20, style='width: 300px') %]</td>
</tr>
<tr>
<th align="right">[% 'Priority' | $T8 %]</th>
<th align="right">[% 'Obsolete' | $T8 %]</th>
<td>[% L.select_tag('filter.obsolete', [ [ '', LxERP.t8('Both') ], [ 0, LxERP.t8('Valid') ], [ 1 , LxERP.t8('Obsolete')]], default=filter.obsolete, style='width: 300px') %]</td>
</tr>
+ <tr>
+ <th align="right">[% 'Has item type' | $T8 %]</th>
+ <td>
+ [%- FOREACH type = SELF.all_price_rule_item_types %]
+ [%- L.checkbox_tag('filter.has_item_type[]', value=type.0, label=type.1, checked=filter.has_item_type_.${type.0}) %]
+ [%- END %]
+ </td>
+ </tr>
+
</table>
[% L.hidden_tag('action', 'PriceRule/dispatch') %]