laravel 8

This commit is contained in:
Denis Duliçi
2020-10-14 17:07:59 +03:00
parent b4e044b199
commit 1ba8835a2d
134 changed files with 3515 additions and 1952 deletions

View File

@ -1,38 +1,78 @@
<?php
use App\Models\Auth\User;
use App\Models\Banking\Account;
use Faker\Generator as Faker;
namespace Database\Factories;
$user = User::first();
$company = $user->companies()->first();
use App\Abstracts\Factory;
use App\Models\Banking\Account as Model;
$factory->define(Account::class, function (Faker $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
class Account extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
return [
'company_id' => $company->id,
'name' => $faker->text(15),
'number' => (string) $faker->iban(),
'currency_code' => $company->currencies()->enabled()->get()->random(1)->pluck('code')->first(),
'opening_balance' => '0',
'bank_name' => $faker->text(15),
'bank_phone' => $faker->phoneNumber,
'bank_address' => $faker->address,
'enabled' => $faker->boolean ? 1 : 0,
];
});
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'number' => (string) $this->faker->iban(),
'currency_code' => $this->company->currencies()->enabled()->get()->random(1)->pluck('code')->first(),
'opening_balance' => '0',
'bank_name' => $this->faker->text(15),
'bank_phone' => $this->faker->phoneNumber,
'bank_address' => $this->faker->address,
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
$factory->state(Account::class, 'enabled', ['enabled' => 1]);
/**
* Indicate that the model is enabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function enabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 1,
];
});
}
$factory->state(Account::class, 'disabled', ['enabled' => 0]);
/**
* Indicate that the model is disabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function disabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 0,
];
});
}
$factory->state(Account::class, 'default_currency', function (Faker $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
return [
'currency_code' => setting('default.currency'),
];
});
/**
* Indicate that the default currency is used.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function default_currency()
{
return $this->state(function (array $attributes) {
return [
'currency_code' => setting('default.currency'),
];
});
}
}

View File

@ -1,185 +1,274 @@
<?php
namespace Database\Factories;
use App\Abstracts\Factory;
use App\Events\Purchase\BillCancelled;
use App\Events\Purchase\BillCreated;
use App\Events\Purchase\BillReceived;
use App\Jobs\Banking\CreateDocumentTransaction;
use App\Jobs\Purchase\UpdateBill;
use App\Models\Auth\User;
use App\Models\Common\Contact;
use App\Models\Common\Item;
use App\Models\Purchase\Bill;
use App\Models\Purchase\Bill as Model;
use App\Models\Setting\Tax;
use App\Utilities\Date;
use Faker\Generator as Faker;
$user = User::first();
$company = $user->companies()->first();
class Bill extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
$factory->define(Bill::class, function (Faker $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$billed_at = $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s');
$due_at = Date::parse($billed_at)->addDays(10)->format('Y-m-d H:i:s');
$billed_at = $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s');
$due_at = Date::parse($billed_at)->addDays(10)->format('Y-m-d H:i:s');
$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 = factory(Contact::class)->states('enabled', 'vendor')->create();
$statuses = ['draft', 'received', 'partial', 'paid', 'cancelled'];
return [
'company_id' => $this->company->id,
'billed_at' => $billed_at,
'due_at' => $due_at,
'bill_number' => (string) $this->faker->randomNumber(5),
'currency_code' => setting('default.currency'),
'currency_rate' => '1',
'notes' => $this->faker->text(5),
'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),
'amount' => '0',
];
}
$statuses = ['draft', 'received', 'partial', 'paid', 'cancelled'];
return [
'company_id' => $company->id,
'billed_at' => $billed_at,
'due_at' => $due_at,
'bill_number' => (string) $faker->randomNumber(5),
'currency_code' => setting('default.currency'),
'currency_rate' => '1',
'notes' => $faker->text(5),
'category_id' => $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' => $faker->randomElement($statuses),
'amount' => '0',
];
});
$factory->state(Bill::class, 'draft', ['status' => 'draft']);
$factory->state(Bill::class, 'received', ['status' => 'received']);
$factory->state(Bill::class, 'partial', ['status' => 'partial']);
$factory->state(Bill::class, 'paid', ['status' => 'paid']);
$factory->state(Bill::class, 'cancelled', ['status' => 'cancelled']);
$factory->state(Bill::class, 'recurring', function (Faker $faker) {
$frequencies = ['monthly', 'weekly'];
return [
'recurring_frequency' => 'yes',
'recurring_interval' => '1',
'recurring_custom_frequency' => $faker->randomElement($frequencies),
'recurring_count' => '1',
];
});
$factory->state(Bill::class, 'items', function (Faker $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
$amount = $faker->randomFloat(2, 1, 1000);
$taxes = Tax::enabled()->get();
if ($taxes->count()) {
$tax = $taxes->random(1)->first();
} else {
$tax = factory(Tax::class)->states('enabled')->create();
}
$items = Item::enabled()->get();
if ($items->count()) {
$item = $items->random(1)->first();
} else {
$item = factory(Item::class)->states('enabled')->create();
}
$items = [
[
'name' => $item->name,
'item_id' => $item->id,
'tax_id' => [$tax->id],
'quantity' => '1',
'price' => $amount,
'currency' => setting('default.currency'),
]
];
return [
'items' => $items,
'recurring_frequency' => 'no',
];
});
$factory->afterCreating(Bill::class, function ($bill, $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
$init_status = $bill->status;
$bill->status = 'draft';
event(new BillCreated($bill));
$bill->status = $init_status;
$amount = $faker->randomFloat(2, 1, 1000);
$taxes = Tax::enabled()->get();
if ($taxes->count()) {
$tax = $taxes->random(1)->first();
} else {
$tax = factory(Tax::class)->states('enabled')->create();
}
$items = Item::enabled()->get();
if ($items->count()) {
$item = $items->random(1)->first();
} else {
$item = factory(Item::class)->states('enabled')->create();
}
$items = [
[
'name' => $item->name,
'item_id' => $item->id,
'tax_id' => [$tax->id],
'quantity' => '1',
'price' => $amount,
'currency' => $bill->currency_code,
]
];
$request = [
'items' => $items,
'recurring_frequency' => 'no',
];
$updated_bill = dispatch_now(new UpdateBill($bill, $request));
switch ($init_status) {
case 'received':
event(new BillReceived($updated_bill));
break;
case 'partial':
case 'paid':
$payment_request = [
'paid_at' => $updated_bill->due_at,
/**
* Indicate that the model status is draft.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function draft()
{
return $this->state(function (array $attributes) {
return [
'status' => 'draft',
];
});
}
if ($init_status == 'partial') {
$payment_request['amount'] = (int) round($amount / 3, $bill->currency->precision);
/**
* Indicate that the model status is received.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function received()
{
return $this->state(function (array $attributes) {
return [
'status' => 'received',
];
});
}
/**
* Indicate that the model status is partial.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function partial()
{
return $this->state(function (array $attributes) {
return [
'status' => 'partial',
];
});
}
/**
* Indicate that the model status is paid.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function paid()
{
return $this->state(function (array $attributes) {
return [
'status' => 'paid',
];
});
}
/**
* Indicate that the model status is cancelled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function cancelled()
{
return $this->state(function (array $attributes) {
return [
'status' => 'cancelled',
];
});
}
/**
* Indicate that the model is recurring.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function recurring()
{
return $this->state(function (array $attributes) {
$frequencies = ['monthly', 'weekly'];
return [
'recurring_frequency' => 'yes',
'recurring_interval' => '1',
'recurring_custom_frequency' => $this->faker->randomElement($frequencies),
'recurring_count' => '1',
];
});
}
/**
* Indicate that the model has items.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function items()
{
return $this->state(function (array $attributes) {
$amount = $this->faker->randomFloat(2, 1, 1000);
$taxes = Tax::enabled()->get();
if ($taxes->count()) {
$tax = $taxes->random(1)->first();
} else {
$tax = Tax::factory()->enabled()->create();
}
$transaction = dispatch_now(new CreateDocumentTransaction($updated_bill, $payment_request));
$items = Item::enabled()->get();
break;
case 'cancelled':
event(new BillCancelled($updated_bill));
if ($items->count()) {
$item = $items->random(1)->first();
} else {
$item = Item::factory()->enabled()->create();
}
break;
$items = [
[
'name' => $item->name,
'item_id' => $item->id,
'tax_id' => [$tax->id],
'quantity' => '1',
'price' => $amount,
'currency' => setting('default.currency'),
]
];
return [
'items' => $items,
'recurring_frequency' => 'no',
];
});
}
});
/**
* Configure the model factory.
*
* @return $this
*/
public function configure()
{
return $this->afterCreating(function (Model $bill) {
$init_status = $bill->status;
$bill->status = 'draft';
event(new BillCreated($bill));
$bill->status = $init_status;
$amount = $this->faker->randomFloat(2, 1, 1000);
$taxes = Tax::enabled()->get();
if ($taxes->count()) {
$tax = $taxes->random(1)->first();
} else {
$tax = Tax::factory()->enabled()->create();
}
$items = Item::enabled()->get();
if ($items->count()) {
$item = $items->random(1)->first();
} else {
$item = Item::factory()->enabled()->create();
}
$items = [
[
'name' => $item->name,
'item_id' => $item->id,
'tax_id' => [$tax->id],
'quantity' => '1',
'price' => $amount,
'currency' => $bill->currency_code,
]
];
$request = [
'items' => $items,
'recurring_frequency' => 'no',
];
$updated_bill = $this->dispatch(new UpdateBill($bill, $request));
switch ($init_status) {
case 'received':
event(new BillReceived($updated_bill));
break;
case 'partial':
case 'paid':
$payment_request = [
'paid_at' => $updated_bill->due_at,
];
if ($init_status == 'partial') {
$payment_request['amount'] = (int) round($amount / 3, $bill->currency->precision);
}
$transaction = dispatch_now(new CreateDocumentTransaction($updated_bill, $payment_request));
break;
case 'cancelled':
event(new BillCancelled($updated_bill));
break;
}
});
}
}

