use Carp;
use CGI;
-use List::MoreUtils qw(uniq);
+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";
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
qw(sellprice listprice weight);
- $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
$form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"});
if ($form->{"not_discountable_$i"}) {
# 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();
}
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');
call_sub($display_form);
# saving the history
if(!exists $form->{addition}) {
- $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
+ $form->{snumbers} = "${inv}number" . "_" . $form->{"${inv}number"};
$form->{addition} = "PRINTED";
$form->save_history;
}
# create the form variables
if ($form->{type} =~ /_delivery_order$/) {
- DO->order_details();
+ DO->order_details(\%myconfig, \%$form);
} elsif ($order) {
OE->order_details(\%myconfig, \%$form);
} else {
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,
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;
- $filename .= $suffix;
- $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
- $form->{OUT_MODE} = '>';
+ 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 {
my $temp_fh;
($temp_fh, $filename) = File::Temp::tempfile(
'kivitendo-spoolXXXXXX',
SUFFIX => "$suffix",
- DIR => $::lx_office_conf{paths}->{spool},
+ DIR => $::lx_office_conf{paths}->{spool},
+ UNLINK => 0,
);
close $temp_fh;
$form->{OUT} = "$filename";
# saving the history
if(!exists $form->{addition}) {
- $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
+ $form->{snumbers} = "${inv}number" . "_" . $form->{"${inv}number"};
if($form->{media} =~ /printer/) {
$form->{addition} = "PRINTED";
}
# prepare meta information for template introspection
$form->{template_meta} = {
formname => $form->{formname},
- language => SL::DB::Manager::Language->find_by_or_create(id => $form->{language_id}),
+ language => SL::DB::Manager::Language->find_by_or_create(id => $form->{language_id} || undef),
format => $form->{format},
media => $form->{media},
extension => $extension,
- printer => SL::DB::Manager::Printer->find_by_or_create(id => $form->{printer_id}),
+ printer => SL::DB::Manager::Printer->find_by_or_create(id => $form->{printer_id} || undef),
today => DateTime->today,
};
my $invdate = $form->{invdate} eq 'undefined' ? undef : $form->{invdate};
my $duedate = $form->get_duedate(\%myconfig, $invdate);
- print $form->ajax_response_header() . $duedate;
+ print $form->ajax_response_header() . ($duedate || $invdate);
$main::lxdebug->leave_sub();
}
$main::lxdebug->leave_sub(2);
}
+
+sub _remove_billed_or_delivered_rows {
+ my (%params) = @_;
+
+ croak "Missing parameter 'quantities'" if !$params{quantities};
+
+ my @fields = map { s/_1$//; $_ } grep { m/_1$/ } keys %{ $::form };
+ my @new_rows;
+
+ my $removed_rows = 0;
+ my $row = 0;
+ while ($row < $::form->{rowcount}) {
+ $row++;
+ next unless $::form->{"id_$row"};
+
+ my $parts_id = $::form->{"id_$row"};
+ my $base_qty = $::form->parse_amount(\%::myconfig, $::form->{"qty_$row"}) * SL::DB::Manager::Unit->find_by(name => $::form->{"unit_$row"})->base_factor;
+
+ my $sub_qty = min($base_qty, $params{quantities}->{$parts_id});
+ $params{quantities}->{$parts_id} -= $sub_qty;
+
+ if (!$sub_qty || ($sub_qty != $base_qty)) {
+ $::form->{"qty_${row}"} = $::form->format_amount(\%::myconfig, ($base_qty - $sub_qty) / SL::DB::Manager::Unit->find_by(name => $::form->{"unit_$row"})->base_factor);
+ push @new_rows, { map { $_ => $::form->{"${_}_${row}"} } @fields };
+
+ } else {
+ $removed_rows++;
+ }
+ }
+
+ $::form->redo_rows(\@fields, \@new_rows, scalar(@new_rows), $::form->{rowcount});
+ $::form->{rowcount} -= $removed_rows;
+}