Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ef220490

Von Moritz Bunkus vor mehr als 15 Jahren hinzugefügt

  • ID ef220490853ca3b41b4b67568af4bf6b6dc5cc30
  • Vorgänger 5c8d3d82
  • Nachfolger 0af7a3a5

Ausweitung der benutzerdefinierten Variablen für Waren/Dienstleistungen/Erzeugnisse auf Anzeige/Modifikation in Angeboten/Aufträgen.

Unterschiede anzeigen:

SL/CVar.pm
33 33
      $config->{precision} = $1 if ($config->{options} =~ m/precision=(\d+)/i);
34 34

  
35 35
    }
36

  
37
    $self->_unpack_flags($config);
36 38
  }
37 39

  
38 40
  $main::lxdebug->leave_sub();
......
57 59

  
58 60
  my $config   = selectfirst_hashref_query($form, $dbh, $query, conv_i($params{id})) || { };
59 61

  
62
  $self->_unpack_flags($config);
63

  
60 64
  $main::lxdebug->leave_sub();
61 65

  
62 66
  return $config;
63 67
}
64 68

  
69
sub _unpack_flags {
70
  $main::lxdebug->enter_sub();
71

  
72
  my $self   = shift;
73
  my $config = shift;
74

  
75
  foreach my $flag (split m/:/, $config->{flags}) {
76
    if ($flag =~ m/(.*?)=(.*)/) {
77
      $config->{"flag_${1}"}    = $2;
78
    } else {
79
      $config->{"flag_${flag}"} = 1;
80
    }
81
  }
82

  
83
  $main::lxdebug->leave_sub();
84
}
85

  
65 86
sub save_config {
66 87
  $main::lxdebug->enter_sub();
67 88

  
......
177 198
    qq|SELECT text_value, timestamp_value, timestamp_value::date AS date_value, number_value, bool_value
178 199
       FROM custom_variables
179 200
       WHERE (config_id = ?) AND (trans_id = ?)|;
201
  $q_var      .= qq| AND (sub_module = ?)| if $params{sub_module};
180 202
  my $h_var    = prepare_query($form, $dbh, $q_var);
181 203

  
182 204
  my $custom_variables = selectall_hashref_query($form, $dbh, $q_cfg, $params{module});
......
201 223

  
202 224
    my $act_var;
203 225
    if ($params{trans_id}) {
204
      do_statement($form, $h_var, $q_var, conv_i($cvar->{id}), conv_i($params{trans_id}));
226
      my @values = (conv_i($cvar->{id}), conv_i($params{trans_id}));
227
      push @values, $params{sub_module} if $params{sub_module};
228

  
229
      do_statement($form, $h_var, $q_var, @values);
205 230
      $act_var = $h_var->fetchrow_hashref();
206 231
    }
207 232

  
......
263 288

  
264 289
  my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
265 290

  
266
  my @configs  = grep { $_->{module} eq $params{module} } @{ CVar->get_configs() };
291
  my @configs  = $params{configs} ? @{ $params{configs} } : grep { $_->{module} eq $params{module} } @{ CVar->get_configs() };
267 292

  
268 293
  my $query    =
269 294
    qq|DELETE FROM custom_variables
......
271 296
         AND (config_id IN (SELECT DISTINCT id
272 297
                            FROM custom_variable_configs
273 298
                            WHERE module = ?))|;
274
  do_query($form, $dbh, $query, conv_i($params{trans_id}), $params{module});
299
  my @values   = (conv_i($params{trans_id}), $params{module});
300

  
301
  if ($params{sub_module}) {
302
    $query .= qq| AND (sub_module = ?)|;
303
    push @values, $params{sub_module};
304
  }
305

  
306
  do_query($form, $dbh, $query, @values);
275 307

  
276 308
  $query  =
277
    qq|INSERT INTO custom_variables (config_id, trans_id, bool_value, timestamp_value, text_value, number_value)
278
       VALUES                       (?,         ?,        ?,          ?,               ?,          ?)|;
309
    qq|INSERT INTO custom_variables (config_id, sub_module, trans_id, bool_value, timestamp_value, text_value, number_value)
310
       VALUES                       (?,         ?,          ?,        ?,          ?,               ?,          ?)|;
279 311
  my $sth = prepare_query($form, $dbh, $query);
280 312

  
281 313
  foreach my $config (@configs) {
282
    my @values = (conv_i($config->{id}), conv_i($params{trans_id}));
314
    my @values = (conv_i($config->{id}), "$params{sub_module}", conv_i($params{trans_id}));
283 315

  
284
    my $value  = $params{variables}->{"cvar_$config->{name}"};
316
    my $value  = $params{variables}->{"$params{name_prefix}cvar_$config->{name}$params{name_postfix}"};
285 317

  
286 318
    if (($config->{type} eq 'text') || ($config->{type} eq 'textfield') || ($config->{type} eq 'select')) {
287 319
      push @values, undef, undef, $value, undef;
......
317 349
  my $myconfig = \%main::myconfig;
318 350
  my $form     = $main::form;
319 351

  
352
  my %options  = ( name_prefix       => "$params{name_prefix}",
353
                   name_postfix      => "$params{name_postfix}",
354
                   hide_non_editable => $params{hide_non_editable},
355
                 );
356

  
320 357
  foreach my $var (@{ $params{variables} }) {
321
    $var->{HTML_CODE} = $form->parse_html_template('amcvar/render_inputs', { 'var' => $var });
358
    $var->{HTML_CODE} = $form->parse_html_template('amcvar/render_inputs', { 'var' => $var, %options });
322 359
  }
323 360

  
324 361
  $main::lxdebug->leave_sub();
......
434 471
    }
435 472

  
436 473
    if (@sub_where) {
474
      push @sub_where,  qq|cvar.sub_module = ?|;
475
      push @sub_values, "$params{sub_module}";
476

  
437 477
      push @where,
438 478
        qq|$not EXISTS(
439 479
             SELECT cvar.id
......
481 521
  my $query     =
482 522
    qq|SELECT text_value, timestamp_value, timestamp_value::date AS date_value, number_value, bool_value, config_id
483 523
       FROM custom_variables
484
       WHERE (config_id IN (| . join(', ', ('?') x scalar(@cfg_ids)) . qq|)) AND (trans_id = ?)|;
524
       WHERE (config_id IN (| . join(', ', ('?') x scalar(@cfg_ids)) . qq|))
525
         AND (trans_id = ?)
526
         AND (sub_module = ?)|;
485 527
  my $sth       = prepare_query($form, $dbh, $query);
486 528

  
487 529
  foreach my $row (@{ $params{data} }) {
488
    do_statement($form, $sth, $query, @cfg_ids, conv_i($row->{$params{trans_id_field}}));
530
    do_statement($form, $sth, $query, @cfg_ids, conv_i($row->{$params{trans_id_field}}), "$params{sub_module}");
489 531

  
490 532
    while (my $ref = $sth->fetchrow_hashref()) {
491 533
      my $cfg = $cfg_map{$ref->{config_id}};

Auch abrufbar als: Unified diff