mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-02 11:04:53 +00:00
Various code cleanup.
This commit is contained in:
@@ -94,13 +94,13 @@ class StoreController extends Controller
|
||||
$validator = Validator::make(
|
||||
['transactions' => [['description' => $e->getMessage()]]], ['transactions.0.description' => new IsDuplicateTransaction]
|
||||
);
|
||||
throw new ValidationException($validator);
|
||||
throw new ValidationException($validator,0, $e);
|
||||
} catch (FireflyException $e) {
|
||||
Log::warning('Caught an exception. Return error message.');
|
||||
Log::error($e->getMessage());
|
||||
$message = sprintf('Internal exception: %s', $e->getMessage());
|
||||
$validator = Validator::make(['transactions' => [['description' => $message]]], ['transactions.0.description' => new IsDuplicateTransaction]);
|
||||
throw new ValidationException($validator);
|
||||
throw new ValidationException($validator,0, $e);
|
||||
}
|
||||
app('preferences')->mark();
|
||||
event(new StoredTransactionGroup($transactionGroup, $data['apply_rules'] ?? true));
|
||||
|
@@ -50,13 +50,9 @@ class DestroyController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var CurrencyRepositoryInterface repository */
|
||||
$this->repository = app(CurrencyRepositoryInterface::class);
|
||||
$this->userRepository = app(UserRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -77,13 +77,9 @@ class ListController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var CurrencyRepositoryInterface repository */
|
||||
$this->repository = app(CurrencyRepositoryInterface::class);
|
||||
$this->userRepository = app(UserRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -56,12 +56,8 @@ class ShowController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var CurrencyRepositoryInterface repository */
|
||||
$this->repository = app(CurrencyRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -56,13 +56,9 @@ class StoreController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var CurrencyRepositoryInterface repository */
|
||||
$this->repository = app(CurrencyRepositoryInterface::class);
|
||||
$this->userRepository = app(UserRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -56,13 +56,9 @@ class UpdateController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var CurrencyRepositoryInterface repository */
|
||||
$this->repository = app(CurrencyRepositoryInterface::class);
|
||||
$this->userRepository = app(UserRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -64,7 +64,7 @@ class ConfigurationController extends Controller
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
throw new FireflyException('200030: Could not load config variables.');
|
||||
throw new FireflyException('200030: Could not load config variables.', 0, $e);
|
||||
}
|
||||
$staticData = $this->getStaticConfiguration();
|
||||
$return = [];
|
||||
|
@@ -54,7 +54,6 @@ class UserController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var UserRepositoryInterface repository */
|
||||
$this->repository = app(UserRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
|
@@ -53,12 +53,8 @@ class AttemptController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var WebhookRepositoryInterface repository */
|
||||
$this->repository = app(WebhookRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -48,12 +48,8 @@ class DestroyController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var WebhookRepositoryInterface repository */
|
||||
$this->repository = app(WebhookRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -49,12 +49,8 @@ class MessageController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var WebhookRepositoryInterface repository */
|
||||
$this->repository = app(WebhookRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -50,12 +50,8 @@ class ShowController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var WebhookRepositoryInterface repository */
|
||||
$this->repository = app(WebhookRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -47,12 +47,8 @@ class StoreController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var WebhookRepositoryInterface repository */
|
||||
$this->repository = app(WebhookRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@ use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Jobs\SendWebhookMessage;
|
||||
use FireflyIII\Models\Webhook;
|
||||
use FireflyIII\Repositories\Webhook\WebhookRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
@@ -45,12 +44,8 @@ class SubmitController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var WebhookRepositoryInterface repository */
|
||||
$this->repository = app(WebhookRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -47,12 +47,8 @@ class UpdateController extends Controller
|
||||
parent::__construct();
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
/** @var WebhookRepositoryInterface repository */
|
||||
$this->repository = app(WebhookRepositoryInterface::class);
|
||||
$this->repository->setUser($admin);
|
||||
$this->repository->setUser(auth()->user());
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ class ApiDemoUser
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
/** @var User $user */
|
||||
/** @var User|null $user */
|
||||
$user = $request->user();
|
||||
|
||||
if (null === $user) {
|
||||
|
@@ -86,9 +86,6 @@ class GenericRequest extends FormRequest
|
||||
*/
|
||||
private function parseAccounts(): void
|
||||
{
|
||||
if (null === $this->accounts) {
|
||||
$this->accounts = new Collection;
|
||||
}
|
||||
if (0 !== $this->accounts->count()) {
|
||||
return;
|
||||
}
|
||||
@@ -121,9 +118,6 @@ class GenericRequest extends FormRequest
|
||||
*/
|
||||
private function parseBills(): void
|
||||
{
|
||||
if (null === $this->bills) {
|
||||
$this->bills = new Collection;
|
||||
}
|
||||
if (0 !== $this->bills->count()) {
|
||||
return;
|
||||
}
|
||||
@@ -156,9 +150,6 @@ class GenericRequest extends FormRequest
|
||||
*/
|
||||
private function parseBudgets(): void
|
||||
{
|
||||
if (null === $this->budgets) {
|
||||
$this->budgets = new Collection;
|
||||
}
|
||||
if (0 !== $this->budgets->count()) {
|
||||
return;
|
||||
}
|
||||
@@ -191,9 +182,6 @@ class GenericRequest extends FormRequest
|
||||
*/
|
||||
private function parseCategories(): void
|
||||
{
|
||||
if (null === $this->categories) {
|
||||
$this->categories = new Collection;
|
||||
}
|
||||
if (0 !== $this->categories->count()) {
|
||||
return;
|
||||
}
|
||||
@@ -284,9 +272,6 @@ class GenericRequest extends FormRequest
|
||||
*/
|
||||
private function parseTags(): void
|
||||
{
|
||||
if (null === $this->tags) {
|
||||
$this->tags = new Collection;
|
||||
}
|
||||
if (0 !== $this->tags->count()) {
|
||||
return;
|
||||
}
|
||||
@@ -311,7 +296,7 @@ class GenericRequest extends FormRequest
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
// this is cheating but it works:
|
||||
// this is cheating but it works to initialize the collections.
|
||||
$this->accounts = new Collection;
|
||||
$this->budgets = new Collection;
|
||||
$this->categories = new Collection;
|
||||
|
@@ -79,7 +79,7 @@ class StoreRequest extends FormRequest
|
||||
{
|
||||
$return = [];
|
||||
// transaction data:
|
||||
/** @var array $transactions */
|
||||
/** @var array|null $transactions */
|
||||
$transactions = $this->get('transactions');
|
||||
if (null === $transactions) {
|
||||
return [];
|
||||
@@ -101,7 +101,7 @@ class StoreRequest extends FormRequest
|
||||
{
|
||||
$return = [];
|
||||
// repetition data:
|
||||
/** @var array $repetitions */
|
||||
/** @var array|null $repetitions */
|
||||
$repetitions = $this->get('repetitions');
|
||||
if (null === $repetitions) {
|
||||
return [];
|
||||
|
@@ -84,7 +84,7 @@ class UpdateRequest extends FormRequest
|
||||
{
|
||||
$return = [];
|
||||
// repetition data:
|
||||
/** @var array $repetitions */
|
||||
/** @var array|null $repetitions */
|
||||
$repetitions = $this->get('repetitions');
|
||||
if (null === $repetitions) {
|
||||
return null;
|
||||
@@ -126,7 +126,7 @@ class UpdateRequest extends FormRequest
|
||||
{
|
||||
$return = [];
|
||||
// transaction data:
|
||||
/** @var array $transactions */
|
||||
/** @var array|null $transactions */
|
||||
$transactions = $this->get('transactions');
|
||||
if (null === $transactions) {
|
||||
return null;
|
||||
|
@@ -150,10 +150,7 @@ class UpdateRequest extends FormRequest
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var int $index
|
||||
* @var array $transaction
|
||||
*/
|
||||
/** @var array $transaction */
|
||||
foreach ($this->get('transactions') as $transaction) {
|
||||
// default response is to update nothing in the transaction:
|
||||
$current = [];
|
||||
|
@@ -117,12 +117,6 @@ class UpdateRequest extends FormRequest
|
||||
$validator->errors()->add('outward_id', 'Inward ID must be different from outward ID.');
|
||||
}
|
||||
|
||||
if (null === $inward) {
|
||||
$validator->errors()->add('inward_id', 'This is not a valid inward journal.');
|
||||
}
|
||||
if (null === $outward) {
|
||||
$validator->errors()->add('inward_id', 'This is not a valid outward journal.');
|
||||
}
|
||||
$inDB = $repository->findSpecificLink($existing->linkType, $inward, $outward);
|
||||
if (null === $inDB) {
|
||||
return;
|
||||
|
@@ -214,14 +214,6 @@ class ApplyRules extends Command
|
||||
$finalList = new Collection;
|
||||
$accountList = explode(',', $accountString);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (0 === count($accountList)) {
|
||||
$this->error('Please use the --accounts option to indicate the accounts to apply rules to.');
|
||||
|
||||
return false;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$accountRepository->setUser($this->getUser());
|
||||
@@ -255,12 +247,7 @@ class ApplyRules extends Command
|
||||
return true;
|
||||
}
|
||||
$ruleGroupList = explode(',', $ruleGroupString);
|
||||
// @codeCoverageIgnoreStart
|
||||
if (0 === count($ruleGroupList)) {
|
||||
// can be empty.
|
||||
return true;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
foreach ($ruleGroupList as $ruleGroupId) {
|
||||
$ruleGroup = $this->ruleGroupRepository->find((int)$ruleGroupId);
|
||||
if ($ruleGroup->active) {
|
||||
@@ -286,14 +273,6 @@ class ApplyRules extends Command
|
||||
}
|
||||
$ruleList = explode(',', $ruleString);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (0 === count($ruleList)) {
|
||||
// can be empty.
|
||||
|
||||
return true;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
foreach ($ruleList as $ruleId) {
|
||||
$rule = $this->ruleRepository->find((int)$ruleId);
|
||||
if (null !== $rule && $rule->active) {
|
||||
|
@@ -65,9 +65,8 @@ class Cron extends Command
|
||||
$date = null;
|
||||
try {
|
||||
$date = new Carbon($this->option('date'));
|
||||
} catch (InvalidArgumentException | Exception $e) {
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$this->error(sprintf('"%s" is not a valid date', $this->option('date')));
|
||||
$e->getMessage();
|
||||
}
|
||||
$force = (bool)$this->option('force');
|
||||
|
||||
@@ -127,13 +126,15 @@ class Cron extends Command
|
||||
$recurring->setDate($date);
|
||||
}
|
||||
|
||||
$result = $recurring->fire();
|
||||
|
||||
if (false === $result) {
|
||||
$this->line('The recurring transaction cron job did not fire.');
|
||||
$recurring->fire();
|
||||
if($recurring->jobErrored) {
|
||||
$this->error(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message));
|
||||
}
|
||||
if (true === $result) {
|
||||
$this->line('The recurring transaction cron job fired successfully.');
|
||||
if($recurring->jobFired) {
|
||||
$this->error(sprintf('"Create recurring transactions" cron fired: %s', $recurring->message));
|
||||
}
|
||||
if($recurring->jobSucceeded) {
|
||||
$this->error(sprintf('"Create recurring transactions" cron ran with success: %s', $recurring->message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +143,6 @@ class Cron extends Command
|
||||
* @param Carbon|null $date
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function autoBudgetCronJob(bool $force, ?Carbon $date): void
|
||||
{
|
||||
@@ -153,13 +153,16 @@ class Cron extends Command
|
||||
$autoBudget->setDate($date);
|
||||
}
|
||||
|
||||
$result = $autoBudget->fire();
|
||||
$autoBudget->fire();
|
||||
|
||||
if (false === $result) {
|
||||
$this->line('The auto budget cron job did not fire.');
|
||||
if($autoBudget->jobErrored) {
|
||||
$this->error(sprintf('Error in "create auto budgets" cron: %s', $autoBudget->message));
|
||||
}
|
||||
if (true === $result) {
|
||||
$this->line('The auto budget cron job fired successfully.');
|
||||
if($autoBudget->jobFired) {
|
||||
$this->error(sprintf('"Create auto budgets" cron fired: %s', $autoBudget->message));
|
||||
}
|
||||
if($autoBudget->jobSucceeded) {
|
||||
$this->error(sprintf('"Create auto budgets" cron ran with success: %s', $autoBudget->message));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -167,6 +170,8 @@ class Cron extends Command
|
||||
/**
|
||||
* @param bool $force
|
||||
* @param Carbon|null $date
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function telemetryCronJob(bool $force, ?Carbon $date): void
|
||||
{
|
||||
@@ -182,13 +187,16 @@ class Cron extends Command
|
||||
$telemetry->setDate($date);
|
||||
}
|
||||
|
||||
$result = $telemetry->fire();
|
||||
$telemetry->fire();
|
||||
|
||||
if (false === $result) {
|
||||
$this->line('The telemetry cron job did not fire.');
|
||||
if($telemetry->jobErrored) {
|
||||
$this->error(sprintf('Error in "send telemetry" cron: %s', $telemetry->message));
|
||||
}
|
||||
if (true === $result) {
|
||||
$this->line('The telemetry cron job fired successfully.');
|
||||
if($telemetry->jobFired) {
|
||||
$this->error(sprintf('"Send telemetry" cron fired: %s', $telemetry->message));
|
||||
}
|
||||
if($telemetry->jobSucceeded) {
|
||||
$this->error(sprintf('"Send telemetry" cron ran with success: %s', $telemetry->message));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -148,7 +148,7 @@ class AccountCurrencies extends Command
|
||||
}
|
||||
Log::debug(sprintf('Users currency pref is %s', $defaultCurrencyCode));
|
||||
|
||||
/** @var TransactionCurrency $defaultCurrency */
|
||||
/** @var TransactionCurrency|null $defaultCurrency */
|
||||
$defaultCurrency = TransactionCurrency::where('code', $defaultCurrencyCode)->first();
|
||||
|
||||
if (null === $defaultCurrency) {
|
||||
|
@@ -73,11 +73,8 @@ class AppendBudgetLimitPeriods extends Command
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||
if (null !== $configVar) {
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -87,11 +87,7 @@ class BackToJournals extends Command
|
||||
private function isMigrated(): bool
|
||||
{
|
||||
$configVar = app('fireflyconfig')->get(MigrateToGroups::CONFIG_NAME, false);
|
||||
if (null !== $configVar) {
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,11 +96,7 @@ class BackToJournals extends Command
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||
if (null !== $configVar) {
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -39,6 +39,7 @@ use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\View\View;
|
||||
use Log;
|
||||
use DB;
|
||||
|
||||
/**
|
||||
* Class HomeController.
|
||||
|
@@ -22,7 +22,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Eloquent;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
@@ -33,7 +32,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
@@ -53,7 +51,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property int $order
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\AccountMeta[] $accountMeta
|
||||
* @property-read int|null $account_meta_count
|
||||
* @property-read \FireflyIII\Models\AccountType $accountType
|
||||
* @property \FireflyIII\Models\AccountType $accountType
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Attachment[] $attachments
|
||||
* @property-read int|null $attachments_count
|
||||
* @property-read string $account_number
|
||||
|
@@ -25,6 +25,7 @@ namespace FireflyIII\Support\Cronjobs;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
|
||||
/**
|
||||
* Class AbstractCronjob
|
||||
@@ -45,8 +46,6 @@ abstract class AbstractCronjob
|
||||
|
||||
/**
|
||||
* AbstractCronjob constructor.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@@ -66,7 +66,7 @@ class FireflyConfig
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param null $default
|
||||
* @param bool|string|int|null $default
|
||||
*
|
||||
* @return Configuration|null
|
||||
* @throws FireflyException
|
||||
|
@@ -35,7 +35,7 @@ trait OBValidation
|
||||
{
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param $accountName
|
||||
* @param mixed $accountName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@@ -33,7 +33,7 @@ trait TransferValidation
|
||||
{
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param $accountName
|
||||
* @param mixed $accountName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@@ -58,14 +58,12 @@ class AccountValidator
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->createMode = false;
|
||||
$this->destError = 'No error yet.';
|
||||
$this->sourceError = 'No error yet.';
|
||||
$this->combinations = config('firefly.source_dests');
|
||||
$this->source = null;
|
||||
$this->destination = null;
|
||||
|
||||
/** @var AccountRepositoryInterface accountRepository */
|
||||
$this->createMode = false;
|
||||
$this->destError = 'No error yet.';
|
||||
$this->sourceError = 'No error yet.';
|
||||
$this->combinations = config('firefly.source_dests');
|
||||
$this->source = null;
|
||||
$this->destination = null;
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
}
|
||||
|
||||
|
@@ -57,7 +57,7 @@ trait ValidatesAutoBudgetRequest
|
||||
if ('' === $period) {
|
||||
$validator->errors()->add('auto_budget_period', (string)trans('validation.auto_budget_period_mandatory'));
|
||||
}
|
||||
if (null !== $amount && null !== $currencyId && null !== $currencyCode && '' === $currencyCode && '' === $currencyId) {
|
||||
if (null !== $amount && null !== $currencyId && null !== $currencyCode && '' === $currencyCode && 0 === $currencyId) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.require_currency_info'));
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Validation;
|
||||
|
||||
use Illuminate\Validation\Validator;
|
||||
use Log;
|
||||
|
||||
@@ -45,7 +46,11 @@ trait CurrencyValidation
|
||||
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
// if foreign amount is present, then the currency must be as well.
|
||||
if (isset($transaction['foreign_amount']) && !(isset($transaction['foreign_currency_id']) || isset($transaction['foreign_currency_code']))
|
||||
if (array_key_exists('foreign_amount', $transaction)
|
||||
&& !(array_key_exists('foreign_currency_id', $transaction)
|
||||
|| array_key_exists(
|
||||
'foreign_currency_code', $transaction
|
||||
))
|
||||
&& 0 !== bccomp('0', $transaction['foreign_amount'])
|
||||
) {
|
||||
$validator->errors()->add(
|
||||
@@ -54,7 +59,10 @@ trait CurrencyValidation
|
||||
);
|
||||
}
|
||||
// if the currency is present, then the amount must be present as well.
|
||||
if ((isset($transaction['foreign_currency_id']) || isset($transaction['foreign_currency_code'])) && !isset($transaction['foreign_amount'])) {
|
||||
if ((array_key_exists('foreign_currency_id', $transaction) || array_key_exists('foreign_currency_code', $transaction))
|
||||
&& !array_key_exists(
|
||||
'foreign_amount', $transaction
|
||||
)) {
|
||||
$validator->errors()->add(
|
||||
'transactions.' . $index . '.foreign_amount',
|
||||
(string)trans('validation.require_currency_amount')
|
||||
|
@@ -52,14 +52,14 @@ use function is_string;
|
||||
class FireflyValidator extends Validator
|
||||
{
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate2faCode($attribute, $value): bool
|
||||
{
|
||||
if (!is_string($value) || null === $value || 6 !== strlen($value)) {
|
||||
if (null === $value || !is_string($value) || 6 !== strlen($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -88,8 +88,8 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -108,14 +108,14 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateIban($attribute, $value): bool
|
||||
{
|
||||
if (!is_string($value) || null === $value || strlen($value) < 6) {
|
||||
if (null === $value || !is_string($value) || strlen($value) < 6) {
|
||||
return false;
|
||||
}
|
||||
// strip spaces
|
||||
@@ -186,9 +186,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -201,9 +201,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -216,9 +216,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -235,9 +235,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $attribute
|
||||
* @param string $attribute
|
||||
*
|
||||
* @param string $value
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -309,8 +309,8 @@ class FireflyValidator extends Validator
|
||||
/**
|
||||
* $attribute has the format triggers.%d.value.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string $value
|
||||
* @param string $attribute
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -375,15 +375,15 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateSecurePassword($attribute, $value): bool
|
||||
{
|
||||
$verify = false;
|
||||
if (isset($this->data['verify_password'])) {
|
||||
if (array_key_exists('verify_password', $this->data)) {
|
||||
$verify = 1 === (int)$this->data['verify_password'];
|
||||
}
|
||||
if ($verify) {
|
||||
@@ -397,9 +397,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -410,21 +410,20 @@ class FireflyValidator extends Validator
|
||||
if (!auth()->check()) {
|
||||
return $this->validateAccountAnonymously();
|
||||
}
|
||||
if (isset($this->data['objectType'])) {
|
||||
|
||||
if (array_key_exists('objectType', $this->data)) {
|
||||
return $this->validateByAccountTypeString($value, $parameters, $this->data['objectType']);
|
||||
}
|
||||
if (isset($this->data['type'])) {
|
||||
if (array_key_exists('type', $this->data)) {
|
||||
return $this->validateByAccountTypeString($value, $parameters, $this->data['type']);
|
||||
}
|
||||
if (isset($this->data['account_type_id'])) {
|
||||
if (array_key_exists('account_type_id', $this->data)) {
|
||||
return $this->validateByAccountTypeId($value, $parameters);
|
||||
}
|
||||
$parameterId = $parameters[0] ?? null;
|
||||
if (null !== $parameterId) {
|
||||
return $this->validateByParameterId((int)$parameterId, $value);
|
||||
}
|
||||
if (isset($this->data['id'])) {
|
||||
if (array_key_exists('id', $this->data)) {
|
||||
return $this->validateByAccountId($value);
|
||||
}
|
||||
|
||||
@@ -437,7 +436,7 @@ class FireflyValidator extends Validator
|
||||
*/
|
||||
private function validateAccountAnonymously(): bool
|
||||
{
|
||||
if (!isset($this->data['user_id'])) {
|
||||
if (!array_key_exists('user_id',$this->data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -466,7 +465,7 @@ class FireflyValidator extends Validator
|
||||
*/
|
||||
private function validateByAccountTypeString(string $value, array $parameters, string $type): bool
|
||||
{
|
||||
/** @var array $search */
|
||||
/** @var array|null $search */
|
||||
$search = Config::get('firefly.accountTypeByIdentifier.' . $type);
|
||||
|
||||
if (null === $search) {
|
||||
@@ -491,8 +490,8 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -516,7 +515,8 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param int $accountId
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -528,7 +528,6 @@ class FireflyValidator extends Validator
|
||||
$type = $existingAccount->accountType;
|
||||
$ignore = $existingAccount->id;
|
||||
|
||||
/** @var Collection $set */
|
||||
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first();
|
||||
@@ -537,7 +536,7 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -549,7 +548,6 @@ class FireflyValidator extends Validator
|
||||
$type = $existingAccount->accountType;
|
||||
$ignore = $existingAccount->id;
|
||||
|
||||
/** @var Collection $set */
|
||||
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first();
|
||||
@@ -568,9 +566,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -602,6 +600,13 @@ class FireflyValidator extends Validator
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $something
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueExistingWebhook($value, $parameters, $something): bool
|
||||
{
|
||||
$existingId = (int)($something[0] ?? 0);
|
||||
@@ -614,7 +619,7 @@ class FireflyValidator extends Validator
|
||||
if (auth()->check()) {
|
||||
// get existing webhook value:
|
||||
if (0 !== $existingId) {
|
||||
/** @var Webhook $webhook */
|
||||
/** @var Webhook|null $webhook */
|
||||
$webhook = auth()->user()->webhooks()->find($existingId);
|
||||
if (null === $webhook) {
|
||||
return false;
|
||||
@@ -645,15 +650,15 @@ class FireflyValidator extends Validator
|
||||
|
||||
/**
|
||||
*
|
||||
* Validate an object and its unicity. Checks for encryption / encrypted values as well.
|
||||
* Validate an object and its uniqueness. Checks for encryption / encrypted values as well.
|
||||
*
|
||||
* parameter 0: the table
|
||||
* parameter 1: the field
|
||||
* parameter 2: an id to ignore (when editing)
|
||||
*
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -667,7 +672,7 @@ class FireflyValidator extends Validator
|
||||
* ID field, set that field to be the $exclude.
|
||||
*/
|
||||
$data = $this->getData();
|
||||
if (!isset($parameters[2]) && isset($data['id']) && (int)$data['id'] > 0) {
|
||||
if (!array_key_exists(2, $parameters) && array_key_exists('id', $data) && (int)$data['id'] > 0) {
|
||||
$exclude = (int)$data['id'];
|
||||
}
|
||||
// get entries from table
|
||||
@@ -686,9 +691,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -707,11 +712,11 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* TODO this method does not need a for loop
|
||||
* TODO this method does not need a for loop
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -738,8 +743,8 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $parameters
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@@ -59,7 +59,7 @@ trait RecurrenceValidation
|
||||
if (null !== $recurrence) {
|
||||
Log::debug('There is a recurrence in the route.');
|
||||
// ok so we have a recurrence should be able to extract type somehow.
|
||||
/** @var RecurrenceTransaction $first */
|
||||
/** @var RecurrenceTransaction|null $first */
|
||||
$first = $recurrence->recurrenceTransactions()->first();
|
||||
if (null !== $first) {
|
||||
$transactionType = $first->transactionType ? $first->transactionType->type : 'withdrawal';
|
||||
@@ -91,7 +91,7 @@ trait RecurrenceValidation
|
||||
continue;
|
||||
}
|
||||
// validate source account.
|
||||
$sourceId = isset($transaction['source_id']) ? (int)$transaction['source_id'] : null;
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null;
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
$validSource = $accountValidator->validateSource($sourceId, $sourceName, null);
|
||||
|
||||
@@ -103,7 +103,7 @@ trait RecurrenceValidation
|
||||
return;
|
||||
}
|
||||
// validate destination account
|
||||
$destinationId = isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null;
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null;
|
||||
$destinationName = $transaction['destination_name'] ?? null;
|
||||
$validDestination = $accountValidator->validateDestination($destinationId, $destinationName, null);
|
||||
// do something with result:
|
||||
|
@@ -100,9 +100,9 @@ trait TransactionValidation
|
||||
$accountValidator->setTransactionType($transactionType);
|
||||
|
||||
// validate source account.
|
||||
$sourceId = isset($transaction['source_id']) ? (int)$transaction['source_id'] : null;
|
||||
$sourceName = isset($transaction['source_name']) ? (string)$transaction['source_name'] : null;
|
||||
$sourceIban = isset($transaction['source_iban']) ? (string)$transaction['source_iban'] : null;
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null;
|
||||
$sourceName = array_key_exists('source_name', $transaction) ? (string)$transaction['source_name'] : null;
|
||||
$sourceIban = array_key_exists('source_iban', $transaction) ? (string)$transaction['source_iban'] : null;
|
||||
$validSource = $accountValidator->validateSource($sourceId, $sourceName, $sourceIban);
|
||||
|
||||
// do something with result:
|
||||
@@ -113,9 +113,9 @@ trait TransactionValidation
|
||||
return;
|
||||
}
|
||||
// validate destination account
|
||||
$destinationId = isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null;
|
||||
$destinationName = isset($transaction['destination_name']) ? (string)$transaction['destination_name'] : null;
|
||||
$destinationIban = isset($transaction['destination_iban']) ? (string)$transaction['destination_iban'] : null;
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null;
|
||||
$destinationName = array_key_exists('destination_name', $transaction) ? (string)$transaction['destination_name'] : null;
|
||||
$destinationIban = array_key_exists('destination_iban', $transaction) ? (string)$transaction['destination_iban'] : null;
|
||||
$validDestination = $accountValidator->validateDestination($destinationId, $destinationName, $destinationIban);
|
||||
// do something with result:
|
||||
if (false === $validDestination) {
|
||||
@@ -155,10 +155,11 @@ trait TransactionValidation
|
||||
Log::debug('Now validating single account update in validateSingleUpdate()');
|
||||
|
||||
// if no account types are given, just skip the check.
|
||||
if (!isset($transaction['source_id'])
|
||||
&& !isset($transaction['source_name'])
|
||||
&& !isset($transaction['destination_id'])
|
||||
&& !isset($transaction['destination_name'])) {
|
||||
if (
|
||||
!array_key_exists('source_id', $transaction)
|
||||
&& !array_key_exists('source_name', $transaction)
|
||||
&& !array_key_exists('destination_id', $transaction)
|
||||
&& !array_key_exists('destination_name', $transaction)) {
|
||||
Log::debug('No account data has been submitted so will not validating account info.');
|
||||
|
||||
return;
|
||||
@@ -362,7 +363,7 @@ trait TransactionValidation
|
||||
if (0 === $journalId) {
|
||||
return 'invalid';
|
||||
}
|
||||
/** @var TransactionJournal $journal */
|
||||
/** @var TransactionJournal|null $journal */
|
||||
$journal = TransactionJournal::with(['transactionType'])->find($journalId);
|
||||
if (null !== $journal) {
|
||||
return strtolower($journal->transactionType->type);
|
||||
|
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* EmptyFactory.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);
|
||||
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
use FireflyIII\User;
|
||||
|
||||
$factory->define(User::class, function (Faker $faker) {
|
||||
return [
|
||||
//
|
||||
];
|
||||
});
|
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* AccountFactory.php
|
||||
* Copyright (c) 2020 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);
|
||||
|
||||
namespace Database\Factories\FireflyIII\Models;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* Class AccountFactory
|
||||
*/
|
||||
class AccountFactory extends Factory
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Account::class;
|
||||
|
||||
/**
|
||||
* @return AccountFactory
|
||||
*/
|
||||
public function asset()
|
||||
{
|
||||
return $this->state(
|
||||
function () {
|
||||
return [
|
||||
'account_type_id' => 3,
|
||||
];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'user_id' => 1,
|
||||
'account_type_id' => 1,
|
||||
'name' => $this->faker->words(3, true),
|
||||
'virtual_balance' => '0',
|
||||
'active' => 1,
|
||||
'encrypted' => 0,
|
||||
'order' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AccountFactory
|
||||
*/
|
||||
public function expense()
|
||||
{
|
||||
return $this->state(
|
||||
function () {
|
||||
return [
|
||||
'account_type_id' => 4,
|
||||
];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AccountFactory
|
||||
*/
|
||||
public function initialBalance()
|
||||
{
|
||||
return $this->state(
|
||||
function () {
|
||||
return [
|
||||
'account_type_id' => 6,
|
||||
];
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* TransactionFactory.php
|
||||
* Copyright (c) 2020 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);
|
||||
|
||||
namespace Database\Factories\FireflyIII\Models;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* Class TransactionFactory
|
||||
*/
|
||||
class TransactionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Transaction::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'transaction_journal_id' => 0,
|
||||
'account_id' => 0,
|
||||
'amount' => 5,
|
||||
];
|
||||
}
|
||||
}
|
@@ -1,123 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* TransactionJournalFactory.php
|
||||
* Copyright (c) 2020 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);
|
||||
|
||||
namespace Database\Factories\FireflyIII\Models;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* Class TransactionJournalFactory
|
||||
*/
|
||||
class TransactionJournalFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = TransactionJournal::class;
|
||||
|
||||
/**
|
||||
* @return Factory
|
||||
*/
|
||||
public function brokenOpeningBalance()
|
||||
{
|
||||
return $this->state(
|
||||
function () {
|
||||
return [
|
||||
'transaction_type_id' => 4,
|
||||
];
|
||||
}
|
||||
)->afterCreating(
|
||||
function (TransactionJournal $journal) {
|
||||
$ob1 = Account::factory(Account::class)->initialBalance()->create();
|
||||
$ob2 = Account::factory(Account::class)->initialBalance()->create();
|
||||
|
||||
Transaction::factory()->create(
|
||||
[
|
||||
'account_id' => $ob1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => '5',
|
||||
]
|
||||
);
|
||||
Transaction::factory()->create(
|
||||
[
|
||||
'account_id' => $ob2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => '5',
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'user_id' => 1,
|
||||
'transaction_type_id' => 1,
|
||||
'description' => $this->faker->words(3, true),
|
||||
'tag_count' => 0,
|
||||
'date' => $this->faker->date('Y-m-d'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory
|
||||
*/
|
||||
public function openingBalance()
|
||||
{
|
||||
return $this
|
||||
->state(fn() => ['transaction_type_id' => 4])
|
||||
->afterCreating(
|
||||
function (TransactionJournal $journal) {
|
||||
// fix factory
|
||||
$obAccount = Account::factory(Account::class)->initialBalance()->create();
|
||||
$assetAccount = Account::factory(Account::class)->asset()->create();
|
||||
Transaction::factory()->create(
|
||||
[
|
||||
'account_id' => $obAccount->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => '5',
|
||||
]
|
||||
);
|
||||
Transaction::factory()->create(
|
||||
[
|
||||
'account_id' => $assetAccount->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => '-5',
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@@ -51,7 +51,7 @@ class AccountTypeSeeder extends Seeder
|
||||
try {
|
||||
AccountType::create(['type' => $type]);
|
||||
} catch (PDOException $e) {
|
||||
// dont care.
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -63,7 +63,7 @@ class LinkTypeSeeder extends Seeder
|
||||
try {
|
||||
LinkType::create($type);
|
||||
} catch (PDOException $e) {
|
||||
// dont care
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ class PermissionSeeder extends Seeder
|
||||
try {
|
||||
Role::create($role);
|
||||
} catch (PDOException $e) {
|
||||
// dont care
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -81,7 +81,7 @@ class TransactionCurrencySeeder extends Seeder
|
||||
try {
|
||||
TransactionCurrency::create($currency);
|
||||
} catch (PDOException $e) {
|
||||
// dont care
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ class TransactionTypeSeeder extends Seeder
|
||||
try {
|
||||
TransactionType::create(['type' => $type]);
|
||||
} catch (PDOException $e) {
|
||||
// dont care
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user