X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fwh.pl;h=c990e632f43ae152129cda8ffd5c8dbf52ee0d6a;hb=549f187d3a2b1d15f96c4556714666ed954447bb;hp=d632d5d961962e29e47b22726ce44c882b1311d1;hpb=16c66f611b987008d72c4475ce7cf691d517af0f;p=kivitendo-erp.git diff --git a/bin/mozilla/wh.pl b/bin/mozilla/wh.pl index d632d5d96..3cb1243ca 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. # ####################################################################### # @@ -38,17 +39,27 @@ use SL::Form; 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; use Data::Dumper; require "bin/mozilla/common.pl"; require "bin/mozilla/reportgenerator.pl"; +use strict; + # parserhappy(R): # contents of the "transfer_type" table: @@ -63,15 +74,21 @@ require "bin/mozilla/reportgenerator.pl"; # $locale->text('used') # $locale->text('return_material') # $locale->text('release_material') +# $locale->text('assembled') +# $locale->text('stocktaking') # -------------------------------------------------------------------- # Transfer # -------------------------------------------------------------------- sub transfer_warehouse_selection { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('warehouse_management'); - $auth->assert('warehouse_management'); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', 'bins' => 'BINS', }); @@ -79,7 +96,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}; @@ -88,23 +114,18 @@ sub transfer_warehouse_selection { my $content; - $form->{jsscript} = 1; - if ($form->{trans_type} eq 'removal') { - $form->{nextsub} = "removal_parts_selection"; + setup_wh_transfer_warehouse_selection_action_bar("removal_parts_selection"); $form->{title} = $locale->text('Removal from Warehouse'); $content = $form->parse_html_template('wh/warehouse_selection'); - } elsif ($form->{trans_type} eq 'stock') { - $form->{title} = $locale->text('Stock'); - $content = $form->parse_html_template('wh/warehouse_selection_stock'); - } elsif (!$form->{trans_type} || ($form->{trans_type} eq 'transfer')) { - $form->{nextsub} = "transfer_parts_selection"; + setup_wh_transfer_warehouse_selection_action_bar("transfer_parts_selection"); $form->{title} = $locale->text('Transfer'); $content = $form->parse_html_template('wh/warehouse_selection'); } elsif ($form->{trans_type} eq 'assembly') { + setup_wh_transfer_warehouse_selection_assembly_action_bar(); $form->{title} = $locale->text('Produce Assembly'); $content = $form->parse_html_template('wh/warehouse_selection_assembly'); } @@ -112,30 +133,40 @@ sub transfer_warehouse_selection { $form->header(); print $content; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub transfer_parts_selection { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('warehouse_management'); - $auth->assert('warehouse_management'); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; transfer_or_removal_prepare_contents('direction' => 'transfer'); + setup_wh_transfer_parts_action_bar(); + $form->{title} = $locale->text('Transfer'); $form->header(); print $form->parse_html_template("wh/transfer_parts_selection"); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub transfer_or_removal_prepare_contents { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('warehouse_management'); + $main::auth->assert('warehouse_management'); my %args = @_; + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', 'bins' => 'BINS', }); @@ -150,24 +181,25 @@ sub transfer_or_removal_prepare_contents { $form->show_generic_error($locale->text("The source warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} }); - map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber partunit ean); + map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit ean); $form->{sort} = 'bindescription'; my @contents = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id}, "bin_id" => $form->{bin_id}, "chargenumber" => $form->{chargenumber}, - "partnumber" => $form->{partnumber}, - "ean" => $form->{ean}, - "description" => $form->{description}); + "bestbefore" => $form->{bestbefore}, + "partsid" => $form->{part_id}, + "ean" => $form->{ean}); - $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); foreach (@contents) { - $_->{qty} = $form->format_amount_units('amount' => $_->{qty}, - 'part_unit' => $_->{partunit}, - 'conv_units' => 'convertible'); + $_->{qty} = $form->format_amount(\%myconfig, $_->{qty}) . ' ' . $_->{partunit}; + my $this_unit = $_->{partunit}; if ($all_units->{$_->{partunit}} && ($all_units->{g}->{base_unit} eq $all_units->{$_->{partunit}}->{base_unit})) { @@ -183,14 +215,18 @@ sub transfer_or_removal_prepare_contents { $form->{CONTENTS} = \@contents; $form->{TRANSFER_TYPES} = $transfer_types; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub transfer_parts { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('warehouse_management'); - $auth->assert('warehouse_management'); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', 'bins' => 'BINS' }); @@ -201,7 +237,7 @@ sub transfer_parts { $form->show_generic_error($locale->text("The source warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} }); - map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber partunit); + map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit); $form->{sort} = 'bindescription'; my @contents = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id}); @@ -225,12 +261,12 @@ sub transfer_parts { 'transfer_type_id' => $form->{transfer_type_id}, }; - map { $transfer->{$_} = $form->{"${_}_${row}"} } qw(src_bin_id chargenumber parts_id qty dst_warehouse_id dst_bin_id); + map { $transfer->{$_} = $form->{"${_}_${row}"} } qw(src_bin_id chargenumber bestbefore parts_id qty dst_warehouse_id dst_bin_id); my $entry; foreach (@contents) { - if (($_->{binid} == $transfer->{src_bin_id}) && ($_->{parts_id} == $transfer->{parts_id}) && ($_->{chargenumber} eq $transfer->{chargenumber})) { + if (($_->{binid} == $transfer->{src_bin_id}) && ($_->{parts_id} == $transfer->{parts_id}) && ($_->{chargenumber} eq $transfer->{chargenumber}) && $_->{bestbefore} eq $transfer->{bestbefore}) { $entry = $_; last; } @@ -250,6 +286,7 @@ sub transfer_parts { } $transfer->{comment} = $form->{comment}; + $transfer->{change_default_bin} = $form->{change_default_bin}; push @transfers, $transfer; @@ -258,7 +295,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); @@ -268,200 +305,115 @@ sub transfer_parts { transfer_warehouse_selection(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # -------------------------------------------------------------------- # Transfer: stock # -------------------------------------------------------------------- -sub transfer_stock_update_part { - $lxdebug->enter_sub(); - - $form->{trans_type} = 'stock'; - $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty}); - - if (!$form->{partnumber} && !$form->{description} && !$form->{ean}) { - delete @{$form}{qw(parts_id partunit ean)}; - transfer_warehouse_selection(); - - } elsif (($form->{partnumber} && ($form->{partnumber} ne $form->{old_partnumber})) || $form->{description} || $form->{ean}) { - - $form->{no_services} = 1; - $form->{no_assemblies} = 0; # assemblies duerfen eingelagert werden (z.B. bei retouren) - - my $parts = Common->retrieve_parts(\%myconfig, $form, 'description', 1); - - if (scalar @{ $parts } == 1) { - @{$form}{qw(parts_id partnumber description ean)} = @{$parts->[0]}{qw(id partnumber description ean)}; - transfer_stock_get_partunit(); - transfer_warehouse_selection(); - - } else { - select_part('transfer_stock_part_selected', @{ $parts }); - } - - } else { - transfer_stock_get_partunit(); - transfer_warehouse_selection(); - } - - $lxdebug->leave_sub(); -} - # -------------------------------------------------------------------- # Transfer: assemblies -# Dies ist die Auswahlmaske für ein assembly. +# Dies ist die Auswahlmaske für ein assembly. # Die ist einfach von transfer_assembly_update_part kopiert und nur um den trans_type (assembly) korrigiert worden # Es wäre schön, hier nochmal check_assembly_max_create auf, um die max. Fertigungszahl herauszufinden. # Ich lass das mal als auskommentierte Idee bestehen jb 18.3.09 # -------------------------------------------------------------------- sub transfer_assembly_update_part { - $lxdebug->enter_sub(); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; $form->{trans_type} = 'assembly'; $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty}); - if (!$form->{partnumber} && !$form->{description}) { - delete @{$form}{qw(parts_id partunit)}; + if (!$form->{parts_id}) { + delete $form->{partunit}; transfer_warehouse_selection(); + return; - } elsif (($form->{partnumber} && ($form->{partnumber} ne $form->{old_partnumber})) || $form->{description}) { - $form->{assemblies} = 1; - $form->{no_assemblies} = 0; - my $parts = Common->retrieve_parts(\%myconfig, $form, 'description', 1); - if (scalar @{ $parts } == 1) { - @{$form}{qw(parts_id partnumber description)} = @{$parts->[0]}{qw(id partnumber description)}; - transfer_stock_get_partunit(); - transfer_warehouse_selection(); - } else { - select_part('transfer_stock_part_selected', @{ $parts }); - } - - } else { - transfer_stock_get_partunit(); - transfer_warehouse_selection(); } -# hier die oben benannte idee -# my $maxcreate = Common->check_assembly_max_create(assembly_id => $form->{parts_id}, dbh => $my_dbh); - $lxdebug->leave_sub(); + my $part = SL::DB::Part->new(id => $::form->{parts_id})->load; + @{$form}{qw(parts_id partnumber description)} = ($part->id, $part->partnumber, $part->description); + + transfer_stock_get_partunit(); + transfer_warehouse_selection(); } + sub transfer_stock_part_selected { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); my $part = shift; - @{$form}{qw(parts_id partnumber description ean)} = @{$part}{qw(id partnumber description ean)}; + my $form = $main::form; + + @{$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(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub transfer_stock_get_partunit { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; if ($form->{parts_id}) { my $part_info = IC->get_basic_part_info('id' => $form->{parts_id}); $form->{partunit} = $part_info->{unit}; } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } -# vorüberlegung jb 22.2.2009 -# wir benötigen für diese funktion, die anzahl die vom erzeugnis hergestellt werden soll. vielleicht direkt per js fehleingaben verhindern? -# ferner dann nochmal mit check_asssembly_max_create gegenprüfen und dann transaktionssicher wegbuchen. -# wir brauchen eine hilfsfunktion, die nee. brauchen wir nicht. der algorithmus läuft genau wie bei check max_create, nur dass hier auch eine lagerbewegung (verbraucht) stattfindet -# Manko ist derzeit noch, dass unterschiedliche Lagerplätze, bzw. das Quelllager an sich nicht ausgewählt werden können. -# Laut Absprache in KW11 09 übernimmt mb hier den rest im April ... jb 18.3.09 - sub create_assembly { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty}); if ($form->{qty} <= 0) { - $form->show_generic_error($locale->text('Invalid quantity.'), 'back_button' => 1); + $form->show_generic_error($locale->text('Invalid quantity.')); } - # TODO Es wäre schön, hier schon die maximale Anzahl der zu fertigenden Erzeugnisse zu haben - #else { if ($form->{qty} > $maxcreate) { #s.o. - # $form->show_generic_error($locale->text('Can not create that quantity with current stock'), 'back_button' => 1); - # $form->show_generic_error('Maximale Stückzahl' . $maxcreate , 'back_button' => 1); - # } - # } - if (!$form->{warehouse_id} || !$form->{bin_id}) { $form->error($locale->text('The warehouse or the bin is missing.')); } - # WIESO war das nicht vorher schon ein %HASH?? ein hash ist ein hash! das hat mich mehr als eine Stunde gekostet herauszufinden. grr. jb 3.3.2009 - # Anm. jb 18.3. vielleicht auch nur meine unwissenheit in perl-datenstrukturen - my %TRANSFER = ( - 'transfer_type' => 'assembly', - 'login' => $form->{login}, - 'dst_warehouse_id' => $form->{warehouse_id}, - 'dst_bin_id' => $form->{bin_id}, - 'chargenumber' => $form->{chargenumber}, - 'assembly_id' => $form->{parts_id}, - 'qty' => $form->{qty}, - 'unit' => $form->{unit}, - 'comment' => $form->{comment} - ); - - my $ret = WH->transfer_assembly (%TRANSFER); - # Frage: Ich pack in den return-wert auch gleich die Fehlermeldung. Irgendwelche Nummern als Fehlerkonstanten definieren find ich auch nicht besonders schick... - # Ideen? jb 18.3.09 - if ($ret ne "1"){ - # Die locale-Funktion kann keine Double-Quotes escapen, deswegen hier erstmal so (ein wahrscheinlich immerwährender Hotfix) s.a. Frage davor jb 25.4.09 - $form->show_generic_error($ret, 'back_button' => 1); - } - - delete @{$form}{qw(parts_id partnumber description qty unit chargenumber comment)}; - - $form->{saved_message} = $locale->text('The assembly has been created.'); - $form->{trans_type} = 'assembly'; - - transfer_warehouse_selection(); - - $lxdebug->leave_sub(); -} + # need part and bin object + my ($bin, $assembly); + $assembly = SL::DB::Manager::Part->find_by(id => $form->{parts_id}, part_type => 'assembly'); + $form->show_generic_error($locale->text('Invalid assembly')) unless ref $assembly eq 'SL::DB::Part'; -sub transfer_stock { - $lxdebug->enter_sub(); + $bin = SL::DB::Manager::Bin->find_by(id => $form->{bin_id}); + $form->show_generic_error($locale->text('Invalid bin')) unless ref $bin eq 'SL::DB::Bin'; - $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty}); - - if ($form->{qty} <= 0) { - $form->show_generic_error($locale->text('Invalid quantity.'), 'back_button' => 1); + if (!$::instance_conf->get_show_bestbefore) { + $form->{bestbefore} = ''; } - if (!$form->{warehouse_id} || !$form->{bin_id}) { - $form->error($locale->text('The warehouse or the bin is missing.')); - } - - my $transfer = { - 'transfer_type' => 'stock', - 'dst_warehouse_id' => $form->{warehouse_id}, - 'dst_bin_id' => $form->{bin_id}, - 'chargenumber' => $form->{chargenumber}, - 'parts_id' => $form->{parts_id}, - 'qty' => $form->{qty}, - 'unit' => $form->{unit}, - 'comment' => $form->{comment}, - }; - - WH->transfer($transfer); + produce_assembly( + part => $assembly, # target assembly + qty => $form->{qty}, # qty + auto_allocate => 1, + bin => $bin, # needed unless a global standard target is configured + chargenumber => $form->{chargenumber}, # optional + bestbefore => $form->{bestbefore}, + comment => $form->{comment}, # optional + ); - delete @{$form}{qw(parts_id partnumber description qty unit chargenumber comment)}; + delete @{$form}{qw(parts_id partnumber description qty unit chargenumber bestbefore comment)}; - $form->{saved_message} = $locale->text('The parts have been stocked.'); - $form->{trans_type} = 'stock'; + $form->{saved_message} = $locale->text('The assembly has been created.'); + $form->{trans_type} = 'assembly'; transfer_warehouse_selection(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # -------------------------------------------------------------------- @@ -469,23 +421,33 @@ sub transfer_stock { # -------------------------------------------------------------------- sub removal_parts_selection { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('warehouse_management'); + $main::auth->assert('warehouse_management'); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; transfer_or_removal_prepare_contents('direction' => 'out'); + setup_wh_removal_parts_selection_action_bar(); + $form->{title} = $locale->text('Removal'); $form->header(); print $form->parse_html_template("wh/removal_parts_selection"); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub remove_parts { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('warehouse_management'); + $main::auth->assert('warehouse_management'); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', 'bins' => 'BINS', }); @@ -497,7 +459,7 @@ sub remove_parts { $form->show_generic_error($locale->text("The warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} }); - map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber partunit); + map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit); $form->{sort} = 'bindescription'; my @contents = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id}); @@ -521,12 +483,12 @@ sub remove_parts { 'transfer_type_id' => $form->{transfer_type_id}, }; - map { $transfer->{$_} = $form->{"${_}_${row}"} } qw(src_bin_id chargenumber parts_id qty); + map { $transfer->{$_} = $form->{"${_}_${row}"} } qw(src_bin_id chargenumber bestbefore parts_id qty); my $entry; foreach (@contents) { - if (($_->{binid} == $transfer->{src_bin_id}) && ($_->{parts_id} == $transfer->{parts_id}) && ($_->{chargenumber} eq $transfer->{chargenumber})) { + if (($_->{binid} == $transfer->{src_bin_id}) && ($_->{parts_id} == $transfer->{parts_id}) && ($_->{chargenumber} eq $transfer->{chargenumber}) && ($_->{bestbefore} eq $transfer->{bestbefore})) { $entry = $_; last; } @@ -554,7 +516,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); @@ -564,7 +526,32 @@ sub remove_parts { transfer_warehouse_selection(); - $lxdebug->leave_sub(); + $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; } # -------------------------------------------------------------------- @@ -572,53 +559,108 @@ sub remove_parts { # -------------------------------------------------------------------- sub journal { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('warehouse_management'); - $auth->assert('warehouse_management'); + 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; + my $cvar_configs = CVar->get_configs('module' => 'IC'); + ($form->{CUSTOM_VARIABLES_FILTER_CODE}, + $form->{CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables' => $cvar_configs, + 'include_prefix' => 'l_', + 'include_value' => 'Y'); + + setup_wh_journal_action_bar(); $form->header(); print $form->parse_html_template("wh/journal_filter", { "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) }); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub generate_journal { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('warehouse_management'); - $auth->assert('warehouse_management'); + my $form = $main::form; + 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 partdescription chargenumber trans_type comment qty employee 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 partnumber description chargenumber); + map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id classification_id partnumber description chargenumber bestbefore transtype_id transtype_ids comment projectnumber); $filter{qty_op} = WH->convert_qty_op($form->{qty_op}); if ($filter{qty_op}) { - $form->isblank(qty, $locale->text('Quantity missing.')); - $form->isblank(qty_unit, $locale->text('Unit missing.')); + $form->isblank("qty", $locale->text('Quantity missing.')); + $form->isblank("qty_unit", $locale->text('Unit missing.')); $filter{qty} = $form->{qty}; $filter{qty_unit} = $form->{qty_unit}; } # /filter stuff + my $allrows = !!($form->{report_generator_output_format} ne 'HTML') ; + + # manual paginating + my $pages = {}; + my $page = $::form->{page} || 1; + $pages->{per_page} = $::form->{per_page} || 15; + my $first_nr = ($page - 1) * $pages->{per_page}; + my $last_nr = $first_nr + $pages->{per_page}; + + # no optimisation if qty op + if ( !$allrows && $form->{maxrows} && !$filter{qty_op}) { + $filter{limit} = $pages->{per_page}; + $filter{offset} = ($page - 1) * $pages->{per_page}; + $first_nr = 0; + $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 ; + } + my $report = SL::ReportGenerator->new(\%myconfig, $form); + my $cvar_configs = CVar->get_configs('module' => 'IC'); + my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs }; + my @searchable_custom_variables = grep { $_->{searchable} } @{ $cvar_configs }; + push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables; + my @hidden_variables = map { "l_${_}" } @columns; - push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber qty_op qty qty_unit fromdate todate); + push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber bestbefore qty_op qty qty_unit unit partunit fromdate todate transtype_ids comment projectnumber); + push @hidden_variables, qw(classification_id); + push @hidden_variables, map({'cvar_'. $_->{name}} @searchable_custom_variables); + push @hidden_variables, map({'cvar_'. $_->{name} .'_from'} grep({$_->{type} eq 'date'} @searchable_custom_variables)); + push @hidden_variables, map({'cvar_'. $_->{name} .'_to'} grep({$_->{type} eq 'date'} @searchable_custom_variables)); + push @hidden_variables, map({'cvar_'. $_->{name} .'_qtyop'} grep({$_->{type} eq 'number'} @searchable_custom_variables)); 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'), }, @@ -628,19 +670,41 @@ 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'), }, + '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 %column_defs_cvars = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @includeable_custom_variables; + %column_defs = (%column_defs, %column_defs_cvars); + + if ($form->{transtype_ids} && 'ARRAY' eq ref $form->{transtype_ids}) { + for (my $i = 0; $i < scalar(@{ $form->{transtype_ids} }); $i++) { + delete $form->{transtype_ids}[$i] if $form->{transtype_ids}[$i] eq ''; + } + $form->{transtype_ids} = join(",", @{ $form->{transtype_ids} }); + } + 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; + $href .= "&maxrows=".$form->{maxrows}; + + map { $column_defs{$_}->{link} = $href ."&page=".$page. "&sort=${_}&order=" . Q($_ eq $form->{sort} ? 1 - $form->{order} : $form->{order}) } grep {!/^cvar/} @columns; my %column_alignment = map { $_ => 'right' } qw(qty); map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns; + $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); @@ -653,38 +717,83 @@ 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); - foreach $entry (@contents) { - $entry->{qty} = $form->format_amount_units('amount' => $entry->{qty}, - 'part_unit' => $entry->{partunit}, - 'conv_units' => 'convertible'); - $entry->{trans_type} = $locale->text($entry->{trans_type}); + CVar->add_custom_variables_to_report('module' => 'IC', + 'trans_id_field' => 'parts_id', + 'configs' => $cvar_configs, + 'column_defs' => \%column_defs, + 'data' => \@contents); + + my %doc_types = ( 'sales_quotation' => { script => 'oe', title => $locale->text('Sales quotation') }, + 'sales_order' => { script => 'oe', title => $locale->text('Sales Order') }, + 'request_quotation' => { script => 'oe', title => $locale->text('Request quotation') }, + 'purchase_order' => { script => 'oe', title => $locale->text('Purchase Order') }, + 'sales_delivery_order' => { script => 'do', title => $locale->text('Sales delivery order') }, + 'purchase_delivery_order' => { script => 'do', title => $locale->text('Purchase delivery order') }, + 'sales_invoice' => { script => 'is', title => $locale->text('Sales Invoice') }, + 'purchase_invoice' => { script => 'ir', title => $locale->text('Purchase Invoice') }, + ); + + 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) { - next if ($column eq 'trans_type'); - $row->{$column} = { 'data' => $entry->{$column}, 'align' => $column_alignment{$column}, }; } - $row->{trans_type} = { - 'raw_data' => $entry->{trans_type}, - 'align' => $column_alignment{trans_type}, - }; + 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}; + + if ($info && $info->{id} && $info->{type} && $doc_types{$info->{type}}) { + $row->{oe_id} = { data => $doc_types{ $info->{type} }->{title} . ' ' . $info->{number}, + link => build_std_url('script=' . $doc_types{ $info->{type} }->{script} . '.pl', 'action=edit', 'id=' . $info->{id}, 'type=' . $info->{type}) }; + } + } - $report->add_data($row); + if ( $allrows || ($idx >= $first_nr && $idx < $last_nr )) { + $report->add_data($row); + } + $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('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(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # -------------------------------------------------------------------- @@ -692,78 +801,171 @@ sub generate_journal { # -------------------------------------------------------------------- sub report { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('warehouse_contents | warehouse_management'); - $auth->assert('warehouse_contents | warehouse_management'); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', - 'bins' => 'BINS', }); + 'bins' => 'BINS', }, + 'partsgroup' => 'PARTSGROUPS'); show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} }); - $form->{fokus} = "partnumber"; - $form->{onload} .= "focus();"; - $form->{title} = $locale->text("Report about wareouse contents"); + my $cvar_configs = CVar->get_configs('module' => 'IC'); + ($form->{CUSTOM_VARIABLES_FILTER_CODE}, + $form->{CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables' => $cvar_configs, + 'include_prefix' => 'l_', + 'include_value' => 'Y'); + + $form->{title} = $locale->text("Report about warehouse contents"); + + setup_wh_report_action_bar(); $form->header(); print $form->parse_html_template("wh/report_filter", - { "nextsub" => "generate_report", - "WAREHOUSES" => $form->{WAREHOUSES}, - "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) }); + { "WAREHOUSES" => $form->{WAREHOUSES}, + "PARTSGROUPS" => $form->{PARTSGROUPS}, + "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)), + }); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub generate_report { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $auth->assert('warehouse_contents | warehouse_management'); + $main::auth->assert('warehouse_contents | warehouse_management'); - $form->{title} = $locale->text("Report about wareouse contents"); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $form->{title} = $locale->text("Report about warehouse contents"); $form->{sort} ||= 'partnumber'; my $sort_col = $form->{sort}; my %filter; - my @columns = qw(warehousedescription bindescription partnumber partdescription chargenumber qty stock_value); + my @columns = qw(warehousedescription bindescription partnumber type_and_classific partdescription chargenumber bestbefore comment qty partunit list_price purchase_price stock_value); # filter stuff - map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id partnumber description chargenumber); + map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id classification_id partnumber description partsgroup_id 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::PartClassification->get_first(where => [ id => $form->{classification_id} ] )->description; }, + description => sub { push @options, $locale->text('Description') . " : $form->{description}"}, + partsgroup_id => sub { push @options, $locale->text('Partsgroup') . " : " . + SL::DB::PartsGroup->new(id => $form->{partsgroup_id})->load->partsgroup}, + 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}) { - $form->isblank(qty, $locale->text('Quantity missing.')); - $form->isblank(qty_unit, $locale->text('Unit missing.')); + $form->isblank("qty", $locale->text('Quantity missing.')); + $form->isblank("qty_unit", $locale->text('Unit missing.')); $filter{qty} = $form->{qty}; $filter{qty_unit} = $form->{qty_unit}; } # /filter stuff + $form->{report_generator_output_format} = 'HTML' if !$form->{report_generator_output_format}; + + # manual paginating + my $allrows = $form->{report_generator_output_format} eq 'HTML' ? $form->{allrows} : 1; + my $page = $::form->{page} || 1; + 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}; + + # no optimisation if qty op + if ( !$allrows && $form->{maxrows} && !$filter{qty_op}) { + $filter{limit} = $pages->{per_page}; + $filter{offset} = ($page - 1) * $pages->{per_page}; + $first_nr = 0; + $last_nr = $pages->{per_page}; + } + + my @contents = WH->get_warehouse_report(%filter); + + # get maxcount + if (!$form->{maxrows}) { + $form->{maxrows} = scalar @contents ; + } + $form->{subtotal} = '' if (!first { $_ eq $sort_col } qw(partnumber partdescription)); my $report = SL::ReportGenerator->new(\%myconfig, $form); + my $cvar_configs = CVar->get_configs('module' => 'IC'); + my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs }; + my @searchable_custom_variables = grep { $_->{searchable} } @{ $cvar_configs }; + push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables; + my @hidden_variables = map { "l_${_}" } @columns; - push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber 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 partsgroup_id 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 stock_value_basis allrows); + push @hidden_variables, map({'cvar_'. $_->{name}} @searchable_custom_variables); + push @hidden_variables, map({'cvar_'. $_->{name} .'_from'} grep({$_->{type} eq 'date'} @searchable_custom_variables)); + push @hidden_variables, map({'cvar_'. $_->{name} .'_to'} grep({$_->{type} eq 'date'} @searchable_custom_variables)); + push @hidden_variables, map({'cvar_'. $_->{name} .'_qtyop'} grep({$_->{type} eq 'number'} @searchable_custom_variables)); my %column_defs = ( 'warehousedescription' => { 'text' => $locale->text('Warehouse'), }, 'bindescription' => { 'text' => $locale->text('Bin'), }, 'partnumber' => { 'text' => $locale->text('Part Number'), }, - 'partdescription' => { 'text' => $locale->text('Description'), }, + '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'), }, + 'purchase_price' => { 'text' => $locale->text('Purchase price'), }, + 'list_price' => { 'text' => $locale->text('List Price'), }, ); + my %column_defs_cvars = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @includeable_custom_variables; + %column_defs = (%column_defs, %column_defs_cvars); + 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; + $href .= "&maxrows=".$form->{maxrows}; - my %column_alignment = map { $_ => 'right' } qw(qty stock_value); + map { $column_defs{$_}->{link} = $href . "&page=".$page."&sort=${_}&order=" . Q($_ eq $sort_col ? 1 - $form->{order} : $form->{order}) } grep {!/^cvar_/} @columns; + + my %column_alignment = map { $_ => 'right' } qw(qty list_price purchase_price stock_value); map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns; + $column_defs{partunit}->{visible} = 1; + $column_defs{type_and_classific}->{visible} = 1; + $column_defs{type_and_classific}->{link} =''; + $report->set_columns(%column_defs); $report->set_column_order(@columns); @@ -771,14 +973,19 @@ 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'; + CVar->add_custom_variables_to_report('module' => 'IC', + 'trans_id_field' => 'parts_id', + 'configs' => $cvar_configs, + 'column_defs' => \%column_defs, + 'data' => \@contents); my $all_units = AM->retrieve_units(\%myconfig, $form); - my @contents = WH->get_warehouse_report(%filter); - my $idx = 0; my @subtotals_columns = qw(qty stock_value); @@ -786,38 +993,41 @@ sub generate_report { my $total_stock_value = 0; - foreach $entry (@contents) { + foreach my $entry (@contents) { + + $entry->{type_and_classific} = SL::Presenter::Part::type_abbreviation($entry->{part_type}). + SL::Presenter::Part::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->{stock_value} = $form->format_amount(\%myconfig, $entry->{stock_value} * 1, 2); + $entry->{purchase_price} = $form->format_amount(\%myconfig, $entry->{purchase_price} * 1, 2); + $entry->{list_price} = $form->format_amount(\%myconfig, $entry->{list_price} * 1, 2); - $row_set = [ { map { $_ => { 'data' => $entry->{$_}, 'align' => $column_alignment{$_} } } @columns } ]; + 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->{stock_value}->{data} = $form->format_amount(\%myconfig, $subtotals{stock_value} * 1, 2); + $row->{purchase_price}->{data} = $form->format_amount(\%myconfig, $subtotals{purchase_price} * 1, 2); + $row->{list_price}->{data} = $form->format_amount(\%myconfig, $subtotals{list_price} * 1, 2); %subtotals = map { $_ => 0 } @subtotals_columns; 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 }; @@ -830,10 +1040,18 @@ sub generate_report { $report->add_data($row); } + 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', + {'pages' => $pages , 'base_url' => $href}) ); + } $report->generate_with_headers(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # -------------------------------------------------------------------- @@ -841,11 +1059,15 @@ sub generate_report { # -------------------------------------------------------------------- sub show_no_warehouses_error { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; my $msg = $locale->text('No warehouse has been created yet or the quantity of the bins is not configured yet.') . ' '; - if ($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.'); @@ -853,12 +1075,14 @@ sub show_no_warehouses_error { $form->show_generic_error($msg); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub get_warehouse_idx { my ($warehouse_id) = @_; + my $form = $main::form; + for (my $i = 0; $i < scalar @{$form->{WAREHOUSES}}; $i++) { return $i if ($form->{WAREHOUSES}->[$i]->{id} == $warehouse_id); } @@ -869,6 +1093,8 @@ sub get_warehouse_idx { sub get_bin_idx { my ($warehouse_index, $bin_id) = @_; + my $form = $main::form; + my $warehouse = $form->{WAREHOUSES}->[$warehouse_index]; return -1 if (!$warehouse); @@ -880,16 +1106,178 @@ sub get_bin_idx { return -1; } +sub new_item { + $main::lxdebug->enter_sub(); + my %params = @_; + + my $form = $main::form; + + # change callback + $form->{old_callback} = $form->escape($form->{callback}, 1); + $form->{callback} = $form->escape("$form->{script}?action=$params{action}", 1); + + # save all form variables except action in a previousform variable + my $previousform = join '&', map { my $value = $form->{$_}; $value =~ s/&/%26/; "$_=$value" } grep { !/action/ } keys %$form; + my @HIDDENS = (); + +# push @HIDDENS, { 'name' => 'previousform', 'value' => $form->escape($previousform, 1) }; + push @HIDDENS, map +{ 'name' => $_, 'value' => $form->{$_} }, qw(partnumber description unit vc sellprice ean); + push @HIDDENS, { 'name' => 'taxaccount2', 'value' => $form->{taxaccounts} }; + push @HIDDENS, { 'name' => 'notes', 'value' => $form->{longdescription} }; + + $form->header(); + print $form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } ); + + $main::lxdebug->leave_sub(); +} + sub update { + my $form = $main::form; call_sub($form->{update_nextsub} || $form->{nextsub}); } sub continue { + my $form = $main::form; call_sub($form->{continue_nextsub} || $form->{nextsub}); } sub stock { + my $form = $main::form; call_sub($form->{stock_nextsub} || $form->{nextsub}); } +sub setup_wh_transfer_warehouse_selection_action_bar { + my ($action) = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Update'), + submit => [ '#form', { action => $action } ], + accesskey => 'enter', + ], + ); + } +} + +sub setup_wh_transfer_warehouse_selection_assembly_action_bar { + my ($action) = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Update'), + submit => [ '#form', { action => 'transfer_assembly_update_part' } ], + accesskey => 'enter', + ], + action => [ + t8('Produce'), + submit => [ '#form', { action => 'create_assembly' } ], + disabled => $::form->{parts_id} ? undef : $::locale->text('No assembly has been selected yet.'), + ], + ); + } +} + +sub setup_wh_transfer_parts_action_bar { + my ($action) = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Transfer'), + submit => [ '#form', { action => 'transfer_parts' } ], + accesskey => 'enter', + ], + action => [ + t8('Back'), + call => [ 'kivi.history_back' ], + ], + ); + } +} + +sub setup_wh_removal_parts_selection_action_bar { + my ($action) = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Transfer out'), + submit => [ '#form', { action => 'remove_parts' } ], + accesskey => 'enter', + ], + action => [ + t8('Back'), + call => [ 'kivi.history_back' ], + ], + ); + } +} + +sub setup_wh_report_action_bar { + my ($action) = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Show'), + submit => [ '#form', { action => 'generate_report' } ], + accesskey => 'enter', + ], + ); + } +} + +sub setup_wh_journal_action_bar { + my ($action) = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Show'), + submit => [ '#form', { action => 'generate_journal' } ], + accesskey => 'enter', + ], + ); + } +} +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; + +__END__ + +=head1 NAME + +bin/mozilla/wh.pl - Warehouse frontend. + +=head1 FUNCTIONS + +=over 4 + +=item new_item + +call new item dialogue from warehouse masks. + +PARAMS: + action => name of sub to be called when new item is done + +=back + +=cut