Revision 98404f3e
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
| SL/Controller/Part.pm | ||
|---|---|---|
|
use SL::JSON;
|
||
|
use SL::Locale::String qw(t8);
|
||
|
use SL::MoreCommon qw(save_form);
|
||
|
use SL::Presenter;
|
||
|
use SL::Presenter::EscapedText qw(escape is_escaped);
|
||
|
use SL::Presenter::Part;
|
||
|
use SL::Presenter::Tag qw(select_tag);
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
|
||
|
sub action_show_multi_variants_dialog {
|
||
|
my ($self) = @_;
|
||
|
|
||
|
$self->render('part/_multi_variants_dialog', { layout => 0 });
|
||
|
}
|
||
|
|
||
|
sub action_multi_variants_update_result {
|
||
|
my ($self) = @_;
|
||
|
my $max_count = $::form->{limit};
|
||
|
|
||
|
my $parent_variant_id = $::form->{multi_items}->{filter}->{parent_variant_id};
|
||
|
my $parent_variant;
|
||
|
$parent_variant = SL::DB::Manager::Part->find_by(
|
||
|
id => $parent_variant_id
|
||
|
) if $parent_variant_id ne '';
|
||
|
return $self->js->flash('error', t8('No parent variant selected.'))->render
|
||
|
unless $parent_variant;
|
||
|
|
||
|
|
||
|
if ($::form->{old_parent_variant_id} ne $parent_variant_id) {
|
||
|
# update parent_variant properties
|
||
|
my $properties_table = SL::Presenter->get->render(
|
||
|
'part/_multi_variants_parent_properties_table',
|
||
|
PROPERTIES => \@{$parent_variant->variant_properties}
|
||
|
);
|
||
|
$::form->{multi_items}->{filter}->{'has_variant_property_value_id'} = [];
|
||
|
$self->js->html('#multi_variants_parent_variant_properties', $properties_table);
|
||
|
$self->js->val('#old_parent_variant_id', $parent_variant_id);
|
||
|
}
|
||
|
|
||
|
my $count = $self->multi_items_models->count;
|
||
|
|
||
|
my $result;
|
||
|
if ($count == 0) {
|
||
|
my $text = escape($::locale->text('No results.'));
|
||
|
$result = $text;
|
||
|
} elsif ($max_count && $count > $max_count) {
|
||
|
my $text = escape($::locale->text('Too many results (#1 from #2).', $count, $max_count));
|
||
|
$result = $text;
|
||
|
} else {
|
||
|
my $multi_variants = SL::DB::Manager::Part->sort_variants(
|
||
|
$self->multi_items_models->get
|
||
|
);
|
||
|
$result = SL::Presenter->get->render('part/_multi_variants_result', multi_variants => $multi_variants);
|
||
|
}
|
||
|
|
||
|
$self->js->html('#multi_items_result', $result)->render;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
sub action_add_makemodel_row {
|
||
|
my ($self) = @_;
|
||
|
|
||
| ... | ... | |
|
SL::Controller::Helper::GetModels->new(
|
||
|
controller => $_[0],
|
||
|
model => 'Part',
|
||
|
with_objects => [ qw(unit_obj partsgroup classification) ],
|
||
|
with_objects => [ qw(unit_obj partsgroup classification parent_variants variant_property_values variant_property_values.variant_property) ],
|
||
|
disable_plugin => 'paginated',
|
||
|
source => $::form->{multi_items},
|
||
|
sorted => {
|
||
| SL/DB/Manager/Part.pm | ||
|---|---|---|
|
return or => [ map { $prefix . $_ => $value } qw(partnumber description ean customerprices.customer_partnumber) ],
|
||
|
$prefix . 'customerprices';
|
||
|
},
|
||
|
has_variant_property_value_id => sub {
|
||
|
my ($key, $value, $prefix) = @_;
|
||
|
|
||
|
my @values = grep {$_}
|
||
|
ref $value eq 'ARRAY' ? @{$value} : split(/\s+/, $value);
|
||
|
return unless scalar @values;
|
||
|
|
||
|
my $where = join(' or ', ("val.id = ?") x @values) || '1=1';
|
||
|
my $query = <<SQL;
|
||
|
SELECT part_id from (
|
||
|
SELECT
|
||
|
t1.part_id, COUNT(*) as count_hits
|
||
|
FROM
|
||
|
variant_property_values val
|
||
|
JOIN variant_property_values_parts t1 ON (t1.variant_property_value_id = val.id)
|
||
|
WHERE
|
||
|
$where
|
||
|
GROUP BY t1.part_id
|
||
|
) as tmp
|
||
|
WHERE count_hits >= ?;
|
||
|
SQL
|
||
|
|
||
|
push @values, scalar @values; # count_hits
|
||
|
|
||
|
my @part_ids =
|
||
|
map {$_->{part_id}}
|
||
|
selectall_hashref_query($::form, $::form->get_standard_dbh, $query, @values);
|
||
|
|
||
|
return id => scalar @part_ids ? \@part_ids : (-1); # empty list not allowed
|
||
|
},
|
||
|
# all_with_variants => sub {
|
||
|
all => sub {
|
||
|
my ($key, $value, $prefix) = @_;
|
||
| ... | ... | |
|
return $open_qty
|
||
|
}
|
||
|
|
||
|
sub sort_variants {
|
||
|
my ($self, $variants) = @_;
|
||
|
|
||
|
my @sorted_variants =
|
||
|
map { $_->{variant} }
|
||
|
sort { $a->{sortkey} cmp $b->{sortkey} }
|
||
|
map { {
|
||
|
variant => $_,
|
||
|
sortkey => join('', map {
|
||
|
(10000 + $_->variant_property->sortkey ) . (10000 + $_->sortkey)
|
||
|
} @{$_->variant_property_values}
|
||
|
),
|
||
|
|
||
|
} }
|
||
|
@$variants;
|
||
|
return \@sorted_variants;
|
||
|
}
|
||
|
|
||
|
sub _sort_spec {
|
||
|
(
|
||
|
default => [ 'partnumber', 1 ],
|
||
| js/kivi.Part.js | ||
|---|---|---|
|
this.last_dummy = this.$dummy.val();
|
||
|
this.timer = undefined;
|
||
|
this.dialog = undefined;
|
||
|
// for different popups on same page
|
||
|
this.multiple_default = this.o.multiple;
|
||
|
this.variants_list_default = this.o.variants_list;
|
||
|
|
||
|
this.init();
|
||
|
};
|
||
| ... | ... | |
|
}
|
||
|
},
|
||
|
open_dialog: function() {
|
||
|
if (this.o.multiple) {
|
||
|
if (this.o.variants_list) {
|
||
|
this.o.variants_list = this.variants_list_default;
|
||
|
this.dialog = new ns.PickerMultiVariantPopup(this);
|
||
|
} else if (this.o.multiple) {
|
||
|
this.o.multiple = this.multiple_default;
|
||
|
this.dialog = new ns.PickerMultiPopup(this);
|
||
|
} else {
|
||
| ... | ... | |
|
}
|
||
|
};
|
||
|
|
||
|
ns.PickerMultiVariantPopup = function(pp) {
|
||
|
this.pp = pp;
|
||
|
this.open_dialog();
|
||
|
};
|
||
|
|
||
|
ns.PickerMultiVariantPopup.prototype = {
|
||
|
open_dialog: function() {
|
||
|
var self = this;
|
||
|
$('#row_table_id thead a img').remove();
|
||
|
|
||
|
kivi.popup_dialog({
|
||
|
url: 'controller.pl?action=Part/show_multi_variants_dialog',
|
||
|
data: $.extend({
|
||
|
real_id: self.pp.real_id,
|
||
|
show_pos_input: self.pp.o.multiple_pos_input,
|
||
|
}, self.pp.ajax_data(this.pp.$dummy.val())),
|
||
|
id: 'jq_multi_variants_dialog',
|
||
|
dialog: {
|
||
|
title: kivi.t8('Add multiple variants'),
|
||
|
width: 800,
|
||
|
height: 800
|
||
|
},
|
||
|
load: function() {
|
||
|
self.init_search();
|
||
|
}
|
||
|
});
|
||
|
return true;
|
||
|
},
|
||
|
init_search: function() {
|
||
|
|
||
|
var self = this;
|
||
|
$('#multi_items_filter_table select').keydown(function(event) {
|
||
|
if(event.which == KEY.ENTER) {
|
||
|
event.preventDefault();
|
||
|
self.update_results();
|
||
|
return false;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// reset picker for parent_variant
|
||
|
kivi.run_once_for('input.part_autocomplete', 'part_picker', function(elt) {
|
||
|
if (!$(elt).data('part_picker'))
|
||
|
$(elt).data('part_picker', new kivi.Part.Picker($(elt)));
|
||
|
});
|
||
|
$('#multi_items_filter_parent_variant_id_name').focus();
|
||
|
$('#multi_items_filter_button').click(function(){ self.update_results(); });
|
||
|
$('#multi_items_filter_reset').click(function(){
|
||
|
$("#multi_items_form").resetForm();
|
||
|
$("#multi_variants_parent_variant_properties").html('');
|
||
|
$("#old_parent_variant_id").val('');
|
||
|
$("#multi_items_result").html('');
|
||
|
});
|
||
|
$('#continue_button').click(function(){ self.add_multi_items(); });
|
||
|
},
|
||
|
update_results: function() {
|
||
|
var self = this;
|
||
|
var data = $('#multi_items_form').serializeArray();
|
||
|
data.push({ name: 'action', value: 'Part/multi_variants_update_result' });
|
||
|
data.push({ name: 'type', value: self.pp.type });
|
||
|
data.push({ name: 'limit', value: self.pp.o.multiple_limit });
|
||
|
var ppdata = self.pp.ajax_data(function(){
|
||
|
var val = $('#multi_items_filter').val();
|
||
|
return val === undefined ? '' : val;
|
||
|
});
|
||
|
$.each(Object.keys(ppdata), function() {data.push({ name: 'multi_items.' + this, value: ppdata[this]});});
|
||
|
|
||
|
$.post(
|
||
|
"controller.pl",
|
||
|
data,
|
||
|
function(data){
|
||
|
kivi.eval_json_result(data);
|
||
|
self.init_results();
|
||
|
self.enable_continue();
|
||
|
}
|
||
|
);
|
||
|
},
|
||
|
set_qty_to_one: function(clicked) {
|
||
|
if ($(clicked).val() === '') {
|
||
|
$(clicked).val(kivi.format_amount(1.00, -2));
|
||
|
}
|
||
|
$(clicked).select();
|
||
|
},
|
||
|
init_results: function() {
|
||
|
var self = this;
|
||
|
$('#multi_items_all_qty').change(function(event){
|
||
|
$('.multi_items_qty').val($(event.target).val());
|
||
|
});
|
||
|
$('.multi_items_qty').focus(function(){ self.set_qty_to_one(this); });
|
||
|
},
|
||
|
result_timer: function() {
|
||
|
},
|
||
|
close_dialog: function() {
|
||
|
$('#jq_multi_variants_dialog').dialog('close');
|
||
|
},
|
||
|
disable_continue: function() {
|
||
|
$('#multi_items_result input, #multi_items_position').off("keydown");
|
||
|
$('#continue_button').prop('disabled', true);
|
||
|
},
|
||
|
enable_continue: function() {
|
||
|
var self = this;
|
||
|
$('#multi_items_result input, #multi_items_position').keydown(function(event) {
|
||
|
if(event.keyCode == KEY.ENTER) {
|
||
|
event.preventDefault();
|
||
|
self.add_multi_items();
|
||
|
return false;
|
||
|
}
|
||
|
});
|
||
|
$('#continue_button').prop('disabled', false);
|
||
|
},
|
||
|
add_multi_items: function() {
|
||
|
// rows at all
|
||
|
var n_rows = $('.multi_items_qty').length;
|
||
|
if ( n_rows === 0) { return; }
|
||
|
|
||
|
// filled rows
|
||
|
n_rows = $('.multi_items_qty').filter(function() {
|
||
|
return $(this).val().length > 0;
|
||
|
}).length;
|
||
|
if (n_rows === 0) { return; }
|
||
|
|
||
|
this.disable_continue();
|
||
|
|
||
|
var data = $('#multi_items_form').serializeArray();
|
||
|
this.pp.set_multi_items(data);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
ns.reinit_widgets = function() {
|
||
|
kivi.run_once_for('input.part_autocomplete', 'part_picker', function(elt) {
|
||
|
if (!$(elt).data('part_picker'))
|
||
| js/locale/de.js | ||
|---|---|---|
|
"Add function block":"Funktionsblock hinzufügen",
|
||
|
"Add linked record":"Verknüpften Beleg hinzufügen",
|
||
|
"Add multiple items":"Mehrere Artikel hinzufügen",
|
||
|
"Add multiple variants":"Mehrere Varianten hinzufügen",
|
||
|
"Add note":"Notiz erfassen",
|
||
|
"Add picture":"Bild hinzufügen",
|
||
|
"Add picture to text block":"Bild dem Textblock hinzufügen",
|
||
| js/locale/en.js | ||
|---|---|---|
|
"Add function block":"",
|
||
|
"Add linked record":"",
|
||
|
"Add multiple items":"",
|
||
|
"Add multiple variants":"",
|
||
|
"Add note":"",
|
||
|
"Add picture":"",
|
||
|
"Add picture to text block":"",
|
||
| locale/de/all | ||
|---|---|---|
|
'Add linked record' => 'Verknüpften Beleg hinzufügen',
|
||
|
'Add links' => 'Verknüpfungen hinzufügen',
|
||
|
'Add multiple items' => 'Mehrere Artikel hinzufügen',
|
||
|
'Add multiple variants' => 'Mehrere Varianten hinzufügen',
|
||
|
'Add new currency' => 'Neue Währung hinzufügen',
|
||
|
'Add new custom variable' => 'Neue benutzerdefinierte Variable erfassen',
|
||
|
'Add new price rule item' => 'Neue Bedingung hinzufügen',
|
||
| ... | ... | |
|
'No internal phone extensions have been configured yet.' => 'Es wurden noch keine internen Durchwahlen konfiguriert.',
|
||
|
'No invoice email found.' => 'Keine Rechnungsmailadresse gefunden.',
|
||
|
'No invoices have been selected.' => 'Es wurden keine Rechnungen ausgewählt.',
|
||
|
'No parent variant selected.' => 'Kein Stammartikel ausgewählt.',
|
||
|
'No part was selected.' => 'Es wurde kein Artikel ausgewählt.',
|
||
|
'No parts selected.' => 'Es wurden keine Artikel ausgewählt.',
|
||
|
'No partsgroup selected.' => 'Es wurde keine Warengruppen ausgewählt.',
|
||
| locale/en/all | ||
|---|---|---|
|
'Add linked record' => '',
|
||
|
'Add links' => '',
|
||
|
'Add multiple items' => '',
|
||
|
'Add multiple variants' => '',
|
||
|
'Add new currency' => '',
|
||
|
'Add new custom variable' => '',
|
||
|
'Add new price rule item' => '',
|
||
| ... | ... | |
|
'No internal phone extensions have been configured yet.' => '',
|
||
|
'No invoice email found.' => '',
|
||
|
'No invoices have been selected.' => '',
|
||
|
'No parent variant selected.' => '',
|
||
|
'No part was selected.' => '',
|
||
|
'No parts selected.' => '',
|
||
|
'No partsgroup selected.' => '',
|
||
| templates/design40_webpages/part/_multi_variants_dialog.html | ||
|---|---|---|
|
[% USE T8 %]
|
||
|
[% USE HTML %]
|
||
|
[% USE L %]
|
||
|
[% USE P %]
|
||
|
[% USE LxERP %]
|
||
|
|
||
|
<form method="post" id="multi_items_form" method="POST">
|
||
|
|
||
|
<div class="buttons">
|
||
|
[% L.button_tag('', LxERP.t8('Filter'), id='multi_items_filter_button') %]
|
||
|
[% L.button_tag('', LxERP.t8('Reset'), id='multi_items_filter_reset') %]
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div class="select-item control-panel">
|
||
|
<table id="multi_items_filter_table" class="tbl-plain">
|
||
|
<colgroup>
|
||
|
<col class="wi-wide">
|
||
|
<col class="wi-wide">
|
||
|
</colgroup>
|
||
|
<tr>
|
||
|
<th>
|
||
|
[% LxERP.t8("Description") %]/[% LxERP.t8("Partnumber") %]
|
||
|
</th>
|
||
|
<td>
|
||
|
[% L.hidden_tag("old_parent_variant_id", '' ) %]
|
||
|
[% P.part.picker(
|
||
|
'multi_items.filter.parent_variant_id', '',
|
||
|
variant_type="parent_variant",
|
||
|
onchange='$("#multi_items_filter_button").click();',
|
||
|
class="wi-wide"
|
||
|
) %]
|
||
|
</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
|
||
|
<div id="multi_variants_parent_variant_properties"/>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div id="multi_items_result"></div>
|
||
|
|
||
|
[%- IF FORM.show_pos_input -%]
|
||
|
[% 'At position' | $T8 %]
|
||
|
[% L.input_tag('multi_items.position', '', id='multi_items_position', size=5, class="numeric") %]
|
||
|
[%- END -%]
|
||
|
<div class="buttons">
|
||
|
[% L.button_tag('', LxERP.t8('Continue'), id='continue_button') %]
|
||
|
</div>
|
||
|
|
||
|
</form>
|
||
| templates/design40_webpages/part/_multi_variants_parent_properties_table.html | ||
|---|---|---|
|
[% USE T8 %]
|
||
|
[% USE HTML %]
|
||
|
[% USE L %]
|
||
|
[% USE LxERP %]
|
||
|
[% USE P %]
|
||
|
|
||
|
<table id="variant_parent_properties">
|
||
|
<colgroup>
|
||
|
<col class="wi-wide">
|
||
|
<col class="wi-wide">
|
||
|
</colgroup>
|
||
|
<tbody>
|
||
|
[% FOREACH property = PROPERTIES %]
|
||
|
<tr>
|
||
|
<th>[% property.displayable_name | html %]</th>
|
||
|
<td>[% L.select_tag("multi_items.filter.has_variant_property_value_id[+]",
|
||
|
property.property_values,
|
||
|
value_key="id", title_key="displayable_name",
|
||
|
with_empty=1, default='',
|
||
|
onchange='$("#multi_items_filter_button").click();',
|
||
|
class='wi-wide',
|
||
|
) %]</td>
|
||
|
</tr>
|
||
|
[% END %]
|
||
|
</tbody>
|
||
|
</table>
|
||
| templates/design40_webpages/part/_multi_variants_result.html | ||
|---|---|---|
|
[% USE T8 %]
|
||
|
[% USE HTML %]
|
||
|
[% USE L %]
|
||
|
[% USE LxERP %]
|
||
|
[% USE P %]
|
||
|
|
||
|
<table id="multi_items" class="tbl-list">
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th>[% 'for all' | $T8 %]</th>
|
||
|
<th>[% L.input_tag("multi_items.all_qty", '', size=5, class='numeric wi-verysmall') %]</th>
|
||
|
<th colspan="4"></th>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<th></th>
|
||
|
<th>[% 'Qty' | $T8 %]</th>
|
||
|
<th>[% 'Unit' | $T8 %]</th>
|
||
|
<th>[% 'Article' | $T8 %]</th>
|
||
|
<th>[% 'Sellprice' | $T8 %]</th>
|
||
|
<th>[% 'Partsgroup' | $T8 %]</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
|
[% FOREACH item = multi_variants %]
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>
|
||
|
[% L.hidden_tag("add_items[+].parts_id", item.id) %]
|
||
|
[% L.input_tag("add_items[].qty_as_number", '', size=5, class = 'multi_items_qty numeric wi-verysmall') %]
|
||
|
</td>
|
||
|
<td>[% HTML.escape(item.unit) %]</td>
|
||
|
<td>[% item.presenter.part(tabindex="-1") %] [% HTML.escape(item.description) %] [% HTML.escape(item.variant_values) %]</td>
|
||
|
<td class="numeric">[% HTML.escape(item.sellprice_as_number) %]</td>
|
||
|
<td class="numeric">[% HTML.escape(item.partsgroup.partsgroup) %]</td>
|
||
|
</tr>
|
||
|
[% END %]
|
||
|
</tbody>
|
||
|
</table>
|
||
Auch abrufbar als: Unified diff
Varianten: PartPicker: mehrere Varianten eines Stammartikel hinzufügen