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