From 666d4cad684028ef5ebb5b62adca17127b9bd864 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 27 Jun 2013 17:14:01 +0200 Subject: [PATCH] Inventory Controller und neue stock_in Maske MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Alte Methode ist weiter im Code vorhanden, wird aber geplant nach und nach durch das neue Interface ersetzt. Benötigt Partpicker --- SL/Controller/Inventory.pm | 246 ++++++++++++++++++ SL/DB/Bin.pm | 8 + SL/DB/Part.pm | 19 ++ css/lx-office-erp/main.css | 6 +- locale/de/all | 6 + menu.ini | 5 +- templates/webpages/inventory/_journal.html | 36 +++ templates/webpages/inventory/_stock.html | 32 +++ .../inventory/warehouse_selection_stock.html | 94 +++++++ 9 files changed, 446 insertions(+), 6 deletions(-) create mode 100644 SL/Controller/Inventory.pm create mode 100644 templates/webpages/inventory/_journal.html create mode 100644 templates/webpages/inventory/_stock.html create mode 100644 templates/webpages/inventory/warehouse_selection_stock.html diff --git a/SL/Controller/Inventory.pm b/SL/Controller/Inventory.pm new file mode 100644 index 000000000..ba208c437 --- /dev/null +++ b/SL/Controller/Inventory.pm @@ -0,0 +1,246 @@ +package SL::Controller::Inventory; + +use strict; +use warnings; + +use parent qw(SL::Controller::Base); + +use SL::DB::Inventory; +use SL::DB::Part; +use SL::DB::Warehouse; +use SL::DB::Unit; +use SL::WH; +use SL::Locale::String qw(t8); +use SL::ClientJS; +use SL::Presenter; +use SL::DBUtils; +use SL::Helper::Flash; + +use Rose::Object::MakeMethods::Generic ( + 'scalar --get_set_init' => [ qw(warehouses units js p) ], + 'scalar' => [ qw(warehouse bin unit part) ], +); + +__PACKAGE__->run_before('_check_auth'); +__PACKAGE__->run_before('_check_warehouses'); +__PACKAGE__->run_before('load_part_from_form', only => [ qw(stock_in part_changed mini_stock stock) ]); +__PACKAGE__->run_before('load_unit_from_form', only => [ qw(stock_in part_changed mini_stock stock) ]); +__PACKAGE__->run_before('load_wh_from_form', only => [ qw(stock_in warehouse_changed stock) ]); +__PACKAGE__->run_before('load_bin_from_form', only => [ qw(stock_in stock) ]); +__PACKAGE__->run_before('set_target_from_part', only => [ qw(part_changed) ]); +__PACKAGE__->run_before('sanitize_target', only => [ qw(stock_in warehouse_changed part_changed) ]); +__PACKAGE__->run_before('set_layout'); + +sub action_stock_in { + my ($self) = @_; + + $::form->{title} = t8('Stock'); + + $::request->layout->focus('#part_id_name'); + $_[0]->render('inventory/warehouse_selection_stock', title => $::form->{title}); +} + +sub action_stock { + my ($self) = @_; + + # do stock + WH->transfer({ + parts => $self->part, + dst_bin => $self->bin, + dst_wh => $self->warehouse, + qty => $::form->format_amount(\%::myconfig, $::form->{qty}), + unit => $self->unit, + transfer_type => 'stock', + chargenumber => $::form->{chargenumber}, + ean => $::form->{ean}, + comment => $::form->{comment}, + }); + + if ($::form->{write_default_bin}) { + $self->part->bin($self->bin); + $self->part->warehouse($self->warehouse); + $self->part->save; + } + + flash_later('info', t8('Transfer successful')); + + # redirect + $self->redirect_to( + action => 'stock_in', + part_id => $self->part->id, + bin_id => $self->bin->id, + warehouse_id => $self->warehouse->id, + ); +} + +sub action_part_changed { + my ($self) = @_; + + # no standard? ask user if he wants to write it + if ($self->part->id && !$self->part->bin_id && !$self->part->warehouse_id) { + $self->js->show('#write_default_bin_span'); + } else { + $self->js->hide('#write_default_bin_span') + ->removeAttr('#write_default_bin', 'checked'); + } + + $self->js + ->replaceWith('#warehouse_id', $self->build_warehouse_select) + ->replaceWith('#bin_id', $self->build_bin_select) + ->replaceWith('#unit_id', $self->build_unit_select) + ->focus('#warehouse_id') + ->render($self); +} + +sub action_warehouse_changed { + my ($self) = @_; + + $self->js + ->replaceWith('#bin_id', $self->build_bin_select) + ->focus('#bin_id') + ->render($self); +} + +sub action_mini_stock { + my ($self) = @_; + + my $stock = $self->part->get_simple_stock; + my $stock_by_bin = { map { $_->{bin_id} => $_ } @$stock }; + my $stock_empty = ! grep { $_->{sum} * 1 } @$stock; + + $self->js + ->html('#stock', $self->render('inventory/_stock', { output => 0 }, stock => $stock_by_bin, stock_empty => $stock_empty )) + ->render($self); +} + +sub action_last_journal { + my ($self) = @_; + +# my $jounal = $self->journal; + +} + +#================================================================ + +sub _check_auth { + $main::auth->assert('warehouse_management'); +} + +sub _check_warehouses { + $_[0]->show_no_warehouses_error if !@{ $_[0]->warehouses }; +} + +sub init_warehouses { + SL::DB::Manager::Warehouse->get_all; +} + +sub init_units { + SL::DB::Manager::Unit->get_all; +} + +sub init_js { + SL::ClientJS->new; +} + +sub init_p { + SL::Presenter->get; +} + +sub set_target_from_part { + my ($self) = @_; + + return if !$self->part; + + $self->warehouse($self->part->warehouse) if $self->part->warehouse; + $self->bin( $self->part->bin) if $self->part->bin; +} + +sub sanitize_target { + my ($self) = @_; + + $self->warehouse(SL::DB::Manager::Warehouse->get_first) if !$self->warehouse || !$self->warehouse->id; + $self->bin ($self->warehouse->bins->[0]) if !$self->bin || !$self->bin->id; +} + +sub load_part_from_form { + $_[0]->part(SL::DB::Manager::Part->find_by_or_create(id => $::form->{part_id})); +} + +sub load_unit_from_form { + $_[0]->unit(SL::DB::Manager::Unit->find_by_or_create(id => $::form->{unit_id})); +} + +sub load_wh_from_form { + $_[0]->warehouse(SL::DB::Manager::Warehouse->find_by_or_create(id => $::form->{warehouse_id})); +} + +sub load_bin_from_form { + $_[0]->bin(SL::DB::Manager::Bin->find_by_or_create(id => $::form->{bin_id})); +} + +sub set_layout { + $::request->layout->add_javascripts('client_js.js'); +} + +sub build_warehouse_select { + $_[0]->p->select_tag('warehouse_id', $_[0]->warehouses, + title_key => 'description', + default => $_[0]->warehouse->id, + onchange => 'reload_bin_selection()', + ) +} + +sub build_bin_select { + $_[0]->p->select_tag('bin_id', [ $_[0]->warehouse->bins ], + title_key => 'description', + default => $_[0]->bin->id, + ); +} + +sub build_unit_select { + $_[0]->part->id + ? $_[0]->p->select_tag('unit_id', $_[0]->part->available_units, + title_key => 'name', + default => $_[0]->part->unit_obj->id, + ) + : $_[0]->p->select_tag('unit_id', $_[0]->units, + title_key => 'name', + ) +} + +sub mini_journal { + my ($self) = @_; + + # get last 10 transaction ids + my $query = 'SELECT trans_id, max(itime) FROM inventory GROUP BY trans_id ORDER BY max(itime) DESC LIMIT 10'; + my @ids = selectall_array_query($::form, $::form->get_standard_dbh, $query); + + my $objs = SL::DB::Manager::Inventory->get_all(query => [ trans_id => \@ids ]); + + # at most 2 of them belong to a transaction and the qty determins in or out. + # sort them for display + my %transactions; + for (@$objs) { + $transactions{ $_->trans_id }{ $_->qty > 0 ? 'in' : 'out' } = $_; + $transactions{ $_->trans_id }{base} = $_; + } + # and get them into order again + my @sorted = map { $transactions{$_} } @ids; + + return \@sorted; +} + +sub show_no_warehouse_error { + my ($self) = @_; + + my $msg = t8('No warehouse has been created yet or the quantity of the bins is not configured yet.') . ' '; + + if ($::auth->check_right($::form->{login}, 'config')) { # TODO wut? + $msg .= t8('You can create warehouses and bins via the menu "System -> Warehouses".'); + } else { + $msg .= t8('Please ask your administrator to create warehouses and bins.'); + } + $::form->show_generic_error($msg); +} + +1; diff --git a/SL/DB/Bin.pm b/SL/DB/Bin.pm index 8d856c4fa..5d184ae9e 100644 --- a/SL/DB/Bin.pm +++ b/SL/DB/Bin.pm @@ -8,4 +8,12 @@ __PACKAGE__->meta->initialize; __PACKAGE__->meta->make_manager_class; +sub full_description { + my ($self) = @_; + + $self->warehouse + ? $self->warehouse->description . "/" . $self->description + : $self->description +} + 1; diff --git a/SL/DB/Part.pm b/SL/DB/Part.pm index 94ce4d207..ecdaeaabe 100644 --- a/SL/DB/Part.pm +++ b/SL/DB/Part.pm @@ -179,6 +179,25 @@ sub get_chart { return $charts->{$taxzone}->{$type}; } +# this is designed to ignore chargenumbers, expiration dates and just give a list of how much <-> where +sub get_simple_stock { + my ($self, %params) = @_; + + return [] unless $self->id; + + my $query = <<''; + SELECT sum(qty), warehouse_id, bin_id FROM inventory WHERE parts_id = ? + GROUP BY warehouse_id, bin_id + + my $stock_info = selectall_hashref_query($::form, $::form->get_standard_dbh, $query, $self->id); + [ map { bless $_, 'SL::DB::Part::SimpleStock'} @$stock_info ]; +} +# helper class to have bin/warehouse accessors in stock result +{ package SL::DB::Part::SimpleStock; + sub warehouse { require SL::DB::Warehouse; SL::DB::Manager::Warehouse->find_by_or_create(id => $_[0]->{warehouse_id}) } + sub bin { require SL::DB::Bin; SL::DB::Manager::Bin ->find_by_or_create(id => $_[0]->{bin_id}) } +} + sub long_description { join ' ', grep $_, map $_[0]->$_, qw(partnumber description); } diff --git a/css/lx-office-erp/main.css b/css/lx-office-erp/main.css index a5b33a706..019c46d79 100644 --- a/css/lx-office-erp/main.css +++ b/css/lx-office-erp/main.css @@ -54,9 +54,9 @@ button:focus { background-color: whitesmoke; } -button:hover, -input[type="button"]:hover, -input[type="submit"]:hover { +button:hover:enabled, +input[type="button"]:hover:enabled, +input[type="submit"]:hover:enabled { border: 1px; background-color: lightgray; border-color: gray; diff --git a/locale/de/all b/locale/de/all index 4495cffd7..e0eb2da39 100755 --- a/locale/de/all +++ b/locale/de/all @@ -1121,6 +1121,7 @@ $self->{texts} = { 'Jan' => 'Jan', 'January' => 'Januar', 'Journal' => 'Buchungsjournal', + 'Journal of Last 10 Transfers' => 'Letzte 10 Lagertransaktionen', 'Jul' => 'Jul', 'July' => 'Juli', 'Jump to' => 'Springe zu', @@ -1322,6 +1323,7 @@ $self->{texts} = { 'No shipto selected to delete' => 'Keine Lieferadresse zum Löschen ausgewählt', 'No summary account' => 'Kein Sammelkonto', 'No transaction selected!' => 'Keine Transaktion ausgewählt', + 'No transactions yet.' => 'Bisher keine Buchungen.', 'No transfers were executed in this export.' => 'In diesem SEPA-Export wurden keine Überweisungen ausgeführt.', 'No users have been created yet.' => 'Es wurden noch keine Benutzer anleget.', 'No valid number entered for pricegroup "#1".' => 'Für Preisgruppe "#1" wurde keine gültige Nummer eingegeben.', @@ -1343,6 +1345,7 @@ $self->{texts} = { 'Nothing has been selected for removal.' => 'Es wurde nichts für eine Entnahme ausgewählt.', 'Nothing has been selected for transfer.' => 'Es wurde nichts zum Umlagern ausgewählt.', 'Nothing selected!' => 'Es wurde nichts ausgewählt!', + 'Nothing stocked yet.' => 'Noch nichts eingelagert.', 'Nov' => 'Nov', 'November' => 'November', 'Number' => 'Nummer', @@ -1871,6 +1874,7 @@ $self->{texts} = { 'Steuersatz' => 'Steuersatz', 'Stock' => 'Einlagern', 'Stock Qty for Date' => 'Lagerbestand am', + 'Stock for part #1' => 'Bestand für Artikel #1', 'Stock value' => 'Bestandswert', 'Stocked Qty' => 'Lagermenge', 'Stop task server' => 'Task-Server beenden', @@ -2248,6 +2252,7 @@ $self->{texts} = { 'Transfer out' => 'Auslagern', 'Transfer out via default' => 'Auslagern über Standard-Lagerplatz', 'Transfer qty' => 'Umlagermenge', + 'Transfer successful' => 'Lagervorgang erfolgreich', 'Translation' => 'Übersetzung', 'Trial Balance' => 'Summen- und Saldenliste', 'Trial balance between %s and %s' => 'Summen- und Saldenlisten vom %s bis zum %s', @@ -2374,6 +2379,7 @@ $self->{texts} = { 'Workflow request_quotation' => 'Workflow Preisanfrage', 'Workflow sales_order' => 'Workflow Auftrag', 'Workflow sales_quotation' => 'Workflow Angebot', + 'Write bin to default bin in part?' => 'Diesen Lagerplatz als Standardlagerplatz im Artikel setzen?', 'Wrong Period' => 'Falscher Zeitraum', 'Wrong tax keys recorded' => 'Gespeicherte Steuerschlüssel sind falsch', 'Wrong taxes recorded' => 'Gespeicherte Steuern passen nicht zum Steuerschlüssel', diff --git a/menu.ini b/menu.ini index 73ac2d072..e72e47a69 100644 --- a/menu.ini +++ b/menu.ini @@ -229,9 +229,8 @@ nextsub=ap_transactions [Warehouse--Stock] ACCESS=warehouse_management -module=wh.pl -action=transfer_warehouse_selection -trans_type=stock +module=controller.pl +action=Inventory/stock_in [Warehouse--Produce Assembly] ACCESS=warehouse_management diff --git a/templates/webpages/inventory/_journal.html b/templates/webpages/inventory/_journal.html new file mode 100644 index 000000000..1dced05a6 --- /dev/null +++ b/templates/webpages/inventory/_journal.html @@ -0,0 +1,36 @@ +[% USE L %] +[% USE HTML %] +[% USE LxERP %] +[% USE T8 %] +

[% 'Journal of Last 10 Transfers' | $T8 %]

+ +[%- IF journal.size %] + + + + + + + + + + + + +[% FOREACH row = journal %] + + + + + + + + + + + +[% END %] +
[% 'Date' | $T8 %][% 'Trans Type' | $T8 %][% 'Part' | $T8 %][% 'Warehouse From' | $T8 %][% 'Qty' | $T8 %][% 'Unit' | $T8 %][% 'Warehouse To' | $T8 %][% 'Charge Number' | $T8 %][% 'Comment' | $T8 %]
[% row.base.itime_as_date %][% row.base.trans_type.description | $T8 %][% row.base.part.long_description | html %][% row.out ? row.out.bin.full_description : '-' | html %][% row.in ? row.in.qty_as_number : LxERP.format_amount(-1 * row.out.qty, 2) %][% row.base.part.unit | html %][% row.in ? row.in.bin.full_description : '-' | html %][% row.base.chargenumber | html %][% row.base.comment | html %]
+[%- ELSE %] +

[% 'No transactions yet.' | $T8 %]

+[%- END %] diff --git a/templates/webpages/inventory/_stock.html b/templates/webpages/inventory/_stock.html new file mode 100644 index 000000000..4bd57ebd4 --- /dev/null +++ b/templates/webpages/inventory/_stock.html @@ -0,0 +1,32 @@ +[%- USE HTML %] +[%- USE LxERP %] +[%- USE L %] +[%- USE T8 %] +[%- IF SELF.part.id %] +

[% LxERP.t8('Stock for part #1', SELF.part.long_description) %]

+ +[%- IF stock_empty && !SELF.part.bin_id %] +

[% 'Nothing stocked yet.' | $T8 %]

+[%- ELSE %] + + + + + + +[%- FOREACH wh = SELF.warehouses -%] +[%- FOREACH bin = wh.bins -%] + [%#- display any bins with stock and default bin -%] + [%- SET stock__set = stock.${bin.id} -%] + [%- IF stock__set.sum > 0 || SELF.part.bin_id == bin.id -%] + + + + + + [%- END -%] +[%- END -%] +[%- END %] +
[% 'Warehouse' | $T8 %][% 'Bin' | $T8 %][% 'Qty' | $T8 %]
[% bin.warehouse.description %][% bin.description %][% LxERP.format_amount(stock__set.sum, 2) %]
+[%- END %] +[%- END %] diff --git a/templates/webpages/inventory/warehouse_selection_stock.html b/templates/webpages/inventory/warehouse_selection_stock.html new file mode 100644 index 000000000..32d625036 --- /dev/null +++ b/templates/webpages/inventory/warehouse_selection_stock.html @@ -0,0 +1,94 @@ +[%- USE T8 %] +[%- USE L %] +[%- USE HTML %] +[%- USE LxERP %] + +

[% title | html %] + +[%- PROCESS 'common/flash.html' %] + +
+ + + + + + + + + + + + + + + + + +[% IF INSTANCE_CONF.get_show_bestbefore %] + + + + +[%- END %] + + + + + + + + + + + + + + + +
[% 'Part' | $T8 %][% L.part_picker('part_id', SELF.part) %]
[% 'Destination warehouse' | $T8 %][% L.select_tag('warehouse_id', SELF.warehouses, default=SELF.warehouse.id, title_key='description') %] + [% IF SELF.warehouse.id %] + [% L.select_tag('bin_id', SELF.warehouse.bins, default=SELF.bin.id, title_key='description') %] + [%- ELSE %] + + [% END %] + +
[% 'Charge number' | $T8 %][% L.input_tag('chargenumber', SELF.chargenumber, size=30) %]
[% 'Best Before' | $T8 %][% L.date_tag('bestbefore', SELF.bestbefore) %]
[% 'EAN' | $T8 %]
[% 'Quantity' | $T8 %] + +[%- IF SELF.part.unit %] + [% L.select_tag('unit_id', SELF.part.available_units, title_key='name', default=SELF.unit.id) %] +[%- ELSE %] + [% L.select_tag('unit_id', SELF.units, title_key='name') %] +[%- END %] +
[% 'Optional comment' | $T8 %]
+ + + +
+ +
+ [%- PROCESS 'inventory/_stock.html' %] +
+
+ [%- PROCESS 'inventory/_journal.html' journal=SELF.mini_journal %] +
+ + -- 2.20.1