X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=582d2aff8edc33ee04ca949fd389de145558d644;hb=35948584de818b00974b9dab65682c4d5ceba67f;hp=fbd1d8554fe86ca666c921e31fff5b5f189c2d22;hpb=1de53cbf8a926ae3ae89bc5466ab660df82484b2;p=kivitendo-erp.git
diff --git a/SL/Form.pm b/SL/Form.pm
index fbd1d8554..582d2aff8 100644
--- a/SL/Form.pm
+++ b/SL/Form.pm
@@ -42,21 +42,31 @@ use Data::Dumper;
use CGI;
use CGI::Ajax;
use Cwd;
+use Encode;
+use File::Copy;
use IO::File;
use SL::Auth;
use SL::Auth::DB;
use SL::Auth::LDAP;
use SL::AM;
use SL::Common;
+use SL::CVar;
+use SL::DB;
+use SL::DBConnect;
use SL::DBUtils;
+use SL::DO;
+use SL::IC;
+use SL::IS;
use SL::Mailer;
use SL::Menu;
+use SL::OE;
use SL::Template;
use SL::User;
+use SL::X;
use Template;
use URI;
use List::Util qw(first max min sum);
-use List::MoreUtils qw(any);
+use List::MoreUtils qw(all any apply);
use strict;
@@ -125,6 +135,7 @@ sub _request_to_hash {
my $self = shift;
my $input = shift;
+ my $uploads = {};
if (!$ENV{'CONTENT_TYPE'}
|| ($ENV{'CONTENT_TYPE'} !~ /multipart\/form-data\s*;\s*boundary\s*=\s*(.+)$/)) {
@@ -132,7 +143,7 @@ sub _request_to_hash {
$self->_input_to_hash($input);
$main::lxdebug->leave_sub(2);
- return;
+ return $uploads;
}
my ($name, $filename, $headers_done, $content_type, $boundary_found, $need_cr, $previous);
@@ -177,7 +188,7 @@ sub _request_to_hash {
substr $line, $-[0], $+[0] - $-[0], "";
}
- $previous = $self->_store_value($name, '') if ($name);
+ $previous = _store_value($uploads, $name, '') if ($name);
$self->{FILENAME} = $filename if ($filename);
next;
@@ -198,6 +209,8 @@ sub _request_to_hash {
${ $previous } =~ s|\r?\n$|| if $previous;
$main::lxdebug->leave_sub(2);
+
+ return $uploads;
}
sub _recode_recursively {
@@ -248,13 +261,14 @@ sub new {
$self->_input_to_hash($ENV{QUERY_STRING}) if $ENV{QUERY_STRING};
$self->_input_to_hash($ARGV[0]) if @ARGV && $ARGV[0];
+ my $uploads;
if ($ENV{CONTENT_LENGTH}) {
my $content;
read STDIN, $content, $ENV{CONTENT_LENGTH};
- $self->_request_to_hash($content);
+ $uploads = $self->_request_to_hash($content);
}
- my $db_charset = $main::dbcharset;
+ my $db_charset = $::lx_office_conf{system}->{dbcharset};
$db_charset ||= Common::DEFAULT_CHARSET;
my $encoding = $self->{INPUT_ENCODING} || $db_charset;
@@ -262,13 +276,12 @@ sub new {
_recode_recursively(SL::Iconv->new($encoding, $db_charset), $self);
- $self->{action} = lc $self->{action};
- $self->{action} =~ s/( |-|,|\#)/_/g;
+ map { $self->{$_} = $uploads->{$_} } keys %{ $uploads } if $uploads;
#$self->{version} = "2.6.1"; # Old hardcoded but secure style
open VERSION_FILE, "VERSION"; # New but flexible code reads version from VERSION-file
$self->{version} =
/g;
$self->show_generic_error($msg);
@@ -475,7 +500,7 @@ sub info {
print qq|
-
+
-
+
|; @@ -592,143 +617,107 @@ sub create_http_response { pop @segments; $uri->path_segments(@segments); - my $session_cookie_value = $main::auth->get_session_id(); - $session_cookie_value ||= 'NO_SESSION'; + my $session_cookie_value = $main::auth->get_session_id(); - $session_cookie = $cgi->cookie('-name' => $main::auth->get_session_cookie_name(), - '-value' => $session_cookie_value, - '-path' => $uri->path, - '-secure' => $ENV{HTTPS}); + if ($session_cookie_value) { + $session_cookie = $cgi->cookie('-name' => $main::auth->get_session_cookie_name(), + '-value' => $session_cookie_value, + '-path' => $uri->path, + '-secure' => $ENV{HTTPS}); + } } my %cgi_params = ('-type' => $params{content_type}); $cgi_params{'-charset'} = $params{charset} if ($params{charset}); + $cgi_params{'-cookie'} = $session_cookie if ($session_cookie); + + map { $cgi_params{'-' . $_} = $params{$_} if exists $params{$_} } qw(content_disposition content_length); - my $output = $cgi->header('-cookie' => $session_cookie, - %cgi_params); + my $output = $cgi->header(%cgi_params); $main::lxdebug->leave_sub(); return $output; } +sub use_stylesheet { + my $self = shift; + + $self->{stylesheet} = [ $self->{stylesheet} ] unless ref $self->{stylesheet} eq 'ARRAY'; + $self->{stylesheet} = [ grep { -f } + map { m:^css/: ? $_ : "css/$_" } + grep { $_ } + (@{ $self->{stylesheet} }, @_) + ]; + + return @{ $self->{stylesheet} }; +} sub header { - $main::lxdebug->enter_sub(); + $::lxdebug->enter_sub; - # extra code ist currently only used by menuv3 and menuv4 to set their css. + # extra code is currently only used by menuv3 and menuv4 to set their css. # it is strongly deprecated, and will be changed in a future version. my ($self, $extra_code) = @_; - - if ($self->{header}) { - $main::lxdebug->leave_sub(); - return; - } - - my ($stylesheet, $favicon, $pagelayout); - - if ($ENV{HTTP_USER_AGENT}) { - my $doctype; - - if ($ENV{'HTTP_USER_AGENT'} =~ m/MSIE\s+\d/) { - # Only set the DOCTYPE for Internet Explorer. Other browsers have problems displaying the menu otherwise. - $doctype = qq|\n|; - } - - my $stylesheets = "$self->{stylesheet} $self->{stylesheets}"; - - $stylesheets =~ s|^\s*||; - $stylesheets =~ s|\s*$||; - foreach my $file (split m/\s+/, $stylesheets) { - $file =~ s|.*/||; - next if (! -f "css/$file"); - - $stylesheet .= qq|\n|; - } - - $self->{favicon} = "favicon.ico" unless $self->{favicon}; - - if ($self->{favicon} && (-f "$self->{favicon}")) { - $favicon = - qq| - |; - } - - my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET; - - if ($self->{landscape}) { - $pagelayout = qq||; - } - - my $fokus = qq| + my $db_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET; + my @header; + + $::lxdebug->leave_sub and return if !$ENV{HTTP_USER_AGENT} || $self->{header}++; + + $self->{favicon} ||= "favicon.ico"; + $self->{titlebar} = "$self->{title} - $self->{titlebar}" if $self->{title}; + + # build includes + if ($self->{refresh_url} || $self->{refresh_time}) { + my $refresh_time = $self->{refresh_time} || 3; + my $refresh_url = $self->{refresh_url} || $ENV{REFERER}; + push @header, ""; + } + + push @header, map { qq|| } $self->use_stylesheet; + + push @header, "" if $self->{landscape}; + push @header, "" if -f $self->{favicon}; + push @header, '', + '', + '', + '', + '', + '', + ''; + push @header, $self->{javascript} if $self->{javascript}; + push @header, map { $_->show_javascript } @{ $self->{AJAX} || [] }; + push @header, "" if $self->{fokus}; + push @header, sprintf "", + join ' - ', grep $_, $self->{title}, $self->{login}, $::myconfig{dbname}, $self->{version} if $self->{title}; + + # if there is a title, we put some JavaScript in to the page, wich writes a + # meaningful title-tag for our frameset. + my $title_hack = ''; + if ($self->{title}) { + $title_hack = qq| - | if $self->{"fokus"}; - - # if there is a title, we put some JavaScript in to the page, wich writes a - # meaningful title-tag for our frameset. - my $title_hack; - if ($self->{"title"}){ - $title_hack = qq| - - |; - } - - #Set Calendar - my $jsscript = ""; - if ($self->{jsscript} == 1) { - - $jsscript = qq| - - - - - - - $self->{javascript} - |; - } - - $self->{titlebar} = - ($self->{title}) - ? "$self->{title} - $self->{titlebar}" - : $self->{titlebar}; - my $ajax = ""; - for my $item (@ { $self->{AJAX} || [] }) { - $ajax .= $item->show_javascript(); - } + |; + } - print $self->create_http_response('content_type' => 'text/html', - 'charset' => $db_charset,); - print qq|${doctype} -
-
+ # output
+ print $self->create_http_response(content_type => 'text/html', charset => $db_charset);
+ print "\n"
+ if $ENV{'HTTP_USER_AGENT'} =~ m/MSIE\s+\d/; # Other browsers may choke on menu scripts with DOCTYPE.
+ print <$info
|);
- ::end_of_request();
- }
-
$file = "templates/webpages/${file}.html";
} else {
- my $info = "Web page template '${file}' not found.\n" .
- "Please re-run 'locales.pl' in 'locale/${language}'.";
- print(qq|$info
|);
+ my $info = "Web page template '${file}' not found.\n";
+ print qq|$info
|;
::end_of_request();
}
@@ -829,22 +808,25 @@ sub _prepare_html_template {
}
if (%main::myconfig) {
- map({ $additional_params->{"myconfig_${_}"} = $main::myconfig{$_}; } keys(%main::myconfig));
- my $jsc_dateformat = $main::myconfig{"dateformat"};
- $jsc_dateformat =~ s/d+/\%d/gi;
- $jsc_dateformat =~ s/m+/\%m/gi;
- $jsc_dateformat =~ s/y+/\%Y/gi;
- $additional_params->{"myconfig_jsc_dateformat"} = $jsc_dateformat;
+ $::myconfig{jsc_dateformat} = apply {
+ s/d+/\%d/gi;
+ s/m+/\%m/gi;
+ s/y+/\%Y/gi;
+ } $::myconfig{"dateformat"};
$additional_params->{"myconfig"} ||= \%::myconfig;
+ map { $additional_params->{"myconfig_${_}"} = $main::myconfig{$_}; } keys %::myconfig;
}
- $additional_params->{"conf_dbcharset"} = $main::dbcharset;
- $additional_params->{"conf_webdav"} = $main::webdav;
- $additional_params->{"conf_lizenzen"} = $main::lizenzen;
- $additional_params->{"conf_latex_templates"} = $main::latex;
- $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates;
- $additional_params->{"conf_vertreter"} = $main::vertreter;
- $additional_params->{"conf_show_best_before"} = $main::show_best_before;
+ $additional_params->{"conf_dbcharset"} = $::lx_office_conf{system}->{dbcharset};
+ $additional_params->{"conf_webdav"} = $::lx_office_conf{features}->{webdav};
+ $additional_params->{"conf_lizenzen"} = $::lx_office_conf{features}->{lizenzen};
+ $additional_params->{"conf_latex_templates"} = $::lx_office_conf{print_templates}->{latex};
+ $additional_params->{"conf_opendocument_templates"} = $::lx_office_conf{print_templates}->{opendocument};
+ $additional_params->{"conf_vertreter"} = $::lx_office_conf{features}->{vertreter};
+ $additional_params->{"conf_show_best_before"} = $::lx_office_conf{features}->{show_best_before};
+ $additional_params->{"conf_parts_image_css"} = $::lx_office_conf{features}->{parts_image_css};
+ $additional_params->{"conf_parts_listing_images"} = $::lx_office_conf{features}->{parts_listing_images};
+ $additional_params->{"conf_parts_show_image"} = $::lx_office_conf{features}->{parts_show_image};
if (%main::debug_options) {
map { $additional_params->{'DEBUG_' . uc($_)} = $main::debug_options{$_} } keys %main::debug_options;
@@ -894,7 +876,7 @@ sub init_template {
'PLUGIN_BASE' => 'SL::Template::Plugin',
'INCLUDE_PATH' => '.:templates/webpages',
'COMPILE_EXT' => '.tcc',
- 'COMPILE_DIR' => $::userspath . '/templates-cache',
+ 'COMPILE_DIR' => $::lx_office_conf{paths}->{userspath} . '/templates-cache',
})) || die;
}
@@ -909,6 +891,12 @@ sub show_generic_error {
my ($self, $error, %params) = @_;
+ if ($self->{__ERROR_HANDLER}) {
+ $self->{__ERROR_HANDLER}->($error);
+ $main::lxdebug->leave_sub();
+ return;
+ }
+
my $add_params = {
'title_error' => $params{title},
'label_error' => $error,
@@ -1013,17 +1001,13 @@ sub redirect {
my ($self, $msg) = @_;
if (!$self->{callback}) {
-
$self->info($msg);
- ::end_of_request();
- }
-# my ($script, $argv) = split(/\?/, $self->{callback}, 2);
-# $script =~ s|.*/||;
-# $script =~ s|[^a-zA-Z0-9_\.]||g;
-# exec("perl", "$script", $argv);
+ } else {
+ print $::form->redirect_header($self->{callback});
+ }
- print $::form->redirect_header($self->{callback});
+ ::end_of_request();
$main::lxdebug->leave_sub();
}
@@ -1180,7 +1164,7 @@ sub parse_amount {
if ( ($myconfig->{numberformat} eq '1.000,00')
|| ($myconfig->{numberformat} eq '1000,00')) {
$amount =~ s/\.//g;
- $amount =~ s/,/\./;
+ $amount =~ s/,/\./g;
}
if ($myconfig->{numberformat} eq "1'000.00") {
@@ -1191,7 +1175,9 @@ sub parse_amount {
$main::lxdebug->leave_sub(2);
- return ($amount * 1);
+ # Make sure no code wich is not a math expression ends up in eval().
+ return 0 unless $amount =~ /^ [\s \d \( \) \- \+ \* \/ \. ]* $/x;
+ return scalar(eval($amount)) * 1 ;
}
sub round_amount {
@@ -1218,11 +1204,13 @@ sub round_amount {
sub parse_template {
$main::lxdebug->enter_sub();
- my ($self, $myconfig, $userspath) = @_;
+ my ($self, $myconfig) = @_;
my $out;
local (*IN, *OUT);
+ my $userspath = $::lx_office_conf{paths}->{userspath};
+
$self->{"cwd"} = getcwd();
$self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
@@ -1247,7 +1235,7 @@ sub parse_template {
$ext_for_format = 'xml';
} elsif ( $self->{"format"} =~ /elster(?:winston|taxbird)/i ) {
- $template_type = 'xml';
+ $template_type = 'XML';
} elsif ( $self->{"format"} =~ /excel/i ) {
$template_type = 'Excel';
@@ -1277,6 +1265,7 @@ sub parse_template {
}
map { $self->{"${_}"} = $myconfig->{$_}; } qw(co_ustid);
+ map { $self->{"myconfig_${_}"} = $myconfig->{$_} } grep { $_ ne 'dbpasswd' } keys %{ $myconfig };
$self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
@@ -1318,6 +1307,16 @@ sub parse_template {
$self->error("$self->{IN} : " . $template->get_error());
}
+ if ($self->{media} eq 'file') {
+ copy(join('/', $self->{cwd}, $userspath, $self->{tmpfile}), $out =~ m|^/| ? $out : join('/', $self->{cwd}, $out)) if $template->uses_temp_file;
+ $self->cleanup;
+ chdir("$self->{cwd}");
+
+ $::lxdebug->leave_sub();
+
+ return;
+ }
+
if ($template->uses_temp_file() || $self->{media} eq 'email') {
if ($self->{media} eq 'email') {
@@ -1326,7 +1325,7 @@ sub parse_template {
map { $mail->{$_} = $self->{$_} }
qw(cc bcc subject message version format);
- $mail->{charset} = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
+ $mail->{charset} = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET;
$mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email};
$mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
$mail->{fileid} = "$fileid.";
@@ -1373,6 +1372,7 @@ sub parse_template {
my $numbytes = (-s $self->{tmpfile});
open(IN, $self->{tmpfile})
or $self->error($self->cleanup . "$self->{tmpfile} : $!");
+ binmode IN;
$self->{copies} = 1 unless $self->{media} eq 'printer';
@@ -1423,7 +1423,6 @@ sub get_formname_translation {
bin_list => $main::locale->text('Bin List'),
credit_note => $main::locale->text('Credit Note'),
invoice => $main::locale->text('Invoice'),
- packing_list => $main::locale->text('Packing List'),
pick_list => $main::locale->text('Pick List'),
proforma => $main::locale->text('Proforma Invoice'),
purchase_order => $main::locale->text('Purchase Order'),
@@ -1431,7 +1430,6 @@ sub get_formname_translation {
sales_order => $main::locale->text('Confirmation'),
sales_quotation => $main::locale->text('Quotation'),
storno_invoice => $main::locale->text('Storno Invoice'),
- storno_packing_list => $main::locale->text('Storno Packing List'),
sales_delivery_order => $main::locale->text('Delivery Order'),
purchase_delivery_order => $main::locale->text('Delivery Order'),
dunning => $main::locale->text('Dunning'),
@@ -1523,7 +1521,7 @@ sub cleanup {
close(FH);
}
- if ($self->{tmpfile} && ! $::keep_temp_files) {
+ if ($self->{tmpfile} && !($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})) {
$self->{tmpfile} =~ s|.*/||g;
# strip extension
$self->{tmpfile} =~ s/\.\w+$//g;
@@ -1588,7 +1586,7 @@ sub dbconnect {
my ($self, $myconfig) = @_;
# connect to database
- my $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options)
+ my $dbh = SL::DBConnect->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options)
or $self->dberror;
# set db options
@@ -1607,7 +1605,7 @@ sub dbconnect_noauto {
my ($self, $myconfig) = @_;
# connect to database
- my $dbh = DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options(AutoCommit => 0))
+ my $dbh = SL::DBConnect->connect($myconfig->{dbconnect}, $myconfig->{dbuser}, $myconfig->{dbpasswd}, $self->_dbconnect_options(AutoCommit => 0))
or $self->dberror;
# set db options
@@ -1645,7 +1643,24 @@ sub date_closed {
my $dbh = $self->dbconnect($myconfig);
my $query = "SELECT 1 FROM defaults WHERE ? < closedto";
- my $sth = prepare_execute_query($self, $dbh, $query, $date);
+ my $sth = prepare_execute_query($self, $dbh, $query, conv_date($date));
+
+ # Falls $date = '' - Fehlermeldung aus der Datenbank. Ich denke,
+ # es ist sicher ein conv_date vorher IMMER auszuführen.
+ # Testfälle ohne definiertes closedto:
+ # Leere Datumseingabe i.O.
+ # SELECT 1 FROM defaults WHERE '' < closedto
+ # normale Zahlungsbuchung über Rechnungsmaske i.O.
+ # SELECT 1 FROM defaults WHERE '10.05.2011' < closedto
+ # Testfälle mit definiertem closedto (30.04.2011):
+ # Leere Datumseingabe i.O.
+ # SELECT 1 FROM defaults WHERE '' < closedto
+ # normale Buchung im geschloßenem Zeitraum i.O.
+ # SELECT 1 FROM defaults WHERE '21.04.2011' < closedto
+ # Fehlermeldung: Es können keine Zahlungen für abgeschlossene Bücher gebucht werden!
+ # normale Buchung in aktiver Buchungsperiode i.O.
+ # SELECT 1 FROM defaults WHERE '01.05.2011' < closedto
+
my ($closed) = $sth->fetchrow_array;
$main::lxdebug->leave_sub();
@@ -1860,12 +1875,12 @@ sub set_payment_options {
my $dbh = $self->get_standard_dbh($myconfig);
my $query =
- qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long | .
+ qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long , p.description | .
qq|FROM payment_terms p | .
qq|WHERE p.id = ?|;
($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
- $self->{payment_terms}) =
+ $self->{payment_terms}, $self->{payment_description}) =
selectrow_query($self, $dbh, $query, $self->{payment_id});
if ($transdate eq "") {
@@ -1912,10 +1927,12 @@ sub set_payment_options {
if ($self->{"language_id"}) {
$query =
- qq|SELECT t.description_long, l.output_numberformat, l.output_dateformat, l.output_longdates | .
- qq|FROM translation_payment_terms t | .
+ qq|SELECT t.translation, l.output_numberformat, l.output_dateformat, l.output_longdates | .
+ qq|FROM generic_translations t | .
qq|LEFT JOIN language l ON t.language_id = l.id | .
- qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
+ qq|WHERE (t.language_id = ?)
+ AND (t.translation_id = ?)
+ AND (t.translation_type = 'SL::DB::PaymentTerm/description_long')|;
my ($description_long, $output_numberformat, $output_dateformat,
$output_longdates) =
selectrow_query($self, $dbh, $query,
@@ -2019,7 +2036,7 @@ sub add_shipto {
my @values;
foreach my $item (qw(name department_1 department_2 street zipcode city country
- contact phone fax email)) {
+ contact cp_gender phone fax email)) {
if ($self->{"shipto$item"}) {
$shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
}
@@ -2037,6 +2054,7 @@ sub add_shipto {
shiptocity = ?,
shiptocountry = ?,
shiptocontact = ?,
+ shiptocp_gender = ?,
shiptophone = ?,
shiptofax = ?,
shiptoemail = ?
@@ -2052,6 +2070,7 @@ sub add_shipto {
shiptocity = ? AND
shiptocountry = ? AND
shiptocontact = ? AND
+ shiptocp_gender = ? AND
shiptophone = ? AND
shiptofax = ? AND
shiptoemail = ? AND
@@ -2062,8 +2081,8 @@ sub add_shipto {
$query =
qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2,
shiptostreet, shiptozipcode, shiptocity, shiptocountry,
- shiptocontact, shiptophone, shiptofax, shiptoemail, module)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
+ shiptocontact, shiptocp_gender, shiptophone, shiptofax, shiptoemail, module)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
do_query($self, $dbh, $query, $id, @values, $module);
}
}
@@ -2387,7 +2406,7 @@ $main::lxdebug->enter_sub();
$key = "all_payments" unless ($key);
- my $query = qq|SELECT * FROM payment_terms ORDER BY id|;
+ my $query = qq|SELECT * FROM payment_terms ORDER BY sortkey|;
$self->{$key} = selectall_hashref_query($self, $dbh, $query);
@@ -2465,7 +2484,8 @@ sub _get_warehouses {
$self->{$key} = selectall_hashref_query($self, $dbh, $query);
if ($bins_key) {
- $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?|;
+ $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?
+ ORDER BY description|;
my $sth = prepare_query($self, $dbh, $query);
foreach my $warehouse (@{ $self->{$key} }) {
@@ -3272,7 +3292,6 @@ sub save_status {
# $main::locale->text('invoice')
# $main::locale->text('proforma')
# $main::locale->text('sales_order')
-# $main::locale->text('packing_list')
# $main::locale->text('pick_list')
# $main::locale->text('purchase_order')
# $main::locale->text('bin_list')
@@ -3546,6 +3565,163 @@ sub restore_vars {
$main::lxdebug->leave_sub();
}
+sub prepare_for_printing {
+ my ($self) = @_;
+
+ $self->{templates} ||= $::myconfig{templates};
+ $self->{formname} ||= $self->{type};
+ $self->{media} ||= 'email';
+
+ die "'media' other than 'email', 'file', 'printer' is not supported yet" unless $self->{media} =~ m/^(?:email|file|printer)$/;
+
+ # set shipto from billto unless set
+ my $has_shipto = any { $self->{"shipto$_"} } qw(name street zipcode city country contact);
+ if (!$has_shipto && ($self->{type} =~ m/^(?:purchase_order|request_quotation)$/)) {
+ $self->{shiptoname} = $::myconfig{company};
+ $self->{shiptostreet} = $::myconfig{address};
+ }
+
+ my $language = $self->{language} ? '_' . $self->{language} : '';
+
+ my ($language_tc, $output_numberformat, $output_dateformat, $output_longdates);
+ if ($self->{language_id}) {
+ ($language_tc, $output_numberformat, $output_dateformat, $output_longdates) = AM->get_language_details(\%::myconfig, $self, $self->{language_id});
+ } else {
+ $output_dateformat = $::myconfig{dateformat};
+ $output_numberformat = $::myconfig{numberformat};
+ $output_longdates = 1;
+ }
+
+ # Retrieve accounts for tax calculation.
+ IC->retrieve_accounts(\%::myconfig, $self, map { $_ => $self->{"id_$_"} } 1 .. $self->{rowcount});
+
+ if ($self->{type} =~ /_delivery_order$/) {
+ DO->order_details();
+ } elsif ($self->{type} =~ /sales_order|sales_quotation|request_quotation|purchase_order/) {
+ OE->order_details(\%::myconfig, $self);
+ } else {
+ IS->invoice_details(\%::myconfig, $self, $::locale);
+ }
+
+ # Chose extension & set source file name
+ my $extension = 'html';
+ if ($self->{format} eq 'postscript') {
+ $self->{postscript} = 1;
+ $extension = 'tex';
+ } elsif ($self->{"format"} =~ /pdf/) {
+ $self->{pdf} = 1;
+ $extension = $self->{'format'} =~ m/opendocument/i ? 'odt' : 'tex';
+ } elsif ($self->{"format"} =~ /opendocument/) {
+ $self->{opendocument} = 1;
+ $extension = 'odt';
+ } elsif ($self->{"format"} =~ /excel/) {
+ $self->{excel} = 1;
+ $extension = 'xls';
+ }
+
+ my $printer_code = '_' . $self->{printer_code} if $self->{printer_code};
+ my $email_extension = '_email' if -f "$self->{templates}/$self->{formname}_email${language}${printer_code}.${extension}";
+ $self->{IN} = "$self->{formname}${email_extension}${language}${printer_code}.${extension}";
+
+ # Format dates.
+ $self->format_dates($output_dateformat, $output_longdates,
+ qw(invdate orddate quodate pldate duedate reqdate transdate shippingdate deliverydate validitydate paymentdate datepaid
+ transdate_oe deliverydate_oe employee_startdate employee_enddate),
+ grep({ /^(?:datepaid|transdate_oe|reqdate|deliverydate|deliverydate_oe|transdate)_\d+$/ } keys(%{$self})));
+
+ $self->reformat_numbers($output_numberformat, 2,
+ qw(invtotal ordtotal quototal subtotal linetotal listprice sellprice netprice discount tax taxbase total paid),
+ grep({ /^(?:linetotal|listprice|sellprice|netprice|taxbase|discount|paid|subtotal|total|tax)_\d+$/ } keys(%{$self})));
+
+ $self->reformat_numbers($output_numberformat, undef, qw(qty price_factor), grep({ /^qty_\d+$/} keys(%{$self})));
+
+ my ($cvar_date_fields, $cvar_number_fields) = CVar->get_field_format_list('module' => 'CT', 'prefix' => 'vc_');
+
+ if (scalar @{ $cvar_date_fields }) {
+ $self->format_dates($output_dateformat, $output_longdates, @{ $cvar_date_fields });
+ }
+
+ while (my ($precision, $field_list) = each %{ $cvar_number_fields }) {
+ $self->reformat_numbers($output_numberformat, $precision, @{ $field_list });
+ }
+
+ return $self;
+}
+
+sub format_dates {
+ my ($self, $dateformat, $longformat, @indices) = @_;
+
+ $dateformat ||= $::myconfig{dateformat};
+
+ foreach my $idx (@indices) {
+ if ($self->{TEMPLATE_ARRAYS} && (ref($self->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) {
+ for (my $i = 0; $i < scalar(@{ $self->{TEMPLATE_ARRAYS}->{$idx} }); $i++) {
+ $self->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $::locale->reformat_date(\%::myconfig, $self->{TEMPLATE_ARRAYS}->{$idx}->[$i], $dateformat, $longformat);
+ }
+ }
+
+ next unless defined $self->{$idx};
+
+ if (!ref($self->{$idx})) {
+ $self->{$idx} = $::locale->reformat_date(\%::myconfig, $self->{$idx}, $dateformat, $longformat);
+
+ } elsif (ref($self->{$idx}) eq "ARRAY") {
+ for (my $i = 0; $i < scalar(@{ $self->{$idx} }); $i++) {
+ $self->{$idx}->[$i] = $::locale->reformat_date(\%::myconfig, $self->{$idx}->[$i], $dateformat, $longformat);
+ }
+ }
+ }
+}
+
+sub reformat_numbers {
+ my ($self, $numberformat, $places, @indices) = @_;
+
+ return if !$numberformat || ($numberformat eq $::myconfig{numberformat});
+
+ foreach my $idx (@indices) {
+ if ($self->{TEMPLATE_ARRAYS} && (ref($self->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) {
+ for (my $i = 0; $i < scalar(@{ $self->{TEMPLATE_ARRAYS}->{$idx} }); $i++) {
+ $self->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $self->parse_amount(\%::myconfig, $self->{TEMPLATE_ARRAYS}->{$idx}->[$i]);
+ }
+ }
+
+ next unless defined $self->{$idx};
+
+ if (!ref($self->{$idx})) {
+ $self->{$idx} = $self->parse_amount(\%::myconfig, $self->{$idx});
+
+ } elsif (ref($self->{$idx}) eq "ARRAY") {
+ for (my $i = 0; $i < scalar(@{ $self->{$idx} }); $i++) {
+ $self->{$idx}->[$i] = $self->parse_amount(\%::myconfig, $self->{$idx}->[$i]);
+ }
+ }
+ }
+
+ my $saved_numberformat = $::myconfig{numberformat};
+ $::myconfig{numberformat} = $numberformat;
+
+ foreach my $idx (@indices) {
+ if ($self->{TEMPLATE_ARRAYS} && (ref($self->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) {
+ for (my $i = 0; $i < scalar(@{ $self->{TEMPLATE_ARRAYS}->{$idx} }); $i++) {
+ $self->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $self->format_amount(\%::myconfig, $self->{TEMPLATE_ARRAYS}->{$idx}->[$i], $places);
+ }
+ }
+
+ next unless defined $self->{$idx};
+
+ if (!ref($self->{$idx})) {
+ $self->{$idx} = $self->format_amount(\%::myconfig, $self->{$idx}, $places);
+
+ } elsif (ref($self->{$idx}) eq "ARRAY") {
+ for (my $i = 0; $i < scalar(@{ $self->{$idx} }); $i++) {
+ $self->{$idx}->[$i] = $self->format_amount(\%::myconfig, $self->{$idx}->[$i], $places);
+ }
+ }
+ }
+
+ $::myconfig{numberformat} = $saved_numberformat;
+}
+
1;
__END__
@@ -3565,9 +3741,7 @@ Points of interest for a beginner are:
=head1 SPECIAL FUNCTIONS
-=over 4
-
-=item _store_value()
+=head2 C<_store_value()>
parses a complex var name, and stores it in the form.
@@ -3622,7 +3796,7 @@ supported key structures are:
filter.status[] => $form->{status}->[ val1, val2, ... ]
-=item update_business PARAMS
+=head2 C