Skip to content

Commit

Permalink
S:C:Part: Massendruck für Artikeletiketten
Browse files Browse the repository at this point in the history
  • Loading branch information
z4m1n0 committed Nov 16, 2024
1 parent e84b30f commit d13114c
Show file tree
Hide file tree
Showing 10 changed files with 363 additions and 14 deletions.
200 changes: 193 additions & 7 deletions SL/Controller/Part.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use SL::DB::History;
use SL::DB::Part;
use SL::DB::PartsGroup;
use SL::DB::PriceRuleItem;
use SL::DB::PartLabelPrint;
use SL::DB::PurchaseBasketItem;
use SL::DB::Shop;
use SL::Helper::Flash;
Expand All @@ -34,7 +35,9 @@ use SL::Locale::String qw(t8);
use SL::MoreCommon qw(save_form);
use SL::Presenter::EscapedText qw(escape is_escaped);
use SL::Presenter::Part;
use SL::Presenter::Tag qw(select_tag);
use SL::Presenter::Tag qw(select_tag checkbox_tag);
use SL::ReportGenerator;
use SL::Controller::Helper::ReportGenerator;

use Rose::Object::MakeMethods::Generic (
'scalar --get_set_init' => [ qw(parts models part p warehouses multi_items_models
Expand Down Expand Up @@ -138,6 +141,25 @@ sub action_save_and_print {
$self->js_reset_part_after_save();
$self->js->flash('info', t8('The item has been saved.'));

$self->print_part($self->part);

$self->js->render();
}

sub action_print_multi {
my ($self) = @_;

my $parts = SL::DB::Manager::Part->get_all(where => [id => $::form->{ids}]);
foreach my $part(@{$parts}) {
$self->print_part($part);
}

$self->js->render();
}

sub print_part {
my ($self, $part) = @_;

my $formname = $::form->{print_options}->{formname};
my $format = $::form->{print_options}->{format};
my $media = $::form->{print_options}->{media};
Expand All @@ -147,9 +169,10 @@ sub action_save_and_print {
$language = SL::DB::Manager::Language->find_by(
id => $::form->{print_options}->{language_id}
);
}
my $copies;
if ($::form->{print_options}->{part_labels_for_stock}) {
$copies = $self->part->stockqty;
$copies = $part->stockqty;
} else {
$copies = $::form->{print_options}->{copies};
}
Expand Down Expand Up @@ -178,13 +201,13 @@ sub action_save_and_print {
}

my $print_form = Form->new('');
$print_form->{part} = $self->part;
$print_form->{part} = $part;

# for doc_filename
$print_form->{type} = 'part';
$print_form->{formname} = $formname;
$print_form->{format} = $format;
$print_form->{partnumber} = $self->part->partnumber;
$print_form->{partnumber} = $part->partnumber;
$print_form->{language} = $language && ("_" .
($language->template_code || $language->description)
);
Expand Down Expand Up @@ -244,8 +267,6 @@ sub action_save_and_print {
->flash('error', t8("Creating the PDF failed!"))
->flash('error', $@);
};

$self->js->render();
}

sub action_save_and_purchase_order {
Expand Down Expand Up @@ -915,6 +936,137 @@ sub action_showdetails {
$self->render(\$output, { layout => 0, process => 0 });
}

sub action_search_print_part_labels_of_changed_prices {
my ($self) = @_;
$self->_setup_search_print_part_labels_of_changed_prices_action_bar();

$::form->{filter} ||= {};

$::form->{filter}->{price_change_printed} ||= {
template => 'part_label',
print_type => 'stock',
printed => 0
};

my $price_change_printed =$::form->{filter}->{price_change_printed};
$::form->{filter}->{price_change_printed} = \$price_change_printed;

my $report = SL::ReportGenerator->new(\%::myconfig, $::form);

$self->models->finalize; # for filter laundering

$::form->{filter}->{price_change_printed} = ${$::form->{filter}->{price_change_printed}};

my $callback = $self->models->get_callback;

$self->{report} = $report;

my @columns_order = qw(
id_check_box
partnumber
ean
description
notes
partsgroup
);

my @default_columns = qw(
id_check_box
partnumber
ean
description
partsgroup
);

my %column_defs = (
id_check_box => {
raw_data => sub {
checkbox_tag("ids[]", value => $_[0]->id, "data-checkall" => 1, checked => 1);
},
raw_header_data => checkbox_tag("", id => "check_all", checkall => "[data-checkall=2]", checked => 1),
text => ' ',
},
partnumber => {
obj_link => sub {$self->url_for(action => 'edit', 'part.id' => $_[0]->id, callback => $callback)},
sub => sub { $_[0]->partnumber },
},
ean => {
obj_link => sub {$self->url_for(action => 'edit', 'part.id' => $_[0]->id, callback => $callback)},
sub => sub { $_[0]->ean },
},
description => {
sub => sub {$_[0]->description },
},
notes => {
sub => sub {$_[0]->notes },
},
partsgroup => {
sub => sub {t8($_[0]->partsgroup ? $_[0]->partsgroup->partsgroup : '') },
},
);

$column_defs{$_}->{text} ||= t8( $self->models->get_sort_spec->{$_}->{title} || $_ )
for keys %column_defs;

unless ($::form->{active_in_report}) {
$::form->{active_in_report}->{$_} = 1 foreach @default_columns;
}

$self->models->add_additional_url_params(
active_in_report => $::form->{active_in_report});
map { $column_defs{$_}->{visible} = $::form->{active_in_report}->{"$_"} || 0 }
grep {$_ ne 'id_check_box'}
keys %column_defs;

# make all sortable
my @sortable =
grep {$_ ne 'id_check_box'}
keys %column_defs;

use SL::Presenter::Filter::Part;
my $filter_html = SL::Presenter::Filter::Part::filter(
$::form->{filter},
show_price_change_printed_filter => 1,
active_in_report => $::form->{active_in_report}
);

$report->set_options(
std_column_visibility => 1,
controller_class => 'Part',
output_format => 'HTML',
raw_top_info_text => $self->render(
'part/_print_part_labels_of_changed_prices_report_top',
{ output => 0 },
FILTER_HTML => $filter_html,
),
raw_bottom_info_text => $self->render(
'part/_print_part_labels_of_changed_prices_report_bottom',
{ output => 0 },
models => $self->models
),
title => t8('Parts with Changed Prices'),
allow_pdf_export => 1,
allow_csv_export => 1,
);

$report->set_columns(%column_defs);
$report->set_column_order(@columns_order);
$report->set_export_options(
'search_print_part_labels_of_changed_prices',
qw(filter active_in_report)
);
$report->set_options_from_form;
$self->models->set_report_generator_sort_options(
report => $report,
sortable_columns => \@sortable
);

$self->report_generator_list_objects(
report => $report,
objects => $self->models->get,
);
}

sub action_print_label {
my ($self) = @_;
# TODO: implement
Expand Down Expand Up @@ -1437,7 +1589,10 @@ sub init_models {
dir => 1,
},
partnumber => t8('Partnumber'),
description => t8('Description'),
description => t8('Description'),
ean => t8('EAN'),
notes => t8('Notes'),
partsgroup => t8('Partsgroup'),
},
with_objects => [ qw(unit_obj classification) ],
);
Expand Down Expand Up @@ -2025,6 +2180,37 @@ sub _setup_form_action_bar {
}
}

sub _setup_search_print_part_labels_of_changed_prices_action_bar {
my ($self, %params) = @_;

for my $bar ($::request->layout->get('actionbar')) {
$bar->add(
action => [
t8('Update'),
submit => [
'#filter_form', {
action => 'Part/search_print_part_labels_of_changed_prices',
}
],
accesskey => 'enter',
],
combobox => [
action => [
t8('Print'),
],
action => [
t8('Print one Label'),
call => [ 'kivi.Part.show_print_options' ],
],
action => [
t8('Print Labels for Stock'),
call => [ 'kivi.Part.show_part_labels_for_stock_print_options' ],
],
],
);
}
}

1;

__END__
Expand Down
69 changes: 69 additions & 0 deletions SL/DB/Manager/Part.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,75 @@ __PACKAGE__->add_filter_specs(
return or => [ map { $prefix . $_ => $value } qw(partnumber description ean customerprices.customer_partnumber) ],
$prefix . 'customerprices';
},
price_change_printed => sub {
my ($key, $value, $prefix) = @_;
die "value must be a scalar ref to a hash ref"
unless ref $value eq 'REF' && ref ($$value) eq 'HASH';

my %value = %$$value;

my $template = $value{template};
my $print_type = $value{print_type};
my $printed = $value{printed};

my $comp = !!$printed ? '>' : '<=';

# table part_table is aliased as t1
return
[\qq{(
SELECT DISTINCT CASE WHEN count(*) $comp 1 THEN FALSE ELSE TRUE END
FROM (
(
-- last printed or first price
SELECT t2_sellprice
FROM (
(
SELECT
parts_price_history.sellprice AS t2_sellprice,
parts_price_history.valid_from AS t2_valid_from,
parts_price_history.id as t2_id
FROM parts_price_history
JOIN part_label_prints
ON (parts_price_history.id = part_label_prints.price_history_id)
WHERE parts_price_history.part_id = t1.id AND (
('' = ? OR part_label_prints.template = ?) AND
('' = ? OR part_label_prints.print_type = ?)
)
ORDER by
parts_price_history.valid_from DESC,
parts_price_history.id DESC
LIMIT 1
) UNION (
SELECT
parts_price_history.sellprice AS t2_sellprice,
parts_price_history.valid_from AS t2_valid_from,
parts_price_history.id as t2_id
FROM parts_price_history
WHERE part_id = t1.id
ORDER BY
parts_price_history.valid_from ASC,
parts_price_history.id ASC
LIMIT 1
)
)
ORDER by
t2_valid_from DESC,
t2_id DESC
LIMIT 1
) UNION (
-- current price
SELECT parts_price_history.sellprice AS t2_sellprice
FROM parts_price_history
WHERE part_id = t1.id
ORDER BY
parts_price_history.valid_from DESC,
parts_price_history.id
DESC LIMIT 1
)
)
)} => ($template, $template, $print_type, $print_type || 'stock')
] => \'TRUE';
},
);

sub type_filter {
Expand Down
24 changes: 22 additions & 2 deletions js/kivi.Part.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,26 @@ namespace('kivi.Part', function(ns) {
$.post("controller.pl", data, kivi.eval_json_result);
};

ns.print_multi = function() {
$('#print_options').dialog('close');

var data = $('#report_form').serializeArray();
data = data.concat($('#print_options_form').serializeArray());
data.push({ name: 'action', value: 'Part/print_multi' });

$.post("controller.pl", data, kivi.eval_json_result);
};

ns.show_part_labels_for_stock_print_options = function() {
kivi.popup_dialog({
id: 'print_part_labels_for_stock_print_options',
dialog: {
title: kivi.t8('Part Labels for Stock Print options'),
title: kivi.t8('Print options for Stock Print'),
width: 800,
height: 300
}
});
}
};

ns.save_and_print_part_labels_for_stock = function() {
$('#print_part_labels_for_stock_print_options').dialog('close');
Expand All @@ -71,6 +81,16 @@ namespace('kivi.Part', function(ns) {
$.post("controller.pl", data, kivi.eval_json_result);
};

ns.print_multi_part_labels_for_stock = function() {
$('#print_part_labels_for_stock_print_options').dialog('close');

var data = $('#report_form').serializeArray();
data = data.concat($('#print_part_labels_for_stock_print_options_form').serializeArray());
data.push({ name: 'action', value: 'Part/print_multi' });

$.post("controller.pl", data, kivi.eval_json_result);
};

ns.delete = function() {
var data = $('#ic').serializeArray();
data.push({ name: 'action', value: 'Part/delete' });
Expand Down
1 change: 1 addition & 0 deletions js/locale/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ namespace("kivi").setupLocale({
"Previous month":"vorheriger Monat",
"Price Types":"Preistypen",
"Print options":"Druckoptionen",
"Print options for Stock Print":"Druckoptionen für Bestand-Druck",
"Print record":"Beleg drucken",
"Project link actions":"Projektverknüpfungs-Aktionen",
"Project picker":"Projektauswahl",
Expand Down
Loading

0 comments on commit d13114c

Please sign in to comment.