commit
a1dd14f1d5
4 changed files with 285 additions and 141 deletions
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
# Next Release
|
# Next Release
|
||||||
|
|
||||||
|
# v0.10.5
|
||||||
|
|
||||||
|
* **Admin Feature** Removed generic Transaction List, replaced with a new
|
||||||
|
transaction statistic viewing list
|
||||||
|
* **Admin Fix** Amended user view to have accordion
|
||||||
|
|
||||||
# v0.10.4
|
# v0.10.4
|
||||||
|
|
||||||
* Added API for category budget
|
* Added API for category budget
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package Pear::LocalLoop::Controller::Admin::Transactions;
|
package Pear::LocalLoop::Controller::Admin::Transactions;
|
||||||
use Mojo::Base 'Mojolicious::Controller';
|
use Mojo::Base 'Mojolicious::Controller';
|
||||||
|
|
||||||
|
use List::Util qw/ max sum /;
|
||||||
|
|
||||||
has result_set => sub {
|
has result_set => sub {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
return $c->schema->resultset('Transaction');
|
return $c->schema->resultset('Transaction');
|
||||||
|
@ -9,15 +11,54 @@ has result_set => sub {
|
||||||
sub index {
|
sub index {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
|
||||||
my $transactions = $c->result_set->search(
|
my $pending_transaction_rs = $c->schema->resultset('Organisation')->search({ pending => 1 })->entity->sales;
|
||||||
undef, {
|
|
||||||
page => $c->param('page') || 1,
|
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
||||||
rows => 10,
|
my $week_transaction_rs = $c->schema->resultset('ViewQuantisedTransaction' . $driver)->search(
|
||||||
order_by => { -desc => 'submitted_at' },
|
{},
|
||||||
},
|
{
|
||||||
|
columns => [
|
||||||
|
{
|
||||||
|
quantised => 'quantised_weeks',
|
||||||
|
count => \"COUNT(*)",
|
||||||
|
sum_value => $c->pg_or_sqlite(
|
||||||
|
'SUM("me"."value")',
|
||||||
|
'SUM("me"."value")',
|
||||||
|
),
|
||||||
|
}
|
||||||
|
],
|
||||||
|
group_by => 'quantised_weeks',
|
||||||
|
order_by => { '-asc' => 'quantised_weeks' },
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my @all_weeks = $week_transaction_rs->all;
|
||||||
|
my $first_week_count = $all_weeks[0]->get_column('count') || 0;
|
||||||
|
my $first_week_value = $all_weeks[0]->get_column('sum_value') / 100000 || 0;
|
||||||
|
my $second_week_count = defined $all_weeks[1] ? $all_weeks[1]->get_column('count') || 0 : 0;
|
||||||
|
my $second_week_value = defined $all_weeks[1] ? $all_weeks[1]->get_column('sum_value') / 100000 || 0 : 0;
|
||||||
|
|
||||||
|
my $transaction_rs = $c->schema->resultset('Transaction');
|
||||||
|
my $value_rs_col = $transaction_rs->get_column('value');
|
||||||
|
my $max_value = $value_rs_col->max / 100000 || 0;
|
||||||
|
my $avg_value = sprintf( '%.2f', $value_rs_col->func('AVG') / 100000) || 0;
|
||||||
|
my $sum_value = $value_rs_col->sum / 100000 || 0;
|
||||||
|
my $count = $transaction_rs->count || 0;
|
||||||
|
|
||||||
|
my $placeholder = 'Placeholder';
|
||||||
$c->stash(
|
$c->stash(
|
||||||
transactions => $transactions,
|
placeholder => $placeholder,
|
||||||
|
pending_trans => $pending_transaction_rs->count,
|
||||||
|
weeks => {
|
||||||
|
first_count => $first_week_count,
|
||||||
|
second_count => $second_week_count,
|
||||||
|
first_value => $first_week_value,
|
||||||
|
second_value => $second_week_value,
|
||||||
|
max => $max_value,
|
||||||
|
avg => $avg_value,
|
||||||
|
sum => $sum_value,
|
||||||
|
count => $count,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,4 +107,19 @@ if ( my $transaction = $c->result_set->find($id) ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub pg_or_sqlite {
|
||||||
|
my ( $c, $pg_sql, $sqlite_sql ) = @_;
|
||||||
|
|
||||||
|
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
||||||
|
|
||||||
|
if ( $driver eq 'Pg' ) {
|
||||||
|
return \$pg_sql;
|
||||||
|
} elsif ( $driver eq 'SQLite' ) {
|
||||||
|
return \$sqlite_sql;
|
||||||
|
} else {
|
||||||
|
$c->app->log->warn('Unknown Driver Used');
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -11,37 +11,91 @@
|
||||||
<strong>Success!</strong> <%= $success %>
|
<strong>Success!</strong> <%= $success %>
|
||||||
</div>
|
</div>
|
||||||
% }
|
% }
|
||||||
<div class="row mb-3">
|
<div class="card-deck">
|
||||||
<div class="col">
|
<div class="card mb-3 text-center text-white bg-primary">
|
||||||
<div class="card">
|
<div class="card-header card-inverse">
|
||||||
<h3 class="card-header">
|
Number of Transactions
|
||||||
Transactions
|
|
||||||
</h3>
|
|
||||||
<div class="list-group list-group-flush">
|
|
||||||
% for my $transaction ( $transactions->all ) {
|
|
||||||
<a href="<%= url_for . '/' . $transaction->id %>" class="list-group-item list-group-item-action" target="_blank">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4 row">
|
|
||||||
<div class="col my-auto">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col">From: <%= $transaction->buyer->name %></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="card-body">
|
||||||
<div class="col">To: <%= $transaction->seller->name %></div>
|
<h2 class="card-title">
|
||||||
|
%= $weeks->{count}
|
||||||
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card mb-3 text-center text-white bg-success">
|
||||||
|
<div class="card-header card-inverse">
|
||||||
|
Sum of all Transaction Value
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 text-center my-auto"><h3><%= sprintf('£%.2f', $transaction->value / 100000) %></h3></div>
|
<div class="card-body">
|
||||||
<div class="col-md-4 text-right my-auto"><%= format_human_datetime $transaction->purchase_time %></div>
|
<h2 class="card-title">
|
||||||
</div>
|
%= '£' . $weeks->{sum}
|
||||||
</a>
|
</h2>
|
||||||
% }
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="card-deck">
|
||||||
<div class="col">
|
<div class="card mb-3 text-center text-white bg-danger">
|
||||||
%= bootstrap_pagination( $c->param('page') || 1, $transactions->pager->last_page, { class => 'justify-content-center' } );
|
<div class="card-header card-inverse">
|
||||||
|
No. Transactions This Week
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h2 class="card-title">
|
||||||
|
%= $weeks->{first_count}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card mb-3 text-center text-white bg-danger">
|
||||||
|
<div class="card-header card-inverse">
|
||||||
|
No. Transactions Last Week
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h2 class="card-title">
|
||||||
|
%= $weeks->{second_count}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-deck">
|
||||||
|
<div class="card mb-3 text-center text-white bg-danger">
|
||||||
|
<div class="card-header card-inverse">
|
||||||
|
Sum of Transactions This Week
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h2 class="card-title">
|
||||||
|
%= $weeks->{first_value}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card mb-3 text-center text-white bg-danger">
|
||||||
|
<div class="card-header card-inverse">
|
||||||
|
Sum of Transactions Last Week
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h2 class="card-title">
|
||||||
|
%= $weeks->{second_value}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-deck">
|
||||||
|
<div class="card mb-3 text-center text-white bg-danger">
|
||||||
|
<div class="card-header card-inverse">
|
||||||
|
Maximum Transaction Value
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h2 class="card-title">
|
||||||
|
%= '£' . $weeks->{max}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card mb-3 text-center text-white bg-danger">
|
||||||
|
<div class="card-header card-inverse">
|
||||||
|
Average Transaction Value
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h2 class="card-title">
|
||||||
|
%= '£' . $weeks->{avg}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -11,7 +11,18 @@
|
||||||
<strong>Success!</strong> <%= $success %>
|
<strong>Success!</strong> <%= $success %>
|
||||||
</div>
|
</div>
|
||||||
% }
|
% }
|
||||||
<form action="<%= url_for %>" method="post" autocomplete="off">
|
<div id="accordion">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header" id="headingOne">
|
||||||
|
<h5 class="mb-0">
|
||||||
|
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
|
||||||
|
Edit User Details
|
||||||
|
</button>
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#accordion">
|
||||||
|
<div class="card-body">
|
||||||
|
<form action="<%= url_for %>" method="post" autocomplete="off">
|
||||||
<div class="card mb-3">
|
<div class="card mb-3">
|
||||||
<h3 class="card-header">
|
<h3 class="card-header">
|
||||||
User Details
|
User Details
|
||||||
|
@ -99,8 +110,21 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<button class="btn btn-primary form-control" type="submit">Edit Account</button>
|
<button class="btn btn-primary form-control" type="submit">Edit Account</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div class="card mb-3">
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header" id="headingTwo">
|
||||||
|
<h5 class="mb-0">
|
||||||
|
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
|
||||||
|
View User Transaction List
|
||||||
|
</button>
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card mb-3">
|
||||||
<h3 class="card-header">
|
<h3 class="card-header">
|
||||||
Transactions
|
Transactions
|
||||||
</h3>
|
</h3>
|
||||||
|
@ -120,4 +144,8 @@
|
||||||
%= bootstrap_pagination( $c->param('page') || 1, $transactions->pager->last_page, { class => 'justify-content-center' } );
|
%= bootstrap_pagination( $c->param('page') || 1, $transactions->pager->last_page, { class => 'justify-content-center' } );
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue