first commit

This commit is contained in:
denisdulici
2017-09-14 22:21:00 +03:00
commit 515bdaf5cd
598 changed files with 48030 additions and 0 deletions

1
database/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.sqlite

View File

@ -0,0 +1,24 @@
<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(App\User::class, function (Faker\Generator $faker) {
static $password;
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
];
});

View File

@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateAccountsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('accounts', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('name');
$table->string('number');
$table->string('currency_code');
$table->decimal('opening_balance')->default('0');
$table->string('bank_name')->nullable();
$table->string('bank_phone')->nullable();
$table->text('bank_address')->nullable();
$table->boolean('enabled');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('accounts');
}
}

View File

@ -0,0 +1,116 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateBillsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('bills', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('bill_number');
$table->string('order_number')->nullable();
$table->string('bill_status_code');
$table->date('billed_at');
$table->date('due_at');
$table->float('amount', 15, 4);
$table->string('currency_code');
$table->float('currency_rate', 15, 8);
$table->integer('vendor_id');
$table->string('vendor_name');
$table->string('vendor_email');
$table->string('vendor_tax_number')->nullable();
$table->string('vendor_phone')->nullable();
$table->text('vendor_address')->nullable();
$table->text('notes')->nullable();
$table->string('attachment')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
$table->unique(['company_id', 'bill_number', 'deleted_at']);
});
Schema::create('bill_items', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('bill_id');
$table->integer('item_id')->nullable();
$table->string('name');
$table->string('sku')->nullable();
$table->integer('quantity');
$table->float('price', 15, 4);
$table->float('total', 15, 4);
$table->float('tax', 15, 4)->default('0.0000');
$table->integer('tax_id');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
Schema::create('bill_statuses', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('name');
$table->string('code');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
Schema::create('bill_payments', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('bill_id');
$table->integer('account_id');
$table->date('paid_at');
$table->float('amount', 15, 4);
$table->string('currency_code');
$table->float('currency_rate', 15, 8);
$table->text('description')->nullable();
$table->string('payment_method');
$table->string('reference')->nullable();
$table->string('attachment')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
Schema::create('bill_histories', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('bill_id');
$table->string('status_code');
$table->boolean('notify');
$table->text('description')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('bills');
Schema::drop('bill_items');
Schema::drop('bill_statuses');
Schema::drop('bill_payments');
Schema::drop('bill_histories');
}
}

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('name');
$table->string('type');
$table->string('color');
$table->boolean('enabled');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('categories');
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateCompaniesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('companies', function (Blueprint $table) {
$table->increments('id');
$table->string('domain');
$table->boolean('enabled')->default(0);
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('companies');
}
}

View File

@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateCurrenciesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('currencies', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('name');
$table->string('code');
$table->float('rate', 15, 8);
$table->tinyInteger('enabled')->default(0);
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
$table->unique(['company_id', 'code', 'deleted_at']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('currencies');
}
}

View File

@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateCustomersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customers', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('user_id')->nullable();
$table->string('name');
$table->string('email');
$table->string('tax_number')->nullable();
$table->string('phone')->nullable();
$table->text('address')->nullable();
$table->string('website')->nullable();
$table->string('currency_code');
$table->boolean('enabled');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
$table->unique(['company_id', 'email', 'deleted_at']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('customers');
}
}

View File

@ -0,0 +1,116 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateInvoicesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('invoices', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('invoice_number');
$table->string('order_number')->nullable();
$table->string('invoice_status_code');
$table->date('invoiced_at');
$table->date('due_at');
$table->float('amount', 15, 4);
$table->string('currency_code');
$table->float('currency_rate', 15, 8);
$table->integer('customer_id');
$table->string('customer_name');
$table->string('customer_email');
$table->string('customer_tax_number')->nullable();
$table->string('customer_phone')->nullable();
$table->text('customer_address')->nullable();
$table->text('notes')->nullable();
$table->string('attachment')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
$table->unique(['company_id', 'invoice_number', 'deleted_at']);
});
Schema::create('invoice_items', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('invoice_id');
$table->integer('item_id')->nullable();
$table->string('name');
$table->string('sku')->nullable();
$table->integer('quantity');
$table->float('price', 15, 4);
$table->float('total', 15, 4);
$table->float('tax', 15, 4)->default('0.0000');
$table->integer('tax_id');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
Schema::create('invoice_statuses', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('name');
$table->string('code');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
Schema::create('invoice_payments', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('invoice_id');
$table->integer('account_id');
$table->date('paid_at');
$table->float('amount', 15, 4);
$table->string('currency_code');
$table->float('currency_rate', 15, 8);
$table->text('description')->nullable();
$table->string('payment_method');
$table->string('reference')->nullable();
$table->string('attachment')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
Schema::create('invoice_histories', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('invoice_id');
$table->string('status_code');
$table->boolean('notify');
$table->text('description')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('invoices');
Schema::drop('invoice_items');
Schema::drop('invoice_statuses');
Schema::drop('invoice_payments');
Schema::drop('invoice_histories');
}
}

View File

@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('items', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('name');
$table->string('sku');
$table->text('description')->nullable();
$table->float('sale_price', 15, 4);
$table->float('purchase_price', 15, 4);
$table->integer('quantity');
$table->integer('category_id')->nullable();
$table->integer('tax_id')->nullable();
$table->string('picture')->nullable();
$table->boolean('enabled');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
$table->unique(['company_id', 'sku', 'deleted_at']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('items');
}
}

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue');
$table->longText('payload');
$table->tinyInteger('attempts')->unsigned();
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
$table->index(['queue', 'reserved_at']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}

View File

@ -0,0 +1,51 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateModulesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('modules', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('alias');
$table->integer('status');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
$table->unique(['company_id', 'alias', 'deleted_at']);
});
Schema::create('module_histories', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('module_id');
$table->string('category');
$table->string('version');
$table->text('description')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index(['company_id', 'module_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('modules');
Schema::drop('module_histories');
}
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateNotificationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('notifications');
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email');
$table->string('token');
$table->timestamp('created_at')->nullable();
$table->index('email');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('password_resets');
}
}

View File

@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreatePaymentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('payments', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('account_id');
$table->date('paid_at');
$table->float('amount', 15, 4);
$table->string('currency_code');
$table->float('currency_rate', 15, 8);
$table->integer('vendor_id')->nullable();
$table->text('description')->nullable();
$table->integer('category_id');
$table->string('payment_method');
$table->string('reference')->nullable();
$table->string('attachment')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('payments');
}
}

