From 9229f6ec923bb5efa78d1282af8a3ddb3163295a Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 15 Mar 2018 13:07:29 +0000 Subject: [PATCH 1/5] removed transaction list code --- .../Controller/Admin/Transactions.pm | 15 ------- templates/admin/transactions/index.html.ep | 43 ------------------- 2 files changed, 58 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm index 084cd99..d42c3d2 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm @@ -6,21 +6,6 @@ has result_set => sub { return $c->schema->resultset('Transaction'); }; -sub index { - my $c = shift; - - my $transactions = $c->result_set->search( - undef, { - page => $c->param('page') || 1, - rows => 10, - order_by => { -desc => 'submitted_at' }, - }, - ); - $c->stash( - transactions => $transactions, - ); -} - sub read { my $c = shift; diff --git a/templates/admin/transactions/index.html.ep b/templates/admin/transactions/index.html.ep index 3ebb83a..3804baf 100644 --- a/templates/admin/transactions/index.html.ep +++ b/templates/admin/transactions/index.html.ep @@ -2,46 +2,3 @@ % title 'Transactions'; % content_for javascript => begin % end -% if ( my $error = flash 'error' ) { - -% } elsif ( my $success = flash 'success' ) { - -% } -
- -
-
-
- %= bootstrap_pagination( $c->param('page') || 1, $transactions->pager->last_page, { class => 'justify-content-center' } ); -
-
From a446e629399ff38b3ef73db0eca974abd7669ec4 Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 15 Mar 2018 13:28:31 +0000 Subject: [PATCH 2/5] amended user info view to accordion --- CHANGELOG.md | 5 + templates/admin/users/read.html.ep | 238 ++++++++++++++++------------- 2 files changed, 138 insertions(+), 105 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97da25d..018820c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ # Next Release +# v0.10.5 + +* **Admin Feature** Removed generic Transaction List +* **Admin Feature** Amended user view to have accordion + # v0.10.4 * Added API for category budget diff --git a/templates/admin/users/read.html.ep b/templates/admin/users/read.html.ep index 0a63324..0a4491a 100644 --- a/templates/admin/users/read.html.ep +++ b/templates/admin/users/read.html.ep @@ -11,113 +11,141 @@ Success! <%= $success %> % } -
-
-

- User Details -

-
-
- - -
-
- - -
-
- - -
-
- - -

Leave blank unless you want to change their password

-
+
+
+
+
+ +
-
-
- % if ( my $customer_rs = $user->entity->customer ) { -

- Customer Details -

-
-
- - -
-
- - -
-
- - -
-
- - -
-
- % } elsif ( my $org_rs = $user->entity->organisation ) { -

- Organisation Details -

-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- % } else { -

- Warning! -

-
- User is not a customer or an organisation -
- % } -
-
- -
- -
-

- Transactions -

-
- % for my $transaction ( $transactions->all ) { - -
-
From: <%= $transaction->buyer->name %>
-
To: <%= $transaction->seller->name %>
-
Value: <%= $transaction->value %>
-
Submitted At: <%= $transaction->submitted_at %>
-
Purchase Time: <%= $transaction->purchase_time %>
+
+
+
+
+

+ User Details +

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +

Leave blank unless you want to change their password

+
+
-
- % } -
- %= bootstrap_pagination( $c->param('page') || 1, $transactions->pager->last_page, { class => 'justify-content-center' } ); +
+ % if ( my $customer_rs = $user->entity->customer ) { +

+ Customer Details +

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ % } elsif ( my $org_rs = $user->entity->organisation ) { +

+ Organisation Details +

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ % } else { +

+ Warning! +

+
+ User is not a customer or an organisation +
+ % } +
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+
+
+

+ Transactions +

+
+ % for my $transaction ( $transactions->all ) { + +
+
From: <%= $transaction->buyer->name %>
+
To: <%= $transaction->seller->name %>
+
Value: <%= $transaction->value %>
+
Submitted At: <%= $transaction->submitted_at %>
+
Purchase Time: <%= $transaction->purchase_time %>
+
+
+ % } +
+ %= bootstrap_pagination( $c->param('page') || 1, $transactions->pager->last_page, { class => 'justify-content-center' } ); +
+
+
+
From b13081faa72489bda830f49fce4134614b9afe65 Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 15 Mar 2018 13:38:06 +0000 Subject: [PATCH 3/5] made changes to still have status view from delete --- CHANGELOG.md | 4 ++-- templates/admin/transactions/index.html.ep | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 018820c..6c5a462 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ # v0.10.5 -* **Admin Feature** Removed generic Transaction List -* **Admin Feature** Amended user view to have accordion +* **Admin Fix** Removed generic Transaction List +* **Admin Fix** Amended user view to have accordion # v0.10.4 diff --git a/templates/admin/transactions/index.html.ep b/templates/admin/transactions/index.html.ep index 3804baf..9ed00f1 100644 --- a/templates/admin/transactions/index.html.ep +++ b/templates/admin/transactions/index.html.ep @@ -2,3 +2,12 @@ % title 'Transactions'; % content_for javascript => begin % end +% if ( my $error = flash 'error' ) { + +% } elsif ( my $success = flash 'success' ) { + +% } From 3341053ca41121a88af23bd02589bad16bbee5c1 Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 15 Mar 2018 16:02:17 +0000 Subject: [PATCH 4/5] revamped transaction list view --- .../Controller/Admin/Transactions.pm | 71 +++++++++++++++ templates/admin/transactions/index.html.ep | 88 +++++++++++++++++++ 2 files changed, 159 insertions(+) diff --git a/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm index d42c3d2..05bcd70 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm @@ -1,11 +1,67 @@ package Pear::LocalLoop::Controller::Admin::Transactions; use Mojo::Base 'Mojolicious::Controller'; +use List::Util qw/ max sum /; + has result_set => sub { my $c = shift; return $c->schema->resultset('Transaction'); }; +sub index { + my $c = shift; + + my $pending_transaction_rs = $c->schema->resultset('Organisation')->search({ pending => 1 })->entity->sales; + + my $driver = $c->schema->storage->dbh->{Driver}->{Name}; + my $week_transaction_rs = $c->schema->resultset('ViewQuantisedTransaction' . $driver)->search( + {}, + { + 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( + 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, + }, + ); +} + sub read { my $c = shift; @@ -51,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; diff --git a/templates/admin/transactions/index.html.ep b/templates/admin/transactions/index.html.ep index 9ed00f1..be1843d 100644 --- a/templates/admin/transactions/index.html.ep +++ b/templates/admin/transactions/index.html.ep @@ -11,3 +11,91 @@ Success! <%= $success %>
% } +
+
+
+ Number of Transactions +
+
+

+ %= $weeks->{count} +

+
+
+
+
+ Sum of all Transaction Value +
+
+

+ %= '£' . $weeks->{sum} +

+
+
+
+
+
+
+ No. Transactions This Week +
+
+

+ %= $weeks->{first_count} +

+
+
+
+
+ No. Transactions Last Week +
+
+

+ %= $weeks->{second_count} +

+
+
+
+
+
+
+ Sum of Transactions This Week +
+
+

+ %= $weeks->{first_value} +

+
+
+
+
+ Sum of Transactions Last Week +
+
+

+ %= $weeks->{second_value} +

+
+
+
+
+
+
+ Maximum Transaction Value +
+
+

+ %= '£' . $weeks->{max} +

+
+
+
+
+ Average Transaction Value +
+
+

+ %= '£' . $weeks->{avg} +

+
+
+
From 8f2b8c163bbcad1e2d0d5c1a22f3e1cb5659d50b Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 15 Mar 2018 16:04:21 +0000 Subject: [PATCH 5/5] Changelog amended --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c5a462..f712caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ # v0.10.5 -* **Admin Fix** Removed generic Transaction List +* **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