Revision 0a798196
Von Sven Schöling vor etwa 2 Jahren hinzugefügt
SL/Controller/PriceRule.pm | ||
---|---|---|
|
||
use Rose::Object::MakeMethods::Generic
|
||
(
|
||
'scalar --get_set_init' => [ qw(models price_rule vc pricegroups partsgroups businesses cvar) ],
|
||
'scalar --get_set_init' => [ qw(models price_rule vc pricegroups partsgroups businesses cvar_configs) ],
|
||
);
|
||
|
||
# __PACKAGE__->run_before('check_auth');
|
||
... | ... | |
sub action_add_item_row {
|
||
my ($self, %params) = @_;
|
||
|
||
my $item = SL::DB::PriceRuleItem->new(type => $::form->{type});
|
||
my $item = $::form->{type} =~ m{cvar/(\d+)}
|
||
? SL::DB::PriceRuleItem->new(type => 'cvar', custom_variable_configs_id => $1)
|
||
: SL::DB::PriceRuleItem->new(type => $::form->{type});
|
||
|
||
my $html = $self->render('price_rule/item', { output => 0 }, item => $item);
|
||
|
||
... | ... | |
}
|
||
|
||
sub all_price_rule_item_types {
|
||
SL::DB::Manager::PriceRuleItem->get_all_types($_[0]->vc || $_[0]->price_rule->type);
|
||
my $item_types = SL::DB::Manager::PriceRuleItem->get_all_types($_[0]->vc || $_[0]->price_rule->type);
|
||
my @cvar_types = map [ "cvar/" . $_->id, $_->presenter->description_with_module ], @{$_[0]->cvar_configs };
|
||
|
||
[ @$item_types, @cvar_types ];
|
||
}
|
||
|
||
sub add_javascripts {
|
||
... | ... | |
|
||
my @items;
|
||
for my $raw_item (@$items) {
|
||
my $item = $raw_item->{id} ? $old_items{ $raw_item->{id} } || SL::DB::PriceRuleItem->new(id => $raw_item->{id})->load : SL::DB::PriceRuleItem->new;
|
||
my $item = $raw_item->{id}
|
||
? $old_items{ $raw_item->{id} } || SL::DB::PriceRuleItem->new(id => $raw_item->{id})->load
|
||
: SL::DB::PriceRuleItem->new;
|
||
$item->assign_attributes(%$raw_item);
|
||
push @items, $item;
|
||
}
|
||
... | ... | |
SL::DB::Manager::PartsGroup->get_all;
|
||
}
|
||
|
||
sub init_cvar {
|
||
# SL::DB::Manager::CustomVariableConfig->get_all_sorted(where => [ module => 'IC' ]);
|
||
# proof of concept: hard coded for articlegroup
|
||
SL::DB::Manager::CustomVariableConfig->get_first(where => [ module => 'IC', name => 'articlegroup' ]) ;
|
||
sub init_cvar_configs {
|
||
# eligible cvars for this are all that are reachable from a record or recorditem (all modules but requirement spec)
|
||
# and of a type that price rules support (currently: id-based with picker, numeric or date) and by special request select
|
||
SL::DB::Manager::CustomVariableConfig->get_all(where => [
|
||
"!module" => 'RequirementSpecs',
|
||
type => [ qw(timestamp date number integer customer vendor part select) ],
|
||
]) ;
|
||
}
|
||
|
||
|
SL/DB/PriceRuleItem.pm | ||
---|---|---|
SL::DB::Pricegroup->load_cached($_[0]->value_int);
|
||
}
|
||
|
||
sub cvar_config {
|
||
die "not a cvar price rule item" unless $_[0]->type eq 'cvar';
|
||
&custom_variable_configs
|
||
}
|
||
|
||
sub full_description {
|
||
my ($self) = @_;
|
||
|
SL/Presenter/CustomVariableConfig.pm | ||
---|---|---|
package SL::Presenter::CustomVariableConfig;
|
||
|
||
use strict;
|
||
|
||
use SL::Presenter::EscapedText qw(escape is_escaped);
|
||
use SL::Locale::String qw(t8);
|
||
|
||
use Exporter qw(import);
|
||
our @EXPORT_OK = qw(cvar_config_description_with_module);
|
||
|
||
our %t8 = (
|
||
CT => t8('Customers and vendors'),
|
||
Contacts => t8('Contact persons'),
|
||
IC => t8('Parts, services and assemblies'),
|
||
Projects => t8('Projects'),
|
||
RequirementSpecs => t8('Requirement Specs'),
|
||
ShipTo => t8('Shipping Address'),
|
||
);
|
||
|
||
|
||
sub cvar_config_description_with_module {
|
||
my ($cvar_config) = @_;
|
||
|
||
my $module = $t8{$cvar_config->module};
|
||
my $description = $cvar_config->description;
|
||
|
||
escape("($module) $description");
|
||
}
|
||
|
||
sub description_with_module {
|
||
goto &cvar_config_description_with_module;
|
||
}
|
||
|
||
|
||
1;
|
templates/webpages/price_rule/item.html | ||
---|---|---|
<a class='price_rule_remove_line interact cursor-pointer'>✘</a>
|
||
[% L.hidden_tag('price_rule.items[+].id', item.id) %]
|
||
[% L.hidden_tag('price_rule.items[].type', item.type) %]
|
||
[% L.hidden_tag('price_rule.items[].custom_variable_configs_id', item.custom_variable_configs_id) %]
|
||
[%- SWITCH item.type %]
|
||
[% CASE 'part' %]
|
||
[% 'Part' | $T8 %] [% 'is' | $T8 %] [% P.part.picker('price_rule.items[].value_int', item.part) %]
|
||
... | ... | |
[% CASE 'pricegroup' %]
|
||
[% 'Pricegroup' | $T8 %] [% 'is' | $T8 %] [% L.select_tag('price_rule.items[].value_int', SELF.pricegroups, title_key='pricegroup', default=item.value_int) %]
|
||
[% CASE 'cvar' %]
|
||
[% # Dumper.dump_html(SELF.cvar.processed_options) %]
|
||
[% 'Custom Variables' | $T8 %] [% 'is' | $T8 %] [% L.select_tag('price_rule.items[].custom_variable_configs_id', SELF.cvar, title_key='description', default=item.custom_variable_configs_id ) %] [% 'with value' | $T8 %] [% L.select_tag('price_rule.items[].value_text', SELF.cvar.processed_options, title_key='options', default=item.value_text ) %]
|
||
|
||
[% # Dumper.dump_html(SELF.cvar.processed_options) %]
|
||
[% SET cvar_config = item.cvar_config %]
|
||
[% SET description = cvar_config.description %]
|
||
[% SWITCH cvar_config.type %]
|
||
[% CASE 'timestamp' %]
|
||
[% description | html %] [% L.select_tag('price_rule.items[].op', date_compare_ops, default=item.op) %] [% L.date_tag('price_rule.items[].value_date', item.value_date) %]
|
||
[% CASE 'date' %]
|
||
[% description | html %] [% L.select_tag('price_rule.items[].op', date_compare_ops, default=item.op) %] [% L.date_tag('price_rule.items[].value_date', item.value_date) %]
|
||
[% CASE 'number' %]
|
||
[% description | html %] [% L.select_tag('price_rule.items[].op', num_compare_ops, default=item.op) %] [% L.input_tag('price_rule.items[].value_num_as_number', item.value_num_as_number) %]
|
||
[% CASE 'integer' %]
|
||
[% description | html %] [% L.select_tag('price_rule.items[].op', num_compare_ops, default=item.op) %] [% L.input_tag('price_rule.items[].value_num_as_number', item.value_num_as_number) %]
|
||
[% CASE 'customer' %]
|
||
[% description | html %] [% 'is' | $T8 %] [% P.customer_vendor.picker('price_rule.items[].value_int', item.customer, type='customer') %]
|
||
[% CASE 'vendor' %]
|
||
[% description | html %] [% 'is' | $T8 %] [% P.customer_vendor.picker('price_rule.items[].value_int', item.vendor, type='vendor') %]
|
||
[% CASE 'part' %]
|
||
[% description | html %] [% 'is' | $T8 %] [% P.part.picker('price_rule.items[].value_int', item.part) %]
|
||
[% CASE 'select' %]
|
||
[% description | html %] [% 'is' | $T8 %] [% L.select_tag('price_rule.items[].value_text', cvar_config.processed_options, title_key='options', default=item.value_text ) %]
|
||
[% END %]
|
||
[% CASE %]
|
||
[%- END %]
|
||
</div>
|
Auch abrufbar als: Unified diff
CVar + PriceRule: anlegen/editieren/speichern im Preisregel Controller
Im Moment erlaubt sind alle CVar configs, die:
- irgendwie im Beleg erreichbar sind (alle module ausser Pflichtenhefte)
- und von einem Typ sind die mit dem bestehenden Preisregelsystem
abgebildet werden können. d.h.: