Revision d3b70d7c
Von Bernd Bleßmann vor fast 11 Jahren hinzugefügt
SL/Controller/CsvImport/Order.pm | ||
---|---|---|
50 | 50 |
# overwrite it with the user specified settings |
51 | 51 |
foreach my $p (@{ $profile }) { |
52 | 52 |
if ($p->{row_ident} eq $::locale->text('Order')) { |
53 |
$p->{row_ident} = $self->settings->{'order_column'};
|
|
53 |
$p->{row_ident} = $self->_order_column;
|
|
54 | 54 |
} |
55 | 55 |
if ($p->{row_ident} eq $::locale->text('OrderItem')) { |
56 |
$p->{row_ident} = $self->settings->{'item_column'};
|
|
56 |
$p->{row_ident} = $self->_item_column;
|
|
57 | 57 |
} |
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
foreach my $p (@{ $profile }) { |
61 | 61 |
my $prof = $p->{profile}; |
62 |
if ($p->{row_ident} eq $self->settings->{'order_column'}) {
|
|
62 |
if ($p->{row_ident} eq $self->_order_column) {
|
|
63 | 63 |
# no need to handle |
64 | 64 |
delete @{$prof}{qw(delivery_customer_id delivery_vendor_id proforma quotation amount netamount)}; |
65 | 65 |
} |
66 |
if ($p->{row_ident} eq $self->settings->{'item_column'}) {
|
|
66 |
if ($p->{row_ident} eq $self->_item_column) {
|
|
67 | 67 |
# no need to handle |
68 | 68 |
delete @{$prof}{qw(trans_id)}; |
69 | 69 |
} |
... | ... | |
78 | 78 |
|
79 | 79 |
$self->SUPER::setup_displayable_columns; |
80 | 80 |
|
81 |
$self->add_displayable_columns($self->settings->{'order_column'},
|
|
82 |
{ name => 'datatype', description => $self->settings->{'order_column'} },
|
|
81 |
$self->add_displayable_columns($self->_order_column,
|
|
82 |
{ name => 'datatype', description => $self->_order_column },
|
|
83 | 83 |
{ name => 'closed', description => $::locale->text('Closed') }, |
84 | 84 |
{ name => 'currency', description => $::locale->text('Currency') }, |
85 | 85 |
{ name => 'currency_id', description => $::locale->text('Currency (database ID)') }, |
... | ... | |
123 | 123 |
{ name => 'shipto_id', description => $::locale->text('Ship to (database ID)') }, |
124 | 124 |
); |
125 | 125 |
|
126 |
$self->add_displayable_columns($self->settings->{'item_column'},
|
|
127 |
{ name => 'datatype', description => $self->settings->{'item_column'} },
|
|
126 |
$self->add_displayable_columns($self->_item_column,
|
|
127 |
{ name => 'datatype', description => $self->_item_column },
|
|
128 | 128 |
{ name => 'cusordnumber', description => $::locale->text('Customer Order Number') }, |
129 | 129 |
{ name => 'description', description => $::locale->text('Description') }, |
130 | 130 |
{ name => 'discount', description => $::locale->text('Discount') }, |
... | ... | |
242 | 242 |
foreach my $entry (@{ $self->controller->data }) { |
243 | 243 |
$self->controller->track_progress(progress => $i/$num_data * 100) if $i % 100 == 0; |
244 | 244 |
|
245 |
if ($entry->{raw_data}->{datatype} eq $self->settings->{'order_column'}) {
|
|
245 |
if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
|
|
246 | 246 |
|
247 | 247 |
my $vc_obj; |
248 | 248 |
if (any { $entry->{raw_data}->{$_} } qw(customer customernumber customer_id)) { |
... | ... | |
289 | 289 |
} |
290 | 290 |
} |
291 | 291 |
|
292 |
$self->add_info_columns($self->settings->{'order_column'},
|
|
292 |
$self->add_info_columns($self->_order_column,
|
|
293 | 293 |
{ header => $::locale->text('Customer/Vendor'), method => 'vc_name' }); |
294 | 294 |
# Todo: access via ->[0] ok? Better: search first order column and use this |
295 |
$self->add_columns($self->settings->{'order_column'},
|
|
295 |
$self->add_columns($self->_order_column,
|
|
296 | 296 |
map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject taxzone cp currency)); |
297 |
$self->add_columns($self->settings->{'order_column'}, 'globalproject_id') if exists $self->controller->data->[0]->{raw_data}->{globalprojectnumber};
|
|
298 |
$self->add_columns($self->settings->{'order_column'}, 'cp_id') if exists $self->controller->data->[0]->{raw_data}->{contact};
|
|
297 |
$self->add_columns($self->_order_column, 'globalproject_id') if exists $self->controller->data->[0]->{raw_data}->{globalprojectnumber};
|
|
298 |
$self->add_columns($self->_order_column, 'cp_id') if exists $self->controller->data->[0]->{raw_data}->{contact};
|
|
299 | 299 |
|
300 | 300 |
foreach my $entry (@{ $self->controller->data }) { |
301 |
if ($entry->{raw_data}->{datatype} eq $self->settings->{'item_column'} && $entry->{object}->can('part')) {
|
|
301 |
if ($entry->{raw_data}->{datatype} eq $self->_item_column && $entry->{object}->can('part')) {
|
|
302 | 302 |
|
303 | 303 |
next if !$self->check_part($entry); |
304 | 304 |
|
... | ... | |
319 | 319 |
} |
320 | 320 |
} |
321 | 321 |
|
322 |
$self->add_info_columns($self->settings->{'item_column'},
|
|
322 |
$self->add_info_columns($self->_item_column,
|
|
323 | 323 |
{ header => $::locale->text('Part Number'), method => 'partnumber' }); |
324 | 324 |
# Todo: access via ->[1] ok? Better: search first item column and use this |
325 |
$self->add_columns($self->settings->{'item_column'},
|
|
325 |
$self->add_columns($self->_item_column,
|
|
326 | 326 |
map { "${_}_id" } grep { exists $self->controller->data->[1]->{raw_data}->{$_} } qw(project price_factor pricegroup)); |
327 |
$self->add_columns($self->settings->{'item_column'}, 'project_id') if exists $self->controller->data->[1]->{raw_data}->{projectnumber};
|
|
327 |
$self->add_columns($self->_item_column, 'project_id') if exists $self->controller->data->[1]->{raw_data}->{projectnumber};
|
|
328 | 328 |
|
329 | 329 |
# add orderitems to order |
330 | 330 |
my $order_entry; |
331 | 331 |
my @orderitems; |
332 | 332 |
foreach my $entry (@{ $self->controller->data }) { |
333 | 333 |
# search first Order |
334 |
if ($entry->{raw_data}->{datatype} eq $self->settings->{'order_column'}) {
|
|
334 |
if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
|
|
335 | 335 |
|
336 | 336 |
# new order entry: add collected orderitems to the last one |
337 | 337 |
if (defined $order_entry) { |
... | ... | |
341 | 341 |
|
342 | 342 |
$order_entry = $entry; |
343 | 343 |
|
344 |
} elsif ( defined $order_entry && $entry->{raw_data}->{datatype} eq $self->settings->{'item_column'} ) {
|
|
344 |
} elsif ( defined $order_entry && $entry->{raw_data}->{datatype} eq $self->_item_column ) {
|
|
345 | 345 |
# collect orderitems to add to order (if they have no errors) |
346 | 346 |
# ( add_orderitems does not work here if we want to call |
347 | 347 |
# calculate_prices_and_taxes afterwards ... |
... | ... | |
360 | 360 |
foreach my $entry (@{ $self->controller->data }) { |
361 | 361 |
next if @{ $entry->{errors} }; |
362 | 362 |
|
363 |
if ($entry->{raw_data}->{datatype} eq $self->settings->{'order_column'}) {
|
|
363 |
if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
|
|
364 | 364 |
|
365 | 365 |
$entry->{object}->calculate_prices_and_taxes; |
366 | 366 |
|
... | ... | |
387 | 387 |
foreach my $tv (@to_verify) { |
388 | 388 |
# Todo: access via ->[0] ok? Better: search first order column and use this |
389 | 389 |
if (exists $self->controller->data->[0]->{raw_data}->{ $tv->{raw_column} }) { |
390 |
$self->add_raw_data_columns($self->settings->{'order_column'}, $tv->{raw_column});
|
|
391 |
$self->add_info_columns($self->settings->{'order_column'},
|
|
390 |
$self->add_raw_data_columns($self->_order_column, $tv->{raw_column});
|
|
391 |
$self->add_info_columns($self->_order_column,
|
|
392 | 392 |
{ header => $::locale->text($tv->{info_header}), method => $tv->{info_method} }); |
393 | 393 |
} |
394 | 394 |
|
395 | 395 |
# check differences |
396 | 396 |
foreach my $entry (@{ $self->controller->data }) { |
397 | 397 |
next if @{ $entry->{errors} }; |
398 |
if ($entry->{raw_data}->{datatype} eq $self->settings->{'order_column'}) {
|
|
398 |
if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
|
|
399 | 399 |
next if !$entry->{raw_data}->{ $tv->{raw_column} }; |
400 | 400 |
my $parsed_value = $::form->parse_amount(\%::myconfig, $entry->{raw_data}->{ $tv->{raw_column} }); |
401 | 401 |
if (abs($entry->{object}->${ \$tv->{column} } - $parsed_value) > $self->settings->{'max_amount_diff'}) { |
... | ... | |
409 | 409 |
$order_entry = undef; |
410 | 410 |
foreach my $entry (@{ $self->controller->data }) { |
411 | 411 |
# Search first order |
412 |
if ($entry->{raw_data}->{datatype} eq $self->settings->{'order_column'}) {
|
|
412 |
if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
|
|
413 | 413 |
$order_entry = $entry; |
414 | 414 |
} elsif ( defined $order_entry |
415 |
&& $entry->{raw_data}->{datatype} eq $self->settings->{'item_column'}
|
|
415 |
&& $entry->{raw_data}->{datatype} eq $self->_item_column
|
|
416 | 416 |
&& scalar @{ $order_entry->{errors} } > 0 ) { |
417 | 417 |
push @{ $entry->{errors} }, $::locale->text('order not valid for this orderitem!'); |
418 | 418 |
} |
... | ... | |
707 | 707 |
foreach my $entry (@{ $self->controller->data }) { |
708 | 708 |
next if @{ $entry->{errors} }; |
709 | 709 |
|
710 |
if ($entry->{raw_data}->{datatype} eq $self->settings->{'order_column'} && !$entry->{object}->ordnumber) {
|
|
710 |
if ($entry->{raw_data}->{datatype} eq $self->_order_column && !$entry->{object}->ordnumber) {
|
|
711 | 711 |
my $number = SL::TransNumber->new(type => 'sales_order', |
712 | 712 |
save => 1); |
713 | 713 |
$entry->{object}->ordnumber($number->create_unique()); |
... | ... | |
719 | 719 |
$self->SUPER::save_objects(data => $objects_to_save); |
720 | 720 |
} |
721 | 721 |
|
722 |
sub _order_column { |
|
723 |
$_[0]->settings->{'order_column'} |
|
724 |
} |
|
725 |
|
|
726 |
sub _item_column { |
|
727 |
$_[0]->settings->{'item_column'} |
|
728 |
} |
|
722 | 729 |
|
723 | 730 |
1; |
Auch abrufbar als: Unified diff
mit kleinen Methoden statt mit Strings auf häufige Hash-Einträge zugreifen.