Lagerstandsbericht: Listenpreis anzeigbar machen
[kivitendo-erp.git] / bin / mozilla / wh.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
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
9 #
10 #  Author: Dieter Simader
11 #   Email: dsimader@sql-ledger.org
12 #     Web: http://www.sql-ledger.org
13 #
14 #
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.
19 #
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., 51 Franklin Street, Fifth Floor, Boston,
27 # MA 02110-1335, USA.
28 #
29 #######################################################################
30 #
31 # warehouse and packinglist
32 #
33 #######################################################################
34
35 use List::Util qw(min max first);
36 use POSIX qw(strftime);
37
38 use SL::Form;
39 use SL::User;
40
41 use SL::AM;
42 use SL::CT;
43 use SL::IC;
44 use SL::WH;
45 use SL::OE;
46 use SL::Locale::String qw(t8);
47 use SL::ReportGenerator;
48 use SL::Presenter::Part;
49
50 use SL::DB::Part;
51
52 use Data::Dumper;
53
54 require "bin/mozilla/common.pl";
55 require "bin/mozilla/reportgenerator.pl";
56
57 use strict;
58
59 # parserhappy(R):
60
61 # contents of the "transfer_type" table:
62 #  $locale->text('back')
63 #  $locale->text('correction')
64 #  $locale->text('disposed')
65 #  $locale->text('found')
66 #  $locale->text('missing')
67 #  $locale->text('stock')
68 #  $locale->text('shipped')
69 #  $locale->text('transfer')
70 #  $locale->text('used')
71 #  $locale->text('return_material')
72 #  $locale->text('release_material')
73 #  $locale->text('assembled')
74 #  $locale->text('stocktaking')
75
76 # --------------------------------------------------------------------
77 # Transfer
78 # --------------------------------------------------------------------
79
80 sub transfer_warehouse_selection {
81   $main::lxdebug->enter_sub();
82
83   $main::auth->assert('warehouse_management');
84
85   my $form     = $main::form;
86   my %myconfig = %main::myconfig;
87   my $locale   = $main::locale;
88
89   $form->get_lists('warehouses' => { 'key'    => 'WAREHOUSES',
90                                      'bins'   => 'BINS', });
91
92   show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} });
93
94   my $units      = AM->retrieve_units(\%myconfig, $form);
95
96   my $part = 0;
97   if ( $form->{parts_id} ) {
98     $part = SL::DB::Part->new();
99     $part->id($form->{parts_id});
100     $part->load();
101   }
102
103   # der zweite Parameter von unit_select_data gibt den default-Namen (selected) vor
104   $form->{UNITS} = AM->unit_select_data($units, $form->{unit}, 0, $part ? $part->unit : 0);
105
106   if (scalar @{ $form->{WAREHOUSES} }) {
107     $form->{warehouse_id} ||= $form->{WAREHOUSES}->[0]->{id};
108     $form->{bin_id}       ||= $form->{WAREHOUSES}->[0]->{BINS}->[0]->{id};
109   }
110
111   my $content;
112
113   if ($form->{trans_type} eq 'removal') {
114     setup_wh_transfer_warehouse_selection_action_bar("removal_parts_selection");
115     $form->{title}   = $locale->text('Removal from Warehouse');
116     $content         = $form->parse_html_template('wh/warehouse_selection');
117
118   } elsif (!$form->{trans_type} || ($form->{trans_type} eq 'transfer')) {
119     setup_wh_transfer_warehouse_selection_action_bar("transfer_parts_selection");
120     $form->{title}   = $locale->text('Transfer');
121     $content         = $form->parse_html_template('wh/warehouse_selection');
122
123   } elsif ($form->{trans_type} eq 'assembly') {
124     setup_wh_transfer_warehouse_selection_assembly_action_bar();
125     $form->{title} = $locale->text('Produce Assembly');
126     $content       = $form->parse_html_template('wh/warehouse_selection_assembly');
127   }
128
129   $form->header();
130   print $content;
131
132   $main::lxdebug->leave_sub();
133 }
134
135 sub transfer_parts_selection {
136   $main::lxdebug->enter_sub();
137
138   $main::auth->assert('warehouse_management');
139
140   my $form     = $main::form;
141   my %myconfig = %main::myconfig;
142   my $locale   = $main::locale;
143
144   transfer_or_removal_prepare_contents('direction' => 'transfer');
145
146   setup_wh_transfer_parts_action_bar();
147
148   $form->{title} = $locale->text('Transfer');
149   $form->header();
150   print $form->parse_html_template("wh/transfer_parts_selection");
151
152   $main::lxdebug->leave_sub();
153 }
154
155 sub transfer_or_removal_prepare_contents {
156   $main::lxdebug->enter_sub();
157
158   $main::auth->assert('warehouse_management');
159
160   my %args = @_;
161
162   my $form     = $main::form;
163   my %myconfig = %main::myconfig;
164   my $locale   = $main::locale;
165
166   $form->get_lists('warehouses' => { 'key'    => 'WAREHOUSES',
167                                      'bins'   => 'BINS', });
168
169   my $warehouse_idx = get_warehouse_idx($form->{warehouse_id});
170   $form->show_generic_error($locale->text("The selected warehouse does not exist.")) if (-1 == $warehouse_idx);
171
172   my $warehouse = $form->{WAREHOUSES}->[$warehouse_idx];
173
174   $form->{initial_warehouse_idx} = $warehouse_idx;
175   $form->{warehouse_description} = $warehouse->{description};
176   $warehouse->{selected}         = 1;
177
178   $form->show_generic_error($locale->text("The source warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} });
179
180   map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit ean);
181
182   $form->{sort} = 'bindescription';
183   my @contents  = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id},
184                                            "bin_id"       => $form->{bin_id},
185                                            "chargenumber" => $form->{chargenumber},
186                                            "bestbefore"   => $form->{bestbefore},
187                                            "partsid"      => $form->{part_id},
188                                            "ean"          => $form->{ean});
189
190   if (0 == scalar(@contents)) {
191     $form->show_generic_error($locale->text("The selected warehouse is empty, or no stocked items where found that match the filter settings."));
192   }
193
194   my $all_units = AM->retrieve_units(\%myconfig, $form);
195
196   foreach (@contents) {
197     $_->{qty} = $form->format_amount_units('amount'     => $_->{qty},
198                                            'part_unit'  => $_->{partunit},
199                                            'conv_units' => 'convertible');
200     my $this_unit = $_->{partunit};
201
202     if ($all_units->{$_->{partunit}} && ($all_units->{g}->{base_unit} eq $all_units->{$_->{partunit}}->{base_unit})) {
203       $this_unit = "kg";
204     }
205
206     $_->{UNITS} = AM->unit_select_data($all_units, $this_unit, 0, $_->{partunit});
207   }
208
209   my $transfer_types = WH->retrieve_transfer_types($args{direction});
210   map { $_->{description} = $locale->text($_->{description}) } @{ $transfer_types };
211
212   $form->{CONTENTS}       = \@contents;
213   $form->{TRANSFER_TYPES} = $transfer_types;
214
215   $main::lxdebug->leave_sub();
216 }
217
218
219 sub transfer_parts {
220   $main::lxdebug->enter_sub();
221
222   $main::auth->assert('warehouse_management');
223
224   my $form     = $main::form;
225   my %myconfig = %main::myconfig;
226   my $locale   = $main::locale;
227
228   $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', 'bins' => 'BINS' });
229
230   my $warehouse_idx = get_warehouse_idx($form->{warehouse_id});
231   $form->show_generic_error($locale->text("The selected warehouse does not exist.")) if (-1 == $warehouse_idx);
232
233   my $warehouse = $form->{WAREHOUSES}->[$warehouse_idx];
234
235   $form->show_generic_error($locale->text("The source warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} });
236
237   map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit);
238
239   $form->{sort} = 'bindescription';
240   my @contents  = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id});
241   my $all_units = AM->retrieve_units(\%myconfig, $form);
242
243   my @transfers;
244
245   foreach my $row (1 .. $form->{rowcount}) {
246     $form->{"qty_$row"} =~ s/^\s*//;
247     $form->{"qty_$row"} =~ s/\s*$//;
248     next if (!$form->{"qty_$row"});
249
250     my $bin_idx = get_bin_idx($warehouse_idx, $form->{"src_bin_id_$row"});
251     $form->show_generic_error($locale->text("The selected bin does not exist.")) if (-1 == $bin_idx);
252     my $bin     = $warehouse->{BINS}->[$bin_idx];
253
254     my $orig_qty = $form->{"qty_$row"} . " " . $form->{"unit_$row"};
255
256     my $transfer = {
257       'src_warehouse_id' => $form->{warehouse_id},
258       'transfer_type_id' => $form->{transfer_type_id},
259     };
260
261     map { $transfer->{$_} = $form->{"${_}_${row}"} } qw(src_bin_id chargenumber bestbefore parts_id qty dst_warehouse_id dst_bin_id);
262
263     my $entry;
264
265     foreach (@contents) {
266       if (($_->{binid} == $transfer->{src_bin_id}) && ($_->{parts_id} == $transfer->{parts_id}) && ($_->{chargenumber} eq $transfer->{chargenumber}) && $_->{bestbefore} eq $transfer->{bestbefore}) {
267         $entry = $_;
268         last;
269       }
270     }
271
272     if (!$entry) {
273       $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
274                                  $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
275     }
276
277     $transfer->{qty}  = $form->parse_amount(\%myconfig, $transfer->{qty}) * $all_units->{$form->{"unit_$row"}}->{factor};
278     $transfer->{qty} /= $all_units->{$entry->{partunit}}->{factor} || 1;
279
280     if (($entry->{qty} < $transfer->{qty}) || (0 >= $transfer->{qty})) {
281       $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
282                                  $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
283     }
284
285     $transfer->{comment} = $form->{comment};
286     $transfer->{change_default_bin} = $form->{change_default_bin};
287
288     push @transfers, $transfer;
289
290     $entry->{qty} -= $transfer->{qty};
291   }
292
293   if (!scalar @transfers) {
294     $form->show_generic_information($locale->text('Nothing has been selected for transfer.'));
295     $::dispatcher->end_request;
296   }
297
298   WH->transfer(@transfers);
299
300   $form->{trans_type}    = 'transfer';
301   $form->{saved_message} = $locale->text('The parts have been transferred.');
302
303   transfer_warehouse_selection();
304
305   $main::lxdebug->leave_sub();
306 }
307
308 # --------------------------------------------------------------------
309 # Transfer: stock
310 # --------------------------------------------------------------------
311
312 # --------------------------------------------------------------------
313 # Transfer: assemblies
314 # Dies ist die Auswahlmaske für ein assembly.
315 # Die ist einfach von transfer_assembly_update_part kopiert und nur um den trans_type (assembly) korrigiert worden
316 # Es wäre schön, hier nochmal check_assembly_max_create auf, um die max. Fertigungszahl herauszufinden.
317 # Ich lass das mal als auskommentierte Idee bestehen jb 18.3.09
318 # --------------------------------------------------------------------
319
320 sub transfer_assembly_update_part {
321   my $form     = $main::form;
322   my %myconfig = %main::myconfig;
323   my $locale   = $main::locale;
324
325   $form->{trans_type} = 'assembly';
326   $form->{qty}        = $form->parse_amount(\%myconfig, $form->{qty});
327
328   if (!$form->{parts_id}) {
329     delete $form->{partunit};
330     transfer_warehouse_selection();
331     return;
332
333   }
334
335   my $part = SL::DB::Part->new(id => $::form->{parts_id})->load;
336   @{$form}{qw(parts_id partnumber description)} = ($part->id, $part->partnumber, $part->description);
337
338   transfer_stock_get_partunit();
339   transfer_warehouse_selection();
340 }
341
342 sub transfer_stock_part_selected {
343   $main::lxdebug->enter_sub();
344
345   my $part = shift;
346
347   my $form     = $main::form;
348
349   @{$form}{qw(parts_id partnumber description ean warehouse_id bin_id)} = @{$part}{qw(id partnumber description ean warehouse_id bin_id)};
350
351   transfer_stock_get_partunit();
352   transfer_warehouse_selection();
353
354   $main::lxdebug->leave_sub();
355 }
356
357 sub transfer_stock_get_partunit {
358   $main::lxdebug->enter_sub();
359
360   my $form     = $main::form;
361
362   if ($form->{parts_id}) {
363     my $part_info     = IC->get_basic_part_info('id' => $form->{parts_id});
364     $form->{partunit} = $part_info->{unit};
365   }
366
367   $main::lxdebug->leave_sub();
368 }
369
370 # vorüberlegung jb 22.2.2009
371 # wir benötigen für diese funktion, die anzahl die vom erzeugnis hergestellt werden soll. vielleicht direkt per js fehleingaben verhindern?
372 # ferner dann nochmal mit check_asssembly_max_create gegenprüfen und dann transaktionssicher wegbuchen.
373 # 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
374 # Manko ist derzeit noch, dass unterschiedliche Lagerplätze, bzw. das Quelllager an sich nicht ausgewählt werden können.
375 # Laut Absprache in KW11 09 Ã¼bernimmt mb hier den rest im April ... jb 18.3.09
376
377 sub create_assembly {
378   $main::lxdebug->enter_sub();
379
380   my $form     = $main::form;
381   my %myconfig = %main::myconfig;
382   my $locale   = $main::locale;
383
384   $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
385   if ($form->{qty} <= 0) {
386     $form->show_generic_error($locale->text('Invalid quantity.'));
387   }
388   # TODO Es wäre schön, hier schon die maximale Anzahl der zu fertigenden Erzeugnisse zu haben
389   #else { if ($form->{qty} > $maxcreate) { #s.o.
390   #     $form->show_generic_error($locale->text('Can not create that quantity with current stock'));
391   #     $form->show_generic_error('Maximale Stückzahl' . $maxcreate);
392   #   }
393   #  }
394
395   if (!$form->{warehouse_id} || !$form->{bin_id}) {
396     $form->error($locale->text('The warehouse or the bin is missing.'));
397   }
398
399   if (!$::instance_conf->get_show_bestbefore) {
400       $form->{bestbefore} = '';
401   }
402
403   # 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
404   # Anm. jb 18.3. vielleicht auch nur meine unwissenheit in perl-datenstrukturen
405   my %TRANSFER = (
406     'transfer_type'    => 'assembly',
407     'login'            => $::myconfig{login},
408     'dst_warehouse_id' => $form->{warehouse_id},
409     'dst_bin_id'       => $form->{bin_id},
410     'chargenumber'     => $form->{chargenumber},
411     'bestbefore'       => $form->{bestbefore},
412     'assembly_id'      => $form->{parts_id},
413     'qty'              => $form->{qty},
414     'unit'             => $form->{unit},
415     'comment'          => $form->{comment}
416   );
417
418   my $ret = WH->transfer_assembly (%TRANSFER);
419   # Frage: Ich pack in den return-wert auch gleich die Fehlermeldung. Irgendwelche Nummern als Fehlerkonstanten definieren find ich auch nicht besonders schick...
420   # Ideen? jb 18.3.09
421   if ($ret ne "1"){
422     # 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
423     $form->show_generic_error($ret);
424   }
425
426   delete @{$form}{qw(parts_id partnumber description qty unit chargenumber bestbefore comment)};
427
428   $form->{saved_message} = $locale->text('The assembly has been created.');
429   $form->{trans_type}    = 'assembly';
430
431   transfer_warehouse_selection();
432
433   $main::lxdebug->leave_sub();
434 }
435
436 # --------------------------------------------------------------------
437 # Transfer: removal
438 # --------------------------------------------------------------------
439
440 sub removal_parts_selection {
441   $main::lxdebug->enter_sub();
442
443   $main::auth->assert('warehouse_management');
444
445   my $form     = $main::form;
446   my %myconfig = %main::myconfig;
447   my $locale   = $main::locale;
448
449   transfer_or_removal_prepare_contents('direction' => 'out');
450
451   setup_wh_removal_parts_selection_action_bar();
452
453   $form->{title} = $locale->text('Removal');
454   $form->header();
455   print $form->parse_html_template("wh/removal_parts_selection");
456
457   $main::lxdebug->leave_sub();
458 }
459
460 sub remove_parts {
461   $main::lxdebug->enter_sub();
462
463   $main::auth->assert('warehouse_management');
464
465   my $form     = $main::form;
466   my %myconfig = %main::myconfig;
467   my $locale   = $main::locale;
468
469   $form->get_lists('warehouses' => { 'key'    => 'WAREHOUSES',
470                                      'bins'   => 'BINS', });
471
472   my $warehouse_idx = get_warehouse_idx($form->{warehouse_id});
473   $form->show_generic_error($locale->text("The selected warehouse does not exist.")) if (-1 == $warehouse_idx);
474
475   my $warehouse = $form->{WAREHOUSES}->[$warehouse_idx];
476
477   $form->show_generic_error($locale->text("The warehouse does not contain any bins.")) if (0 == scalar @{ $warehouse->{BINS} });
478
479   map { $form->{"l_$_"} = 'Y' } qw(parts_id qty warehouseid binid partnumber partdescription bindescription chargenumber bestbefore partunit);
480
481   $form->{sort} = 'bindescription';
482   my @contents  = WH->get_warehouse_report("warehouse_id" => $form->{warehouse_id});
483   my $all_units = AM->retrieve_units(\%myconfig, $form);
484
485   my @transfers;
486
487   foreach my $row (1 .. $form->{rowcount}) {
488     $form->{"qty_$row"} =~ s/^\s*//;
489     $form->{"qty_$row"} =~ s/\s*$//;
490     next if (!$form->{"qty_$row"});
491
492     my $bin_idx = get_bin_idx($warehouse_idx, $form->{"src_bin_id_$row"});
493     $form->show_generic_error($locale->text("The selected bin does not exist.")) if (-1 == $bin_idx);
494     my $bin     = $warehouse->{BINS}->[$bin_idx];
495
496     my $orig_qty = $form->{"qty_$row"} . " " . $form->{"unit_$row"};
497
498     my $transfer = {
499       'src_warehouse_id' => $form->{warehouse_id},
500       'transfer_type_id' => $form->{transfer_type_id},
501     };
502
503     map { $transfer->{$_} = $form->{"${_}_${row}"} } qw(src_bin_id chargenumber bestbefore parts_id qty);
504
505     my $entry;
506
507     foreach (@contents) {
508       if (($_->{binid} == $transfer->{src_bin_id}) && ($_->{parts_id} == $transfer->{parts_id}) && ($_->{chargenumber} eq $transfer->{chargenumber}) && ($_->{bestbefore} eq $transfer->{bestbefore})) {
509         $entry = $_;
510         last;
511       }
512     }
513
514     if (!$entry) {
515       $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
516                                  $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
517     }
518
519     $transfer->{qty}  = $form->parse_amount(\%myconfig, $transfer->{qty}) * $all_units->{$form->{"unit_$row"}}->{factor};
520     $transfer->{qty} /= $all_units->{$entry->{partunit}}->{factor} || 1;
521
522     if (($entry->{qty} < $transfer->{qty}) || (0 >= $transfer->{qty})) {
523       $form->error($locale->text("There is not enough left of '#1' in bin '#2' for the removal of #3.",
524                                  $form->{"partdescription_$row"}, $bin->{description}, $orig_qty));
525     }
526
527     $transfer->{comment} = $form->{comment};
528
529     push @transfers, $transfer;
530
531     $entry->{qty} -= $transfer->{qty};
532   }
533
534   if (!scalar @transfers) {
535     $form->show_generic_information($locale->text('Nothing has been selected for removal.'));
536     $::dispatcher->end_request;
537   }
538
539   WH->transfer(@transfers);
540
541   $form->{trans_type}    = 'removal';
542   $form->{saved_message} = $locale->text('The parts have been removed.');
543
544   transfer_warehouse_selection();
545
546   $main::lxdebug->leave_sub();
547 }
548
549 # --------------------------------------------------------------------
550 # Journal
551 # --------------------------------------------------------------------
552
553 sub journal {
554   $main::lxdebug->enter_sub();
555
556   $main::auth->assert('warehouse_management');
557
558   my $form     = $main::form;
559   my %myconfig = %main::myconfig;
560   my $locale   = $main::locale;
561
562   $form->{title} = $locale->text('Report about warehouse transactions');
563   $form->get_lists('warehouses' => { 'key'  => 'WAREHOUSES',
564                                      'bins' => 'BINS', });
565
566   show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} });
567
568   setup_wh_journal_action_bar();
569
570   $form->header();
571   print $form->parse_html_template("wh/journal_filter", { "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) });
572
573   $main::lxdebug->leave_sub();
574 }
575
576 sub generate_journal {
577   $main::lxdebug->enter_sub();
578
579   $main::auth->assert('warehouse_management');
580
581   my $form     = $main::form;
582   my %myconfig = %main::myconfig;
583   my $locale   = $main::locale;
584
585   $form->{title}   = $locale->text("WHJournal");
586   $form->{sort}  ||= 'date';
587
588   $form->{report_generator_output_format} = 'HTML' if !$form->{report_generator_output_format};
589
590   my %filter;
591   my @columns = qw(trans_id date warehouse_from bin_from warehouse_to bin_to partnumber type_and_classific partdescription chargenumber bestbefore trans_type comment qty unit partunit employee oe_id projectnumber);
592
593   # filter stuff
594   map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id classification_id partnumber description chargenumber bestbefore transtype_id transtype_ids comment projectnumber);
595
596   $filter{qty_op} = WH->convert_qty_op($form->{qty_op});
597   if ($filter{qty_op}) {
598     $form->isblank("qty",      $locale->text('Quantity missing.'));
599     $form->isblank("qty_unit", $locale->text('Unit missing.'));
600
601     $filter{qty}      = $form->{qty};
602     $filter{qty_unit} = $form->{qty_unit};
603   }
604   # /filter stuff
605
606   my $allrows        = !!($form->{report_generator_output_format} ne 'HTML') ;
607
608   # manual paginating
609   my $pages          = {};
610   my $page           = $::form->{page} || 1;
611   $pages->{per_page} = $::form->{per_page} || 15;
612   my $first_nr       = ($page - 1) * $pages->{per_page};
613   my $last_nr        = $first_nr + $pages->{per_page};
614
615   # no optimisation if qty op
616   if ( !$allrows && $form->{maxrows} && !$filter{qty_op}) {
617     $filter{limit}  = $pages->{per_page};
618     $filter{offset} = ($page - 1) * $pages->{per_page};
619     $first_nr       = 0;
620     $last_nr        = $pages->{per_page};
621   }
622
623   my @contents  = WH->get_warehouse_journal(%filter);
624   # get maxcount
625   if (!$form->{maxrows}) {
626     $form->{maxrows} = scalar @contents ;
627   }
628
629   my $report = SL::ReportGenerator->new(\%myconfig, $form);
630
631   my @hidden_variables = map { "l_${_}" } @columns;
632   push @hidden_variables, qw(warehouse_id bin_id partnumber description chargenumber bestbefore qty_op qty qty_unit unit partunit fromdate todate transtype_ids comment projectnumber);
633   push @hidden_variables, qw(classification_id);
634
635   my %column_defs = (
636     'date'            => { 'text' => $locale->text('Date'), },
637     'trans_id'        => { 'text' => $locale->text('Trans Id'), },
638     'trans_type'      => { 'text' => $locale->text('Trans Type'), },
639     'comment'         => { 'text' => $locale->text('Comment'), },
640     'warehouse_from'  => { 'text' => $locale->text('Warehouse From'), },
641     'warehouse_to'    => { 'text' => $locale->text('Warehouse To'), },
642     'bin_from'        => { 'text' => $locale->text('Bin From'), },
643     'bin_to'          => { 'text' => $locale->text('Bin To'), },
644     'partnumber'      => { 'text' => $locale->text('Part Number'), },
645     'type_and_classific'
646                       => { 'text' => $locale->text('Type'), },
647     'partdescription' => { 'text' => $locale->text('Part Description'), },
648     'chargenumber'    => { 'text' => $locale->text('Charge Number'), },
649     'bestbefore'      => { 'text' => $locale->text('Best Before'), },
650     'qty'             => { 'text' => $locale->text('Qty'), },
651     'unit'            => { 'text' => $locale->text('Part Unit'), },
652     'partunit'        => { 'text' => $locale->text('Unit'), },
653     'employee'        => { 'text' => $locale->text('Employee'), },
654     'projectnumber'   => { 'text' => $locale->text('Project Number'), },
655     'oe_id'           => { 'text' => $locale->text('Document'), },
656   );
657
658   if ($form->{transtype_ids} && 'ARRAY' eq ref $form->{transtype_ids}) {
659     for (my $i = 0; $i < scalar(@{ $form->{transtype_ids} }); $i++) {
660       delete $form->{transtype_ids}[$i] if $form->{transtype_ids}[$i] eq '';
661     }
662     $form->{transtype_ids} = join(",", @{ $form->{transtype_ids} });
663   }
664
665   my $href = build_std_url('action=generate_journal', grep { $form->{$_} } @hidden_variables);
666   $href .= "&maxrows=".$form->{maxrows};
667
668   map { $column_defs{$_}->{link} = $href ."&page=".$page. "&sort=${_}&order=" . Q($_ eq $form->{sort} ? 1 - $form->{order} : $form->{order}) } @columns;
669
670   my %column_alignment = map { $_ => 'right' } qw(qty);
671
672   map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
673   $column_defs{partunit}->{visible} = 1;
674   $column_defs{type_and_classific}->{visible} = 1;
675   $column_defs{type_and_classific}->{link} ='';
676
677   $report->set_columns(%column_defs);
678   $report->set_column_order(@columns);
679
680   $report->set_export_options('generate_journal', @hidden_variables, qw(sort order));
681
682   $report->set_sort_indicator($form->{sort}, $form->{order});
683
684   $report->set_options('output_format'        => 'HTML',
685                        'title'                => $form->{title},
686                        'attachment_basename'  => strftime($locale->text('warehouse_journal_list') . '_%Y%m%d', localtime time));
687   $report->set_options_from_form();
688   $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
689
690   my $all_units = AM->retrieve_units(\%myconfig, $form);
691
692   my %doc_types = ( 'sales_quotation'         => { script => 'oe', title => $locale->text('Sales quotation') },
693                     'sales_order'             => { script => 'oe', title => $locale->text('Sales Order') },
694                     'request_quotation'       => { script => 'oe', title => $locale->text('Request quotation') },
695                     'purchase_order'          => { script => 'oe', title => $locale->text('Purchase Order') },
696                     'sales_delivery_order'    => { script => 'do', title => $locale->text('Sales delivery order') },
697                     'purchase_delivery_order' => { script => 'do', title => $locale->text('Purchase delivery order') },
698                     'sales_invoice'           => { script => 'is', title => $locale->text('Sales Invoice') },
699                     'purchase_invoice'        => { script => 'ir', title => $locale->text('Purchase Invoice') },
700                   );
701
702   my $idx       = 0;
703
704   foreach my $entry (@contents) {
705     $entry->{type_and_classific} = SL::Presenter::Part::type_abbreviation($entry->{part_type}) .
706                                    SL::Presenter::Part::classification_abbreviation($entry->{classification_id});
707     $entry->{qty}        = $form->format_amount(\%myconfig, $entry->{qty});
708     $entry->{trans_type} = $locale->text($entry->{trans_type});
709
710     my $row = { };
711
712     foreach my $column (@columns) {
713       $row->{$column} = {
714         'data'  => $entry->{$column},
715         'align' => $column_alignment{$column},
716       };
717     }
718
719     $row->{trans_type}->{raw_data} = $entry->{trans_type};
720
721     if ($form->{l_oe_id}) {
722       $row->{oe_id}->{data} = '';
723       my $info              = $entry->{oe_id_info};
724
725       if ($info && $info->{id} && $info->{type} && $doc_types{$info->{type}}) {
726         $row->{oe_id} = { data => $doc_types{ $info->{type} }->{title} . ' ' . $info->{number},
727                           link => build_std_url('script=' . $doc_types{ $info->{type} }->{script} . '.pl', 'action=edit', 'id=' . $info->{id}, 'type=' . $info->{type}) };
728       }
729     }
730
731     if ( $allrows || ($idx >= $first_nr && $idx < $last_nr )) {
732       $report->add_data($row);
733     }
734     $idx++;
735   }
736
737   if ( ! $allrows ) {
738       $pages->{max}  = SL::DB::Helper::Paginated::ceil($form->{maxrows}, $pages->{per_page}) || 1;
739       $pages->{page} = $page < 1 ? 1: $page > $pages->{max} ? $pages->{max}: $page;
740       $pages->{common} = [ grep { $_->{visible} } @{ SL::DB::Helper::Paginated::make_common_pages($pages->{page}, $pages->{max}) } ];
741
742       $report->set_options('raw_bottom_info_text' => $form->parse_html_template('common/paginate',
743                                                             { 'pages' => $pages , 'base_url' => $href.'&sort='.$form->{sort}.'&order='.$form->{order}}) );
744   }
745   $report->generate_with_headers();
746
747   $main::lxdebug->leave_sub();
748 }
749
750 # --------------------------------------------------------------------
751 # Report
752 # --------------------------------------------------------------------
753
754 sub report {
755   $main::lxdebug->enter_sub();
756
757   $main::auth->assert('warehouse_contents | warehouse_management');
758
759   my $form     = $main::form;
760   my %myconfig = %main::myconfig;
761   my $locale   = $main::locale;
762
763   $form->get_lists('warehouses' => { 'key'    => 'WAREHOUSES',
764                                      'bins'   => 'BINS', });
765
766   show_no_warehouses_error() if (!scalar @{ $form->{WAREHOUSES} });
767
768   $form->{title}   = $locale->text("Report about warehouse contents");
769
770   setup_wh_report_action_bar();
771
772   $form->header();
773   print $form->parse_html_template("wh/report_filter",
774                                    { "WAREHOUSES" => $form->{WAREHOUSES},
775                                      "UNITS"      => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) });
776
777   $main::lxdebug->leave_sub();
778 }
779
780 sub generate_report {
781   $main::lxdebug->enter_sub();
782
783   $main::auth->assert('warehouse_contents | warehouse_management');
784
785   my $form     = $main::form;
786   my %myconfig = %main::myconfig;
787   my $locale   = $main::locale;
788
789   $form->{title}   = $locale->text("Report about warehouse contents");
790   $form->{sort}  ||= 'partnumber';
791   my $sort_col     = $form->{sort};
792
793   my %filter;
794   my @columns = qw(warehousedescription bindescription partnumber type_and_classific partdescription chargenumber bestbefore comment qty partunit list_price purchase_price stock_value);
795
796   # filter stuff
797   map { $filter{$_} = $form->{$_} if ($form->{$_}) } qw(warehouse_id bin_id classification_id partnumber description chargenumber bestbefore date include_invalid_warehouses);
798
799   # show filter stuff also in report
800   my @options;
801   my $currentdate = $form->current_date(\%myconfig);
802   push @options, $locale->text('Printdate') . " : ".$locale->date(\%myconfig, $currentdate, 1);
803
804   # dispatch all options
805   my $dispatch_options = {
806    warehouse_id   => sub { push @options, $locale->text('Warehouse') . " : " .
807                                             SL::DB::Manager::Warehouse->find_by(id => $form->{warehouse_id})->description},
808    bin_id         => sub { push @options, $locale->text('Bin') . " : " .
809                                             SL::DB::Manager::Bin->find_by(id => $form->{bin_id})->description},
810    partnumber     => sub { push @options, $locale->text('Partnumber')     . " : $form->{partnumber}"},
811    classification_id => sub { push @options, $locale->text('Parts Classification'). " : ".
812                                                SL::DB::Manager::PartClassification->get_first(where => [ id => $form->{classification_id} ] )->description; },
813    description    => sub { push @options, $locale->text('Description')    . " : $form->{description}"},
814    chargenumber   => sub { push @options, $locale->text('Charge Number')  . " : $form->{chargenumber}"},
815    bestbefore     => sub { push @options, $locale->text('Best Before')    . " : $form->{bestbefore}"},
816    include_invalid_warehouses    => sub { push @options, $locale->text('Include invalid warehouses ')},
817   };
818   foreach (keys %filter) {
819    $dispatch_options->{$_}->() if $dispatch_options->{$_};
820   }
821   push @options, $locale->text('Stock Qty for Date') . " " . $locale->date(\%myconfig, $form->{date}?$form->{date}:$currentdate, 1);
822
823   # / end show filter stuff also in report
824
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.'));
829
830     $filter{qty}      = $form->{qty};
831     $filter{qty_unit} = $form->{qty_unit};
832   }
833   # /filter stuff
834
835   $form->{report_generator_output_format} = 'HTML' if !$form->{report_generator_output_format};
836
837   # manual paginating
838   my $allrows        = !!($form->{report_generator_output_format} ne 'HTML') ;
839   my $page           = $::form->{page} || 1;
840   my $pages          = {};
841   $pages->{per_page} = $::form->{per_page} || 20;
842   my $first_nr       = ($page - 1) * $pages->{per_page};
843   my $last_nr        = $first_nr + $pages->{per_page};
844
845   # no optimisation if qty op
846   if ( !$allrows && $form->{maxrows} && !$filter{qty_op}) {
847     $filter{limit}  = $pages->{per_page};
848     $filter{offset} = ($page - 1) * $pages->{per_page};
849     $first_nr       = 0;
850     $last_nr        = $pages->{per_page};
851   }
852
853   my @contents  = WH->get_warehouse_report(%filter);
854
855   # get maxcount
856   if (!$form->{maxrows}) {
857     $form->{maxrows} = scalar @contents ;
858   }
859
860   $form->{subtotal} = '' if (!first { $_ eq $sort_col } qw(partnumber partdescription));
861
862   my $report = SL::ReportGenerator->new(\%myconfig, $form);
863
864   my @hidden_variables = map { "l_${_}" } @columns;
865   push @hidden_variables, qw(warehouse_id bin_id partnumber partstypes_id description chargenumber bestbefore qty_op qty qty_unit partunit l_warehousedescription l_bindescription);
866   push @hidden_variables, qw(include_empty_bins subtotal include_invalid_warehouses date);
867   push @hidden_variables, qw(classification_id);
868
869   my %column_defs = (
870     'warehousedescription' => { 'text' => $locale->text('Warehouse'), },
871     'bindescription'       => { 'text' => $locale->text('Bin'), },
872     'partnumber'           => { 'text' => $locale->text('Part Number'), },
873     'type_and_classific'   => { 'text' => $locale->text('Type'), },
874     'partdescription'      => { 'text' => $locale->text('Part Description'), },
875     'chargenumber'         => { 'text' => $locale->text('Charge Number'), },
876     'bestbefore'           => { 'text' => $locale->text('Best Before'), },
877     'qty'                  => { 'text' => $locale->text('Qty'), },
878     'partunit'             => { 'text' => $locale->text('Unit'), },
879     'stock_value'          => { 'text' => $locale->text('Stock value'), },
880     'purchase_price'       => { 'text' => $locale->text('Purchase price'), },
881     'list_price'           => { 'text' => $locale->text('List Price'), },
882   );
883
884   my $href = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
885   $href .= "&maxrows=".$form->{maxrows};
886
887   map { $column_defs{$_}->{link} = $href . "&page=".$page."&sort=${_}&order=" . Q($_ eq $sort_col ? 1 - $form->{order} : $form->{order}) } @columns;
888
889   my %column_alignment = map { $_ => 'right' } qw(qty list_price purchase_price stock_value);
890
891   map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
892
893   $column_defs{partunit}->{visible}           = 1;
894   $column_defs{type_and_classific}->{visible} = 1;
895   $column_defs{type_and_classific}->{link} ='';
896
897   $report->set_columns(%column_defs);
898   $report->set_column_order(@columns);
899
900   $report->set_export_options('generate_report', @hidden_variables, qw(sort order));
901
902   $report->set_sort_indicator($sort_col, $form->{order});
903
904   $report->set_options('top_info_text'        => join("\n", @options),
905                        'output_format'        => 'HTML',
906                        'title'                => $form->{title},
907                        'attachment_basename'  => strftime($locale->text('warehouse_report_list') . '_%Y%m%d', localtime time));
908   $report->set_options_from_form();
909   $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
910
911   my $all_units = AM->retrieve_units(\%myconfig, $form);
912   my $idx       = 0;
913
914   my @subtotals_columns = qw(qty stock_value);
915   my %subtotals         = map { $_ => 0 } @subtotals_columns;
916
917   my $total_stock_value = 0;
918
919   foreach my $entry (@contents) {
920
921     $entry->{type_and_classific} = SL::Presenter::Part::type_abbreviation($entry->{part_type}).
922                                    SL::Presenter::Part::classification_abbreviation($entry->{classification_id});
923     map { $subtotals{$_} += $entry->{$_} } @subtotals_columns;
924     $total_stock_value   += $entry->{stock_value} * 1;
925     $entry->{qty}         = $form->format_amount(\%myconfig, $entry->{qty});
926 #    $entry->{qty}         = $form->format_amount_units('amount'     => $entry->{qty},
927 #                                                       'part_unit'  => $entry->{partunit},
928 #                                                       'conv_units' => 'convertible');
929     $entry->{stock_value} = $form->format_amount(\%myconfig, $entry->{stock_value} * 1, 2);
930     $entry->{purchase_price} = $form->format_amount(\%myconfig, $entry->{purchase_price} * 1, 2);
931     $entry->{list_price}     = $form->format_amount(\%myconfig, $entry->{list_price}     * 1, 2);
932
933     my $row_set = [ { map { $_ => { 'data' => $entry->{$_}, 'align' => $column_alignment{$_} } } @columns } ];
934
935     if ( ($form->{subtotal} eq 'Y' && !$form->{report_generator_csv_options_for_import} )
936         && (($idx == (scalar @contents - 1))
937             || ($entry->{$sort_col} ne $contents[$idx + 1]->{$sort_col}))) {
938
939       my $row = { map { $_ => { 'data' => '', 'class' => 'listsubtotal', 'align' => $column_alignment{$_}, } } @columns };
940       $row->{qty}->{data}         = $form->format_amount(\%myconfig, $subtotals{qty});
941 #      $row->{qty}->{data}         = $form->format_amount_units('amount'     => $subtotals{qty} * 1,
942 #                                                               'part_unit'  => $entry->{partunit},
943 #                                                               'conv_units' => 'convertible');
944       $row->{stock_value}->{data} = $form->format_amount(\%myconfig, $subtotals{stock_value} * 1, 2);
945       $row->{purchase_price}->{data} = $form->format_amount(\%myconfig, $subtotals{purchase_price} * 1, 2);
946       $row->{list_price}->{data}     = $form->format_amount(\%myconfig, $subtotals{list_price}     * 1, 2);
947
948       %subtotals                  = map { $_ => 0 } @subtotals_columns;
949
950       push @{ $row_set }, $row;
951     }
952
953     if ( $allrows || ($idx >= $first_nr && $idx < $last_nr )) {
954         $report->add_data($row_set);
955     }
956     $idx++;
957   }
958
959   if ( $column_defs{stock_value}->{visible} && !$form->{report_generator_csv_options_for_import} ) {
960     $report->add_separator();
961
962     my $row                      = { map { $_ => { 'data' => '', 'class' => 'listsubtotal', } } @columns };
963
964     my $left_col                 = first { $column_defs{$_}->{visible} } @columns;
965
966     $row->{$left_col}->{data}    = $locale->text('Total stock value');
967     $row->{stock_value}->{data}  = $form->format_amount(\%myconfig, $total_stock_value, 2);
968     $row->{stock_value}->{align} = 'right';
969
970     $report->add_data($row);
971   }
972   if ( ! $allrows ) {
973     $pages->{max}  = SL::DB::Helper::Paginated::ceil($form->{maxrows}, $pages->{per_page}) || 1;
974     $pages->{page} = $page < 1 ? 1: $page > $pages->{max} ? $pages->{max}: $page;
975     $pages->{common} = [ grep { $_->{visible} } @{ SL::DB::Helper::Paginated::make_common_pages($pages->{page}, $pages->{max}) } ];
976
977     $report->set_options('raw_bottom_info_text' => $form->parse_html_template('common/paginate',
978                                                                               {'pages' => $pages , 'base_url' => $href}) );
979   }
980
981   $report->generate_with_headers();
982
983   $main::lxdebug->leave_sub();
984 }
985
986 # --------------------------------------------------------------------
987 # Utility functions
988 # --------------------------------------------------------------------
989
990 sub show_no_warehouses_error {
991   $main::lxdebug->enter_sub();
992
993   my $form     = $main::form;
994   my %myconfig = %main::myconfig;
995   my $locale   = $main::locale;
996
997   my $msg = $locale->text('No warehouse has been created yet or the quantity of the bins is not configured yet.') . ' ';
998
999   if ($main::auth->check_right($::myconfig{login}, 'config')) {
1000     $msg .= $locale->text('You can create warehouses and bins via the menu "System -> Warehouses".');
1001   } else {
1002     $msg .= $locale->text('Please ask your administrator to create warehouses and bins.');
1003   }
1004
1005   $form->show_generic_error($msg);
1006
1007   $main::lxdebug->leave_sub();
1008 }
1009
1010 sub get_warehouse_idx {
1011   my ($warehouse_id) = @_;
1012
1013   my $form     = $main::form;
1014
1015   for (my $i = 0; $i < scalar @{$form->{WAREHOUSES}}; $i++) {
1016     return $i if ($form->{WAREHOUSES}->[$i]->{id} == $warehouse_id);
1017   }
1018
1019   return -1;
1020 }
1021
1022 sub get_bin_idx {
1023   my ($warehouse_index, $bin_id) = @_;
1024
1025   my $form     = $main::form;
1026
1027   my $warehouse = $form->{WAREHOUSES}->[$warehouse_index];
1028
1029   return -1 if (!$warehouse);
1030
1031   for (my $i = 0; $i < scalar @{ $warehouse->{BINS} }; $i++) {
1032     return $i if ($warehouse->{BINS}->[$i]->{id} == $bin_id);
1033   }
1034
1035   return -1;
1036 }
1037
1038 sub new_item {
1039   $main::lxdebug->enter_sub();
1040   my %params = @_;
1041
1042   my $form     = $main::form;
1043
1044   # change callback
1045   $form->{old_callback} = $form->escape($form->{callback}, 1);
1046   $form->{callback}     = $form->escape("$form->{script}?action=$params{action}", 1);
1047
1048   # save all form variables except action in a previousform variable
1049   my $previousform = join '&', map { my $value = $form->{$_}; $value =~ s/&/%26/; "$_=$value" } grep { !/action/ } keys %$form;
1050   my @HIDDENS = ();
1051
1052 #  push @HIDDENS,      { 'name' => 'previousform', 'value' => $form->escape($previousform, 1) };
1053   push @HIDDENS, map +{ 'name' => $_,             'value' => $form->{$_} }, qw(partnumber description unit vc sellprice ean);
1054   push @HIDDENS,      { 'name' => 'taxaccount2',  'value' => $form->{taxaccounts} };
1055   push @HIDDENS,      { 'name' => 'notes',        'value' => $form->{longdescription} };
1056
1057   $form->header();
1058   print $form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } );
1059
1060   $main::lxdebug->leave_sub();
1061 }
1062
1063 sub update {
1064   my $form     = $main::form;
1065   call_sub($form->{update_nextsub} || $form->{nextsub});
1066 }
1067
1068 sub continue {
1069   my $form     = $main::form;
1070   call_sub($form->{continue_nextsub} || $form->{nextsub});
1071 }
1072
1073 sub stock {
1074   my $form     = $main::form;
1075   call_sub($form->{stock_nextsub} || $form->{nextsub});
1076 }
1077
1078 sub setup_wh_transfer_warehouse_selection_action_bar {
1079   my ($action) = @_;
1080
1081   for my $bar ($::request->layout->get('actionbar')) {
1082     $bar->add(
1083       action => [
1084         t8('Update'),
1085         submit    => [ '#form', { action => $action } ],
1086         accesskey => 'enter',
1087       ],
1088     );
1089   }
1090 }
1091
1092 sub setup_wh_transfer_warehouse_selection_assembly_action_bar {
1093   my ($action) = @_;
1094
1095   for my $bar ($::request->layout->get('actionbar')) {
1096     $bar->add(
1097       action => [
1098         t8('Update'),
1099         submit    => [ '#form', { action => 'transfer_assembly_update_part' } ],
1100         accesskey => 'enter',
1101       ],
1102       action => [
1103         t8('Produce'),
1104         submit   => [ '#form', { action => 'create_assembly' } ],
1105         disabled => $::form->{parts_id} ? undef : $::locale->text('No assembly has been selected yet.'),
1106       ],
1107     );
1108   }
1109 }
1110
1111 sub setup_wh_transfer_parts_action_bar {
1112   my ($action) = @_;
1113
1114   for my $bar ($::request->layout->get('actionbar')) {
1115     $bar->add(
1116       action => [
1117         t8('Transfer'),
1118         submit    => [ '#form', { action => 'transfer_parts' } ],
1119         accesskey => 'enter',
1120       ],
1121       action => [
1122         t8('Back'),
1123         call => [ 'kivi.history_back' ],
1124       ],
1125     );
1126   }
1127 }
1128
1129 sub setup_wh_removal_parts_selection_action_bar {
1130   my ($action) = @_;
1131
1132   for my $bar ($::request->layout->get('actionbar')) {
1133     $bar->add(
1134       action => [
1135         t8('Transfer out'),
1136         submit    => [ '#form', { action => 'remove_parts' } ],
1137         accesskey => 'enter',
1138       ],
1139       action => [
1140         t8('Back'),
1141         call => [ 'kivi.history_back' ],
1142       ],
1143     );
1144   }
1145 }
1146
1147 sub setup_wh_report_action_bar {
1148   my ($action) = @_;
1149
1150   for my $bar ($::request->layout->get('actionbar')) {
1151     $bar->add(
1152       action => [
1153         t8('Show'),
1154         submit    => [ '#form', { action => 'generate_report' } ],
1155         accesskey => 'enter',
1156       ],
1157     );
1158   }
1159 }
1160
1161 sub setup_wh_journal_action_bar {
1162   my ($action) = @_;
1163
1164   for my $bar ($::request->layout->get('actionbar')) {
1165     $bar->add(
1166       action => [
1167         t8('Show'),
1168         submit    => [ '#form', { action => 'generate_journal' } ],
1169         accesskey => 'enter',
1170       ],
1171     );
1172   }
1173 }
1174
1175 1;
1176
1177 __END__
1178
1179 =head1 NAME
1180
1181 bin/mozilla/wh.pl - Warehouse frontend.
1182
1183 =head1 FUNCTIONS
1184
1185 =over 4
1186
1187 =item new_item
1188
1189 call new item dialogue from warehouse masks.
1190
1191 PARAMS:
1192   action  => name of sub to be called when new item is done
1193
1194 =back
1195
1196 =cut