mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
New stuff for categories and transactions.
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Http\Requests\CategoryFormRequest;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface as CRI;
|
||||
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface as SCRI;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -69,12 +69,12 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SCRI $repository
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(SCRI $repository, Category $category)
|
||||
public function destroy(CRI $repository, Category $category)
|
||||
{
|
||||
|
||||
$name = $category->name;
|
||||
@@ -108,18 +108,17 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRI $repository
|
||||
* @param SCRI $singleRepository
|
||||
* @param CRI $repository
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(CRI $repository, SCRI $singleRepository)
|
||||
public function index(CRI $repository)
|
||||
{
|
||||
$categories = $repository->getCategories();
|
||||
|
||||
$categories->each(
|
||||
function (Category $category) use ($singleRepository) {
|
||||
$category->lastActivity = $singleRepository->getLatestActivity($category);
|
||||
function (Category $category) use ($repository) {
|
||||
$category->lastActivity = $repository->lastUseDate($category, new Collection);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -137,7 +136,7 @@ class CategoryController extends Controller
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Carbon::now()->startOfMonth());
|
||||
$list = $repository->listNoCategory($start, $end);
|
||||
$list = $repository->journalsInPeriodWithoutCategory(new Collection(), $start, $end);
|
||||
$subTitle = trans(
|
||||
'firefly.without_category_between',
|
||||
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||
@@ -147,26 +146,24 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SCRI $repository
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(SCRI $repository, Category $category)
|
||||
public function show(CRI $repository, Category $category)
|
||||
{
|
||||
$hideCategory = true; // used in list.
|
||||
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||
$page = intval(Input::get('page'));
|
||||
$set = $repository->getJournals($category, $page, $pageSize);
|
||||
$count = $repository->countJournals($category);
|
||||
$subTitle = $category->name;
|
||||
$journals = new LengthAwarePaginator($set, $count, $pageSize, $page);
|
||||
$journals = $repository->getJournals($category, $page, $pageSize);
|
||||
$journals->setPath('categories/show/' . $category->id);
|
||||
|
||||
// list of ranges for list of periods:
|
||||
|
||||
// oldest transaction in category:
|
||||
$start = $repository->getFirstActivityDate($category);
|
||||
//$start = $repository->getFirstActivityDate($category);
|
||||
$start = $repository->firstUseDate($category, new Account);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($start, $range);
|
||||
$end = Navigation::endOfX(new Carbon, $range);
|
||||
@@ -179,26 +176,22 @@ class CategoryController extends Controller
|
||||
$cache->addProperty('category-show');
|
||||
$cache->addProperty($category->id);
|
||||
|
||||
// get all spent and earned data:
|
||||
// get amount earned in period, grouped by day.
|
||||
$spentArray = $repository->spentPerDay($category, $start, $end, new Collection);
|
||||
$earnedArray = $repository->earnedPerDay($category, $start, $end, new Collection);
|
||||
|
||||
if ($cache->has()) {
|
||||
$entries = $cache->get();
|
||||
|
||||
return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));
|
||||
//$entries = $cache->get();
|
||||
//return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));
|
||||
}
|
||||
|
||||
|
||||
$categoryCollection = new Collection([$category]);
|
||||
$empty = new Collection;
|
||||
while ($end >= $start) {
|
||||
$end = Navigation::startOfPeriod($end, $range);
|
||||
$currentEnd = Navigation::endOfPeriod($end, $range);
|
||||
|
||||
// get data from spentArray:
|
||||
$spent = $this->getSumOfRange($end, $currentEnd, $spentArray);
|
||||
$earned = $this->getSumOfRange($end, $currentEnd, $earnedArray);
|
||||
$dateStr = $end->format('Y-m-d');
|
||||
$dateName = Navigation::periodShow($end, $range);
|
||||
$spent = $repository->spentInPeriod($categoryCollection, $empty, $end, $currentEnd);
|
||||
$earned = $repository->earnedInPeriod($categoryCollection, $empty, $end, $currentEnd);
|
||||
$dateStr = $end->format('Y-m-d');
|
||||
$dateName = Navigation::periodShow($end, $range);
|
||||
$entries->push([$dateStr, $dateName, $spent, $earned]);
|
||||
|
||||
$end = Navigation::subtractPeriod($end, $range, 1);
|
||||
@@ -210,28 +203,28 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SCRI $repository
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @param $date
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showWithDate(SCRI $repository, Category $category, string $date)
|
||||
public function showWithDate(CRI $repository, Category $category, string $date)
|
||||
{
|
||||
$carbon = new Carbon($date);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($carbon, $range);
|
||||
$end = Navigation::endOfPeriod($carbon, $range);
|
||||
$subTitle = $category->name;
|
||||
|
||||
$carbon = new Carbon($date);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($carbon, $range);
|
||||
$end = Navigation::endOfPeriod($carbon, $range);
|
||||
$subTitle = $category->name;
|
||||
$hideCategory = true; // used in list.
|
||||
$page = intval(Input::get('page'));
|
||||
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||
|
||||
$set = $repository->getJournalsInRange($category, $start, $end, $page, $pageSize);
|
||||
$count = $repository->countJournals($category, $start, $end);
|
||||
$journals = new LengthAwarePaginator($set, $count, $pageSize, $page);
|
||||
$offset = ($page - 1) * $pageSize;
|
||||
$set = $repository->journalsInPeriod(new Collection([$category]), new Collection, [], $start, $end);
|
||||
$count = $set->count();
|
||||
$subSet = $set->splice($offset, $pageSize);
|
||||
$journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page);
|
||||
$journals->setPath('categories/show/' . $category->id . '/' . $date);
|
||||
|
||||
return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
|
||||
@@ -239,11 +232,11 @@ class CategoryController extends Controller
|
||||
|
||||
/**
|
||||
* @param CategoryFormRequest $request
|
||||
* @param SCRI $repository
|
||||
* @param CRI $repository
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(CategoryFormRequest $request, SCRI $repository)
|
||||
public function store(CategoryFormRequest $request, CRI $repository)
|
||||
{
|
||||
$categoryData = [
|
||||
'name' => $request->input('name'),
|
||||
@@ -266,12 +259,12 @@ class CategoryController extends Controller
|
||||
|
||||
/**
|
||||
* @param CategoryFormRequest $request
|
||||
* @param SCRI $repository
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(CategoryFormRequest $request, SCRI $repository, Category $category)
|
||||
public function update(CategoryFormRequest $request, CRI $repository, Category $category)
|
||||
{
|
||||
$categoryData = [
|
||||
'name' => $request->input('name'),
|
||||
|
@@ -10,8 +10,6 @@ use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface as CRI;
|
||||
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface as SCRI;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Navigation;
|
||||
@@ -47,13 +45,14 @@ class CategoryController extends Controller
|
||||
/**
|
||||
* Show an overview for a category for all time, per month/week/year.
|
||||
*
|
||||
* @param SCRI $repository
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function all(SCRI $repository, Category $category)
|
||||
public function all(CRI $repository, Category $category)
|
||||
{
|
||||
/**
|
||||
// oldest transaction in category:
|
||||
$start = $repository->getFirstActivityDate($category);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
@@ -87,21 +86,24 @@ class CategoryController extends Controller
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
* **/
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SCRI $repository
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function currentPeriod(SCRI $repository, Category $category)
|
||||
public function currentPeriod(CRI $repository, Category $category)
|
||||
{
|
||||
/**
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$data = $this->makePeriodChart($repository, $category, $start, $end);
|
||||
|
||||
return Response::json($data);
|
||||
* **/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,6 +120,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function earnedInPeriod(CRI $repository, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
/**
|
||||
$cache = new CacheProperties; // chart properties for cache:
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
@@ -140,7 +143,7 @@ class CategoryController extends Controller
|
||||
$cache->store($data);
|
||||
|
||||
return $data;
|
||||
|
||||
**/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +157,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function frontpage(CRI $repository, ARI $accountRepository)
|
||||
{
|
||||
|
||||
/**
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
|
||||
@@ -184,7 +187,7 @@ class CategoryController extends Controller
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
**/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,8 +201,9 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function multiYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts, Collection $categories)
|
||||
{
|
||||
/** @var CRI $repository */
|
||||
$repository = app(CRI::class);
|
||||
/**
|
||||
// /** @var CRI $repository
|
||||
// $repository = app(CRI::class);
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
@@ -217,7 +221,7 @@ class CategoryController extends Controller
|
||||
$entries = new Collection;
|
||||
$set = $repository->listMultiYear($categories, $accounts, $start, $end);
|
||||
|
||||
/** @var Category $category */
|
||||
/** @var Category $category
|
||||
foreach ($categories as $category) {
|
||||
$entry = ['name' => '', 'spent' => [], 'earned' => []];
|
||||
|
||||
@@ -268,6 +272,8 @@ class CategoryController extends Controller
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -282,6 +288,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function period(Category $category, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
/**
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
@@ -295,8 +302,8 @@ class CategoryController extends Controller
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
/** @var SingleCategoryRepositoryInterface $repository */
|
||||
$repository = app(SingleCategoryRepositoryInterface::class);
|
||||
/** @var CategoryRepositoryInterface $repository
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
// loop over period, add by users range:
|
||||
$current = clone $start;
|
||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||
@@ -324,19 +331,21 @@ class CategoryController extends Controller
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
* **/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SCRI $repository
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
*
|
||||
* @param $date
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function specificPeriod(SCRI $repository, Category $category, $date)
|
||||
public function specificPeriod(CRI $repository, Category $category, $date)
|
||||
{
|
||||
/**
|
||||
$carbon = new Carbon($date);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($carbon, $range);
|
||||
@@ -345,7 +354,7 @@ class CategoryController extends Controller
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
|
||||
**/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,6 +372,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function spentInPeriod(CRI $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
/**
|
||||
$cache = new CacheProperties; // chart properties for cache:
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
@@ -387,6 +397,7 @@ class CategoryController extends Controller
|
||||
$cache->store($data);
|
||||
|
||||
return $data;
|
||||
* */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,6 +410,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
private function filterCollection(Carbon $start, Carbon $end, Collection $set, Collection $categories): Collection
|
||||
{
|
||||
/**
|
||||
$entries = new Collection;
|
||||
|
||||
while ($start < $end) { // filter the set:
|
||||
@@ -408,7 +420,7 @@ class CategoryController extends Controller
|
||||
return $category->dateFormatted == $start->format('Y-m');
|
||||
}
|
||||
);
|
||||
/** @var Category $category */
|
||||
/** @var Category $category
|
||||
foreach ($categories as $category) { // check for each category if its in the current set.
|
||||
$entry = $currentSet->filter( // if its in there, use the value.
|
||||
function (Category $cat) use ($category) {
|
||||
@@ -426,6 +438,7 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
return $entries;
|
||||
* */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,6 +450,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
private function invertSelection(Collection $entries): Collection
|
||||
{
|
||||
/**
|
||||
$result = new Collection;
|
||||
foreach ($entries as $entry) {
|
||||
$new = [$entry[0]];
|
||||
@@ -448,19 +462,21 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
return $result;
|
||||
* **/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SCRI $repository
|
||||
* @param CRI $repository
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function makePeriodChart(SCRI $repository, Category $category, Carbon $start, Carbon $end)
|
||||
private function makePeriodChart(CRI $repository, Category $category, Carbon $start, Carbon $end)
|
||||
{
|
||||
/**
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
@@ -490,6 +506,7 @@ class CategoryController extends Controller
|
||||
$cache->store($data);
|
||||
|
||||
return $data;
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -73,7 +73,7 @@ class Controller extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the array as returned by SingleCategoryRepositoryInterface::spentPerDay and SingleCategoryRepositoryInterface::earnedByDay
|
||||
* Take the array as returned by CategoryRepositoryInterface::spentPerDay and CategoryRepositoryInterface::earnedByDay
|
||||
* and sum up everything in the array in the given range.
|
||||
*
|
||||
* @param Carbon $start
|
||||
|
@@ -18,7 +18,7 @@ use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Support\Binder\AccountList;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -160,10 +160,10 @@ class ReportController extends Controller
|
||||
*/
|
||||
private function categoryEntry(array $attributes): string
|
||||
{
|
||||
/** @var SingleCategoryRepositoryInterface $repository */
|
||||
$repository = app(SingleCategoryRepositoryInterface::class);
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$category = $repository->find(intval($attributes['categoryId']));
|
||||
$journals = $repository->getJournalsForAccountsInRange($category, $attributes['accounts'], $attributes['startDate'], $attributes['endDate']);
|
||||
$journals = $repository->journalsInPeriod(new Collection([$category]), $attributes['accounts'], [], $attributes['startDate'], $attributes['endDate']);
|
||||
$view = view('popup.report.category-entry', compact('journals', 'category'))->render();
|
||||
|
||||
return $view;
|
||||
|
@@ -317,7 +317,7 @@ class ReportController extends Controller
|
||||
$budgets = $this->budgetHelper->getBudgetsWithExpenses($start, $end, $accounts);
|
||||
|
||||
// find the categories we've spent money on this period with these accounts:
|
||||
$categories = $this->helper->getCategoriesWithExpenses($start, $end, $accounts);
|
||||
$categories = $this->helper->getCategoriesWithTransactions($start, $end, $accounts);
|
||||
|
||||
Session::flash('gaEventCategory', 'report');
|
||||
Session::flash('gaEventAction', 'year');
|
||||
|
Reference in New Issue
Block a user