Expand new charts.

This commit is contained in:
James Cole
2016-04-26 22:30:53 +02:00
parent 66f2df9677
commit 1591b61b77
4 changed files with 49 additions and 32 deletions

View File

@@ -181,8 +181,8 @@ class CategoryController extends Controller
// get all spent and earned data: // get all spent and earned data:
// get amount earned in period, grouped by day. // get amount earned in period, grouped by day.
$spentArray = $repository->spentPerDay($category, $start, $end); $spentArray = $repository->spentPerDay($category, $start, $end, new Collection);
$earnedArray = $repository->earnedPerDay($category, $start, $end); $earnedArray = $repository->earnedPerDay($category, $start, $end, new Collection);
if ($cache->has()) { if ($cache->has()) {
$entries = $cache->get(); $entries = $cache->get();

View File

@@ -68,8 +68,8 @@ class CategoryController extends Controller
if ($cache->has()) { if ($cache->has()) {
return Response::json($cache->get()); return Response::json($cache->get());
} }
$spentArray = $repository->spentPerDay($category, $start, $end); $spentArray = $repository->spentPerDay($category, $start, $end, new Collection);
$earnedArray = $repository->earnedPerDay($category, $start, $end); $earnedArray = $repository->earnedPerDay($category, $start, $end, new Collection);
while ($start <= $end) { while ($start <= $end) {
$currentEnd = Navigation::endOfPeriod($start, $range); $currentEnd = Navigation::endOfPeriod($start, $range);
@@ -417,8 +417,8 @@ class CategoryController extends Controller
// get amount earned in period, grouped by day. // get amount earned in period, grouped by day.
// get amount spent in period, grouped by day. // get amount spent in period, grouped by day.
$spentArray = $repository->spentPerDay($category, $start, $end); $spentArray = $repository->spentPerDay($category, $start, $end, new Collection);
$earnedArray = $repository->earnedPerDay($category, $start, $end); $earnedArray = $repository->earnedPerDay($category, $start, $end, new Collection);
while ($start <= $end) { while ($start <= $end) {
$str = $start->format('Y-m-d'); $str = $start->format('Y-m-d');
@@ -470,8 +470,8 @@ class CategoryController extends Controller
$currentStart = clone $current; $currentStart = clone $current;
$currentEnd = Navigation::endOfPeriod($currentStart, $viewRange); $currentEnd = Navigation::endOfPeriod($currentStart, $viewRange);
$spent = strval(array_sum($repository->spentPerDay($category, $currentStart, $currentEnd))); $spent = strval(array_sum($repository->spentPerDay($category, $currentStart, $currentEnd, new Collection)));
$earned = strval(array_sum($repository->earnedPerDay($category, $currentStart, $currentEnd))); $earned = strval(array_sum($repository->earnedPerDay($category, $currentStart, $currentEnd, new Collection)));
$entry = [ $entry = [
$category->name, $category->name,

View File

@@ -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 * Where yyyy-mm-dd is the date and <amount> is the money earned using DEPOSITS in the $category
* from all the users $accounts. * from all the users $accounts.
* *
* @param Category $category * @param Category $category
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* @param Collection $accounts
* *
* @return array * @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 */ /** @var Collection $query */
$query = $category->transactionjournals() $query = $category->transactionjournals()
->expanded()
->transactionTypes([TransactionType::DEPOSIT]) ->transactionTypes([TransactionType::DEPOSIT])
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.amount', '>', 0)
->before($end) ->before($end)
->after($start) ->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 = []; $return = [];
foreach ($query->toArray() as $entry) { foreach ($result->toArray() as $entry) {
$return[$entry['dateFormatted']] = $entry['sum']; $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 * Where yyyy-mm-dd is the date and <amount> is the money spent using DEPOSITS in the $category
* from all the users accounts. * from all the users accounts.
* *
* @param Category $category * @param Category $category
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* @param Collection $accounts
* *
* @return array * @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 */ /** @var Collection $query */
$query = $category->transactionjournals() $query = $category->transactionjournals()
->expanded()
->transactionTypes([TransactionType::WITHDRAWAL]) ->transactionTypes([TransactionType::WITHDRAWAL])
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.amount', '<', 0)
->before($end) ->before($end)
->after($start) ->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 = []; $return = [];
foreach ($query->toArray() as $entry) { foreach ($result->toArray() as $entry) {
$return[$entry['dateFormatted']] = $entry['sum']; $return[$entry['dateFormatted']] = $entry['sum'];
} }

View File

@@ -47,13 +47,14 @@ interface SingleCategoryRepositoryInterface
* Where yyyy-mm-dd is the date and <amount> is the money earned using DEPOSITS in the $category * Where yyyy-mm-dd is the date and <amount> is the money earned using DEPOSITS in the $category
* from all the users accounts. * from all the users accounts.
* *
* @param Category $category * @param Category $category
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* @param Collection $accounts
* *
* @return array * @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 * 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 * Where yyyy-mm-dd is the date and <amount> is the money spent using WITHDRAWALS in the $category
* from all the users accounts. * from all the users accounts.
* *
* @param Category $category * @param Category $category
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* @param Collection $accounts
* *
* @return array * @return array
*/ */
public function spentPerDay(Category $category, Carbon $start, Carbon $end): array; public function spentPerDay(Category $category, Carbon $start, Carbon $end, Collection $accounts): array;
/** /**