23 |
23 |
use Rose::Object::MakeMethods::Generic
|
24 |
24 |
(
|
25 |
25 |
scalar => [ qw(controller file csv test_run save_with_cascade) ],
|
26 |
|
'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by delivery_terms_by all_bank_accounts all_vc vc_by clone_methods) ],
|
|
26 |
'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by delivery_terms_by all_bank_accounts all_vc vc_by vc_counts_by clone_methods) ],
|
27 |
27 |
);
|
28 |
28 |
|
29 |
29 |
sub run {
|
... | ... | |
197 |
197 |
gln => \%by_gln };
|
198 |
198 |
}
|
199 |
199 |
|
|
200 |
sub init_vc_counts_by {
|
|
201 |
my ($self) = @_;
|
|
202 |
|
|
203 |
my $vc_counts_by;
|
|
204 |
|
|
205 |
$vc_counts_by->{number}->{customers}->{$_->number}++ for @{ $self->all_vc->{customers} };
|
|
206 |
$vc_counts_by->{number}->{vendors}-> {$_->number}++ for @{ $self->all_vc->{vendors} };
|
|
207 |
$vc_counts_by->{name}-> {customers}->{$_->name}++ for @{ $self->all_vc->{customers} };
|
|
208 |
$vc_counts_by->{name}-> {vendors}-> {$_->name}++ for @{ $self->all_vc->{vendors} };
|
|
209 |
$vc_counts_by->{gln}-> {customers}->{$_->gln}++ for @{ $self->all_vc->{customers} };
|
|
210 |
$vc_counts_by->{gln}-> {vendors}-> {$_->gln}++ for @{ $self->all_vc->{vendors} };
|
|
211 |
|
|
212 |
return $vc_counts_by;
|
|
213 |
}
|
|
214 |
|
200 |
215 |
sub check_vc {
|
201 |
216 |
my ($self, $entry, $id_column) = @_;
|
202 |
217 |
|
... | ... | |
204 |
219 |
$entry->{object}->$id_column(undef) if !$self->vc_by->{id}->{ $entry->{object}->$id_column };
|
205 |
220 |
}
|
206 |
221 |
|
|
222 |
my $is_ambiguous;
|
207 |
223 |
if (!$entry->{object}->$id_column) {
|
208 |
|
my $vc = ($entry->{raw_data}->{customernumber} && $self->vc_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} })
|
209 |
|
|| ($entry->{raw_data}->{vendornumber} && $self->vc_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} });
|
|
224 |
my $vc = $entry->{raw_data}->{customernumber} && $self->vc_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} };
|
|
225 |
if ($vc && $self->vc_counts_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} } > 1) {
|
|
226 |
$vc = undef;
|
|
227 |
$is_ambiguous = 1;
|
|
228 |
}
|
|
229 |
$vc ||= $entry->{raw_data}->{vendornumber} && $self->vc_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} };
|
|
230 |
if ($vc && $self->vc_counts_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} } > 1) {
|
|
231 |
$vc = undef;
|
|
232 |
$is_ambiguous = 1;
|
|
233 |
}
|
|
234 |
|
210 |
235 |
$entry->{object}->$id_column($vc->id) if $vc;
|
211 |
236 |
}
|
212 |
237 |
|
213 |
238 |
if (!$entry->{object}->$id_column) {
|
214 |
|
my $vc = ($entry->{raw_data}->{customer} && $self->vc_by->{name}->{customers}->{ $entry->{raw_data}->{customer} })
|
215 |
|
|| ($entry->{raw_data}->{vendor} && $self->vc_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} });
|
|
239 |
my $vc = $entry->{raw_data}->{customer} && $self->vc_by->{name}->{customers}->{ $entry->{raw_data}->{customer} };
|
|
240 |
if ($vc && $self->vc_counts_by->{name}->{customers}->{ $entry->{raw_data}->{customer} } > 1) {
|
|
241 |
$vc = undef;
|
|
242 |
$is_ambiguous = 1;
|
|
243 |
}
|
|
244 |
$vc ||= $entry->{raw_data}->{vendor} && $self->vc_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} };
|
|
245 |
if ($vc && $self->vc_counts_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} } > 1) {
|
|
246 |
$vc = undef;
|
|
247 |
$is_ambiguous = 1;
|
|
248 |
}
|
|
249 |
|
216 |
250 |
$entry->{object}->$id_column($vc->id) if $vc;
|
217 |
251 |
}
|
218 |
252 |
|
219 |
253 |
if (!$entry->{object}->$id_column) {
|
220 |
|
my $vc = ($entry->{raw_data}->{customer_gln} && $self->vc_by->{gln}->{customers}->{ $entry->{raw_data}->{customer_gln} })
|
221 |
|
|| ($entry->{raw_data}->{vendor_gln} && $self->vc_by->{gln}->{vendors}->{ $entry->{raw_data}->{vendor_gln} } );
|
|
254 |
my $vc = $entry->{raw_data}->{customer_gln} && $self->vc_by->{gln}->{customers}->{ $entry->{raw_data}->{customer_gln} };
|
|
255 |
if ($vc && $self->vc_counts_by->{gln}->{customers}->{ $entry->{raw_data}->{customer_gln} } > 1) {
|
|
256 |
$vc = undef;
|
|
257 |
$is_ambiguous = 1;
|
|
258 |
}
|
|
259 |
$vc ||= $entry->{raw_data}->{vendor_gln} && $self->vc_by->{gln}->{vendors}->{ $entry->{raw_data}->{vendor_gln} };
|
|
260 |
if ($vc && $self->vc_counts_by->{gln}->{vendors}->{ $entry->{raw_data}->{vendor_gln} } > 1) {
|
|
261 |
$vc = undef;
|
|
262 |
$is_ambiguous = 1;
|
|
263 |
}
|
|
264 |
|
222 |
265 |
$entry->{object}->$id_column($vc->id) if $vc;
|
223 |
266 |
}
|
224 |
267 |
|
225 |
268 |
if ($entry->{object}->$id_column) {
|
226 |
269 |
$entry->{info_data}->{vc_name} = $self->vc_by->{id}->{ $entry->{object}->$id_column }->name;
|
227 |
270 |
} else {
|
228 |
|
push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor not found');
|
|
271 |
if ($is_ambiguous) {
|
|
272 |
push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor is ambiguous');
|
|
273 |
} else {
|
|
274 |
push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor not found');
|
|
275 |
}
|
229 |
276 |
}
|
230 |
277 |
}
|
231 |
278 |
|
CsvImport: bei nicht eindeutigen Kunden/Lieferanten Fehler melden.