View File

@ -1,34 +1,118 @@
<?php
use App\Models\Auth\User;
use App\Models\Setting\Category;
use Faker\Generator as Faker;
namespace Database\Factories;
$user = User::first();
$company = $user->companies()->first();
use App\Abstracts\Factory;
use App\Models\Setting\Category as Model;
$factory->define(Category::class, function (Faker $faker) use ($company) {
setting()->setExtraColumns(['company_id' => $company->id]);
class Category extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
$types = ['income', 'expense', 'item', 'other'];
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$types = ['income', 'expense', 'item', 'other'];
return [
'company_id' => $company->id,
'name' => $faker->text(15),
'type' => $faker->randomElement($types),
'color' => $faker->hexColor,
'enabled' => $faker->boolean ? 1 : 0,
];
});
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'type' => $this->faker->randomElement($types),
'color' => $this->faker->hexColor,
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
$factory->state(Category::class, 'enabled', ['enabled' => 1]);
/**
* Indicate that the model is enabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function enabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 1,
];
});
}
$factory->state(Category::class, 'disabled', ['enabled' => 0]);
/**
* Indicate that the model is disabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function disabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 0,
];
});
}
$factory->state(Category::class, 'income', ['type' => 'income']);
/**
* Indicate that the model type is income.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function income()
{
return $this->state(function (array $attributes) {
return [
'type' => 'income',
];
});
}
$factory->state(Category::class, 'expense', ['type' => 'expense']);
/**
* Indicate that the model type is expense.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function expense()
{
return $this->state(function (array $attributes) {
return [
'type' => 'expense',
];
});
}
$factory->state(Category::class, 'item', ['type' => 'item']);
/**
* Indicate that the model type is item.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function item()
{
return $this->state(function (array $attributes) {
return [
'type' => 'item',
];
});
}
$factory->state(Category::class, 'other', ['type' => 'other']);
/**
* Indicate that the model type is other.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function other()
{
return $this->state(function (array $attributes) {
return [
'type' => 'other',
];
});
}
}

View File

@ -1,38 +1,100 @@
<?php
use App\Models\Auth\User;
use App\Models\Common\Contact;
use Faker\Generator as Faker;
namespace Database\Factories;
$user = User::first();
$company = $user->companies()->first();
use App\Abstracts\Factory;
use App\Models\Common\Contact as Model;
use App\Traits\Contacts;
$factory->define(Contact::class, function (Faker $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
class Contact extends Factory
{
use Contacts;
$types = ['customer', 'vendor'];
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
return [
'company_id' => $company->id,
'type' => $faker->randomElement($types),
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'user_id' => null,
'tax_number' => $faker->randomNumber(9),
'phone' => $faker->phoneNumber,
'address' => $faker->address,
'website' => 'https://akaunting.com',
'currency_code' => setting('default.currency'),
'reference' => $faker->text(5),
'enabled' => $faker->boolean ? 1 : 0,
];
});
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$types = array_merge($this->getCustomerTypes(), $this->getVendorTypes());
$factory->state(Contact::class, 'enabled', ['enabled' => 1]);
return [
'company_id' => $this->company->id,
'type' => $this->faker->randomElement($types),
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'user_id' => null,
'tax_number' => $this->faker->randomNumber(9),
'phone' => $this->faker->phoneNumber,
'address' => $this->faker->address,
'website' => 'https://akaunting.com',
'currency_code' => setting('default.currency'),
'reference' => $this->faker->text(5),
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
$factory->state(Contact::class, 'disabled', ['enabled' => 0]);
/**
* Indicate that the model is enabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function enabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 1,
];
});
}
$factory->state(Contact::class, 'customer', ['type' => 'customer']);
/**
* Indicate that the model is disabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function disabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 0,
];
});
}
$factory->state(Contact::class, 'vendor', ['type' => 'vendor']);
/**
* Indicate that the model type is customer.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function customer()
{
return $this->state(function (array $attributes) {
return [
'type' => 'customer',
];
});
}
/**
* Indicate that the model type is vendor.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function vendor()
{
return $this->state(function (array $attributes) {
return [
'type' => 'vendor',
];
});
}
}

View File

@ -1,45 +1,80 @@
<?php
use App\Models\Auth\User;
use App\Models\Setting\Currency;
use Faker\Generator as Faker;
namespace Database\Factories;
$user = User::first();
$company = $user->companies()->first();
use App\Abstracts\Factory;
use App\Models\Setting\Currency as Model;
$factory->define(Currency::class, function (Faker $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
class Currency extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
$currencies = config('money');
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$currencies = config('money');
Currency::pluck('code')->each(function ($db_code) use (&$currencies) {
unset($currencies[$db_code]);
});
Model::pluck('code')->each(function ($db_code) use (&$currencies) {
unset($currencies[$db_code]);
});
$random = $faker->randomElement($currencies);
$random = $this->faker->randomElement($currencies);
$filtered = array_filter($currencies, function ($value) use ($random) {
return ($value['code'] == $random['code']);
});
$filtered = array_filter($currencies, function ($value) use ($random) {
return ($value['code'] == $random['code']);
});
$code = key($filtered);
$currency = $filtered[$code];
$code = key($filtered);
$currency = $filtered[$code];
return [
'company_id' => $company->id,
'name' => $currency['name'],
'code' => $code,
'rate' => $faker->randomFloat($currency['precision'], 1, 10),
'precision' => $currency['precision'],
'symbol' => $currency['symbol'],
'symbol_first' => $currency['symbol_first'],
'decimal_mark' => $currency['decimal_mark'],
'thousands_separator' => $currency['thousands_separator'],
'enabled' => $faker->boolean ? 1 : 0,
];
});
return [
'company_id' => $this->company->id,
'name' => $currency['name'],
'code' => $code,
'rate' => $this->faker->randomFloat($currency['precision'], 1, 10),
'precision' => $currency['precision'],
'symbol' => $currency['symbol'],
'symbol_first' => $currency['symbol_first'],
'decimal_mark' => $currency['decimal_mark'],
'thousands_separator' => $currency['thousands_separator'],
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
$factory->state(Currency::class, 'enabled', ['enabled' => 1]);
/**
* Indicate that the model is enabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function enabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 1,
];
});
}
$factory->state(Currency::class, 'disabled', ['enabled' => 0]);
/**
* Indicate that the model is disabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function disabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 0,
];
});
}
}

View File

@ -1,32 +1,84 @@
<?php
use App\Models\Auth\User;
use App\Models\Common\Dashboard;
use Faker\Generator as Faker;
namespace Database\Factories;
$user = User::first();
$company = $user->companies()->first();
use App\Abstracts\Factory;
use App\Models\Common\Dashboard as Model;
$factory->define(Dashboard::class, function (Faker $faker) use ($company) {
setting()->setExtraColumns(['company_id' => $company->id]);
class Dashboard extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
return [
'company_id' => $company->id,
'name' => $faker->text(15),
'enabled' => $faker->boolean ? 1 : 0,
];
});
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
$factory->state(Dashboard::class, 'enabled', ['enabled' => 1]);
/**
* Indicate that the model is enabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function enabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 1,
];
});
}
$factory->state(Dashboard::class, 'disabled', ['enabled' => 0]);
/**
* Indicate that the model is disabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function disabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 0,
];
});
}
$factory->state(Dashboard::class, 'users', function (Faker $faker) use ($company) {
return [
'users' => $company->users()->enabled()->get()->pluck('id')->toArray(),
];
});
/**
* Indicate the model users.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function users()
{
return $this->state(function (array $attributes) {
return [
'users' => $this->getCompanyUsers(),
];
});
}
$factory->afterCreating(Dashboard::class, function ($dashboard, $faker) use ($company) {
$dashboard->users()->attach($company->users()->enabled()->get()->pluck('id')->toArray());
});
/**
* Configure the model factory.
*
* @return $this
*/
public function configure()
{
return $this->afterCreating(function (Model $dashboard) {
$dashboard->users()->attach($this->getCompanyUsers());
});
}
}

