Various fixes and extensions.

This commit is contained in:
James Cole
2021-07-18 14:51:30 +02:00
parent fb17da3f56
commit 6d971e86b1
13 changed files with 233 additions and 84 deletions

View File

@@ -107,18 +107,18 @@ class IndexController extends Controller
'object_group_title' => $array['object_group_title'],
'bills' => [],
];
// expected today? default:
$array['next_expected_match_diff'] = trans('firefly.not_expected_period');
$nextExpectedMatch = new Carbon($array['next_expected_match']);
if ($nextExpectedMatch->isToday()) {
$array['next_expected_match_diff'] = trans('firefly.today');
}
$current = $array['pay_dates'][0] ?? null;
if (null !== $current && !$nextExpectedMatch->isToday()) {
$currentExpectedMatch = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
$array['next_expected_match_diff'] = $currentExpectedMatch->diffForHumans(today(), Carbon::DIFF_RELATIVE_TO_NOW);
}
// var_dump($array);exit;
// // expected today? default:
// $array['next_expected_match_diff'] = trans('firefly.not_expected_period');
// $nextExpectedMatch = new Carbon($array['next_expected_match']);
// if ($nextExpectedMatch->isToday()) {
// $array['next_expected_match_diff'] = trans('firefly.today');
// }
// $current = $array['pay_dates'][0] ?? null;
// if (null !== $current && !$nextExpectedMatch->isToday()) {
// $currentExpectedMatch = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
// $array['next_expected_match_diff'] = $currentExpectedMatch->diffForHumans(today(), Carbon::DIFF_RELATIVE_TO_NOW);
// }
$currency = $bill->transactionCurrency ?? $defaultCurrency;
$array['currency_id'] = $currency->id;

View File

@@ -30,6 +30,7 @@ use FireflyIII\Http\Requests\RecurrenceFormRequest;
use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Illuminate\Contracts\View\Factory;
@@ -47,6 +48,7 @@ class CreateController extends Controller
private AttachmentHelperInterface $attachments;
private BudgetRepositoryInterface $budgetRepos;
private RecurringRepositoryInterface $recurring;
private BillRepositoryInterface $billRepository;
/**
* CreateController constructor.
@@ -64,9 +66,10 @@ class CreateController extends Controller
app('view')->share('title', (string)trans('firefly.recurrences'));
app('view')->share('subTitle', (string)trans('firefly.create_new_recurrence'));
$this->recurring = app(RecurringRepositoryInterface::class);
$this->budgetRepos = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
$this->recurring = app(RecurringRepositoryInterface::class);
$this->budgetRepos = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
$this->billRepository = app(BillRepositoryInterface::class);
return $next($request);
}
@@ -83,6 +86,7 @@ class CreateController extends Controller
public function create(Request $request)
{
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
$bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills());
$defaultCurrency = app('amount')->getDefaultCurrency();
$tomorrow = today(config('app.timezone'));
$oldRepetitionType = $request->old('repetition_type');
@@ -115,7 +119,7 @@ class CreateController extends Controller
return prefixView(
'recurring.create',
compact('tomorrow', 'oldRepetitionType', 'weekendResponses', 'preFilled', 'repetitionEnds', 'defaultCurrency', 'budgets')
compact('tomorrow', 'oldRepetitionType', 'bills', 'weekendResponses', 'preFilled', 'repetitionEnds', 'defaultCurrency', 'budgets')
);
}
@@ -155,11 +159,12 @@ class CreateController extends Controller
$type = strtolower($journal->transactionType->type);
/** @var Transaction $source */
$source = $journal->transactions()->where('amount', '<', 0)->first();
$source = $journal->transactions()->where('amount', '<', 0)->first();
/** @var Transaction $dest */
$dest = $journal->transactions()->where('amount', '>', 0)->first();
$category = $journal->categories()->first() ? $journal->categories()->first()->name : '';
$budget = $journal->budgets()->first() ? $journal->budgets()->first()->id : 0;
$bill = $journal->bill ? $journal->bill->id : 0;
$hasOldInput = null !== $request->old('_token'); // flash some data
$preFilled = [];
if (true === $hasOldInput) {
@@ -178,6 +183,7 @@ class CreateController extends Controller
'transaction_type' => $request->old('transaction_type'),
'category' => $request->old('category'),
'budget_id' => $request->old('budget_id'),
'bill_id' => $request->old('bill_id'),
'active' => (bool)$request->old('active'),
'apply_rules' => (bool)$request->old('apply_rules'),
];
@@ -198,6 +204,7 @@ class CreateController extends Controller
'transaction_type' => $type,
'category' => $category,
'budget_id' => $budget,
'bill_id' => $bill,
'active' => true,
'apply_rules' => true,
];
@@ -243,7 +250,7 @@ class CreateController extends Controller
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
}
$redirect = redirect($this->getPreviousUri('recurring.create.uri'));