View File

@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateRevenuesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('revenues', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('account_id');
$table->date('paid_at');
$table->float('amount', 15, 4);
$table->string('currency_code');
$table->float('currency_rate', 15, 8);
$table->integer('customer_id')->nullable();
$table->text('description')->nullable();
$table->integer('category_id');
$table->string('payment_method');
$table->string('reference')->nullable();
$table->string('attachment')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('revenues');
}
}

View File

@ -0,0 +1,89 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Create table for storing roles
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('display_name');
$table->string('description')->nullable();
$table->timestamps();
$table->unique('name');
});
// Create table for associating roles to users (Many To Many Polymorphic)
Schema::create('user_roles', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->string('user_type');
$table->foreign('role_id')->references('id')->on('roles')
->onUpdate('cascade')->onDelete('cascade');
$table->primary(['user_id', 'role_id', 'user_type']);
});
// Create table for storing permissions
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('display_name');
$table->string('description')->nullable();
$table->timestamps();
$table->unique('name');
});
// Create table for associating permissions to roles (Many-to-Many)
Schema::create('role_permissions', function (Blueprint $table) {
$table->integer('role_id')->unsigned();
$table->integer('permission_id')->unsigned();
$table->foreign('role_id')->references('id')->on('roles')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('permission_id')->references('id')->on('permissions')
->onUpdate('cascade')->onDelete('cascade');
$table->primary(['role_id', 'permission_id']);
});
// Create table for associating permissions to users (Many To Many Polymorphic)
Schema::create('user_permissions', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->integer('permission_id')->unsigned();
$table->string('user_type');
$table->foreign('permission_id')->references('id')->on('permissions')
->onUpdate('cascade')->onDelete('cascade');
$table->primary(['user_id', 'permission_id', 'user_type']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Cascade table first
Schema::dropIfExists('user_permissions');
Schema::dropIfExists('role_permissions');
Schema::dropIfExists('permissions');
Schema::dropIfExists('user_roles');
Schema::dropIfExists('roles');
}
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSessionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->unique();
$table->unsignedInteger('user_id')->nullable();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->text('payload');
$table->integer('last_activity');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('sessions');
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('key');
$table->text('value')->nullable();
$table->index('company_id');
$table->unique(['company_id', 'key']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('settings');
}
}

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateTaxesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('taxes', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->string('name');
$table->integer('rate');
$table->boolean('enabled');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('taxes');
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateTransfersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('transfers', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('payment_id');
$table->integer('revenue_id');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('transfers');
}
}

