X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FCVar.pm;h=6d04f35a9ed0029f6920f2d44754c063ba7068e8;hb=217751aba9f1e746f67914e83bb669fc784d6eac;hp=8b3cd8e27c97ef66321a0ecf4aac85f9560ac022;hpb=ef90159c18e52835e03b1775a23c64fbb91436de;p=kivitendo-erp.git diff --git a/SL/CVar.pm b/SL/CVar.pm index 8b3cd8e27..6d04f35a9 100644 --- a/SL/CVar.pm +++ b/SL/CVar.pm @@ -3,6 +3,7 @@ package CVar; use strict; use List::Util qw(first); +use Scalar::Util qw(blessed); use Data::Dumper; use SL::DBUtils; @@ -175,8 +176,9 @@ sub delete_config { my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); - do_query($form, $dbh, qq|DELETE FROM custom_variables WHERE config_id = ?|, conv_i($params{id})); - do_query($form, $dbh, qq|DELETE FROM custom_variable_configs WHERE id = ?|, conv_i($params{id})); + do_query($form, $dbh, qq|DELETE FROM custom_variables WHERE config_id = ?|, conv_i($params{id})); + do_query($form, $dbh, qq|DELETE FROM custom_variables_validity WHERE config_id = ?|, conv_i($params{id})); + do_query($form, $dbh, qq|DELETE FROM custom_variable_configs WHERE id = ?|, conv_i($params{id})); $dbh->commit(); @@ -355,7 +357,7 @@ sub save_custom_variables { $sth->finish(); - $dbh->commit(); + $dbh->commit() unless $params{dbh}; $main::lxdebug->leave_sub(); } @@ -573,7 +575,7 @@ sub add_custom_variables_to_report { $cfg->{type} eq 'date' ? $ref->{date_value} : $cfg->{type} eq 'timestamp' ? $ref->{timestamp_value} : $cfg->{type} eq 'number' ? $form->format_amount($myconfig, $ref->{number_value} * 1, $cfg->{precision}) - : $cfg->{type} eq 'customer' ? SL::DB::Manager::Customer->find_by(id => 1* $ref->{number_value})->name + : $cfg->{type} eq 'customer' ? (SL::DB::Manager::Customer->find_by(id => 1*$ref->{number_value}) || SL::DB::Customer->new)->name : $cfg->{type} eq 'bool' ? ($ref->{bool_value} ? $locale->text('Yes') : $locale->text('No')) : $ref->{text_value}; } @@ -656,7 +658,7 @@ sub save_custom_variables_validity { $sth->finish(); - $dbh->commit(); + $dbh->commit() unless $params{dbh}; $main::lxdebug->leave_sub(); } @@ -705,6 +707,25 @@ sub custom_variables_validity_by_trans_id { return sub { !$invalids{+shift} }; } +sub parse { + my ($self, $value, $config) = @_; + + return $::form->parse_amount(\%::myconfig, $value) if $config->{type} eq 'number'; + return DateTime->from_lxoffice($value) if $config->{type} eq 'date'; + return !ref $value ? SL::DB::Manager::Customer->find_by(id => $value * 1) : $value if $config->{type} eq 'customer'; + return $value; +} + +sub format_to_template { + my ($self, $value, $config) = @_; + # stupid template expects everything formated. except objects + # do not use outside of print routines for legacy templates + + return $::form->format_amount(\%::myconfig, $value) if $config->{type} eq 'number'; + return $value->to_lxoffice if $config->{type} eq 'date' && blessed $value && $value->can('to_lxoffice'); + return $value; +} + 1; __END__