c90e03800b935487d079dc2c5c32aa71c9bb0394
[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
8 use SL::DB::MetaSetup::CustomVariable;
9 use SL::DB::CustomVariableValidity;
10 use SL::DB::Customer;
11
12 __PACKAGE__->meta->initialize;
13
14 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
15 __PACKAGE__->meta->make_manager_class;
16
17 sub value {
18   my $self = $_[0];
19   my $type = $self->config->type;
20
21   goto &bool_value      if $type eq 'boolean';
22   goto &timestamp_value if $type eq 'timestamp';
23   goto &number_value    if $type eq 'number';
24   if ( $type eq 'customer' ) {
25     if ( defined($_[1]) && $_[1] ) {
26       goto &number_value;
27     }
28     else {
29       my $id = int($self->number_value);
30       return $id ? SL::DB::Customer->new(id => $id)->load() : 0;
31     }
32   }
33   goto &text_value; # text and select
34 }
35
36 sub is_valid {
37   my ($self) = @_;
38
39   return SL::DB::Manager::CustomVariableValidity->get_all_count(config_id => $self->config_id, trans_id => $self->trans_id) == 0;
40 }
41
42 1;