View File

@@ -29,6 +29,7 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\RecurrenceFormRequest;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Transformers\RecurrenceTransformer;
@@ -48,6 +49,7 @@ class EditController extends Controller
private AttachmentHelperInterface $attachments;
private BudgetRepositoryInterface $budgetRepos;
private RecurringRepositoryInterface $recurring;
private BillRepositoryInterface $billRepository;
/**
* EditController constructor.
@@ -65,9 +67,10 @@ class EditController extends Controller
app('view')->share('title', (string)trans('firefly.recurrences'));
app('view')->share('subTitle', (string)trans('firefly.recurrences'));
$this->recurring = app(RecurringRepositoryInterface::class);
$this->budgetRepos = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
$this->recurring = app(RecurringRepositoryInterface::class);
$this->budgetRepos = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
$this->billRepository = app(BillRepositoryInterface::class);
return $next($request);
}
@@ -86,7 +89,7 @@ class EditController extends Controller
*/
public function edit(Request $request, Recurrence $recurrence)
{
// See reference nr. 69
// See reference nr. 69
$count = $recurrence->recurrenceTransactions()->count();
if (0 === $count) {
throw new FireflyException('This recurring transaction has no meta-data. You will have to delete it and recreate it. Sorry!');
@@ -98,6 +101,7 @@ class EditController extends Controller
$array = $transformer->transform($recurrence);
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
$bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills());
/** @var RecurrenceRepetition $repetition */
$repetition = $recurrence->recurrenceRepetitions()->first();
@@ -146,7 +150,10 @@ class EditController extends Controller
return prefixView(
'recurring.edit',
compact('recurrence', 'array', 'weekendResponses', 'budgets', 'preFilled', 'currentRepType', 'repetitionEnd', 'repetitionEnds')
compact(
'recurrence', 'array', 'bills',
'weekendResponses', 'budgets', 'preFilled', 'currentRepType', 'repetitionEnd', 'repetitionEnds'
)
);
}

View File

@@ -78,6 +78,8 @@ class RecurrenceFormRequest extends FormRequest
'foreign_currency_code' => null,
'budget_id' => $this->integer('budget_id'),
'budget_name' => null,
'bill_id' => $this->integer('bill_id'),
'bill_name' => null,
'category_id' => null,
'category_name' => $this->string('category'),
'tags' => '' !== $this->string('tags') ? explode(',', $this->string('tags')) : [],
@@ -109,7 +111,7 @@ class RecurrenceFormRequest extends FormRequest
// fill in source and destination account data
switch ($this->string('transaction_type')) {
default:
throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->string('transaction_type')));
throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->string('transaction_type')));
case 'withdrawal':
$return['transactions'][0]['source_id'] = $this->integer('source_id');
$return['transactions'][0]['destination_id'] = $this->integer('withdrawal_destination_id');
@@ -162,11 +164,11 @@ class RecurrenceFormRequest extends FormRequest
$return['type'] = substr($value, 0, 6);
$return['moment'] = substr($value, 7);
}
if (0 === strpos($value, 'monthly')) {
if (str_starts_with($value, 'monthly')) {
$return['type'] = substr($value, 0, 7);
$return['moment'] = substr($value, 8);
}
if (0 === strpos($value, 'ndom')) {
if (str_starts_with($value, 'ndom')) {
$return['type'] = substr($value, 0, 4);
$return['moment'] = substr($value, 5);
}
@@ -213,6 +215,7 @@ class RecurrenceFormRequest extends FormRequest
// optional fields:
'budget_id' => 'mustExist:budgets,id|belongsToUser:budgets,id|nullable',
'bill_id' => 'mustExist:bills,id|belongsToUser:bills,id|nullable',
'category' => 'between:1,255|nullable',
'tags' => 'between:1,255|nullable',
];
@@ -251,7 +254,7 @@ class RecurrenceFormRequest extends FormRequest
break;
default:
throw new FireflyException(sprintf('Cannot handle transaction type of type "%s"', $this->string('transaction_type')));
throw new FireflyException(sprintf('Cannot handle transaction type of type "%s"', $this->string('transaction_type')));
}
// update some rules in case the user is editing a post:
@@ -304,11 +307,11 @@ class RecurrenceFormRequest extends FormRequest
$sourceId = null;
$destinationId = null;
// See reference nr. 45
// See reference nr. 45
switch ($this->string('transaction_type')) {
default:
throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->string('transaction_type')));
throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->string('transaction_type')));
case 'withdrawal':
$sourceId = (int)$data['source_id'];
$destinationId = (int)$data['withdrawal_destination_id'];