akaunting 3.0 (the last dance)

This commit is contained in:
Burak Civan
2022-06-01 10:15:55 +03:00
parent cead09f6d4
commit d9c0764572
3812 changed files with 126831 additions and 102949 deletions

View File

@ -5,6 +5,7 @@ namespace Database\Factories;
use App\Abstracts\Factory;
use App\Models\Banking\Transaction as Model;
use App\Traits\Transactions;
use App\Utilities\Date;
class Transaction extends Factory
{
@ -17,6 +18,13 @@ class Transaction extends Factory
*/
protected $model = Model::class;
/**
* The type of the model.
*
* @var string
*/
protected $type = 'income';
/**
* Define the model's default state.
*
@ -25,13 +33,14 @@ class Transaction extends Factory
public function definition()
{
$types = array_merge($this->getIncomeTypes(), $this->getExpenseTypes());
$type = $this->faker->randomElement($types);
$this->type = $this->faker->randomElement($types);
$category_type = in_array($type, $this->getIncomeTypes()) ? 'income' : 'expense';
$category_type = in_array($this->type, $this->getIncomeTypes()) ? 'income' : 'expense';
return [
'company_id' => $this->company->id,
'type' => $type,
'type' => $this->type,
'number' => $this->getNextTransactionNumber(),
'account_id' => setting('default.account'),
'paid_at' => $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'),
'amount' => $this->faker->randomFloat(2, 1, 1000),
@ -70,4 +79,26 @@ class Transaction extends Factory
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
]);
}
/**
* Indicate that the model is recurring.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function recurring()
{
return $this->state([
'type' => $this->getRawAttribute('type') . '-recurring',
'number' => $this->getNextTransactionNumber('-recurring'),
'recurring_started_at' => $this->getRawAttribute('paid_at'),
'recurring_frequency' => 'daily',
'recurring_custom_frequency' => 'daily',
'recurring_interval' => '1',
'recurring_limit' => 'date',
'recurring_limit_date' => Date::now()->addDay(7)->format('Y-m-d'),
'disabled_transaction_paid' => "Auto-generated",
'disabled_transaction_number' => "Auto-generated",
'real_type' => $this->getRawAttribute('type'),
]);
}
}