View File

@ -0,0 +1,52 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email');
$table->string('password');
$table->rememberToken();
$table->string('picture')->nullable();
$table->timestamp('last_logged_in_at')->nullable();
$table->boolean('enabled')->default(1);
$table->timestamps();
$table->softDeletes();
$table->unique(['email', 'deleted_at']);
});
// Create table for associating companies to users (Many To Many Polymorphic)
Schema::create('user_companies', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->integer('company_id')->unsigned();
$table->string('user_type');
$table->primary(['user_id', 'company_id', 'user_type']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Cascade table first
Schema::dropIfExists('user_companies');
Schema::dropIfExists('users');
}
}

View File

@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateVendorsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('vendors', function (Blueprint $table) {
$table->increments('id');
$table->integer('company_id');
$table->integer('user_id')->nullable();
$table->string('name');
$table->string('email');
$table->string('tax_number')->nullable();
$table->string('phone')->nullable();
$table->text('address')->nullable();
$table->string('website')->nullable();
$table->string('currency_code');
$table->boolean('enabled');
$table->timestamps();
$table->softDeletes();
$table->index('company_id');
$table->unique(['company_id', 'email', 'deleted_at']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('vendors');
}
}

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
class AddLocaleColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function ($table) {
$table->string('locale')->default(config('app.locale'));
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function ($table) {
$table->dropColumn('locale');
});
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace Database\Seeds;
use App\Models\Model;
use App\Models\Banking\Account;
use Setting;
use Illuminate\Database\Seeder;
class Accounts extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->create();
Model::reguard();
}
private function create()
{
$company_id = $this->command->argument('company');
$rows = [
[
'company_id' => $company_id,
'name' => trans('demo.accounts_cash'),
'number' => '1',
'currency_code' => 'USD',
'bank_name' => trans('demo.accounts_cash'),
'enabled' => '1',
],
];
foreach ($rows as $row) {
$account = Account::create($row);
Setting::set('general.default_account', $account->id);
}
}
}

View File

@ -0,0 +1,57 @@
<?php
namespace Database\Seeds;
use App\Models\Model;
use App\Models\Expense\BillStatus;
use Illuminate\Database\Seeder;
class BillStatuses extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->create();
Model::reguard();
}
private function create()
{
$company_id = $this->command->argument('company');
$rows = [
[
'company_id' => $company_id,
'name' => trans('bills.status.new'),
'code' => 'new',
],
[
'company_id' => $company_id,
'name' => trans('bills.status.updated'),
'code' => 'updated',
],
[
'company_id' => $company_id,
'name' => trans('bills.status.partial'),
'code' => 'partial',
],
[
'company_id' => $company_id,
'name' => trans('bills.status.paid'),
'code' => 'paid',
],
];
foreach ($rows as $row) {
BillStatus::create($row);
}
}
}

