-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add ranges to reports, add new report type
- Loading branch information
1 parent
f4b916d
commit 331819f
Showing
23 changed files
with
14,051 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Models\Category; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class ExpensesPerCategory | ||
{ | ||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
|
||
$query = Category::query() | ||
->where('type', Category::EXPENSES) | ||
->join('brands', 'brands.category_id', '=', 'categories.id') | ||
->join('transactions', 'transactions.brand_id', '=', 'brands.id') | ||
->select("categories.name as label", DB::raw("SUM(transactions.amount) as value")) | ||
->groupBy("categories.id") | ||
->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\Category; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class IncomePerCategory | ||
{ | ||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
|
||
$query = Category::query() | ||
->where('type', Category::INCOME) | ||
->join('brands', 'brands.category_id', '=', 'categories.id') | ||
->join('transactions', 'transactions.brand_id', '=', 'brands.id') | ||
->select("categories.name as label", DB::raw("SUM(transactions.amount) as value")) | ||
->groupBy("categories.id") | ||
->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,25 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Models\Transaction; | ||
|
||
class TotalExpenses | ||
{ | ||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
|
||
$query = Transaction::query()->expenses(); | ||
|
||
if($rangeData) { | ||
$query->whereBetween('created_at', [$rangeData->start(), $rangeData->end()]); | ||
} | ||
|
||
return $query->sum('amount'); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Queries; | ||
|
||
use App\Models\Transaction; | ||
|
||
class TotalIncome | ||
{ | ||
/** | ||
* @param null $_ | ||
* @param array<string, mixed> $args | ||
*/ | ||
public function __invoke($_, array $args) | ||
{ | ||
$rangeData = app('findRangeByKey', ["key" => $args['range']]); | ||
|
||
$query = Transaction::query()->income(); | ||
|
||
if($rangeData) { | ||
$query->whereBetween('created_at', [$rangeData->start(), $rangeData->end()]); | ||
} | ||
|
||
return $query->sum('amount'); | ||
} | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.