View File

@ -1,194 +1,295 @@
<?php
namespace Database\Factories;
use App\Abstracts\Factory;
use App\Events\Sale\InvoiceCancelled;
use App\Events\Sale\InvoiceCreated;
use App\Events\Sale\InvoiceSent;
use App\Events\Sale\InvoiceViewed;
use App\Events\Sale\PaymentReceived;
use App\Jobs\Sale\UpdateInvoice;
use App\Models\Auth\User;
use App\Models\Common\Contact;
use App\Models\Common\Item;
use App\Models\Sale\Invoice;
use App\Models\Sale\Invoice as Model;
use App\Models\Setting\Tax;
use App\Utilities\Date;
use Faker\Generator as Faker;
$user = User::first();
$company = $user->companies()->first();
class Invoice extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
$factory->define(Invoice::class, function (Faker $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$invoiced_at = $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s');
$due_at = Date::parse($invoiced_at)->addDays(setting('invoice.payment_terms'))->format('Y-m-d H:i:s');
$invoiced_at = $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s');
$due_at = Date::parse($invoiced_at)->addDays(setting('invoice.payment_terms'))->format('Y-m-d H:i:s');
$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 = factory(Contact::class)->states('enabled', 'customer')->create();
$statuses = ['draft', 'sent', 'viewed', 'partial', 'paid', 'cancelled'];
return [
'company_id' => $this->company->id,
'invoiced_at' => $invoiced_at,
'due_at' => $due_at,
'invoice_number' => setting('invoice.number_prefix') . $this->faker->randomNumber(setting('invoice.number_digit')),
'currency_code' => setting('default.currency'),
'currency_rate' => '1',
'notes' => $this->faker->text(5),
'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),
'amount' => '0',
];
}
$statuses = ['draft', 'sent', 'viewed', 'partial', 'paid', 'cancelled'];
return [
'company_id' => $company->id,
'invoiced_at' => $invoiced_at,
'due_at' => $due_at,
'invoice_number' => setting('invoice.number_prefix') . $faker->randomNumber(setting('invoice.number_digit')),
'currency_code' => setting('default.currency'),
'currency_rate' => '1',
'notes' => $faker->text(5),
'category_id' => $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' => $faker->randomElement($statuses),
'amount' => '0',
];
});
$factory->state(Invoice::class, 'draft', ['status' => 'draft']);
$factory->state(Invoice::class, 'sent', ['status' => 'sent']);
$factory->state(Invoice::class, 'viewed', ['status' => 'viewed']);
$factory->state(Invoice::class, 'partial', ['status' => 'partial']);
$factory->state(Invoice::class, 'paid', ['status' => 'paid']);
$factory->state(Invoice::class, 'cancelled', ['status' => 'cancelled']);
$factory->state(Invoice::class, 'recurring', function (Faker $faker) {
$frequencies = ['monthly', 'weekly'];
return [
'recurring_frequency' => 'yes',
'recurring_interval' => '1',
'recurring_custom_frequency' => $faker->randomElement($frequencies),
'recurring_count' => '1',
];
});
$factory->state(Invoice::class, 'items', function (Faker $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
$amount = $faker->randomFloat(2, 1, 1000);
$taxes = Tax::enabled()->get();
if ($taxes->count()) {
$tax = $taxes->random(1)->first();
} else {
$tax = factory(Tax::class)->states('enabled')->create();
}
$items = Item::enabled()->get();
if ($items->count()) {
$item = $items->random(1)->first();
} else {
$item = factory(Item::class)->states('enabled')->create();
}
$items = [
[
'name' => $item->name,
'item_id' => $item->id,
'tax_id' => [$tax->id],
'quantity' => '1',
'price' => $amount,
'currency' => setting('default.currency'),
]
];
return [
'items' => $items,
'recurring_frequency' => 'no',
];
});
$factory->afterCreating(Invoice::class, function ($invoice, $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
$init_status = $invoice->status;
$invoice->status = 'draft';
event(new InvoiceCreated($invoice));
$invoice->status = $init_status;
$amount = $faker->randomFloat(2, 1, 1000);
$taxes = Tax::enabled()->get();
if ($taxes->count()) {
$tax = $taxes->random(1)->first();
} else {
$tax = factory(Tax::class)->states('enabled')->create();
}
$items = Item::enabled()->get();
if ($items->count()) {
$item = $items->random(1)->first();
} else {
$item = factory(Item::class)->states('enabled')->create();
}
$items = [
[
'name' => $item->name,
'item_id' => $item->id,
'tax_id' => [$tax->id],
'quantity' => '1',
'price' => $amount,
'currency' => $invoice->currency_code,
]
];
$request = [
'items' => $items,
'recurring_frequency' => 'no',
];
$updated_invoice = dispatch_now(new UpdateInvoice($invoice, $request));
switch ($init_status) {
case 'sent':
event(new InvoiceSent($updated_invoice));
break;
case 'viewed':
$updated_invoice->status = 'sent';
event(new InvoiceViewed($updated_invoice));
$updated_invoice->status = $init_status;
break;
case 'partial':
case 'paid':
$payment_request = [
'paid_at' => $updated_invoice->due_at,
/**
* Indicate that the model status is draft.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function draft()
{
return $this->state(function (array $attributes) {
return [
'status' => 'draft',
];
});
}
if ($init_status == 'partial') {
$payment_request['amount'] = (int) round($amount / 3, $invoice->currency->precision);
/**
* Indicate that the model status is sent.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function sent()
{
return $this->state(function (array $attributes) {
return [
'status' => 'sent',
];
});
}
/**
* Indicate that the model status is viewed.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function viewed()
{
return $this->state(function (array $attributes) {
return [
'status' => 'viewed',
];
});
}
/**
* Indicate that the model status is partial.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function partial()
{
return $this->state(function (array $attributes) {
return [
'status' => 'partial',
];
});
}
/**
* Indicate that the model status is paid.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function paid()
{
return $this->state(function (array $attributes) {
return [
'status' => 'paid',
];
});
}
/**
* Indicate that the model status is cancelled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function cancelled()
{
return $this->state(function (array $attributes) {
return [
'status' => 'cancelled',
];
});
}
/**
* Indicate that the model is recurring.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function recurring()
{
return $this->state(function (array $attributes) {
$frequencies = ['monthly', 'weekly'];
return [
'recurring_frequency' => 'yes',
'recurring_interval' => '1',
'recurring_custom_frequency' => $this->faker->randomElement($frequencies),
'recurring_count' => '1',
];
});
}
/**
* Indicate that the model has items.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function items()
{
return $this->state(function (array $attributes) {
$amount = $this->faker->randomFloat(2, 1, 1000);
$taxes = Tax::enabled()->get();
if ($taxes->count()) {
$tax = $taxes->random(1)->first();
} else {
$tax = Tax::factory()->enabled()->create();
}
event(new PaymentReceived($updated_invoice, $payment_request));
$items = Item::enabled()->get();
break;
case 'cancelled':
event(new InvoiceCancelled($updated_invoice));
if ($items->count()) {
$item = $items->random(1)->first();
} else {
$item = Item::factory()->enabled()->create();
}
break;
$items = [
[
'name' => $item->name,
'item_id' => $item->id,
'tax_id' => [$tax->id],
'quantity' => '1',
'price' => $amount,
'currency' => setting('default.currency'),
]
];
return [
'items' => $items,
'recurring_frequency' => 'no',
];
});
}
});
/**
* Configure the model factory.
*
* @return $this
*/
public function configure()
{
return $this->afterCreating(function (Model $invoice) {
$init_status = $invoice->status;
$invoice->status = 'draft';
event(new InvoiceCreated($invoice));
$invoice->status = $init_status;
$amount = $this->faker->randomFloat(2, 1, 1000);
$taxes = Tax::enabled()->get();
if ($taxes->count()) {
$tax = $taxes->random(1)->first();
} else {
$tax = Tax::factory()->enabled()->create();
}
$items = Item::enabled()->get();
if ($items->count()) {
$item = $items->random(1)->first();
} else {
$item = Item::factory()->enabled()->create();
}
$items = [
[
'name' => $item->name,
'item_id' => $item->id,
'tax_id' => [$tax->id],
'quantity' => '1',
'price' => $amount,
'currency' => $invoice->currency_code,
]
];
$request = [
'items' => $items,
'recurring_frequency' => 'no',
];
$updated_invoice = $this->dispatch(new UpdateInvoice($invoice, $request));
switch ($init_status) {
case 'sent':
event(new InvoiceSent($updated_invoice));
break;
case 'viewed':
$updated_invoice->status = 'sent';
event(new InvoiceViewed($updated_invoice));
$updated_invoice->status = $init_status;
break;
case 'partial':
case 'paid':
$payment_request = [
'paid_at' => $updated_invoice->due_at,
];
if ($init_status == 'partial') {
$payment_request['amount'] = (int) round($amount / 3, $invoice->currency->precision);
}
event(new PaymentReceived($updated_invoice, $payment_request));
break;
case 'cancelled':
event(new InvoiceCancelled($updated_invoice));
break;
}
});
}
}

View File

@ -1,27 +1,63 @@
<?php
use App\Models\Auth\User;
use App\Models\Common\Item;
use Faker\Generator as Faker;
namespace Database\Factories;
$user = User::first();
$company = $user->companies()->first();
use App\Abstracts\Factory;
use App\Models\Common\Item as Model;
$factory->define(Item::class, function (Faker $faker) use ($company) {
setting()->setExtraColumns(['company_id' => $company->id]);
class Item extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
return [
'company_id' => $company->id,
'name' => $faker->text(15),
'description' => $faker->text(100),
'purchase_price' => $faker->randomFloat(2, 10, 20),
'sale_price' => $faker->randomFloat(2, 10, 20),
'category_id' => $company->categories()->item()->get()->random(1)->pluck('id')->first(),
'tax_id' => null,
'enabled' => $faker->boolean ? 1 : 0,
];
});
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'description' => $this->faker->text(100),
'purchase_price' => $this->faker->randomFloat(2, 10, 20),
'sale_price' => $this->faker->randomFloat(2, 10, 20),
'category_id' => $this->company->categories()->item()->get()->random(1)->pluck('id')->first(),
'tax_id' => null,
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
$factory->state(Item::class, 'enabled', ['enabled' => 1]);
/**
* Indicate that the model is enabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function enabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 1,
];
});
}
$factory->state(Item::class, 'disabled', ['enabled' => 0]);
/**
* Indicate that the model is disabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function disabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 0,
];
});
}
}

View File

@ -1,18 +1,36 @@
<?php
use App\Models\Auth\Permission;
use Faker\Generator as Faker;
namespace Database\Factories;
$factory->define(Permission::class, function (Faker $faker) {
$map = ['Create', 'Read', 'Update', 'Delete'];
use App\Abstracts\Factory;
use App\Models\Auth\Permission as Model;
$prefix = $faker->randomElement($map);
$word_1 = $faker->word;
$word_2 = $faker->word;
class Permission extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
return [
'name' => strtolower($prefix) . '-' . strtolower($word_1) . '-' . strtolower($word_2),
'display_name' => $prefix . ' ' . $word_1 . ' ' . $word_2,
'description' => $prefix . ' ' . $word_1 . ' ' . $word_2,
];
});
/**
* 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,
];
}
}

View File

@ -1,25 +1,64 @@
<?php
namespace Database\Factories;
use App\Abstracts\Factory;
use App\Models\Auth\Permission;
use App\Models\Auth\Role;
use Faker\Generator as Faker;
use App\Models\Auth\Role as Model;
$factory->define(Role::class, function (Faker $faker) {
$name = $faker->word;
class Role extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
return [
'name' => strtolower($name),
'display_name' => $name,
'description' => $name,
];
});
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$name = $this->faker->word;
$factory->state(Role::class, 'permissions', function (Faker $faker) {
return [
'permissions' => Permission::take(50)->pluck('id')->toArray(),
];
});
return [
'name' => strtolower($name),
'display_name' => $name,
'description' => $name,
];
}
$factory->afterCreating(Role::class, function ($role, $faker) {
$role->permissions()->attach(Permission::take(50)->pluck('id')->toArray());
});
/**
* Indicate the model permissions.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function permissions()
{
return $this->state(function (array $attributes) {
return [
'permissions' => $this->getPermissions(),
];
});
}
protected function getPermissions()
{
return Permission::take(50)->pluck('id')->toArray();
}
/**
* Configure the model factory.
*
* @return $this
*/
public function configure()
{
return $this->afterCreating(function (Model $role) {
$role->permissions()->attach($this->getPermissions());
});
}
}

View File

@ -1,36 +1,132 @@
<?php
use App\Models\Auth\User;
use App\Models\Setting\Tax;
use Faker\Generator as Faker;
namespace Database\Factories;
$user = User::first();
$company = $user->companies()->first();
use App\Abstracts\Factory;
use App\Models\Setting\Tax as Model;
$factory->define(Tax::class, function (Faker $faker) use ($company) {
setting()->setExtraColumns(['company_id' => $company->id]);
class Tax extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
$types = ['normal', 'inclusive', 'compound', 'fixed', 'withholding'];
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$types = ['normal', 'inclusive', 'compound', 'fixed', 'withholding'];
return [
'company_id' => $company->id,
'name' => $faker->text(15),
'rate' => $faker->randomFloat(2, 10, 20),
'type' => $faker->randomElement($types),
'enabled' => $faker->boolean ? 1 : 0,
];
});
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'rate' => $this->faker->randomFloat(2, 10, 20),
'type' => $this->faker->randomElement($types),
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
$factory->state(Tax::class, 'enabled', ['enabled' => 1]);
/**
* Indicate that the model is enabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function enabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 1,
];
});
}
$factory->state(Tax::class, 'disabled', ['enabled' => 0]);
/**
* Indicate that the model is disabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function disabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 0,
];
});
}
$factory->state(Tax::class, 'normal', ['type' => 'normal']);
/**
* Indicate that the model type is normal.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function normal()
{
return $this->state(function (array $attributes) {
return [
'type' => 'normal',
];
});
}
$factory->state(Tax::class, 'inclusive', ['type' => 'inclusive']);
/**
* Indicate that the model type is inclusive.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function inclusive()
{
return $this->state(function (array $attributes) {
return [
'type' => 'inclusive',
];
});
}
$factory->state(Tax::class, 'compound', ['type' => 'compound']);
/**
* Indicate that the model type is compound.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function compound()
{
return $this->state(function (array $attributes) {
return [
'type' => 'compound',
];
});
}
$factory->state(Tax::class, 'fixed', ['type' => 'fixed']);
/**
* Indicate that the model type is fixed.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function fixed()
{
return $this->state(function (array $attributes) {
return [
'type' => 'fixed',
];
});
}
$factory->state(Tax::class, 'withholding', ['type' => 'withholding']);
/**
* Indicate that the model type is normal.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function withholding()
{
return $this->state(function (array $attributes) {
return [
'type' => 'withholding',
];
});
}
}

View File

@ -1,43 +1,74 @@
<?php
use App\Models\Auth\User;
use App\Models\Banking\Transaction;
use Faker\Generator as Faker;
namespace Database\Factories;
$user = User::first();
$company = $user->companies()->first();
use App\Abstracts\Factory;
use App\Models\Banking\Transaction as Model;
use App\Traits\Transactions;
$factory->define(Transaction::class, function (Faker $faker) use ($company) {
setting()->setExtraColumns(['company_id' => $company->id]);
class Transaction extends Factory
{
use Transactions;
$types = ['income', 'expense'];
$type = $faker->randomElement($types);
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
return [
'company_id' => $company->id,
'type' => $type,
'account_id' => setting('default.account'),
'paid_at' => $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'),
'amount' => $faker->randomFloat(2, 1, 1000),
'currency_code' => setting('default.currency'),
'currency_rate' => '1.0',
'description' => $faker->text(5),
'category_id' => $company->categories()->type($type)->get()->random(1)->pluck('id')->first(),
'reference' => $faker->text(5),
'payment_method' => setting('default.payment_method'),
];
});
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$types = array_merge($this->getIncomeTypes(), $this->getExpenseTypes());
$type = $this->faker->randomElement($types);
$factory->state(Transaction::class, 'income', function (Faker $faker) use ($company) {
return [
'type' => 'income',
'category_id' => $company->categories()->income()->get()->random(1)->pluck('id')->first(),
];
});
return [
'company_id' => $this->company->id,
'type' => $type,
'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),
'currency_code' => setting('default.currency'),
'currency_rate' => '1.0',
'description' => $this->faker->text(5),
'category_id' => $this->company->categories()->type($type)->get()->random(1)->pluck('id')->first(),
'reference' => $this->faker->text(5),
'payment_method' => setting('default.payment_method'),
];
}
$factory->state(Transaction::class, 'expense', function (Faker $faker) use ($company) {
return [
'type' => 'expense',
'category_id' => $company->categories()->expense()->get()->random(1)->pluck('id')->first(),
];
});
/**
* Indicate that the model type is income.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function income()
{
return $this->state(function (array $attributes) {
return [
'type' => 'income',
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
];
});
}
/**
* Indicate that the model type is expense.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function expense()
{
return $this->state(function (array $attributes) {
return [
'type' => 'expense',
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
];
});
}
}

View File

@ -1,53 +1,64 @@
<?php
use App\Models\Auth\User;
namespace Database\Factories;
use App\Abstracts\Factory;
use App\Models\Banking\Account;
use App\Models\Banking\Transaction;
use App\Models\Banking\Transfer;
use App\Models\Banking\Transfer as Model;
use App\Models\Setting\Category;
use Faker\Generator as Faker;
$user = User::first();
$company = $user->companies()->first();
class Transfer extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
$factory->define(Transfer::class, function (Faker $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$accounts = Account::enabled()->get();
$accounts = Account::enabled()->get();
if ($accounts->count() >= 2) {
$random = $accounts->random(2);
if ($accounts->count() >= 2) {
$random = $accounts->random(2);
$expense_account = $random->first();
$income_account = $random->last();
} else {
$expense_account = $accounts->first();
$expense_account = $random->first();
$income_account = $random->last();
} else {
$expense_account = $accounts->first();
$income_account = Account::factory()->enabled()->default_currency()->create();
}
$income_account = factory(Account::class)->states('enabled', 'default_currency')->create();
$request = [
'amount' => $this->faker->randomFloat(2, 1, 1000),
'paid_at' => $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'),
'category_id' => Category::transfer(),
'description' => $this->faker->text(20),
'reference' => $this->faker->text(20),
];
$expense_transaction = Transaction::factory()->create(array_merge($request, [
'type' => 'expense',
'account_id' => $expense_account->id,
]));
$income_transaction = Transaction::factory()->create(array_merge($request, [
'type' => 'income',
'account_id' => $income_account->id,
]));
return [
'company_id' => $this->company->id,
'expense_transaction_id' => $expense_transaction->id,
'income_transaction_id' => $income_transaction->id,
];
}
$request = [
'amount' => $faker->randomFloat(2, 1, 1000),
'paid_at' => $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'),
'category_id' => Category::transfer(),
'description' => $faker->text(20),
'reference' => $faker->text(20),
];
$expense_transaction = factory(Transaction::class)->create(array_merge($request, [
'type' => 'expense',
'account_id' => $expense_account->id,
]));
$income_transaction = factory(Transaction::class)->create(array_merge($request, [
'type' => 'income',
'account_id' => $income_account->id,
]));
return [
'company_id' => $company->id,
'expense_transaction_id' => $expense_transaction->id,
'income_transaction_id' => $income_transaction->id,
];
});
}

View File

@ -1,25 +1,67 @@
<?php
use App\Models\Auth\User;
use Faker\Generator as Faker;
namespace Database\Factories;
use App\Abstracts\Factory;
use App\Models\Auth\User as Model;
use Illuminate\Support\Str;
$factory->define(User::class, function (Faker $faker) {
$password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'; // password
class User extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => $password,
'password_confirmation' => $password,
'remember_token' => Str::random(10),
'locale' => 'en-GB',
'companies' => ['1'],
'roles' => ['1'],
'enabled' => $this->faker->boolean ? 1 : 0,
];
});
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'; // password
$factory->state(User::class, 'enabled', ['enabled' => 1]);
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'password' => $password,
'password_confirmation' => $password,
'remember_token' => Str::random(10),
'locale' => 'en-GB',
'companies' => ['1'],
'roles' => ['1'],
'enabled' => $this->faker->boolean ? 1 : 0,
];
}
$factory->state(User::class, 'disabled', ['enabled' => 0]);
/**
* Indicate that the model is enabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function enabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 1,
];
});
}
/**
* Indicate that the model is disabled.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function disabled()
{
return $this->state(function (array $attributes) {
return [
'enabled' => 0,
];
});
}
}