X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=f2fe969bc0c85a878bcc1343739cb45560406d61;hb=c7f9bb36eb122b2d79f5aa8c4d080279705ddc7e;hp=c7595ac4ffc12bbe142d67a94e08436fad8a0a7e;hpb=d319704a66e9be64da837ccea10af6774c2b0838;p=kivitendo-erp.git diff --git a/SL/Form.pm b/SL/Form.pm index c7595ac4f..f2fe969bc 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -192,6 +192,42 @@ sub unescape { return $str; } +sub quote { + my ($self, $str) = @_; + + if ($str && ! ref($str)) { + $str =~ s/"/"/g; + } + + $str; + +} + + +sub unquote { + my ($self, $str) = @_; + + if ($str && ! ref($str)) { + $str =~ s/"/"/g; + } + + $str; + +} + + +sub hide_form { + my $self = shift; + + if (@_) { + for (@_) { print qq|\n| } + } else { + delete $self->{header}; + for (sort keys %$self) { print qq|\n| } + } + +} + sub error { $main::lxdebug->enter_sub(); @@ -348,6 +384,7 @@ function fokus(){document.$self->{fokus}.focus();}     + $self->{javascript} |; } @@ -439,7 +476,7 @@ sub write_trigger { + //--> |; @@ -489,6 +526,7 @@ sub format_amount { # is the amount negative my $negative = ($amount < 0); + my $fillup = ""; if ($amount != 0) { if ($myconfig->{numberformat} && ($myconfig->{numberformat} ne '1000.00')) @@ -496,24 +534,25 @@ sub format_amount { my ($whole, $dec) = split /\./, "$amount"; $whole =~ s/-//; $amount = join '', reverse split //, $whole; + $fillup = "0" x ($places - length($dec)); if ($myconfig->{numberformat} eq '1,000.00') { $amount =~ s/\d{3,}?/$&,/g; $amount =~ s/,$//; $amount = join '', reverse split //, $amount; - $amount .= "\.$dec" if ($dec ne ""); + $amount .= "\.$dec".$fillup; } if ($myconfig->{numberformat} eq '1.000,00') { $amount =~ s/\d{3,}?/$&./g; $amount =~ s/\.$//; $amount = join '', reverse split //, $amount; - $amount .= ",$dec" if ($dec ne ""); + $amount .= ",$dec" .$fillup; } if ($myconfig->{numberformat} eq '1000,00') { $amount = "$whole"; - $amount .= ",$dec" if ($dec ne ""); + $amount .= ",$dec" .$fillup; } if ($dash =~ /-/) { @@ -565,28 +604,24 @@ sub round_amount { $main::lxdebug->enter_sub(); my ($self, $amount, $places) = @_; - my $rc; - - # $places = 3 if $places == 2; - - if (($places * 1) >= 0) { + my $round_amount; - # add 1/10^$places+3 - $rc = - sprintf("%.${places}f", - $amount + (1 / (10**($places + 3))) * (($amount > 0) ? 1 : -1)); - } else { - $places *= -1; - $rc = - sprintf("%.f", $amount / (10**$places) + (($amount > 0) ? 0.1 : -0.1)) * - (10**$places); - } + # Rounding like "Kaufmannsrunden" + # Descr. http://de.wikipedia.org/wiki/Rundung + # Inspired by + # http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.13.html + # Solves Bug: 189 + # Udo Spallek + $amount = $amount * (10 ** ($places)); + $round_amount = int($amount + .5 * ($amount <=> 0))/(10**($places)); $main::lxdebug->leave_sub(); - return $rc; + return $round_amount; } + + sub parse_template { $main::lxdebug->enter_sub(); @@ -1253,7 +1288,7 @@ sub add_shipto { ##LINET my $shipto; foreach - my $item (qw(name street zipcode city country contact phone fax email)) { + my $item (qw(name department_1 department_2 street zipcode city country contact phone fax email)) { if ($self->{"shipto$item"}) { $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"}); } @@ -1261,10 +1296,10 @@ sub add_shipto { } if ($shipto) { - my $query = qq|INSERT INTO shipto (trans_id, shiptoname, shiptostreet, + my $query = qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2, shiptostreet, shiptozipcode, shiptocity, shiptocountry, shiptocontact, shiptophone, shiptofax, shiptoemail) VALUES ($id, - '$self->{shiptoname}', '$self->{shiptostreet}', + '$self->{shiptoname}', '$self->{shiptodepartment_1}', '$self->{shiptodepartment_2}', '$self->{shiptostreet}', '$self->{shiptozipcode}', '$self->{shiptocity}', '$self->{shiptocountry}', '$self->{shiptocontact}', '$self->{shiptophone}', '$self->{shiptofax}', @@ -1300,7 +1335,7 @@ sub get_contact { my ($self, $dbh, $id) = @_; my $query = qq|SELECT c.* - FROM contacts c + FROM contacts c WHERE cp_id=$id|; $sth = $dbh->prepare($query); $sth->execute || $self->dberror($query); @@ -1319,8 +1354,8 @@ sub get_contacts { my ($self, $dbh, $id) = @_; - my $query = qq|SELECT c.cp_id, c.cp_cv_id, c.cp_name, c.cp_givenname - FROM contacts c + my $query = qq|SELECT c.cp_id, c.cp_cv_id, c.cp_name, c.cp_givenname + FROM contacts c WHERE cp_cv_id=$id|; my $sth = $dbh->prepare($query); $sth->execute || $self->dberror($query); @@ -1687,7 +1722,7 @@ sub lastname_used { $where = "quotation = '1'"; } - my $query = qq|SELECT id FROM $arap + my $query = qq|SELECT id FROM $arap WHERE id IN (SELECT MAX(id) FROM $arap WHERE $where AND ${table}_id > 0)|; @@ -2043,6 +2078,94 @@ sub get_partsgroup { $main::lxdebug->leave_sub(); } + +sub audittrail { + my ($self, $dbh, $myconfig, $audittrail) = @_; + +# table, $reference, $formname, $action, $id, $transdate) = @_; + + my $query; + my $rv; + my $disconnect; + + if (! $dbh) { + $dbh = $self->dbconnect($myconfig); + $disconnect = 1; + } + + # if we have an id add audittrail, otherwise get a new timestamp + + if ($audittrail->{id}) { + + $query = qq|SELECT audittrail FROM defaults|; + + if ($dbh->selectrow_array($query)) { + my ($null, $employee_id) = $self->get_employee($dbh); + + if ($self->{audittrail} && !$myconfig) { + chop $self->{audittrail}; + + my @a = split /\|/, $self->{audittrail}; + my %newtrail = (); + my $key; + my $i; + my @flds = qw(tablename reference formname action transdate); + + # put into hash and remove dups + while (@a) { + $key = "$a[2]$a[3]"; + $i = 0; + $newtrail{$key} = { map { $_ => $a[$i++] } @flds }; + splice @a, 0, 5; + } + + $query = qq|INSERT INTO audittrail (trans_id, tablename, reference, + formname, action, employee_id, transdate) + VALUES ($audittrail->{id}, ?, ?, + ?, ?, $employee_id, ?)|; + my $sth = $dbh->prepare($query) || $self->dberror($query); + + foreach $key (sort { $newtrail{$a}{transdate} cmp $newtrail{$b}{transdate} } keys %newtrail) { + $i = 1; + for (@flds) { $sth->bind_param($i++, $newtrail{$key}{$_}) } + + $sth->execute || $self->dberror; + $sth->finish; + } + } + + + if ($audittrail->{transdate}) { + $query = qq|INSERT INTO audittrail (trans_id, tablename, reference, + formname, action, employee_id, transdate) VALUES ( + $audittrail->{id}, '$audittrail->{tablename}', | + .$dbh->quote($audittrail->{reference}).qq|', + '$audittrail->{formname}', '$audittrail->{action}', + $employee_id, '$audittrail->{transdate}')|; + } else { + $query = qq|INSERT INTO audittrail (trans_id, tablename, reference, + formname, action, employee_id) VALUES ($audittrail->{id}, + '$audittrail->{tablename}', | + .$dbh->quote($audittrail->{reference}).qq|, + '$audittrail->{formname}', '$audittrail->{action}', + $employee_id)|; + } + $dbh->do($query); + } + } else { + + $query = qq|SELECT current_timestamp FROM defaults|; + my ($timestamp) = $dbh->selectrow_array($query); + + $rv = "$audittrail->{tablename}|$audittrail->{reference}|$audittrail->{formname}|$audittrail->{action}|$timestamp|"; + } + + $dbh->disconnect if $disconnect; + + $rv; + +} + package Locale; sub new { @@ -2211,4 +2334,3 @@ sub parse_date { } 1; -