1 package SL::Helper::PrintOptions;
5 use List::MoreUtils qw(any);
8 # generate the printing options displayed at the bottom of oe and is forms.
9 # this function will attempt to guess what type of form is displayed, and will generate according options
12 # this version builds the arrays of options pretty directly. if you have trouble understanding how,
13 # the opthash function builds hashrefs which are then pieced together for the template arrays.
14 # unneeded options are "undef"ed out, and then grepped out.
16 # the inline options is untested, but intended to be used later in metatemplating
17 sub get_print_options {
18 my ($class, %params) = @_;
20 my $form = $params{form} || $::form;
21 my $myconfig = $params{myconfig} || \%::myconfig;
22 my $locale = $params{locale} || $::locale;
23 my $options = $params{options};
25 # names 3 parameters and returns a hashref, for use in templates
26 sub opthash { +{ value => shift, selected => shift, oname => shift } }
27 my (@FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = ();
29 # note: "||"-selection is only correct for values where "0" is _not_ a correct entry
30 $form->{sendmode} = "attachment";
31 $form->{format} = $form->{format} || $myconfig->{template_format} || "pdf";
32 $form->{copies} = $form->{copies} || $myconfig->{copies} || 3;
33 $form->{media} = $form->{media} || $myconfig->{default_media} || "screen";
34 $form->{printer_id} = defined $form->{printer_id} ? $form->{printer_id} :
35 defined $myconfig->{default_printer_id} ? $myconfig->{default_printer_id} : "";
37 $form->{PD}{ $form->{formname} } = "selected";
38 $form->{DF}{ $form->{format} } = "selected";
39 $form->{OP}{ $form->{media} } = "selected";
40 $form->{SM}{ $form->{sendmode} } = "selected";
42 push @FORMNAME, grep $_,
43 ($form->{type} eq 'purchase_order') ? (
44 opthash("purchase_order", $form->{PD}{purchase_order}, $locale->text('Purchase Order')),
45 opthash("bin_list", $form->{PD}{bin_list}, $locale->text('Bin List'))
47 ($form->{type} eq 'credit_note') ?
48 opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef,
49 ($form->{type} eq 'sales_order') ? (
50 opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')),
51 opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
53 ($form->{type} =~ /sales_quotation$/) ?
54 opthash('sales_quotation', $form->{PD}{sales_quotation}, $locale->text('Quotation')) : undef,
55 ($form->{type} =~ /request_quotation$/) ?
56 opthash('request_quotation', $form->{PD}{request_quotation}, $locale->text('Request for Quotation')) : undef,
57 ($form->{type} eq 'invoice') ? (
58 opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')),
59 opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
61 ($form->{type} eq 'invoice' && $form->{storno}) ? (
62 opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')),
64 ($form->{type} =~ /_delivery_order$/) ? (
65 opthash($form->{type}, $form->{PD}{$form->{type}}, $locale->text('Delivery Order')),
66 opthash('pick_list', $form->{PD}{pick_list}, $locale->text('Pick List')),
70 opthash("attachment", $form->{SM}{attachment}, $locale->text('Attachment')),
71 opthash("inline", $form->{SM}{inline}, $locale->text('In-line'))
72 if ($form->{media} eq 'email');
74 my $printable_templates = any { $::lx_office_conf{print_templates}->{$_} } qw(latex opendocument);
76 opthash("screen", $form->{OP}{screen}, $locale->text('Screen')),
77 ($printable_templates && $form->{printers} && scalar @{ $form->{printers} }) ?
78 opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef,
79 ($printable_templates && !$options->{no_queue}) ?
80 opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef
81 if ($form->{media} ne 'email');
83 push @FORMAT, grep $_,
84 ($::lx_office_conf{print_templates}->{opendocument} && $::lx_office_conf{applications}->{openofficeorg_writer} && $::lx_office_conf{applications}->{xvfb}
85 && (-x $::lx_office_conf{applications}->{openofficeorg_writer}) && (-x $::lx_office_conf{applications}->{xvfb})
86 && !$options->{no_opendocument_pdf}) ?
87 opthash("opendocument_pdf", $form->{DF}{"opendocument_pdf"}, $locale->text("PDF (OpenDocument/OASIS)")) : undef,
88 ($::lx_office_conf{print_templates}->{latex}) ?
89 opthash("pdf", $form->{DF}{pdf}, $locale->text('PDF')) : undef,
90 ($::lx_office_conf{print_templates}->{latex} && !$options->{no_postscript}) ?
91 opthash("postscript", $form->{DF}{postscript}, $locale->text('Postscript')) : undef,
92 (!$options->{no_html}) ?
93 opthash("html", $form->{DF}{html}, "HTML") : undef,
94 ($::lx_office_conf{print_templates}->{opendocument} && !$options->{no_opendocument}) ?
95 opthash("opendocument", $form->{DF}{opendocument}, $locale->text("OpenDocument/OASIS")) : undef,
96 ($::lx_office_conf{print_templates}->{excel} && !$options->{no_excel}) ?
97 opthash("excel", $form->{DF}{excel}, $locale->text("Excel")) : undef;
100 map { opthash($_->{id}, ($_->{id} eq $form->{language_id} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }
101 if (ref $form->{languages} eq 'ARRAY');
104 map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} }
105 if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } });
110 show => !$options->{"hide_" . $_->[1]} && scalar @{ $_->[0] }
112 [ \@FORMNAME, 'formname', ],
113 [ \@LANGUAGE_ID, 'language_id', ],
114 [ \@FORMAT, 'format', ],
115 [ \@SENDMODE, 'sendmode', ],
116 [ \@MEDIA, 'media', ],
117 [ \@PRINTER_ID, 'printer_id', ];
119 my %dont_display_groupitems = (
124 my %template_vars = (
125 display_copies => scalar @{ $form->{printers} || [] } && $::lx_office_conf{print_templates}->{latex} && $form->{media} ne 'email',
126 display_remove_draft => (!$form->{id} && $form->{draft_id}),
127 display_groupitems => !$dont_display_groupitems{$form->{type}},
128 groupitems_checked => $form->{groupitems} ? "checked" : '',
129 remove_draft_checked => $form->{remove_draft} ? "checked" : ''
132 return $form->parse_html_template("generic/print_options", { SELECTS => \@SELECTS, %template_vars } );