use Carp;
use CGI;
+use List::MoreUtils qw(any uniq);
use List::Util qw(min max first);
use SL::CVar;
use SL::DB::Language;
use SL::DB::Printer;
+use SL::Helper::Flash;
require "bin/mozilla/common.pl";
# adjust prices by unit, ignore if pricegroup changed
if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) {
$form->{"sellprice_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
+ $form->{"lastcost_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1;
$form->{"unit_old_$i"} = $form->{"selected_unit_$i"};
}
my $this_unit = $form->{"unit_$i"};
$column_data{"unit"} = AM->unit_select_html($all_units, "unit_$i", $this_unit, $form->{"id_$i"} ? $form->{"unit_$i"} : undef);
# / unit ending
+#count the max of decimalplaces of sellprice and lastcost, so the same number of decimalplaces
+#is shown for lastcost and sellprice.
my $decimalplaces = ($form->{"sellprice_$i"} =~ /\.(\d+)/) ? max 2, length $1 : 2;
+ $decimalplaces = ($form->{"lastcost_$i"} =~ /\.(\d+)/) ? max $decimalplaces, length $1 : $decimalplaces;
my $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || 1;
my $discount = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100 / $price_factor, 2);
} else {
$real_sellprice = $linetotal;
};
- my $real_lastcost = $form->{"lastcost_$i"} * $form->{"qty_$i"} / ( $form->{"marge_price_factor_$i"} || 1 );
+ my $real_lastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"} / $price_factor, 2);
my $marge_percent_warn = $myconfig{marge_percent_warn} * 1 || 15;
my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
<b>%s</b> <input size="5" name="lastcost_$i" value="%s">|,
$marge_color, $locale->text('Ertrag'),$form->{"marge_absolut_$i"}, $form->{"marge_percent_$i"},
$locale->text('LP'), $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2),
- $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2) }
+ $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces) }
if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ || $form->{type} =~ /invoice/ || $form->{type} =~ /^credit_note$/ ) && !$is_delivery_order;
$form->{"listprice_$i"} = $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2)
} @{ $::form->{item_list} };
# delete action variable
- delete @{$::form}{qw(action item_list header)};
+ delete @{$::form}{qw(action item_list)};
print $::form->parse_html_template('io/select_item', { PREVIOUS_FORM => $previous_form,
MODE => $mode,
# check if items are valid
if ($form->{rowcount} == 1) {
+ flash('warning', $::locale->text('The action you\'ve chosen has not been executed because the document does not contain any item yet.'));
&update;
::end_of_request();
}
my $attachment_filename = $form->generate_attachment_filename();
my $subject = $form->{subject} || $form->generate_email_subject();
- $form->{"fokus"} = $form->{"email"} ? "Form.subject" : "Form.email";
+ $::request->{layout}->focus($form->{"email"} ? "#subject" : "#email");
$form->header;
my (@dont_hide_key_list, %dont_hide_key, @hidden_keys);
opthash("inline", $form->{SM}{inline}, $locale->text('In-line'))
if ($form->{media} eq 'email');
+ my $printable_templates = any { $::lx_office_conf{print_templates}->{$_} } qw(latex opendocument);
push @MEDIA, grep $_,
opthash("screen", $form->{OP}{screen}, $locale->text('Screen')),
- ($form->{printers} && scalar @{ $form->{printers} } && $::lx_office_conf{print_templates}->{latex}) ?
+ ($printable_templates && $form->{printers} && scalar @{ $form->{printers} }) ?
opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef,
- ($::lx_office_conf{print_templates}->{latex} && !$options{no_queue}) ?
+ ($printable_templates && !$options{no_queue}) ?
opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef
if ($form->{media} ne 'email');
reformat_numbers($output_numberformat, 2,
qw(invtotal ordtotal quototal subtotal linetotal
listprice sellprice netprice discount
- tax taxbase total paid),
+ tax taxbase total paid payment),
grep({ /^(?:linetotal|nodiscount_linetotal|listprice|sellprice|netprice|taxbase|discount|p_discount|discount_sub|nodiscount_sub|paid|subtotal|total|tax)_\d+$/ } keys(%{$form})));
reformat_numbers($output_numberformat, undef,
push @template_files, "$form->{formname}$form->{language}$printer_code.$extension";
push @template_files, "$form->{formname}.$extension";
push @template_files, "default.$extension";
-
- $form->{IN} = undef;
- for my $filename (@template_files) {
- if (-f "$myconfig{templates}/$filename") {
- $form->{IN} = $filename;
- last;
- }
- }
+ @template_files = uniq @template_files;
+ $form->{IN} = first { -f "$myconfig{templates}/$_" } @template_files;
if (!defined $form->{IN}) {
$::form->error($::locale->text('Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.', join ', ', map { "'$_'"} @template_files));
my $emailed = $form->{emailed};
if ($form->{media} eq 'queue') {
- my %queued = map { s|.*/|| } split / /, $form->{queued};
+ my %queued = map { s|.*[/\\]||; $_ } split / /, $form->{queued};
my $filename;
+ my $suffix = ($form->{postscript}) ? '.ps' : '.pdf';
if ($filename = $queued{ $form->{formname} }) {
- $form->{queued} =~ s/\Q$form->{formname} $filename\E//;
unlink $::lx_office_conf{paths}->{spool} . "/$filename";
- $filename =~ s/\..*$//g;
+ delete $queued{ $form->{formname} };
+
+ $form->{queued} = join ' ', %queued;
+ $filename =~ s/\..*$//g;
+ $filename .= $suffix;
+ $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
+ $form->{OUT_MODE} = '>';
+
} else {
- $filename = time;
- $filename .= $$;
+ my $temp_fh;
+ ($temp_fh, $filename) = File::Temp::tempfile(
+ 'kivitendo-spoolXXXXXX',
+ SUFFIX => "$suffix",
+ DIR => $::lx_office_conf{paths}->{spool},
+ UNLINK => 0,
+ );
+ close $temp_fh;
+ $form->{OUT} = "$filename";
+ # use >> for OUT_MODE because file is already created by File::Temp
+ $form->{OUT_MODE} = '>>';
+ # strip directory so that only filename is stored in table status
+ ($filename) = $filename =~ /^$::lx_office_conf{paths}->{spool}\/(.*)/;
}
- $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
- $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
- $form->{OUT_MODE} = '>';
-
# add type
$form->{queued} .= " $form->{formname} $filename";
-
$form->{queued} =~ s/^ //;
}
my $queued = $form->{queued};