Made some things less complex.

This commit is contained in:
James Cole 2016-05-15 15:08:59 +02:00
parent b7b52707fb
commit 60d732067b
3 changed files with 46 additions and 55 deletions

View File

@ -161,10 +161,8 @@ class AccountController extends Controller
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
$types = config('firefly.accountTypesByIdentifier.' . $what);
$accounts = $repository->getAccountsByType($types);
/** @var Carbon $start */
$start = clone session('start', Carbon::now()->startOfMonth());
/** @var Carbon $end */
$end = clone session('end', Carbon::now()->endOfMonth());
$start = clone session('start', Carbon::now()->startOfMonth());
$end = clone session('end', Carbon::now()->endOfMonth());
$start->subDay();
$ids = $accounts->pluck('id')->toArray();
@ -183,32 +181,6 @@ class AccountController extends Controller
return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts'));
}
/**
* @param ARI $repository
* @param Account $account
* @param string $date
*
* @return View
*/
public function showWithDate(ARI $repository, Account $account, string $date)
{
$carbon = new Carbon($date);
$range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($carbon, $range);
$end = Navigation::endOfPeriod($carbon, $range);
$subTitle = $account->name;
$page = intval(Input::get('page'));
$pageSize = Preferences::get('transactionPageSize', 50)->data;
$offset = ($page - 1) * $pageSize;
$set = $repository->journalsInPeriod(new Collection([$account]), [], $start, $end);
$count = $set->count();
$subSet = $set->splice($offset, $pageSize);
$journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page);
$journals->setPath('categories/show/' . $account->id . '/' . $date);
return view('accounts.show_with_date', compact('category', 'journals', 'subTitle', 'carbon'));
}
/**
* @param ARI $repository
* @param Account $account
@ -251,6 +223,7 @@ class AccountController extends Controller
if ($cache->has()) {
$entries = $cache->get();
return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle'));
}
@ -272,6 +245,32 @@ class AccountController extends Controller
return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle'));
}
/**
* @param ARI $repository
* @param Account $account
* @param string $date
*
* @return View
*/
public function showWithDate(ARI $repository, Account $account, string $date)
{
$carbon = new Carbon($date);
$range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($carbon, $range);
$end = Navigation::endOfPeriod($carbon, $range);
$subTitle = $account->name;
$page = intval(Input::get('page'));
$pageSize = Preferences::get('transactionPageSize', 50)->data;
$offset = ($page - 1) * $pageSize;
$set = $repository->journalsInPeriod(new Collection([$account]), [], $start, $end);
$count = $set->count();
$subSet = $set->splice($offset, $pageSize);
$journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page);
$journals->setPath('categories/show/' . $account->id . '/' . $date);
return view('accounts.show_with_date', compact('category', 'journals', 'subTitle', 'carbon'));
}
/**
* @param AccountFormRequest $request
* @param ARI $repository

View File

@ -14,18 +14,15 @@ use Carbon\Carbon;
use ExpandedForm;
use FireflyIII\Events\TransactionJournalStored;
use FireflyIII\Events\TransactionJournalUpdated;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Requests\JournalFormRequest;
use FireflyIII\Http\Requests\MassDeleteJournalRequest;
use FireflyIII\Http\Requests\MassEditJournalRequest;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Log;
use Preferences;
use Response;
use Session;
@ -51,31 +48,30 @@ class TransactionController extends Controller
}
/**
* @param ARI $repository
* @param string $what
*
* @return \Illuminate\View\View
*/
public function create(ARI $repository, string $what = TransactionType::DEPOSIT)
public function create(string $what = TransactionType::DEPOSIT)
{
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$what = strtolower($what);
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
$assetAccounts = ExpandedForm::makeSelectList($repository->getAccountsByType(['Default account', 'Asset account']));
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
$piggyBanks = $piggyRepository->getPiggyBanksWithAmount();
$piggies = ExpandedForm::makeSelectListWithEmpty($piggyBanks);
$preFilled = Session::has('preFilled') ? session('preFilled') : [];
$subTitle = trans('form.add_new_' . $what);
$subTitleIcon = 'fa-plus';
$accountRepository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$what = strtolower($what);
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
$assetAccounts = ExpandedForm::makeSelectList($accountRepository->getAccountsByType(['Default account', 'Asset account']));
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
$piggyBanks = $piggyRepository->getPiggyBanksWithAmount();
$piggies = ExpandedForm::makeSelectListWithEmpty($piggyBanks);
$preFilled = Session::has('preFilled') ? session('preFilled') : [];
$subTitle = trans('form.add_new_' . $what);
$subTitleIcon = 'fa-plus';
Session::put('preFilled', $preFilled);
// put previous url in session if not redirect from store (not "create another").
if (session('transactions.create.fromStore') !== true) {
$url = URL::previous();
Log::debug('TransactionController::create. Previous URL is ' . $url);
Session::put('transactions.create.url', $url);
}
Session::forget('transactions.create.fromStore');
@ -388,7 +384,6 @@ class TransactionController extends Controller
* @param JournalRepositoryInterface $repository
*
* @return View
* @throws FireflyException
*/
public function show(TransactionJournal $journal, JournalRepositoryInterface $repository)
{
@ -410,12 +405,11 @@ class TransactionController extends Controller
* @param JournalFormRequest $request
* @param JournalRepositoryInterface $repository
*
* @param AttachmentHelperInterface $att
*
* @return \Illuminate\Http\RedirectResponse
*/
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att)
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository)
{
$att = app('FireflyIII\Helpers\Attachments\AttachmentHelperInterface');
$doSplit = intval($request->get('split_journal')) === 1;
$journalData = $request->getJournalData();
@ -487,8 +481,6 @@ class TransactionController extends Controller
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, AttachmentHelperInterface $att, TransactionJournal $journal)
{
$journalData = $request->getJournalData();
Log::debug('Will update journal ', $journal->toArray());
Log::debug('Update related data ', $journalData);
$repository->update($journal, $journalData);
// save attachments:

View File

@ -114,7 +114,7 @@ class CategoryRepository implements CategoryRepositoryInterface
$firstJournalQuery->whereIn('t.account_id', $ids);
}
$firstJournal = $firstJournalQuery->first(['transaction_journals.*']);
$firstJournal = $firstJournalQuery->first(['transaction_journals.date']);
if ($firstJournal) {
$first = $firstJournal->date;
@ -131,7 +131,7 @@ class CategoryRepository implements CategoryRepositoryInterface
$firstTransactionQuery->whereIn('transactions.account_id', $ids);
}
$firstTransaction = $firstTransactionQuery->first(['transaction_journals.*']);
$firstTransaction = $firstTransactionQuery->first(['transaction_journals.date']);
if (!is_null($firstTransaction) && ((!is_null($first) && $firstTransaction->date < $first) || is_null($first))) {
$first = new Carbon($firstTransaction->date);