Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision eb518737

Von Bernd Blessmann vor mehr als 12 Jahren hinzugefügt

  • ID eb518737fe286cb180f4b5d4c0fc54831381e2cf
  • Vorgänger 7846799c
  • Nachfolger b213d89c

Waren und Lieferanten als benutzerdefinierte Variablen hinzugefügt.

Mit einfachen vendor_ und part_selectoren im L-Plugin, die das
select_tag verwenden. vc_limit wird nicht berücksichtigt und das
ganze ist nur rudimentär getestet.

Unterschiede anzeigen:

SL/CVar.pm
7 7
use Data::Dumper;
8 8

  
9 9
use SL::DBUtils;
10
use SL::MoreCommon qw(listify);
10
use SL::MoreCommon qw(any listify);
11 11

  
12 12
sub get_configs {
13 13
  $main::lxdebug->enter_sub();
......
243 243
                     : $cvar->{type} eq 'timestamp' ? $act_var->{timestamp_value}
244 244
                     : $cvar->{type} eq 'number'    ? $act_var->{number_value}
245 245
                     : $cvar->{type} eq 'customer'  ? $act_var->{number_value}
246
                     : $cvar->{type} eq 'vendor'    ? $act_var->{number_value}
247
                     : $cvar->{type} eq 'part'      ? $act_var->{number_value}
246 248
                     : $cvar->{type} eq 'bool'      ? $act_var->{bool_value}
247 249
                     :                                $act_var->{text_value};
248 250
      $cvar->{valid} = $valid;
......
279 281
    } elsif ($cvar->{type} eq 'customer') {
280 282
      require SL::DB::Customer;
281 283
      $cvar->{value} = SL::DB::Manager::Customer->find_by(id => $cvar->{value} * 1);
284
    } elsif ($cvar->{type} eq 'vendor') {
285
      require SL::DB::Vendor;
286
      $cvar->{value} = SL::DB::Manager::Vendor->find_by(id => $cvar->{value} * 1);
287
    } elsif ($cvar->{type} eq 'part') {
288
      require SL::DB::Part;
289
      $cvar->{value} = SL::DB::Manager::Part->find_by(id => $cvar->{value} * 1);
282 290
    }
283 291
  }
284 292

  
......
340 348

  
341 349
    } elsif ($config->{type} eq 'bool') {
342 350
      push @values, $value ? 't' : 'f', undef, undef, undef;
343
    } elsif ($config->{type} eq 'customer') {
351
    } elsif (any { $config->{type} eq $_ } qw(customer vendor part)) {
344 352
      push @values, undef, undef, undef, $value * 1;
345 353
    }
346 354

  
......
498 506

  
499 507
      $not = 'NOT' if ($params{filter}->{$name} eq 'no');
500 508
      push @sub_where,  qq|COALESCE(cvar.bool_value, false) = TRUE|;
501
    } elsif ($config->{type} eq 'customer') {
509
    } elsif (any { $config->{type} eq $_ } qw(customer vendor part)) {
502 510
      next unless $params{filter}->{$name};
503 511

  
504
      push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM customer WHERE name ILIKE ?)|;
512
      my $table = $config->{type};
513
      push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM $table WHERE name ILIKE ?)|;
514
      push @sub_values, "%$params{filter}->{$name}%";
515
    } elsif ($config->{type} eq 'part') {
516
      next unless $params{filter}->{$name};
517

  
518
      push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM parts WHERE partnumber ILIKE ?)|;
505 519
      push @sub_values, "%$params{filter}->{$name}%";
506 520
    }
507 521

  
......
577 591
        : $cfg->{type} eq 'timestamp' ? $ref->{timestamp_value}
578 592
        : $cfg->{type} eq 'number'    ? $form->format_amount($myconfig, $ref->{number_value} * 1, $cfg->{precision})
579 593
        : $cfg->{type} eq 'customer'  ? (SL::DB::Manager::Customer->find_by(id => 1*$ref->{number_value}) || SL::DB::Customer->new)->name
594
        : $cfg->{type} eq 'vendor'    ? (SL::DB::Manager::Vendor->find_by(id => 1*$ref->{number_value})   || SL::DB::Vendor->new)->name
