Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d13c7050

Von Bernd Bleßmann vor etwa 9 Jahren hinzugefügt

  • ID d13c70502afaee0fec445b82a0e1db1e37d0dfd2
  • Vorgänger 232d7868
  • Nachfolger 40c5441d

CsvImport für Kunden und Lieferanten: Verkäufer importieren können.

Unterschiede anzeigen:

SL/Controller/CsvImport/CustomerVendor.pm
14 14

  
15 15
use Rose::Object::MakeMethods::Generic
16 16
(
17
 'scalar --get_set_init' => [ qw(table languages_by businesses_by) ],
17
 'scalar --get_set_init' => [ qw(table languages_by businesses_by salesmen_by) ],
18 18
);
19 19

  
20 20
sub set_profile_defaults {
......
50 50
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_languages } } ) } qw(id description article_code) };
51 51
}
52 52

  
53
sub init_salesmen_by {
54
  my ($self) = @_;
55

  
56
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ SL::DB::Manager::Employee->get_all } } ) } qw(id name) };
57
}
58

  
53 59
sub check_objects {
54 60
  my ($self) = @_;
55 61

  
......
74 80
    $self->check_delivery_term($entry);
75 81
    $self->check_taxzone($entry,  take_default => 1);
76 82
    $self->check_currency($entry, take_default => 1);
83
    $self->check_salesman($entry);
77 84
    $self->handle_cvars($entry);
78 85

  
79 86
    next if @{ $entry->{errors} };
......
196 203
  return 1;
197 204
}
198 205

  
206
sub check_salesman {
207
  my ($self, $entry) = @_;
208

  
209
  my $object = $entry->{object};
210

  
211
  # Check whether or not salesman ID is valid.
212
  if ($object->salesman_id && !$self->salesmen_by->{id}->{ $object->salesman_id }) {
213
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid salesman');
214
    return 0;
215
  }
216

  
217
  # Map name to ID if given.
218
  if (!$object->salesman_id && $entry->{raw_data}->{salesman}) {
219
    my $salesman = $self->salesmen_by->{name}->{ $entry->{raw_data}->{salesman} };
220

  
221
    if (!$salesman) {
222
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid salesman');
223
      return 0;
224
    }
225

  
226
    $object->salesman_id($salesman->id);
227

  
228
    # register salesman_id for method copying later
229
    $self->clone_methods->{salesman_id} = 1;
230
  }
231

  
232
  return 1;
233
}
234

  
199 235
sub save_objects {
200 236
  my ($self, %params) = @_;
201 237

  
......
224 260
  my ($self) = @_;
225 261

  
226 262
  my $profile = $self->SUPER::init_profile;
227
  delete @{$profile}{qw(business datevexport language payment delivery_term salesman salesman_id taxincluded terms)};
263
  delete @{$profile}{qw(business datevexport language payment delivery_term taxincluded terms)};
264
  delete @{$profile}{qw(salesman salesman_id)}    if $::instance_conf->get_vertreter;
228 265

  
229 266
  return $profile;
230 267
}
......
280 317
                                 { name => 'ustid',             description => $::locale->text('sales tax identification number') },
281 318
                                 { name => 'zipcode',           description => $::locale->text('Zipcode')                         },
282 319
                                );
320

  
321
  if (!$::instance_conf->get_vertreter) {
322
    $self->add_displayable_columns({ name => 'salesman_id', description => $::locale->text('Salesman (database ID)') });
323
    $self->add_displayable_columns({ name => 'salesman',    description => $::locale->text('Salesman') });
324
  }
325

  
283 326
}
284 327

  
285 328
# TODO:

Auch abrufbar als: Unified diff