Benutzerdef. Variablen f. Waren per Voreinstellung für Belege aktivieren/deaktivieren.
[kivitendo-erp.git] / SL / CVar.pm
1 package CVar;
2
3 use strict;
4
5 use List::MoreUtils qw(any);
6 use List::Util qw(first);
7 use Scalar::Util qw(blessed);
8 use Data::Dumper;
9
10 use SL::DBUtils;
11 use SL::MoreCommon qw(listify);
12
13 sub get_configs {
14   $main::lxdebug->enter_sub();
15
16   my $self     = shift;
17   my %params   = @_;
18
19   my $myconfig = \%main::myconfig;
20   my $form     = $main::form;
21
22   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
23
24   my ($where, @values);
25   if ($params{module}) {
26     $where = 'WHERE module = ?';
27     push @values, $params{module};
28   }
29
30   my $query    = <<SQL;
31     SELECT *, date_trunc('seconds', localtimestamp) AS current_timestamp
32     FROM custom_variable_configs $where ORDER BY sortkey
33 SQL
34
35   $::form->{CVAR_CONFIGS} = {} unless 'HASH' eq ref $::form->{CVAR_CONFIGS};
36   if (!$::form->{CVAR_CONFIGS}->{$params{module}}) {
37     my $configs  = selectall_hashref_query($form, $dbh, $query, @values);
38
39     foreach my $config (@{ $configs }) {
40       if ($config->{type} eq 'select') {
41         $config->{OPTIONS} = [ map { { 'value' => $_ } } split(m/\#\#/, $config->{options}) ];
42
43       } elsif ($config->{type} eq 'number') {
44         $config->{precision} = $1 if ($config->{options} =~ m/precision=(\d+)/i);
45
46       } elsif ($config->{type} eq 'textfield') {
47         $config->{width}  = 30;
48         $config->{height} =  5;
49         $config->{width}  = $1 if ($config->{options} =~ m/width=(\d+)/i);
50         $config->{height} = $1 if ($config->{options} =~ m/height=(\d+)/i);
51
52       } elsif ($config->{type} eq 'text') {
53         $config->{maxlength} = $1 if ($config->{options} =~ m/maxlength=(\d+)/i);
54
55       }
56
57       $self->_unpack_flags($config);
58     }
59     $::form->{CVAR_CONFIGS}->{$params{module}} = $configs;
60   }
61
62   $main::lxdebug->leave_sub();
63
64   return $::form->{CVAR_CONFIGS}->{$params{module}};
65 }
66
67 sub _unpack_flags {
68   $main::lxdebug->enter_sub();
69
70   my $self   = shift;
71   my $config = shift;
72
73   foreach my $flag (split m/:/, $config->{flags}) {
74     if ($flag =~ m/(.*?)=(.*)/) {
75       $config->{"flag_${1}"}    = $2;
76     } else {
77       $config->{"flag_${flag}"} = 1;
78     }
79   }
80
81   $main::lxdebug->leave_sub();
82 }
83
84 sub get_custom_variables {
85   $main::lxdebug->enter_sub();
86
87   my $self     = shift;
88   my %params   = @_;
89
90   Common::check_params(\%params, qw(module));
91
92   my $myconfig = \%main::myconfig;
93   my $form     = $main::form;
94
95   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
96
97   my $trans_id = $params{trans_id} ? 'OR (v.trans_id = ?) ' : '';
98
99   my $q_var    =
100     qq|SELECT text_value, timestamp_value, timestamp_value::date AS date_value, number_value, bool_value
101        FROM custom_variables
102        WHERE (config_id = ?) AND (trans_id = ?)|;
103   $q_var      .= qq| AND (sub_module = ?)| if $params{sub_module};
104   my $h_var    = prepare_query($form, $dbh, $q_var);
105
106   my $custom_variables = $self->get_configs(module => $params{module});
107
108   foreach my $cvar (@{ $custom_variables }) {
109     if ($cvar->{type} eq 'textfield') {
110       $cvar->{width}  = 30;
111       $cvar->{height} =  5;
112
113       $cvar->{width}  = $1 if ($cvar->{options} =~ m/width=(\d+)/i);
114       $cvar->{height} = $1 if ($cvar->{options} =~ m/height=(\d+)/i);
115
116     } elsif ($cvar->{type} eq 'text') {
117       $cvar->{maxlength} = $1 if ($cvar->{options} =~ m/maxlength=(\d+)/i);
118
119     } elsif ($cvar->{type} eq 'number') {
120       $cvar->{precision} = $1 if ($cvar->{options} =~ m/precision=(\d+)/i);
121
122     } elsif ($cvar->{type} eq 'select') {
123       $cvar->{OPTIONS} = [ map { { 'value' => $_ } } split(m/\#\#/, $cvar->{options}) ];
124     }
125
126     my ($act_var, $valid);
127     if ($params{trans_id}) {
128       my @values = (conv_i($cvar->{id}), conv_i($params{trans_id}));
129       push @values, $params{sub_module} if $params{sub_module};
130
131       do_statement($form, $h_var, $q_var, @values);
132       $act_var = $h_var->fetchrow_hashref();
133
134       $valid = $self->get_custom_variables_validity(config_id => $cvar->{id}, trans_id => $params{trans_id});
135     } else {
136       $valid = !$cvar->{flag_defaults_to_invalid};
137     }
138
139     if ($act_var) {
140       $cvar->{value} = $cvar->{type} eq 'date'      ? $act_var->{date_value}
141                      : $cvar->{type} eq 'timestamp' ? $act_var->{timestamp_value}
142                      : $cvar->{type} eq 'number'    ? $act_var->{number_value}
143                      : $cvar->{type} eq 'customer'  ? $act_var->{number_value}
144                      : $cvar->{type} eq 'vendor'    ? $act_var->{number_value}
145                      : $cvar->{type} eq 'part'      ? $act_var->{number_value}
146                      : $cvar->{type} eq 'bool'      ? $act_var->{bool_value}
147                      :                                $act_var->{text_value};
148       $cvar->{valid} = $valid;
149     } else {
150       $cvar->{valid} = $valid // 1;
151
152       if ($cvar->{type} eq 'date') {
153         if ($cvar->{default_value} eq 'NOW') {
154           $cvar->{value} = $cvar->{current_date};
155         } else {
156           $cvar->{value} = $cvar->{default_value};
157         }
158
159       } elsif ($cvar->{type} eq 'timestamp') {
160         if ($cvar->{default_value} eq 'NOW') {
161           $cvar->{value} = $cvar->{current_timestamp};
162         } else {
163           $cvar->{value} = $cvar->{default_value};
164         }
165
166       } elsif ($cvar->{type} eq 'bool') {
167         $cvar->{value} = $cvar->{default_value} * 1;
168
169       } elsif ($cvar->{type} eq 'number') {
170         $cvar->{value} = $cvar->{default_value} * 1 if ($cvar->{default_value} ne '');
171
172       } else {
173         $cvar->{value} = $cvar->{default_value};
174       }
175     }
176
177     if ($cvar->{type} eq 'number') {
178       $cvar->{value} = $form->format_amount($myconfig, $cvar->{value} * 1, $cvar->{precision});
179     } elsif ($cvar->{type} eq 'customer') {
180       require SL::DB::Customer;
181       $cvar->{value} = SL::DB::Manager::Customer->find_by(id => $cvar->{value} * 1);
182     } elsif ($cvar->{type} eq 'vendor') {
183       require SL::DB::Vendor;
184       $cvar->{value} = SL::DB::Manager::Vendor->find_by(id => $cvar->{value} * 1);
185     } elsif ($cvar->{type} eq 'part') {
186       require SL::DB::Part;
187       $cvar->{value} = SL::DB::Manager::Part->find_by(id => $cvar->{value} * 1);
188     }
189   }
190
191   $h_var->finish();
192
193   $main::lxdebug->leave_sub();
194
195   return $custom_variables;
196 }
197
198 sub save_custom_variables {
199   $main::lxdebug->enter_sub();
200
201   my $self     = shift;
202   my %params   = @_;
203
204   Common::check_params(\%params, qw(module trans_id variables));
205
206   my $myconfig = \%main::myconfig;
207   my $form     = $main::form;
208
209   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
210
211   my @configs  = $params{configs} ? @{ $params{configs} } : grep { $_->{module} eq $params{module} } @{ CVar->get_configs() };
212
213   my $query    =
214     qq|DELETE FROM custom_variables
215        WHERE (trans_id  = ?)
216          AND (config_id IN (SELECT DISTINCT id
217                             FROM custom_variable_configs
218                             WHERE module = ?))|;
219   my @values   = (conv_i($params{trans_id}), $params{module});
220
221   if ($params{sub_module}) {
222     $query .= qq| AND (sub_module = ?)|;
223     push @values, $params{sub_module};
224   }
225
226   do_query($form, $dbh, $query, @values);
227
228   $query  =
229     qq|INSERT INTO custom_variables (config_id, sub_module, trans_id, bool_value, timestamp_value, text_value, number_value)
230        VALUES                       (?,         ?,          ?,        ?,          ?,               ?,          ?)|;
231   my $sth = prepare_query($form, $dbh, $query);
232
233   foreach my $config (@configs) {
234     my @values = (conv_i($config->{id}), "$params{sub_module}", conv_i($params{trans_id}));
235
236     my $value  = $params{variables}->{"$params{name_prefix}cvar_$config->{name}$params{name_postfix}"};
237
238     if (($config->{type} eq 'text') || ($config->{type} eq 'textfield') || ($config->{type} eq 'select')) {
239       push @values, undef, undef, $value, undef;
240
241     } elsif (($config->{type} eq 'date') || ($config->{type} eq 'timestamp')) {
242       push @values, undef, conv_date($value), undef, undef;
243
244     } elsif ($config->{type} eq 'number') {
245       push @values, undef, undef, undef, conv_i($form->parse_amount($myconfig, $value));
246
247     } elsif ($config->{type} eq 'bool') {
248       push @values, $value ? 't' : 'f', undef, undef, undef;
249     } elsif (any { $config->{type} eq $_ } qw(customer vendor part)) {
250       push @values, undef, undef, undef, $value * 1;
251     }
252
253     do_statement($form, $sth, $query, @values);
254
255     if ($params{save_validity}) {
256       my $valid_index = "$params{name_prefix}cvar_$config->{name}$params{name_postfix}_valid";
257       $self->save_custom_variables_validity(trans_id  => $params{trans_id},
258                                             config_id => $config->{id},
259                                             validity  => ($params{variables}{$valid_index} || $params{always_valid} ? 1 : 0)
260                                            );
261     }
262   }
263
264   $sth->finish();
265
266   $dbh->commit() unless $params{dbh};
267
268   $main::lxdebug->leave_sub();
269 }
270
271 sub render_inputs {
272   $main::lxdebug->enter_sub(2);
273
274   my $self     = shift;
275   my %params   = @_;
276
277   Common::check_params(\%params, qw(variables));
278
279   my $myconfig = \%main::myconfig;
280   my $form     = $main::form;
281
282   my %options  = ( name_prefix       => "$params{name_prefix}",
283                    name_postfix      => "$params{name_postfix}",
284                    hide_non_editable => $params{hide_non_editable},
285                    show_disabled_message => $params{show_disabled_message},
286                  );
287
288   foreach my $var (@{ $params{variables} }) {
289     $var->{HTML_CODE} = $form->parse_html_template('amcvar/render_inputs',     { var => $var, %options });
290     $var->{VALID_BOX} = $form->parse_html_template('amcvar/render_checkboxes', { var => $var, %options });
291   }
292
293   $main::lxdebug->leave_sub(2);
294 }
295
296 sub render_search_options {
297   $main::lxdebug->enter_sub();
298
299   my $self     = shift;
300   my %params   = @_;
301
302   Common::check_params(\%params, qw(variables));
303
304   my $myconfig = \%main::myconfig;
305   my $form     = $main::form;
306
307   $params{hidden_cvar_filters} = $myconfig->{hide_cvar_search_options};
308
309   $params{include_prefix}   = 'l_' unless defined($params{include_prefix});
310   $params{include_value}  ||= '1';
311   $params{filter_prefix}  ||= '';
312
313   my $filter  = $form->parse_html_template('amcvar/search_filter',  \%params);
314   my $include = $form->parse_html_template('amcvar/search_include', \%params);
315
316   $main::lxdebug->leave_sub();
317
318   return ($filter, $include);
319 }
320
321 sub build_filter_query {
322   $main::lxdebug->enter_sub();
323
324   my $self     = shift;
325   my %params   = @_;
326
327   Common::check_params(\%params, qw(module trans_id_field filter));
328
329   my $myconfig = \%main::myconfig;
330   my $form     = $main::form;
331
332   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
333
334   my $configs  = $self->get_configs(%params);
335
336   my (@where, @values);
337
338   foreach my $config (@{ $configs }) {
339     next unless ($config->{searchable});
340
341     my $name = "cvar_$config->{name}";
342
343     my (@sub_values, @sub_where, $not);
344
345     if (($config->{type} eq 'text') || ($config->{type} eq 'textfield')) {
346       next unless ($params{filter}->{$name});
347
348       push @sub_where,  qq|cvar.text_value ILIKE ?|;
349       push @sub_values, '%' . $params{filter}->{$name} . '%'
350
351     } elsif ($config->{type} eq 'select') {
352       next unless ($params{filter}->{$name});
353
354       push @sub_where,  qq|cvar.text_value = ?|;
355       push @sub_values, $params{filter}->{$name};
356
357     } elsif (($config->{type} eq 'date') || ($config->{type} eq 'timestamp')) {
358       my $name_from = "${name}_from";
359       my $name_to   = "${name}_to";
360
361       if ($params{filter}->{$name_from}) {
362         push @sub_where,  qq|cvar.timestamp_value >= ?|;
363         push @sub_values, conv_date($params{filter}->{$name_from});
364       }
365
366       if ($params{filter}->{$name_to}) {
367         push @sub_where,  qq|cvar.timestamp_value <= ?|;
368         push @sub_values, conv_date($params{filter}->{$name_to});
369       }
370
371     } elsif ($config->{type} eq 'number') {
372       next if ($params{filter}->{$name} eq '');
373
374       my $f_op = $params{filter}->{"${name}_qtyop"};
375
376       my $op;
377       if ($f_op eq '==') {
378         $op  = '=';
379
380       } elsif ($f_op eq '=/=') {
381         $not = 'NOT';
382         $op  = '<>';
383
384       } elsif ($f_op eq '<') {
385         $not = 'NOT';
386         $op  = '>=';
387
388       } elsif ($f_op eq '<=') {
389         $not = 'NOT';
390         $op  = '>';
391
392       } elsif (($f_op eq '>') || ($f_op eq '>=')) {
393         $op  = $f_op;
394
395       } else {
396         $op  = '=';
397       }
398
399       push @sub_where,  qq|cvar.number_value $op ?|;
400       push @sub_values, $form->parse_amount($myconfig, $params{filter}->{$name});
401
402     } elsif ($config->{type} eq 'bool') {
403       next unless ($params{filter}->{$name});
404
405       $not = 'NOT' if ($params{filter}->{$name} eq 'no');
406       push @sub_where,  qq|COALESCE(cvar.bool_value, false) = TRUE|;
407     } elsif (any { $config->{type} eq $_ } qw(customer vendor)) {
408       next unless $params{filter}->{$name};
409
410       my $table = $config->{type};
411       push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM $table WHERE name ILIKE ?)|;
412       push @sub_values, "%$params{filter}->{$name}%";
413     } elsif ($config->{type} eq 'part') {
414       next unless $params{filter}->{$name};
415
416       push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM parts WHERE partnumber ILIKE ?)|;
417       push @sub_values, "%$params{filter}->{$name}%";
418     }
419
420     if (@sub_where) {
421       add_token(\@sub_where, \@sub_values, col => 'cvar.sub_module', val => $params{sub_module} || '');
422
423       push @where,
424         qq|$not EXISTS(
425              SELECT cvar.id
426              FROM custom_variables cvar
427              LEFT JOIN custom_variable_configs cvarcfg ON (cvar.config_id = cvarcfg.id)
428              WHERE (cvarcfg.module = ?)
429                AND (cvarcfg.id     = ?)
430                AND (cvar.trans_id  = $params{trans_id_field})
431                AND | . join(' AND ', map { "($_)" } @sub_where) . qq|)|;
432       push @values, $params{module}, conv_i($config->{id}), @sub_values;
433     }
434   }
435
436   my $query = join ' AND ', @where;
437
438   $main::lxdebug->leave_sub();
439
440   return ($query, @values);
441 }
442
443 sub add_custom_variables_to_report {
444   $main::lxdebug->enter_sub();
445
446   my $self      = shift;
447   my %params    = @_;
448
449   Common::check_params(\%params, qw(module trans_id_field column_defs data configs));
450
451   my $myconfig  = \%main::myconfig;
452   my $form      = $main::form;
453   my $locale    = $main::locale;
454
455   my $dbh       = $params{dbh} || $form->get_standard_dbh($myconfig);
456
457   my $configs   = [ grep { $_->{includeable} && $params{column_defs}->{"cvar_$_->{name}"}->{visible} } @{ $params{configs} } ];
458
459   if (!scalar(@{ $params{data} }) || ! scalar(@{ $configs })) {
460     $main::lxdebug->leave_sub();
461     return;
462   }
463
464   # allow sub_module to be a coderef or a fixed value
465   if (ref $params{sub_module} ne 'CODE') {
466     my $sub_module = "$params{sub_module}";
467     $params{sub_module} = sub { $sub_module };
468   }
469
470   my %cfg_map   = map { $_->{id} => $_ } @{ $configs };
471   my @cfg_ids   = keys %cfg_map;
472
473   my $query     =
474     qq|SELECT text_value, timestamp_value, timestamp_value::date AS date_value, number_value, bool_value, config_id
475        FROM custom_variables
476        WHERE (config_id IN (| . join(', ', ('?') x scalar(@cfg_ids)) . qq|))
477          AND (trans_id = ?)
478          AND (sub_module = ?)|;
479   my $sth       = prepare_query($form, $dbh, $query);
480
481   foreach my $row (@{ $params{data} }) {
482     do_statement($form, $sth, $query, @cfg_ids, conv_i($row->{$params{trans_id_field}}), $params{sub_module}->($row));
483
484     while (my $ref = $sth->fetchrow_hashref()) {
485       my $cfg = $cfg_map{$ref->{config_id}};
486
487       $row->{"cvar_$cfg->{name}"} =
488           $cfg->{type} eq 'date'      ? $ref->{date_value}
489         : $cfg->{type} eq 'timestamp' ? $ref->{timestamp_value}
490         : $cfg->{type} eq 'number'    ? $form->format_amount($myconfig, $ref->{number_value} * 1, $cfg->{precision})
491         : $cfg->{type} eq 'customer'  ? (SL::DB::Manager::Customer->find_by(id => 1*$ref->{number_value}) || SL::DB::Customer->new)->name
492         : $cfg->{type} eq 'vendor'    ? (SL::DB::Manager::Vendor->find_by(id => 1*$ref->{number_value})   || SL::DB::Vendor->new)->name
493         : $cfg->{type} eq 'part'      ? (SL::DB::Manager::Part->find_by(id => 1*$ref->{number_value})     || SL::DB::Part->new)->partnumber
494         : $cfg->{type} eq 'bool'      ? ($ref->{bool_value} ? $locale->text('Yes') : $locale->text('No'))
495         :                               $ref->{text_value};
496     }
497   }
498
499   $sth->finish();
500
501   $main::lxdebug->leave_sub();
502 }
503
504 sub get_field_format_list {
505   $main::lxdebug->enter_sub();
506
507   my $self          = shift;
508   my %params        = @_;
509
510   Common::check_params(\%params, qw(module));
511
512   my $myconfig      = \%main::myconfig;
513   my $form          = $main::form;
514
515   my $dbh           = $params{dbh} || $form->get_standard_dbh($myconfig);
516
517   my $configs       = $self->get_configs(%params);
518
519   my $date_fields   = [];
520   my $number_fields = {};
521
522   foreach my $config (@{ $configs }) {
523     my $name = "$params{prefix}cvar_$config->{name}";
524
525     if ($config->{type} eq 'date') {
526       push @{ $date_fields }, $name;
527
528     } elsif ($config->{type} eq 'number') {
529       $number_fields->{$config->{precision}} ||= [];
530       push @{ $number_fields->{$config->{precision}} }, $name;
531     }
532   }
533
534   $main::lxdebug->leave_sub();
535
536   return ($date_fields, $number_fields);
537 }
538
539 sub save_custom_variables_validity {
540   $main::lxdebug->enter_sub();
541
542   my $self     = shift;
543   my %params   = @_;
544
545   Common::check_params(\%params, qw(config_id trans_id validity));
546
547   my $myconfig = \%main::myconfig;
548   my $form     = $main::form;
549
550   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
551
552   my (@where, @values);
553   add_token(\@where, \@values, col => "config_id", val => $params{config_id}, esc => \&conv_i);
554   add_token(\@where, \@values, col => "trans_id",  val => $params{trans_id},  esc => \&conv_i);
555
556   my $where = scalar @where ? "WHERE " . join ' AND ', @where : '';
557   my $query = qq|DELETE FROM custom_variables_validity $where|;
558
559   do_query($form, $dbh, $query, @values);
560
561   $query  =
562     qq|INSERT INTO custom_variables_validity (config_id, trans_id)
563        VALUES                                (?,         ?       )|;
564   my $sth = prepare_query($form, $dbh, $query);
565
566   unless ($params{validity}) {
567     foreach my $config_id (listify($params{config_id})) {
568       foreach my $trans_id (listify($params{trans_id})) {
569         do_statement($form, $sth, $query, conv_i($config_id), conv_i($trans_id));
570       }
571     }
572   }
573
574   $sth->finish();
575
576   $dbh->commit() unless $params{dbh};
577
578   $main::lxdebug->leave_sub();
579 }
580
581 sub get_custom_variables_validity {
582   $main::lxdebug->enter_sub(2);
583
584   my $self     = shift;
585   my %params   = @_;
586
587   Common::check_params(\%params, qw(config_id trans_id));
588
589   my $myconfig = \%main::myconfig;
590   my $form     = $main::form;
591
592   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
593
594   my $query    = qq|SELECT id FROM custom_variables_validity WHERE config_id = ? AND trans_id = ? LIMIT 1|;
595
596   my ($invalid) = selectfirst_array_query($form, $dbh, $query, conv_i($params{config_id}), conv_i($params{trans_id}));
597
598   $main::lxdebug->leave_sub(2);
599
600   return !$invalid;
601 }
602
603 sub custom_variables_validity_by_trans_id {
604   $main::lxdebug->enter_sub(2);
605
606   my $self     = shift;
607   my %params   = @_;
608
609   return sub { 0 } unless $params{trans_id};
610
611   my $myconfig = \%main::myconfig;
612   my $form     = $main::form;
613
614   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
615
616   my $query    = qq|SELECT DISTINCT config_id FROM custom_variables_validity WHERE trans_id = ?|;
617
618   my %invalids = map { +($_->{config_id} => 1) } selectall_hashref_query($form, $dbh, $query, $params{trans_id});
619
620   $main::lxdebug->leave_sub(2);
621
622   return sub { !$invalids{+shift} };
623 }
624
625 sub parse {
626   my ($self, $value, $config) = @_;
627
628   return $::form->parse_amount(\%::myconfig, $value)          if $config->{type} eq 'number';
629   return DateTime->from_lxoffice($value)                      if $config->{type} eq 'date';
630   return !ref $value ? SL::DB::Manager::Customer->find_by(id => $value * 1) : $value  if $config->{type} eq 'customer';
631   return !ref $value ? SL::DB::Manager::Vendor->find_by(id => $value * 1)   : $value  if $config->{type} eq 'vendor';
632   return !ref $value ? SL::DB::Manager::Part->find_by(id => $value * 1)     : $value  if $config->{type} eq 'part';
633   return $value;
634 }
635
636 sub format_to_template {
637   my ($self, $value, $config) = @_;
638   # stupid template expects everything formated. except objects
639   # do not use outside of print routines for legacy templates
640
641   return $::form->format_amount(\%::myconfig, $value) if $config->{type} eq 'number';
642   return $value->to_lxoffice if $config->{type} eq 'date' && blessed $value && $value->can('to_lxoffice');
643   return $value;
644 }
645
646 1;
647
648 __END__
649
650 =head1 NAME
651
652 SL::CVar.pm - Custom Variables module
653
654 =head1 SYNOPSIS
655
656   # dealing with configs
657
658   my $all_configs = CVar->get_configs()
659
660   # dealing with custom vars
661
662   CVar->get_custom_variables(module => 'ic')
663
664 =head2 VALIDITY
665
666 Suppose the following scenario:
667
668 You have a lot of parts in your database, and a set of properties cofigured. Now not every part has every of these properties, some combinations will just make no sense. In order to clean up your inputs a bit, you want to mark certain combinations as invalid, blocking them from modification and possibly display.
669
670 Validity is assumed. If you modify validity, you actually save B<invalidity>.
671 Invalidity is saved as a function of config_id, and the trans_id
672
673 In the naive way, disable an attribute for a specific id (simple)
674
675 =cut