2017-11-13 13:30:33 +00:00
|
|
|
package Pear::LocalLoop::Schema::ResultSet::ImportSet;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use base 'DBIx::Class::ResultSet';
|
|
|
|
|
|
|
|
sub get_values {
|
|
|
|
my $self = shift;
|
|
|
|
my $id = shift;
|
2017-11-14 18:41:54 +00:00
|
|
|
my $include_ignored = shift;
|
2017-11-15 18:22:49 +00:00
|
|
|
my $include_imported = shift;
|
2017-11-13 13:30:33 +00:00
|
|
|
|
|
|
|
return $self->find($id)->search_related(
|
|
|
|
'values',
|
2017-11-15 18:22:49 +00:00
|
|
|
{
|
|
|
|
( $include_ignored ? () : ( ignore_value => 0 ) ),
|
|
|
|
( $include_imported ? () : ( transaction_id => undef ) ),
|
|
|
|
},
|
2017-11-13 13:30:33 +00:00
|
|
|
{
|
2017-11-13 19:00:34 +00:00
|
|
|
order_by => { '-asc' => 'id' },
|
2017-11-13 13:30:33 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-23 16:52:33 +00:00
|
|
|
sub _unordered_get_values {
|
|
|
|
my $self = shift;
|
|
|
|
my $id = shift;
|
|
|
|
my $include_ignored = shift;
|
|
|
|
my $include_imported = shift;
|
|
|
|
|
|
|
|
return $self->find($id)->search_related(
|
|
|
|
'values',
|
|
|
|
{
|
|
|
|
( $include_ignored ? () : ( ignore_value => 0 ) ),
|
|
|
|
( $include_imported ? () : ( transaction_id => undef ) ),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-13 13:30:33 +00:00
|
|
|
sub get_users {
|
|
|
|
my $self = shift;
|
|
|
|
|
2017-11-23 16:52:33 +00:00
|
|
|
return $self->_unordered_get_values(@_)->search({},
|
2017-11-13 13:30:33 +00:00
|
|
|
{
|
|
|
|
group_by => 'user_name',
|
2017-11-23 16:52:33 +00:00
|
|
|
columns => [ qw/ user_name / ],
|
2017-11-13 13:30:33 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_orgs {
|
|
|
|
my $self = shift;
|
|
|
|
|
2017-11-23 16:52:33 +00:00
|
|
|
return $self->_unordered_get_values(@_)->search({},
|
2017-11-13 13:30:33 +00:00
|
|
|
{
|
|
|
|
group_by => 'org_name',
|
2017-11-23 16:52:33 +00:00
|
|
|
columns => [ qw/ org_name / ],
|
2017-11-13 13:30:33 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-13 19:00:34 +00:00
|
|
|
sub get_lookups {
|
|
|
|
my $self = shift;
|
|
|
|
my $id = shift;
|
|
|
|
|
2017-11-15 18:22:49 +00:00
|
|
|
my $lookup_rs = $self->find($id)->search_related(
|
2017-11-13 19:00:34 +00:00
|
|
|
'lookups',
|
|
|
|
undef,
|
|
|
|
{
|
2017-11-15 18:22:49 +00:00
|
|
|
prefetch => { entity => [ qw/ organisation customer / ] },
|
|
|
|
order_by => { '-asc' => 'me.id' },
|
2017-11-13 19:00:34 +00:00
|
|
|
},
|
|
|
|
);
|
2017-11-15 18:22:49 +00:00
|
|
|
my $lookup_map = {
|
|
|
|
map {
|
|
|
|
$_->name => {
|
|
|
|
entity_id => $_->entity->id,
|
|
|
|
name => $_->entity->name,
|
|
|
|
},
|
|
|
|
} $lookup_rs->all
|
|
|
|
};
|
|
|
|
return $lookup_map;
|
2017-11-13 19:00:34 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 13:30:33 +00:00
|
|
|
1;
|