1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #############################################################################
7 # SQL-Ledger, Accounting
8 # Copyright (c) 1998-2002
10 # Author: Dieter Simader
11 # Email: dsimader@sql-ledger.org
12 # Web: http://www.sql-ledger.org
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #######################################################################
30 # warehouse and packinglist
32 #######################################################################
34 use List::Util qw(min max first);
35 use POSIX qw(strftime);
45 use SL::ReportGenerator;
49 require "bin/mozilla/common.pl";
50 require "bin/mozilla/reportgenerator.pl";
56 # contents of the "transfer_type" table:
57 # $locale->text('back')
58 # $locale->text('correction')
59 # $locale->text('disposed')
60 # $locale->text('found')
61 # $locale->text('missing')
62 # $locale->text('stock')
63 # $locale->text('shipped')
64 # $locale->text('transfer')
65 # $locale->text('used')
66 # $locale->text('return_material')
67 # $locale->text('release_material')
69 # --------------------------------------------------------------------
71 # --------------------------------------------------------------------
73 sub transfer_warehouse_selection {
74 $main::lxdebug->enter_sub();
76 $main::auth->assert('warehouse_management');
78 my $form = $main::form;
79 my %myconfig = %main::myconfig;
80 my $locale = $main::locale;
82 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES',
85 show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} });
87 my $units = AM->retrieve_units(\%myconfig, $form);
88 # der zweite Parameter von unit_select_data gibt den default-Namen (selected) vor
89 $form->{UNITS} = AM->unit_select_data($units, $form->{unit}, 0, $form->{unit});
91 if (scalar @{ $form->{WAREHOUSES} }) {
92 $form->{warehouse_id} ||= $form->{WAREHOUSES}->[0]->{id};
93 $form->{bin_id} ||= $form->{WAREHOUSES}->[0]->{BINS}->[0]->{id};
98 $form->{jsscript} = 1;
100 if ($form->{trans_type} eq 'removal') {
101 $form->{nextsub} = "removal_parts_selection";
102 $form->{title} = $locale->text('Removal from Warehouse');
103 $content = $form->parse_html_template('wh/warehouse_selection');
105 } elsif ($form->{trans_type} eq 'stock') {
106 $form->{title} = $locale->text('Stock');
107 $content = $form->parse_html_template('wh/warehouse_selection_stock');
109 } elsif (!$form->{trans_type} || ($form->{trans_type} eq 'transfer')) {
110 $form->{nextsub} = "transfer_parts_selection";
111 $form->{title} = $locale->text('Transfer');
112 $content = $form->parse_html_template('wh/warehouse_selection');
114 } elsif ($form->{trans_type} eq 'assembly') {
115 $form->{title} = $locale->text('Produce Assembly');
116 $content = $form->parse_html_template('wh/warehouse_selection_assembly');
122 $main::lxdebug->leave_sub();
125 sub transfer_parts_selection {
126 $main::lxdebug->enter_sub();
128 $main::auth->assert('warehouse_management');
130 my $form = $main::form;
131 my %myconfig = %main::myconfig;
132 my $locale = $main::locale;
134 transfer_or_removal_prepare_contents('direction' => 'transfer');
136 $form->{title} = $locale->text('Transfer');
138 print $form->parse_html_template("wh/transfer_parts_selection");
140 $main::lxdebug->leave_sub();
143 sub transfer_or_removal_prepare_contents {
144 $main::lxdebug->enter_sub();
146 $main::auth->assert('warehouse_management');
150 my $form = $main::form;
151 my %myconfig = %main::myconfig;
152 my $locale = $main::locale;
154 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES',
155 'bins' => 'BINS', });
157 my $warehouse_idx = get_warehouse_idx($form->{warehouse_id});
158 $form->show_generic_error($locale->text("The selected warehouse does not exist.")) if (-1 == $warehouse_idx);
160 my $warehouse = $form->{WAREHOUSES}->[$warehouse_idx];
162 $form->{initial_warehouse_idx} = $warehouse_idx;
163 $form->{warehouse_description} = $warehouse->{description};
164 $warehouse->{selected} = 1;
166 $form->show_generic_error($locale->text("The source warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} });
168 map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit ean);
170 $form->{sort} = 'bindescription';
171 my @contents = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id},
172 "bin_id" => $form->{bin_id},
173 "chargenumber" => $form->{chargenumber},
174 "bestbefore" => $form->{bestbefore},
175 "partnumber" => $form->{partnumber},
176 "ean" => $form->{ean},
177 "description" => $form->{description});
179 if (0 == scalar(@contents)) {
180 $form->show_generic_error($locale->text("The selected warehouse is empty, or no stocked items where found that match the filter settings."));
183 my $all_units = AM->retrieve_units(\%myconfig, $form);
185 foreach (@contents) {
186 $_->{qty} = $form->format_amount_units('amount' => $_->{qty},
187 'part_unit' => $_->{partunit},
188 'conv_units' => 'convertible');
189 my $this_unit = $_->{partunit};
191 if ($all_units->{$_->{partunit}} && ($all_units->{g}->{base_unit} eq $all_units->{$_->{partunit}}->{base_unit})) {
195 $_->{UNITS} = AM->unit_select_data($all_units, $this_unit, 0, $_->{partunit});
198 my $transfer_types = WH->retrieve_transfer_types($args{direction});
199 map { $_->{description} = $locale->text($_->{description}) } @{ $transfer_types };
201 $form->{CONTENTS} = \@contents;
202 $form->{TRANSFER_TYPES} = $transfer_types;
204 $main::lxdebug->leave_sub();
209 $main::lxdebug->enter_sub();
211 $main::auth->assert('warehouse_management');
213 my $form = $main::form;
214 my %myconfig = %main::myconfig;
215 my $locale = $main::locale;
217 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', 'bins' => 'BINS' });
219 my $warehouse_idx = get_warehouse_idx($form->{warehouse_id});
220 $form->show_generic_error($locale->text("The selected warehouse does not exist.")) if (-1 == $warehouse_idx);
222 my $warehouse = $form->{WAREHOUSES}->[$warehouse_idx];
224 $form->show_generic_error($locale->text("The source warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} });
226 map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit);
228 $form->{sort} = 'bindescription';
229 my @contents = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id});
230 my $all_units = AM->retrieve_units(\%myconfig, $form);
234 foreach my $row (1 .. $form->{rowcount}) {
235 $form->{"qty_$row"} =~ s/^\s*//;
236 $form->{"qty_$row"} =~ s/\s*$//;
237 next if (!$form->{"qty_$row"});
239 my $bin_idx = get_bin_idx($warehouse_idx, $form->{"src_bin_id_$row"});
240 $form->show_generic_error($locale->text("The selected bin does not exist.")) if (-1 == $bin_idx);
241 my $bin = $warehouse->{BINS}->[$bin_idx];
243 my $orig_qty = $form->{"qty_$row"} . " " . $form->{"unit_$row"};
246 'src_warehouse_id' => $form->{warehouse_id},
247 'transfer_type_id' => $form->{transfer_type_id},
250 map { $transfer->{$_} = $form->{"${_}_${row}"} } qw(src_bin_id chargenumber bestbefore parts_id qty dst_warehouse_id dst_bin_id);
254 foreach (@contents) {
255 if (($_->{binid} == $transfer->{src_bin_id}) && ($_->{parts_id} == $transfer->{parts_id}) && ($_->{chargenumber} eq $transfer->{chargenumber}) && $_->{bestbefore} eq $transfer->{bestbefore}) {
262 $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
263 $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
266 $transfer->{qty} = $form->parse_amount(\%myconfig, $transfer->{qty}) * $all_units->{$form->{"unit_$row"}}->{factor};
267 $transfer->{qty} /= $all_units->{$entry->{partunit}}->{factor} || 1;
269 if (($entry->{qty} < $transfer->{qty}) || (0 >= $transfer->{qty})) {
270 $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
271 $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
274 $transfer->{comment} = $form->{comment};
276 push @transfers, $transfer;
278 $entry->{qty} -= $transfer->{qty};
281 if (!scalar @transfers) {
282 $form->show_generic_information($locale->text('Nothing has been selected for transfer.'));
286 WH->transfer(@transfers);
288 $form->{trans_type} = 'transfer';
289 $form->{saved_message} = $locale->text('The parts have been transferred.');
291 transfer_warehouse_selection();
293 $main::lxdebug->leave_sub();
296 # --------------------------------------------------------------------
298 # --------------------------------------------------------------------
300 sub transfer_stock_update_part {
301 $main::lxdebug->enter_sub();
303 my $form = $main::form;
304 my %myconfig = %main::myconfig;
305 my $locale = $main::locale;
307 $form->{trans_type} = 'stock';
308 $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
310 if (!$form->{partnumber} && !$form->{description} && !$form->{ean}) {
311 delete @{$form}{qw(parts_id partunit ean)};
312 transfer_warehouse_selection();
314 } elsif (($form->{partnumber} && ($form->{partnumber} ne $form->{old_partnumber})) || $form->{description} || $form->{ean}) {
316 # $form->{no_services} = 1; # services may now be transfered. fix for Bug 1383.
317 $form->{no_assemblies} = 0; # assemblies duerfen eingelagert werden (z.B. bei retouren)
319 my $parts = Common->retrieve_parts(\%myconfig, $form, 'description', 1);
321 if (!scalar @{ $parts }) {
322 new_item(action => "transfer_stock_update_part");
323 } elsif (scalar @{ $parts } == 1) {
324 @{$form}{qw(parts_id partnumber description ean)} = @{$parts->[0]}{qw(id partnumber description ean)};
325 transfer_stock_get_partunit();
326 transfer_warehouse_selection();
329 select_part('transfer_stock_part_selected', @{ $parts });
333 transfer_stock_get_partunit();
334 transfer_warehouse_selection();
337 $main::lxdebug->leave_sub();
340 # --------------------------------------------------------------------
341 # Transfer: assemblies
342 # Dies ist die Auswahlmaske fĂĽr ein assembly.
343 # Die ist einfach von transfer_assembly_update_part kopiert und nur um den trans_type (assembly) korrigiert worden
344 # Es wäre schön, hier nochmal check_assembly_max_create auf, um die max. Fertigungszahl herauszufinden.
345 # Ich lass das mal als auskommentierte Idee bestehen jb 18.3.09
346 # --------------------------------------------------------------------
348 sub transfer_assembly_update_part {
349 $main::lxdebug->enter_sub();
351 my $form = $main::form;
352 my %myconfig = %main::myconfig;
353 my $locale = $main::locale;
355 $form->{trans_type} = 'assembly';
356 $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
358 if (!$form->{partnumber} && !$form->{description}) {
359 delete @{$form}{qw(parts_id partunit)};
360 transfer_warehouse_selection();
362 } elsif (($form->{partnumber} && ($form->{partnumber} ne $form->{old_partnumber})) || $form->{description}) {
363 $form->{assemblies} = 1;
364 $form->{no_assemblies} = 0;
365 my $parts = Common->retrieve_parts(\%myconfig, $form, 'description', 1);
366 if (scalar @{ $parts } == 1) {
367 @{$form}{qw(parts_id partnumber description)} = @{$parts->[0]}{qw(id partnumber description)};
368 transfer_stock_get_partunit();
369 transfer_warehouse_selection();
371 select_part('transfer_stock_part_selected', @{ $parts });
375 transfer_stock_get_partunit();
376 transfer_warehouse_selection();
379 # hier die oben benannte idee
380 # my $maxcreate = Common->check_assembly_max_create(assembly_id => $form->{parts_id}, dbh => $my_dbh);
381 $main::lxdebug->leave_sub();
384 sub transfer_stock_part_selected {
385 $main::lxdebug->enter_sub();
389 my $form = $main::form;
391 @{$form}{qw(parts_id partnumber description ean)} = @{$part}{qw(id partnumber description ean)};
393 transfer_stock_get_partunit();
394 transfer_warehouse_selection();
396 $main::lxdebug->leave_sub();
399 sub transfer_stock_get_partunit {
400 $main::lxdebug->enter_sub();
402 my $form = $main::form;
404 if ($form->{parts_id}) {
405 my $part_info = IC->get_basic_part_info('id' => $form->{parts_id});
406 $form->{partunit} = $part_info->{unit};
409 $main::lxdebug->leave_sub();
412 # vorĂĽberlegung jb 22.2.2009
413 # wir benötigen für diese funktion, die anzahl die vom erzeugnis hergestellt werden soll. vielleicht direkt per js fehleingaben verhindern?
414 # ferner dann nochmal mit check_asssembly_max_create gegenprĂĽfen und dann transaktionssicher wegbuchen.
415 # 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
416 # Manko ist derzeit noch, dass unterschiedliche Lagerplätze, bzw. das Quelllager an sich nicht ausgewählt werden können.
417 # Laut Absprache in KW11 09 ĂĽbernimmt mb hier den rest im April ... jb 18.3.09
419 sub create_assembly {
420 $main::lxdebug->enter_sub();
422 my $form = $main::form;
423 my %myconfig = %main::myconfig;
424 my $locale = $main::locale;
426 $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
427 if ($form->{qty} <= 0) {
428 $form->show_generic_error($locale->text('Invalid quantity.'), 'back_button' => 1);
430 # TODO Es wäre schön, hier schon die maximale Anzahl der zu fertigenden Erzeugnisse zu haben
431 #else { if ($form->{qty} > $maxcreate) { #s.o.
432 # $form->show_generic_error($locale->text('Can not create that quantity with current stock'), 'back_button' => 1);
433 # $form->show_generic_error('Maximale StĂĽckzahl' . $maxcreate , 'back_button' => 1);
437 if (!$form->{warehouse_id} || !$form->{bin_id}) {
438 $form->error($locale->text('The warehouse or the bin is missing.'));
441 if (!$::instance_conf->get_show_bestbefore) {
442 $form->{bestbefore} = '';
445 # 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
446 # Anm. jb 18.3. vielleicht auch nur meine unwissenheit in perl-datenstrukturen
448 'transfer_type' => 'assembly',
449 'login' => $form->{login},
450 'dst_warehouse_id' => $form->{warehouse_id},
451 'dst_bin_id' => $form->{bin_id},
452 'chargenumber' => $form->{chargenumber},
453 'bestbefore' => $form->{bestbefore},
454 'assembly_id' => $form->{parts_id},
455 'qty' => $form->{qty},
456 'unit' => $form->{unit},
457 'comment' => $form->{comment}
460 my $ret = WH->transfer_assembly (%TRANSFER);
461 # Frage: Ich pack in den return-wert auch gleich die Fehlermeldung. Irgendwelche Nummern als Fehlerkonstanten definieren find ich auch nicht besonders schick...
464 # 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
465 $form->show_generic_error($ret, 'back_button' => 1);
468 delete @{$form}{qw(parts_id partnumber description qty unit chargenumber bestbefore comment)};
470 $form->{saved_message} = $locale->text('The assembly has been created.');
471 $form->{trans_type} = 'assembly';
473 transfer_warehouse_selection();
475 $main::lxdebug->leave_sub();
479 $main::lxdebug->enter_sub();
481 my $form = $main::form;
482 my %myconfig = %main::myconfig;
483 my $locale = $main::locale;
485 $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
487 if ($form->{qty} <= 0) {
488 $form->show_generic_error($locale->text('Invalid quantity.'), 'back_button' => 1);
491 if (!$form->{warehouse_id} || !$form->{bin_id}) {
492 $form->error($locale->text('The warehouse or the bin is missing.'));
496 'transfer_type' => 'stock',
497 'dst_warehouse_id' => $form->{warehouse_id},
498 'dst_bin_id' => $form->{bin_id},
499 'chargenumber' => $form->{chargenumber},
500 'bestbefore' => $form->{bestbefore},
501 'parts_id' => $form->{parts_id},
502 'qty' => $form->{qty},
503 'unit' => $form->{unit},
504 'comment' => $form->{comment},
507 WH->transfer($transfer);
509 delete @{$form}{qw(parts_id partnumber description qty unit chargenumber bestbefore comment ean)};
511 $form->{saved_message} = $locale->text('The parts have been stocked.');
512 $form->{trans_type} = 'stock';
514 transfer_warehouse_selection();
516 $main::lxdebug->leave_sub();
519 # --------------------------------------------------------------------
521 # --------------------------------------------------------------------
523 sub removal_parts_selection {
524 $main::lxdebug->enter_sub();
526 $main::auth->assert('warehouse_management');
528 my $form = $main::form;
529 my %myconfig = %main::myconfig;
530 my $locale = $main::locale;
532 transfer_or_removal_prepare_contents('direction' => 'out');
534 $form->{title} = $locale->text('Removal');
536 print $form->parse_html_template("wh/removal_parts_selection");
538 $main::lxdebug->leave_sub();
542 $main::lxdebug->enter_sub();
544 $main::auth->assert('warehouse_management');
546 my $form = $main::form;
547 my %myconfig = %main::myconfig;
548 my $locale = $main::locale;
550 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES',
551 'bins' => 'BINS', });
553 my $warehouse_idx = get_warehouse_idx($form->{warehouse_id});
554 $form->show_generic_error($locale->text("The selected warehouse does not exist.")) if (-1 == $warehouse_idx);
556 my $warehouse = $form->{WAREHOUSES}->[$warehouse_idx];
558 $form->show_generic_error($locale->text("The warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} });
560 map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit);
562 $form->{sort} = 'bindescription';
563 my @contents = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id});
564 my $all_units = AM->retrieve_units(\%myconfig, $form);
568 foreach my $row (1 .. $form->{rowcount}) {
569 $form->{"qty_$row"} =~ s/^\s*//;
570 $form->{"qty_$row"} =~ s/\s*$//;
571 next if (!$form->{"qty_$row"});
573 my $bin_idx = get_bin_idx($warehouse_idx, $form->{"src_bin_id_$row"});
574 $form->show_generic_error($locale->text("The selected bin does not exist.")) if (-1 == $bin_idx);
575 my $bin = $warehouse->{BINS}->[$bin_idx];
577 my $orig_qty = $form->{"qty_$row"} . " " . $form->{"unit_$row"};
580 'src_warehouse_id' => $form->{warehouse_id},
581 'transfer_type_id' => $form->{transfer_type_id},
584 map { $transfer->{$_} = $form->{"${_}_${row}"} } qw(src_bin_id chargenumber bestbefore parts_id qty);
588 foreach (@contents) {
589 if (($_->{binid} == $transfer->{src_bin_id}) && ($_->{parts_id} == $transfer->{parts_id}) && ($_->{chargenumber} eq $transfer->{chargenumber}) && ($_->{bestbefore} eq $transfer->{bestbefore})) {
596 $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
597 $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
600 $transfer->{qty} = $form->parse_amount(\%myconfig, $transfer->{qty}) * $all_units->{$form->{"unit_$row"}}->{factor};
601 $transfer->{qty} /= $all_units->{$entry->{partunit}}->{factor} || 1;
603 if (($entry->{qty} < $transfer->{qty}) || (0 >= $transfer->{qty})) {
604 $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
605 $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
608 $transfer->{comment} = $form->{comment};
610 push @transfers, $transfer;
612 $entry->{qty} -= $transfer->{qty};
615 if (!scalar @transfers) {
616 $form->show_generic_information($locale->text('Nothing has been selected for removal.'));
620 WH->transfer(@transfers);
622 $form->{trans_type} = 'removal';
623 $form->{saved_message} = $locale->text('The parts have been removed.');
625 transfer_warehouse_selection();
627 $main::lxdebug->leave_sub();
630 # --------------------------------------------------------------------
632 # --------------------------------------------------------------------
635 $main::lxdebug->enter_sub();
637 $main::auth->assert('warehouse_management');
639 my $form = $main::form;
640 my %myconfig = %main::myconfig;
641 my $locale = $main::locale;
643 $form->{title} = $locale->text('Report about warehouse transactions');
644 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES',
645 'bins' => 'BINS', });
647 show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} });
649 $form->{jsscript} = 1;
652 print $form->parse_html_template("wh/journal_filter", { "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) });
654 $main::lxdebug->leave_sub();
657 sub generate_journal {
658 $main::lxdebug->enter_sub();
660 $main::auth->assert('warehouse_management');
662 my $form = $main::form;
663 my %myconfig = %main::myconfig;
664 my $locale = $main::locale;
666 $form->{title} = $locale->text("WHJournal");
667 $form->{sort} ||= 'date';
670 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);
673 map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id partnumber description chargenumber bestbefore);
675 $filter{qty_op} = WH->convert_qty_op($form->{qty_op});
676 if ($filter{qty_op}) {
677 $form->isblank("qty", $locale->text('Quantity missing.'));
678 $form->isblank("qty_unit", $locale->text('Unit missing.'));
680 $filter{qty} = $form->{qty};
681 $filter{qty_unit} = $form->{qty_unit};
685 my $report = SL::ReportGenerator->new(\%myconfig, $form);
687 my @hidden_variables = map { "l_${_}" } @columns;
688 push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber bestbefore qty_op qty qty_unit fromdate todate);
691 'date' => { 'text' => $locale->text('Date'), },
692 'trans_id' => { 'text' => $locale->text('Trans Id'), },
693 'trans_type' => { 'text' => $locale->text('Trans Type'), },
694 'comment' => { 'text' => $locale->text('Comment'), },
695 'warehouse_from' => { 'text' => $locale->text('Warehouse From'), },
696 'warehouse_to' => { 'text' => $locale->text('Warehouse To'), },
697 'bin_from' => { 'text' => $locale->text('Bin From'), },
698 'bin_to' => { 'text' => $locale->text('Bin To'), },
699 'partnumber' => { 'text' => $locale->text('Part Number'), },
700 'partdescription' => { 'text' => $locale->text('Part Description'), },
701 'chargenumber' => { 'text' => $locale->text('Charge Number'), },
702 'bestbefore' => { 'text' => $locale->text('Best Before'), },
703 'qty' => { 'text' => $locale->text('Qty'), },
704 'employee' => { 'text' => $locale->text('Employee'), },
705 'projectnumber' => { 'text' => $locale->text('Project Number'), },
706 'oe_id' => { 'text' => $locale->text('Document'), },
709 my $href = build_std_url('action=generate_journal', grep { $form->{$_} } @hidden_variables);
710 map { $column_defs{$_}->{link} = $href . "&sort=${_}&order=" . Q($_ eq $form->{sort} ? 1 - $form->{order} : $form->{order}) } @columns;
712 my %column_alignment = map { $_ => 'right' } qw(qty);
714 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
716 $report->set_columns(%column_defs);
717 $report->set_column_order(@columns);
719 $report->set_export_options('generate_journal', @hidden_variables, qw(sort order));
721 $report->set_sort_indicator($form->{sort}, $form->{order});
723 $report->set_options('output_format' => 'HTML',
724 'title' => $form->{title},
725 'attachment_basename' => strftime($locale->text('warehouse_journal_list') . '_%Y%m%d', localtime time));
726 $report->set_options_from_form();
727 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
729 my $all_units = AM->retrieve_units(\%myconfig, $form);
730 my @contents = WH->get_warehouse_journal(%filter);
732 my %doc_types = ( 'sales_quotation' => { script => 'oe', title => $locale->text('Sales quotation') },
733 'sales_order' => { script => 'oe', title => $locale->text('Sales Order') },
734 'request_quotation' => { script => 'oe', title => $locale->text('Request quotation') },
735 'purchase_order' => { script => 'oe', title => $locale->text('Purchase Order') },
736 'sales_delivery_order' => { script => 'do', title => $locale->text('Sales delivery order') },
737 'purchase_delivery_order' => { script => 'do', title => $locale->text('Purchase delivery order') },
738 'sales_invoice' => { script => 'is', title => $locale->text('Sales Invoice') },
739 'purchase_invoice' => { script => 'ir', title => $locale->text('Purchase Invoice') },
742 foreach my $entry (@contents) {
743 $entry->{qty} = $form->format_amount_units('amount' => $entry->{qty},
744 'part_unit' => $entry->{partunit},
745 'conv_units' => 'convertible');
746 $entry->{trans_type} = $locale->text($entry->{trans_type});
750 foreach my $column (@columns) {
752 'data' => $entry->{$column},
753 'align' => $column_alignment{$column},
757 $row->{trans_type}->{raw_data} = $entry->{trans_type};
759 if ($form->{l_oe_id}) {
760 $row->{oe_id}->{data} = '';
761 my $info = $entry->{oe_id_info};
763 if ($info && $info->{id} && $info->{type} && $doc_types{$info->{type}}) {
764 $row->{oe_id} = { data => $doc_types{ $info->{type} }->{title} . ' ' . $info->{number},
765 link => build_std_url('script=' . $doc_types{ $info->{type} }->{script} . '.pl', 'action=edit', 'id=' . $info->{id}, 'type=' . $info->{type}) };
769 $report->add_data($row);
772 $report->generate_with_headers();
774 $main::lxdebug->leave_sub();
777 # --------------------------------------------------------------------
779 # --------------------------------------------------------------------
782 $main::lxdebug->enter_sub();
784 $main::auth->assert('warehouse_contents | warehouse_management');
786 my $form = $main::form;
787 my %myconfig = %main::myconfig;
788 my $locale = $main::locale;
790 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES',
791 'bins' => 'BINS', });
793 show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} });
795 $form->{jsscript} = 1;
797 $form->{title} = $locale->text("Report about warehouse contents");
800 print $form->parse_html_template("wh/report_filter",
801 { "nextsub" => "generate_report",
802 "WAREHOUSES" => $form->{WAREHOUSES},
803 "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) });
805 $main::lxdebug->leave_sub();
808 sub generate_report {
809 $main::lxdebug->enter_sub();
811 $main::auth->assert('warehouse_contents | warehouse_management');
813 my $form = $main::form;
814 my %myconfig = %main::myconfig;
815 my $locale = $main::locale;
817 $form->{title} = $locale->text("Report about warehouse contents");
818 $form->{sort} ||= 'partnumber';
819 my $sort_col = $form->{sort};
822 my @columns = qw(warehousedescription bindescription partnumber partdescription chargenumber bestbefore qty stock_value);
825 map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id partnumber description chargenumber bestbefore date include_invalid_warehouses);
827 $filter{qty_op} = WH->convert_qty_op($form->{qty_op});
828 if ($filter{qty_op}) {
829 $form->isblank("qty", $locale->text('Quantity missing.'));
830 $form->isblank("qty_unit", $locale->text('Unit missing.'));
832 $filter{qty} = $form->{qty};
833 $filter{qty_unit} = $form->{qty_unit};
837 $form->{subtotal} = '' if (!first { $_ eq $sort_col } qw(partnumber partdescription));
839 my $report = SL::ReportGenerator->new(\%myconfig, $form);
841 my @hidden_variables = map { "l_${_}" } @columns;
842 push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber bestbefore qty_op qty qty_unit l_warehousedescription l_bindescription);
843 push @hidden_variables, qw(include_empty_bins subtotal include_invalid_warehouses);
846 'warehousedescription' => { 'text' => $locale->text('Warehouse'), },
847 'bindescription' => { 'text' => $locale->text('Bin'), },
848 'partnumber' => { 'text' => $locale->text('Part Number'), },
849 'partdescription' => { 'text' => $locale->text('Part Description'), },
850 'chargenumber' => { 'text' => $locale->text('Charge Number'), },
851 'bestbefore' => { 'text' => $locale->text('Best Before'), },
852 'qty' => { 'text' => $locale->text('Qty'), },
853 'stock_value' => { 'text' => $locale->text('Stock value'), },
856 my $href = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
857 map { $column_defs{$_}->{link} = $href . "&sort=${_}&order=" . Q($_ eq $sort_col ? 1 - $form->{order} : $form->{order}) } @columns;
859 my %column_alignment = map { $_ => 'right' } qw(qty stock_value);
861 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
863 $report->set_columns(%column_defs);
864 $report->set_column_order(@columns);
866 $report->set_export_options('generate_report', @hidden_variables, qw(sort order));
868 $report->set_sort_indicator($sort_col, $form->{order});
870 $report->set_options('output_format' => 'HTML',
871 'title' => $form->{title},
872 'attachment_basename' => strftime($locale->text('warehouse_report_list') . '_%Y%m%d', localtime time));
873 $report->set_options_from_form();
874 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
876 my $all_units = AM->retrieve_units(\%myconfig, $form);
877 my @contents = WH->get_warehouse_report(%filter);
881 my @subtotals_columns = qw(qty stock_value);
882 my %subtotals = map { $_ => 0 } @subtotals_columns;
884 my $total_stock_value = 0;
886 foreach my $entry (@contents) {
887 map { $subtotals{$_} += $entry->{$_} } @subtotals_columns;
888 $total_stock_value += $entry->{stock_value} * 1;
890 $entry->{qty} = $form->format_amount_units('amount' => $entry->{qty},
891 'part_unit' => $entry->{partunit},
892 'conv_units' => 'convertible');
893 $entry->{stock_value} = $form->format_amount(\%myconfig, $entry->{stock_value} * 1, 2);
895 my $row_set = [ { map { $_ => { 'data' => $entry->{$_}, 'align' => $column_alignment{$_} } } @columns } ];
897 if ( ($form->{subtotal} eq 'Y' && !$form->{report_generator_csv_options_for_import} )
898 && (($idx == (scalar @contents - 1))
899 || ($entry->{$sort_col} ne $contents[$idx + 1]->{$sort_col}))) {
901 my $row = { map { $_ => { 'data' => '', 'class' => 'listsubtotal', 'align' => $column_alignment{$_}, } } @columns };
902 $row->{qty}->{data} = $form->format_amount_units('amount' => $subtotals{qty} * 1,
903 'part_unit' => $entry->{partunit},
904 'conv_units' => 'convertible');
905 $row->{stock_value}->{data} = $form->format_amount(\%myconfig, $subtotals{stock_value} * 1, 2);
907 %subtotals = map { $_ => 0 } @subtotals_columns;
909 push @{ $row_set }, $row;
912 $report->add_data($row_set);
917 if ( $column_defs{stock_value}->{visible} && !$form->{report_generator_csv_options_for_import} ) {
918 $report->add_separator();
920 my $row = { map { $_ => { 'data' => '', 'class' => 'listsubtotal', } } @columns };
922 my $left_col = first { $column_defs{$_}->{visible} } @columns;
924 $row->{$left_col}->{data} = $locale->text('Total stock value');
925 $row->{stock_value}->{data} = $form->format_amount(\%myconfig, $total_stock_value, 2);
926 $row->{stock_value}->{align} = 'right';
928 $report->add_data($row);
931 $report->generate_with_headers();
933 $main::lxdebug->leave_sub();
936 # --------------------------------------------------------------------
938 # --------------------------------------------------------------------
940 sub show_no_warehouses_error {
941 $main::lxdebug->enter_sub();
943 my $form = $main::form;
944 my %myconfig = %main::myconfig;
945 my $locale = $main::locale;
947 my $msg = $locale->text('No warehouse has been created yet or the quantity of the bins is not configured yet.') . ' ';
949 if ($main::auth->check_right($form->{login}, 'config')) {
950 $msg .= $locale->text('You can create warehouses and bins via the menu "System -> Warehouses".');
952 $msg .= $locale->text('Please ask your administrator to create warehouses and bins.');
955 $form->show_generic_error($msg);
957 $main::lxdebug->leave_sub();
960 sub get_warehouse_idx {
961 my ($warehouse_id) = @_;
963 my $form = $main::form;
965 for (my $i = 0; $i < scalar @{$form->{WAREHOUSES}}; $i++) {
966 return $i if ($form->{WAREHOUSES}->[$i]->{id} == $warehouse_id);
973 my ($warehouse_index, $bin_id) = @_;
975 my $form = $main::form;
977 my $warehouse = $form->{WAREHOUSES}->[$warehouse_index];
979 return -1 if (!$warehouse);
981 for (my $i = 0; $i < scalar @{ $warehouse->{BINS} }; $i++) {
982 return $i if ($warehouse->{BINS}->[$i]->{id} == $bin_id);
989 $main::lxdebug->enter_sub();
992 my $form = $main::form;
995 $form->{old_callback} = $form->escape($form->{callback}, 1);
996 $form->{callback} = $form->escape("$form->{script}?action=$params{action}", 1);
998 # save all form variables except action in a previousform variable
999 my $previousform = join '&', map { my $value = $form->{$_}; $value =~ s/&/%26/; "$_=$value" } grep { !/action/ } keys %$form;
1002 # push @HIDDENS, { 'name' => 'previousform', 'value' => $form->escape($previousform, 1) };
1003 push @HIDDENS, map +{ 'name' => $_, 'value' => $form->{$_} }, qw(partnumber description unit vc sellprice ean);
1004 push @HIDDENS, { 'name' => 'taxaccount2', 'value' => $form->{taxaccounts} };
1005 push @HIDDENS, { 'name' => 'notes', 'value' => $form->{longdescription} };
1008 print $form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } );
1010 $main::lxdebug->leave_sub();
1014 my $form = $main::form;
1015 call_sub($form->{update_nextsub} || $form->{nextsub});
1019 my $form = $main::form;
1020 call_sub($form->{continue_nextsub} || $form->{nextsub});
1024 my $form = $main::form;
1025 call_sub($form->{stock_nextsub} || $form->{nextsub});
1034 bin/mozilla/wh.pl - Warehouse frontend.
1042 call new item dialogue from warehouse masks.
1045 action => name of sub to be called when new item is done