mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
commit
8cd13ba13b
@ -104,6 +104,7 @@ class DeleteController extends Controller
|
||||
*/
|
||||
public function destroy(TransactionGroup $group): RedirectResponse
|
||||
{
|
||||
Log::debug(sprintf('Now in %s(#%d).', __METHOD__, $group->id));
|
||||
if (!$this->isEditableGroup($group)) {
|
||||
return $this->redirectGroupToAccount($group);
|
||||
}
|
||||
|
@ -98,17 +98,23 @@ class MassController extends Controller
|
||||
*/
|
||||
public function destroy(MassDeleteJournalRequest $request)
|
||||
{
|
||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||
$ids = $request->get('confirm_mass_delete');
|
||||
$count = 0;
|
||||
if (is_array($ids)) {
|
||||
Log::debug('Array of IDs', $ids);
|
||||
/** @var string $journalId */
|
||||
foreach ($ids as $journalId) {
|
||||
Log::debug(sprintf('Searching for ID #%d', $journalId));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->repository->find((int)$journalId);
|
||||
if (null !== $journal && (int)$journalId === $journal->id) {
|
||||
if (null !== $journal && (int)$journalId === (int) $journal->id) {
|
||||
$this->repository->destroyJournal($journal);
|
||||
++$count;
|
||||
Log::debug(sprintf('Deleted transaction journal #%d', $journalId));
|
||||
continue;
|
||||
}
|
||||
Log::debug(sprintf('Could not find transaction journal #%d', $journalId));
|
||||
}
|
||||
}
|
||||
app('preferences')->mark();
|
||||
|
@ -32,6 +32,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
@ -94,18 +95,22 @@ class TransactionGroup extends Model
|
||||
*/
|
||||
public static function routeBinder(string $value): TransactionGroup
|
||||
{
|
||||
Log::debug(sprintf('Now in %s("%s")', __METHOD__, $value));
|
||||
if (auth()->check()) {
|
||||
$groupId = (int)$value;
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
Log::debug(sprintf('User authenticated as %s', $user->email));
|
||||
/** @var TransactionGroup $group */
|
||||
$group = $user->transactionGroups()
|
||||
->with(['transactionJournals', 'transactionJournals.transactions'])
|
||||
->where('transaction_groups.id', $groupId)->first(['transaction_groups.*']);
|
||||
if (null !== $group) {
|
||||
Log::debug(sprintf('Found group #%d.', $group->id));
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
Log::debug('Found no group.');
|
||||
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
@ -46,5 +46,8 @@ class CategoryDestroyService
|
||||
|
||||
// also delete all relations between categories and transactions:
|
||||
DB::table('category_transaction')->where('category_id', (int)$category->id)->delete();
|
||||
|
||||
// delete references to category from recurring transactions.
|
||||
DB::table('rt_meta')->where('name', 'category_id')->where('value', $category->id)->delete();
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ trait RecurringTransactionTrait
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$transaction->recurrenceTransactionMeta()->where('name', 'category_name')->delete();
|
||||
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'category_id')->first();
|
||||
if (null === $meta) {
|
||||
$meta = new RecurrenceTransactionMeta();
|
||||
|
@ -224,9 +224,10 @@ class RecurrenceUpdateService
|
||||
*/
|
||||
private function updateTransactions(Recurrence $recurrence, array $transactions): void
|
||||
{
|
||||
Log::debug('Now in updateTransactions()');
|
||||
$originalCount = $recurrence->recurrenceTransactions()->count();
|
||||
if (0 === count($transactions)) {
|
||||
// wont drop transactions, rather avoid.
|
||||
// won't drop transactions, rather avoid.
|
||||
return;
|
||||
}
|
||||
// user added or removed repetitions, delete all and recreate:
|
||||
@ -240,12 +241,13 @@ class RecurrenceUpdateService
|
||||
$currencyFactory = app(TransactionCurrencyFactory::class);
|
||||
// loop all and try to match them:
|
||||
if ($originalCount === count($transactions)) {
|
||||
Log::debug('Loop and find');
|
||||
Log::debug(sprintf('Count is equal (%d), update transactions.', $originalCount));
|
||||
foreach ($transactions as $current) {
|
||||
$match = $this->matchTransaction($recurrence, $current);
|
||||
if (null === $match) {
|
||||
throw new FireflyException('Cannot match recurring transaction to existing transaction. Not sure what to do. Break.');
|
||||
}
|
||||
// complex loop to find currency:
|
||||
$currency = null;
|
||||
$foreignCurrency = null;
|
||||
if (array_key_exists('currency_id', $current) || array_key_exists('currency_code', $current)) {
|
||||
@ -267,7 +269,7 @@ class RecurrenceUpdateService
|
||||
$current['foreign_currency_id'] = (int)$foreignCurrency->id;
|
||||
}
|
||||
|
||||
// update fields
|
||||
// update fields that are part of the recurring transaction itself.
|
||||
$fields = [
|
||||
'source_id' => 'source_id',
|
||||
'destination_id' => 'destination_id',
|
||||
@ -293,11 +295,13 @@ class RecurrenceUpdateService
|
||||
// reset category if name is set but empty:
|
||||
// can be removed when v1 is retired.
|
||||
if (array_key_exists('category_name', $current) && '' === (string)$current['category_name']) {
|
||||
Log::debug('Category name is submitted but is empty. Set category to be empty.');
|
||||
$current['category_name'] = null;
|
||||
$current['category_id'] = 0;
|
||||
}
|
||||
|
||||
if (array_key_exists('category_id', $current)) {
|
||||
Log::debug(sprintf('Category ID is submitted, set category to be %d.', (int)$current['category_id']));
|
||||
$this->setCategory($match, (int)$current['category_id']);
|
||||
}
|
||||
|
||||
@ -319,9 +323,10 @@ class RecurrenceUpdateService
|
||||
*/
|
||||
private function matchTransaction(Recurrence $recurrence, array $data): ?RecurrenceTransaction
|
||||
{
|
||||
Log::debug('Now in matchTransaction()');
|
||||
$originalCount = $recurrence->recurrenceTransactions()->count();
|
||||
if (1 === $originalCount) {
|
||||
Log::debug('Return the first one');
|
||||
Log::debug('Return the first one.');
|
||||
|
||||
return $recurrence->recurrenceTransactions()->first();
|
||||
}
|
||||
|
2
public/v1/js/create_transaction.js
vendored
2
public/v1/js/create_transaction.js
vendored
File diff suppressed because one or more lines are too long
2
public/v1/js/webhooks/create.js
vendored
2
public/v1/js/webhooks/create.js
vendored
File diff suppressed because one or more lines are too long
2
public/v1/js/webhooks/edit.js
vendored
2
public/v1/js/webhooks/edit.js
vendored
File diff suppressed because one or more lines are too long
2
public/v1/js/webhooks/show.js
vendored
2
public/v1/js/webhooks/show.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user