mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 11:48:05 +00:00
Various fixes and extensions.
This commit is contained in:
@@ -107,18 +107,18 @@ class IndexController extends Controller
|
|||||||
'object_group_title' => $array['object_group_title'],
|
'object_group_title' => $array['object_group_title'],
|
||||||
'bills' => [],
|
'bills' => [],
|
||||||
];
|
];
|
||||||
|
// var_dump($array);exit;
|
||||||
// expected today? default:
|
// // expected today? default:
|
||||||
$array['next_expected_match_diff'] = trans('firefly.not_expected_period');
|
// $array['next_expected_match_diff'] = trans('firefly.not_expected_period');
|
||||||
$nextExpectedMatch = new Carbon($array['next_expected_match']);
|
// $nextExpectedMatch = new Carbon($array['next_expected_match']);
|
||||||
if ($nextExpectedMatch->isToday()) {
|
// if ($nextExpectedMatch->isToday()) {
|
||||||
$array['next_expected_match_diff'] = trans('firefly.today');
|
// $array['next_expected_match_diff'] = trans('firefly.today');
|
||||||
}
|
// }
|
||||||
$current = $array['pay_dates'][0] ?? null;
|
// $current = $array['pay_dates'][0] ?? null;
|
||||||
if (null !== $current && !$nextExpectedMatch->isToday()) {
|
// if (null !== $current && !$nextExpectedMatch->isToday()) {
|
||||||
$currentExpectedMatch = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
|
// $currentExpectedMatch = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
|
||||||
$array['next_expected_match_diff'] = $currentExpectedMatch->diffForHumans(today(), Carbon::DIFF_RELATIVE_TO_NOW);
|
// $array['next_expected_match_diff'] = $currentExpectedMatch->diffForHumans(today(), Carbon::DIFF_RELATIVE_TO_NOW);
|
||||||
}
|
// }
|
||||||
|
|
||||||
$currency = $bill->transactionCurrency ?? $defaultCurrency;
|
$currency = $bill->transactionCurrency ?? $defaultCurrency;
|
||||||
$array['currency_id'] = $currency->id;
|
$array['currency_id'] = $currency->id;
|
||||||
|
@@ -30,6 +30,7 @@ use FireflyIII\Http\Requests\RecurrenceFormRequest;
|
|||||||
use FireflyIII\Models\RecurrenceRepetition;
|
use FireflyIII\Models\RecurrenceRepetition;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
@@ -47,6 +48,7 @@ class CreateController extends Controller
|
|||||||
private AttachmentHelperInterface $attachments;
|
private AttachmentHelperInterface $attachments;
|
||||||
private BudgetRepositoryInterface $budgetRepos;
|
private BudgetRepositoryInterface $budgetRepos;
|
||||||
private RecurringRepositoryInterface $recurring;
|
private RecurringRepositoryInterface $recurring;
|
||||||
|
private BillRepositoryInterface $billRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CreateController constructor.
|
* CreateController constructor.
|
||||||
@@ -64,9 +66,10 @@ class CreateController extends Controller
|
|||||||
app('view')->share('title', (string)trans('firefly.recurrences'));
|
app('view')->share('title', (string)trans('firefly.recurrences'));
|
||||||
app('view')->share('subTitle', (string)trans('firefly.create_new_recurrence'));
|
app('view')->share('subTitle', (string)trans('firefly.create_new_recurrence'));
|
||||||
|
|
||||||
$this->recurring = app(RecurringRepositoryInterface::class);
|
$this->recurring = app(RecurringRepositoryInterface::class);
|
||||||
$this->budgetRepos = app(BudgetRepositoryInterface::class);
|
$this->budgetRepos = app(BudgetRepositoryInterface::class);
|
||||||
$this->attachments = app(AttachmentHelperInterface::class);
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
|
$this->billRepository = app(BillRepositoryInterface::class);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@@ -83,6 +86,7 @@ class CreateController extends Controller
|
|||||||
public function create(Request $request)
|
public function create(Request $request)
|
||||||
{
|
{
|
||||||
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
|
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
|
||||||
|
$bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills());
|
||||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||||
$tomorrow = today(config('app.timezone'));
|
$tomorrow = today(config('app.timezone'));
|
||||||
$oldRepetitionType = $request->old('repetition_type');
|
$oldRepetitionType = $request->old('repetition_type');
|
||||||
@@ -115,7 +119,7 @@ class CreateController extends Controller
|
|||||||
|
|
||||||
return prefixView(
|
return prefixView(
|
||||||
'recurring.create',
|
'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);
|
$type = strtolower($journal->transactionType->type);
|
||||||
|
|
||||||
/** @var Transaction $source */
|
/** @var Transaction $source */
|
||||||
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||||
/** @var Transaction $dest */
|
/** @var Transaction $dest */
|
||||||
$dest = $journal->transactions()->where('amount', '>', 0)->first();
|
$dest = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
$category = $journal->categories()->first() ? $journal->categories()->first()->name : '';
|
$category = $journal->categories()->first() ? $journal->categories()->first()->name : '';
|
||||||
$budget = $journal->budgets()->first() ? $journal->budgets()->first()->id : 0;
|
$budget = $journal->budgets()->first() ? $journal->budgets()->first()->id : 0;
|
||||||
|
$bill = $journal->bill ? $journal->bill->id : 0;
|
||||||
$hasOldInput = null !== $request->old('_token'); // flash some data
|
$hasOldInput = null !== $request->old('_token'); // flash some data
|
||||||
$preFilled = [];
|
$preFilled = [];
|
||||||
if (true === $hasOldInput) {
|
if (true === $hasOldInput) {
|
||||||
@@ -178,6 +183,7 @@ class CreateController extends Controller
|
|||||||
'transaction_type' => $request->old('transaction_type'),
|
'transaction_type' => $request->old('transaction_type'),
|
||||||
'category' => $request->old('category'),
|
'category' => $request->old('category'),
|
||||||
'budget_id' => $request->old('budget_id'),
|
'budget_id' => $request->old('budget_id'),
|
||||||
|
'bill_id' => $request->old('bill_id'),
|
||||||
'active' => (bool)$request->old('active'),
|
'active' => (bool)$request->old('active'),
|
||||||
'apply_rules' => (bool)$request->old('apply_rules'),
|
'apply_rules' => (bool)$request->old('apply_rules'),
|
||||||
];
|
];
|
||||||
@@ -198,6 +204,7 @@ class CreateController extends Controller
|
|||||||
'transaction_type' => $type,
|
'transaction_type' => $type,
|
||||||
'category' => $category,
|
'category' => $category,
|
||||||
'budget_id' => $budget,
|
'budget_id' => $budget,
|
||||||
|
'bill_id' => $bill,
|
||||||
'active' => true,
|
'active' => true,
|
||||||
'apply_rules' => true,
|
'apply_rules' => true,
|
||||||
];
|
];
|
||||||
@@ -243,7 +250,7 @@ class CreateController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
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'));
|
$redirect = redirect($this->getPreviousUri('recurring.create.uri'));
|
||||||
|
@@ -29,6 +29,7 @@ use FireflyIII\Http\Controllers\Controller;
|
|||||||
use FireflyIII\Http\Requests\RecurrenceFormRequest;
|
use FireflyIII\Http\Requests\RecurrenceFormRequest;
|
||||||
use FireflyIII\Models\Recurrence;
|
use FireflyIII\Models\Recurrence;
|
||||||
use FireflyIII\Models\RecurrenceRepetition;
|
use FireflyIII\Models\RecurrenceRepetition;
|
||||||
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
use FireflyIII\Transformers\RecurrenceTransformer;
|
use FireflyIII\Transformers\RecurrenceTransformer;
|
||||||
@@ -48,6 +49,7 @@ class EditController extends Controller
|
|||||||
private AttachmentHelperInterface $attachments;
|
private AttachmentHelperInterface $attachments;
|
||||||
private BudgetRepositoryInterface $budgetRepos;
|
private BudgetRepositoryInterface $budgetRepos;
|
||||||
private RecurringRepositoryInterface $recurring;
|
private RecurringRepositoryInterface $recurring;
|
||||||
|
private BillRepositoryInterface $billRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EditController constructor.
|
* EditController constructor.
|
||||||
@@ -65,9 +67,10 @@ class EditController extends Controller
|
|||||||
app('view')->share('title', (string)trans('firefly.recurrences'));
|
app('view')->share('title', (string)trans('firefly.recurrences'));
|
||||||
app('view')->share('subTitle', (string)trans('firefly.recurrences'));
|
app('view')->share('subTitle', (string)trans('firefly.recurrences'));
|
||||||
|
|
||||||
$this->recurring = app(RecurringRepositoryInterface::class);
|
$this->recurring = app(RecurringRepositoryInterface::class);
|
||||||
$this->budgetRepos = app(BudgetRepositoryInterface::class);
|
$this->budgetRepos = app(BudgetRepositoryInterface::class);
|
||||||
$this->attachments = app(AttachmentHelperInterface::class);
|
$this->attachments = app(AttachmentHelperInterface::class);
|
||||||
|
$this->billRepository = app(BillRepositoryInterface::class);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@@ -86,7 +89,7 @@ class EditController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(Request $request, Recurrence $recurrence)
|
public function edit(Request $request, Recurrence $recurrence)
|
||||||
{
|
{
|
||||||
// See reference nr. 69
|
// See reference nr. 69
|
||||||
$count = $recurrence->recurrenceTransactions()->count();
|
$count = $recurrence->recurrenceTransactions()->count();
|
||||||
if (0 === $count) {
|
if (0 === $count) {
|
||||||
throw new FireflyException('This recurring transaction has no meta-data. You will have to delete it and recreate it. Sorry!');
|
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);
|
$array = $transformer->transform($recurrence);
|
||||||
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
|
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
|
||||||
|
$bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills());
|
||||||
|
|
||||||
/** @var RecurrenceRepetition $repetition */
|
/** @var RecurrenceRepetition $repetition */
|
||||||
$repetition = $recurrence->recurrenceRepetitions()->first();
|
$repetition = $recurrence->recurrenceRepetitions()->first();
|
||||||
@@ -146,7 +150,10 @@ class EditController extends Controller
|
|||||||
|
|
||||||
return prefixView(
|
return prefixView(
|
||||||
'recurring.edit',
|
'recurring.edit',
|
||||||
compact('recurrence', 'array', 'weekendResponses', 'budgets', 'preFilled', 'currentRepType', 'repetitionEnd', 'repetitionEnds')
|
compact(
|
||||||
|
'recurrence', 'array', 'bills',
|
||||||
|
'weekendResponses', 'budgets', 'preFilled', 'currentRepType', 'repetitionEnd', 'repetitionEnds'
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -78,6 +78,8 @@ class RecurrenceFormRequest extends FormRequest
|
|||||||
'foreign_currency_code' => null,
|
'foreign_currency_code' => null,
|
||||||
'budget_id' => $this->integer('budget_id'),
|
'budget_id' => $this->integer('budget_id'),
|
||||||
'budget_name' => null,
|
'budget_name' => null,
|
||||||
|
'bill_id' => $this->integer('bill_id'),
|
||||||
|
'bill_name' => null,
|
||||||
'category_id' => null,
|
'category_id' => null,
|
||||||
'category_name' => $this->string('category'),
|
'category_name' => $this->string('category'),
|
||||||
'tags' => '' !== $this->string('tags') ? explode(',', $this->string('tags')) : [],
|
'tags' => '' !== $this->string('tags') ? explode(',', $this->string('tags')) : [],
|
||||||
@@ -109,7 +111,7 @@ class RecurrenceFormRequest extends FormRequest
|
|||||||
// fill in source and destination account data
|
// fill in source and destination account data
|
||||||
switch ($this->string('transaction_type')) {
|
switch ($this->string('transaction_type')) {
|
||||||
default:
|
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':
|
case 'withdrawal':
|
||||||
$return['transactions'][0]['source_id'] = $this->integer('source_id');
|
$return['transactions'][0]['source_id'] = $this->integer('source_id');
|
||||||
$return['transactions'][0]['destination_id'] = $this->integer('withdrawal_destination_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['type'] = substr($value, 0, 6);
|
||||||
$return['moment'] = substr($value, 7);
|
$return['moment'] = substr($value, 7);
|
||||||
}
|
}
|
||||||
if (0 === strpos($value, 'monthly')) {
|
if (str_starts_with($value, 'monthly')) {
|
||||||
$return['type'] = substr($value, 0, 7);
|
$return['type'] = substr($value, 0, 7);
|
||||||
$return['moment'] = substr($value, 8);
|
$return['moment'] = substr($value, 8);
|
||||||
}
|
}
|
||||||
if (0 === strpos($value, 'ndom')) {
|
if (str_starts_with($value, 'ndom')) {
|
||||||
$return['type'] = substr($value, 0, 4);
|
$return['type'] = substr($value, 0, 4);
|
||||||
$return['moment'] = substr($value, 5);
|
$return['moment'] = substr($value, 5);
|
||||||
}
|
}
|
||||||
@@ -213,6 +215,7 @@ class RecurrenceFormRequest extends FormRequest
|
|||||||
|
|
||||||
// optional fields:
|
// optional fields:
|
||||||
'budget_id' => 'mustExist:budgets,id|belongsToUser:budgets,id|nullable',
|
'budget_id' => 'mustExist:budgets,id|belongsToUser:budgets,id|nullable',
|
||||||
|
'bill_id' => 'mustExist:bills,id|belongsToUser:bills,id|nullable',
|
||||||
'category' => 'between:1,255|nullable',
|
'category' => 'between:1,255|nullable',
|
||||||
'tags' => 'between:1,255|nullable',
|
'tags' => 'between:1,255|nullable',
|
||||||
];
|
];
|
||||||
@@ -251,7 +254,7 @@ class RecurrenceFormRequest extends FormRequest
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
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:
|
// update some rules in case the user is editing a post:
|
||||||
@@ -304,11 +307,11 @@ class RecurrenceFormRequest extends FormRequest
|
|||||||
$sourceId = null;
|
$sourceId = null;
|
||||||
$destinationId = null;
|
$destinationId = null;
|
||||||
|
|
||||||
// See reference nr. 45
|
// See reference nr. 45
|
||||||
|
|
||||||
switch ($this->string('transaction_type')) {
|
switch ($this->string('transaction_type')) {
|
||||||
default:
|
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':
|
case 'withdrawal':
|
||||||
$sourceId = (int)$data['source_id'];
|
$sourceId = (int)$data['source_id'];
|
||||||
$destinationId = (int)$data['withdrawal_destination_id'];
|
$destinationId = (int)$data['withdrawal_destination_id'];
|
||||||
|
@@ -110,6 +110,8 @@ class Bill extends Model
|
|||||||
'updated_at' => 'datetime',
|
'updated_at' => 'datetime',
|
||||||
'deleted_at' => 'datetime',
|
'deleted_at' => 'datetime',
|
||||||
'date' => 'date',
|
'date' => 'date',
|
||||||
|
'end_date' => 'date',
|
||||||
|
'extension_date' => 'date',
|
||||||
'skip' => 'int',
|
'skip' => 'int',
|
||||||
'automatch' => 'boolean',
|
'automatch' => 'boolean',
|
||||||
'active' => 'boolean',
|
'active' => 'boolean',
|
||||||
|
@@ -61,6 +61,7 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function destroy(Tag $tag): bool
|
public function destroy(Tag $tag): bool
|
||||||
{
|
{
|
||||||
|
DB::table('tag_transaction_journal')->where('tag_id', $tag->id)->delete();
|
||||||
$tag->transactionJournals()->sync([]);
|
$tag->transactionJournals()->sync([]);
|
||||||
$tag->delete();
|
$tag->delete();
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Services\Internal\Support;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Factory\AccountFactory;
|
use FireflyIII\Factory\AccountFactory;
|
||||||
|
use FireflyIII\Factory\BillFactory;
|
||||||
use FireflyIII\Factory\BudgetFactory;
|
use FireflyIII\Factory\BudgetFactory;
|
||||||
use FireflyIII\Factory\CategoryFactory;
|
use FireflyIII\Factory\CategoryFactory;
|
||||||
use FireflyIII\Factory\PiggyBankFactory;
|
use FireflyIII\Factory\PiggyBankFactory;
|
||||||
@@ -136,16 +137,16 @@ trait RecurringTransactionTrait
|
|||||||
$validator->setUser($recurrence->user);
|
$validator->setUser($recurrence->user);
|
||||||
$validator->setTransactionType($recurrence->transactionType->type);
|
$validator->setTransactionType($recurrence->transactionType->type);
|
||||||
if (!$validator->validateSource($source->id, null, null)) {
|
if (!$validator->validateSource($source->id, null, null)) {
|
||||||
throw new FireflyException(sprintf('Source invalid: %s', $validator->sourceError));
|
throw new FireflyException(sprintf('Source invalid: %s', $validator->sourceError));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$validator->validateDestination($destination->id, null, null)) {
|
if (!$validator->validateDestination($destination->id, null, null)) {
|
||||||
throw new FireflyException(sprintf('Destination invalid: %s', $validator->destError));
|
throw new FireflyException(sprintf('Destination invalid: %s', $validator->destError));
|
||||||
}
|
}
|
||||||
if (array_key_exists('foreign_amount', $array) && '' === (string)$array['foreign_amount']) {
|
if (array_key_exists('foreign_amount', $array) && '' === (string)$array['foreign_amount']) {
|
||||||
unset($array['foreign_amount']);
|
unset($array['foreign_amount']);
|
||||||
}
|
}
|
||||||
// See reference nr. 100
|
// See reference nr. 100
|
||||||
$transaction = new RecurrenceTransaction(
|
$transaction = new RecurrenceTransaction(
|
||||||
[
|
[
|
||||||
'recurrence_id' => $recurrence->id,
|
'recurrence_id' => $recurrence->id,
|
||||||
@@ -163,6 +164,9 @@ trait RecurringTransactionTrait
|
|||||||
if (array_key_exists('budget_id', $array)) {
|
if (array_key_exists('budget_id', $array)) {
|
||||||
$this->setBudget($transaction, (int)$array['budget_id']);
|
$this->setBudget($transaction, (int)$array['budget_id']);
|
||||||
}
|
}
|
||||||
|
if (array_key_exists('bill_id', $array)) {
|
||||||
|
$this->setBill($transaction, (int)$array['bill_id']);
|
||||||
|
}
|
||||||
if (array_key_exists('category_id', $array)) {
|
if (array_key_exists('category_id', $array)) {
|
||||||
$this->setCategory($transaction, (int)$array['category_id']);
|
$this->setCategory($transaction, (int)$array['category_id']);
|
||||||
}
|
}
|
||||||
@@ -254,6 +258,29 @@ trait RecurringTransactionTrait
|
|||||||
$meta->save();
|
$meta->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param RecurrenceTransaction $transaction
|
||||||
|
* @param int $billId
|
||||||
|
*/
|
||||||
|
private function setBill(RecurrenceTransaction $transaction, int $billId): void
|
||||||
|
{
|
||||||
|
$billFactory = app(BillFactory::class);
|
||||||
|
$billFactory->setUser($transaction->recurrence->user);
|
||||||
|
$bill = $billFactory->find($billId, null);
|
||||||
|
if (null === $bill) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'bill_id')->first();
|
||||||
|
if (null === $meta) {
|
||||||
|
$meta = new RecurrenceTransactionMeta;
|
||||||
|
$meta->rt_id = $transaction->id;
|
||||||
|
$meta->name = 'bill_id';
|
||||||
|
}
|
||||||
|
$meta->value = $bill->id;
|
||||||
|
$meta->save();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param RecurrenceTransaction $transaction
|
* @param RecurrenceTransaction $transaction
|
||||||
* @param int $categoryId
|
* @param int $categoryId
|
||||||
@@ -269,6 +296,7 @@ trait RecurringTransactionTrait
|
|||||||
// remove category:
|
// remove category:
|
||||||
$transaction->recurrenceTransactionMeta()->where('name', 'category_id')->delete();
|
$transaction->recurrenceTransactionMeta()->where('name', 'category_id')->delete();
|
||||||
$transaction->recurrenceTransactionMeta()->where('name', 'category_name')->delete();
|
$transaction->recurrenceTransactionMeta()->where('name', 'category_name')->delete();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -289,6 +289,9 @@ class RecurrenceUpdateService
|
|||||||
if (array_key_exists('budget_id', $current)) {
|
if (array_key_exists('budget_id', $current)) {
|
||||||
$this->setBudget($match, (int)$current['budget_id']);
|
$this->setBudget($match, (int)$current['budget_id']);
|
||||||
}
|
}
|
||||||
|
if (array_key_exists('bill_id', $current)) {
|
||||||
|
$this->setBill($match, (int)$current['bill_id']);
|
||||||
|
}
|
||||||
// reset category if name is set but empty:
|
// reset category if name is set but empty:
|
||||||
// can be removed when v1 is retired.
|
// can be removed when v1 is retired.
|
||||||
if (array_key_exists('category_name', $current) && '' === (string)$current['category_name']) {
|
if (array_key_exists('category_name', $current) && '' === (string)$current['category_name']) {
|
||||||
|
@@ -78,43 +78,62 @@ class BillTransformer extends AbstractTransformer
|
|||||||
|
|
||||||
$paidDataFormatted = [];
|
$paidDataFormatted = [];
|
||||||
$payDatesFormatted = [];
|
$payDatesFormatted = [];
|
||||||
foreach($paidData['paid_dates'] as $object) {
|
foreach ($paidData['paid_dates'] as $object) {
|
||||||
$object['date'] = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone'))->toAtomString();
|
$object['date'] = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone'))->toAtomString();
|
||||||
$paidDataFormatted[] = $object;
|
$paidDataFormatted[] = $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($payDates as $string) {
|
foreach ($payDates as $string) {
|
||||||
$payDatesFormatted[] = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone'))->toAtomString();
|
$payDatesFormatted[] = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone'))->toAtomString();
|
||||||
}
|
}
|
||||||
$nextExpectedMatch = null;
|
$nextExpectedMatch = null;
|
||||||
if(null !== $paidData['next_expected_match'] ) {
|
if (null !== $paidData['next_expected_match']) {
|
||||||
$nextExpectedMatch = Carbon::createFromFormat('!Y-m-d', $paidData['next_expected_match'], config('app.timezone'))->toAtomString();
|
$nextExpectedMatch = Carbon::createFromFormat('!Y-m-d', $paidData['next_expected_match'], config('app.timezone'))->toAtomString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$nextExpectedMatchDiff = trans('firefly.not_expected_period');
|
||||||
|
// converting back and forth is bad code but OK.
|
||||||
|
$temp = new Carbon($nextExpectedMatch);
|
||||||
|
if ($temp->isToday()) {
|
||||||
|
$nextExpectedMatchDiff = trans('firefly.today');
|
||||||
|
}
|
||||||
|
|
||||||
|
$current = $payDatesFormatted[0] ?? null;
|
||||||
|
if (null !== $current && !$temp->isToday()) {
|
||||||
|
$temp2 = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
|
||||||
|
$nextExpectedMatchDiff = $temp2->diffForHumans(today(), Carbon::DIFF_RELATIVE_TO_NOW);
|
||||||
|
}
|
||||||
|
unset($temp, $temp2);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => (int)$bill->id,
|
'id' => (int)$bill->id,
|
||||||
'created_at' => $bill->created_at->toAtomString(),
|
'created_at' => $bill->created_at->toAtomString(),
|
||||||
'updated_at' => $bill->updated_at->toAtomString(),
|
'updated_at' => $bill->updated_at->toAtomString(),
|
||||||
'currency_id' => (string)$bill->transaction_currency_id,
|
'currency_id' => (string)$bill->transaction_currency_id,
|
||||||
'currency_code' => $currency->code,
|
'currency_code' => $currency->code,
|
||||||
'currency_symbol' => $currency->symbol,
|
'currency_symbol' => $currency->symbol,
|
||||||
'currency_decimal_places' => (int)$currency->decimal_places,
|
'currency_decimal_places' => (int)$currency->decimal_places,
|
||||||
'name' => $bill->name,
|
'name' => $bill->name,
|
||||||
'amount_min' => number_format((float)$bill->amount_min, $currency->decimal_places, '.', ''),
|
'amount_min' => number_format((float)$bill->amount_min, $currency->decimal_places, '.', ''),
|
||||||
'amount_max' => number_format((float)$bill->amount_max, $currency->decimal_places, '.', ''),
|
'amount_max' => number_format((float)$bill->amount_max, $currency->decimal_places, '.', ''),
|
||||||
'date' => $bill->date->toAtomString(),
|
'date' => $bill->date->toAtomString(),
|
||||||
'repeat_freq' => $bill->repeat_freq,
|
'end_date' => $bill->end_date?->toAtomString(),
|
||||||
'skip' => (int)$bill->skip,
|
'extension_date' => $bill->extension_date?->toAtomString(),
|
||||||
'active' => $bill->active,
|
'repeat_freq' => $bill->repeat_freq,
|
||||||
'order' => (int)$bill->order,
|
'skip' => (int)$bill->skip,
|
||||||
'notes' => $notes,
|
'active' => $bill->active,
|
||||||
'next_expected_match' => $nextExpectedMatch,
|
'order' => (int)$bill->order,
|
||||||
'pay_dates' => $payDatesFormatted,
|
'notes' => $notes,
|
||||||
'paid_dates' => $paidDataFormatted,
|
'object_group_id' => $objectGroupId ? (string)$objectGroupId : null,
|
||||||
'object_group_id' => $objectGroupId ? (string)$objectGroupId : null,
|
'object_group_order' => $objectGroupOrder,
|
||||||
'object_group_order' => $objectGroupOrder,
|
'object_group_title' => $objectGroupTitle,
|
||||||
'object_group_title' => $objectGroupTitle,
|
|
||||||
'links' => [
|
// these fields need work:
|
||||||
|
'next_expected_match' => $nextExpectedMatch,
|
||||||
|
'next_expected_match_diff' => $nextExpectedMatchDiff,
|
||||||
|
'pay_dates' => $payDatesFormatted,
|
||||||
|
'paid_dates' => $paidDataFormatted,
|
||||||
|
'links' => [
|
||||||
[
|
[
|
||||||
'rel' => 'self',
|
'rel' => 'self',
|
||||||
'uri' => '/bills/' . $bill->id,
|
'uri' => '/bills/' . $bill->id,
|
||||||
@@ -208,7 +227,7 @@ class BillTransformer extends AbstractTransformer
|
|||||||
protected function lastPaidDate(Collection $dates, Carbon $default): Carbon
|
protected function lastPaidDate(Collection $dates, Carbon $default): Carbon
|
||||||
{
|
{
|
||||||
if (0 === $dates->count()) {
|
if (0 === $dates->count()) {
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
$latest = $dates->first()->date;
|
$latest = $dates->first()->date;
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
@@ -254,6 +273,7 @@ class BillTransformer extends AbstractTransformer
|
|||||||
return $date->format('Y-m-d');
|
return $date->format('Y-m-d');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return $simple->toArray();
|
return $simple->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace FireflyIII\Transformers;
|
namespace FireflyIII\Transformers;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Factory\CategoryFactory;
|
use FireflyIII\Factory\CategoryFactory;
|
||||||
@@ -29,6 +30,7 @@ use FireflyIII\Models\Recurrence;
|
|||||||
use FireflyIII\Models\RecurrenceRepetition;
|
use FireflyIII\Models\RecurrenceRepetition;
|
||||||
use FireflyIII\Models\RecurrenceTransaction;
|
use FireflyIII\Models\RecurrenceTransaction;
|
||||||
use FireflyIII\Models\RecurrenceTransactionMeta;
|
use FireflyIII\Models\RecurrenceTransactionMeta;
|
||||||
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
@@ -44,6 +46,7 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
private CategoryFactory $factory;
|
private CategoryFactory $factory;
|
||||||
private PiggyBankRepositoryInterface $piggyRepos;
|
private PiggyBankRepositoryInterface $piggyRepos;
|
||||||
private RecurringRepositoryInterface $repository;
|
private RecurringRepositoryInterface $repository;
|
||||||
|
private BillRepositoryInterface $billRepos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RecurrenceTransformer constructor.
|
* RecurrenceTransformer constructor.
|
||||||
@@ -56,6 +59,7 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
$this->piggyRepos = app(PiggyBankRepositoryInterface::class);
|
$this->piggyRepos = app(PiggyBankRepositoryInterface::class);
|
||||||
$this->factory = app(CategoryFactory::class);
|
$this->factory = app(CategoryFactory::class);
|
||||||
$this->budgetRepos = app(BudgetRepositoryInterface::class);
|
$this->budgetRepos = app(BudgetRepositoryInterface::class);
|
||||||
|
$this->billRepos = app(BillRepositoryInterface::class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,6 +255,8 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
$array['budget_name'] = null;
|
$array['budget_name'] = null;
|
||||||
$array['piggy_bank_id'] = null;
|
$array['piggy_bank_id'] = null;
|
||||||
$array['piggy_bank_name'] = null;
|
$array['piggy_bank_name'] = null;
|
||||||
|
$array['bill_id'] = null;
|
||||||
|
$array['bill_name'] = null;
|
||||||
|
|
||||||
/** @var RecurrenceTransactionMeta $transactionMeta */
|
/** @var RecurrenceTransactionMeta $transactionMeta */
|
||||||
foreach ($transaction->recurrenceTransactionMeta as $transactionMeta) {
|
foreach ($transaction->recurrenceTransactionMeta as $transactionMeta) {
|
||||||
@@ -258,6 +264,11 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
default:
|
default:
|
||||||
throw new FireflyException(sprintf('Recurrence transformer cant handle field "%s"', $transactionMeta->name));
|
throw new FireflyException(sprintf('Recurrence transformer cant handle field "%s"', $transactionMeta->name));
|
||||||
case 'bill_id':
|
case 'bill_id':
|
||||||
|
$bill = $this->billRepos->find((int)$transactionMeta->value);
|
||||||
|
if (null !== $bill) {
|
||||||
|
$array['bill_id'] = (string)$bill->id;
|
||||||
|
$array['bill_name'] = $bill->name;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'tags':
|
case 'tags':
|
||||||
$array['tags'] = json_decode($transactionMeta->value);
|
$array['tags'] = json_decode($transactionMeta->value);
|
||||||
|
@@ -1,29 +1,54 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 2021_05_09_064644_add_ldap_columns_to_users_table.php
|
||||||
|
* Copyright (c) 2021 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
class AddLdapColumnsToUsersTable extends Migration
|
class AddLdapColumnsToUsersTable extends Migration
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
$table->string('domain')->nullable();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the migrations.
|
* Reverse the migrations.
|
||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::table('users', function (Blueprint $table) {
|
Schema::table(
|
||||||
|
'users', function (Blueprint $table) {
|
||||||
$table->dropColumn(['domain']);
|
$table->dropColumn(['domain']);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table(
|
||||||
|
'users', function (Blueprint $table) {
|
||||||
|
$table->string('domain')->nullable();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 2021_05_13_053836_extend_currency_info.php
|
||||||
|
* Copyright (c) 2021 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
@@ -1,4 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 2021_07_05_193044_drop_tele_table.php
|
||||||
|
* Copyright (c) 2021 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
@@ -9,16 +30,6 @@ use Illuminate\Support\Facades\Schema;
|
|||||||
*/
|
*/
|
||||||
class DropTeleTable extends Migration
|
class DropTeleTable extends Migration
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('telemetry');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the migrations.
|
* Reverse the migrations.
|
||||||
*
|
*
|
||||||
@@ -28,4 +39,14 @@ class DropTeleTable extends Migration
|
|||||||
{
|
{
|
||||||
Schema::dropIfExists('telemetry');
|
Schema::dropIfExists('telemetry');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('telemetry');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user