--- /dev/null
+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;
__PACKAGE__->meta->make_manager_class;
+sub full_description {
+ my ($self) = @_;
+
+ $self->warehouse
+ ? $self->warehouse->description . "/" . $self->description
+ : $self->description
+}
+
1;
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);
}
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;
'Jan' => 'Jan',
'January' => 'Januar',
'Journal' => 'Buchungsjournal',
+ 'Journal of Last 10 Transfers' => 'Letzte 10 Lagertransaktionen',
'Jul' => 'Jul',
'July' => 'Juli',
'Jump to' => 'Springe zu',
'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.',
'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',
'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',
'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',
'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',
[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
--- /dev/null
+[% USE L %]
+[% USE HTML %]
+[% USE LxERP %]
+[% USE T8 %]
+<h3>[% 'Journal of Last 10 Transfers' | $T8 %]</h3>
+
+[%- IF journal.size %]
+<table>
+ <tr class='listheading'>
+ <th>[% 'Date' | $T8 %]</th>
+ <th>[% 'Trans Type' | $T8 %]</th>
+ <th>[% 'Part' | $T8 %]</th>
+ <th>[% 'Warehouse From' | $T8 %]</th>
+ <th>[% 'Qty' | $T8 %]</th>
+ <th>[% 'Unit' | $T8 %]</th>
+ <th>[% 'Warehouse To' | $T8 %]</th>
+ <th>[% 'Charge Number' | $T8 %]</th>
+ <th>[% 'Comment' | $T8 %]</th>
+ </tr>
+[% FOREACH row = journal %]
+ <tr class='listrow'>
+ <td>[% row.base.itime_as_date %]</td>
+ <td>[% row.base.trans_type.description | $T8 %]</td>
+ <td>[% row.base.part.long_description | html %]</td>
+ <td>[% row.out ? row.out.bin.full_description : '-' | html %]</td>
+ <td class='numeric'>[% row.in ? row.in.qty_as_number : LxERP.format_amount(-1 * row.out.qty, 2) %]</td>
+ <td>[% row.base.part.unit | html %]</td>
+ <td>[% row.in ? row.in.bin.full_description : '-' | html %]</td>
+ <td>[% row.base.chargenumber | html %]</td>
+ <td>[% row.base.comment | html %]</td>
+ </tr>
+[% END %]
+</table>
+[%- ELSE %]
+<p>[% 'No transactions yet.' | $T8 %]</p>
+[%- END %]
--- /dev/null
+[%- USE HTML %]
+[%- USE LxERP %]
+[%- USE L %]
+[%- USE T8 %]
+[%- IF SELF.part.id %]
+<h3>[% LxERP.t8('Stock for part #1', SELF.part.long_description) %]</h3>
+
+[%- IF stock_empty && !SELF.part.bin_id %]
+<p>[% 'Nothing stocked yet.' | $T8 %]</p>
+[%- ELSE %]
+<table>
+ <tr class='listheading'>
+ <th>[% 'Warehouse' | $T8 %]</th>
+ <th>[% 'Bin' | $T8 %]</th>
+ <th>[% 'Qty' | $T8 %]</th>
+ </tr>
+[%- 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 -%]
+ <tr class='listrow'>
+ <td>[% bin.warehouse.description %]</td>
+ <td>[% bin.description %]</td>
+ <td class='numeric'>[% LxERP.format_amount(stock__set.sum, 2) %]</td>
+ </tr>
+ [%- END -%]
+[%- END -%]
+[%- END %]
+</table>
+[%- END %]
+[%- END %]
--- /dev/null
+[%- USE T8 %]
+[%- USE L %]
+[%- USE HTML %]
+[%- USE LxERP %]
+
+<h1>[% title | html %]</div>
+
+[%- PROCESS 'common/flash.html' %]
+
+<form name="Form" method="post" action="controller.pl">
+
+ <table>
+ <tr>
+ <th align="right" nowrap>[% 'Part' | $T8 %]</th>
+ <td>[% L.part_picker('part_id', SELF.part) %]</td>
+ </tr>
+
+ <tr>
+ <th align="right" nowrap>[% 'Destination warehouse' | $T8 %]</th>
+ <td>[% 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 %]
+ <span id='bin_id'></span>
+ [% END %]
+ <span id='write_default_bin_span' style='display:none'><br>[% L.checkbox_tag('write_default_bin', label=LxERP.t8('Write bin to default bin in part?')) %]</span>
+ </td>
+ </tr>
+
+ <tr>
+ <th align="right" nowrap>[% 'Charge number' | $T8 %]</th>
+ <td>[% L.input_tag('chargenumber', SELF.chargenumber, size=30) %]</td>
+ </tr>
+
+[% IF INSTANCE_CONF.get_show_bestbefore %]
+ <tr>
+ <th align="right" nowrap>[% 'Best Before' | $T8 %]</th>
+ <td>[% L.date_tag('bestbefore', SELF.bestbefore) %]</td>
+ </tr>
+[%- END %]
+
+ <tr>
+ <th align="right" nowrap>[% 'EAN' | $T8 %]</th>
+ <td><input name="ean" size="30" value="[% HTML.escape(ean) %]"></td>
+ </tr>
+
+ <tr>
+ <th align="right" nowrap>[% 'Quantity' | $T8 %]</th>
+ <td>
+ <input name="qty" size="10" value="[% HTML.escape(LxERP.format_amount(qty)) %]">
+[%- 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 %]
+ </td>
+ </tr>
+
+ <tr>
+ <th align="right" nowrap>[% 'Optional comment' | $T8 %]</th>
+ <td><input name="comment" size="60" value="[% HTML.escape(comment) %]"></td>
+ </tr>
+ </table>
+
+ <input type="hidden" name="action" value="Inventory/dispatch">
+ <input type="submit" id='action_stock' class="submit" name="action_stock" value="[% 'Stock' | $T8 %]" [% IF !SELF.part.id %]disabled[% END %]>
+</form>
+
+<div id='stock'>
+ [%- PROCESS 'inventory/_stock.html' %]
+</div>
+<div id='journal'>
+ [%- PROCESS 'inventory/_journal.html' journal=SELF.mini_journal %]
+</div>
+
+<script type='text/javascript'>
+function reload_warehouse_selection () {
+ $.post("controller.pl", { action: 'Inventory/part_changed', part_id: function(){ return $('#part_id').val() } }, kivi.eval_json_result);
+ $.post("controller.pl", { action: 'Inventory/mini_stock', part_id: function(){ return $('#part_id').val() } }, kivi.eval_json_result);
+}
+function reload_bin_selection () {
+ $.post("controller.pl", { action: 'Inventory/warehouse_changed', warehouse_id: function(){ return $('#warehouse_id').val() } }, kivi.eval_json_result);
+}
+$(function(){
+ $('#part_id').change(reload_warehouse_selection);
+ $('#part_id').change(function(){
+ if ($('#part_id').val() > 0)
+ $('#action_stock').removeAttr('disabled');
+ else
+ $('#action_stock').attr('disabled', 'disabled');
+ });
+ $('#warehouse_id').change(reload_bin_selection);
+})
+</script>