mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
v5.0.0 update
This commit is contained in:
@ -33,12 +33,12 @@ class UpdateCraterVersion400 extends Migration
|
||||
]);
|
||||
|
||||
// Update language
|
||||
$user->setSettings(['language' => CompanySetting::getSetting('language', $user->company_id)]);
|
||||
$user->setSettings(['language' => CompanySetting::getSetting('language', $user->companies()->first()->id)]);
|
||||
|
||||
// Update user's addresses
|
||||
if ($user->addresses()->exists()) {
|
||||
foreach ($user->addresses as $address) {
|
||||
$address->company_id = $user->company_id;
|
||||
$address->company_id = $user->companies()->first()->id;
|
||||
$address->user_id = null;
|
||||
$address->save();
|
||||
}
|
||||
@ -131,6 +131,6 @@ class UpdateCraterVersion400 extends Migration
|
||||
'payment_from_customer_address_format' => $paymentFromCustomerAddress,
|
||||
];
|
||||
|
||||
CompanySetting::setSettings($settings, $user->company_id);
|
||||
CompanySetting::setSettings($settings, $user->companies()->first()->id);
|
||||
}
|
||||
}
|
||||
|
||||
114
database/migrations/2021_06_28_105334_create_bouncer_tables.php
Normal file
114
database/migrations/2021_06_28_105334_create_bouncer_tables.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Silber\Bouncer\Database\Models;
|
||||
|
||||
class CreateBouncerTables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('roles')) {
|
||||
Schema::drop(Models::table('roles'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('permissions')) {
|
||||
Schema::drop(Models::table('permissions'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('model_has_permissions')) {
|
||||
Schema::drop(Models::table('model_has_permissions'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('model_has_roles')) {
|
||||
Schema::drop(Models::table('model_has_roles'));
|
||||
}
|
||||
|
||||
if (Schema::hasTable('role_has_permissions')) {
|
||||
Schema::drop(Models::table('role_has_permissions'));
|
||||
}
|
||||
|
||||
Schema::create(Models::table('abilities'), function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->string('title')->nullable();
|
||||
$table->bigInteger('entity_id')->unsigned()->nullable();
|
||||
$table->string('entity_type')->nullable();
|
||||
$table->boolean('only_owned')->default(false);
|
||||
$table->json('options')->nullable();
|
||||
$table->integer('scope')->nullable()->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create(Models::table('roles'), function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->string('title')->nullable();
|
||||
$table->integer('level')->unsigned()->nullable();
|
||||
$table->integer('scope')->nullable()->index();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(
|
||||
['name', 'scope'],
|
||||
'roles_name_unique'
|
||||
);
|
||||
});
|
||||
|
||||
Schema::create(Models::table('assigned_roles'), function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->bigInteger('role_id')->unsigned()->index();
|
||||
$table->bigInteger('entity_id')->unsigned();
|
||||
$table->string('entity_type');
|
||||
$table->bigInteger('restricted_to_id')->unsigned()->nullable();
|
||||
$table->string('restricted_to_type')->nullable();
|
||||
$table->integer('scope')->nullable()->index();
|
||||
|
||||
$table->index(
|
||||
['entity_id', 'entity_type', 'scope'],
|
||||
'assigned_roles_entity_index'
|
||||
);
|
||||
|
||||
$table->foreign('role_id')
|
||||
->references('id')->on(Models::table('roles'))
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
|
||||
Schema::create(Models::table('permissions'), function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->bigInteger('ability_id')->unsigned()->index();
|
||||
$table->bigInteger('entity_id')->unsigned()->nullable();
|
||||
$table->string('entity_type')->nullable();
|
||||
$table->boolean('forbidden')->default(false);
|
||||
$table->integer('scope')->nullable()->index();
|
||||
|
||||
$table->index(
|
||||
['entity_id', 'entity_type', 'scope'],
|
||||
'permissions_entity_index'
|
||||
);
|
||||
|
||||
$table->foreign('ability_id')
|
||||
->references('id')->on(Models::table('abilities'))
|
||||
->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop(Models::table('permissions'));
|
||||
Schema::drop(Models::table('assigned_roles'));
|
||||
Schema::drop(Models::table('roles'));
|
||||
Schema::drop(Models::table('abilities'));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateCustomersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('customers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique()->nullable();
|
||||
$table->string('phone')->nullable();
|
||||
$table->string('password')->nullable();
|
||||
$table->rememberToken();
|
||||
$table->string('facebook_id')->nullable();
|
||||
$table->string('google_id')->nullable();
|
||||
$table->string('github_id')->nullable();
|
||||
$table->string('contact_name')->nullable();
|
||||
$table->string('company_name')->nullable();
|
||||
$table->string('website')->nullable();
|
||||
$table->boolean('enable_portal')->nullable();
|
||||
$table->integer('currency_id')->unsigned()->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
$table->integer('company_id')->unsigned()->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies');
|
||||
$table->unsignedInteger('creator_id')->nullable();
|
||||
$table->foreign('creator_id')->references('id')->on('users');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('customers');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomerIdToEstimatesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->foreign('customer_id')->references('id')->on('customers');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['customer_id']);
|
||||
}
|
||||
$table->dropColumn('customer_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomerIdToExpensesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->dropColumn('customer_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomerIdToInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->foreign('customer_id')->references('id')->on('customers');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['customer_id']);
|
||||
}
|
||||
$table->dropColumn('customer_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomerIdToPaymentsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->foreign('customer_id')->references('id')->on('customers');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['customer_id']);
|
||||
}
|
||||
$table->dropColumn('customer_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCustomerIdToAddressesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('addresses', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->foreign('customer_id')->references('id')->on('customers');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('addresses', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['customer_id']);
|
||||
}
|
||||
$table->dropColumn('customer_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\CustomField;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UpdateCustomerIdInAllTables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$users = User::where('role', 'customer')
|
||||
->get();
|
||||
|
||||
$users->makeVisible('password', 'remember_token');
|
||||
|
||||
if ($users) {
|
||||
foreach ($users as $user) {
|
||||
$newCustomer = Customer::create($user->toArray());
|
||||
|
||||
$customFields = CustomField::where('model_type', 'User')->get();
|
||||
|
||||
if ($customFields) {
|
||||
$user->fields->map(function ($customFieldValue) use ($newCustomer) {
|
||||
$customFieldValue->custom_field_valuable_type = "Crater\Models\Customer";
|
||||
$customFieldValue->custom_field_valuable_id = $newCustomer->id;
|
||||
$customFieldValue->save();
|
||||
|
||||
$customField = $customFieldValue->customField;
|
||||
$customField->model_type = "Customer";
|
||||
$customField->slug = Str::upper('CUSTOM_'.$customField->model_type.'_'.Str::slug($customField->label, '_'));
|
||||
$customField->save();
|
||||
});
|
||||
}
|
||||
|
||||
$user->addresses->map(function ($address) use ($newCustomer) {
|
||||
if ($address) {
|
||||
$address->customer_id = $newCustomer->id;
|
||||
$address->user_id = null;
|
||||
$address->save();
|
||||
}
|
||||
});
|
||||
|
||||
$user->expenses->map(function ($expense) use ($newCustomer) {
|
||||
if ($expense) {
|
||||
$expense->customer_id = $newCustomer->id;
|
||||
$expense->user_id = null;
|
||||
$expense->save();
|
||||
}
|
||||
});
|
||||
|
||||
$user->estimates->map(function ($estimate) use ($newCustomer) {
|
||||
if ($estimate) {
|
||||
$estimate->customer_id = $newCustomer->id;
|
||||
$estimate->user_id = null;
|
||||
$estimate->save();
|
||||
}
|
||||
});
|
||||
|
||||
$user->invoices->map(function ($invoice) use ($newCustomer) {
|
||||
if ($invoice) {
|
||||
$invoice->customer_id = $newCustomer->id;
|
||||
$invoice->user_id = null;
|
||||
$invoice->save();
|
||||
}
|
||||
});
|
||||
|
||||
$user->payments->map(function ($payment) use ($newCustomer) {
|
||||
if ($payment) {
|
||||
$payment->customer_id = $newCustomer->id;
|
||||
$payment->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['user_id']);
|
||||
}
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['user_id']);
|
||||
}
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['user_id']);
|
||||
}
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['user_id']);
|
||||
}
|
||||
$table->dropColumn('user_id');
|
||||
});
|
||||
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('unit');
|
||||
});
|
||||
|
||||
$users = User::where('role', 'customer')
|
||||
->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateUserCompanyTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_company', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedInteger('user_id')->nullable();
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->unsignedInteger('company_id')->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('company_user');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ChangeRelationshipOfCompany extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$users = User::all();
|
||||
|
||||
if ($users) {
|
||||
foreach ($users as $user) {
|
||||
$user->companies()->attach($user->company_id);
|
||||
$user->company_id = null;
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
if (config('database.default') !== 'sqlite') {
|
||||
$table->dropForeign(['company_id']);
|
||||
}
|
||||
$table->dropColumn('company_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class AddOwnerIdToCompaniesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('companies', function (Blueprint $table) {
|
||||
$table->string('slug')->nullable();
|
||||
$table->unsignedInteger('owner_id')->nullable();
|
||||
$table->foreign('owner_id')->references('id')->on('users');
|
||||
});
|
||||
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
|
||||
$companies = Company::all();
|
||||
|
||||
if ($companies) {
|
||||
foreach ($companies as $company) {
|
||||
$company->owner_id = $user->id;
|
||||
$company->slug = Str::slug($company->name);
|
||||
$company->save();
|
||||
|
||||
$company->setupRoles();
|
||||
$user->assign('super admin');
|
||||
|
||||
$users = User::where('role', 'admin')->get();
|
||||
$users->map(function ($user) {
|
||||
$user->assign('super admin');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('companies', function (Blueprint $table) {
|
||||
$table->dropColumn('slug');
|
||||
$table->dropForeign(['owner_id']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Note;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCompanyToNotesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('notes', function (Blueprint $table) {
|
||||
$table->unsignedInteger('company_id')->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
});
|
||||
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
|
||||
if ($user) {
|
||||
$notes = Note::where('company_id', null)->get();
|
||||
$notes->map(function ($note) use ($user) {
|
||||
$note->company_id = $user->companies()->first()->id;
|
||||
$note->save();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('notes', function (Blueprint $table) {
|
||||
$table->dropForeign(['company_id']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateRecurringInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('recurring_invoices', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->dateTime('starts_at', $precision = 0);
|
||||
$table->boolean('send_automatically')->default(false);
|
||||
$table->unsignedBigInteger('customer_id')->nullable();
|
||||
$table->foreign('customer_id')->references('id')->on('customers');
|
||||
$table->integer('company_id')->unsigned()->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies');
|
||||
$table->enum('status', ['COMPLETED', 'ON_HOLD', 'ACTIVE'])->default('ACTIVE');
|
||||
$table->dateTime('next_invoice_at', $precision = 0)->nullable();
|
||||
$table->unsignedInteger('creator_id')->nullable();
|
||||
$table->foreign('creator_id')->references('id')->on('users');
|
||||
$table->string('frequency');
|
||||
$table->enum('limit_by', ['NONE', 'COUNT', 'DATE'])->default('NONE');
|
||||
$table->integer('limit_count')->nullable();
|
||||
$table->date('limit_date')->nullable();
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->string('tax_per_item');
|
||||
$table->string('discount_per_item');
|
||||
$table->text('notes')->nullable();
|
||||
$table->string('discount_type')->nullable();
|
||||
$table->decimal('discount', 15, 2)->nullable();
|
||||
$table->unsignedBigInteger('discount_val')->nullable();
|
||||
$table->unsignedBigInteger('sub_total');
|
||||
$table->unsignedBigInteger('total');
|
||||
$table->unsignedBigInteger('tax');
|
||||
$table->string('template_name')->nullable();
|
||||
$table->unsignedBigInteger('due_amount');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('recurring_invoices');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddRecurringInvoiceIdToInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('recurring_invoice_id')->nullable();
|
||||
$table->foreign('recurring_invoice_id')->references('id')->on('recurring_invoices');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->dropColumn('recurring_invoice_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddRecurringInvoiceIdToInvoiceItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoice_items', function (Blueprint $table) {
|
||||
$table->integer('invoice_id')->unsigned()->nullable()->change();
|
||||
$table->unsignedBigInteger('recurring_invoice_id')->nullable();
|
||||
$table->foreign('recurring_invoice_id')->references('id')->on('recurring_invoices');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoice_items', function (Blueprint $table) {
|
||||
$table->dropColumn('recurring_invoice_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class MakeDueDateOptionalInInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->date('due_date')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class MakeExpiryDateOptionalEstimatesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->date('expiry_date')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnsIntoInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_discount_val')->nullable();
|
||||
$table->unsignedBigInteger('base_sub_total')->nullable();
|
||||
$table->unsignedBigInteger('base_total')->nullable();
|
||||
$table->unsignedBigInteger('base_tax')->nullable();
|
||||
$table->unsignedBigInteger('base_due_amount')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'base_discount_val',
|
||||
'exchange_rate',
|
||||
'base_sub_total',
|
||||
'base_total',
|
||||
'base_tax',
|
||||
'base_due_amount'
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnsIntoInvoiceItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoice_items', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('base_price')->nullable();
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_discount_val')->nullable();
|
||||
$table->unsignedBigInteger('base_tax')->nullable();
|
||||
$table->unsignedBigInteger('base_total')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoice_items', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'base_price',
|
||||
'exchange_rate',
|
||||
'base_discount_val',
|
||||
'base_tax',
|
||||
'base_total'
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnsIntoEstimatesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_discount_val')->nullable();
|
||||
$table->unsignedBigInteger('base_sub_total')->nullable();
|
||||
$table->unsignedBigInteger('base_total')->nullable();
|
||||
$table->unsignedBigInteger('base_tax')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'exchange_rate',
|
||||
'base_discount_val',
|
||||
'base_sub_total',
|
||||
'base_total',
|
||||
'base_tax',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnsIntoEstimateItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('estimate_items', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_discount_val')->nullable();
|
||||
$table->unsignedBigInteger('base_price')->nullable();
|
||||
$table->unsignedBigInteger('base_tax')->nullable();
|
||||
$table->unsignedBigInteger('base_total')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('estimate_items', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'exchange_rate',
|
||||
'base_discount_val',
|
||||
'base_price',
|
||||
'base_tax',
|
||||
'base_total'
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnIntoPaymentsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_amount')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->dropColumn('base_amount');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseValuesIntoTaxesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_amount')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'exchange_rate',
|
||||
'base_amount',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCurrencyIdIntoInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->dropColumn('currency_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCurrencyIdIntoPaymentsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->dropColumn('currency_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCurrencyIdIntoItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('currency_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCurrencyIdIntoTaxesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->dropColumn('currency_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddCurrencyIdIntoEstimatesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->dropColumn('currency_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateExchangeRateLogsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('exchange_rate_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('company_id')->unsigned()->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies');
|
||||
$table->unsignedInteger('base_currency_id')->nullable();
|
||||
$table->foreign('base_currency_id')->references('id')->on('currencies');
|
||||
$table->unsignedInteger('currency_id')->nullable();
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('exchange_rates');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Item;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddTaxPerItemIntoItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->boolean('tax_per_item')->default(false);
|
||||
});
|
||||
|
||||
$items = Item::with('taxes')->get();
|
||||
|
||||
if ($items) {
|
||||
foreach ($items as $item) {
|
||||
if (! $item->taxes()->get()->isEmpty()) {
|
||||
$item->tax_per_item = true;
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('tax_per_item');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBaseColumnsToExpenseTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->decimal('exchange_rate', 19, 6)->nullable();
|
||||
$table->unsignedBigInteger('base_amount')->nullable();
|
||||
$table->unsignedInteger('currency_id');
|
||||
$table->foreign('currency_id')->references('id')->on('currencies');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->dropColumn([
|
||||
'exchange_rate',
|
||||
'base_amount',
|
||||
'currency_id',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateExchangeRateProvidersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('exchange_rate_providers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('driver');
|
||||
$table->string('key');
|
||||
$table->json('currencies')->nullable();
|
||||
$table->json('driver_config')->nullable();
|
||||
$table->boolean('active')->default(true);
|
||||
$table->integer('company_id')->unsigned()->nullable();
|
||||
$table->foreign('company_id')->references('id')->on('companies');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('exchange_rate_providers');
|
||||
}
|
||||
}
|
||||
101
database/migrations/2021_09_28_130822_add_sequence_column.php
Normal file
101
database/migrations/2021_09_28_130822_add_sequence_column.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddSequenceColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('customers', function (Blueprint $table) {
|
||||
$table->string('prefix')->nullable()->after('id');
|
||||
});
|
||||
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->mediumInteger('sequence_number')->unsigned()->nullable()->after('id');
|
||||
$table->mediumInteger('customer_sequence_number')->unsigned()->nullable()->after('sequence_number');
|
||||
});
|
||||
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->mediumInteger('sequence_number')->unsigned()->nullable()->after('id');
|
||||
$table->mediumInteger('customer_sequence_number')->unsigned()->nullable()->after('sequence_number');
|
||||
});
|
||||
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->mediumInteger('sequence_number')->unsigned()->nullable()->after('id');
|
||||
$table->mediumInteger('customer_sequence_number')->unsigned()->nullable()->after('sequence_number');
|
||||
});
|
||||
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
|
||||
if ($user && $user->role == 'super admin') {
|
||||
$customers = Customer::all();
|
||||
foreach ($customers as $customer) {
|
||||
$invoices = $customer->invoices;
|
||||
if ($invoices) {
|
||||
$customerSequence = 1;
|
||||
$invoices->map(function ($invoice) use ($customerSequence) {
|
||||
$invoiceNumber = explode("-", $invoice->invoice_number);
|
||||
$invoice->sequence_number = intval(end($invoiceNumber));
|
||||
$invoice->customer_sequence_number = $customerSequence;
|
||||
$invoice->save();
|
||||
$customerSequence += 1;
|
||||
});
|
||||
}
|
||||
|
||||
$estimates = $customer->estimates;
|
||||
if ($estimates) {
|
||||
$customerSequence = 1;
|
||||
$estimates->map(function ($estimate) use ($customerSequence) {
|
||||
$estimateNumber = explode("-", $estimate->estimate_number);
|
||||
$estimate->sequence_number = intval(end($estimateNumber));
|
||||
$estimate->customer_sequence_number = $customerSequence;
|
||||
$estimate->save();
|
||||
$customerSequence += 1;
|
||||
});
|
||||
}
|
||||
|
||||
$payments = $customer->payments;
|
||||
if ($estimates) {
|
||||
$customerSequence = 1;
|
||||
$payments->map(function ($payment) use ($customerSequence) {
|
||||
$paymentNumber = explode("-", $payment->payment_number);
|
||||
$payment->sequence_number = intval(end($paymentNumber));
|
||||
$payment->customer_sequence_number = $customerSequence;
|
||||
$payment->save();
|
||||
$customerSequence += 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->dropColumn('sequence_number');
|
||||
$table->dropColumn('customer_sequence_number');
|
||||
});
|
||||
Schema::table('estimates', function (Blueprint $table) {
|
||||
$table->dropColumn('sequence_number');
|
||||
$table->dropColumn('customer_sequence_number');
|
||||
});
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->dropColumn('sequence_number');
|
||||
$table->dropColumn('customer_sequence_number');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddRecurringInvoiceIdToTaxesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('recurring_invoice_id')->nullable();
|
||||
$table->foreign('recurring_invoice_id')->references('id')->on('recurring_invoices');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('taxes', function (Blueprint $table) {
|
||||
$table->dropColumn('recurring_invoice_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddPaymentMethodToExpenseTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->integer('payment_method_id')->unsigned()->nullable();
|
||||
$table->foreign('payment_method_id')->references('id')->on('payment_methods');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->dropColumn('payment_method_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Item;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CalculateBaseValuesForExistingData extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
|
||||
if ($user) {
|
||||
$companyId = $user->companies()->first()->id;
|
||||
|
||||
$currency_id = CompanySetting::getSetting('currency', $companyId);
|
||||
|
||||
$items = Item::all();
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item->currency_id = $currency_id;
|
||||
$item->save();
|
||||
}
|
||||
|
||||
$customers = Customer::all();
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
if ($customer->invoices()->exists()) {
|
||||
$customer->invoices->map(function ($invoice) use ($currency_id, $customer) {
|
||||
if ($customer->currency_id == $currency_id) {
|
||||
$invoice->update([
|
||||
'currency_id' => $currency_id,
|
||||
'exchange_rate' => 1,
|
||||
'base_discount_val' => $invoice->sub_total,
|
||||
'base_sub_total' => $invoice->sub_total,
|
||||
'base_total' => $invoice->total,
|
||||
'base_tax' => $invoice->tax,
|
||||
'base_due_amount' => $invoice->due_amount
|
||||
]);
|
||||
} else {
|
||||
$invoice->update([
|
||||
'currency_id' => $customer->currency_id,
|
||||
]);
|
||||
}
|
||||
$this->items($invoice);
|
||||
});
|
||||
}
|
||||
|
||||
if ($customer->expenses()->exists()) {
|
||||
$customer->expenses->map(function ($expense) use ($currency_id) {
|
||||
$expense->update([
|
||||
'currency_id' => $currency_id,
|
||||
'exchange_rate' => 1,
|
||||
'base_amount' => $expense->amount,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
if ($customer->estimates()->exists()) {
|
||||
$customer->estimates->map(function ($estimate) use ($currency_id, $customer) {
|
||||
if ($customer->currency_id == $currency_id) {
|
||||
$estimate->update([
|
||||
'currency_id' => $currency_id,
|
||||
'exchange_rate' => 1,
|
||||
'base_discount_val' => $estimate->sub_total,
|
||||
'base_sub_total' => $estimate->sub_total,
|
||||
'base_total' => $estimate->total,
|
||||
'base_tax' => $estimate->tax
|
||||
]);
|
||||
} else {
|
||||
$estimate->update([
|
||||
'currency_id' => $customer->currency_id,
|
||||
]);
|
||||
}
|
||||
$this->items($estimate);
|
||||
});
|
||||
}
|
||||
|
||||
if ($customer->payments()->exists()) {
|
||||
$customer->payments->map(function ($payment) use ($currency_id, $customer) {
|
||||
if ($customer->currency_id == $currency_id) {
|
||||
$payment->update([
|
||||
'currency_id' => $currency_id,
|
||||
'base_amount' => $payment->amount,
|
||||
'exchange_rate' => 1
|
||||
]);
|
||||
} else {
|
||||
$payment->update([
|
||||
'currency_id' => $customer->currency_id,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function items($model)
|
||||
{
|
||||
$model->items->map(function ($item) use ($model) {
|
||||
$item->update([
|
||||
'exchange_rate' => $model->exchange_rate,
|
||||
'base_discount_val' => $item->discount_val * $model->exchange_rate,
|
||||
'base_price' => $item->price * $model->exchange_rate,
|
||||
'base_tax' => $item->tax * $model->exchange_rate,
|
||||
'base_total' => $item->total * $model->exchange_rate
|
||||
]);
|
||||
|
||||
$this->taxes($item, $model->currency_id);
|
||||
});
|
||||
|
||||
$this->taxes($model, $model->currency_id);
|
||||
}
|
||||
|
||||
public function taxes($model, $currency_id)
|
||||
{
|
||||
if ($model->taxes()->exists()) {
|
||||
$model->taxes->map(function ($tax) use ($model, $currency_id) {
|
||||
$tax->update([
|
||||
'currency_id' => $currency_id,
|
||||
'exchange_rate' => $model->exchange_rate,
|
||||
'base_amount' => $tax->amount * $model->exchange_rate,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddNewCompanySettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$companies = Company::all();
|
||||
|
||||
if ($companies) {
|
||||
$companies->map(function ($company) {
|
||||
$settingsToRemove = [
|
||||
'invoice_number_length',
|
||||
'estimate_number_length',
|
||||
'payment_number_length',
|
||||
'invoice_prefix',
|
||||
'estimate_prefix',
|
||||
'payment_prefix',
|
||||
];
|
||||
|
||||
$oldSettings = CompanySetting::getSettings($settingsToRemove, $company->id);
|
||||
$oldSettings = $oldSettings->toArray();
|
||||
|
||||
$settings = [
|
||||
'invoice_set_due_date_automatically' => 'YES',
|
||||
'invoice_due_date_days' => 7,
|
||||
'estimate_set_expiry_date_automatically' => 'YES',
|
||||
'estimate_expiry_date_days' => 7,
|
||||
'estimate_convert_action' => 'no_action',
|
||||
'bulk_exchange_rate_configured' => "NO",
|
||||
'invoice_number_format' => "{{SERIES:{$oldSettings['invoice_prefix']}}}{{DELIMITER:-}}{{SEQUENCE:{$oldSettings['invoice_number_length']}}}",
|
||||
'estimate_number_format' => "{{SERIES:{$oldSettings['estimate_prefix']}}}{{DELIMITER:-}}{{SEQUENCE:{$oldSettings['estimate_number_length']}}}",
|
||||
'payment_number_format' => "{{SERIES:{$oldSettings['payment_prefix']}}}{{DELIMITER:-}}{{SEQUENCE:{$oldSettings['payment_number_length']}}}",
|
||||
];
|
||||
|
||||
CompanySetting::whereIn('option', $settingsToRemove)->delete();
|
||||
|
||||
CompanySetting::setSettings($settings, $company->id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class UpdateCraterVersion500 extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Setting::setSetting('version', '5.0.0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user