Add code formatter, format all code
This commit is contained in:
parent
602a59f1c3
commit
47a55f6322
120 changed files with 8061 additions and 6967 deletions
|
@ -6,31 +6,27 @@ use warnings;
|
|||
use base 'DBIx::Class::ResultSet';
|
||||
|
||||
sub as_hash {
|
||||
my ( $self ) = @_;
|
||||
my ($self) = @_;
|
||||
|
||||
my %category_list = (
|
||||
(
|
||||
map {
|
||||
$_->id => $_->name,
|
||||
} $self->all
|
||||
),
|
||||
0 => 'Uncategorised',
|
||||
);
|
||||
return \%category_list;
|
||||
my %category_list = (
|
||||
(
|
||||
map { $_->id => $_->name, } $self->all
|
||||
),
|
||||
0 => 'Uncategorised',
|
||||
);
|
||||
return \%category_list;
|
||||
}
|
||||
|
||||
sub as_hash_name_icon {
|
||||
my ( $self ) = @_;
|
||||
my ($self) = @_;
|
||||
|
||||
my %category_list = (
|
||||
(
|
||||
map {
|
||||
$_->name => $_->line_icon,
|
||||
} $self->all
|
||||
),
|
||||
0 => 'Uncategorised',
|
||||
);
|
||||
return \%category_list;
|
||||
my %category_list = (
|
||||
(
|
||||
map { $_->name => $_->line_icon, } $self->all
|
||||
),
|
||||
0 => 'Uncategorised',
|
||||
);
|
||||
return \%category_list;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -5,15 +5,17 @@ use warnings;
|
|||
|
||||
use base 'DBIx::Class::ResultSet';
|
||||
|
||||
sub sales { shift->search_related('sales', @_) }
|
||||
sub sales { shift->search_related( 'sales', @_ ) }
|
||||
|
||||
sub create_org {
|
||||
my ( $self, $org ) = @_;
|
||||
my ( $self, $org ) = @_;
|
||||
|
||||
return $self->create({
|
||||
organisation => $org,
|
||||
type => 'organisation',
|
||||
});
|
||||
return $self->create(
|
||||
{
|
||||
organisation => $org,
|
||||
type => 'organisation',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -6,81 +6,83 @@ use warnings;
|
|||
use base 'DBIx::Class::ResultSet';
|
||||
|
||||
sub get_values {
|
||||
my $self = shift;
|
||||
my $id = shift;
|
||||
my $include_ignored = shift;
|
||||
my $include_imported = shift;
|
||||
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 ) ),
|
||||
},
|
||||
{
|
||||
order_by => { '-asc' => 'id' },
|
||||
},
|
||||
);
|
||||
return $self->find($id)->search_related(
|
||||
'values',
|
||||
{
|
||||
( $include_ignored ? () : ( ignore_value => 0 ) ),
|
||||
( $include_imported ? () : ( transaction_id => undef ) ),
|
||||
},
|
||||
{
|
||||
order_by => { '-asc' => 'id' },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
sub _unordered_get_values {
|
||||
my $self = shift;
|
||||
my $id = shift;
|
||||
my $include_ignored = shift;
|
||||
my $include_imported = shift;
|
||||
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 ) ),
|
||||
},
|
||||
);
|
||||
return $self->find($id)->search_related(
|
||||
'values',
|
||||
{
|
||||
( $include_ignored ? () : ( ignore_value => 0 ) ),
|
||||
( $include_imported ? () : ( transaction_id => undef ) ),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
sub get_users {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
|
||||
return $self->_unordered_get_values(@_)->search({},
|
||||
{
|
||||
group_by => 'user_name',
|
||||
columns => [ qw/ user_name / ],
|
||||
},
|
||||
);
|
||||
return $self->_unordered_get_values(@_)->search(
|
||||
{},
|
||||
{
|
||||
group_by => 'user_name',
|
||||
columns => [qw/ user_name /],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
sub get_orgs {
|
||||
my $self = shift;
|
||||
|
||||
return $self->_unordered_get_values(@_)->search({},
|
||||
{
|
||||
group_by => 'org_name',
|
||||
columns => [ qw/ org_name / ],
|
||||
},
|
||||
);
|
||||
my $self = shift;
|
||||
|
||||
return $self->_unordered_get_values(@_)->search(
|
||||
{},
|
||||
{
|
||||
group_by => 'org_name',
|
||||
columns => [qw/ org_name /],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
sub get_lookups {
|
||||
my $self = shift;
|
||||
my $id = shift;
|
||||
my $self = shift;
|
||||
my $id = shift;
|
||||
|
||||
my $lookup_rs = $self->find($id)->search_related(
|
||||
'lookups',
|
||||
undef,
|
||||
{
|
||||
prefetch => { entity => [ qw/ organisation customer / ] },
|
||||
order_by => { '-asc' => 'me.id' },
|
||||
},
|
||||
);
|
||||
my $lookup_map = {
|
||||
map {
|
||||
$_->name => {
|
||||
entity_id => $_->entity->id,
|
||||
name => $_->entity->name,
|
||||
},
|
||||
} $lookup_rs->all
|
||||
};
|
||||
return $lookup_map;
|
||||
my $lookup_rs = $self->find($id)->search_related(
|
||||
'lookups',
|
||||
undef,
|
||||
{
|
||||
prefetch => { entity => [qw/ organisation customer /] },
|
||||
order_by => { '-asc' => 'me.id' },
|
||||
},
|
||||
);
|
||||
my $lookup_map = {
|
||||
map {
|
||||
$_->name => {
|
||||
entity_id => $_->entity->id,
|
||||
name => $_->entity->name,
|
||||
},
|
||||
} $lookup_rs->all
|
||||
};
|
||||
return $lookup_map;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -8,87 +8,103 @@ use base 'DBIx::Class::ResultSet';
|
|||
use DateTime;
|
||||
|
||||
sub get_latest {
|
||||
my $self = shift;
|
||||
my $type = shift;
|
||||
my $self = shift;
|
||||
my $type = shift;
|
||||
|
||||
my $type_result = $self->find_by_type( $type );
|
||||
my $type_result = $self->find_by_type($type);
|
||||
|
||||
return unless defined $type_result;
|
||||
return unless defined $type_result;
|
||||
|
||||
my $latest = $type_result->search_related('sets', {}, {
|
||||
order_by => { -desc => 'date' },
|
||||
})->first;
|
||||
my $latest = $type_result->search_related(
|
||||
'sets',
|
||||
{},
|
||||
{
|
||||
order_by => { -desc => 'date' },
|
||||
}
|
||||
)->first;
|
||||
|
||||
return $latest;
|
||||
return $latest;
|
||||
}
|
||||
|
||||
sub create_new {
|
||||
my $self = shift;
|
||||
my $type = shift;
|
||||
my $date = shift;
|
||||
my $self = shift;
|
||||
my $type = shift;
|
||||
my $date = shift;
|
||||
|
||||
my $type_result = $self->find_by_type($type);
|
||||
my $type_result = $self->find_by_type($type);
|
||||
|
||||
return unless $type_result;
|
||||
return unless $type_result;
|
||||
|
||||
return $type_result->create_new($date);
|
||||
return $type_result->create_new($date);
|
||||
}
|
||||
|
||||
sub find_by_type {
|
||||
my $self = shift;
|
||||
my $type = shift;
|
||||
my $self = shift;
|
||||
my $type = shift;
|
||||
|
||||
return $self->find({ type => $type });
|
||||
return $self->find( { type => $type } );
|
||||
}
|
||||
|
||||
sub recalculate_all {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
|
||||
for my $leaderboard_result ( $self->all ) {
|
||||
my $lb_type = $leaderboard_result->type;
|
||||
if ( $lb_type =~ /^daily/ ) {
|
||||
for my $leaderboard_result ( $self->all ) {
|
||||
my $lb_type = $leaderboard_result->type;
|
||||
if ( $lb_type =~ /^daily/ ) {
|
||||
|
||||
# Recalculating a daily set. This is calculated from the start of the
|
||||
# day, so we need yesterdays date:
|
||||
my $date = DateTime->today->subtract( days => 1 );
|
||||
$self->_recalculate_leaderboard( $leaderboard_result, $date, 'days' );
|
||||
# Recalculating a daily set. This is calculated from the start of the
|
||||
# day, so we need yesterdays date:
|
||||
my $date = DateTime->today->subtract( days => 1 );
|
||||
$self->_recalculate_leaderboard( $leaderboard_result, $date,
|
||||
'days' );
|
||||
|
||||
} elsif ( $lb_type =~ /^weekly/ ) {
|
||||
}
|
||||
elsif ( $lb_type =~ /^weekly/ ) {
|
||||
|
||||
# Recalculating a weekly set. This is calculated from a Monday, of the
|
||||
# week before.
|
||||
my $date = DateTime->today->truncate( to => 'week' )->subtract( weeks => 1 );
|
||||
$self->_recalculate_leaderboard( $leaderboard_result, $date, 'weeks' );
|
||||
# Recalculating a weekly set. This is calculated from a Monday, of the
|
||||
# week before.
|
||||
my $date =
|
||||
DateTime->today->truncate( to => 'week' )->subtract( weeks => 1 );
|
||||
$self->_recalculate_leaderboard( $leaderboard_result, $date,
|
||||
'weeks' );
|
||||
|
||||
} elsif ( $lb_type =~ /^monthly/ ) {
|
||||
}
|
||||
elsif ( $lb_type =~ /^monthly/ ) {
|
||||
|
||||
# Recalculate a monthly set. This is calculated from the first of the
|
||||
# month, for the month before.
|
||||
my $date = DateTime->today->truncate( to => 'month' )->subtract( months => 1);
|
||||
$self->_recalculate_leaderboard( $leaderboard_result, $date, 'months' );
|
||||
# Recalculate a monthly set. This is calculated from the first of the
|
||||
# month, for the month before.
|
||||
my $date = DateTime->today->truncate( to => 'month' )
|
||||
->subtract( months => 1 );
|
||||
$self->_recalculate_leaderboard( $leaderboard_result, $date,
|
||||
'months' );
|
||||
|
||||
} elsif ( $lb_type =~ /^all_time/ ) {
|
||||
}
|
||||
elsif ( $lb_type =~ /^all_time/ ) {
|
||||
|
||||
# Recalculate for an all time set. This is calculated similarly to
|
||||
# daily, but is calculated from an end time.
|
||||
my $date = DateTime->today;
|
||||
$self->_recalculate_leaderboard( $leaderboard_result, $date, 'days' );
|
||||
# Recalculate for an all time set. This is calculated similarly to
|
||||
# daily, but is calculated from an end time.
|
||||
my $date = DateTime->today;
|
||||
$self->_recalculate_leaderboard( $leaderboard_result, $date,
|
||||
'days' );
|
||||
|
||||
} else {
|
||||
warn "Unrecognised Set";
|
||||
}
|
||||
else {
|
||||
warn "Unrecognised Set";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub _recalculate_leaderboard {
|
||||
my ( $self, $lb_result, $date, $diff ) = @_;
|
||||
my ( $self, $lb_result, $date, $diff ) = @_;
|
||||
|
||||
$self->result_source->schema->txn_do( sub {
|
||||
$lb_result->sets->related_resultset('values')->delete_all;
|
||||
$lb_result->sets->delete_all;
|
||||
$lb_result->create_new($date->clone->subtract( $diff => 1 ));
|
||||
$lb_result->create_new($date);
|
||||
});
|
||||
$self->result_source->schema->txn_do(
|
||||
sub {
|
||||
$lb_result->sets->related_resultset('values')->delete_all;
|
||||
$lb_result->sets->delete_all;
|
||||
$lb_result->create_new( $date->clone->subtract( $diff => 1 ) );
|
||||
$lb_result->create_new($date);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -5,6 +5,6 @@ use warnings;
|
|||
|
||||
use base 'DBIx::Class::ResultSet';
|
||||
|
||||
sub entity { shift->search_related('entity', @_) }
|
||||
sub entity { shift->search_related( 'entity', @_ ) }
|
||||
|
||||
1;
|
||||
|
|
|
@ -8,47 +8,51 @@ use base 'DBIx::Class::ResultSet';
|
|||
use DateTime;
|
||||
|
||||
sub search_between {
|
||||
my ( $self, $from, $to ) = @_;
|
||||
my ( $self, $from, $to ) = @_;
|
||||
|
||||
my $dtf = $self->result_source->schema->storage->datetime_parser;
|
||||
return $self->search({
|
||||
purchase_time => {
|
||||
-between => [
|
||||
$dtf->format_datetime($from),
|
||||
$dtf->format_datetime($to),
|
||||
],
|
||||
},
|
||||
});
|
||||
my $dtf = $self->result_source->schema->storage->datetime_parser;
|
||||
return $self->search(
|
||||
{
|
||||
purchase_time => {
|
||||
-between =>
|
||||
[ $dtf->format_datetime($from), $dtf->format_datetime($to), ],
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
sub search_before {
|
||||
my ( $self, $date ) = @_;
|
||||
my ( $self, $date ) = @_;
|
||||
|
||||
my $dtf = $self->result_source->schema->storage->datetime_parser;
|
||||
return $self->search({
|
||||
purchase_time => { '<' => $dtf->format_datetime( $date ) },
|
||||
});
|
||||
my $dtf = $self->result_source->schema->storage->datetime_parser;
|
||||
return $self->search(
|
||||
{
|
||||
purchase_time => { '<' => $dtf->format_datetime($date) },
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
sub today_rs {
|
||||
my ( $self ) = @_;
|
||||
my ($self) = @_;
|
||||
|
||||
my $today = DateTime->today();
|
||||
return $self->search_between( $today, $today->clone->add( days => 1 ) );
|
||||
my $today = DateTime->today();
|
||||
return $self->search_between( $today, $today->clone->add( days => 1 ) );
|
||||
}
|
||||
|
||||
sub week_rs {
|
||||
my ( $self ) = @_;
|
||||
my ($self) = @_;
|
||||
|
||||
my $today = DateTime->today();
|
||||
return $self->search_between( $today->clone->subtract( days => 7 ), $today );
|
||||
my $today = DateTime->today();
|
||||
return $self->search_between( $today->clone->subtract( days => 7 ),
|
||||
$today );
|
||||
}
|
||||
|
||||
sub month_rs {
|
||||
my ( $self ) = @_;
|
||||
my ($self) = @_;
|
||||
|
||||
my $today = DateTime->today();
|
||||
return $self->search_between( $today->clone->subtract( days => 30 ), $today );
|
||||
my $today = DateTime->today();
|
||||
return $self->search_between( $today->clone->subtract( days => 30 ),
|
||||
$today );
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Reference in a new issue