X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fwh.pl;h=66594ff685325196f2f959c3e3db04e2c9ffdd6d;hb=5067d7bd31514962af9730b33323b831d87164f8;hp=f4971078554893cee622d2032ff57db942eabc38;hpb=e055700faea1906bea6c03184ba4516b57cac887;p=kivitendo-erp.git diff --git a/bin/mozilla/wh.pl b/bin/mozilla/wh.pl index f49710785..66594ff68 100644 --- a/bin/mozilla/wh.pl +++ b/bin/mozilla/wh.pl @@ -44,6 +44,8 @@ use SL::WH; use SL::OE; use SL::ReportGenerator; +use SL::DB::Part; + use Data::Dumper; require "bin/mozilla/common.pl"; @@ -65,6 +67,7 @@ use strict; # $locale->text('used') # $locale->text('return_material') # $locale->text('release_material') +# $locale->text('assembled') # -------------------------------------------------------------------- # Transfer @@ -85,8 +88,16 @@ sub transfer_warehouse_selection { show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} }); my $units = AM->retrieve_units(\%myconfig, $form); + + my $part = 0; + if ( $form->{parts_id} ) { + $part = SL::DB::Part->new(); + $part->id($form->{parts_id}); + $part->load(); + } + # der zweite Parameter von unit_select_data gibt den default-Namen (selected) vor - $form->{UNITS} = AM->unit_select_data($units, $form->{partunit}, 0, $form->{partunit}); + $form->{UNITS} = AM->unit_select_data($units, $form->{unit}, 0, $part ? $part->unit : 0); if (scalar @{ $form->{WAREHOUSES} }) { $form->{warehouse_id} ||= $form->{WAREHOUSES}->[0]->{id}; @@ -95,8 +106,6 @@ sub transfer_warehouse_selection { my $content; - $form->{jsscript} = 1; - if ($form->{trans_type} eq 'removal') { $form->{nextsub} = "removal_parts_selection"; $form->{title} = $locale->text('Removal from Warehouse'); @@ -272,6 +281,7 @@ sub transfer_parts { } $transfer->{comment} = $form->{comment}; + $transfer->{change_default_bin} = $form->{change_default_bin}; push @transfers, $transfer; @@ -280,7 +290,7 @@ sub transfer_parts { if (!scalar @transfers) { $form->show_generic_information($locale->text('Nothing has been selected for transfer.')); - ::end_of_request(); + $::dispatcher->end_request; } WH->transfer(@transfers); @@ -321,7 +331,7 @@ sub transfer_stock_update_part { if (!scalar @{ $parts }) { new_item(action => "transfer_stock_update_part"); } elsif (scalar @{ $parts } == 1) { - @{$form}{qw(parts_id partnumber description ean)} = @{$parts->[0]}{qw(id partnumber description ean)}; + @{$form}{qw(parts_id partnumber description ean warehouse_id bin_id)} = @{$parts->[0]}{qw(id partnumber description ean warehouse_id bin_id)}; transfer_stock_get_partunit(); transfer_warehouse_selection(); @@ -388,7 +398,7 @@ sub transfer_stock_part_selected { my $form = $main::form; - @{$form}{qw(parts_id partnumber description ean)} = @{$part}{qw(id partnumber description ean)}; + @{$form}{qw(parts_id partnumber description ean warehouse_id bin_id)} = @{$part}{qw(id partnumber description ean warehouse_id bin_id)}; transfer_stock_get_partunit(); transfer_warehouse_selection(); @@ -438,7 +448,7 @@ sub create_assembly { $form->error($locale->text('The warehouse or the bin is missing.')); } - if (!$::lx_office_conf{system}->{show_best_before}) { + if (!$::instance_conf->get_show_bestbefore) { $form->{bestbefore} = ''; } @@ -446,7 +456,7 @@ sub create_assembly { # Anm. jb 18.3. vielleicht auch nur meine unwissenheit in perl-datenstrukturen my %TRANSFER = ( 'transfer_type' => 'assembly', - 'login' => $form->{login}, + 'login' => $::myconfig{login}, 'dst_warehouse_id' => $form->{warehouse_id}, 'dst_bin_id' => $form->{bin_id}, 'chargenumber' => $form->{chargenumber}, @@ -614,7 +624,7 @@ sub remove_parts { if (!scalar @transfers) { $form->show_generic_information($locale->text('Nothing has been selected for removal.')); - ::end_of_request(); + $::dispatcher->end_request; } WH->transfer(@transfers); @@ -646,8 +656,6 @@ sub journal { show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} }); - $form->{jsscript} = 1; - $form->header(); print $form->parse_html_template("wh/journal_filter", { "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) }); @@ -666,11 +674,13 @@ sub generate_journal { $form->{title} = $locale->text("WHJournal"); $form->{sort} ||= 'date'; + $form->{report_generator_output_format} = 'HTML' if !$form->{report_generator_output_format}; + my %filter; - my @columns = qw(trans_id date warehouse_from bin_from warehouse_to bin_to partnumber partdescription chargenumber bestbefore trans_type comment qty employee oe_id projectnumber); + my @columns = qw(trans_id date warehouse_from bin_from warehouse_to bin_to partnumber type_and_classific partdescription chargenumber bestbefore trans_type comment qty unit partunit employee oe_id projectnumber); # filter stuff - map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id partnumber description chargenumber bestbefore); + map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id classification_id partnumber description chargenumber bestbefore); $filter{qty_op} = WH->convert_qty_op($form->{qty_op}); if ($filter{qty_op}) { @@ -686,6 +696,7 @@ sub generate_journal { my @hidden_variables = map { "l_${_}" } @columns; push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber bestbefore qty_op qty qty_unit fromdate todate); + push @hidden_variables, qw(classification_id); my %column_defs = ( 'date' => { 'text' => $locale->text('Date'), }, @@ -697,21 +708,28 @@ sub generate_journal { 'bin_from' => { 'text' => $locale->text('Bin From'), }, 'bin_to' => { 'text' => $locale->text('Bin To'), }, 'partnumber' => { 'text' => $locale->text('Part Number'), }, + 'type_and_classific' + => { 'text' => $locale->text('Type'), }, 'partdescription' => { 'text' => $locale->text('Part Description'), }, 'chargenumber' => { 'text' => $locale->text('Charge Number'), }, 'bestbefore' => { 'text' => $locale->text('Best Before'), }, 'qty' => { 'text' => $locale->text('Qty'), }, + 'unit' => { 'text' => $locale->text('Part Unit'), }, + 'partunit' => { 'text' => $locale->text('Unit'), }, 'employee' => { 'text' => $locale->text('Employee'), }, 'projectnumber' => { 'text' => $locale->text('Project Number'), }, 'oe_id' => { 'text' => $locale->text('Document'), }, ); my $href = build_std_url('action=generate_journal', grep { $form->{$_} } @hidden_variables); - map { $column_defs{$_}->{link} = $href . "&sort=${_}&order=" . Q($_ eq $form->{sort} ? 1 - $form->{order} : $form->{order}) } @columns; + my $page = $::form->{page} || 1; + map { $column_defs{$_}->{link} = $href ."&page=".$page. "&sort=${_}&order=" . Q($_ eq $form->{sort} ? 1 - $form->{order} : $form->{order}) } @columns; my %column_alignment = map { $_ => 'right' } qw(qty); map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns; + $column_defs{type_and_classific}->{visible} = 1; + $column_defs{type_and_classific}->{link} =''; $report->set_columns(%column_defs); $report->set_column_order(@columns); @@ -739,7 +757,20 @@ sub generate_journal { 'purchase_invoice' => { script => 'ir', title => $locale->text('Purchase Invoice') }, ); + my $allrows = 0; + $allrows = 1 if $form->{report_generator_output_format} ne 'HTML' ; + + # manual paginating + my $pages = {}; + $pages->{per_page} = $::form->{per_page} || 15; + my $first_nr = ($page - 1) * $pages->{per_page}; + my $last_nr = $first_nr + $pages->{per_page}; + my $idx = 0; + foreach my $entry (@contents) { + # type impl $entry->{type_and_classific} = $::request->presenter->type_abbreviation($entry->{type}). + $entry->{type_and_classific} = $::request->presenter->type_abbreviation($entry->{assembly},$entry->{inventory_accno_id}). + $::request->presenter->classification_abbreviation($entry->{classification_id}); $entry->{qty} = $form->format_amount_units('amount' => $entry->{qty}, 'part_unit' => $entry->{partunit}, 'conv_units' => 'convertible'); @@ -766,9 +797,20 @@ sub generate_journal { } } - $report->add_data($row); + if ( $allrows || ($idx >= $first_nr && $idx < $last_nr )) { + $report->add_data($row); + } + $idx++; } + if ( ! $allrows ) { + $pages->{max} = SL::DB::Helper::Paginated::ceil($idx, $pages->{per_page}) || 1; + $pages->{page} = $page < 1 ? 1: $page > $pages->{max} ? $pages->{max}: $page; + $pages->{common} = [ grep { $_->{visible} } @{ SL::DB::Helper::Paginated::make_common_pages($pages->{page}, $pages->{max}) } ]; + + $report->set_options('raw_bottom_info_text' => $form->parse_html_template('common/paginate', + { 'pages' => $pages , 'base_url' => $href}) ); + } $report->generate_with_headers(); $main::lxdebug->leave_sub(); @@ -792,10 +834,6 @@ sub report { show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} }); - $form->{jsscript} = 1; - -# $form->{fokus} = "partnumber"; -# $form->{onload} .= "focus();"; $form->{title} = $locale->text("Report about warehouse contents"); $form->header(); @@ -818,13 +856,40 @@ sub generate_report { $form->{title} = $locale->text("Report about warehouse contents"); $form->{sort} ||= 'partnumber'; + $form->{sort} ||= 'partunit'; my $sort_col = $form->{sort}; my %filter; - my @columns = qw(warehousedescription bindescription partnumber partdescription chargenumber bestbefore qty stock_value); + my @columns = qw(warehousedescription bindescription partnumber type_and_classific partdescription chargenumber bestbefore comment qty partunit stock_value); # filter stuff - map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id partnumber description chargenumber bestbefore); + map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id classification_id partnumber description chargenumber bestbefore date include_invalid_warehouses); + + # show filter stuff also in report + my @options; + my $currentdate = $form->current_date(\%myconfig); + push @options, $locale->text('Printdate') . " : ".$locale->date(\%myconfig, $currentdate, 1); + + # dispatch all options + my $dispatch_options = { + warehouse_id => sub { push @options, $locale->text('Warehouse') . " : " . + SL::DB::Manager::Warehouse->find_by(id => $form->{warehouse_id})->description}, + bin_id => sub { push @options, $locale->text('Bin') . " : " . + SL::DB::Manager::Bin->find_by(id => $form->{bin_id})->description}, + partnumber => sub { push @options, $locale->text('Partnumber') . " : $form->{partnumber}"}, + classification_id => sub { push @options, $locale->text('Parts Classification'). " : ". + SL::DB::Manager::PartsClassification->get_first(where => [ id => $form->{classification_id} ] )->description; }, + description => sub { push @options, $locale->text('Description') . " : $form->{description}"}, + chargenumber => sub { push @options, $locale->text('Charge Number') . " : $form->{chargenumber}"}, + bestbefore => sub { push @options, $locale->text('Best Before') . " : $form->{bestbefore}"}, + include_invalid_warehouses => sub { push @options, $locale->text('Include invalid warehouses ')}, + }; + foreach (keys %filter) { + $dispatch_options->{$_}->() if $dispatch_options->{$_}; + } + push @options, $locale->text('Stock Qty for Date') . " " . $locale->date(\%myconfig, $form->{date}?$form->{date}:$currentdate, 1); + + # / end show filter stuff also in report $filter{qty_op} = WH->convert_qty_op($form->{qty_op}); if ($filter{qty_op}) { @@ -838,30 +903,38 @@ sub generate_report { $form->{subtotal} = '' if (!first { $_ eq $sort_col } qw(partnumber partdescription)); + $form->{report_generator_output_format} = 'HTML' if !$form->{report_generator_output_format}; my $report = SL::ReportGenerator->new(\%myconfig, $form); my @hidden_variables = map { "l_${_}" } @columns; - push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber bestbefore qty_op qty qty_unit l_warehousedescription l_bindescription); - push @hidden_variables, qw(include_empty_bins subtotal); + push @hidden_variables, qw(warehouse_id bin_id partnumber partstypes_id description chargenumber bestbefore qty_op qty qty_unit partunit l_warehousedescription l_bindescription); + push @hidden_variables, qw(include_empty_bins subtotal include_invalid_warehouses date); + push @hidden_variables, qw(classification_id); my %column_defs = ( 'warehousedescription' => { 'text' => $locale->text('Warehouse'), }, 'bindescription' => { 'text' => $locale->text('Bin'), }, 'partnumber' => { 'text' => $locale->text('Part Number'), }, + 'type_and_classific' => { 'text' => $locale->text('Type'), }, 'partdescription' => { 'text' => $locale->text('Part Description'), }, 'chargenumber' => { 'text' => $locale->text('Charge Number'), }, 'bestbefore' => { 'text' => $locale->text('Best Before'), }, 'qty' => { 'text' => $locale->text('Qty'), }, + 'partunit' => { 'text' => $locale->text('Unit'), }, 'stock_value' => { 'text' => $locale->text('Stock value'), }, ); my $href = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables); - map { $column_defs{$_}->{link} = $href . "&sort=${_}&order=" . Q($_ eq $sort_col ? 1 - $form->{order} : $form->{order}) } @columns; + my $page = $::form->{page} || 1; + map { $column_defs{$_}->{link} = $href . "&page=".$page."&sort=${_}&order=" . Q($_ eq $sort_col ? 1 - $form->{order} : $form->{order}) } @columns; my %column_alignment = map { $_ => 'right' } qw(qty stock_value); map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns; + $column_defs{type_and_classific}->{visible} = 1; + $column_defs{type_and_classific}->{link} =''; + $report->set_columns(%column_defs); $report->set_column_order(@columns); @@ -869,7 +942,8 @@ sub generate_report { $report->set_sort_indicator($sort_col, $form->{order}); - $report->set_options('output_format' => 'HTML', + $report->set_options('top_info_text' => join("\n", @options), + 'output_format' => 'HTML', 'title' => $form->{title}, 'attachment_basename' => strftime($locale->text('warehouse_report_list') . '_%Y%m%d', localtime time)); $report->set_options_from_form(); @@ -885,25 +959,39 @@ sub generate_report { my $total_stock_value = 0; + my $allrows = 0; + $allrows = 1 if $form->{report_generator_output_format} ne 'HTML' ; + + # manual paginating + my $pages = {}; + $pages->{per_page} = $::form->{per_page} || 20; + my $first_nr = ($page - 1) * $pages->{per_page}; + my $last_nr = $first_nr + $pages->{per_page}; + foreach my $entry (@contents) { + + # type impl $entry->{type_and_classific} = $::request->presenter->type_abbreviation($entry->{type}). + $entry->{type_and_classific} = $::request->presenter->type_abbreviation($entry->{assembly},$entry->{inventory_accno_id}). + $::request->presenter->classification_abbreviation($entry->{classification_id}); map { $subtotals{$_} += $entry->{$_} } @subtotals_columns; $total_stock_value += $entry->{stock_value} * 1; - - $entry->{qty} = $form->format_amount_units('amount' => $entry->{qty}, - 'part_unit' => $entry->{partunit}, - 'conv_units' => 'convertible'); + $entry->{qty} = $form->format_amount(\%myconfig, $entry->{qty}); +# $entry->{qty} = $form->format_amount_units('amount' => $entry->{qty}, +# 'part_unit' => $entry->{partunit}, +# 'conv_units' => 'convertible'); $entry->{stock_value} = $form->format_amount(\%myconfig, $entry->{stock_value} * 1, 2); my $row_set = [ { map { $_ => { 'data' => $entry->{$_}, 'align' => $column_alignment{$_} } } @columns } ]; - if (($form->{subtotal} eq 'Y') + if ( ($form->{subtotal} eq 'Y' && !$form->{report_generator_csv_options_for_import} ) && (($idx == (scalar @contents - 1)) || ($entry->{$sort_col} ne $contents[$idx + 1]->{$sort_col}))) { my $row = { map { $_ => { 'data' => '', 'class' => 'listsubtotal', 'align' => $column_alignment{$_}, } } @columns }; - $row->{qty}->{data} = $form->format_amount_units('amount' => $subtotals{qty} * 1, - 'part_unit' => $entry->{partunit}, - 'conv_units' => 'convertible'); + $row->{qty}->{data} = $form->format_amount(\%myconfig, $subtotals{qty}); +# $row->{qty}->{data} = $form->format_amount_units('amount' => $subtotals{qty} * 1, +# 'part_unit' => $entry->{partunit}, +# 'conv_units' => 'convertible'); $row->{stock_value}->{data} = $form->format_amount(\%myconfig, $subtotals{stock_value} * 1, 2); %subtotals = map { $_ => 0 } @subtotals_columns; @@ -911,12 +999,13 @@ sub generate_report { push @{ $row_set }, $row; } - $report->add_data($row_set); - + if ( $allrows || ($idx >= $first_nr && $idx < $last_nr )) { + $report->add_data($row_set); + } $idx++; } - if ($column_defs{stock_value}->{visible}) { + if ( $column_defs{stock_value}->{visible} && !$form->{report_generator_csv_options_for_import} ) { $report->add_separator(); my $row = { map { $_ => { 'data' => '', 'class' => 'listsubtotal', } } @columns }; @@ -948,7 +1037,7 @@ sub show_no_warehouses_error { my $msg = $locale->text('No warehouse has been created yet or the quantity of the bins is not configured yet.') . ' '; - if ($main::auth->check_right($form->{login}, 'config')) { + if ($main::auth->check_right($::myconfig{login}, 'config')) { $msg .= $locale->text('You can create warehouses and bins via the menu "System -> Warehouses".'); } else { $msg .= $locale->text('Please ask your administrator to create warehouses and bins.');