mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand services.
This commit is contained in:
parent
9f37bf5875
commit
81221038f0
@ -80,7 +80,7 @@ class AccountController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function delete(Account $account)
|
public function delete(Account $account)
|
||||||
{
|
{
|
||||||
$this->repository->destroy($account, new Account);
|
$this->repository->destroy($account, null);
|
||||||
|
|
||||||
return response()->json([], 204);
|
return response()->json([], 204);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ use FireflyIII\Models\Transaction;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Services\Internal\JournalUpdateService;
|
use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
||||||
use FireflyIII\Transformers\TransactionTransformer;
|
use FireflyIII\Transformers\TransactionTransformer;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@ -91,7 +91,6 @@ class TransactionController extends Controller
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
* @throws \FireflyIII\Exceptions\FireflyException
|
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
@ -152,7 +151,6 @@ class TransactionController extends Controller
|
|||||||
$include = $request->get('include') ?? '';
|
$include = $request->get('include') ?? '';
|
||||||
$manager->parseIncludes($include);
|
$manager->parseIncludes($include);
|
||||||
|
|
||||||
// needs a lot of extra data to match the journal collector. Or just expand that one.
|
|
||||||
// collect transactions using the journal collector
|
// collect transactions using the journal collector
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setUser(auth()->user());
|
$collector->setUser(auth()->user());
|
||||||
|
@ -139,7 +139,7 @@ class AccountController extends Controller
|
|||||||
$type = $account->accountType->type;
|
$type = $account->accountType->type;
|
||||||
$typeName = config('firefly.shortNamesByFullName.' . $type);
|
$typeName = config('firefly.shortNamesByFullName.' . $type);
|
||||||
$name = $account->name;
|
$name = $account->name;
|
||||||
$moveTo = $this->repository->find(intval($request->get('move_account_before_delete')));
|
$moveTo = $this->repository->findNull(intval($request->get('move_account_before_delete')));
|
||||||
|
|
||||||
$this->repository->destroy($account, $moveTo);
|
$this->repository->destroy($account, $moveTo);
|
||||||
|
|
||||||
|
@ -334,17 +334,44 @@ class SingleController extends Controller
|
|||||||
* @param JournalRepositoryInterface $repository
|
* @param JournalRepositoryInterface $repository
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
* @throws \FireflyIII\Exceptions\FireflyException
|
||||||
*/
|
*/
|
||||||
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository)
|
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$doSplit = 1 === intval($request->get('split_journal'));
|
$doSplit = 1 === intval($request->get('split_journal'));
|
||||||
$createAnother = 1 === intval($request->get('create_another'));
|
$createAnother = 1 === intval($request->get('create_another'));
|
||||||
$data = $request->getJournalData();
|
$data = $request->getJournalData();
|
||||||
|
$data['user'] = auth()->user()->id;
|
||||||
|
$data['bill_id'] = null;
|
||||||
|
$data['bill_name'] = null;
|
||||||
|
$data['piggy_bank_name'] = null;
|
||||||
|
$data['transactions'] = [
|
||||||
|
[
|
||||||
|
'amount' => $data['amount'],
|
||||||
|
'currency_id' => $data['currency_id'],
|
||||||
|
'description' => null,
|
||||||
|
'reconciled' => false,
|
||||||
|
'identifier' => 0,
|
||||||
|
'currency_code' => null,
|
||||||
|
'budget_id' => $data['budget_id'],
|
||||||
|
'budget_name' => null,
|
||||||
|
'category_id' => null,
|
||||||
|
'category_name' => $data['category'],
|
||||||
|
'source_id' => (int)$data['source_account_id'],
|
||||||
|
'source_name' => $data['source_account_name'],
|
||||||
|
'destination_id' => (int)$data['destination_account_id'],
|
||||||
|
'destination_name' => $data['destination_account_name'],
|
||||||
|
'foreign_currency_id' => null,
|
||||||
|
'foreign_currency_code' => null,
|
||||||
|
'foreign_amount' => null,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
var_dump($data);exit;
|
||||||
// todo call factory instead of repository
|
// todo call factory instead of repository
|
||||||
|
/** @var TransactionJournalFactory $factory */
|
||||||
$factory = app(TransactionJournalFactory::class);
|
$factory = app(TransactionJournalFactory::class);
|
||||||
$factory->setUser(auth()->user());
|
$factory->setUser(auth()->user());
|
||||||
$journal = $repository->store($data);
|
$journal = $factory->create($data);
|
||||||
//$journal = $repository->store($data);
|
//$journal = $repository->store($data);
|
||||||
if (null === $journal->id) {
|
if (null === $journal->id) {
|
||||||
// error!
|
// error!
|
||||||
|
@ -47,7 +47,7 @@ class JournalFormRequest extends Request
|
|||||||
public function getJournalData()
|
public function getJournalData()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'what' => $this->get('what'), // type. can be 'deposit', 'withdrawal' or 'transfer'
|
'type' => $this->get('what'), // type. can be 'deposit', 'withdrawal' or 'transfer'
|
||||||
'date' => $this->date('date'),
|
'date' => $this->date('date'),
|
||||||
'tags' => explode(',', $this->string('tags')),
|
'tags' => explode(',', $this->string('tags')),
|
||||||
'currency_id' => $this->integer('amount_currency_id_amount'),
|
'currency_id' => $this->integer('amount_currency_id_amount'),
|
||||||
|
@ -122,20 +122,7 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
protected function registerDeleteEvents()
|
protected function registerDeleteEvents()
|
||||||
{
|
{
|
||||||
Account::deleted(
|
|
||||||
function (Account $account) {
|
|
||||||
Log::debug('Now trigger account delete response #' . $account->id);
|
|
||||||
/** @var Transaction $transaction */
|
|
||||||
foreach ($account->transactions()->get() as $transaction) {
|
|
||||||
Log::debug('Now at transaction #' . $transaction->id);
|
|
||||||
$journal = $transaction->transactionJournal()->first();
|
|
||||||
if (null !== $journal) {
|
|
||||||
Log::debug('Call for deletion of journal #' . $journal->id);
|
|
||||||
$journal->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
TransactionJournal::deleted(
|
TransactionJournal::deleted(
|
||||||
function (TransactionJournal $journal) {
|
function (TransactionJournal $journal) {
|
||||||
|
@ -35,6 +35,7 @@ use FireflyIII\Models\Transaction;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
|
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Log;
|
use Log;
|
||||||
use Validator;
|
use Validator;
|
||||||
@ -82,12 +83,9 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function destroy(Account $account, Account $moveTo): bool
|
public function destroy(Account $account, Account $moveTo): bool
|
||||||
{
|
{
|
||||||
if (null !== $moveTo->id) {
|
/** @var AccountDestroyService $service */
|
||||||
DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
|
$service = app(AccountDestroyService::class);
|
||||||
}
|
$service->destroy($account, $moveTo);
|
||||||
if (null !== $account) {
|
|
||||||
$account->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
68
app/Services/Internal/Destroy/AccountDestroyService.php
Normal file
68
app/Services/Internal/Destroy/AccountDestroyService.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* AccountDestroyService.php
|
||||||
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Services\Internal\Destroy;
|
||||||
|
|
||||||
|
use DB;
|
||||||
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AccountDestroyService
|
||||||
|
*/
|
||||||
|
class AccountDestroyService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Account $account
|
||||||
|
* @param Account|null $moveTo
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function destroy(Account $account, ?Account $moveTo): bool
|
||||||
|
{
|
||||||
|
if (null !== $moveTo) {
|
||||||
|
DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug('Now trigger account delete response #' . $account->id);
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($account->transactions()->get() as $transaction) {
|
||||||
|
Log::debug('Now at transaction #' . $transaction->id);
|
||||||
|
$journal = $transaction->transactionJournal()->first();
|
||||||
|
if (null !== $journal) {
|
||||||
|
Log::debug('Call for deletion of journal #' . $journal->id);
|
||||||
|
$journal->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$account->delete();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// don't care
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace FireflyIII\Services\Internal;
|
namespace FireflyIII\Services\Internal\Update;
|
||||||
|
|
||||||
use FireflyIII\Factory\BillFactory;
|
use FireflyIII\Factory\BillFactory;
|
||||||
use FireflyIII\Factory\TagFactory;
|
use FireflyIII\Factory\TagFactory;
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace FireflyIII\Services\Internal;
|
namespace FireflyIII\Services\Internal\Update;
|
||||||
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Factory\AccountFactory;
|
use FireflyIII\Factory\AccountFactory;
|
Loading…
Reference in New Issue
Block a user