1 package SL::Controller::CsvImport::Helper::Consistency;
8 use SL::Helper::Csv::Error;
10 use parent qw(Exporter);
11 our @EXPORT = qw(check_currency);
18 my ($self, $entry, %params) = @_;
20 my $object = $entry->{object};
22 # Check whether or not currency ID is valid.
23 if ($object->currency_id && ! _currencies_by($self)->{id}->{ $object->currency_id }) {
24 push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency');
28 # Map name to ID if given.
29 if (!$object->currency_id && $entry->{raw_data}->{currency}) {
30 my $currency = _currencies_by($self)->{name}->{ $entry->{raw_data}->{currency} };
32 push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency');
36 $object->currency_id($currency->id);
38 # register currency_id for method copying later
39 $self->clone_methods->{currency_id} = 1;
42 # Set default currency if none was given and take_default is true.
43 $object->currency_id(_default_currency_id($self)) if !$object->currency_id and $params{take_default};
45 $entry->{raw_data}->{currency_id} = $object->currency_id;
57 return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ _all_currencies($self) } } ) } qw(id name) };
63 return SL::DB::Manager::Currency->get_all;
66 sub _default_currency_id {
69 return SL::DB::Default->get->currency_id;