X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FHelper%2FPrintOptions.pm;h=9108a224e623abfd0841a5cc6ceb23f1799c49d2;hb=549f187d3a2b1d15f96c4556714666ed954447bb;hp=430425a29965962165535d9cb44848519c8ae0c4;hpb=2500bc30ea2952fdd9b8ff07b8bad697032ab76f;p=kivitendo-erp.git diff --git a/SL/Helper/PrintOptions.pm b/SL/Helper/PrintOptions.pm index 430425a29..9108a224e 100644 --- a/SL/Helper/PrintOptions.pm +++ b/SL/Helper/PrintOptions.pm @@ -4,6 +4,7 @@ use strict; use List::MoreUtils qw(any); +sub opthash { +{ value => shift, selected => shift, oname => shift } } # generate the printing options displayed at the bottom of oe and is forms. # this function will attempt to guess what type of form is displayed, and will generate according options @@ -17,13 +18,18 @@ use List::MoreUtils qw(any); sub get_print_options { my ($class, %params) = @_; + no warnings 'once'; + my $form = $params{form} || $::form; my $myconfig = $params{myconfig} || \%::myconfig; my $locale = $params{locale} || $::locale; my $options = $params{options}; + use warnings 'once'; + + my $prefix = $options->{dialog_name_prefix} || ''; + # names 3 parameters and returns a hashref, for use in templates - sub opthash { +{ value => shift, selected => shift, oname => shift } } my (@FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = (); # note: "||"-selection is only correct for values where "0" is _not_ a correct entry @@ -49,6 +55,7 @@ sub get_print_options { ($form->{type} eq 'sales_order') ? ( opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')), opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')), + opthash("ic_supply", $form->{PD}{ic_supply}, $locale->text('Intra-Community supply')), ) : undef, ($form->{type} =~ /sales_quotation$/) ? opthash('sales_quotation', $form->{PD}{sales_quotation}, $locale->text('Quotation')) : undef, @@ -57,13 +64,26 @@ sub get_print_options { ($form->{type} eq 'invoice') ? ( opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')), opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')), + opthash("invoice_copy", $form->{PD}{invoice_copy}, $locale->text('Invoice Copy')), ) : undef, ($form->{type} eq 'invoice' && $form->{storno}) ? ( opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')), ) : undef, - ($form->{type} =~ /_delivery_order$/) ? ( + ($form->{type} eq 'invoice_for_advance_payment') ? ( + opthash("invoice_for_advance_payment", $form->{PD}{invoice_for_advance_payment}, $locale->text('Invoice for Advance Payment')), + ) : undef, + ($form->{type} eq 'final_invoice') ? ( + opthash("final_invoice", $form->{PD}{final_invoice}, $locale->text('Final Invoice')), + ) : undef, + ($form->{type} =~ /^supplier_delivery_order$/) ? ( + opthash('supplier_delivery_order', $form->{PD}{supplier_delivery_order}, $locale->text('Supplier Delivery Order')), + ) : undef, + ($form->{type} =~ /(sales|purchase)_delivery_order$/) ? ( opthash($form->{type}, $form->{PD}{$form->{type}}, $locale->text('Delivery Order')), opthash('pick_list', $form->{PD}{pick_list}, $locale->text('Pick List')), + ) : undef, + ($form->{type} =~ /^letter$/) ? ( + opthash('letter', $form->{PD}{letter}, $locale->text('Letter')), ) : undef; push @SENDMODE, @@ -105,33 +125,129 @@ sub get_print_options { if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } }); @SELECTS = map { - sname => $_->[1], - DATA => $_->[0], - show => !$options->{"hide_" . $_->[1]} && scalar @{ $_->[0] } + sname => $_->[1], + DATA => $_->[0], + show => !$options->{"hide_" . $_->[1]} && scalar @{ $_->[0]}, + hname => $locale->text($_->[2]) }, - [ \@FORMNAME, 'formname', ], - [ \@LANGUAGE_ID, 'language_id', ], - [ \@FORMAT, 'format', ], - [ \@SENDMODE, 'sendmode', ], - [ \@MEDIA, 'media', ], - [ \@PRINTER_ID, 'printer_id', ]; + [ \@FORMNAME, 'formname', 'Formname' ], + [ \@LANGUAGE_ID, 'language_id', 'Language' ], + [ \@FORMAT, 'format', 'Format' ], + [ \@SENDMODE, 'sendmode', 'Sendmode' ], + [ \@MEDIA, 'media', 'Media' ], + [ \@PRINTER_ID, 'printer_id', 'Printer' ]; my %dont_display_groupitems = ( 'dunning' => 1, - 'letter' => 1, ); my %template_vars = ( + name_prefix => $prefix || '', + show_headers => $options->{show_headers}, display_copies => scalar @{ $form->{printers} || [] } && $::lx_office_conf{print_templates}->{latex} && $form->{media} ne 'email', display_remove_draft => (!$form->{id} && $form->{draft_id}), display_groupitems => !$dont_display_groupitems{$form->{type}}, + display_bothsided => $options->{show_bothsided}, groupitems_checked => $form->{groupitems} ? "checked" : '', + bothsided_checked => $form->{bothsided} ? "checked" : '', remove_draft_checked => $form->{remove_draft} ? "checked" : '' ); return $form->parse_html_template("generic/print_options", { SELECTS => \@SELECTS, %template_vars } ); } - 1; +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::Helper::PrintOptions - A helper for generating the print options for +templates + +=head1 SYNOPSIS + + # render your template with print_options + $self->render('letter/edit', + %params, + letter => $letter, + print_options => SL::Helper::PrintOptions->get_print_options ( + options => { no_postscript => 1, + no_opendocument => 1, + no_html => 1, + no_queue => 1 }), + + ); + +Then, in the template, you can render the options with + C<[% print_options %]>. Look at the template + C to see, which variables you get back. + +=head1 FUNCTIONS + +=over 4 + +=item C + +Parses the template C. It does some guessings + and settings according to the params, (namely C
). + + +The recognized parameters are: + +=over 2 + +=item * C: defaults to $::form if not given. There are several + keys in C which control the output of the options, + e.g. C, C, C, C, C, + C, C, ... + +=item * C: defaults to %::myconfig + +=item * C: defaults to $::locale + +=item * C: Options can be: + +* C: a string prefixed to the template + variables. E.g. if prefix is C the value for copies + returned from the user is in $::form->{mypref_copies} + +* C: render headings for the input elements + +* C: if set, do not show option for printing to queue + +* C: if set, do not show option for printing + opendocument format + +* C: if set, do not show option for printing + postscript format + +* C: if set, do not show option for printing + html format + +* C + +* C + +* and some more + +=back + +=back + +=head1 AUTHOR + +? + +Bernd Bleßmann Ebernd@kivitendo-premium.deE (I just moved + it from io.pl to here and did some minor changes) + +=head1 BUGS + +incomplete documentation + +=cut