1 package SL::Controller::CsvImport::Order;
6 use List::MoreUtils qw(any none);
9 use SL::Controller::CsvImport::Helper::Consistency;
11 use SL::DB::OrderItem;
13 use SL::DB::PaymentTerm;
15 use SL::DB::Department;
16 use SL::DB::PriceFactor;
17 use SL::DB::Pricegroup;
24 use parent qw(SL::Controller::CsvImport::BaseMulti);
27 use Rose::Object::MakeMethods::Generic
29 'scalar --get_set_init' => [ qw(settings languages_by all_parts parts_by part_counts_by contacts_by ct_shiptos_by price_factors_by pricegroups_by units_by) ],
35 $self->class(['SL::DB::Order', 'SL::DB::OrderItem']);
38 sub set_profile_defaults {
41 $self->controller->profile->_set_defaults(
42 order_column => $::locale->text('Order'),
43 item_column => $::locale->text('OrderItem'),
44 max_amount_diff => 0.02,
52 return { map { ( $_ => $self->controller->profile->get($_) ) } qw(order_column item_column max_amount_diff) };
56 sub init_cvar_configs_by {
59 my $item_cvar_configs = SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'IC' ]);
60 $item_cvar_configs = [grep { $_->has_flag('editable') } @{ $item_cvar_configs }];
63 $ccb->{class}->{'SL::DB::Order'} = [];
64 $ccb->{class}->{'SL::DB::OrderItem'} = $item_cvar_configs;
65 $ccb->{row_ident}->{$self->_order_column} = [];
66 $ccb->{row_ident}->{$self->_item_column} = $item_cvar_configs;
75 my $profile = $self->SUPER::init_profile;
77 # SUPER::init_profile sets row_ident to the translated class name
78 # overwrite it with the user specified settings
79 foreach my $p (@{ $profile }) {
80 if ($p->{class} eq 'SL::DB::Order') {
81 $p->{row_ident} = $self->_order_column;
83 if ($p->{class} eq 'SL::DB::OrderItem') {
84 $p->{row_ident} = $self->_item_column;
88 foreach my $p (@{ $profile }) {
89 my $prof = $p->{profile};
90 if ($p->{row_ident} eq $self->_order_column) {
92 delete @{$prof}{qw(delivery_customer_id delivery_vendor_id proforma quotation amount netamount)};
94 if ($p->{row_ident} eq $self->_item_column) {
96 delete @{$prof}{qw(trans_id)};
104 sub setup_displayable_columns {
107 $self->SUPER::setup_displayable_columns;
109 $self->add_displayable_columns($self->_order_column,
110 { name => 'datatype', description => $self->_order_column . ' [1]' },
111 { name => 'closed', description => $::locale->text('Closed') },
112 { name => 'currency', description => $::locale->text('Currency') },
113 { name => 'currency_id', description => $::locale->text('Currency (database ID)') },
114 { name => 'cusordnumber', description => $::locale->text('Customer Order Number') },
115 { name => 'delivered', description => $::locale->text('Delivered') },
116 { name => 'delivery_term_id', description => $::locale->text('Delivery terms (database ID)') },
117 { name => 'delivery_term', description => $::locale->text('Delivery terms (name)') },
118 { name => 'employee_id', description => $::locale->text('Employee (database ID)') },
119 { name => 'intnotes', description => $::locale->text('Internal Notes') },
120 { name => 'marge_percent', description => $::locale->text('Margepercent') },
121 { name => 'marge_total', description => $::locale->text('Margetotal') },
122 { name => 'notes', description => $::locale->text('Notes') },
123 { name => 'ordnumber', description => $::locale->text('Order Number') },
124 { name => 'quonumber', description => $::locale->text('Quotation Number') },
125 { name => 'reqdate', description => $::locale->text('Reqdate') },
126 { name => 'salesman_id', description => $::locale->text('Salesman (database ID)') },
127 { name => 'shippingpoint', description => $::locale->text('Shipping Point') },
128 { name => 'shipvia', description => $::locale->text('Ship via') },
129 { name => 'transaction_description', description => $::locale->text('Transaction description') },
130 { name => 'transdate', description => $::locale->text('Order Date') },
131 { name => 'verify_amount', description => $::locale->text('Amount (for verification)') . ' [2]' },
132 { name => 'verify_netamount', description => $::locale->text('Net amount (for verification)') . ' [2]'},
133 { name => 'taxincluded', description => $::locale->text('Tax Included') },
134 { name => 'customer', description => $::locale->text('Customer (name)') },
135 { name => 'customernumber', description => $::locale->text('Customer Number') },
136 { name => 'customer_gln', description => $::locale->text('Customer GLN') },
137 { name => 'customer_id', description => $::locale->text('Customer (database ID)') },
138 { name => 'vendor', description => $::locale->text('Vendor (name)') },
139 { name => 'vendornumber', description => $::locale->text('Vendor Number') },
140 { name => 'vendor_gln', description => $::locale->text('Vendor GLN') },
141 { name => 'vendor_id', description => $::locale->text('Vendor (database ID)') },
142 { name => 'language_id', description => $::locale->text('Language (database ID)') },
143 { name => 'language', description => $::locale->text('Language (name)') },
144 { name => 'payment_id', description => $::locale->text('Payment terms (database ID)') },
145 { name => 'payment', description => $::locale->text('Payment terms (name)') },
146 { name => 'taxzone_id', description => $::locale->text('Tax zone (database ID)') },
147 { name => 'taxzone', description => $::locale->text('Tax zone (description)') },
148 { name => 'cp_id', description => $::locale->text('Contact Person (database ID)') },
149 { name => 'contact', description => $::locale->text('Contact Person (name)') },
150 { name => 'department_id', description => $::locale->text('Department (database ID)') },
151 { name => 'department', description => $::locale->text('Department (description)') },
152 { name => 'globalproject_id', description => $::locale->text('Document Project (database ID)') },
153 { name => 'globalprojectnumber', description => $::locale->text('Document Project (number)') },
154 { name => 'globalproject', description => $::locale->text('Document Project (description)') },
155 { name => 'shipto_id', description => $::locale->text('Ship to (database ID)') },
158 $self->add_cvar_columns_to_displayable_columns($self->_item_column);
160 $self->add_displayable_columns($self->_item_column,
161 { name => 'datatype', description => $self->_item_column . ' [1]' },
162 { name => 'cusordnumber', description => $::locale->text('Customer Order Number') },
163 { name => 'description', description => $::locale->text('Description') },
164 { name => 'discount', description => $::locale->text('Discount') },
165 { name => 'ean', description => $::locale->text('EAN') },
166 { name => 'lastcost', description => $::locale->text('Lastcost') },
167 { name => 'longdescription', description => $::locale->text('Long Description') },
168 { name => 'marge_percent', description => $::locale->text('Margepercent') },
169 { name => 'marge_total', description => $::locale->text('Margetotal') },
170 { name => 'ordnumber', description => $::locale->text('Order Number') },
171 { name => 'parts_id', description => $::locale->text('Part (database ID)') },
172 { name => 'partnumber', description => $::locale->text('Part Number') },
173 { name => 'position', description => $::locale->text('position') },
174 { name => 'project_id', description => $::locale->text('Project (database ID)') },
175 { name => 'projectnumber', description => $::locale->text('Project (number)') },
176 { name => 'project', description => $::locale->text('Project (description)') },
177 { name => 'price_factor_id', description => $::locale->text('Price factor (database ID)') },
178 { name => 'price_factor', description => $::locale->text('Price factor (name)') },
179 { name => 'pricegroup_id', description => $::locale->text('Price group (database ID)') },
180 { name => 'pricegroup', description => $::locale->text('Price group (name)') },
181 { name => 'qty', description => $::locale->text('Quantity') },
182 { name => 'reqdate', description => $::locale->text('Reqdate') },
183 { name => 'sellprice', description => $::locale->text('Sellprice') },
184 { name => 'serialnumber', description => $::locale->text('Serial No.') },
185 { name => 'subtotal', description => $::locale->text('Subtotal') },
186 { name => 'unit', description => $::locale->text('Unit') },
191 sub init_languages_by {
194 return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_languages } } ) } qw(id description article_code) };
200 return SL::DB::Manager::Part->get_all;
206 return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_parts } } ) } qw(id partnumber ean description) };
209 sub init_part_counts_by {
214 $part_counts_by->{ean}-> {$_->ean}++ for @{ $self->all_parts };
215 $part_counts_by->{description}->{$_->description}++ for @{ $self->all_parts };
217 return $part_counts_by;
220 sub init_contacts_by {
223 my $all_contacts = SL::DB::Manager::Contact->get_all;
226 # by customer/vendor id _and_ contact person id
227 $cby->{'cp_cv_id+cp_id'} = { map { ( $_->cp_cv_id . '+' . $_->cp_id => $_ ) } @{ $all_contacts } };
228 # by customer/vendor id _and_ contact person name
229 $cby->{'cp_cv_id+cp_name'} = { map { ( $_->cp_cv_id . '+' . $_->cp_name => $_ ) } @{ $all_contacts } };
234 sub init_ct_shiptos_by {
237 my $all_ct_shiptos = SL::DB::Manager::Shipto->get_all(query => [module => 'CT']);
240 # by trans_id _and_ shipto_id
241 $sby->{'trans_id+shipto_id'} = { map { ( $_->trans_id . '+' . $_->shipto_id => $_ ) } @{ $all_ct_shiptos } };
246 sub init_price_factors_by {
249 my $all_price_factors = SL::DB::Manager::PriceFactor->get_all;
250 return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_price_factors } } ) } qw(id description) };
253 sub init_pricegroups_by {
256 my $all_pricegroups = SL::DB::Manager::Pricegroup->get_all;
257 return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_pricegroups } } ) } qw(id pricegroup) };
263 my $all_units = SL::DB::Manager::Unit->get_all;
264 return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_units } } ) } qw(name) };
270 $self->controller->track_progress(phase => 'building data', progress => 0);
273 my $num_data = scalar @{ $self->controller->data };
275 foreach my $entry (@{ $self->controller->data }) {
276 $self->controller->track_progress(progress => $i/$num_data * 100) if $i % 100 == 0;
278 $entry->{info_data}->{datatype} = $entry->{raw_data}->{datatype};
280 if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
281 $self->handle_order($entry);
282 $order_entry = $entry;
283 } elsif ($entry->{raw_data}->{datatype} eq $self->_item_column && $entry->{object}->can('part')) {
284 $self->handle_item($entry, $order_entry);
286 $order_entry = undef;
289 $self->handle_cvars($entry, sub_module => 'orderitems');
295 $self->add_info_columns($self->_order_column,
296 { header => $::locale->text('Data type'), method => 'datatype' });
297 $self->add_info_columns($self->_item_column,
298 { header => $::locale->text('Data type'), method => 'datatype' });
300 $self->add_info_columns($self->_order_column,
301 { header => $::locale->text('Customer/Vendor'), method => 'vc_name' });
302 # Todo: access via ->[0] ok? Better: search first order column and use this
303 $self->add_columns($self->_order_column,
304 map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment delivery_term language department globalproject taxzone cp currency));
305 $self->add_columns($self->_order_column, 'globalproject_id') if exists $self->controller->data->[0]->{raw_data}->{globalprojectnumber};
306 $self->add_columns($self->_order_column, 'cp_id') if exists $self->controller->data->[0]->{raw_data}->{contact};
308 $self->add_info_columns($self->_item_column,
309 { header => $::locale->text('Part Number'), method => 'partnumber' });
310 # Todo: access via ->[1] ok? Better: search first item column and use this
311 $self->add_columns($self->_item_column,
312 map { "${_}_id" } grep { exists $self->controller->data->[1]->{raw_data}->{$_} } qw(project price_factor pricegroup));
313 $self->add_columns($self->_item_column, 'project_id') if exists $self->controller->data->[1]->{raw_data}->{projectnumber};
315 $self->add_cvar_raw_data_columns();
317 $self->add_items_to_order();
318 $self->handle_prices_and_taxes();
322 my ($self, $entry) = @_;
324 my $object = $entry->{object};
327 if (any { $entry->{raw_data}->{$_} } qw(customer customernumber customer_gln customer_id)) {
328 $self->check_vc($entry, 'customer_id');
329 $vc_obj = SL::DB::Customer->new(id => $object->customer_id)->load if $object->customer_id;
330 } elsif (any { $entry->{raw_data}->{$_} } qw(vendor vendornumber vendor_gln vendor_id)) {
331 $self->check_vc($entry, 'vendor_id');
332 $vc_obj = SL::DB::Vendor->new(id => $object->vendor_id)->load if $object->vendor_id;
334 push @{ $entry->{errors} }, $::locale->text('Error: Customer/vendor missing');
337 $self->check_contact($entry);
338 $self->check_language($entry);
339 $self->check_payment($entry);
340 $self->check_delivery_term($entry);
341 $self->check_department($entry);
342 $self->check_project($entry, global => 1);
343 $self->check_ct_shipto($entry);
344 $self->check_taxzone($entry);
345 $self->check_currency($entry, take_default => 0);
348 # copy from customer if not given
349 foreach (qw(payment_id delivery_term_id language_id taxzone_id currency_id)) {
350 $object->$_($vc_obj->$_) unless $object->$_;
352 $object->intnotes($vc_obj->notes) unless $object->intnotes;
355 $self->handle_salesman($entry);
356 $self->handle_employee($entry);
360 my ($self, $entry) = @_;
362 my $object = $entry->{object};
364 # Check whether or not language ID is valid.
365 if ($object->language_id && !$self->languages_by->{id}->{ $object->language_id }) {
366 push @{ $entry->{errors} }, $::locale->text('Error: Invalid language');
370 # Map name to ID if given.
371 if (!$object->language_id && $entry->{raw_data}->{language}) {
372 my $language = $self->languages_by->{description}->{ $entry->{raw_data}->{language} }
373 || $self->languages_by->{article_code}->{ $entry->{raw_data}->{language} };
376 push @{ $entry->{errors} }, $::locale->text('Error: Invalid language');
380 $object->language_id($language->id);
383 if ($object->language_id) {
384 $entry->{info_data}->{language} = $self->languages_by->{id}->{ $object->language_id }->description;
391 my ($self, $entry, $order_entry) = @_;
393 return unless $order_entry;
395 my $object = $entry->{object};
397 return unless $self->check_part($entry);
399 my $part_obj = SL::DB::Part->new(id => $object->parts_id)->load;
401 $self->handle_unit($entry);
403 # copy from part if not given
404 $object->description($part_obj->description) unless $object->description;
405 $object->longdescription($part_obj->notes) unless $object->longdescription;
406 $object->lastcost($part_obj->lastcost) unless defined $object->lastcost;
408 # set to 0 if not given
409 $object->ship(0) unless $object->ship;
411 $self->check_project($entry, global => 0);
412 $self->check_price_factor($entry);
413 $self->check_pricegroup($entry);
415 $self->handle_sellprice($entry, $order_entry);
416 $self->handle_discount($entry, $order_entry);
420 my ($self, $entry) = @_;
422 my $object = $entry->{object};
424 # Set unit from part if not given.
425 if (!$object->unit) {
426 $object->unit($object->part->unit);
430 # Check whether or not unit is valid.
431 if ($object->unit && !$self->units_by->{name}->{ $object->unit }) {
432 push @{ $entry->{errors} }, $::locale->text('Error: Invalid unit');
436 # Check whether unit is convertible to parts unit
437 if (none { $object->unit eq $_ } map { $_->name } @{ $object->part->unit_obj->convertible_units }) {
438 push @{ $entry->{errors} }, $::locale->text('Error: Invalid unit');
445 sub handle_sellprice {
446 my ($self, $entry, $record_entry) = @_;
448 my $item = $entry->{object};
449 my $record = $record_entry->{object};
451 return if !$record->customervendor;
453 # If sellprice is given, set price source to pricegroup if given or to none.
454 if (exists $entry->{raw_data}->{sellprice}) {
455 my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
456 my $price_source_spec = $item->pricegroup_id ? 'pricegroup' . '/' . $item->pricegroup_id : '';
457 my $price = $price_source->price_from_source($price_source_spec);
458 $item->active_price_source($price->source);
461 # Set sellprice the best price of price source
462 my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
463 my $price = $price_source->best_price;
465 $item->sellprice($price->price);
466 $item->active_price_source($price->source);
469 $item->active_price_source($price_source->price_from_source('')->source);
474 sub handle_discount {
475 my ($self, $entry, $record_entry) = @_;
477 my $item = $entry->{object};
478 my $record = $record_entry->{object};
480 return if !$record->customervendor;
482 # If discount is given, set discount source to none.
483 if (exists $entry->{raw_data}->{discount}) {
484 $item->discount($item->discount/100.0) if $item->discount;
485 $item->discount(0) unless $item->discount;
487 my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
488 my $discount = $price_source->price_from_source('');
489 $item->active_discount_source($discount->source);
492 # Set discount the best discount of price source
493 my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
494 my $discount = $price_source->best_discount;
496 $item->discount($discount->discount);
497 $item->active_discount_source($discount->source);
500 $item->active_discount_source($price_source->discount_from_source('')->source);
506 my ($self, $entry) = @_;
508 my $object = $entry->{object};
511 # Check whether or not part ID is valid.
512 if ($object->parts_id && !$self->parts_by->{id}->{ $object->parts_id }) {
513 push @{ $entry->{errors} }, $::locale->text('Error: Invalid part');
517 # Map number to ID if given.
518 if (!$object->parts_id && $entry->{raw_data}->{partnumber}) {
519 my $part = $self->parts_by->{partnumber}->{ $entry->{raw_data}->{partnumber} };
521 push @{ $entry->{errors} }, $::locale->text('Error: Invalid part');
525 $object->parts_id($part->id);
528 # Map description to ID if given.
529 if (!$object->parts_id && $entry->{raw_data}->{description}) {
530 my $part = $self->parts_by->{description}->{ $entry->{raw_data}->{description} };
532 push @{ $entry->{errors} }, $::locale->text('Error: Invalid part');
536 if ($self->part_counts_by->{description}->{ $entry->{raw_data}->{description} } > 1) {
539 $object->parts_id($part->id);
543 # Map ean to ID if given.
544 if (!$object->parts_id && $entry->{raw_data}->{ean}) {
545 my $part = $self->parts_by->{ean}->{ $entry->{raw_data}->{ean} };
547 push @{ $entry->{errors} }, $::locale->text('Error: Invalid part');
551 if ($self->part_counts_by->{ean}->{ $entry->{raw_data}->{ean} } > 1) {
554 $object->parts_id($part->id);
558 if ($object->parts_id) {
559 $entry->{info_data}->{partnumber} = $self->parts_by->{id}->{ $object->parts_id }->partnumber;
562 push @{ $entry->{errors} }, $::locale->text('Error: Part is ambiguous');
564 push @{ $entry->{errors} }, $::locale->text('Error: Part not found');
569 if ($self->parts_by->{id}->{ $object->parts_id }->obsolete) {
570 push @{ $entry->{errors} }, $::locale->text('Error: Part is obsolete');
578 my ($self, $entry) = @_;
580 my $object = $entry->{object};
582 my $cp_cv_id = $object->customer_id || $object->vendor_id;
583 return 0 unless $cp_cv_id;
585 # Check whether or not contact ID is valid.
586 if ($object->cp_id && !$self->contacts_by->{'cp_cv_id+cp_id'}->{ $cp_cv_id . '+' . $object->cp_id }) {
587 push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact');
591 # Map name to ID if given.
592 if (!$object->cp_id && $entry->{raw_data}->{contact}) {
593 my $cp = $self->contacts_by->{'cp_cv_id+cp_name'}->{ $cp_cv_id . '+' . $entry->{raw_data}->{contact} };
595 push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact');
599 $object->cp_id($cp->cp_id);
602 if ($object->cp_id) {
603 $entry->{info_data}->{contact} = $self->contacts_by->{'cp_cv_id+cp_id'}->{ $cp_cv_id . '+' . $object->cp_id }->cp_name;
609 sub check_ct_shipto {
610 my ($self, $entry) = @_;
612 my $object = $entry->{object};
614 my $trans_id = $object->customer_id || $object->vendor_id;
615 return 0 unless $trans_id;
617 # Check whether or not shipto ID is valid.
618 if ($object->shipto_id && !$self->ct_shiptos_by->{'trans_id+shipto_id'}->{ $trans_id . '+' . $object->shipto_id }) {
619 push @{ $entry->{errors} }, $::locale->text('Error: Invalid shipto');
626 sub check_price_factor {
627 my ($self, $entry) = @_;
629 my $object = $entry->{object};
631 # Check whether or not price_factor ID is valid.
632 if ($object->price_factor_id && !$self->price_factors_by->{id}->{ $object->price_factor_id }) {
633 push @{ $entry->{errors} }, $::locale->text('Error: Invalid price factor');
637 # Map description to ID if given.
638 if (!$object->price_factor_id && $entry->{raw_data}->{price_factor}) {
639 my $price_factor = $self->price_factors_by->{description}->{ $entry->{raw_data}->{price_factor} };
640 if (!$price_factor) {
641 push @{ $entry->{errors} }, $::locale->text('Error: Invalid price factor');
645 $object->price_factor_id($price_factor->id);
651 sub check_pricegroup {
652 my ($self, $entry) = @_;
654 my $object = $entry->{object};
656 # Check whether or not pricegroup ID is valid.
657 if ($object->pricegroup_id && !$self->pricegroups_by->{id}->{ $object->pricegroup_id }) {
658 push @{ $entry->{errors} }, $::locale->text('Error: Invalid price group');
662 # Map pricegroup to ID if given.
663 if (!$object->pricegroup_id && $entry->{raw_data}->{pricegroup}) {
664 my $pricegroup = $self->pricegroups_by->{pricegroup}->{ $entry->{raw_data}->{pricegroup} };
666 push @{ $entry->{errors} }, $::locale->text('Error: Invalid price group');
670 $object->pricegroup_id($pricegroup->id);
676 sub add_items_to_order {
679 # add orderitems to order
682 foreach my $entry (@{ $self->controller->data }) {
683 # search first/next order
684 if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
686 # next order entry: add collected orderitems to the previous one
687 if (defined $order_entry) {
688 $order_entry->{object}->orderitems(@orderitems);
692 $order_entry = $entry;
694 } elsif ( defined $order_entry && $entry->{raw_data}->{datatype} eq $self->_item_column ) {
695 # collect orderitems to add to order (if they have no errors)
696 # ( add_orderitems does not work here if we want to call
697 # calculate_prices_and_taxes afterwards ...
698 # so collect orderitems and add them at once )
699 push @orderitems, $entry->{object} if (scalar @{ $entry->{errors} } == 0);
702 # add last collected orderitems to last order
703 $order_entry->{object}->orderitems(@orderitems) if $order_entry;
706 sub handle_prices_and_taxes() {
709 # calculate prices and taxes
710 foreach my $entry (@{ $self->controller->data }) {
711 next if @{ $entry->{errors} };
713 if ($entry->{raw_data}->{datatype} eq $self->_order_column && $entry->{object}->orderitems) {
715 $entry->{object}->calculate_prices_and_taxes;
717 $entry->{info_data}->{calc_amount} = $entry->{object}->amount_as_number;
718 $entry->{info_data}->{calc_netamount} = $entry->{object}->netamount_as_number;
722 # If amounts are given, show calculated amounts as info and given amounts (verify_xxx).
723 # And throw an error if the differences are too big.
724 my @to_verify = ( { column => 'amount',
725 raw_column => 'verify_amount',
726 info_header => 'Calc. Amount',
727 info_method => 'calc_amount',
728 err_msg => 'Amounts differ too much',
730 { column => 'netamount',
731 raw_column => 'verify_netamount',
732 info_header => 'Calc. Net amount',
733 info_method => 'calc_netamount',
734 err_msg => 'Net amounts differ too much',
737 foreach my $tv (@to_verify) {
738 # Todo: access via ->[0] ok? Better: search first order column and use this
739 if (exists $self->controller->data->[0]->{raw_data}->{ $tv->{raw_column} }) {
740 $self->add_raw_data_columns($self->_order_column, $tv->{raw_column});
741 $self->add_info_columns($self->_order_column,
742 { header => $::locale->text($tv->{info_header}), method => $tv->{info_method} });
746 foreach my $entry (@{ $self->controller->data }) {
747 next if @{ $entry->{errors} };
748 if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
749 next if !$entry->{raw_data}->{ $tv->{raw_column} };
750 my $parsed_value = $::form->parse_amount(\%::myconfig, $entry->{raw_data}->{ $tv->{raw_column} });
751 if (abs($entry->{object}->${ \$tv->{column} } - $parsed_value) > $self->settings->{'max_amount_diff'}) {
752 push @{ $entry->{errors} }, $::locale->text($tv->{err_msg});
761 my ($self, %params) = @_;
763 # Collect orders without errors to save.
764 my $entries_to_save = [];
765 foreach my $entry (@{ $self->controller->data }) {
766 next if $entry->{raw_data}->{datatype} ne $self->_order_column;
767 next if @{ $entry->{errors} };
769 push @{ $entries_to_save }, $entry;
772 $self->SUPER::save_objects(data => $entries_to_save);
776 $_[0]->settings->{'order_column'}
780 $_[0]->settings->{'item_column'}