X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fwh.pl;h=fe37c26da727caf5c5a2300f204e9ad41afc1098;hb=1b9a64fa292f375c82b4af788d0606354bc4e8ff;hp=3b732bceddb7a7d19b7743158d282e4c6f03573f;hpb=f2d34a8eb90b47e323c67c5da186b131254e85a6;p=kivitendo-erp.git diff --git a/bin/mozilla/wh.pl b/bin/mozilla/wh.pl index 3b732bced..fe37c26da 100644 --- a/bin/mozilla/wh.pl +++ b/bin/mozilla/wh.pl @@ -23,7 +23,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. # ####################################################################### # @@ -44,6 +45,8 @@ use SL::WH; use SL::OE; use SL::ReportGenerator; +use SL::DB::Part; + use Data::Dumper; require "bin/mozilla/common.pl"; @@ -65,6 +68,7 @@ use strict; # $locale->text('used') # $locale->text('return_material') # $locale->text('release_material') +# $locale->text('assembled') # -------------------------------------------------------------------- # Transfer @@ -85,7 +89,16 @@ sub transfer_warehouse_selection { show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} }); my $units = AM->retrieve_units(\%myconfig, $form); - $form->{UNITS} = AM->unit_select_data($units, $form->{unit}, 0, $form->{partunit}); + + 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->{unit}, 0, $part ? $part->unit : 0); if (scalar @{ $form->{WAREHOUSES} }) { $form->{warehouse_id} ||= $form->{WAREHOUSES}->[0]->{id}; @@ -94,8 +107,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'); @@ -175,7 +186,9 @@ sub transfer_or_removal_prepare_contents { "ean" => $form->{ean}, "description" => $form->{description}); - $form->show_generic_error($locale->text("The selected warehouse is empty.")) if (0 == scalar(@contents)); + if (0 == scalar(@contents)) { + $form->show_generic_error($locale->text("The selected warehouse is empty, or no stocked items where found that match the filter settings.")); + } my $all_units = AM->retrieve_units(\%myconfig, $form); @@ -269,6 +282,7 @@ sub transfer_parts { } $transfer->{comment} = $form->{comment}; + $transfer->{change_default_bin} = $form->{change_default_bin}; push @transfers, $transfer; @@ -277,7 +291,7 @@ sub transfer_parts { if (!scalar @transfers) { $form->show_generic_information($locale->text('Nothing has been selected for transfer.')); - exit 0; + $::dispatcher->end_request; } WH->transfer(@transfers); @@ -310,7 +324,7 @@ sub transfer_stock_update_part { } elsif (($form->{partnumber} && ($form->{partnumber} ne $form->{old_partnumber})) || $form->{description} || $form->{ean}) { - $form->{no_services} = 1; +# $form->{no_services} = 1; # services may now be transfered. fix for Bug 1383. $form->{no_assemblies} = 0; # assemblies duerfen eingelagert werden (z.B. bei retouren) my $parts = Common->retrieve_parts(\%myconfig, $form, 'description', 1); @@ -318,7 +332,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(); @@ -385,7 +399,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(); @@ -435,7 +449,7 @@ sub create_assembly { $form->error($locale->text('The warehouse or the bin is missing.')); } - if (!$main::show_best_before) { + if (!$::instance_conf->get_show_bestbefore) { $form->{bestbefore} = ''; } @@ -443,7 +457,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}, @@ -503,7 +517,7 @@ sub transfer_stock { WH->transfer($transfer); - delete @{$form}{qw(parts_id partnumber description qty unit chargenumber bestbefore comment)}; + delete @{$form}{qw(parts_id partnumber description qty unit chargenumber bestbefore comment ean)}; $form->{saved_message} = $locale->text('The parts have been stocked.'); $form->{trans_type} = 'stock'; @@ -611,7 +625,7 @@ sub remove_parts { if (!scalar @transfers) { $form->show_generic_information($locale->text('Nothing has been selected for removal.')); - exit 0; + $::dispatcher->end_request; } WH->transfer(@transfers); @@ -635,14 +649,14 @@ sub journal { my $form = $main::form; my %myconfig = %main::myconfig; + my $locale = $main::locale; + $form->{title} = $locale->text('Report about warehouse transactions'); $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', 'bins' => 'BINS', }); 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)) }); @@ -661,6 +675,8 @@ 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); @@ -692,17 +708,20 @@ sub generate_journal { 'bin_from' => { 'text' => $locale->text('Bin From'), }, 'bin_to' => { 'text' => $locale->text('Bin To'), }, 'partnumber' => { 'text' => $locale->text('Part Number'), }, - 'partdescription' => { 'text' => $locale->text('Description'), }, + '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); @@ -719,6 +738,7 @@ sub generate_journal { 'title' => $form->{title}, 'attachment_basename' => strftime($locale->text('warehouse_journal_list') . '_%Y%m%d', localtime time)); $report->set_options_from_form(); + $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv'; my $all_units = AM->retrieve_units(\%myconfig, $form); my @contents = WH->get_warehouse_journal(%filter); @@ -733,6 +753,16 @@ 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) { $entry->{qty} = $form->format_amount_units('amount' => $entry->{qty}, 'part_unit' => $entry->{partunit}, @@ -760,9 +790,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(); @@ -786,11 +827,7 @@ 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 wareouse contents"); + $form->{title} = $locale->text("Report about warehouse contents"); $form->header(); print $form->parse_html_template("wh/report_filter", @@ -810,15 +847,36 @@ sub generate_report { my %myconfig = %main::myconfig; my $locale = $main::locale; - $form->{title} = $locale->text("Report about wareouse contents"); + $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); # 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 partstypes_id partnumber description chargenumber bestbefore date include_invalid_warehouses); + + # show filter stuff also in report + my @options; + # 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}"}, + 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}"}, + date => sub { push @options, $locale->text('Date') . " : $form->{date}"}, + include_invalid_warehouses => sub { push @options, $locale->text('Include invalid warehouses ')}, + }; + foreach (keys %filter) { + $dispatch_options->{$_}->() if $dispatch_options->{$_}; + } + # / end show filter stuff also in report $filter{qty_op} = WH->convert_qty_op($form->{qty_op}); if ($filter{qty_op}) { @@ -832,25 +890,28 @@ 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); my %column_defs = ( 'warehousedescription' => { 'text' => $locale->text('Warehouse'), }, 'bindescription' => { 'text' => $locale->text('Bin'), }, 'partnumber' => { 'text' => $locale->text('Part Number'), }, - 'partdescription' => { 'text' => $locale->text('Description'), }, + '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); @@ -863,10 +924,12 @@ 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(); + $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv'; my $all_units = AM->retrieve_units(\%myconfig, $form); my @contents = WH->get_warehouse_report(%filter); @@ -878,25 +941,35 @@ 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) { 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; @@ -904,12 +977,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 }; @@ -941,7 +1015,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.');