-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from saleem-hadad/feat/add-facts-reports-to-da…
…shboard 💰 Add facts reports to dashboard #feature
- Loading branch information
Showing
40 changed files
with
827 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Models\Transaction; | ||
use Illuminate\Support\Facades\DB; | ||
use App\Domain\Metrics\PartitionMetric; | ||
|
||
class AverageValueTransaction extends PartitionMetric | ||
{ | ||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
|
||
$query = Transaction::query() | ||
->join('brands', 'brands.id', '=', 'transactions.brand_id') | ||
->join('categories', 'categories.id', '=', 'brands.id') | ||
->select("categories.type as label", DB::raw("avg(transactions.amount) as value")) | ||
->groupBy("categories.type") | ||
->orderBy('value', 'DESC'); | ||
|
||
if($rangeData) { | ||
$query->whereBetween('transactions.created_at', [$rangeData->start(), $rangeData->end()]); | ||
} | ||
|
||
return $query->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Models\Transaction; | ||
use Illuminate\Support\Facades\DB; | ||
use App\Domain\Metrics\PartitionMetric; | ||
|
||
class HighestValueTransaction extends PartitionMetric | ||
{ | ||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
|
||
$query = Transaction::query() | ||
->join('brands', 'brands.id', '=', 'transactions.brand_id') | ||
->join('categories', 'categories.id', '=', 'brands.id') | ||
->select("categories.type as label", DB::raw("max(transactions.amount) as value")) | ||
->groupBy("categories.type") | ||
->orderBy('value', 'DESC'); | ||
|
||
if($rangeData) { | ||
$query->whereBetween('transactions.created_at', [$rangeData->start(), $rangeData->end()]); | ||
} | ||
|
||
return $query->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Models\Transaction; | ||
use Illuminate\Support\Facades\DB; | ||
use App\Domain\Metrics\PartitionMetric; | ||
|
||
class LowestValueTransaction extends PartitionMetric | ||
{ | ||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
|
||
$query = Transaction::query() | ||
->join('brands', 'brands.id', '=', 'transactions.brand_id') | ||
->join('categories', 'categories.id', '=', 'brands.id') | ||
->select("categories.type as label", DB::raw("min(transactions.amount) as value")) | ||
->groupBy("categories.type") | ||
->orderBy('value', 'DESC'); | ||
|
||
if($rangeData) { | ||
$query->whereBetween('transactions.created_at', [$rangeData->start(), $rangeData->end()]); | ||
} | ||
|
||
return $query->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Models\Transaction; | ||
use Illuminate\Support\Facades\DB; | ||
use App\Domain\Metrics\PartitionMetric; | ||
|
||
class NumberOfTransactions extends PartitionMetric | ||
{ | ||
protected $showCurrency = false; | ||
|
||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
|
||
$query = Transaction::query() | ||
->join('brands', 'brands.id', '=', 'transactions.brand_id') | ||
->join('categories', 'categories.id', '=', 'brands.id') | ||
->select("categories.type as label", DB::raw("count(transactions.id) as value")) | ||
->groupBy("categories.type") | ||
->orderBy('value', 'DESC'); | ||
|
||
if($rangeData) { | ||
$query->whereBetween('transactions.created_at', [$rangeData->start(), $rangeData->end()]); | ||
} | ||
|
||
return $query->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Models\Transaction; | ||
use Illuminate\Support\Facades\DB; | ||
use App\Domain\Metrics\RelationPartitionMetric; | ||
|
||
class NumberOfTransactionsPerBrand extends RelationPartitionMetric | ||
{ | ||
protected $showCurrency = false; | ||
protected $relationGraphqlQuery = 'allCategories'; | ||
protected $relationDisplayUsing = 'name'; | ||
protected $relationForeignKey = 'id'; | ||
|
||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
$categoryId = $args['id']; | ||
|
||
$query = Transaction::query() | ||
->join('brands', 'brands.id', '=', 'transactions.brand_id') | ||
->whereHas('brand.category', function ($query) use($categoryId) { | ||
return $query->where('id', $categoryId); | ||
}) | ||
->select("brands.name as label", DB::raw("count(transactions.id) as value")) | ||
->groupBy("brands.name") | ||
->orderBy('value', 'DESC'); | ||
|
||
if($rangeData) { | ||
$query->whereBetween('transactions.created_at', [$rangeData->start(), $rangeData->end()]); | ||
} | ||
|
||
return $query->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Models\Transaction; | ||
use Illuminate\Support\Facades\DB; | ||
use App\Domain\Metrics\PartitionMetric; | ||
|
||
class NumberOfTransactionsPerCategory extends PartitionMetric | ||
{ | ||
protected $showCurrency = false; | ||
|
||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
|
||
$query = Transaction::query() | ||
->join('brands', 'brands.id', '=', 'transactions.brand_id') | ||
->join('categories', 'categories.id', '=', 'brands.id') | ||
->select("categories.name as label", DB::raw("count(transactions.id) as value")) | ||
->groupBy("categories.name") | ||
->orderBy('value', 'DESC'); | ||
|
||
if($rangeData) { | ||
$query->whereBetween('transactions.created_at', [$rangeData->start(), $rangeData->end()]); | ||
} | ||
|
||
return $query->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Domain\Element; | ||
|
||
class SectionDivider extends Element | ||
{ | ||
protected $component = "section-divider"; | ||
protected $width = 'full'; | ||
protected $title; | ||
|
||
public function component() | ||
{ | ||
return $this->component; | ||
} | ||
|
||
public function width() | ||
{ | ||
return $this->width; | ||
} | ||
|
||
public function title() | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function withTitle($title) | ||
{ | ||
$this->title = $title; | ||
|
||
return $this; | ||
} | ||
|
||
public function jsonSerialize(): mixed | ||
{ | ||
return array_merge(parent::jsonSerialize(), [ | ||
'component' => $this->component(), | ||
'width' => $this->width(), | ||
'title' => $this->title(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Models\Transaction; | ||
use Illuminate\Support\Facades\DB; | ||
use App\Domain\Metrics\RelationTrendMetric; | ||
|
||
class TransactionsStandardDeviation extends RelationTrendMetric | ||
{ | ||
protected $relationGraphqlQuery = 'allCategories'; | ||
protected $relationDisplayUsing = 'name'; | ||
protected $relationForeignKey = 'id'; | ||
protected $showStandardDeviation = true; | ||
|
||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
$categoryId = $args['id']; | ||
|
||
$query = Transaction::query() | ||
->whereHas('brand.category', function ($query) use($categoryId) { | ||
return $query->where('id', $categoryId); | ||
}) | ||
->select(DB::raw("transactions.id as label, transactions.amount as value")) | ||
->orderBy('transactions.created_at', 'asc'); | ||
|
||
if($rangeData) { | ||
$query->whereBetween('transactions.created_at', [$rangeData->start(), $rangeData->end()]); | ||
} | ||
|
||
return $query->get(); | ||
} | ||
} |
Oops, something went wrong.