akaunting 3.0 (the last dance)
This commit is contained in:
@ -21,8 +21,11 @@ class Account extends Factory
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$types = ['bank', 'credit_card'];
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'type' => $this->faker->randomElement($types),
|
||||
'name' => $this->faker->text(15),
|
||||
'number' => (string) $this->faker->iban(),
|
||||
'currency_code' => $this->company->currencies()->enabled()->get()->random(1)->pluck('code')->first(),
|
||||
|
95
database/factories/Company.php
Normal file
95
database/factories/Company.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Abstracts\Factory;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\Common\Company as Model;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class Company extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Model::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'enabled' => $this->faker->boolean ? 1 : 0,
|
||||
'created_from' => 'core::factory',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model is enabled.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
public function enabled()
|
||||
{
|
||||
return $this->state([
|
||||
'enabled' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model is disabled.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
public function disabled()
|
||||
{
|
||||
return $this->state([
|
||||
'enabled' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the model factory.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function configure()
|
||||
{
|
||||
return $this->afterCreating(function (Model $company) {
|
||||
$company->makeCurrent();
|
||||
|
||||
app()->setLocale('en-GB');
|
||||
|
||||
// Company seeds
|
||||
Artisan::call('company:seed', [
|
||||
'company' => $company->id
|
||||
]);
|
||||
|
||||
$user = User::first();
|
||||
|
||||
$user->companies()->attach($company->id);
|
||||
|
||||
// User seeds
|
||||
Artisan::call('user:seed', [
|
||||
'user' => $user->id,
|
||||
'company' => $company->id,
|
||||
]);
|
||||
|
||||
setting()->set([
|
||||
'company.name' => $this->faker->text(15),
|
||||
'company.address' => 'New Street 1254',
|
||||
'company.city' => 'London',
|
||||
'company.country' => $this->faker->countryCode,
|
||||
'default.currency' => 'USD',
|
||||
'default.locale' => 'en-GB',
|
||||
]);
|
||||
|
||||
setting()->save();
|
||||
});
|
||||
}
|
||||
}
|
@ -25,16 +25,18 @@ class Contact extends Factory
|
||||
public function definition()
|
||||
{
|
||||
$types = array_merge($this->getCustomerTypes(), $this->getVendorTypes());
|
||||
$countries = array_keys(trans('countries'));
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'type' => $this->faker->randomElement($types),
|
||||
'name' => $this->faker->name,
|
||||
'email' => $this->faker->unique()->safeEmail,
|
||||
'email' => $this->faker->freeEmail,
|
||||
'user_id' => null,
|
||||
'tax_number' => $this->faker->randomNumber(9),
|
||||
'phone' => $this->faker->phoneNumber,
|
||||
'address' => $this->faker->address,
|
||||
'country' => $this->faker->randomElement($countries),
|
||||
'website' => 'https://akaunting.com',
|
||||
'currency_code' => setting('default.currency'),
|
||||
'reference' => $this->faker->text(5),
|
||||
|
@ -14,12 +14,15 @@ use App\Models\Common\Contact;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Document\Document as Model;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Traits\Documents;
|
||||
use App\Utilities\Date;
|
||||
use App\Utilities\Overrider;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class Document extends AbstractFactory
|
||||
{
|
||||
use Documents;
|
||||
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
@ -35,7 +38,7 @@ class Document extends AbstractFactory
|
||||
public function definition()
|
||||
{
|
||||
$issued_at = $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s');
|
||||
$due_at = Date::parse($issued_at)->addDays($this->faker->randomNumber(3))->format('Y-m-d H:i:s');
|
||||
$due_at = Date::parse($issued_at)->addDays($this->faker->randomNumber(2))->format('Y-m-d H:i:s');
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
@ -54,30 +57,28 @@ class Document extends AbstractFactory
|
||||
*/
|
||||
public function invoice(): Factory
|
||||
{
|
||||
return $this->state(function (array $attributes): array {
|
||||
$contacts = Contact::customer()->enabled()->get();
|
||||
$contacts = Contact::customer()->enabled()->get();
|
||||
|
||||
if ($contacts->count()) {
|
||||
$contact = $contacts->random(1)->first();
|
||||
} else {
|
||||
$contact = Contact::factory()->customer()->enabled()->create();
|
||||
}
|
||||
if ($contacts->count()) {
|
||||
$contact = $contacts->random(1)->first();
|
||||
} else {
|
||||
$contact = Contact::factory()->customer()->enabled()->create();
|
||||
}
|
||||
|
||||
$statuses = ['draft', 'sent', 'viewed', 'partial', 'paid', 'cancelled'];
|
||||
$statuses = ['draft', 'sent', 'viewed', 'partial', 'paid', 'cancelled'];
|
||||
|
||||
return [
|
||||
'type' => Model::INVOICE_TYPE,
|
||||
'document_number' => setting('invoice.number_prefix') . $this->faker->randomNumber(setting('invoice.number_digit')),
|
||||
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
|
||||
'contact_id' => $contact->id,
|
||||
'contact_name' => $contact->name,
|
||||
'contact_email' => $contact->email,
|
||||
'contact_tax_number' => $contact->tax_number,
|
||||
'contact_phone' => $contact->phone,
|
||||
'contact_address' => $contact->address,
|
||||
'status' => $this->faker->randomElement($statuses),
|
||||
];
|
||||
});
|
||||
return $this->state([
|
||||
'type' => Model::INVOICE_TYPE,
|
||||
'document_number' => $this->getNextDocumentNumber(Model::INVOICE_TYPE),
|
||||
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
|
||||
'contact_id' => $contact->id,
|
||||
'contact_name' => $contact->name,
|
||||
'contact_email' => $contact->email,
|
||||
'contact_tax_number' => $contact->tax_number,
|
||||
'contact_phone' => $contact->phone,
|
||||
'contact_address' => $contact->address,
|
||||
'status' => $this->faker->randomElement($statuses),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,30 +86,28 @@ class Document extends AbstractFactory
|
||||
*/
|
||||
public function bill(): Factory
|
||||
{
|
||||
return $this->state(function (array $attributes): array {
|
||||
$contacts = Contact::vendor()->enabled()->get();
|
||||
$contacts = Contact::vendor()->enabled()->get();
|
||||
|
||||
if ($contacts->count()) {
|
||||
$contact = $contacts->random(1)->first();
|
||||
} else {
|
||||
$contact = Contact::factory()->vendor()->enabled()->create();
|
||||
}
|
||||
if ($contacts->count()) {
|
||||
$contact = $contacts->random(1)->first();
|
||||
} else {
|
||||
$contact = Contact::factory()->vendor()->enabled()->create();
|
||||
}
|
||||
|
||||
$statuses = ['draft', 'received', 'partial', 'paid', 'cancelled'];
|
||||
$statuses = ['draft', 'received', 'partial', 'paid', 'cancelled'];
|
||||
|
||||
return [
|
||||
'type' => Model::BILL_TYPE,
|
||||
'document_number' => setting('bill.number_prefix') . $this->faker->randomNumber(setting('bill.number_digit')),
|
||||
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
|
||||
'contact_id' => $contact->id,
|
||||
'contact_name' => $contact->name,
|
||||
'contact_email' => $contact->email,
|
||||
'contact_tax_number' => $contact->tax_number,
|
||||
'contact_phone' => $contact->phone,
|
||||
'contact_address' => $contact->address,
|
||||
'status' => $this->faker->randomElement($statuses),
|
||||
];
|
||||
});
|
||||
return $this->state([
|
||||
'type' => Model::BILL_TYPE,
|
||||
'document_number' => $this->getNextDocumentNumber(Model::BILL_TYPE),
|
||||
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
|
||||
'contact_id' => $contact->id,
|
||||
'contact_name' => $contact->name,
|
||||
'contact_email' => $contact->email,
|
||||
'contact_tax_number' => $contact->tax_number,
|
||||
'contact_phone' => $contact->phone,
|
||||
'contact_address' => $contact->address,
|
||||
'status' => $this->faker->randomElement($statuses),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,10 +201,15 @@ class Document extends AbstractFactory
|
||||
*/
|
||||
public function recurring()
|
||||
{
|
||||
$type = $this->getRawAttribute('type') . '-recurring';
|
||||
|
||||
return $this->state([
|
||||
'type' => $type,
|
||||
'document_number' => $this->getNextDocumentNumber($type),
|
||||
'recurring_started_at' => $this->getRawAttribute('issued_at'),
|
||||
'recurring_frequency' => 'daily',
|
||||
'recurring_interval' => '1',
|
||||
'recurring_count' => '7',
|
||||
'recurring_limit_count' => '7',
|
||||
]);
|
||||
}
|
||||
|
||||
@ -216,43 +220,41 @@ class Document extends AbstractFactory
|
||||
*/
|
||||
public function items()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
$amount = $this->faker->randomFloat(2, 1, 1000);
|
||||
$amount = $this->faker->randomFloat(2, 1, 1000);
|
||||
|
||||
$taxes = Tax::enabled()->get();
|
||||
$taxes = Tax::enabled()->get();
|
||||
|
||||
if ($taxes->count()) {
|
||||
$tax = $taxes->random(1)->first();
|
||||
} else {
|
||||
$tax = Tax::factory()->enabled()->create();
|
||||
}
|
||||
if ($taxes->count()) {
|
||||
$tax = $taxes->random(1)->first();
|
||||
} else {
|
||||
$tax = Tax::factory()->enabled()->create();
|
||||
}
|
||||
|
||||
$items = Item::enabled()->get();
|
||||
$items = Item::enabled()->get();
|
||||
|
||||
if ($items->count()) {
|
||||
$item = $items->random(1)->first();
|
||||
} else {
|
||||
$item = Item::factory()->enabled()->create();
|
||||
}
|
||||
if ($items->count()) {
|
||||
$item = $items->random(1)->first();
|
||||
} else {
|
||||
$item = Item::factory()->enabled()->create();
|
||||
}
|
||||
|
||||
$items = [
|
||||
[
|
||||
'type' => $attributes['type'],
|
||||
'name' => $item->name,
|
||||
'description' => $this->faker->text,
|
||||
'item_id' => $item->id,
|
||||
'tax_ids' => [$tax->id],
|
||||
'quantity' => '1',
|
||||
'price' => $amount,
|
||||
'currency' => setting('default.currency'),
|
||||
],
|
||||
];
|
||||
$items = [
|
||||
[
|
||||
'type' => $this->getRawAttribute('type'),
|
||||
'name' => $item->name,
|
||||
'description' => $this->faker->text,
|
||||
'item_id' => $item->id,
|
||||
'tax_ids' => [$tax->id],
|
||||
'quantity' => '1',
|
||||
'price' => $amount,
|
||||
'currency' => setting('default.currency'),
|
||||
],
|
||||
];
|
||||
|
||||
return [
|
||||
'items' => $items,
|
||||
'recurring_frequency' => 'no',
|
||||
];
|
||||
});
|
||||
return $this->state([
|
||||
'items' => $items,
|
||||
'recurring_frequency' => 'no',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,6 +293,7 @@ class Document extends AbstractFactory
|
||||
|
||||
$items = [
|
||||
[
|
||||
'type' => $document->type,
|
||||
'name' => $item->name,
|
||||
'description' => $this->faker->text,
|
||||
'item_id' => $item->id,
|
||||
@ -327,7 +330,7 @@ class Document extends AbstractFactory
|
||||
case 'paid':
|
||||
$payment_request = [
|
||||
'paid_at' => $updated_document->due_at,
|
||||
'type' => config('type.' . $document->type . '.transaction_type'),
|
||||
'type' => config('type.document.' . $document->type . '.transaction_type'),
|
||||
];
|
||||
|
||||
if ($init_status === 'partial') {
|
||||
|
@ -21,8 +21,11 @@ class Item extends Factory
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$types = ['product', 'service'];
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'type' => $this->faker->randomElement($types),
|
||||
'name' => $this->faker->text(15),
|
||||
'description' => $this->faker->text(100),
|
||||
'purchase_price' => $this->faker->randomFloat(2, 10, 20),
|
||||
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Abstracts\Factory;
|
||||
use App\Models\Auth\Permission as Model;
|
||||
|
||||
class Permission extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Model::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$map = ['Create', 'Read', 'Update', 'Delete'];
|
||||
|
||||
$prefix = $this->faker->randomElement($map);
|
||||
$word_1 = $this->faker->word;
|
||||
$word_2 = $this->faker->word;
|
||||
|
||||
return [
|
||||
'name' => strtolower($prefix) . '-' . strtolower($word_1) . '-' . strtolower($word_2),
|
||||
'display_name' => $prefix . ' ' . $word_1 . ' ' . $word_2,
|
||||
'description' => $prefix . ' ' . $word_1 . ' ' . $word_2,
|
||||
];
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Abstracts\Factory;
|
||||
use App\Models\Auth\Permission;
|
||||
use App\Models\Auth\Role as Model;
|
||||
|
||||
class Role extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Model::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$name = $this->faker->word;
|
||||
|
||||
return [
|
||||
'name' => strtolower($name),
|
||||
'display_name' => $name,
|
||||
'description' => $name,
|
||||
'created_from' => 'core::factory',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate the model permissions.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
||||
*/
|
||||
public function permissions()
|
||||
{
|
||||
return $this->state([
|
||||
'permissions' => $this->getPermissions(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the model factory.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function configure()
|
||||
{
|
||||
return $this->afterCreating(function (Model $role) {
|
||||
$role->permissions()->attach($this->getPermissions());
|
||||
});
|
||||
}
|
||||
|
||||
protected function getPermissions()
|
||||
{
|
||||
return Permission::take(50)->pluck('id')->toArray();
|
||||
}
|
||||
}
|
@ -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'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -26,13 +26,13 @@ class User extends Factory
|
||||
|
||||
return [
|
||||
'name' => $this->faker->name,
|
||||
'email' => $this->faker->unique()->safeEmail,
|
||||
'email' => $this->faker->freeEmail,
|
||||
'password' => $password,
|
||||
'password_confirmation' => $password,
|
||||
'remember_token' => Str::random(10),
|
||||
'locale' => 'en-GB',
|
||||
'companies' => ['1'],
|
||||
'roles' => ['1'],
|
||||
'roles' => '1',
|
||||
'enabled' => $this->faker->boolean ? 1 : 0,
|
||||
'created_from' => 'core::factory',
|
||||
];
|
||||
|
@ -5,6 +5,7 @@ namespace Database\Factories;
|
||||
use App\Abstracts\Factory;
|
||||
use App\Models\Common\Dashboard;
|
||||
use App\Models\Common\Widget as Model;
|
||||
use App\Utilities\Widgets;
|
||||
|
||||
class Widget extends Factory
|
||||
{
|
||||
@ -15,19 +16,6 @@ class Widget extends Factory
|
||||
*/
|
||||
protected $model = Model::class;
|
||||
|
||||
public $classes = [
|
||||
'App\Widgets\TotalIncome',
|
||||
'App\Widgets\TotalExpenses',
|
||||
'App\Widgets\TotalProfit',
|
||||
'App\Widgets\CashFlow',
|
||||
'App\Widgets\IncomeByCategory',
|
||||
'App\Widgets\ExpensesByCategory',
|
||||
'App\Widgets\AccountBalance',
|
||||
'App\Widgets\LatestIncome',
|
||||
'App\Widgets\LatestExpenses',
|
||||
'App\Widgets\Currencies',
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
@ -41,7 +29,7 @@ class Widget extends Factory
|
||||
'company_id' => $this->company->id,
|
||||
'dashboard_id' => $dashboard->id,
|
||||
'name' => $this->faker->text(15),
|
||||
'class' => $this->faker->randomElement($this->classes),
|
||||
'class' => $this->faker->randomElement(Widgets::$core_widgets),
|
||||
'created_from' => 'core::factory',
|
||||
];
|
||||
}
|
||||
|
Reference in New Issue
Block a user