Organized some category charts. Still needs some translating

This commit is contained in:
James Cole
2015-09-26 07:18:12 +02:00
parent cdc0e3cfd8
commit 7e10641461
9 changed files with 78 additions and 46 deletions

View File

@@ -31,7 +31,7 @@ interface CategoryChartGenerator
*
* @return array
*/
public function month(Collection $entries);
public function period(Collection $entries);
/**

View File

@@ -17,17 +17,12 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
/**
* @param Collection $entries
* @param string $dateFormat
*
* @return array
*/
public function all(Collection $entries, $dateFormat = 'month')
public function all(Collection $entries)
{
// language:
//$language = Preferences::get('language', 'en')->data;
//$format = Config::get('firefly.' . $dateFormat . '.' . $language);
$data = [
'count' => 2,
@@ -45,7 +40,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
];
foreach ($entries as $entry) {
$data['labels'][] = $entry[1];//$entry[0]->formatLocalized($format);
$data['labels'][] = $entry[1];
$spent = round($entry[2], 2);
$earned = round($entry[3], 2);
@@ -90,9 +85,9 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
*
* @return array
*/
public function month(Collection $entries)
public function period(Collection $entries)
{
return $this->all($entries, 'monthAndDay');
return $this->all($entries);
}

View File

@@ -164,7 +164,7 @@ class CategoryController extends Controller
$journals = new LengthAwarePaginator($set, $count, 50, $page);
$journals->setPath('categories/show/' . $category->id . '/' . $date);
return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle','carbon'));
return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
}
/**
@@ -179,8 +179,6 @@ class CategoryController extends Controller
$page = intval(Input::get('page'));
$set = $repository->getJournals($category, $page);
$count = $repository->countJournals($category);
$totalSum = $repository->journalsSum($category);
$periodSum = $repository->journalsSum($category, Session::get('start'), Session::get('end'));
$subTitle = $category->name;
$journals = new LengthAwarePaginator($set, $count, 50, $page);
$journals->setPath('categories/show/' . $category->id);
@@ -221,7 +219,7 @@ class CategoryController extends Controller
$cache->store($entries);
}
return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'totalSum', 'periodSum', 'subTitle'));
return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));
}
/**

View File

@@ -132,7 +132,7 @@ class CategoryController extends Controller
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function month(CategoryRepositoryInterface $repository, Category $category)
public function currentPeriod(CategoryRepositoryInterface $repository, Category $category)
{
$start = clone Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
@@ -143,7 +143,7 @@ class CategoryController extends Controller
$cache->addProperty($end);
$cache->addProperty($category->id);
$cache->addProperty('category');
$cache->addProperty('month');
$cache->addProperty('currentPeriod');
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
@@ -153,12 +153,55 @@ class CategoryController extends Controller
while ($start <= $end) {
$spent = $repository->spentOnDaySumCorrected($category, $start);
$earned = $repository->earnedOnDaySumCorrected($category, $start);
$date = Navigation::periodShow($start, '1D');
$date = Navigation::periodShow($start, '1D');
$entries->push([clone $start, $date, $spent, $earned]);
$start->addDay();
}
$data = $this->generator->month($entries);
$data = $this->generator->period($entries);
$cache->store($data);
return Response::json($data);
}
/**
* @param CategoryRepositoryInterface $repository
* @param Category $category
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, $date)
{
$carbon = new Carbon($date);
$range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($carbon, $range);
$end = Navigation::endOfPeriod($carbon, $range);
// chart properties for cache:
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($category->id);
$cache->addProperty('category');
$cache->addProperty('specificPeriod');
$cache->addProperty($date);
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
$entries = new Collection;
while ($start <= $end) {
$spent = $repository->spentOnDaySumCorrected($category, $start);
$earned = $repository->earnedOnDaySumCorrected($category, $start);
$theDate = Navigation::periodShow($start, '1D');
$entries->push([clone $start, $theDate, $spent, $earned]);
$start->addDay();
}
$data = $this->generator->period($entries);
$cache->store($data);
return Response::json($data);

View File

@@ -303,12 +303,13 @@ Route::group(
// categories:
Route::get('/chart/category/frontpage', ['uses' => 'Chart\CategoryController@frontpage']);
Route::get('/chart/category/spent-in-year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@spentInYear'])->where(
['year' => '[0-9]{4}', 'shared' => 'shared']
['year' => '[0-9]{4}', 'shared' => 'shared']
);
Route::get('/chart/category/earned-in-year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@earnedInYear'])->where(
['year' => '[0-9]{4}', 'shared' => 'shared']
);
Route::get('/chart/category/{category}/month', ['uses' => 'Chart\CategoryController@month']); // should be period.
Route::get('/chart/category/{category}/period', ['uses' => 'Chart\CategoryController@currentPeriod']);
Route::get('/chart/category/{category}/period/{date}', ['uses' => 'Chart\CategoryController@specificPeriod']);
Route::get('/chart/category/{category}/all', ['uses' => 'Chart\CategoryController@all']);
// piggy banks:

View File

@@ -254,6 +254,7 @@ class TransactionJournal extends Model
return $amount;
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany