use Data::Dumper;
use SL::DBUtils;
-use SL::MoreCommon qw(listify);
+use SL::MoreCommon qw(any listify);
sub get_configs {
$main::lxdebug->enter_sub();
: $cvar->{type} eq 'timestamp' ? $act_var->{timestamp_value}
: $cvar->{type} eq 'number' ? $act_var->{number_value}
: $cvar->{type} eq 'customer' ? $act_var->{number_value}
+ : $cvar->{type} eq 'vendor' ? $act_var->{number_value}
+ : $cvar->{type} eq 'part' ? $act_var->{number_value}
: $cvar->{type} eq 'bool' ? $act_var->{bool_value}
: $act_var->{text_value};
$cvar->{valid} = $valid;
} elsif ($cvar->{type} eq 'customer') {
require SL::DB::Customer;
$cvar->{value} = SL::DB::Manager::Customer->find_by(id => $cvar->{value} * 1);
+ } elsif ($cvar->{type} eq 'vendor') {
+ require SL::DB::Vendor;
+ $cvar->{value} = SL::DB::Manager::Vendor->find_by(id => $cvar->{value} * 1);
+ } elsif ($cvar->{type} eq 'part') {
+ require SL::DB::Part;
+ $cvar->{value} = SL::DB::Manager::Part->find_by(id => $cvar->{value} * 1);
}
}
} elsif ($config->{type} eq 'bool') {
push @values, $value ? 't' : 'f', undef, undef, undef;
- } elsif ($config->{type} eq 'customer') {
+ } elsif (any { $config->{type} eq $_ } qw(customer vendor part)) {
push @values, undef, undef, undef, $value * 1;
}
$not = 'NOT' if ($params{filter}->{$name} eq 'no');
push @sub_where, qq|COALESCE(cvar.bool_value, false) = TRUE|;
- } elsif ($config->{type} eq 'customer') {
+ } elsif (any { $config->{type} eq $_ } qw(customer vendor part)) {
next unless $params{filter}->{$name};
- push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM customer WHERE name ILIKE ?)|;
+ my $table = $config->{type};
+ push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM $table WHERE name ILIKE ?)|;
+ push @sub_values, "%$params{filter}->{$name}%";
+ } elsif ($config->{type} eq 'part') {
+ next unless $params{filter}->{$name};
+
+ push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM parts WHERE partnumber ILIKE ?)|;
push @sub_values, "%$params{filter}->{$name}%";
}
: $cfg->{type} eq 'timestamp' ? $ref->{timestamp_value}
: $cfg->{type} eq 'number' ? $form->format_amount($myconfig, $ref->{number_value} * 1, $cfg->{precision})
: $cfg->{type} eq 'customer' ? (SL::DB::Manager::Customer->find_by(id => 1*$ref->{number_value}) || SL::DB::Customer->new)->name
+ : $cfg->{type} eq 'vendor' ? (SL::DB::Manager::Vendor->find_by(id => 1*$ref->{number_value}) || SL::DB::Vendor->new)->name
+ : $cfg->{type} eq 'part' ? (SL::DB::Manager::Part->find_by(id => 1*$ref->{number_value}) || SL::DB::Part->new)->partnumber
: $cfg->{type} eq 'bool' ? ($ref->{bool_value} ? $locale->text('Yes') : $locale->text('No'))
: $ref->{text_value};
}
JS
}
+# simple version with select_tag
+sub vendor_selector {
+ my ($self, $name, $value, %params) = @_;
+
+ my $actual_vendor_id = (defined $::form->{"$name"})? ((ref $::form->{"$name"}) ? $::form->{"$name"}->id : $::form->{"$name"}) :
+ (ref $value && $value->can('id')) ? $value->id : '';
+ my $options_str = $self->options_for_select(SL::DB::Manager::Vendor->get_all(),
+ default => $actual_vendor_id,
+ title_sub => sub { $_[0]->vendornumber . " : " . $_[0]->name },
+ 'with_empty' => 1);
+
+ return $self->select_tag($name, $options_str, %params);
+}
+
+
+# simple version with select_tag
+sub part_selector {
+ my ($self, $name, $value, %params) = @_;
+
+ my $actual_part_id = (defined $::form->{"$name"})? ((ref $::form->{"$name"})? $::form->{"$name"}->id : $::form->{"$name"}) :
+ (ref $value && $value->can('id')) ? $value->id : '';
+ my $options_str = $self->options_for_select(SL::DB::Manager::Part->get_all(),
+ default => $actual_part_id,
+ title_sub => sub { $_[0]->partnumber . " : " . $_[0]->description },
+ 'with_empty' => 1);
+
+ return $self->select_tag($name, $options_str, %params);
+}
+
+
sub javascript_tag {
my $self = shift;
my $code = '';
'bool' => $locale->text('Yes/No (Checkbox)'),
'select' => $locale->text('Selection'),
'customer' => $locale->text('Customer'),
+ 'vendor' => $locale->text('Vendor'),
+ 'part' => $locale->text('Part'),
);
-our @types = qw(text textfield number date bool select customer); # timestamp
+our @types = qw(text textfield number date bool select customer vendor part); # timestamp
our @modules = ({ module => 'CT', description => $locale->text('Customers and vendors') },
{ module => 'Contacts', description => $locale->text('Contact persons') },