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);
39 # Set default currency if none was given and take_default is true.
40 $object->currency_id(_default_currency_id($self)) if !$object->currency_id and $params{take_default};
42 $entry->{raw_data}->{currency_id} = $object->currency_id;
54 return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ _all_currencies($self) } } ) } qw(id name) };
60 return SL::DB::Manager::Currency->get_all;
63 sub _default_currency_id {
66 return SL::DB::Default->get->currency_id;