View File

@ -0,0 +1,72 @@
<?php
namespace Database\Seeds;
use App\Models\Model;
use App\Models\Setting\Category;
use Illuminate\Database\Seeder;
class Categories extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->create();
Model::reguard();
}
private function create()
{
$company_id = $this->command->argument('company');
$rows = [
[
'company_id' => $company_id,
'name' => trans_choice('general.transfers', 1),
'type' => 'other',
'color' => '#605ca8',
'enabled' => '1'
],
[
'company_id' => $company_id,
'name' => trans('demo.categories_deposit'),
'type' => 'income',
'color' => '#f39c12',
'enabled' => '1'
],
[
'company_id' => $company_id,
'name' => trans('demo.categories_sales'),
'type' => 'income',
'color' => '#6da252',
'enabled' => '1'
],
[
'company_id' => $company_id,
'name' => trans('demo.categories_uncat'),
'type' => 'expense',
'color' => '#d2d6de',
'enabled' => '1'
],
[
'company_id' => $company_id,
'name' => trans('general.general'),
'type' => 'item',
'color' => '#00c0ef',
'enabled' => '1'
],
];
foreach ($rows as $row) {
Category::create($row);
}
}
}

View File

@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Seeder;
class CompanySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(Database\Seeds\Accounts::class);
$this->call(Database\Seeds\BillStatuses::class);
$this->call(Database\Seeds\Categories::class);
$this->call(Database\Seeds\Currencies::class);
$this->call(Database\Seeds\InvoiceStatuses::class);
$this->call(Database\Seeds\Settings::class);
$this->call(Database\Seeds\Taxes::class);
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace Database\Seeds;
use App\Models\Model;
use App\Models\Setting\Currency;
use Illuminate\Database\Seeder;
class Currencies extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->create();
Model::reguard();
}
private function create()
{
$company_id = $this->command->argument('company');
$rows = [
[
'company_id' => $company_id,
'name' => trans('demo.currencies_usd'),
'code' => 'USD',
'rate' => '1.00',
'enabled' => '1',
],
[
'company_id' => $company_id,
'name' => trans('demo.currencies_eur'),
'code' => 'EUR',
'rate' => '1.25',
],
[
'company_id' => $company_id,
'name' => trans('demo.currencies_gbp'),
'code' => 'GBP',
'rate' => '1.60',
],
[
'company_id' => $company_id,
'name' => trans('demo.currencies_try'),
'code' => 'TRY',
'rate' => '0.80',
],
];
foreach ($rows as $row) {
Currency::create($row);
}
}
}

View File

@ -0,0 +1,16 @@
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace Database\Seeds;
use App\Models\Model;
use App\Models\Income\InvoiceStatus;
use Illuminate\Database\Seeder;
class InvoiceStatuses extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->create();
Model::reguard();
}
private function create()
{
$company_id = $this->command->argument('company');
$rows = [
[
'company_id' => $company_id,
'name' => trans('invoices.status.draft'),
'code' => 'draft',
],
[
'company_id' => $company_id,
'name' => trans('invoices.status.sent'),
'code' => 'sent',
],
[
'company_id' => $company_id,
'name' => trans('invoices.status.viewed'),
'code' => 'viewed',
],
[
'company_id' => $company_id,
'name' => trans('invoices.status.approved'),
'code' => 'approved',
],
[
'company_id' => $company_id,
'name' => trans('invoices.status.partial'),
'code' => 'partial',
],
[
'company_id' => $company_id,
'name' => trans('invoices.status.paid'),
'code' => 'paid',
],
];
foreach ($rows as $row) {
InvoiceStatus::create($row);
}
}
}

152
database/seeds/Roles.php Normal file
View File

