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