mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-18 15:39:50 +00:00
Various small changes.
This commit is contained in:
@@ -13,6 +13,10 @@ namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Amount;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Navigation;
|
||||
use Preferences;
|
||||
@@ -26,6 +30,33 @@ use Session;
|
||||
class JavascriptController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository)
|
||||
{
|
||||
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$preference = Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'));
|
||||
$default = $currencyRepository->findByCode($preference->data);
|
||||
|
||||
$data = ['accounts' => [],];
|
||||
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$accountId = $account->id;
|
||||
$currency = intval($account->getMeta('currency_id'));
|
||||
$currency = $currency === 0 ? $default->id : $currency;
|
||||
$entry = ['preferredCurrency' => $currency];
|
||||
$data['accounts'][$accountId] = $entry;
|
||||
}
|
||||
|
||||
|
||||
return response()
|
||||
->view('javascript.accounts', $data, 200)
|
||||
->header('Content-Type', 'text/javascript');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
|
||||
@@ -162,9 +162,12 @@ class SingleController extends Controller
|
||||
*/
|
||||
public function delete(TransactionJournal $journal)
|
||||
{
|
||||
// Covered by another controller's tests
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($this->isOpeningBalance($journal)) {
|
||||
return $this->redirectToAccount($journal);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
||||
$subTitle = trans('firefly.delete_' . $what, ['description' => $journal->description]);
|
||||
@@ -187,9 +190,11 @@ class SingleController extends Controller
|
||||
*/
|
||||
public function destroy(JournalRepositoryInterface $repository, TransactionJournal $transactionJournal)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($this->isOpeningBalance($transactionJournal)) {
|
||||
return $this->redirectToAccount($transactionJournal);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
$type = TransactionJournal::transactionTypeStr($transactionJournal);
|
||||
Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => e($transactionJournal->description)])));
|
||||
|
||||
@@ -207,9 +212,11 @@ class SingleController extends Controller
|
||||
*/
|
||||
public function edit(TransactionJournal $journal)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($this->isOpeningBalance($journal)) {
|
||||
return $this->redirectToAccount($journal);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
@@ -313,22 +320,20 @@ class SingleController extends Controller
|
||||
Session::flash('success', strval(trans('firefly.stored_journal', ['description' => e($journal->description)])));
|
||||
Preferences::mark();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($createAnother === true) {
|
||||
// set value so create routine will not overwrite URL:
|
||||
Session::put('transactions.create.fromStore', true);
|
||||
|
||||
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
|
||||
}
|
||||
|
||||
if ($doSplit === true) {
|
||||
// redirect to edit screen:
|
||||
return redirect(route('transactions.split.edit', [$journal->id]));
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// redirect to previous URL.
|
||||
return redirect($this->getPreviousUri('transactions.create.uri'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -340,9 +345,11 @@ class SingleController extends Controller
|
||||
*/
|
||||
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($this->isOpeningBalance($journal)) {
|
||||
return $this->redirectToAccount($journal);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$data = $request->getJournalData();
|
||||
$journal = $repository->update($journal, $data);
|
||||
@@ -350,14 +357,14 @@ class SingleController extends Controller
|
||||
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
||||
$this->attachments->saveAttachmentsForModel($journal, $files);
|
||||
|
||||
// flash errors
|
||||
// @codeCoverageIgnoreStart
|
||||
if (count($this->attachments->getErrors()->get('attachments')) > 0) {
|
||||
Session::flash('error', $this->attachments->getErrors()->get('attachments'));
|
||||
}
|
||||
// flash messages
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
Session::flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
event(new UpdatedTransactionJournal($journal));
|
||||
// update, get events by date and sort DESC
|
||||
@@ -366,15 +373,13 @@ class SingleController extends Controller
|
||||
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['description'])])));
|
||||
Preferences::mark();
|
||||
|
||||
// if wishes to split:
|
||||
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (intval($request->get('return_to_edit')) === 1) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
Session::put('transactions.edit.fromUpdate', true);
|
||||
|
||||
return redirect(route('transactions.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// redirect to previous URL.
|
||||
return redirect($this->getPreviousUri('transactions.edit.uri'));
|
||||
|
||||
@@ -141,25 +141,27 @@ class SplitController extends Controller
|
||||
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
||||
// save attachments:
|
||||
$this->attachments->saveAttachmentsForModel($journal, $files);
|
||||
|
||||
event(new UpdatedTransactionJournal($journal));
|
||||
// update, get events by date and sort DESC
|
||||
|
||||
// flash messages
|
||||
// @codeCoverageIgnoreStart
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
Session::flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$type = strtolower(TransactionJournal::transactionTypeStr($journal));
|
||||
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['journal_description'])])));
|
||||
Preferences::mark();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (intval($request->get('return_to_edit')) === 1) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
Session::put('transactions.edit-split.fromUpdate', true);
|
||||
|
||||
return redirect(route('transactions.split.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// redirect to previous URL.
|
||||
return redirect($this->getPreviousUri('transactions.edit-split.uri'));
|
||||
|
||||
Reference in New Issue
Block a user