Code cleanup

This commit is contained in:
James Cole
2021-03-21 09:15:40 +01:00
parent da1751940e
commit 206845575c
317 changed files with 7418 additions and 7362 deletions

View File

@@ -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,
];
}
);
}
}

View File

@@ -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',
]
);
}
);
}
}