@ -0,0 +1,152 @@
<?php
namespace Database\Seeds;
use App\Models\Model;
use App\Models\Auth\Role;
use App\Models\Auth\Permission;
use Illuminate\Database\Seeder;
class Roles extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->create($this->roles(), $this->map());
Model::reguard();
}
private function roles()
{
$rows = [
'admin' => [
'admin-panel' => 'r',
'api' => 'r',
'auth-users' => 'c,r,u,d',
'auth-roles' => 'c,r,u,d',
'auth-permissions' => 'c,r,u,d',
'auth-profile' => 'r,u',
'companies-companies' => 'c,r,u,d',
'items-items' => 'c,r,u,d',
'incomes-invoices' => 'c,r,u,d',
'incomes-revenues' => 'c,r,u,d',
'incomes-customers' => 'c,r,u,d',
'expenses-bills' => 'c,r,u,d',
'expenses-payments' => 'c,r,u,d',
'expenses-vendors' => 'c,r,u,d',
'banking-accounts' => 'c,r,u,d',
'banking-transfers' => 'c,r,u,d',
'banking-transactions' => 'r',
'settings-categories' => 'c,r,u,d',
'settings-settings' => 'r,u',
'settings-taxes' => 'c,r,u,d',
'settings-currencies' => 'c,r,u,d',
'settings-modules' => 'r,u',
'modules-home' => 'r',
'modules-tiles' => 'r',
'modules-item' => 'c,r,u,d',
'modules-token' => 'c,u',
'install-updates' => 'r,u',
'notifications' => 'r,u',
'reports-income-summary' => 'r',
'reports-expense-summary' => 'r',
'reports-income-expense-summary' => 'r',
],
'manager' => [
'admin-panel' => 'r',
'auth-profile' => 'r,u',
'companies-companies' => 'c,r,u,d',
'items-items' => 'c,r,u,d',
'incomes-invoices' => 'c,r,u,d',
'incomes-revenues' => 'c,r,u,d',
'incomes-customers' => 'c,r,u,d',
'expenses-bills' => 'c,r,u,d',
'expenses-payments' => 'c,r,u,d',
'expenses-vendors' => 'c,r,u,d',
'banking-accounts' => 'c,r,u,d',
'banking-transfers' => 'c,r,u,d',
'banking-transactions' => 'r',
'settings-settings' => 'r,u',
'settings-categories' => 'c,r,u,d',
'settings-taxes' => 'c,r,u,d',
'settings-currencies' => 'c,r,u,d',
'settings-modules' => 'r,u',
'install-updates' => 'r,u',
'notifications' => 'r,u',
'reports-income-summary' => 'r',
'reports-expense-summary' => 'r',
'reports-income-expense-summary' => 'r',
],
'customer' => [
'customer-panel' => 'r',
'customers-invoices' => 'r,u',
'customers-payments' => 'r,u',
'customers-transactions' => 'r',
'customers-profile' => 'r,u',
],
];
return $rows;
}
private function map()
{
$rows = [
'c' => 'create',
'r' => 'read',
'u' => 'update',
'd' => 'delete'
];
return $rows;
}
private function create($roles, $map)
{
$mapPermission = collect($map);
foreach ($roles as $key => $modules) {
// Create a new role
$role = Role::create([
'name' => $key,
'display_name' => ucwords(str_replace("_", " ", $key)),
'description' => ucwords(str_replace("_", " ", $key))
]);
$this->command->info('Creating Role '. strtoupper($key));
// Reading role permission modules
foreach ($modules as $module => $value) {
$permissions = explode(',', $value);
foreach ($permissions as $p => $perm) {
$permissionValue = $mapPermission->get($perm);
$moduleName = ucwords(str_replace("-", " ", $module));
$permission = Permission::firstOrCreate([
'name' => $permissionValue . '-' . $module,
'display_name' => ucfirst($permissionValue) . ' ' . $moduleName,
'description' => ucfirst($permissionValue) . ' ' . $moduleName,
]);
$this->command->info('Creating Permission to '.$permissionValue.' for '. $moduleName);
if (!$role->hasPermission($permission->name)) {
$role->attachPermission($permission);
} else {
$this->command->info($key . ': ' . $p . ' ' . $permissionValue . ' already exist');
}
}
}
}
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace Database\Seeds;
use App\Models\Model;
use Illuminate\Database\Seeder;
use Setting;
class Settings extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->create();
Model::reguard();
}
private function create()
{
$company_id = $this->command->argument('company');
Setting::set([
'general.date_format' => 'd M Y',
'general.date_separator' => 'space',
'general.timezone' => 'Europe/London',
'general.invoice_prefix' => 'INV-',
'general.invoice_digit' => '5',
'general.invoice_start' => '1',
'general.default_payment_method' => 'cash',
'general.email_protocol' => 'mail',
'general.email_sendmail_path' => '/usr/sbin/sendmail -bs',
'general.send_invoice_reminder' => '0',
'general.schedule_invoice_days' => '1,3,5,10',
'general.send_bill_reminder' => '0',
'general.schedule_bill_days' => '10,5,3,1',
'general.schedule_time' => '09:00',
'general.admin_theme' => 'skin-green-light',
'general.list_limit' => '25',
'general.use_gravatar' => '0',
'general.session_handler' => 'file',
'general.session_lifetime' => '30',
'general.file_size' => '2',
'general.file_types' => 'pdf,jpeg,jpg,png',
'offline.payment.methods' => '[{"code":"offline.cash.1","name":"Cash","order":"1","description":null},{"code":"offline.bank_transfer.2","name":"Bank Transfer","order":"2","description":null}]',
]);
}
}

