Rose-DB-Query gefixt
[kivitendo-erp.git] / SL / DB / CustomVariable.pm
1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
3
4 package SL::DB::CustomVariable;
5
6 use strict;
7 use SL::DB::MetaSetup::CustomVariable;
8
9 __PACKAGE__->meta->initialize;
10
11 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
12 __PACKAGE__->meta->make_manager_class;
13
14 sub value {
15   my $self = $_[0];
16   my $type = $self->config->type;
17
18   goto &bool_value      if $type eq 'boolean';
19   goto &timestamp_value if $type eq 'timestamp';
20   goto &number_value    if $type eq 'number';
21   if ( $type eq 'customer' ) {
22     if ( defined($_[1]) && $_[1] ) {
23       goto &number_value;
24     }
25     else {
26       require SL::DB::Customer;
27
28       my $id = int($self->number_value);
29       return $id ? SL::DB::Customer->new(id => $id)->load() : 0;
30     }
31   }
32   goto &text_value; # text and select
33 }
34
35 sub is_valid {
36   my ($self) = @_;
37
38   require SL::DB::CustomVariableValidity;
39
40   my $query = [config_id => $self->config_id, trans_id => $self->trans_id];
41   return SL::DB::Manager::CustomVariableValidity->get_all_count(query => $query) == 0;
42 }
43
44 1;