mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 04:19:12 +00:00
Code cleanup
This commit is contained in:
@@ -39,6 +39,20 @@ class AccountFactory extends Factory
|
||||
*/
|
||||
protected $model = Account::class;
|
||||
|
||||
/**
|
||||
* @return AccountFactory
|
||||
*/
|
||||
public function asset()
|
||||
{
|
||||
return $this->state(
|
||||
function () {
|
||||
return [
|
||||
'account_type_id' => 3,
|
||||
];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -58,12 +72,12 @@ class AccountFactory extends Factory
|
||||
/**
|
||||
* @return AccountFactory
|
||||
*/
|
||||
public function asset()
|
||||
public function expense()
|
||||
{
|
||||
return $this->state(
|
||||
function () {
|
||||
return [
|
||||
'account_type_id' => 3,
|
||||
'account_type_id' => 4,
|
||||
];
|
||||
}
|
||||
);
|
||||
@@ -83,19 +97,5 @@ class AccountFactory extends Factory
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AccountFactory
|
||||
*/
|
||||
public function expense()
|
||||
{
|
||||
return $this->state(
|
||||
function () {
|
||||
return [
|
||||
'account_type_id' => 4,
|
||||
];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -41,53 +41,7 @@ class TransactionJournalFactory extends Factory
|
||||
protected $model = TransactionJournal::class;
|
||||
|
||||
/**
|
||||
* 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 \Illuminate\Database\Eloquent\Factories\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',
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
* @return Factory
|
||||
*/
|
||||
public function brokenOpeningBalance()
|
||||
{
|
||||
@@ -120,4 +74,50 @@ class TransactionJournalFactory extends Factory
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
]
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user