mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 06:51:08 +00:00
@@ -88,21 +88,24 @@ class BulkController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param BulkEditJournalRequest $request
|
* @param BulkEditJournalRequest $request
|
||||||
* @param JournalRepositoryInterface $repository
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function update(BulkEditJournalRequest $request, JournalRepositoryInterface $repository)
|
public function update(BulkEditJournalRequest $request)
|
||||||
{
|
{
|
||||||
$journalIds = $request->get('journals');
|
$journalIds = $request->get('journals');
|
||||||
|
$journalIds = \is_array($journalIds) ? $journalIds : [];
|
||||||
$ignoreCategory = (int)$request->get('ignore_category') === 1;
|
$ignoreCategory = (int)$request->get('ignore_category') === 1;
|
||||||
$ignoreBudget = (int)$request->get('ignore_budget') === 1;
|
$ignoreBudget = (int)$request->get('ignore_budget') === 1;
|
||||||
$ignoreTags = (int)$request->get('ignore_tags') === 1;
|
$ignoreTags = (int)$request->get('ignore_tags') === 1;
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
if (\is_array($journalIds)) {
|
|
||||||
foreach ($journalIds as $journalId) {
|
foreach ($journalIds as $journalId) {
|
||||||
$journal = $repository->find((int)$journalId);
|
$journal = $this->repository->findNull((int)$journalId);
|
||||||
|
if (null === $journal) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$count++;
|
$count++;
|
||||||
Log::debug(sprintf('Found journal #%d', $journal->id));
|
Log::debug(sprintf('Found journal #%d', $journal->id));
|
||||||
|
|
||||||
@@ -110,17 +113,19 @@ class BulkController extends Controller
|
|||||||
if ($ignoreCategory === false) {
|
if ($ignoreCategory === false) {
|
||||||
Log::debug(sprintf('Set category to %s', $request->string('category')));
|
Log::debug(sprintf('Set category to %s', $request->string('category')));
|
||||||
|
|
||||||
$repository->updateCategory($journal, $request->string('category'));
|
$this->repository->updateCategory($journal, $request->string('category'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// update budget if not told to ignore (and is withdrawal)
|
// update budget if not told to ignore (and is withdrawal)
|
||||||
if ($ignoreBudget === false) {
|
if ($ignoreBudget === false) {
|
||||||
Log::debug(sprintf('Set budget to %d', $request->integer('budget_id')));
|
Log::debug(sprintf('Set budget to %d', $request->integer('budget_id')));
|
||||||
$repository->updateBudget($journal, $request->integer('budget_id'));
|
$this->repository->updateBudget($journal, $request->integer('budget_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update tags:
|
||||||
if ($ignoreTags === false) {
|
if ($ignoreTags === false) {
|
||||||
Log::debug(sprintf('Set tags to %s', $request->string('budget_id')));
|
Log::debug(sprintf('Set tags to %s', $request->string('budget_id')));
|
||||||
$repository->updateTags($journal, ['tags' => explode(',', $request->string('tags'))]);
|
$this->repository->updateTags($journal, ['tags' => explode(',', $request->string('tags'))]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,5 +135,4 @@ class BulkController extends Controller
|
|||||||
// redirect to previous URL:
|
// redirect to previous URL:
|
||||||
return redirect($this->getPreviousUri('transactions.bulk-edit.uri'));
|
return redirect($this->getPreviousUri('transactions.bulk-edit.uri'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -97,27 +97,14 @@ class ConvertController extends Controller
|
|||||||
$destinationAccount = $this->repository->getJournalDestinationAccounts($journal)->first();
|
$destinationAccount = $this->repository->getJournalDestinationAccounts($journal)->first();
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'transactions.convert',
|
'transactions.convert', compact(
|
||||||
compact(
|
'sourceType', 'destinationType', 'journal', 'positiveAmount', 'sourceAccount', 'destinationAccount', 'sourceType', 'subTitle', 'subTitleIcon'
|
||||||
'sourceType',
|
|
||||||
'destinationType',
|
|
||||||
'journal',
|
|
||||||
'positiveAmount',
|
|
||||||
'sourceAccount',
|
|
||||||
'destinationAccount',
|
|
||||||
'sourceType',
|
|
||||||
'subTitle',
|
|
||||||
'subTitleIcon'
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// convert withdrawal to deposit requires a new source account ()
|
|
||||||
// or to transfer requires
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param JournalRepositoryInterface $repository
|
|
||||||
* @param TransactionType $destinationType
|
* @param TransactionType $destinationType
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
@@ -126,7 +113,7 @@ class ConvertController extends Controller
|
|||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function postIndex(Request $request, JournalRepositoryInterface $repository, TransactionType $destinationType, TransactionJournal $journal)
|
public function postIndex(Request $request, TransactionType $destinationType, TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
if ($this->isOpeningBalance($journal)) {
|
if ($this->isOpeningBalance($journal)) {
|
||||||
@@ -153,7 +140,7 @@ class ConvertController extends Controller
|
|||||||
$destination = $this->getDestinationAccount($journal, $destinationType, $data);
|
$destination = $this->getDestinationAccount($journal, $destinationType, $data);
|
||||||
|
|
||||||
// update the journal:
|
// update the journal:
|
||||||
$errors = $repository->convert($journal, $destinationType, $source, $destination);
|
$errors = $this->repository->convert($journal, $destinationType, $source, $destination);
|
||||||
|
|
||||||
if ($errors->count() > 0) {
|
if ($errors->count() > 0) {
|
||||||
return redirect(route('transactions.convert.index', [strtolower($destinationType->type), $journal->id]))->withErrors($errors)->withInput();
|
return redirect(route('transactions.convert.index', [strtolower($destinationType->type), $journal->id]))->withErrors($errors)->withInput();
|
||||||
|
@@ -27,7 +27,6 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
|||||||
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Http\Requests\MassDeleteJournalRequest;
|
use FireflyIII\Http\Requests\MassDeleteJournalRequest;
|
||||||
use FireflyIII\Http\Requests\MassEditBulkJournalRequest;
|
|
||||||
use FireflyIII\Http\Requests\MassEditJournalRequest;
|
use FireflyIII\Http\Requests\MassEditJournalRequest;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
|
@@ -60,6 +60,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function convert(TransactionJournal $journal, TransactionType $type, Account $source, Account $destination): MessageBag
|
public function convert(TransactionJournal $journal, TransactionType $type, Account $source, Account $destination): MessageBag
|
||||||
{
|
{
|
||||||
|
if ($source->id === $destination->id || null === $source->id || null === $destination->id) {
|
||||||
// default message bag that shows errors for everything.
|
// default message bag that shows errors for everything.
|
||||||
$messages = new MessageBag;
|
$messages = new MessageBag;
|
||||||
$messages->add('source_account_revenue', trans('firefly.invalid_convert_selection'));
|
$messages->add('source_account_revenue', trans('firefly.invalid_convert_selection'));
|
||||||
@@ -67,12 +68,22 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
$messages->add('destination_account_expense', trans('firefly.invalid_convert_selection'));
|
$messages->add('destination_account_expense', trans('firefly.invalid_convert_selection'));
|
||||||
$messages->add('source_account_asset', trans('firefly.invalid_convert_selection'));
|
$messages->add('source_account_asset', trans('firefly.invalid_convert_selection'));
|
||||||
|
|
||||||
if ($source->id === $destination->id || null === $source->id || null === $destination->id) {
|
|
||||||
return $messages;
|
return $messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sourceTransaction = $journal->transactions()->where('amount', '<', 0)->first();
|
$sourceTransaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||||
$destinationTransaction = $journal->transactions()->where('amount', '>', 0)->first();
|
$destinationTransaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
|
if (null === $sourceTransaction || null === $destinationTransaction) {
|
||||||
|
// default message bag that shows errors for everything.
|
||||||
|
|
||||||
|
$messages = new MessageBag;
|
||||||
|
$messages->add('source_account_revenue', trans('firefly.source_or_dest_invalid'));
|
||||||
|
$messages->add('destination_account_asset', trans('firefly.source_or_dest_invalid'));
|
||||||
|
$messages->add('destination_account_expense', trans('firefly.source_or_dest_invalid'));
|
||||||
|
$messages->add('source_account_asset', trans('firefly.source_or_dest_invalid'));
|
||||||
|
|
||||||
|
return $messages;
|
||||||
|
}
|
||||||
$sourceTransaction->account_id = $source->id;
|
$sourceTransaction->account_id = $source->id;
|
||||||
$sourceTransaction->save();
|
$sourceTransaction->save();
|
||||||
$destinationTransaction->account_id = $destination->id;
|
$destinationTransaction->account_id = $destination->id;
|
||||||
@@ -83,6 +94,10 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
// if journal is a transfer now, remove budget:
|
// if journal is a transfer now, remove budget:
|
||||||
if (TransactionType::TRANSFER === $type->type) {
|
if (TransactionType::TRANSFER === $type->type) {
|
||||||
$journal->budgets()->detach();
|
$journal->budgets()->detach();
|
||||||
|
// also from transactions:
|
||||||
|
foreach ($journal->transactions as $transaction) {
|
||||||
|
$transaction->budgets()->detach();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
@@ -137,8 +152,6 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @param int $journalId
|
* @param int $journalId
|
||||||
*
|
*
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* @return TransactionJournal|null
|
* @return TransactionJournal|null
|
||||||
*/
|
*/
|
||||||
public function findNull(int $journalId): ?TransactionJournal
|
public function findNull(int $journalId): ?TransactionJournal
|
||||||
|
@@ -78,7 +78,6 @@ interface JournalRepositoryInterface
|
|||||||
* Find a specific journal.
|
* Find a specific journal.
|
||||||
*
|
*
|
||||||
* @param int $journalId
|
* @param int $journalId
|
||||||
* @deprecated
|
|
||||||
*
|
*
|
||||||
* @return TransactionJournal|null
|
* @return TransactionJournal|null
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user