use SL::DB::Default;
use SL::DB::Unit;
use SL::DB::Price;
+use SL::DB::Part;
use SL::Helper::DateTime;
use SL::Helper::CreatePDF qw(:all);
+use SL::Controller::Helper::GetModels;
+
use List::Util qw(max first);
use List::MoreUtils qw(none pairwise first_index);
use English qw(-no_match_vars);
use Rose::Object::MakeMethods::Generic
(
- 'scalar --get_set_init' => [ qw(order valid_types type cv p) ],
+ 'scalar --get_set_init' => [ qw(order valid_types type cv p multi_items_models) ],
);
}
sub action_show_multi_items_dialog {
- my ($self) = @_;
-
- $self->{multi_items}->{parts} = SL::DB::Manager::Part->get_all_sorted(where => [ obsolete => 0 ]);
- my $dialog_html = $self->render('order/tabs/_multi_items_dialog', { output => 0 });
+ require SL::DB::PartsGroup;
+ $_[0]->render('order/tabs/_multi_items_dialog', { layout => 0 },
+ all_partsgroups => SL::DB::Manager::PartsGroup->get_all);
+}
- $self->js
- ->run('show_multi_items_dialog', $dialog_html, t8('Add multiple parts'))
- ->reinit_widgets
- ->render();
+sub action_multi_items_update_result {
+ $_[0]->render('order/tabs/_multi_items_result', { layout => 0 },
+ multi_items => $_[0]->multi_items_models->get);
}
sub action_add_multi_items {
_make_order();
}
+sub init_multi_items_models {
+ SL::Controller::Helper::GetModels->new(
+ controller => $_[0],
+ model => 'Part',
+ with_objects => [ qw(unit_obj) ],
+ disable_plugin => 'paginated',
+ source => $::form->{multi_items},
+ sorted => {
+ _default => {
+ by => 'partnumber',
+ dir => 1,
+ },
+ partnumber => t8('Partnumber'),
+ description => t8('Description')}
+ );
+}
+
sub _check_auth {
my ($self) = @_;
[%- USE T8 %][%- USE HTML %][%- USE L %][%- USE LxERP %]
<form method="post" id="multi_items_form" method="POST">
-<h2>[%- 'Add multiple parts' | $T8 %] [%- SELF.type | $T8 %]</h2>
-
-<table width="100%">
- [%- FOREACH part = SELF.multi_items.parts %]
- <tr>
- <td>
- [% L.hidden_tag("add_multi_items[+].parts_id", part.id) %]
- [% L.input_tag("add_multi_items[].qty", '', size => 5) %]
- </td>
- <td>[% HTML.escape(part.unit) %]</td>
- <td>[% HTML.escape(part.partnumber) %]</td>
- <td>[% HTML.escape(part.description) %]</td>
- </tr>
- [%- END %]
+
+<table id='multi_items_filter_table'>
+ <tr>
+ <th>[%- LxERP.t8("Description") %]/[%- LxERP.t8("Partnumber") %]:</th>
+ <td>[%- L.input_tag('multi_items.filter.all:substr::ilike', '') %]</td>
+ <th>[%- LxERP.t8("Group") %]</th>
+ <td>[%- L.select_tag('multi_items.filter.partsgroup_id', all_partsgroups, title_key='displayable_name', value_key='id', with_empty=1) %]</td>
+ <tr>
</table>
-<br>
-[% L.hidden_tag('action', 'Order/dispatch') %]
+[% L.button_tag('update_result()', LxERP.t8('Filter')) %]
+<a href='#' onClick='javascript:$("#multi_items_filter_table input").val("");$("#multi_items_filter_table input[type=checkbox]").prop("checked", 0);$("#multi_items_filter_table select").prop("selectedIndex", 0);'>[% 'Reset' | $T8 %]</a>
+
+<hr>
+<div id='multi_items_result'></div>
+<hr>
+
[% L.button_tag('add_multi_items()', LxERP.t8('Continue')) %]
<a href="#" onclick="close_multi_items_dialog();">[%- LxERP.t8("Cancel") %]</a>
<script type='text/javascript'>
+function update_result() {
+ var data = $('#multi_items_form').serialize();
+ data += '&type=[%- FORM.type %]';
+ $.ajax({
+ url: 'controller.pl?action=Order/multi_items_update_result',
+ data: data,
+ success: function(data){ $('#multi_items_result').html(data) }
+ });
+}
+
function add_multi_items() {
- var data = $('#order_form').serialize();
+ var data = $('#[%- FORM.callback_data_id %]').serialize();
data += '&';
data += $('#multi_items_form').serialize();
- data += '&action=Order/add_multi_items';
+ data += '&action=[%- FORM.callback %]';
$.post("controller.pl", data, kivi.eval_json_result);
}
</script>
--- /dev/null
+[%- USE T8 %][%- USE HTML %][%- USE L %][%- USE LxERP %]
+
+<table width="100%">
+ [%- FOREACH item = multi_items %]
+ <tr>
+ <td>
+ [% L.hidden_tag("add_multi_items[+].parts_id", item.id) %]
+ [% L.input_tag("add_multi_items[].qty", '', size => 5) %]
+ </td>
+ <td>[% HTML.escape(item.unit) %]</td>
+ <td>[% HTML.escape(item.partnumber) %]</td>
+ <td>[% HTML.escape(item.description) %]</td>
+ </tr>
+ [%- END %]
+</table>
[%- PROCESS order/tabs/_item_input.html %]
- [% L.button_tag('setup_multi_items_dialog()', LxERP.t8('Add multiple parts')) %]</td>
+ [% L.button_tag('show_multi_items_dialog()', LxERP.t8('Add multiple parts')) %]</td>
<table width="100%">
<tr>
$.post("controller.pl", data, kivi.eval_json_result);
}
-function setup_multi_items_dialog() {
+function show_multi_items_dialog() {
if (!check_cv()) return;
- var data = $('#order_form').serialize();
- data += '&action=Order/show_multi_items_dialog';
-
- $.post("controller.pl", data, kivi.eval_json_result);
-}
-
-var multi_items_dialog;
-
-function show_multi_items_dialog(html, title) {
- var id = 'jq_multi_items_dialog';
- var dialog_params = {
- id: id,
- width: 800,
- height: 500,
- modal: true,
- close: function(event, ui) {
- multi_items_dialog.remove();
- },
- };
-
- $('#' + id).remove();
-
- multi_items_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
- multi_items_dialog.attr('title', title);
- multi_items_dialog.html(html);
- multi_items_dialog.dialog(dialog_params);
-
- $('.cancel').click(close_multi_items_dialog);
+ var data = 'type=' + $('#type').val();
+ data += 'type=' + $('#type').val();
+ kivi.popup_dialog({
+ url: 'controller.pl?action=Order/show_multi_items_dialog',
+ data: $.extend({},
+ { 'type': $('#type').val(),
+ 'callback': 'Order/add_multi_items',
+ 'callback_data_id': 'order_form' }),
+ id: 'jq_multi_items_dialog',
+ dialog: {
+ title: kivi.t8('Add multiple items'),
+ width: 800,
+ height: 500
+ }
+ });
return true;
}
-var close_multi_items_dialog = function() {
- multi_items_dialog.dialog('close');
-}
+function close_multi_items_dialog() {
+ $('#jq_multi_items_dialog').dialog('close');
+};
function delete_order_item_row(clicked) {
var row = $(clicked).parents("tbody").first();