mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-06 12:45:30 +00:00
Fix #3435
This commit is contained in:
@@ -29,6 +29,8 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\RecurrenceFormRequest;
|
||||
use FireflyIII\Models\RecurrenceRepetition;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
@@ -75,6 +77,97 @@ class CreateController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
public function createFromJournal(Request $request, TransactionJournal $journal)
|
||||
{
|
||||
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$tomorrow = new Carbon;
|
||||
$oldRepetitionType = $request->old('repetition_type');
|
||||
$tomorrow->addDay();
|
||||
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (true !== session('recurring.create.fromStore')) {
|
||||
$this->rememberPreviousUri('recurring.create.uri');
|
||||
}
|
||||
$request->session()->forget('recurring.create.fromStore');
|
||||
$repetitionEnds = [
|
||||
'forever' => (string) trans('firefly.repeat_forever'),
|
||||
'until_date' => (string) trans('firefly.repeat_until_date'),
|
||||
'times' => (string) trans('firefly.repeat_times'),
|
||||
];
|
||||
$weekendResponses = [
|
||||
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string) trans('firefly.do_nothing'),
|
||||
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string) trans('firefly.skip_transaction'),
|
||||
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string) trans('firefly.jump_to_friday'),
|
||||
RecurrenceRepetition::WEEKEND_TO_MONDAY => (string) trans('firefly.jump_to_monday'),
|
||||
];
|
||||
|
||||
/** @var Transaction $source */
|
||||
/** @var Transaction $dest */
|
||||
|
||||
// fill prefilled with journal info
|
||||
$type = strtolower($journal->transactionType->type);
|
||||
|
||||
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$dest = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$category = $journal->categories()->first() ? $journal->categories()->first()->name : '';
|
||||
$budget = $journal->budgets()->first() ? $journal->budgets()->first()->id : 0;
|
||||
$hasOldInput = null !== $request->old('_token'); // flash some data
|
||||
$preFilled = [];
|
||||
if (true === $hasOldInput) {
|
||||
$preFilled = [
|
||||
'title' => $request->old('title'),
|
||||
'transaction_description' => $request->old('description'),
|
||||
'transaction_currency_id' => $request->old('transaction_currency_id'),
|
||||
'amount' => $request->old('amount'),
|
||||
'foreign_currency_id' => $request->old('foreign_currency_id'),
|
||||
'foreign_amount' => $request->old('foreign_amount'),
|
||||
'source_id' => $request->old('source_id'),
|
||||
'deposit_source_id' => $request->old('deposit_source_id'),
|
||||
'destination_id' => $request->old('destination_id'),
|
||||
'withdrawal_destination_id' => $request->old('withdrawal_destination_id'),
|
||||
'first_date' => $request->old('first_date'),
|
||||
'transaction_type' => $request->old('transaction_type'),
|
||||
'category' => $request->old('category'),
|
||||
'budget_id' => $request->old('budget_id'),
|
||||
'active' => (bool) $request->old('active'),
|
||||
'apply_rules' => (bool) $request->old('apply_rules'),
|
||||
];
|
||||
}
|
||||
if (false === $hasOldInput) {
|
||||
$preFilled = [
|
||||
'title' => $journal->description,
|
||||
'transaction_description' => $journal->description,
|
||||
'transaction_currency_id' => $journal->transaction_currency_id,
|
||||
'amount' => $dest->amount,
|
||||
'foreign_currency_id' => $dest->foreign_currency_id,
|
||||
'foreign_amount' => $dest->foreign_amount,
|
||||
'source_id' => $source->account_id,
|
||||
'deposit_source_id' => $source->account_id,
|
||||
'destination_id' => $dest->account_id,
|
||||
'withdrawal_destination_id' => $dest->account_id,
|
||||
'first_date' => $tomorrow->format('Y-m-d'),
|
||||
'transaction_type' => $type,
|
||||
'category' => $category,
|
||||
'budget_id' => $budget,
|
||||
'active' => true,
|
||||
'apply_rules' => true,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$request->session()->flash('preFilled', $preFilled);
|
||||
|
||||
return view(
|
||||
'recurring.create',
|
||||
compact('tomorrow', 'oldRepetitionType', 'weekendResponses', 'preFilled', 'repetitionEnds', 'defaultCurrency', 'budgets')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new recurring transaction.
|
||||
*
|
||||
|
Reference in New Issue
Block a user