Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1c84c7f2

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID 1c84c7f2353749b92ab39bb6f3fec67e5e645756
  • Vorgänger e055b3ff
  • Nachfolger 7caf72ff

Viele weitere Klartextfelder bei Kunden-/Lieferantenstammdaten

Unterschiede anzeigen:

SL/Controller/CsvImport/Base.pm
5 5
use List::MoreUtils qw(pairwise);
6 6

  
7 7
use SL::Helper::Csv;
8
use SL::DB::Language;
9
use SL::DB::PaymentTerm;
8 10

  
9 11
use parent qw(Rose::Object);
10 12

  
11 13
use Rose::Object::MakeMethods::Generic
12 14
(
13 15
 scalar                  => [ qw(controller file csv) ],
14
 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class cvar_columns all_cvar_configs) ],
16
 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by) ],
15 17
);
16 18

  
17 19
sub run {
......
84 86
  return [ map { "cvar_" . $_->name } (@{ $self->all_cvar_configs }) ];
85 87
}
86 88

  
89
sub init_all_languages {
90
  my ($self) = @_;
91

  
92
  return SL::DB::Manager::Language->get_all;
93
}
94

  
95
sub init_payment_terms_by {
96
  my ($self) = @_;
97

  
98
  my $all_payment_terms = SL::DB::Manager::PaymentTerm->get_all;
99
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_payment_terms } } ) } qw(id description) };
100
}
101

  
87 102
sub handle_cvars {
88 103
  my ($self, $entry) = @_;
89 104

  
......
154 169
sub check_duplicates {
155 170
}
156 171

  
172
sub check_payment {
173
  my ($self, $entry) = @_;
174

  
175
  my $object = $entry->{object};
176

  
177
  # Check whether or not payment ID is valid.
178
  if ($object->payment_id && !$self->payment_terms_by->{id}->{ $object->payment_id }) {
179
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid payment terms');
180
    return 0;
181
  }
182

  
183
  # Map name to ID if given.
184
  if (!$object->payment_id && $entry->{raw_data}->{payment}) {
185
    my $terms = $self->payment_terms_by->{description}->{ $entry->{raw_data}->{payment} };
186

  
187
    if (!$terms) {
188
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid payment terms');
189
      return 0;
190
    }
191

  
192
    $object->payment_id($terms->id);
193
  }
194

  
195
  return 1;
196
}
197

  
157 198
sub save_objects {
158 199
  my ($self, %params) = @_;
159 200

  
SL/Controller/CsvImport/CustomerVendor.pm
3 3
use strict;
4 4

  
5 5
use SL::Helper::Csv;
6
use SL::DB::Business;
6 7
use SL::DB::CustomVariable;
7 8
use SL::DB::CustomVariableConfig;
9
use SL::DB::PaymentTerm;
8 10

  
9 11
use parent qw(SL::Controller::CsvImport::Base);
10 12

  
11 13
use Rose::Object::MakeMethods::Generic
12 14
(
13
 'scalar --get_set_init' => [ qw(table) ],
15
 'scalar --get_set_init' => [ qw(table languages_by businesses_by) ],
14 16
);
15 17

  
16 18
sub init_table {
......
29 31
  return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'CT' ]);
30 32
}
31 33

  
34
sub init_businesses_by {
35
  my ($self) = @_;
36

  
37
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ SL::DB::Manager::Business->get_all } } ) } qw(id description) };
38
}
39

  
40
sub init_languages_by {
41
  my ($self) = @_;
42

  
43
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_languages } } ) } qw(id description article_code) };
44
}
45

  
32 46
sub check_objects {
33 47
  my ($self) = @_;
34 48

  
......
38 52
  foreach my $entry (@{ $self->controller->data }) {
39 53
    my $object = $entry->{object};
40 54

  
41
    my $name =  $object->name;
42
    $name    =~ s/^\s+//;
43
    $name    =~ s/\s+$//;
44
    if (!$name) {
45
      push @{ $entry->{errors} }, $::locale->text('Error: Name missing');
46
      next;
47
    }
55
    next unless $self->check_name($entry);
56
    next unless $self->check_language($entry);
57
    next unless $self->check_business($entry);
58
    next unless $self->check_payment($entry);
59
    $self->handle_cvars($entry);
48 60

  
49 61
    if ($vcs_by_number{ $object->$numbercolumn }) {
50 62
      $entry->{object}->$numbercolumn('####');
51 63
    } else {
52 64
      $vcs_by_number{ $object->$numbercolumn } = $object;
53 65
    }
54

  
55
    $self->handle_cvars($entry);
56 66
  }
57 67

  
68
  $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(language business payment));
58 69
  $self->add_cvar_raw_data_columns;
59 70
}
60 71

  
......
81 92
  }
