mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Improvements for #616 and others.
This commit is contained in:
@@ -152,6 +152,18 @@ class LinkController extends Controller
|
||||
return view('admin.link.index', compact('subTitle', 'subTitleIcon', 'linkTypes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function show(LinkType $linkType)
|
||||
{
|
||||
$subTitle = trans('firefly.overview_for_link', ['name' => $linkType->name]);
|
||||
$subTitleIcon = 'fa-link';
|
||||
$links = $linkType->transactionJournalLinks()->get();
|
||||
|
||||
return view('admin.link.show', compact('subTitle', 'subTitleIcon', 'linkType', 'links'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LinkTypeFormRequest $request
|
||||
* @param LinkTypeRepositoryInterface $repository
|
||||
|
||||
@@ -13,17 +13,83 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers\Transaction;
|
||||
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\JournalLinkRequest;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionJournalLink;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Session;
|
||||
use URL;
|
||||
use View;
|
||||
|
||||
class LinkController
|
||||
/**
|
||||
* Class LinkController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Transaction
|
||||
*/
|
||||
class LinkController extends Controller
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// some useful repositories:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
View::share('title', trans('firefly.transactions'));
|
||||
View::share('mainTitleIcon', 'fa-repeat');
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function delete(TransactionJournalLink $link)
|
||||
{
|
||||
$subTitleIcon = 'fa-link';
|
||||
$subTitle = trans('breadcrumbs.delete_journal_link');
|
||||
$this->rememberPreviousUri('journal_links.delete.uri');
|
||||
|
||||
return view('transactions.links.delete', compact('link', 'subTitle', 'subTitleIcon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LinkTypeRepositoryInterface $repository
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function destroy(LinkTypeRepositoryInterface $repository, TransactionJournalLink $link)
|
||||
{
|
||||
$repository->destroyLink($link);
|
||||
|
||||
Session::flash('success', strval(trans('firefly.deleted_link')));
|
||||
Preferences::mark();
|
||||
|
||||
return redirect(strval(session('journal_links.delete.uri')));
|
||||
}
|
||||
|
||||
public function switch(LinkTypeRepositoryInterface $repository, TransactionJournalLink $link) {
|
||||
|
||||
$repository->switchLink($link);
|
||||
|
||||
return redirect(URL::previous());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param JournalLinkRequest $request
|
||||
* @param LinkTypeRepositoryInterface $repository
|
||||
|
||||
@@ -28,6 +28,7 @@ use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionJournalLink;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -167,6 +168,13 @@ Breadcrumbs::register(
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'admin.links.show', function (BreadCrumbGenerator $breadcrumbs, LinkType $linkType) {
|
||||
$breadcrumbs->parent('admin.links.index');
|
||||
$breadcrumbs->push(trans('firefly.overview_for_link', [$linkType->name]), route('admin.links.show', [$linkType->id]));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'admin.links.edit', function (BreadCrumbGenerator $breadcrumbs, LinkType $linkType) {
|
||||
$breadcrumbs->parent('admin.links.index');
|
||||
@@ -181,6 +189,14 @@ Breadcrumbs::register(
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'transactions.link.delete', function (BreadCrumbGenerator $breadcrumbs, TransactionJournalLink $link) {
|
||||
$breadcrumbs->parent('home');
|
||||
$breadcrumbs->push(trans('breadcrumbs.delete_journal_link'), route('transactions.link.delete', $link->id));
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* ATTACHMENTS
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace FireflyIII\Models;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* @property int $journalCount
|
||||
@@ -36,7 +37,25 @@ class LinkType extends Model
|
||||
'editable' => 'boolean',
|
||||
];
|
||||
|
||||
public function transactionJournalLinks() {
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public static function routeBinder($value)
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$model = self::where('id', $value)->first();
|
||||
if (!is_null($model)) {
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
public function transactionJournalLinks()
|
||||
{
|
||||
return $this->hasMany(TransactionJournalLink::class);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace FireflyIII\Models;
|
||||
use Crypt;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class TransactionJournalLink
|
||||
@@ -26,6 +27,28 @@ class TransactionJournalLink extends Model
|
||||
{
|
||||
protected $table = 'journal_links';
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public static function routeBinder($value)
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$model = self::where('journal_links.id', $value)
|
||||
->leftJoin('transaction_journals as t_a', 't_a.id', '=', 'source_id')
|
||||
->leftJoin('transaction_journals as t_b', 't_b.id', '=', 'destination_id')
|
||||
->where('t_a.user_id', auth()->user()->id)
|
||||
->where('t_b.user_id', auth()->user()->id)
|
||||
->first(['journal_links.*']);
|
||||
if (!is_null($model)) {
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
||||
@@ -54,6 +54,18 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroyLink(TransactionJournalLink $link): bool
|
||||
{
|
||||
$link->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
@@ -135,6 +147,21 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
return $linkType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function switchLink(TransactionJournalLink $link): bool
|
||||
{
|
||||
$source = $link->source_id;
|
||||
$link->source_id = $link->destination_id;
|
||||
$link->destination_id = $source;
|
||||
$link->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LinkType $linkType
|
||||
* @param array $data
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace FireflyIII\Repositories\LinkType;
|
||||
|
||||
use FireflyIII\Models\LinkType;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionJournalLink;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
@@ -45,6 +46,20 @@ interface LinkTypeRepositoryInterface
|
||||
*/
|
||||
public function find(int $id): LinkType;
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroyLink(TransactionJournalLink $link):bool;
|
||||
|
||||
/**
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function switchLink(TransactionJournalLink $link): bool;
|
||||
|
||||
/**
|
||||
* Check if link exists between journals.
|
||||
*
|
||||
|
||||
@@ -300,6 +300,7 @@ class Amount
|
||||
public function transactionAmount(TransactionModel $transaction, bool $coloured = true): string
|
||||
{
|
||||
$amount = bcmul(app('steam')->positive(strval($transaction->transaction_amount)), '-1');
|
||||
|
||||
$format = '%s';
|
||||
|
||||
if ($transaction->transaction_type_type === TransactionType::DEPOSIT) {
|
||||
@@ -322,7 +323,11 @@ class Amount
|
||||
|
||||
|
||||
if (!is_null($transaction->transaction_foreign_amount)) {
|
||||
$amount = strval($transaction->transaction_foreign_amount);
|
||||
$amount = bcmul(app('steam')->positive(strval($transaction->transaction_foreign_amount)), '-1');
|
||||
if ($transaction->transaction_type_type === TransactionType::DEPOSIT) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
|
||||
|
||||
if ($transaction->transaction_type_type === TransactionType::TRANSFER) {
|
||||
$amount = app('steam')->positive($amount);
|
||||
|
||||
@@ -46,6 +46,7 @@ class AmountFormat extends Twig_Extension
|
||||
{
|
||||
return [
|
||||
$this->formatAmountByAccount(),
|
||||
$this->formatAmountBySymbol(),
|
||||
$this->transactionAmount(),
|
||||
$this->journalAmount(),
|
||||
$this->formatDestinationAfter(),
|
||||
@@ -108,6 +109,26 @@ class AmountFormat extends Twig_Extension
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will format the amount by the currency related to the given account.
|
||||
*
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function formatAmountBySymbol(): Twig_SimpleFunction
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatAmountBySymbol', function (string $amount, string $symbol, int $decimalPlaces = 2, bool $coloured = true): string {
|
||||
|
||||
$currency = new TransactionCurrency;
|
||||
$currency->symbol = $symbol;
|
||||
$currency->decimal_places = $decimalPlaces;
|
||||
return app('amount')->formatAnything($currency, $amount, $coloured);
|
||||
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will format the amount by the currency related to the given account.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user