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 $form->{UNITS} = AM->unit_select_data($units, $form->{unit}, 0, $form->{partunit});
90 if (scalar @{ $form->{WAREHOUSES} }) {
91 $form->{warehouse_id} ||= $form->{WAREHOUSES}->[0]->{id};
92 $form->{bin_id} ||= $form->{WAREHOUSES}->[0]->{BINS}->[0]->{id};
97 $form->{jsscript} = 1;
99 if ($form->{trans_type} eq 'removal') {
100 $form->{nextsub} = "removal_parts_selection";
101 $form->{title} = $locale->text('Removal from Warehouse');
102 $content = $form->parse_html_template('wh/warehouse_selection');
104 } elsif ($form->{trans_type} eq 'stock') {
105 $form->{title} = $locale->text('Stock');
106 $content = $form->parse_html_template('wh/warehouse_selection_stock');
108 } elsif (!$form->{trans_type} || ($form->{trans_type} eq 'transfer')) {
109 $form->{nextsub} = "transfer_parts_selection";
110 $form->{title} = $locale->text('Transfer');
111 $content = $form->parse_html_template('wh/warehouse_selection');
113 } elsif ($form->{trans_type} eq 'assembly') {
114 $form->{title} = $locale->text('Produce Assembly');
115 $content = $form->parse_html_template('wh/warehouse_selection_assembly');
121 $main::lxdebug->leave_sub();
124 sub transfer_parts_selection {
125 $main::lxdebug->enter_sub();
127 $main::auth->assert('warehouse_management');
129 my $form = $main::form;
130 my %myconfig = %main::myconfig;
131 my $locale = $main::locale;
133 transfer_or_removal_prepare_contents('direction' => 'transfer');
135 $form->{title} = $locale->text('Transfer');
137 print $form->parse_html_template("wh/transfer_parts_selection");
139 $main::lxdebug->leave_sub();
142 sub transfer_or_removal_prepare_contents {
143 $main::lxdebug->enter_sub();
145 $main::auth->assert('warehouse_management');
149 my $form = $main::form;
150 my %myconfig = %main::myconfig;
151 my $locale = $main::locale;
153 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES',
154 'bins' => 'BINS', });
156 my $warehouse_idx = get_warehouse_idx($form->{warehouse_id});
157 $form->show_generic_error($locale->text("The selected warehouse does not exist.")) if (-1 == $warehouse_idx);
159 my $warehouse = $form->{WAREHOUSES}->[$warehouse_idx];
161 $form->{initial_warehouse_idx} = $warehouse_idx;
162 $form->{warehouse_description} = $warehouse->{description};
163 $warehouse->{selected} = 1;
165 $form->show_generic_error($locale->text("The source warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} });
167 map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit ean);
169 $form->{sort} = 'bindescription';
170 my @contents = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id},
171 "bin_id" => $form->{bin_id},
172 "chargenumber" => $form->{chargenumber},
173 "bestbefore" => $form->{bestbefore},
174 "partnumber" => $form->{partnumber},
175 "ean" => $form->{ean},
176 "description" => $form->{description});
178 $form->show_generic_error($locale->text("The selected warehouse is empty.")) if (0 == scalar(@contents));
180 my $all_units = AM->retrieve_units(\%myconfig, $form);
182 foreach (@contents) {
183 $_->{qty} = $form->format_amount_units('amount' => $_->{qty},
184 'part_unit' => $_->{partunit},
185 'conv_units' => 'convertible');
186 my $this_unit = $_->{partunit};
188 if ($all_units->{$_->{partunit}} && ($all_units->{g}->{base_unit} eq $all_units->{$_->{partunit}}->{base_unit})) {
192 $_->{UNITS} = AM->unit_select_data($all_units, $this_unit, 0, $_->{partunit});
195 my $transfer_types = WH->retrieve_transfer_types($args{direction});
196 map { $_->{description} = $locale->text($_->{description}) } @{ $transfer_types };
198 $form->{CONTENTS} = \@contents;
199 $form->{TRANSFER_TYPES} = $transfer_types;
201 $main::lxdebug->leave_sub();
206 $main::lxdebug->enter_sub();
208 $main::auth->assert('warehouse_management');
210 my $form = $main::form;
211 my %myconfig = %main::myconfig;
212 my $locale = $main::locale;
214 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', 'bins' => 'BINS' });
216 my $warehouse_idx = get_warehouse_idx($form->{warehouse_id});
217 $form->show_generic_error($locale->text("The selected warehouse does not exist.")) if (-1 == $warehouse_idx);
219 my $warehouse = $form->{WAREHOUSES}->[$warehouse_idx];
221 $form->show_generic_error($locale->text("The source warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} });
223 map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit);
225 $form->{sort} = 'bindescription';
226 my @contents = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id});
227 my $all_units = AM->retrieve_units(\%myconfig, $form);
231 foreach my $row (1 .. $form->{rowcount}) {
232 $form->{"qty_$row"} =~ s/^\s*//;
233 $form->{"qty_$row"} =~ s/\s*$//;
234 next if (!$form->{"qty_$row"});
236 my $bin_idx = get_bin_idx($warehouse_idx, $form->{"src_bin_id_$row"});
237 $form->show_generic_error($locale->text("The selected bin does not exist.")) if (-1 == $bin_idx);
238 my $bin = $warehouse->{BINS}->[$bin_idx];
240 my $orig_qty = $form->{"qty_$row"} . " " . $form->{"unit_$row"};
243 'src_warehouse_id' => $form->{warehouse_id},
244 'transfer_type_id' => $form->{transfer_type_id},
247 map { $transfer->{$_} = $form->{"${_}_${row}"} } qw(src_bin_id chargenumber bestbefore parts_id qty dst_warehouse_id dst_bin_id);
251 foreach (@contents) {
252 if (($_->{binid} == $transfer->{src_bin_id}) && ($_->{parts_id} == $transfer->{parts_id}) && ($_->{chargenumber} eq $transfer->{chargenumber}) && $_->{bestbefore} eq $transfer->{bestbefore}) {
259 $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
260 $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
263 $transfer->{qty} = $form->parse_amount(\%myconfig, $transfer->{qty}) * $all_units->{$form->{"unit_$row"}}->{factor};
264 $transfer->{qty} /= $all_units->{$entry->{partunit}}->{factor} || 1;
266 if (($entry->{qty} < $transfer->{qty}) || (0 >= $transfer->{qty})) {
267 $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
268 $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
271 $transfer->{comment} = $form->{comment};
273 push @transfers, $transfer;
275 $entry->{qty} -= $transfer->{qty};
278 if (!scalar @transfers) {
279 $form->show_generic_information($locale->text('Nothing has been selected for transfer.'));
283 WH->transfer(@transfers);
285 $form->{trans_type} = 'transfer';
286 $form->{saved_message} = $locale->text('The parts have been transferred.');
288 transfer_warehouse_selection();
290 $main::lxdebug->leave_sub();
293 # --------------------------------------------------------------------
295 # --------------------------------------------------------------------
297 sub transfer_stock_update_part {
298 $main::lxdebug->enter_sub();
300 my $form = $main::form;
301 my %myconfig = %main::myconfig;
302 my $locale = $main::locale;
304 $form->{trans_type} = 'stock';
305 $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
307 if (!$form->{partnumber} && !$form->{description} && !$form->{ean}) {
308 delete @{$form}{qw(parts_id partunit ean)};
309 transfer_warehouse_selection();
311 } elsif (($form->{partnumber} && ($form->{partnumber} ne $form->{old_partnumber})) || $form->{description} || $form->{ean}) {
313 $form->{no_services} = 1;
314 $form->{no_assemblies} = 0; # assemblies duerfen eingelagert werden (z.B. bei retouren)
316 my $parts = Common->retrieve_parts(\%myconfig, $form, 'description', 1);
318 if (!scalar @{ $parts }) {
319 new_item(action => "transfer_stock_update_part");
320 } elsif (scalar @{ $parts } == 1) {
321 @{$form}{qw(parts_id partnumber description ean)} = @{$parts->[0]}{qw(id partnumber description ean)};
322 transfer_stock_get_partunit();
323 transfer_warehouse_selection();
326 select_part('transfer_stock_part_selected', @{ $parts });
330 transfer_stock_get_partunit();
331 transfer_warehouse_selection();
334 $main::lxdebug->leave_sub();
337 # --------------------------------------------------------------------
338 # Transfer: assemblies
339 # Dies ist die Auswahlmaske für ein assembly.
340 # Die ist einfach von transfer_assembly_update_part kopiert und nur um den trans_type (assembly) korrigiert worden
341 # Es wäre schön, hier nochmal check_assembly_max_create auf, um die max. Fertigungszahl herauszufinden.
342 # Ich lass das mal als auskommentierte Idee bestehen jb 18.3.09
343 # --------------------------------------------------------------------
345 sub transfer_assembly_update_part {
346 $main::lxdebug->enter_sub();
348 my $form = $main::form;
349 my %myconfig = %main::myconfig;
350 my $locale = $main::locale;
352 $form->{trans_type} = 'assembly';
353 $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
355 if (!$form->{partnumber} && !$form->{description}) {
356 delete @{$form}{qw(parts_id partunit)};
357 transfer_warehouse_selection();
359 } elsif (($form->{partnumber} && ($form->{partnumber} ne $form->{old_partnumber})) || $form->{description}) {
360 $form->{assemblies} = 1;
361 $form->{no_assemblies} = 0;
362 my $parts = Common->retrieve_parts(\%myconfig, $form, 'description', 1);
363 if (scalar @{ $parts } == 1) {
364 @{$form}{qw(parts_id partnumber description)} = @{$parts->[0]}{qw(id partnumber description)};
365 transfer_stock_get_partunit();
366 transfer_warehouse_selection();
368 select_part('transfer_stock_part_selected', @{ $parts });
372 transfer_stock_get_partunit();
373 transfer_warehouse_selection();
376 # hier die oben benannte idee
377 # my $maxcreate = Common->check_assembly_max_create(assembly_id => $form->{parts_id}, dbh => $my_dbh);
378 $main::lxdebug->leave_sub();
381 sub transfer_stock_part_selected {
382 $main::lxdebug->enter_sub();
386 my $form = $main::form;
388 @{$form}{qw(parts_id partnumber description ean)} = @{$part}{qw(id partnumber description ean)};
390 transfer_stock_get_partunit();
391 transfer_warehouse_selection();
393 $main::lxdebug->leave_sub();
396 sub transfer_stock_get_partunit {
397 $main::lxdebug->enter_sub();
399 my $form = $main::form;
401 if ($form->{parts_id}) {
402 my $part_info = IC->get_basic_part_info('id' => $form->{parts_id});
403 $form->{partunit} = $part_info->{unit};
406 $main::lxdebug->leave_sub();
409 # vorüberlegung jb 22.2.2009
410 # wir benötigen für diese funktion, die anzahl die vom erzeugnis hergestellt werden soll. vielleicht direkt per js fehleingaben verhindern?
411 # ferner dann nochmal mit check_asssembly_max_create gegenprüfen und dann transaktionssicher wegbuchen.
412 # 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
413 # Manko ist derzeit noch, dass unterschiedliche Lagerplätze, bzw. das Quelllager an sich nicht ausgewählt werden können.
414 # Laut Absprache in KW11 09 übernimmt mb hier den rest im April ... jb 18.3.09
416 sub create_assembly {
417 $main::lxdebug->enter_sub();
419 my $form = $main::form;
420 my %myconfig = %main::myconfig;
421 my $locale = $main::locale;
423 $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
424 if ($form->{qty} <= 0) {
425 $form->show_generic_error($locale->text('Invalid quantity.'), 'back_button' => 1);
427 # TODO Es wäre schön, hier schon die maximale Anzahl der zu fertigenden Erzeugnisse zu haben
428 #else { if ($form->{qty} > $maxcreate) { #s.o.
429 # $form->show_generic_error($locale->text('Can not create that quantity with current stock'), 'back_button' => 1);
430 # $form->show_generic_error('Maximale Stückzahl' . $maxcreate , 'back_button' => 1);
434 if (!$form->{warehouse_id} || !$form->{bin_id}) {
435 $form->error($locale->text('The warehouse or the bin is missing.'));
438 if (!$main::show_best_before) {
439 $form->{bestbefore} = '';
442 # 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
443 # Anm. jb 18.3. vielleicht auch nur meine unwissenheit in perl-datenstrukturen
445 'transfer_type' => 'assembly',
446 'login' => $form->{login},
447 'dst_warehouse_id' => $form->{warehouse_id},
448 'dst_bin_id' => $form->{bin_id},
449 'chargenumber' => $form->{chargenumber},
450 'bestbefore' => $form->{bestbefore},
451 'assembly_id' => $form->{parts_id},
452 'qty' => $form->{qty},
453 'unit' => $form->{unit},
454 'comment' => $form->{comment}
457 my $ret = WH->transfer_assembly (%TRANSFER);
458 # Frage: Ich pack in den return-wert auch gleich die Fehlermeldung. Irgendwelche Nummern als Fehlerkonstanten definieren find ich auch nicht besonders schick...
461 # 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
462 $form->show_generic_error($ret, 'back_button' => 1);
465 delete @{$form}{qw(parts_id partnumber description qty unit chargenumber bestbefore comment)};
467 $form->{saved_message} = $locale->text('The assembly has been created.');
468 $form->{trans_type} = 'assembly';
470 transfer_warehouse_selection();
472 $main::lxdebug->leave_sub();
476 $main::lxdebug->enter_sub();
478 my $form = $main::form;
479 my %myconfig = %main::myconfig;
480 my $locale = $main::locale;
482 $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
484 if ($form->{qty} <= 0) {
485 $form->show_generic_error($locale->text('Invalid quantity.'), 'back_button' => 1);
488 if (!$form->{warehouse_id} || !$form->{bin_id}) {
489 $form->error($locale->text('The warehouse or the bin is missing.'));
493 'transfer_type' => 'stock',
494 'dst_warehouse_id' => $form->{warehouse_id},
495 'dst_bin_id' => $form->{bin_id},
496 'chargenumber' => $form->{chargenumber},
497 'bestbefore' => $form->{bestbefore},
498 'parts_id' => $form->{parts_id},
499 'qty' => $form->{qty},
500 'unit' => $form->{unit},
501 'comment' => $form->{comment},
504 WH->transfer($transfer);
506 delete @{$form}{qw(parts_id partnumber description qty unit chargenumber bestbefore comment ean)};
508 $form->{saved_message} = $locale->text('The parts have been stocked.');
509 $form->{trans_type} = 'stock';
511 transfer_warehouse_selection();
513 $main::lxdebug->leave_sub();
516 # --------------------------------------------------------------------
518 # --------------------------------------------------------------------
520 sub removal_parts_selection {
521 $main::lxdebug->enter_sub();
523 $main::auth->assert('warehouse_management');
525 my $form = $main::form;
526 my %myconfig = %main::myconfig;
527 my $locale = $main::locale;
529 transfer_or_removal_prepare_contents('direction' => 'out');
531 $form->{title} = $locale->text('Removal');
533 print $form->parse_html_template("wh/removal_parts_selection");
535 $main::lxdebug->leave_sub();
539 $main::lxdebug->enter_sub();
541 $main::auth->assert('warehouse_management');
543 my $form = $main::form;
544 my %myconfig = %main::myconfig;
545 my $locale = $main::locale;
547 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES',
548 'bins' => 'BINS', });
550 my $warehouse_idx = get_warehouse_idx($form->{warehouse_id});
551 $form->show_generic_error($locale->text("The selected warehouse does not exist.")) if (-1 == $warehouse_idx);
553 my $warehouse = $form->{WAREHOUSES}->[$warehouse_idx];
555 $form->show_generic_error($locale->text("The warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} });
557 map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit);
559 $form->{sort} = 'bindescription';
560 my @contents = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id});
561 my $all_units = AM->retrieve_units(\%myconfig, $form);
565 foreach my $row (1 .. $form->{rowcount}) {
566 $form->{"qty_$row"} =~ s/^\s*//;
567 $form->{"qty_$row"} =~ s/\s*$//;
568 next if (!$form->{"qty_$row"});
570 my $bin_idx = get_bin_idx($warehouse_idx, $form->{"src_bin_id_$row"});
571 $form->show_generic_error($locale->text("The selected bin does not exist.")) if (-1 == $bin_idx);
572 my $bin = $warehouse->{BINS}->[$bin_idx];
574 my $orig_qty = $form->{"qty_$row"} . " " . $form->{"unit_$row"};
577 'src_warehouse_id' => $form->{warehouse_id},
578 'transfer_type_id' => $form->{transfer_type_id},
581 map { $transfer->{$_} = $form->{"${_}_${row}"} } qw(src_bin_id chargenumber bestbefore parts_id qty);
585 foreach (@contents) {
586 if (($_->{binid} == $transfer->{src_bin_id}) && ($_->{parts_id} == $transfer->{parts_id}) && ($_->{chargenumber} eq $transfer->{chargenumber}) && ($_->{bestbefore} eq $transfer->{bestbefore})) {
593 $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
594 $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
597 $transfer->{qty} = $form->parse_amount(\%myconfig, $transfer->{qty}) * $all_units->{$form->{"unit_$row"}}->{factor};
598 $transfer->{qty} /= $all_units->{$entry->{partunit}}->{factor} || 1;
600 if (($entry->{qty} < $transfer->{qty}) || (0 >= $transfer->{qty})) {
601 $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
602 $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
605 $transfer->{comment} = $form->{comment};
607 push @transfers, $transfer;
609 $entry->{qty} -= $transfer->{qty};
612 if (!scalar @transfers) {
613 $form->show_generic_information($locale->text('Nothing has been selected for removal.'));
617 WH->transfer(@transfers);
619 $form->{trans_type} = 'removal';
620 $form->{saved_message} = $locale->text('The parts have been removed.');
622 transfer_warehouse_selection();
624 $main::lxdebug->leave_sub();
627 # --------------------------------------------------------------------
629 # --------------------------------------------------------------------
632 $main::lxdebug->enter_sub();
634 $main::auth->assert('warehouse_management');
636 my $form = $main::form;
637 my %myconfig = %main::myconfig;
638 my $locale = $main::locale;
640 $form->{title} = $locale->text('Report about warehouse transactions');
641 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES',
642 'bins' => 'BINS', });
644 show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} });
646 $form->{jsscript} = 1;
649 print $form->parse_html_template("wh/journal_filter", { "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) });
651 $main::lxdebug->leave_sub();
654 sub generate_journal {
655 $main::lxdebug->enter_sub();
657 $main::auth->assert('warehouse_management');
659 my $form = $main::form;
660 my %myconfig = %main::myconfig;
661 my $locale = $main::locale;
663 $form->{title} = $locale->text("WHJournal");
664 $form->{sort} ||= 'date';
667 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);
670 map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id partnumber description chargenumber bestbefore);
672 $filter{qty_op} = WH->convert_qty_op($form->{qty_op});
673 if ($filter{qty_op}) {
674 $form->isblank("qty", $locale->text('Quantity missing.'));
675 $form->isblank("qty_unit", $locale->text('Unit missing.'));
677 $filter{qty} = $form->{qty};
678 $filter{qty_unit} = $form->{qty_unit};
682 my $report = SL::ReportGenerator->new(\%myconfig, $form);
684 my @hidden_variables = map { "l_${_}" } @columns;
685 push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber bestbefore qty_op qty qty_unit fromdate todate);
688 'date' => { 'text' => $locale->text('Date'), },
689 'trans_id' => { 'text' => $locale->text('Trans Id'), },
690 'trans_type' => { 'text' => $locale->text('Trans Type'), },
691 'comment' => { 'text' => $locale->text('Comment'), },
692 'warehouse_from' => { 'text' => $locale->text('Warehouse From'), },
693 'warehouse_to' => { 'text' => $locale->text('Warehouse To'), },
694 'bin_from' => { 'text' => $locale->text('Bin From'), },
695 'bin_to' => { 'text' => $locale->text('Bin To'), },
696 'partnumber' => { 'text' => $locale->text('Part Number'), },
697 'partdescription' => { 'text' => $locale->text('Part Description'), },
698 'chargenumber' => { 'text' => $locale->text('Charge Number'), },
699 'bestbefore' => { 'text' => $locale->text('Best Before'), },
700 'qty' => { 'text' => $locale->text('Qty'), },
701 'employee' => { 'text' => $locale->text('Employee'), },
702 'projectnumber' => { 'text' => $locale->text('Project Number'), },
703 'oe_id' => { 'text' => $locale->text('Document'), },
706 my $href = build_std_url('action=generate_journal', grep { $form->{$_} } @hidden_variables);
707 map { $column_defs{$_}->{link} = $href . "&sort=${_}&order=" . Q($_ eq $form->{sort} ? 1 - $form->{order} : $form->{order}) } @columns;
709 my %column_alignment = map { $_ => 'right' } qw(qty);
711 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
713 $report->set_columns(%column_defs);
714 $report->set_column_order(@columns);
716 $report->set_export_options('generate_journal', @hidden_variables, qw(sort order));
718 $report->set_sort_indicator($form->{sort}, $form->{order});
720 $report->set_options('output_format' => 'HTML',
721 'title' => $form->{title},
722 'attachment_basename' => strftime($locale->text('warehouse_journal_list') . '_%Y%m%d', localtime time));
723 $report->set_options_from_form();
725 my $all_units = AM->retrieve_units(\%myconfig, $form);
726 my @contents = WH->get_warehouse_journal(%filter);
728 my %doc_types = ( 'sales_quotation' => { script => 'oe', title => $locale->text('Sales quotation') },
729 'sales_order' => { script => 'oe', title => $locale->text('Sales Order') },
730 'request_quotation' => { script => 'oe', title => $locale->text('Request quotation') },
731 'purchase_order' => { script => 'oe', title => $locale->text('Purchase Order') },
732 'sales_delivery_order' => { script => 'do', title => $locale->text('Sales delivery order') },
733 'purchase_delivery_order' => { script => 'do', title => $locale->text('Purchase delivery order') },
734 'sales_invoice' => { script => 'is', title => $locale->text('Sales Invoice') },
735 'purchase_invoice' => { script => 'ir', title => $locale->text('Purchase Invoice') },
738 foreach my $entry (@contents) {
739 $entry->{qty} = $form->format_amount_units('amount' => $entry->{qty},
740 'part_unit' => $entry->{partunit},
741 'conv_units' => 'convertible');
742 $entry->{trans_type} = $locale->text($entry->{trans_type});
746 foreach my $column (@columns) {
748 'data' => $entry->{$column},
749 'align' => $column_alignment{$column},
753 $row->{trans_type}->{raw_data} = $entry->{trans_type};
755 if ($form->{l_oe_id}) {
756 $row->{oe_id}->{data} = '';
757 my $info = $entry->{oe_id_info};
759 if ($info && $info->{id} && $info->{type} && $doc_types{$info->{type}}) {
760 $row->{oe_id} = { data => $doc_types{ $info->{type} }->{title} . ' ' . $info->{number},
761 link => build_std_url('script=' . $doc_types{ $info->{type} }->{script} . '.pl', 'action=edit', 'id=' . $info->{id}, 'type=' . $info->{type}) };
765 $report->add_data($row);
768 $report->generate_with_headers();
770 $main::lxdebug->leave_sub();
773 # --------------------------------------------------------------------
775 # --------------------------------------------------------------------
778 $main::lxdebug->enter_sub();
780 $main::auth->assert('warehouse_contents | warehouse_management');
782 my $form = $main::form;
783 my %myconfig = %main::myconfig;
784 my $locale = $main::locale;
786 $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES',
787 'bins' => 'BINS', });
789 show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} });
791 $form->{jsscript} = 1;
793 # $form->{fokus} = "partnumber";
794 # $form->{onload} .= "focus();";
795 $form->{title} = $locale->text("Report about warehouse contents");
798 print $form->parse_html_template("wh/report_filter",
799 { "nextsub" => "generate_report",
800 "WAREHOUSES" => $form->{WAREHOUSES},
801 "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) });
803 $main::lxdebug->leave_sub();
806 sub generate_report {
807 $main::lxdebug->enter_sub();
809 $main::auth->assert('warehouse_contents | warehouse_management');
811 my $form = $main::form;
812 my %myconfig = %main::myconfig;
813 my $locale = $main::locale;
815 $form->{title} = $locale->text("Report about warehouse contents");
816 $form->{sort} ||= 'partnumber';
817 my $sort_col = $form->{sort};
820 my @columns = qw(warehousedescription bindescription partnumber partdescription chargenumber bestbefore qty stock_value);
823 map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id partnumber description chargenumber bestbefore);
825 $filter{qty_op} = WH->convert_qty_op($form->{qty_op});
826 if ($filter{qty_op}) {
827 $form->isblank("qty", $locale->text('Quantity missing.'));
828 $form->isblank("qty_unit", $locale->text('Unit missing.'));
830 $filter{qty} = $form->{qty};
831 $filter{qty_unit} = $form->{qty_unit};
835 $form->{subtotal} = '' if (!first { $_ eq $sort_col } qw(partnumber partdescription));
837 my $report = SL::ReportGenerator->new(\%myconfig, $form);
839 my @hidden_variables = map { "l_${_}" } @columns;
840 push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber bestbefore qty_op qty qty_unit l_warehousedescription l_bindescription);
841 push @hidden_variables, qw(include_empty_bins subtotal);
844 'warehousedescription' => { 'text' => $locale->text('Warehouse'), },
845 'bindescription' => { 'text' => $locale->text('Bin'), },
846 'partnumber' => { 'text' => $locale->text('Part Number'), },
847 'partdescription' => { 'text' => $locale->text('Part Description'), },
848 'chargenumber' => { 'text' => $locale->text('Charge Number'), },
849 'bestbefore' => { 'text' => $locale->text('Best Before'), },
850 'qty' => { 'text' => $locale->text('Qty'), },
851 'stock_value' => { 'text' => $locale->text('Stock value'), },
854 my $href = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
855 map { $column_defs{$_}->{link} = $href . "&sort=${_}&order=" . Q($_ eq $sort_col ? 1 - $form->{order} : $form->{order}) } @columns;
857 my %column_alignment = map { $_ => 'right' } qw(qty stock_value);
859 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
861 $report->set_columns(%column_defs);
862 $report->set_column_order(@columns);
864 $report->set_export_options('generate_report', @hidden_variables, qw(sort order));
866 $report->set_sort_indicator($sort_col, $form->{order});
868 $report->set_options('output_format' => 'HTML',
869 'title' => $form->{title},
870 'attachment_basename' => strftime($locale->text('warehouse_report_list') . '_%Y%m%d', localtime time));
871 $report->set_options_from_form();
873 my $all_units = AM->retrieve_units(\%myconfig, $form);
874 my @contents = WH->get_warehouse_report(%filter);
878 my @subtotals_columns = qw(qty stock_value);
879 my %subtotals = map { $_ => 0 } @subtotals_columns;
881 my $total_stock_value = 0;
883 foreach my $entry (@contents) {
884 map { $subtotals{$_} += $entry->{$_} } @subtotals_columns;
885 $total_stock_value += $entry->{stock_value} * 1;
887 $entry->{qty} = $form->format_amount_units('amount' => $entry->{qty},
888 'part_unit' => $entry->{partunit},
889 'conv_units' => 'convertible');
890 $entry->{stock_value} = $form->format_amount(\%myconfig, $entry->{stock_value} * 1, 2);
892 my $row_set = [ { map { $_ => { 'data' => $entry->{$_}, 'align' => $column_alignment{$_} } } @columns } ];
894 if (($form->{subtotal} eq 'Y')
895 && (($idx == (scalar @contents - 1))
896 || ($entry->{$sort_col} ne $contents[$idx + 1]->{$sort_col}))) {
898 my $row = { map { $_ => { 'data' => '', 'class' => 'listsubtotal', 'align' => $column_alignment{$_}, } } @columns };
899 $row->{qty}->{data} = $form->format_amount_units('amount' => $subtotals{qty} * 1,
900 'part_unit' => $entry->{partunit},
901 'conv_units' => 'convertible');
902 $row->{stock_value}->{data} = $form->format_amount(\%myconfig, $subtotals{stock_value} * 1, 2);
904 %subtotals = map { $_ => 0 } @subtotals_columns;
906 push @{ $row_set }, $row;
909 $report->add_data($row_set);
914 if ($column_defs{stock_value}->{visible}) {
915 $report->add_separator();
917 my $row = { map { $_ => { 'data' => '', 'class' => 'listsubtotal', } } @columns };
919 my $left_col = first { $column_defs{$_}->{visible} } @columns;
921 $row->{$left_col}->{data} = $locale->text('Total stock value');
922 $row->{stock_value}->{data} = $form->format_amount(\%myconfig, $total_stock_value, 2);
923 $row->{stock_value}->{align} = 'right';
925 $report->add_data($row);
928 $report->generate_with_headers();
930 $main::lxdebug->leave_sub();
933 # --------------------------------------------------------------------
935 # --------------------------------------------------------------------
937 sub show_no_warehouses_error {
938 $main::lxdebug->enter_sub();
940 my $form = $main::form;
941 my %myconfig = %main::myconfig;
942 my $locale = $main::locale;
944 my $msg = $locale->text('No warehouse has been created yet or the quantity of the bins is not configured yet.') . ' ';
946 if ($main::auth->check_right($form->{login}, 'config')) {
947 $msg .= $locale->text('You can create warehouses and bins via the menu "System -> Warehouses".');
949 $msg .= $locale->text('Please ask your administrator to create warehouses and bins.');
952 $form->show_generic_error($msg);
954 $main::lxdebug->leave_sub();
957 sub get_warehouse_idx {
958 my ($warehouse_id) = @_;
960 my $form = $main::form;
962 for (my $i = 0; $i < scalar @{$form->{WAREHOUSES}}; $i++) {
963 return $i if ($form->{WAREHOUSES}->[$i]->{id} == $warehouse_id);
970 my ($warehouse_index, $bin_id) = @_;
972 my $form = $main::form;
974 my $warehouse = $form->{WAREHOUSES}->[$warehouse_index];
976 return -1 if (!$warehouse);
978 for (my $i = 0; $i < scalar @{ $warehouse->{BINS} }; $i++) {
979 return $i if ($warehouse->{BINS}->[$i]->{id} == $bin_id);
986 $main::lxdebug->enter_sub();
989 my $form = $main::form;
992 $form->{old_callback} = $form->escape($form->{callback}, 1);
993 $form->{callback} = $form->escape("$form->{script}?action=$params{action}", 1);
995 # save all form variables except action in a previousform variable
996 my $previousform = join '&', map { my $value = $form->{$_}; $value =~ s/&/%26/; "$_=$value" } grep { !/action/ } keys %$form;
999 # push @HIDDENS, { 'name' => 'previousform', 'value' => $form->escape($previousform, 1) };
1000 push @HIDDENS, map +{ 'name' => $_, 'value' => $form->{$_} }, qw(partnumber description unit vc sellprice ean);
1001 push @HIDDENS, { 'name' => 'taxaccount2', 'value' => $form->{taxaccounts} };
1002 push @HIDDENS, { 'name' => 'notes', 'value' => $form->{longdescription} };
1005 print $form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } );
1007 $main::lxdebug->leave_sub();
1011 my $form = $main::form;
1012 call_sub($form->{update_nextsub} || $form->{nextsub});
1016 my $form = $main::form;
1017 call_sub($form->{continue_nextsub} || $form->{nextsub});
1021 my $form = $main::form;
1022 call_sub($form->{stock_nextsub} || $form->{nextsub});
1031 bin/mozilla/wh.pl - Warehouse frontend.
1039 call new item dialogue from warehouse masks.
1042 action => name of sub to be called when new item is done