595
        : $cfg->{type} eq 'part'      ? (SL::DB::Manager::Part->find_by(id => 1*$ref->{number_value})     || SL::DB::Part->new)->partnumber
580 596
        : $cfg->{type} eq 'bool'      ? ($ref->{bool_value} ? $locale->text('Yes') : $locale->text('No'))
581 597
        :                               $ref->{text_value};
582 598
    }
SL/Template/Plugin/L.pm
342 342
JS
343 343
}
344 344

  
345
# simple version with select_tag
346
sub vendor_selector {
347
  my ($self, $name, $value, %params) = @_;
348

  
349
  my $actual_vendor_id = (defined $::form->{"$name"})? ((ref $::form->{"$name"}) ? $::form->{"$name"}->id : $::form->{"$name"}) :
350
                         (ref $value && $value->can('id')) ? $value->id : '';
351
  my $options_str = $self->options_for_select(SL::DB::Manager::Vendor->get_all(),
352
                                              default      => $actual_vendor_id,
353
                                              title_sub    => sub { $_[0]->vendornumber . " : " . $_[0]->name },
354
                                              'with_empty' => 1);
355
  
356
  return $self->select_tag($name, $options_str, %params);
357
}
358

  
359

  
360
# simple version with select_tag
361
sub part_selector {
362
  my ($self, $name, $value, %params) = @_;
363

  
364
  my $actual_part_id = (defined $::form->{"$name"})? ((ref $::form->{"$name"})? $::form->{"$name"}->id : $::form->{"$name"}) :
365
                       (ref $value && $value->can('id')) ? $value->id : '';
366
  my $options_str = $self->options_for_select(SL::DB::Manager::Part->get_all(),
367
                                              default      => $actual_part_id,
368
                                              title_sub    => sub { $_[0]->partnumber . " : " . $_[0]->description },
369
                                              'with_empty' => 1);
370
  
371
  return $self->select_tag($name, $options_str, %params);
372
}
373

  
374

  
345 375
sub javascript_tag {
346 376
  my $self = shift;
347 377
  my $code = '';
bin/mozilla/amcvar.pl
55 55
                     'bool'      => $locale->text('Yes/No (Checkbox)'),
56 56
                     'select'    => $locale->text('Selection'),
57 57
                     'customer'  => $locale->text('Customer'),
58
                     'vendor'    => $locale->text('Vendor'),
59
                     'part'      => $locale->text('Part'),
58 60
                     );
59 61

  
60
our @types = qw(text textfield number date bool select customer); # timestamp
62
our @types = qw(text textfield number date bool select customer vendor part); # timestamp
61 63

  
62 64
our @modules = ({ module => 'CT',       description => $locale->text('Customers and vendors')          },
63 65
                { module => 'Contacts', description => $locale->text('Contact persons')                },
templates/webpages/amcvar/render_inputs.html
27 27
[%- ELSIF var.type == 'customer' %]
28 28
[% L.customer_picker(var_name, var.value) %]
29 29

  
30
[%- ELSIF var.type == 'vendor' %]
31
[% L.vendor_selector(var_name, var.value) %]
32

  
33
[%- ELSIF var.type == 'part' %]
34
[% L.part_selector(var_name, var.value) %]
35

  
30 36
[%- ELSIF var.type == 'select' %]
31 37

  
32 38
<select name="[% var_name %]">
templates/webpages/amcvar/render_inputs_block.html
30 30
[%- ELSIF cvar.var.type == 'customer' %]
31 31
[%- L.customer_picker(render_input_blocks__cvar_name, cvar.value) %]
32 32

  
33
[%- ELSIF cvar.var.type == 'vendor' %]
34
[% L.vendor_selector(render_input_blocks__cvar_name, cvar.value) %]
35

  
36
[%- ELSIF cvar.var.type == 'part' %]
37
[% L.part_selector(render_input_blocks__cvar_name, cvar.value) %]
38

  
33 39
[%- ELSIF cvar.var.type == 'number' %]
34 40
[%- L.input_tag(render_input_blocks__cvar_name, LxERP.format_amount(cvar.value, -2)) %]
35 41

  

Auch abrufbar als: Unified diff