X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=2a04e15797c0ad4ebfbf5a1a48b329a6f04f4507;hb=6a4c2859de9d57ed2157e6040cbbf7eaa53fa145;hp=326ff9f0057034b964ce0b7e54308b15d6f74a37;hpb=7d82f0e8db96e595122ebe723c129e6f3e26bb0d;p=kivitendo-erp.git diff --git a/SL/Form.pm b/SL/Form.pm index 326ff9f00..2a04e1579 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -146,7 +146,7 @@ sub new { $self->{action} = lc $self->{action}; $self->{action} =~ s/( |-|,|\#)/_/g; - $self->{version} = "2.4.0"; + $self->{version} = "2.3.9"; $main::lxdebug->leave_sub(); @@ -219,6 +219,25 @@ sub unquote { } +sub quote_html { + $main::lxdebug->enter_sub(2); + + my ($self, $str) = @_; + + my %replace = + ('order' => ['"', '<', '>'], + '<' => '<', + '>' => '>', + '"' => '"', + ); + + map({ $str =~ s/$_/$replace{$_}/g; } @{ $replace{"order"} }); + + $main::lxdebug->leave_sub(2); + + return $str; +} + sub hide_form { my $self = shift; @@ -404,6 +423,7 @@ function fokus(){document.$self->{fokus}.focus();} $jsscript $ajax $fokus + @@ -630,78 +650,38 @@ sub sort_columns { return @columns; } - +# sub format_amount { $main::lxdebug->enter_sub(2); my ($self, $myconfig, $amount, $places, $dash) = @_; - - #Workaround for $format_amount calls without $places - if (!defined $places) { - (my $dec) = ($amount =~ /\.(\d+)/); - $places = length $dec; + + if ($amount eq "") { + $amount = 0; } + my $neg = ($amount =~ s/-//); - if ($places =~ /\d/) { - $amount = $self->round_amount($amount, $places); - } + $amount = $self->round_amount($amount, $places) if ($places =~ /\d/); - # is the amount negative - my $negative = ($amount < 0); - my $fillup = ""; + my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars + my @p = split /\./, $amount ; # split amount at decimal point - if ($amount != 0) { - if ($myconfig->{numberformat} && ($myconfig->{numberformat} ne '1000.00')) - { - my ($whole, $dec) = split /\./, "$amount"; - $whole =~ s/-//; - $amount = join '', reverse split //, $whole; - $fillup = "0" x ($places - length($dec)); + $p[0] =~ s/\B(?=(...)*$)/$d[1]/g if $d[1]; # add 1,000 delimiters - if ($myconfig->{numberformat} eq '1,000.00') { - $amount =~ s/\d{3,}?/$&,/g; - $amount =~ s/,$//; - $amount = join '', reverse split //, $amount; - $amount .= "\.$dec" . $fillup if ($places ne '' && $places * 1 != 0); - } + $amount = $p[0]; + $amount .= $d[0].$p[1].(0 x ($places - length $p[1])) if ($places || $p[1] ne ''); - if ($myconfig->{numberformat} eq '1.000,00') { - $amount =~ s/\d{3,}?/$&./g; - $amount =~ s/\.$//; - $amount = join '', reverse split //, $amount; - $amount .= ",$dec" . $fillup if ($places ne '' && $places * 1 != 0); - } - - if ($myconfig->{numberformat} eq '1000,00') { - $amount = "$whole"; - $amount .= ",$dec" . $fillup if ($places ne '' && $places * 1 != 0); - } - - if ($dash =~ /-/) { - $amount = ($negative) ? "($amount)" : "$amount"; - } elsif ($dash =~ /DRCR/) { - $amount = ($negative) ? "$amount DR" : "$amount CR"; - } else { - $amount = ($negative) ? "-$amount" : "$amount"; - } - } - } else { - if ($dash eq "0" && $places) { - if ($myconfig->{numberformat} eq '1.000,00') { - $amount = "0" . "," . "0" x $places; - } else { - $amount = "0" . "." . "0" x $places; - } - } else { - $amount = ($dash ne "") ? "$dash" : "0"; - } - } + $amount = do { + ($dash =~ /-/) ? ($neg ? "($amount)" : "$amount" ) : + ($dash =~ /DRCR/) ? ($neg ? "$amount DR" : "$amount CR" ) : + ($neg ? "-$amount" : "$amount" ) ; + }; + $main::lxdebug->leave_sub(2); - return $amount; } - +# sub parse_amount { $main::lxdebug->enter_sub(2); @@ -823,6 +803,7 @@ sub parse_template { $mail->{to} = qq|$self->{email}|; $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|; $mail->{fileid} = "$fileid."; + $myconfig->{signature} =~ s/\\r\\n/\\n/g; # if we send html or plain text inline if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) { @@ -830,7 +811,7 @@ sub parse_template { $mail->{message} =~ s/\r\n/
\n/g; $myconfig->{signature} =~ s/\\n/
\n/g; - $mail->{message} .= "
\n--
\n$myconfig->{signature}\n
"; + $mail->{message} .= "
\n--
\n$myconfig->{signature}\n
"; open(IN, $self->{tmpfile}) or $self->error($self->cleanup . "$self->{tmpfile} : $!"); @@ -844,8 +825,9 @@ sub parse_template { @{ $mail->{attachments} } = ($self->{tmpfile}) unless ($form->{do_not_attach}); - $myconfig->{signature} =~ s/\\n/\r\n/g; - $mail->{message} .= "\r\n--\r\n$myconfig->{signature}"; + $mail->{message} =~ s/\r\n/\n/g; + $myconfig->{signature} =~ s/\\n/\n/g; + $mail->{message} .= "\n-- \n$myconfig->{signature}"; } @@ -1253,7 +1235,7 @@ sub get_shipto { my $query = qq|SELECT s.* FROM shipto s - WHERE s.id = $self->{shipto_id}|; + WHERE s.shipto_id = $self->{shipto_id}|; my $sth = $dbh->prepare($query); $sth->execute || $self->dberror($query); $ref = $sth->fetchrow_hashref(NAME_lc); @@ -1280,7 +1262,6 @@ sub add_shipto { } $self->{"shipto$item"} =~ s/\'/\'\'/g; } - if ($shipto) { if ($self->{shipto_id}) { my $query = qq| UPDATE shipto set @@ -1295,7 +1276,7 @@ sub add_shipto { shiptophone = '$self->{shiptophone}', shiptofax = '$self->{shiptofax}', shiptoemail = '$self->{shiptoemail}' - WHERE id = $self->{shipto_id}|; + WHERE shipto_id = $self->{shipto_id}|; $dbh->do($query) || $self->dberror($query); } else { my $query = @@ -1607,18 +1588,6 @@ sub language_payment { } $sth->finish; - # get adr - $query = qq|SELECT id, adr_description, adr_code - FROM adr|; - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - - - $self->{ADR} = []; - while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - push @{ $self->{ADR} }, $ref; - } - $sth->finish; $dbh->disconnect; $main::lxdebug->leave_sub(); } @@ -1666,40 +1635,47 @@ sub create_links { my ($query, $sth); my $dbh = $self->dbconnect($myconfig); - my %xkeyref = (); - # now get the account numbers - $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id - FROM chart c - WHERE c.link LIKE '%$module%' - ORDER BY c.accno|; - - $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); - - $self->{accounts} = ""; - while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - - foreach my $key (split /:/, $ref->{link}) { - if ($key =~ /$module/) { - - # cross reference for keys - $xkeyref{ $ref->{accno} } = $key; + if (!$self->{id}) { - push @{ $self->{"${module}_links"}{$key} }, - { accno => $ref->{accno}, - description => $ref->{description}, - taxkey => $ref->{taxkey_id} }; - - $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/; + my $transdate = "current_date"; + if ($self->{transdate}) { + $transdate = qq|'$self->{transdate}'|; + } + + # now get the account numbers + $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id + FROM chart c, taxkeys tk + WHERE c.link LIKE '%$module%' AND c.id=tk.chart_id AND tk.id = (SELECT id from taxkeys where taxkeys.chart_id =c.id AND startdate<=$transdate ORDER BY startdate desc LIMIT 1) + ORDER BY c.accno|; + + $sth = $dbh->prepare($query); + $sth->execute || $self->dberror($query); + + $self->{accounts} = ""; + while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { + + foreach my $key (split /:/, $ref->{link}) { + if ($key =~ /$module/) { + + # cross reference for keys + $xkeyref{ $ref->{accno} } = $key; + + push @{ $self->{"${module}_links"}{$key} }, + { accno => $ref->{accno}, + description => $ref->{description}, + taxkey => $ref->{taxkey_id}, + tax_id => $ref->{tax_id} }; + + $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/; + } } } } - $sth->finish; # get taxkeys and description - $query = qq|SELECT taxkey, taxdescription + $query = qq|SELECT id, taxkey, taxdescription FROM tax|; $sth = $dbh->prepare($query); $sth->execute || $self->dberror($query); @@ -1761,14 +1737,50 @@ sub create_links { } $sth->finish; + + my $transdate = "current_date"; + if ($self->{transdate}) { + $transdate = qq|'$self->{transdate}'|; + } + + # now get the account numbers + $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id + FROM chart c, taxkeys tk + WHERE c.link LIKE '%$module%' AND (((tk.chart_id=c.id) AND NOT(c.link like '%_tax%')) OR (NOT(tk.chart_id=c.id) AND (c.link like '%_tax%'))) AND (((tk.id = (SELECT id from taxkeys where taxkeys.chart_id =c.id AND startdate<=$transdate ORDER BY startdate desc LIMIT 1)) AND NOT(c.link like '%_tax%')) OR (c.link like '%_tax%')) + ORDER BY c.accno|; + + $sth = $dbh->prepare($query); + $sth->execute || $self->dberror($query); + + $self->{accounts} = ""; + while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { + + foreach my $key (split /:/, $ref->{link}) { + if ($key =~ /$module/) { + + # cross reference for keys + $xkeyref{ $ref->{accno} } = $key; + + push @{ $self->{"${module}_links"}{$key} }, + { accno => $ref->{accno}, + description => $ref->{description}, + taxkey => $ref->{taxkey_id}, + tax_id => $ref->{tax_id} }; + + $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/; + } + } + } + + # get amounts from individual entries $query = qq|SELECT c.accno, c.description, a.source, a.amount, a.memo, - a.transdate, a.cleared, a.project_id, p.projectnumber, a.taxkey, t.rate + a.transdate, a.cleared, a.project_id, p.projectnumber, a.taxkey, t.rate, t.id FROM acc_trans a JOIN chart c ON (c.id = a.chart_id) LEFT JOIN project p ON (p.id = a.project_id) - LEFT Join tax t ON (a.taxkey = t.taxkey) - WHERE a.trans_id = $self->{id} + LEFT JOIN tax t ON (t.id=(SELECT tk.tax_id from taxkeys tk WHERE (tk.taxkey_id=a.taxkey) AND ((CASE WHEN a.chart_id IN (SELECT chart_id FROM taxkeys WHERE taxkey_id=a.taxkey) THEN tk.chart_id=a.chart_id ELSE 1=1 END) OR (c.link='%tax%')) AND startdate <=a.transdate ORDER BY startdate DESC LIMIT 1)) + WHERE a.trans_id = $self->{id} AND a.fx_transaction = '0' ORDER BY a.oid,a.transdate|; $sth = $dbh->prepare($query); @@ -1797,8 +1809,8 @@ sub create_links { push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref; } - $sth->finish; + $sth->finish; $query = qq|SELECT d.curr AS currencies, d.closedto, d.revtrans, (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno, @@ -1849,6 +1861,8 @@ sub create_links { } + $sth->finish; + $dbh->disconnect; $main::lxdebug->leave_sub(); @@ -2356,10 +2370,14 @@ sub new { my ($type, $country, $NLS_file) = @_; my $self = {}; - %self = (); if ($country && -d "locale/$country") { + local *IN; $self->{countrycode} = $country; - eval { require "locale/$country/$NLS_file"; }; + if (open(IN, "locale/$country/$NLS_file")) { + my $code = join("", ); + eval($code); + close(IN); + } } $self->{NLS_file} = $NLS_file; @@ -2379,7 +2397,7 @@ sub new { sub text { my ($self, $text) = @_; - return (exists $self{texts}{$text}) ? $self{texts}{$text} : $text; + return (exists $self->{texts}{$text}) ? $self->{texts}{$text} : $text; } sub findsub { @@ -2387,8 +2405,8 @@ sub findsub { my ($self, $text) = @_; - if (exists $self{subs}{$text}) { - $text = $self{subs}{$text}; + if (exists $self->{subs}{$text}) { + $text = $self->{subs}{$text}; } else { if ($self->{countrycode} && $self->{NLS_file}) { Form->error(