mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-22 20:36:43 +00:00
Clean up some code.
This commit is contained in:
@@ -23,6 +23,10 @@ use stdClass;
|
|||||||
*/
|
*/
|
||||||
class CategoryController extends Controller
|
class CategoryController extends Controller
|
||||||
{
|
{
|
||||||
|
const MAKE_POSITIVE = -1;
|
||||||
|
const KEEP_POSITIVE = 1;
|
||||||
|
|
||||||
|
|
||||||
/** @var \FireflyIII\Generator\Chart\Category\CategoryChartGeneratorInterface */
|
/** @var \FireflyIII\Generator\Chart\Category\CategoryChartGeneratorInterface */
|
||||||
protected $generator;
|
protected $generator;
|
||||||
|
|
||||||
@@ -134,32 +138,8 @@ class CategoryController extends Controller
|
|||||||
return $category->name;
|
return $category->name;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$entries = new Collection;
|
$entries = $this->filterCollection($start, $end, $set, $categories);
|
||||||
|
$data = $this->generator->earnedInPeriod($categories, $entries);
|
||||||
while ($start < $end) { // filter the set:
|
|
||||||
$row = [clone $start];
|
|
||||||
$currentSet = $set->filter( // get possibly relevant entries from the big $set
|
|
||||||
function (Category $category) use ($start) {
|
|
||||||
return $category->dateFormatted == $start->format('Y-m');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
/** @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) {
|
|
||||||
return ($cat->id == $category->id);
|
|
||||||
}
|
|
||||||
)->first();
|
|
||||||
if (!is_null($entry)) {
|
|
||||||
$row[] = round($entry->earned, 2);
|
|
||||||
} else {
|
|
||||||
$row[] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$entries->push($row);
|
|
||||||
$start->addMonth();
|
|
||||||
}
|
|
||||||
$data = $this->generator->earnedInPeriod($categories, $entries);
|
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
@@ -340,42 +320,58 @@ class CategoryController extends Controller
|
|||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$set = $repository->spentForAccountsPerMonth($accounts, $start, $end);
|
$set = $repository->spentForAccountsPerMonth($accounts, $start, $end);
|
||||||
$categories = $set->unique('id')->sortBy(
|
$categories = $set->unique('id')->sortBy(
|
||||||
function (Category $category) {
|
function (Category $category) {
|
||||||
return $category->name;
|
return $category->name;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$entries = new Collection;
|
|
||||||
|
$entries = $this->filterCollection($start, $end, $set, $categories);
|
||||||
|
$data = $this->generator->spentInPeriod($categories, $entries);
|
||||||
|
$cache->store($data);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param Collection $set
|
||||||
|
* @param Collection $categories
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
private function filterCollection(Carbon $start, Carbon $end, Collection $set, Collection $categories): Collection
|
||||||
|
{
|
||||||
|
$entries = new Collection;
|
||||||
|
|
||||||
while ($start < $end) { // filter the set:
|
while ($start < $end) { // filter the set:
|
||||||
$row = [clone $start];
|
$row = [clone $start];
|
||||||
$currentSet = $set->filter(// get possibly relevant entries from the big $set
|
$currentSet = $set->filter( // get possibly relevant entries from the big $set
|
||||||
function (Category $category) use ($start) {
|
function (Category $category) use ($start) {
|
||||||
return $category->dateFormatted == $start->format('Y-m');
|
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.
|
foreach ($categories as $category) { // check for each category if its in the current set.
|
||||||
$entry = $currentSet->filter(// if its in there, use the value.
|
$entry = $currentSet->filter( // if its in there, use the value.
|
||||||
function (Category $cat) use ($category) {
|
function (Category $cat) use ($category) {
|
||||||
return ($cat->id == $category->id);
|
return ($cat->id == $category->id);
|
||||||
}
|
}
|
||||||
)->first();
|
)->first();
|
||||||
if (!is_null($entry)) {
|
if (!is_null($entry)) {
|
||||||
$row[] = round(($entry->spent * -1), 2);
|
$row[] = round($entry->earned, 2);
|
||||||
} else {
|
} else {
|
||||||
$row[] = 0;
|
$row[] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$entries->push($row);
|
$entries->push($row);
|
||||||
$start->addMonth();
|
$start->addMonth();
|
||||||
}
|
}
|
||||||
$data = $this->generator->spentInPeriod($categories, $entries);
|
|
||||||
$cache->store($data);
|
|
||||||
|
|
||||||
return $data;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -419,5 +415,4 @@ class CategoryController extends Controller
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -832,8 +832,6 @@ class TestData
|
|||||||
*/
|
*/
|
||||||
public static function createTransactions(TransactionJournal $journal, Account $from, Account $to, string $amount): bool
|
public static function createTransactions(TransactionJournal $journal, Account $from, Account $to, string $amount): bool
|
||||||
{
|
{
|
||||||
// Log::debug('---- Transaction From: ' . bcmul($amount, '-1'));
|
|
||||||
// Log::debug('---- Transaction To : ' . $amount);
|
|
||||||
Transaction::create(
|
Transaction::create(
|
||||||
[
|
[
|
||||||
'account_id' => $from->id,
|
'account_id' => $from->id,
|
||||||
|
@@ -199,6 +199,13 @@ class FireflyValidator extends Validator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attribute
|
||||||
|
* @param $value
|
||||||
|
* @param $parameters
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool
|
public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool
|
||||||
{
|
{
|
||||||
$accountId = $this->data['id'] ?? 0;
|
$accountId = $this->data['id'] ?? 0;
|
||||||
|
Reference in New Issue
Block a user