mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-23 22:35:03 +00:00
Refactoring.
This commit is contained in:
@@ -8,10 +8,7 @@ use FireflyIII\Generator\Chart\Account\AccountChartGeneratorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
use Response;
|
||||
|
||||
/** checked
|
||||
* Class AccountController
|
||||
@@ -34,39 +31,6 @@ class AccountController extends Controller
|
||||
$this->generator = app(AccountChartGeneratorInterface::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows the balances for a given set of dates and accounts.
|
||||
*
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function report(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('all');
|
||||
$cache->addProperty('accounts');
|
||||
$cache->addProperty('default');
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($accounts);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
// make chart:
|
||||
$data = $this->generator->frontpage($accounts, $start, $end);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the balances for all the user's expense accounts.
|
||||
*
|
||||
@@ -76,6 +40,7 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function expenseAccounts(ARI $repository)
|
||||
{
|
||||
/*
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
$accounts = $repository->getAccounts(['Expense account', 'Beneficiary account']);
|
||||
@@ -94,7 +59,7 @@ class AccountController extends Controller
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,6 +71,7 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function frontpage(ARI $repository)
|
||||
{
|
||||
/*
|
||||
$frontPage = Preferences::get('frontPageAccounts', []);
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
@@ -125,7 +91,41 @@ class AccountController extends Controller
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the balances for a given set of dates and accounts.
|
||||
*
|
||||
* @param $reportType
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function report(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
/*
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('all');
|
||||
$cache->addProperty('accounts');
|
||||
$cache->addProperty('default');
|
||||
$cache->addProperty($reportType);
|
||||
$cache->addProperty($accounts);
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
// make chart:
|
||||
$data = $this->generator->frontpage($accounts, $start, $end);
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +137,7 @@ class AccountController extends Controller
|
||||
*/
|
||||
public function single(Account $account)
|
||||
{
|
||||
|
||||
/*
|
||||
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
@@ -157,5 +157,6 @@ class AccountController extends Controller
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@@ -42,26 +42,11 @@ class BillController extends Controller
|
||||
*/
|
||||
public function frontpage(BillRepositoryInterface $repository)
|
||||
{
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$paid = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
|
||||
$unpaid = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
|
||||
$creditCardDue = $repository->getCreditCardBill($start, $end);
|
||||
|
||||
if ($creditCardDue < 0) {
|
||||
// expenses are negative (bill not yet paid),
|
||||
$creditCardDue = bcmul($creditCardDue, '-1');
|
||||
$unpaid = bcadd($unpaid, $creditCardDue);
|
||||
}
|
||||
|
||||
// if $creditCardDue more than zero, the bill has been paid: (transfer = positive).
|
||||
// amount must be negative to be added to $paid:
|
||||
if ($creditCardDue >= 0) {
|
||||
$paid = bcadd($paid, $creditCardDue);
|
||||
}
|
||||
|
||||
// build chart:
|
||||
$data = $this->generator->frontpage($paid, $unpaid);
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$paid = $repository->getBillsPaidInRange($start, $end); // will be a negative amount.
|
||||
$unpaid = $repository->getBillsUnpaidInRange($start, $end); // will be a positive amount.
|
||||
$data = $this->generator->frontpage($paid, $unpaid);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
@@ -110,7 +110,7 @@ class BudgetController extends Controller
|
||||
$cache->addProperty($repetition->id);
|
||||
|
||||
if ($cache->has()) {
|
||||
// return Response::json($cache->get());
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$entries = new Collection;
|
||||
@@ -150,7 +150,7 @@ class BudgetController extends Controller
|
||||
$cache->addProperty('budget');
|
||||
$cache->addProperty('all');
|
||||
if ($cache->has()) {
|
||||
//return Response::json($cache->get());
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$budgets = $repository->getActiveBudgets();
|
||||
$repetitions = $repository->getAllBudgetLimitRepetitions($start, $end);
|
||||
@@ -203,8 +203,6 @@ class BudgetController extends Controller
|
||||
$data = $this->generator->frontpage($allEntries);
|
||||
$cache->store($data);
|
||||
|
||||
return ' ' . json_encode($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
@@ -230,7 +228,7 @@ class BudgetController extends Controller
|
||||
$cache->addProperty('multiYearBudget');
|
||||
|
||||
if ($cache->has()) {
|
||||
//return Response::json($cache->get());
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$budgetIds = $budgets->pluck('id')->toArray();
|
||||
$repetitions = $repository->getAllBudgetLimitRepetitions($start, $end);
|
||||
@@ -300,7 +298,7 @@ class BudgetController extends Controller
|
||||
$cache->addProperty('budget');
|
||||
$cache->addProperty('period');
|
||||
if ($cache->has()) {
|
||||
//return Response::json($cache->get());
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
// loop over period, add by users range:
|
||||
$current = clone $start;
|
||||
|
@@ -64,7 +64,7 @@ class CategoryController extends Controller
|
||||
$cache->addProperty('all');
|
||||
$cache->addProperty('categories');
|
||||
if ($cache->has()) {
|
||||
//return Response::json($cache->get());
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
while ($start <= $end) {
|
||||
@@ -119,7 +119,7 @@ class CategoryController extends Controller
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('frontpage');
|
||||
if ($cache->has()) {
|
||||
//return Response::json($cache->get());
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
$categories = $repository->getCategories();
|
||||
$set = new Collection;
|
||||
@@ -169,7 +169,7 @@ class CategoryController extends Controller
|
||||
$cache->addProperty('multiYearCategory');
|
||||
|
||||
if ($cache->has()) {
|
||||
//return Response::json($cache->get());
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$entries = new Collection;
|
||||
@@ -237,7 +237,7 @@ class CategoryController extends Controller
|
||||
$cache->addProperty('category');
|
||||
$cache->addProperty('period');
|
||||
if ($cache->has()) {
|
||||
// return Response::json($cache->get());
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
/** @var CRI $repository */
|
||||
|
Reference in New Issue
Block a user