X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fwh.pl;h=980cddb2ec097697e56d4f7e397d64c111172d8b;hb=4a852cb1ba0225e6e086786d3950fc7a3c068f38;hp=2e812f31f1333cb52fd180ba2665906a69d59fe7;hpb=96aa399e04832dae8c16d8159be230b313211b83;p=kivitendo-erp.git diff --git a/bin/mozilla/wh.pl b/bin/mozilla/wh.pl index 2e812f31f..980cddb2e 100644 --- a/bin/mozilla/wh.pl +++ b/bin/mozilla/wh.pl @@ -41,11 +41,14 @@ use SL::User; use SL::AM; use SL::CVar; use SL::CT; +use SL::Helper::Flash qw(flash_later); use SL::IC; use SL::WH; use SL::OE; +# use SL::Helper::Inventory qw(produce_assembly); use SL::Locale::String qw(t8); use SL::ReportGenerator; +use SL::Presenter::Tag qw(checkbox_tag); use SL::Presenter::Part; use SL::DB::Part; @@ -547,6 +550,31 @@ sub remove_parts { $main::lxdebug->leave_sub(); } +sub disassemble_assembly { + $main::lxdebug->enter_sub(); + + $main::auth->assert('warehouse_management'); + + my $form = $main::form; + + croak("No assembly ids") unless scalar @{ $form->{ids}} > 0; + + # everything in one transaction + my $db = SL::DB::Inventory->new->db; + $db->with_transaction(sub { + + foreach my $trans_id (@{ $::form->{ids}} ) { + SL::DB::Manager::Inventory->delete_all(where => [ trans_id => $trans_id ]); + flash_later('info', t8("Disassembly successful for trans_id #1", $trans_id)); + } + + 1; + }) || die t8('error while disassembling for trans_ids #1 : #2', $form->{ids}) . $db->error . "\n"; + + $main::lxdebug->leave_sub(); + $form->redirect; +} + # -------------------------------------------------------------------- # Journal # -------------------------------------------------------------------- @@ -583,13 +611,14 @@ sub generate_journal { my %myconfig = %main::myconfig; my $locale = $main::locale; + setup_wh_journal_list_all_action_bar(); $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 type_and_classific partdescription chargenumber bestbefore trans_type comment qty unit partunit employee oe_id projectnumber); + my @columns = qw(ids 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 classification_id partnumber description chargenumber bestbefore transtype_id transtype_ids comment projectnumber); @@ -621,7 +650,10 @@ sub generate_journal { $last_nr = $pages->{per_page}; } + my $old_l_trans_id = $form->{l_trans_id}; my @contents = WH->get_warehouse_journal(%filter); + $form->{l_trans_id} = $old_l_trans_id; + # get maxcount if (!$form->{maxrows}) { $form->{maxrows} = scalar @contents ; @@ -634,6 +666,7 @@ sub generate_journal { push @hidden_variables, qw(classification_id); my %column_defs = ( + 'ids' => { raw_header_data => checkbox_tag("", id => "check_all", checkall => "[data-checkall=1]") }, 'date' => { 'text' => $locale->text('Date'), }, 'trans_id' => { 'text' => $locale->text('Trans Id'), }, 'trans_type' => { 'text' => $locale->text('Trans Type'), }, @@ -674,6 +707,7 @@ sub generate_journal { $column_defs{partunit}->{visible} = 1; $column_defs{type_and_classific}->{visible} = 1; $column_defs{type_and_classific}->{link} =''; + $column_defs{ids}->{visible} = 1; $report->set_columns(%column_defs); $report->set_column_order(@columns); @@ -701,13 +735,13 @@ sub generate_journal { ); my $idx = 0; - + my $undo_date = DateTime->today->subtract(days => $::instance_conf->get_undo_transfer_interval); foreach my $entry (@contents) { $entry->{type_and_classific} = SL::Presenter::Part::type_abbreviation($entry->{part_type}) . SL::Presenter::Part::classification_abbreviation($entry->{classification_id}); $entry->{qty} = $form->format_amount(\%myconfig, $entry->{qty}); + $entry->{assembled} = $entry->{trans_type} eq 'assembled' ? 1 : ''; $entry->{trans_type} = $locale->text($entry->{trans_type}); - my $row = { }; foreach my $column (@columns) { @@ -717,8 +751,13 @@ sub generate_journal { }; } + if ($entry->{assembled}) { + my $insertdate = DateTime->from_kivitendo($entry->{shippingdate}); + if (ref $undo_date eq 'DateTime' && ref $insertdate eq 'DateTime' && $insertdate > $undo_date) { + $row->{ids}->{raw_data} = checkbox_tag("ids[]", value => $entry->{trans_id}, "data-checkall" => 1); + } + } $row->{trans_type}->{raw_data} = $entry->{trans_type}; - if ($form->{l_oe_id}) { $row->{oe_id}->{data} = ''; my $info = $entry->{oe_id_info}; @@ -735,12 +774,17 @@ sub generate_journal { $idx++; } + + $report->set_options( + raw_top_info_text => $form->parse_html_template('wh/report_top'), + raw_bottom_info_text => $form->parse_html_template('wh/report_bottom', { callback => $href }), + ); if ( ! $allrows ) { $pages->{max} = SL::DB::Helper::Paginated::ceil($form->{maxrows}, $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', + $report->set_options('raw_bottom_info_text' => $form->parse_html_template('wh/report_bottom', { callback => $href }) . $form->parse_html_template('common/paginate', { 'pages' => $pages , 'base_url' => $href.'&sort='.$form->{sort}.'&order='.$form->{order}}) ); } $report->generate_with_headers(); @@ -1190,6 +1234,22 @@ sub setup_wh_journal_action_bar { ); } } +sub setup_wh_journal_list_all_action_bar { + my ($action) = @_; + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + combobox => [ + action => [ t8('Actions') ], + action => [ + t8('Disassemble Assembly'), + submit => [ '#form', { action => 'disassemble_assembly' } ], + checks => [ [ 'kivi.check_if_entries_selected', '[name="ids[]"]' ] ], + ], + ], + ); + } +} + 1;