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 (!$::lx_office_conf{features}->{show_best_before}) {
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->{fokus} = "partnumber";
798 $form->{title} = $locale->text("Report about warehouse contents");
801 print $form->parse_html_template("wh/report_filter",
802 { "nextsub" => "generate_report",
803 "WAREHOUSES" => $form->{WAREHOUSES},
804 "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) });
806 $main::lxdebug->leave_sub();
809 sub generate_report {
810 $main::lxdebug->enter_sub();
812 $main::auth->assert('warehouse_contents | warehouse_management');
814 my $form = $main::form;
815 my %myconfig = %main::myconfig;
816 my $locale = $main::locale;
818 $form->{title} = $locale->text("Report about warehouse contents");
819 $form->{sort} ||= 'partnumber';
820 my $sort_col = $form->{sort};
823 my @columns = qw(warehousedescription bindescription partnumber partdescription chargenumber bestbefore qty stock_value);
826 map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id partnumber description chargenumber bestbefore date include_invalid_warehouses);
828 $filter{qty_op} = WH->convert_qty_op($form->{qty_op});
829 if ($filter{qty_op}) {
830 $form->isblank("qty", $locale->text('Quantity missing.'));
831 $form->isblank("qty_unit", $locale->text('Unit missing.'));
833 $filter{qty} = $form->{qty};
834 $filter{qty_unit} = $form->{qty_unit};
838 $form->{subtotal} = '' if (!first { $_ eq $sort_col } qw(partnumber partdescription));
840 my $report = SL::ReportGenerator->new(\%myconfig, $form);
842 my @hidden_variables = map { "l_${_}" } @columns;
843 push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber bestbefore qty_op qty qty_unit l_warehousedescription l_bindescription);
844 push @hidden_variables, qw(include_empty_bins subtotal include_invalid_warehouses);
847 'warehousedescription' => { 'text' => $locale->text('Warehouse'), },
848 'bindescription' => { 'text' => $locale->text('Bin'), },
849 'partnumber' => { 'text' => $locale->text('Part Number'), },
850 'partdescription' => { 'text' => $locale->text('Part Description'), },
851 'chargenumber' => { 'text' => $locale->text('Charge Number'), },
852 'bestbefore' => { 'text' => $locale->text('Best Before'), },
853 'qty' => { 'text' => $locale->text('Qty'), },
854 'stock_value' => { 'text' => $locale->text('Stock value'), },
857 my $href = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
858 map { $column_defs{$_}->{link} = $href . "&sort=${_}&order=" . Q($_ eq $sort_col ? 1 - $form->{order} : $form->{order}) } @columns;
860 my %column_alignment = map { $_ => 'right' } qw(qty stock_value);
862 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
864 $report->set_columns(%column_defs);
865 $report->set_column_order(@columns);
867 $report->set_export_options('generate_report', @hidden_variables, qw(sort order));
869 $report->set_sort_indicator($sort_col, $form->{order});
871 $report->set_options('output_format' => 'HTML',
872 'title' => $form->{title},
873 'attachment_basename' => strftime($locale->text('warehouse_report_list') . '_%Y%m%d', localtime time));
874 $report->set_options_from_form();
875 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
877 my $all_units = AM->retrieve_units(\%myconfig, $form);
878 my @contents = WH->get_warehouse_report(%filter);
882 my @subtotals_columns = qw(qty stock_value);
883 my %subtotals = map { $_ => 0 } @subtotals_columns;
885 my $total_stock_value = 0;
887 foreach my $entry (@contents) {
888 map { $subtotals{$_} += $entry->{$_} } @subtotals_columns;
889 $total_stock_value += $entry->{stock_value} * 1;
891 $entry->{qty} = $form->format_amount_units('amount' => $entry->{qty},
892 'part_unit' => $entry->{partunit},
893 'conv_units' => 'convertible');
894 $entry->{stock_value} = $form->format_amount(\%myconfig, $entry->{stock_value} * 1, 2);
896 my $row_set = [ { map { $_ => { 'data' => $entry->{$_}, 'align' => $column_alignment{$_} } } @columns } ];
898 if ( ($form->{subtotal} eq 'Y' && !$form->{report_generator_csv_options_for_import} )
899 && (($idx == (scalar @contents - 1))
900 || ($entry->{$sort_col} ne $contents[$idx + 1]->{$sort_col}))) {
902 my $row = { map { $_ => { 'data' => '', 'class' => 'listsubtotal', 'align' => $column_alignment{$_}, } } @columns };
903 $row->{qty}->{data} = $form->format_amount_units('amount' => $subtotals{qty} * 1,
904 'part_unit' => $entry->{partunit},
905 'conv_units' => 'convertible');
906 $row->{stock_value}->{data} = $form->format_amount(\%myconfig, $subtotals{stock_value} * 1, 2);
908 %subtotals = map { $_ => 0 } @subtotals_columns;
910 push @{ $row_set }, $row;
913 $report->add_data($row_set);
918 if ( $column_defs{stock_value}->{visible} && !$form->{report_generator_csv_options_for_import} ) {
919 $report->add_separator();
921 my $row = { map { $_ => { 'data' => '', 'class' => 'listsubtotal', } } @columns };
923 my $left_col = first { $column_defs{$_}->{visible} } @columns;
925 $row->{$left_col}->{data} = $locale->text('Total stock value');
926 $row->{stock_value}->{data} = $form->format_amount(\%myconfig, $total_stock_value, 2);
927 $row->{stock_value}->{align} = 'right';
929 $report->add_data($row);
932 $report->generate_with_headers();
934 $main::lxdebug->leave_sub();
937 # --------------------------------------------------------------------
939 # --------------------------------------------------------------------
941 sub show_no_warehouses_error {
942 $main::lxdebug->enter_sub();
944 my $form = $main::form;
945 my %myconfig = %main::myconfig;
946 my $locale = $main::locale;
948 my $msg = $locale->text('No warehouse has been created yet or the quantity of the bins is not configured yet.') . ' ';
950 if ($main::auth->check_right($form->{login}, 'config')) {
951 $msg .= $locale->text('You can create warehouses and bins via the menu "System -> Warehouses".');
953 $msg .= $locale->text('Please ask your administrator to create warehouses and bins.');
956 $form->show_generic_error($msg);
958 $main::lxdebug->leave_sub();
961 sub get_warehouse_idx {
962 my ($warehouse_id) = @_;
964 my $form = $main::form;
966 for (my $i = 0; $i < scalar @{$form->{WAREHOUSES}}; $i++) {
967 return $i if ($form->{WAREHOUSES}->[$i]->{id} == $warehouse_id);
974 my ($warehouse_index, $bin_id) = @_;
976 my $form = $main::form;
978 my $warehouse = $form->{WAREHOUSES}->[$warehouse_index];
980 return -1 if (!$warehouse);
982 for (my $i = 0; $i < scalar @{ $warehouse->{BINS} }; $i++) {
983 return $i if ($warehouse->{BINS}->[$i]->{id} == $bin_id);
990 $main::lxdebug->enter_sub();
993 my $form = $main::form;
996 $form->{old_callback} = $form->escape($form->{callback}, 1);
997 $form->{callback} = $form->escape("$form->{script}?action=$params{action}", 1);
999 # save all form variables except action in a previousform variable
1000 my $previousform = join '&', map { my $value = $form->{$_}; $value =~ s/&/%26/; "$_=$value" } grep { !/action/ } keys %$form;
1003 # push @HIDDENS, { 'name' => 'previousform', 'value' => $form->escape($previousform, 1) };
1004 push @HIDDENS, map +{ 'name' => $_, 'value' => $form->{$_} }, qw(partnumber description unit vc sellprice ean);
1005 push @HIDDENS, { 'name' => 'taxaccount2', 'value' => $form->{taxaccounts} };
1006 push @HIDDENS, { 'name' => 'notes', 'value' => $form->{longdescription} };
1009 print $form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } );
1011 $main::lxdebug->leave_sub();
1015 my $form = $main::form;
1016 call_sub($form->{update_nextsub} || $form->{nextsub});
1020 my $form = $main::form;
1021 call_sub($form->{continue_nextsub} || $form->{nextsub});
1025 my $form = $main::form;
1026 call_sub($form->{stock_nextsub} || $form->{nextsub});
1035 bin/mozilla/wh.pl - Warehouse frontend.
1043 call new item dialogue from warehouse masks.
1046 action => name of sub to be called when new item is done