$cvar->{value} = $cvar->{type} eq 'date' ? $act_var->{date_value}
: $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 'bool' ? $act_var->{bool_value}
: $act_var->{text_value};
$cvar->{valid} = $valid;
if ($cvar->{type} eq 'number') {
$cvar->{value} = $form->format_amount($myconfig, $cvar->{value} * 1, $cvar->{precision});
+ } elsif ($cvar->{type} eq 'customer') {
+ require SL::DB::Customer;
+ $cvar->{value} = SL::DB::Manager::Customer->find_by(id => $cvar->{value} * 1);
}
}
} elsif ($config->{type} eq 'bool') {
push @values, $value ? 't' : 'f', undef, undef, undef;
+ } elsif ($config->{type} eq 'customer') {
+ push @values, undef, undef, undef, $value * 1;
}
do_statement($form, $sth, $query, @values);
$not = 'NOT' if ($params{filter}->{$name} eq 'no');
push @sub_where, qq|COALESCE(cvar.bool_value, false) = TRUE|;
+ } elsif ($config->{type} eq 'customer') {
+ next unless $params{filter}->{$name};
+
+ push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM customer WHERE name ILIKE ?)|;
+ push @sub_values, "%$params{filter}->{$name}%";
}
if (@sub_where) {
$cfg->{type} eq 'date' ? $ref->{date_value}
: $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})->name
: $cfg->{type} eq 'bool' ? ($ref->{bool_value} ? $locale->text('Yes') : $locale->text('No'))
: $ref->{text_value};
}
'timestamp' => $locale->text('Timestamp'),
'bool' => $locale->text('Yes/No (Checkbox)'),
'select' => $locale->text('Selection'),
+ 'customer' => $locale->text('Customer'),
);
-our @types = qw(text textfield number date bool select); # timestamp
+our @types = qw(text textfield number date bool select customer); # timestamp
our @modules = ({ module => 'CT', description => $locale->text('Customers and vendors') },
{ module => 'IC', description => $locale->text('Parts, services and assemblies') },
[%- USE T8 %]
-[% USE HTML %]
+[%- USE HTML %]
+[%- USE L %]
[%- SET var_name = HTML.escape(name_prefix) _ "cvar_" _ HTML.escape(var.name) _ HTML.escape(name_postfix) -%]
[%- ELSIF var.type == 'timestamp' %]
<input name="[% var_name %]" value="[% HTML.escape(var.value) %]">
+[%- ELSIF var.type == 'customer' %]
+[% L.customer_picker(var_name, var.value) %]
+
[%- ELSIF var.type == 'select' %]
<select name="[% var_name %]">
[%- USE T8 %]
[%- USE HTML %]
+[%- USE L %]
[%- BLOCK cvar_name %][% HTML.escape(cvar.name_prefix) _ "cvar_" _ HTML.escape(cvar.var.name) _ HTML.escape(cvar.name_postfix) -%][% END %]
[%- BLOCK cvar_inputs %]
[%- %]
<option[% IF option.value == cvar.value %] selected[% END %]>[% HTML.escape(option.value) %]</option>
[%- END %]
</select>
+[%- ELSIF cvar.var.type == 'customer' %]
+[% render_input_blocks__cvar_name = PROCESS cvar_name %][% L.customer_picker(render_input_blocks__cvar_name, cvar.value) %]
[%- ELSE %]
<input name="[% PROCESS cvar_name %]" value="[% HTML.escape(cvar.value) %]" [%- IF cvar.var.maxlength %] maxlength="[% HTML.escape(cvar.var.maxlength) %]"[% END -%]>
[%- END %]