55
database/seeds/Taxes.php Normal file
View File

@ -0,0 +1,55 @@
<?php
namespace Database\Seeds;
use App\Models\Model;
use App\Models\Setting\Tax;
use Illuminate\Database\Seeder;
class Taxes extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->create();
Model::reguard();
}
private function create()
{
$company_id = $this->command->argument('company');
$rows = [
[
'company_id' => $company_id,
'name' => trans('demo.taxes_exempt'),
'rate' => '0',
'enabled' => '1'
],
[
'company_id' => $company_id,
'name' => trans('demo.taxes_normal'),
'rate' => '5',
'enabled' => '1'
],
[
'company_id' => $company_id,
'name' => trans('demo.taxes_sales'),
'rate' => '15',
'enabled' => '1'
],
];
foreach ($rows as $row) {
Tax::create($row);
}
}
}

View File

@ -0,0 +1,75 @@
<?php
namespace Database\Seeds;
use App\Models\Model;
use App\Models\Auth\User;
use App\Models\Company\Company;
use Jenssegers\Date\Date;
use Illuminate\Database\Seeder;
use Setting;
class TestCompany extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call(Roles::class);
$this->createCompany();
$this->createUser();
Model::reguard();
}
private function createCompany()
{
$rows = [
[
'id' => '1',
'domain' => 'test.com',
],
];
foreach ($rows as $row) {
Company::create($row);
}
Setting::setExtraColumns(['company_id' => '1']);
Setting::set('general.company_name', 'Test Inc.');
Setting::set('general.company_email', 'info@test.com');
Setting::set('general.company_address', 'New Street 1254');
Setting::set('general.default_currency', 'USD');
Setting::set('general.default_account', '1');
Setting::set('general.default_payment_method', 'cash');
Setting::save();
$this->command->info('Test company created.');
}
public function createUser()
{
// Create user
$user = User::create([
'name' => 'Admin',
'email' => 'admin@akaunting.com',
'password' => '123456',
'last_logged_in_at' => Date::now(),
]);
// Attach Role
$user->roles()->attach(1);
// Attach company
$user->companies()->attach(1);
$this->command->info('Admin user created.');
}
}