X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/c0713b66e59e458d4966b8954ec1c835e2bc0c5b..fd47986c57c883f91779be1f9700886388354e63:/SL/Form.pm
diff --git a/SL/Form.pm b/SL/Form.pm
index 99fe818cc..35050a0c7 100644
--- a/SL/Form.pm
+++ b/SL/Form.pm
@@ -539,7 +539,7 @@ sub footer {
print $::request->{layout}->post_content;
if (my @inline_scripts = $::request->{layout}->javascripts_inline) {
- print "\n";
+ print "\n";
}
print <leave_sub;
}
+sub prepare_global_vars {
+ my ($self) = @_;
+
+ $self->{AUTH} = $::auth;
+ $self->{INSTANCE_CONF} = $::instance_conf;
+ $self->{LOCALE} = $::locale;
+ $self->{LXCONFIG} = $::lx_office_conf;
+ $self->{LXDEBUG} = $::lxdebug;
+ $self->{MYCONFIG} = \%::myconfig;
+}
+
sub _prepare_html_template {
$main::lxdebug->enter_sub();
@@ -934,17 +945,15 @@ sub parse_amount {
return 0;
}
- if ( ($myconfig->{numberformat} eq '1.000,00')
- || ($myconfig->{numberformat} eq '1000,00')) {
+ if ($myconfig->{numberformat} eq '1,000.00') {
+ $amount =~ s/,//g;
+ } elsif ($myconfig->{numberformat} eq '1.000,00') {
$amount =~ s/\.//g;
- $amount =~ s/,/\./g;
- }
-
- if ($myconfig->{numberformat} eq "1'000.00") {
+ } elsif ($myconfig->{numberformat} eq "1'000.00") {
$amount =~ s/\'//g;
}
- $amount =~ s/,//g;
+ $amount =~ s/,/\./g;
$main::lxdebug->leave_sub(2);
@@ -958,7 +967,18 @@ sub parse_amount {
}
sub round_amount {
- my ($self, $amount, $places) = @_;
+ my ($self, $amount, $places, $adjust) = @_;
+
+ if ($adjust) {
+ my $precision = 0.01;
+ # Round amounts to eight places before rounding to the requested
+ # number of places. This gets rid of errors due to internal floating
+ # point representation.
+ $amount = int($amount * 10**8 + .5 * ($amount <=> 0)) / 10**8 if $places < 8;
+ $amount = int($amount / ($precision = _get_precision()) + ($amount <=> 0) * .5) * $precision;
+ $amount = int($amount * 10**$places + .5 * ($amount <=> 0)) / 10**$places;
+ return $amount;
+ }
return 0 if !defined $amount;
@@ -1301,6 +1321,9 @@ sub generate_attachment_filename {
} elsif ($attachment_filename && $self->{"${prefix}number"}) {
$attachment_filename .= "_" . $self->{"${prefix}number"} . $self->get_extension_for_format();
+ } elsif ($attachment_filename) {
+ $attachment_filename .= $self->get_extension_for_format();
+
} else {
$attachment_filename = "";
}
@@ -1787,6 +1810,10 @@ sub set_payment_options {
$self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
$self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
$self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
+ $self->{payment_terms} =~ s/<\%bic\%>/$self->{bic}/g;
+ $self->{payment_terms} =~ s/<\%iban\%>/$self->{iban}/g;
+ $self->{payment_terms} =~ s/<\%mandate_date_of_signature\%>/$self->{mandate_date_of_signature}/g;
+ $self->{payment_terms} =~ s/<\%mandator_id\%>/$self->{mandator_id}/g;
map { $self->{payment_terms} =~ s/<%${_}%>/$formatted_amounts{$_}/g; } keys %formatted_amounts;
@@ -2585,6 +2612,24 @@ sub all_vc {
$main::lxdebug->leave_sub();
}
+sub mtime_ischanged {
+ my ($self, $table, $option) = @_;
+
+ return unless $self->{id};
+ croak ("wrong call, no valid table defined") unless $table =~ /^(oe|ar|ap|delivery_orders|parts)$/;
+
+ my $query = "SELECT mtime, itime FROM " . $table . " WHERE id = ?";
+ my $ref = selectfirst_hashref_query($self, $self->get_standard_dbh, $query, $self->{id});
+ $ref->{mtime} ||= $ref->{itime};
+
+ if ($self->{lastmtime} && $self->{lastmtime} ne $ref->{mtime} ) {
+ my $etxt = ($option eq 'mail') ? "The document has been changed by another user. Please reopen it in another window and copy the changes to the new window" :
+ "The document has been changed by another user. No mail was sent. Please reopen it in another window and copy the changes to the new window";
+ $self->error($main::locale->text($etxt));
+ ::end_of_request();
+ }
+}
+
sub language_payment {
$main::lxdebug->enter_sub();
@@ -2736,6 +2781,7 @@ sub create_links {
qq|SELECT
a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid,
a.duedate, a.ordnumber, a.taxincluded, (SELECT cu.name FROM currencies cu WHERE cu.id=a.currency_id) AS currency, a.notes,
+ a.mtime, a.itime,
a.intnotes, a.department_id, a.amount AS oldinvtotal,
a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
a.globalproject_id, ${extra_columns}
@@ -2752,7 +2798,8 @@ sub create_links {
foreach my $key (keys %$ref) {
$self->{$key} = $ref->{$key};
}
-
+ $self->{mtime} ||= $self->{itime};
+ $self->{lastmtime} = $self->{mtime};
my $transdate = "current_date";
if ($self->{transdate}) {
$transdate = $dbh->quote($self->{transdate});
@@ -3474,9 +3521,9 @@ sub calculate_arap {
if ( $selected_tax ) {
if ( $buysell eq 'sell' ) {
- $self->{AR_amounts}{"tax_$i"} = $selected_tax->chart->accno unless $selected_tax->taxkey == 0;
+ $self->{AR_amounts}{"tax_$i"} = $selected_tax->chart->accno if defined $selected_tax->chart;
} else {
- $self->{AP_amounts}{"tax_$i"} = $selected_tax->chart->accno unless $selected_tax->taxkey == 0;
+ $self->{AP_amounts}{"tax_$i"} = $selected_tax->chart->accno if defined $selected_tax->chart;
};
$self->{"taxkey_$i"} = $selected_tax->taxkey;
@@ -3647,6 +3694,20 @@ sub calculate_tax {
return ($amount,$tax);
};
+sub _get_precision {
+ my ( $self ) = @_;
+ my $precision = 0.01;
+ eval {
+ my $client = $::auth->{client};
+ my $dbconnect = 'dbi:Pg:dbname=' . $client->{dbname} . ';host=' . $client->{dbhost} . ';port=' . $client->{dbport};
+ my $dbh = DBI->connect($dbconnect, $client->{dbuser}, $client->{dbpasswd});
+ my $query = q{ SELECT precision FROM defaults };
+ ($precision) = selectrow_query($::form, $dbh, $query);
+ $dbh->disconnect;
+ };
+ return $precision;
+}
+
1;
__END__
@@ -3718,6 +3779,17 @@ Used to override the default favicon.
A html page title will be generated from this
+=item mtime_ischanged
+
+Tries to avoid concurrent write operations to records by checking the database mtime with a fetched one.
+
+Can be used / called with any table, that has itime and mtime attributes.
+Valid C names are: oe, ar, ap, delivery_orders, parts.
+Can be called wit C