mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-26 08:51:12 -06:00
Some last minute updates.
This commit is contained in:
parent
2e67bd3b78
commit
54afc6ca8c
@ -64,13 +64,13 @@ class RuleController extends Controller
|
||||
/**
|
||||
* Delete the resource.
|
||||
*
|
||||
* @param string $object
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(string $object): JsonResponse
|
||||
public function delete(Rule $rule): JsonResponse
|
||||
{
|
||||
// todo delete object.
|
||||
$this->ruleRepository->destroy($rule);
|
||||
|
||||
return response()->json([], 204);
|
||||
}
|
||||
|
@ -66,9 +66,9 @@ class RuleGroupController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(string $object): JsonResponse
|
||||
public function delete(RuleGroup $ruleGroup): JsonResponse
|
||||
{
|
||||
// todo delete object.
|
||||
$this->ruleGroupRepository->destroy($ruleGroup, null);
|
||||
|
||||
return response()->json([], 204);
|
||||
}
|
||||
|
@ -1,112 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* TagController.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class TagController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
// todo add local repositories.
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the resource.
|
||||
*
|
||||
* @param string $object
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(string $object): JsonResponse
|
||||
{
|
||||
// todo delete object.
|
||||
|
||||
return response()->json([], 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* List all of them.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse]
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
// todo implement.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* List single resource.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $object
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function show(Request $request, string $object): JsonResponse
|
||||
{
|
||||
// todo implement me.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new object.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
// todo replace code and replace request object.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $object
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(Request $request, string $object): JsonResponse
|
||||
{
|
||||
// todo replace code and replace request object.
|
||||
|
||||
}
|
||||
}
|
@ -127,7 +127,7 @@ class JobStatusController extends Controller
|
||||
public function start(ImportJob $importJob): JsonResponse
|
||||
{
|
||||
// catch impossible status:
|
||||
$allowed = ['ready_to_run', 'need_job_config', 'error']; // todo remove error
|
||||
$allowed = ['ready_to_run', 'need_job_config'];
|
||||
|
||||
if (null !== $importJob && !\in_array($importJob->status, $allowed, true)) {
|
||||
Log::error('Job is not ready.');
|
||||
|
@ -57,7 +57,7 @@ class BillFormRequest extends Request
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
$nameRule = 'required|between:1,255|uniqueObjectForUser:bills,name';
|
||||
if ($this->integer('id') > 0) {
|
||||
|
@ -101,7 +101,6 @@ class SpectreRoutine implements RoutineInterface
|
||||
$handler = app(StageImportDataHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
// todo apply rules.
|
||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||
$this->repository->setStage($this->importJob, 'final');
|
||||
}
|
||||
|
@ -7,8 +7,13 @@ use FireflyIII\Events\RequestedReportOnJournals;
|
||||
use FireflyIII\Models\Recurrence;
|
||||
use FireflyIII\Models\RecurrenceRepetition;
|
||||
use FireflyIII\Models\RecurrenceTransaction;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use FireflyIII\TransactionRules\Processor;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@ -30,6 +35,8 @@ class CreateRecurringTransactions implements ShouldQueue
|
||||
private $journalRepository;
|
||||
/** @var RecurringRepositoryInterface */
|
||||
private $repository;
|
||||
/** @var array */
|
||||
private $rules = [];
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
@ -42,6 +49,7 @@ class CreateRecurringTransactions implements ShouldQueue
|
||||
$this->date = $date;
|
||||
$this->repository = app(RecurringRepositoryInterface::class);
|
||||
$this->journalRepository = app(JournalRepositoryInterface::class);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,6 +85,9 @@ class CreateRecurringTransactions implements ShouldQueue
|
||||
$created = $this->handleRepetitions($recurrence);
|
||||
Log::debug(sprintf('Done with recurrence #%d', $recurrence->id));
|
||||
$result[$recurrence->user_id] = $result[$recurrence->user_id]->merge($created);
|
||||
|
||||
// apply rules:
|
||||
$this->applyRules($recurrence->user, $created);
|
||||
}
|
||||
|
||||
Log::debug('Now running report thing.');
|
||||
@ -100,6 +111,34 @@ class CreateRecurringTransactions implements ShouldQueue
|
||||
return $recurrence->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param Collection $journals
|
||||
*/
|
||||
private function applyRules(User $user, Collection $journals): void
|
||||
{
|
||||
$userId = $user->id;
|
||||
if (!isset($this->rules[$userId])) {
|
||||
$this->rules[$userId] = $this->getRules($user);
|
||||
}
|
||||
// run the rules:
|
||||
if ($this->rules[$userId]->count() > 0) {
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$this->rules[$userId]->each(
|
||||
function (Rule $rule) use ($journal) {
|
||||
Log::debug(sprintf('Going to apply rule #%d to journal %d.', $rule->id, $journal->id));
|
||||
$processor = Processor::make($rule);
|
||||
$processor->handleTransactionJournal($journal);
|
||||
if ($rule->stop_processing) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $occurrences
|
||||
*
|
||||
@ -115,6 +154,23 @@ class CreateRecurringTransactions implements ShouldQueue
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function getRules(User $user): Collection
|
||||
{
|
||||
/** @var RuleRepositoryInterface $repository */
|
||||
$repository = app(RuleRepositoryInterface::class);
|
||||
$repository->setUser($user);
|
||||
$set = $repository->getForImport();
|
||||
|
||||
Log::debug(sprintf('Found %d user rules.', $set->count()));
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
@ -214,7 +270,7 @@ class CreateRecurringTransactions implements ShouldQueue
|
||||
];
|
||||
$journal = $this->journalRepository->store($array);
|
||||
Log::info(sprintf('Created new journal #%d', $journal->id));
|
||||
// todo fire rules
|
||||
|
||||
$collection->push($journal);
|
||||
// update recurring thing:
|
||||
$recurrence->latest_date = $date;
|
||||
|
Loading…
Reference in New Issue
Block a user