sub _get_customers {
$main::lxdebug->enter_sub();
- my ($self, $dbh, $key, $limit) = @_;
-
- $key = "all_customers" unless ($key);
- my $limit_clause = "LIMIT $limit" if $limit;
+ my ($self, $dbh, $key) = @_;
- my $query = qq|SELECT * FROM customer WHERE NOT obsolete ORDER BY name $limit_clause|;
+ my $options = ref $key eq 'HASH' ? $key : { key => $key };
+ $options->{key} ||= "all_customers";
+ my $limit_clause = "LIMIT $options->{limit}" if $options->{limit};
+ my $where = $options->{business_is_salesman} ? qq| AND business_id IN (SELECT id FROM business WHERE salesman)| : '';
- $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+ my $query = qq|SELECT * FROM customer WHERE NOT obsolete $where ORDER BY name $limit_clause|;
+ $self->{ $options->{key} } = selectall_hashref_query($self, $dbh, $query);
$main::lxdebug->leave_sub();
}
}
if($params{"customers"}) {
- if (ref $params{"customers"} eq 'HASH') {
- $self->_get_customers($dbh, $params{"customers"}{key}, $params{"customers"}{limit});
- } else {
- $self->_get_customers($dbh, $params{"customers"});
- }
+ $self->_get_customers($dbh, $params{"customers"});
}
if($params{"vendors"}) {
my %myconfig = %main::myconfig;
my $locale = $main::locale;
- $form->get_lists(employees => "ALL_EMPLOYEES",
- taxzones => "ALL_TAXZONES",
- business_types => { key => 'ALL_SALESMAN_BUSINESSES', salesman => 1 });
+ $form->get_lists(employees => "ALL_EMPLOYEES",
+ taxzones => "ALL_TAXZONES");
$form->get_pricegroup(\%myconfig, { all => 1 });
+ $form->get_lists(customers => { key => "ALL_SALESMAN_CUSTOMERS", business_is_salesman => 1 }) if $::vertreter;
+
$form->{ALL_SALESMEN} = $form->{ALL_EMPLOYEES};
$form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
$form->{is_admin} = $myconfig{role} eq 'admin';
<th align="right">Vertreter</th>
<td>
[%- INCLUDE generic/multibox.html
- name = 'salesman_id',
- DATA = ALL_SALESMAN_BUSINESSES,
- show_empty = 1,
- id_key = 'id',
- label_key = 'description',
+ name = 'salesman_id',
+ DATA = ALL_SALESMAN_CUSTOMERS,
+ id_key = 'id',
+ label_key = 'name',
-%]
</td>
</tr>
label_key = 'description',
-%]
</td>
- [%- IF is_customer && !use_vertreter %]
+ [%- IF is_customer && !conf_vertreter %]
<th align="right">Verkäufer/in</th>
<td>
[%- INCLUDE generic/multibox.html
<th align="right"><translate>Representative</translate></th>
<td>
[%- INCLUDE generic/multibox.html
- name = 'salesman_id',
- DATA = ALL_SALESMAN_BUSINESSES,
- show_empty = 1,
- id_key = 'id',
- label_key = 'description',
+ name = 'salesman_id',
+ DATA = ALL_SALESMAN_CUSTOMERS,
+ id_key = 'id',
+ label_key = 'name',
-%]
</td>
</tr>
label_key = 'description',
-%]
</td>
- [%- IF is_customer && !use_vertreter %]
+ [%- IF is_customer && !conf_vertreter %]
<th align="right"><translate>Salesman</translate></th>
<td>
[%- INCLUDE generic/multibox.html