mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-13 07:53:16 +00:00
Expand new charts.
This commit is contained in:
@@ -181,8 +181,8 @@ class CategoryController extends Controller
|
||||
|
||||
// get all spent and earned data:
|
||||
// get amount earned in period, grouped by day.
|
||||
$spentArray = $repository->spentPerDay($category, $start, $end);
|
||||
$earnedArray = $repository->earnedPerDay($category, $start, $end);
|
||||
$spentArray = $repository->spentPerDay($category, $start, $end, new Collection);
|
||||
$earnedArray = $repository->earnedPerDay($category, $start, $end, new Collection);
|
||||
|
||||
if ($cache->has()) {
|
||||
$entries = $cache->get();
|
||||
|
@@ -68,8 +68,8 @@ class CategoryController extends Controller
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$spentArray = $repository->spentPerDay($category, $start, $end);
|
||||
$earnedArray = $repository->earnedPerDay($category, $start, $end);
|
||||
$spentArray = $repository->spentPerDay($category, $start, $end, new Collection);
|
||||
$earnedArray = $repository->earnedPerDay($category, $start, $end, new Collection);
|
||||
|
||||
while ($start <= $end) {
|
||||
$currentEnd = Navigation::endOfPeriod($start, $range);
|
||||
@@ -417,8 +417,8 @@ class CategoryController extends Controller
|
||||
|
||||
// get amount earned in period, grouped by day.
|
||||
// get amount spent in period, grouped by day.
|
||||
$spentArray = $repository->spentPerDay($category, $start, $end);
|
||||
$earnedArray = $repository->earnedPerDay($category, $start, $end);
|
||||
$spentArray = $repository->spentPerDay($category, $start, $end, new Collection);
|
||||
$earnedArray = $repository->earnedPerDay($category, $start, $end, new Collection);
|
||||
|
||||
while ($start <= $end) {
|
||||
$str = $start->format('Y-m-d');
|
||||
@@ -470,8 +470,8 @@ class CategoryController extends Controller
|
||||
$currentStart = clone $current;
|
||||
$currentEnd = Navigation::endOfPeriod($currentStart, $viewRange);
|
||||
|
||||
$spent = strval(array_sum($repository->spentPerDay($category, $currentStart, $currentEnd)));
|
||||
$earned = strval(array_sum($repository->earnedPerDay($category, $currentStart, $currentEnd)));
|
||||
$spent = strval(array_sum($repository->spentPerDay($category, $currentStart, $currentEnd, new Collection)));
|
||||
$earned = strval(array_sum($repository->earnedPerDay($category, $currentStart, $currentEnd, new Collection)));
|
||||
|
||||
$entry = [
|
||||
$category->name,
|
||||
|
@@ -76,25 +76,32 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
* Where yyyy-mm-dd is the date and <amount> is the money earned using DEPOSITS in the $category
|
||||
* from all the users $accounts.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function earnedPerDay(Category $category, Carbon $start, Carbon $end): array
|
||||
public function earnedPerDay(Category $category, Carbon $start, Carbon $end, Collection $accounts): array
|
||||
{
|
||||
/** @var Collection $query */
|
||||
$query = $category->transactionjournals()
|
||||
->expanded()
|
||||
->transactionTypes([TransactionType::DEPOSIT])
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.amount', '>', 0)
|
||||
->before($end)
|
||||
->after($start)
|
||||
->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
->groupBy('transaction_journals.date');
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$query->whereIn('destination_account.id', $ids);
|
||||
}
|
||||
|
||||
$result = $query->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`destination`.`amount`) AS `sum`')]);
|
||||
|
||||
$return = [];
|
||||
foreach ($query->toArray() as $entry) {
|
||||
foreach ($result->toArray() as $entry) {
|
||||
$return[$entry['dateFormatted']] = $entry['sum'];
|
||||
}
|
||||
|
||||
@@ -226,25 +233,33 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
* Where yyyy-mm-dd is the date and <amount> is the money spent using DEPOSITS in the $category
|
||||
* from all the users accounts.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentPerDay(Category $category, Carbon $start, Carbon $end): array
|
||||
public function spentPerDay(Category $category, Carbon $start, Carbon $end, Collection $accounts): array
|
||||
{
|
||||
/** @var Collection $query */
|
||||
$query = $category->transactionjournals()
|
||||
->expanded()
|
||||
->transactionTypes([TransactionType::WITHDRAWAL])
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.amount', '<', 0)
|
||||
->before($end)
|
||||
->after($start)
|
||||
->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
->groupBy('transaction_journals.date');
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$query->whereIn('source_account.id', $ids);
|
||||
}
|
||||
|
||||
|
||||
$result = $query->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
|
||||
$return = [];
|
||||
foreach ($query->toArray() as $entry) {
|
||||
foreach ($result->toArray() as $entry) {
|
||||
$return[$entry['dateFormatted']] = $entry['sum'];
|
||||
}
|
||||
|
||||
|
@@ -47,13 +47,14 @@ interface SingleCategoryRepositoryInterface
|
||||
* Where yyyy-mm-dd is the date and <amount> is the money earned using DEPOSITS in the $category
|
||||
* from all the users accounts.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function earnedPerDay(Category $category, Carbon $start, Carbon $end): array;
|
||||
public function earnedPerDay(Category $category, Carbon $start, Carbon $end, Collection $accounts): array;
|
||||
|
||||
/**
|
||||
* Find a category
|
||||
@@ -118,13 +119,14 @@ interface SingleCategoryRepositoryInterface
|
||||
* Where yyyy-mm-dd is the date and <amount> is the money spent using WITHDRAWALS in the $category
|
||||
* from all the users accounts.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentPerDay(Category $category, Carbon $start, Carbon $end): array;
|
||||
public function spentPerDay(Category $category, Carbon $start, Carbon $end, Collection $accounts): array;
|
||||
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user