82 93
}
83 94

  
95
sub check_name {
96
  my ($self, $entry) = @_;
97

  
98
  my $name =  $entry->{object}->name;
99
  $name    =~ s/^\s+//;
100
  $name    =~ s/\s+$//;
101

  
102
  return 1 if $name;
103

  
104
  push @{ $entry->{errors} }, $::locale->text('Error: Name missing');
105
  return 0;
106
}
107

  
108
sub check_language {
109
  my ($self, $entry) = @_;
110

  
111
  my $object = $entry->{object};
112

  
113
  # Check whether or not language ID is valid.
114
  if ($object->language_id && !$self->languages_by->{id}->{ $object->language_id }) {
115
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid language');
116
    return 0;
117
  }
118

  
119
  # Map name to ID if given.
120
  if (!$object->language_id && $entry->{raw_data}->{language}) {
121
    my $language = $self->languages_by->{description}->{  $entry->{raw_data}->{language} }
122
                || $self->languages_by->{article_code}->{ $entry->{raw_data}->{language} };
123

  
124
    if (!$language) {
125
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid language');
126
      return 0;
127
    }
128

  
129
    $object->language_id($language->id);
130
  }
131

  
132
  return 1;
133
}
134

  
135
sub check_business {
136
  my ($self, $entry) = @_;
137

  
138
  my $object = $entry->{object};
139

  
140
  # Check whether or not business ID is valid.
141
  if ($object->business_id && !$self->businesss_by->{id}->{ $object->business_id }) {
142
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid business');
143
    return 0;
144
  }
145

  
146
  # Map name to ID if given.
147
  if (!$object->business_id && $entry->{raw_data}->{business}) {
148
    my $business = $self->businesses_by->{description}->{ $entry->{raw_data}->{business} };
149

  
150
    if (!$business) {
151
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid business');
152
      return 0;
153
    }
154

  
155
    $object->business_id($business->id);
156
  }
157

  
158
  return 1;
159
}
160

  
84 161
sub save_objects {
85 162
  my ($self, %params) = @_;
86 163

  
......
115 192
         );
116 193
}
117 194

  
195
sub init_profile {
196
  my ($self) = @_;
197

  
198
  my $profile = $self->SUPER::init_profile;
199
  delete @{$profile}{qw(language business salesman payment)};
200

  
201
  return $profile;
202
}
203

  
118 204
# TODO:
119
# Kundentyp
120
# salesman_id
121
# Sprache
122
# Zahlungsbedingungen
205
# salesman_id -- Kunden mit Typ 'Verkäufer', falls $::vertreter an ist, ansonsten Employees
123 206

  
124 207
1;
SL/Controller/CsvImport/Part.pm
7 7
use SL::DB::Buchungsgruppe;
8 8
use SL::DB::CustomVariable;
9 9
use SL::DB::CustomVariableConfig;
10
use SL::DB::Language;
11 10
use SL::DB::PartsGroup;
12 11
use SL::DB::PaymentTerm;
13 12
use SL::DB::PriceFactor;
......
19 18
use Rose::Object::MakeMethods::Generic
20 19
(
21 20
 scalar                  => [ qw(table) ],
22
 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by payment_terms_by packing_types_by partsgroups_by
23
                                 all_languages translation_columns) ],
21
 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by packing_types_by partsgroups_by
22
                                 translation_columns) ],
24 23
);
25 24

  
26 25
sub init_class {
......
42 41
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_price_factors } } ) } qw(id description) };
43 42
}
44 43

  
45
sub init_payment_terms_by {
46
  my ($self) = @_;
47

  
48
  my $all_payment_terms = SL::DB::Manager::PaymentTerm->get_all;
49
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_payment_terms } } ) } qw(id description) };
50
}
51

  
52 44
sub init_packing_types_by {
53 45
  my ($self) = @_;
54 46

  
......
93 85
                                                                    shoparticle_if_missing parts_type) };
94 86
}
95 87

  
96
sub init_all_languages {
97
  my ($self) = @_;
98

  
99
  return SL::DB::Manager::Language->get_all;
100
}
101

  
102 88
sub init_all_cvar_configs {
103 89
  my ($self) = @_;
104 90

  
......
291 277
  return 1;
292 278
}
293 279

  
294
sub check_payment {
295
  my ($self, $entry) = @_;
296

  
297
  my $object = $entry->{object};
298

  
299
  # Check whether or not payment ID is valid.
300
  if ($object->payment_id && !$self->payment_terms_by->{id}->{ $object->payment_id }) {
301
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid payment terms');
302
    return 0;
303
  }
304

  
305
  # Map name to ID if given.
306
  if (!$object->payment_id && $entry->{raw_data}->{payment}) {
307
    my $terms = $self->payment_terms_by->{description}->{ $entry->{raw_data}->{payment} };
308

  
309
    if (!$terms) {
310
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid payment terms');
311
      return 0;
312
    }
313

  
314
    $object->payment_id($terms->id);
315
  }
316

  
317
  return 1;
318
}
319

  
320 280
sub check_packing_type {
321 281
  my ($self, $entry) = @_;
322 282

  

Auch abrufbar als: Unified diff