use Cwd;
use Encode;
use File::Copy;
+use File::Temp ();
use IO::File;
use Math::BigInt;
use POSIX qw(strftime);
local (*IN, *OUT);
- my $defaults = SL::DB::Default->get;
- my $userspath = $::lx_office_conf{paths}->{userspath};
+ my $defaults = SL::DB::Default->get;
- $self->{"cwd"} = getcwd();
- $self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
+ my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
+ $self->{cwd} = getcwd();
+ my $temp_dir = File::Temp->newdir(
+ "kivitendo-print-XXXXXX",
+ DIR => $self->{cwd} . "/" . $::lx_office_conf{paths}->{userspath},
+ CLEANUP => !$keep_temp_files,
+ );
+
+ my $userspath = File::Spec->abs2rel($temp_dir->dirname);
+ $self->{tmpdir} = $temp_dir->dirname;
my $ext_for_format;
$template_type = 'HTML';
$ext_for_format = 'html';
- } elsif (($self->{"format"} =~ /xml/i) || (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
- $template_type = 'XML';
- $ext_for_format = 'xml';
-
- } elsif ( $self->{"format"} =~ /elster(?:winston|taxbird)/i ) {
- $template_type = 'XML';
-
} elsif ( $self->{"format"} =~ /excel/i ) {
$template_type = 'Excel';
$ext_for_format = 'xls';
# OUT is used for the media, screen, printer, email
# for postscript we store a copy in a temporary file
- my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
my ($temp_fh, $suffix);
$suffix = $self->{IN};
if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
$mail->{content_type} = "text/html";
$mail->{message} =~ s/\r//g;
- $mail->{message} =~ s/\n/<br>\n/g;
- $full_signature =~ s/\n/<br>\n/g;
+ $mail->{message} =~ s{\n}{<br>\n}g;
+ $full_signature =~ s{\n}{<br>\n}g;
$mail->{message} .= $full_signature;
open(IN, "<", $self->{tmpfile})
} elsif (($self->{attachment_policy} // '') ne 'no_file') {
my $attachment_name = $self->{attachment_filename} || $self->{tmpfile};
- $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
+ $attachment_name =~ s{\.(.+?)$}{.${ext_for_format}} if ($ext_for_format);
if (($self->{attachment_policy} // '') eq 'old_file') {
my ( $attfile ) = SL::File->get_all(object_id => $self->{id},
return if !$shipto;
+ # shiptocp_gender only makes sense, if any other shipto attribute is set.
+ # Because shiptocp_gender is set to 'm' by default in forms
+ # it must not be considered above to decide if shiptos has to be added or
+ # updated, but must be inserted or updated as well in case.
+ push(@values, $self->{shiptocp_gender});
+
my $shipto_id = $self->{shipto_id};
if ($self->{shipto_id}) {
$main::lxdebug->leave_sub();
}
-sub _get_shipto {
- $main::lxdebug->enter_sub();
-
- my ($self, $dbh, $vc_id, $key) = @_;
-
- $key = "all_shipto" unless ($key);
-
- if ($vc_id) {
- # get shipping addresses
- my $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
-
- $self->{$key} = selectall_hashref_query($self, $dbh, $query, $vc_id);
-
- } else {
- $self->{$key} = [];
- }
-
- $main::lxdebug->leave_sub();
-}
-
sub _get_printers {
$main::lxdebug->enter_sub();
$main::lxdebug->leave_sub();
}
-#sub _get_groups {
-# $main::lxdebug->enter_sub();
-#
-# my ($self, $dbh, $key) = @_;
-#
-# $key ||= "all_groups";
-#
-# my $groups = $main::auth->read_groups();
-#
-# $self->{$key} = selectall_hashref_query($self, $dbh, $query);
-#
-# $main::lxdebug->leave_sub();
-#}
-
sub get_lists {
$main::lxdebug->enter_sub();
my $self = shift;
my %params = @_;
+ croak "get_lists: shipto is no longer supported" if $params{shipto};
+
my $dbh = $self->get_standard_dbh(\%main::myconfig);
my ($sth, $query, $ref);
my ($vc, $vc_id);
- if ($params{contacts} || $params{shipto}) {
+ if ($params{contacts}) {
$vc = 'customer' if $self->{"vc"} eq "customer";
$vc = 'vendor' if $self->{"vc"} eq "vendor";
die "invalid use of get_lists, need 'vc'" unless $vc;
$self->_get_contacts($dbh, $vc_id, $params{"contacts"});
}
- if ($params{"shipto"}) {
- $self->_get_shipto($dbh, $vc_id, $params{"shipto"});
- }
-
if ($params{"projects"} || $params{"all_projects"}) {
$self->_get_projects($dbh, $params{"all_projects"} ?
$params{"all_projects"} : $params{"projects"},
$self->_get_warehouses($dbh, $params{warehouses});
}
-# if ($params{groups}) {
-# $self->_get_groups($dbh, $params{groups});
-# }
-
if ($params{partsgroup}) {
$self->get_partsgroup(\%main::myconfig, { all => 1, target => $params{partsgroup} });
}