renamed income/expense

This commit is contained in:
denisdulici
2019-12-31 15:49:09 +03:00
parent e2189158b9
commit 2428feb73b
235 changed files with 815 additions and 2147 deletions

View File

@ -1,31 +0,0 @@
<?php
namespace App\Listeners\Update\V10;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use File;
class Version106 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.0.6';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Moved to app directory
File::deleteDirectory(app_path('Http' . DIRECTORY_SEPARATOR .'Transformers'));
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace App\Listeners\Update\V10;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use DB;
class Version107 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.0.7';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
$table = env('DB_PREFIX') . 'taxes';
DB::statement("ALTER TABLE `$table` MODIFY `rate` DOUBLE(15,4) NOT NULL");
}
}

View File

@ -1,91 +0,0 @@
<?php
namespace App\Listeners\Update\V10;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Common\Company;
use App\Models\Expense\Bill;
use App\Models\Expense\BillStatus;
class Version108 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.0.8';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
$this->updateSettings();
$this->updateBills();
}
private function updateSettings()
{
// Set new invoice settings
setting(['general.invoice_number_prefix' => setting('invoice.prefix', 'INV-')]);
setting(['general.invoice_number_digit' => setting('invoice.digit', '5')]);
setting(['general.invoice_number_next' => setting('invoice.start', '1')]);
setting()->forget('general.invoice_prefix');
setting()->forget('general.invoice_digit');
setting()->forget('general.invoice_start');
setting()->save();
}
private function updateBills()
{
// Create new bill statuses
$companies = Company::all();
foreach ($companies as $company) {
$rows = [
[
'company_id' => $company->id,
'name' => trans('bills.status.draft'),
'code' => 'draft',
],
[
'company_id' => $company->id,
'name' => trans('bills.status.received'),
'code' => 'received',
],
];
foreach ($rows as $row) {
BillStatus::create($row);
}
}
$bills = Bill::all();
foreach ($bills as $bill) {
if (($bill->bill_status_code != 'new') || ($bill->bill_status_code != 'updated')) {
continue;
}
$bill->bill_status_code = 'draft';
$bill->save();
}
$new = BillStatus::where('code', 'new');
$new->delete();
$new->forceDelete();
$updated = BillStatus::where('code', 'updated');
$updated->delete();
$updated->forceDelete();
}
}

View File

@ -1,37 +0,0 @@
<?php
namespace App\Listeners\Update\V10;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Common\Company;
use Artisan;
class Version109 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.0.9';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Create new bill statuses
$companies = Company::all();
foreach ($companies as $company) {
Artisan::call('module:install', ['alias' => 'offlinepayment', 'company_id' => $company->id]);
Artisan::call('module:install', ['alias' => 'paypalstandard', 'company_id' => $company->id]);
}
}
}

View File

@ -1,49 +0,0 @@
<?php
namespace App\Listeners\Update\V11;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Auth\Role;
use App\Models\Auth\Permission;
class Version110 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.1.0';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Create permission
$permission = Permission::firstOrCreate([
'name' => 'create-common-import',
'display_name' => 'Create Common Import',
'description' => 'Create Common Import',
]);
// Attach permission to roles
$roles = Role::all();
foreach ($roles as $role) {
$allowed = ['admin', 'manager'];
if (!in_array($role->name, $allowed)) {
continue;
}
$role->attachPermission($permission);
}
}
}

View File

@ -1,39 +0,0 @@
<?php
namespace App\Listeners\Update\V11;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Common\Company;
use App\Utilities\Installer;
class Version112 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.1.2';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
$locale = 'en-GB';
// Get default locale if only 1 company
if (Company::all()->count() == 1) {
$locale = setting('default.locale', 'en-GB');
}
// Set default locale
Installer::updateEnv(['APP_LOCALE' => $locale]);
}
}

View File

@ -1,45 +0,0 @@
<?php
namespace App\Listeners\Update\V11;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Setting\Currency;
use Artisan;
class Version113 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.1.3';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Update database
Artisan::call('migrate', ['--force' => true]);
// Update currencies
$currencies = Currency::all();
foreach ($currencies as $currency) {
$currency->precision = config('money.' . $currency->code . '.precision');
$currency->symbol = config('money.' . $currency->code . '.symbol');
$currency->symbol_first = config('money.' . $currency->code . '.symbol_first') ? 1 : 0;
$currency->decimal_mark = config('money.' . $currency->code . '.decimal_mark');
$currency->thousands_separator = config('money.' . $currency->code . '.thousands_separator');
$currency->save();
}
}
}

View File

@ -1,161 +0,0 @@
<?php
namespace App\Listeners\Update\V11;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Auth\Role;
use App\Models\Auth\Permission;
use Illuminate\Support\Facades\Schema;
use MediaUploader;
use Storage;
use Artisan;
class Version119 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.1.9';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
if (Schema::hasTable('mediables')) {
return;
}
if (Schema::hasTable('media')) {
Schema::drop('media');
}
// Create permission
if (!Permission::where('name', 'delete-common-uploads')->first()) {
$permission = Permission::firstOrCreate([
'name' => 'delete-common-uploads',
'display_name' => 'Delete Common Uploads',
'description' => 'Delete Common Uploads',
]);
// Attach permission to roles
$roles = Role::all();
$allowed = ['admin'];
foreach ($roles as $role) {
if (!in_array($role->name, $allowed)) {
continue;
}
$role->attachPermission($permission);
}
}
$data = [];
$migrations = [
'\App\Models\Auth\User' => 'picture',
'\App\Models\Common\Item' => 'picture',
'\App\Models\Expense\Bill' => 'attachment',
'\App\Models\Expense\Payment' => 'attachment',
'\App\Models\Income\Invoice' => 'attachment',
'\App\Models\Income\Revenue' => 'attachment',
];
foreach ($migrations as $model => $name) {
if ($model != '\App\Models\Auth\User') {
$items = $model::where('company_id', '<>', '0')->get();
} else {
$items = $model::all();
}
$data[basename($model)] = $items;
}
// Clear cache after update
Artisan::call('cache:clear');
// Update database
Artisan::call('migrate', ['--force' => true]);
foreach ($migrations as $model => $name) {
$items = $data[basename($model)];
foreach ($items as $item) {
if (!$item->$name) {
continue;
}
$path = explode('uploads/', $item->$name);
$path = end($path);
if (!empty($item->company_id) && (strpos($path, $item->company_id . '/') === false)) {
$path = $item->company_id . '/' . $path;
}
if (!empty($path) && Storage::exists($path)) {
$media = \App\Models\Common\Media::where('filename', '=', pathinfo(basename($path), PATHINFO_FILENAME))->first();
if ($media) {
$item->attachMedia($media, $name);
continue;
}
$media = MediaUploader::importPath(config('mediable.default_disk'), $path);
$item->attachMedia($media, $name);
}
}
}
$settings['company_logo'] = \App\Models\Setting\Setting::where('key', '=', 'general.company_logo')->where('company_id', '<>', '0')->get();
$settings['invoice_logo'] = \App\Models\Setting\Setting::where('key', '=', 'general.invoice_logo')->where('company_id', '<>', '0')->get();
foreach ($settings as $name => $items) {
foreach ($items as $item) {
if (!$item->value) {
continue;
}
$path = explode('uploads/', $item->value);
$path = end($path);
if (!empty($item->company_id) && (strpos($path, $item->company_id . '/') === false)) {
$path = $item->company_id . '/' . $path;
}
if (!empty($path) && Storage::exists($path)) {
$company = \App\Models\Common\Company::find($item->company_id);
$media = \App\Models\Common\Media::where('filename', '=', pathinfo(basename($path), PATHINFO_FILENAME))->first();
if ($company && !$media) {
$media = MediaUploader::importPath(config('mediable.default_disk'), $path);
$company->attachMedia($media, $name);
$item->update(['value' => $media->id]);
} elseif ($media) {
$item->update(['value' => $media->id]);
} else {
$item->update(['value' => '']);
}
} else {
$item->update(['value' => '']);
}
}
}
}
}

View File

@ -1,138 +0,0 @@
<?php
namespace App\Listeners\Update\V12;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Auth\Role;
use App\Models\Auth\Permission;
use App\Models\Common\Company;
use App\Models\Expense\Bill;
use App\Models\Income\Invoice;
use App\Models\Setting\Category;
use DB;
use Schema;
use Artisan;
class Version120 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.2.0';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
$this->updatePermissions();
// Update database
Artisan::call('migrate', ['--force' => true]);
$this->updateInvoicesAndBills();
$this->changeQuantityColumn();
}
protected function updatePermissions()
{
$permissions = [];
// Create tax summary permission
$permissions[] = Permission::firstOrCreate([
'name' => 'read-reports-tax-summary',
'display_name' => 'Read Reports Tax Summary',
'description' => 'Read Reports Tax Summary',
]);
// Create profit loss permission
$permissions[] = Permission::firstOrCreate([
'name' => 'read-reports-profit-loss',
'display_name' => 'Read Reports Profit Loss',
'description' => 'Read Reports Profit Loss',
]);
// Attach permission to roles
$roles = Role::all();
foreach ($roles as $role) {
$allowed = ['admin', 'manager'];
if (!in_array($role->name, $allowed)) {
continue;
}
foreach ($permissions as $permission) {
$role->attachPermission($permission);
}
}
}
protected function updateInvoicesAndBills()
{
$companies = Company::all();
foreach ($companies as $company) {
// Invoices
$invoice_category = Category::create([
'company_id' => $company->id,
'name' => trans_choice('general.invoices', 2),
'type' => 'income',
'color' => '#00c0ef',
'enabled' => '1'
]);
foreach ($company->invoices as $invoice) {
$invoice->category_id = $invoice_category->id;
$invoice->save();
}
// Bills
$bill_category = Category::create([
'company_id' => $company->id,
'name' => trans_choice('general.bills', 2),
'type' => 'expense',
'color' => '#dd4b39',
'enabled' => '1'
]);
foreach ($company->bills as $bill) {
$bill->category_id = $bill_category->id;
$bill->save();
}
}
}
protected function changeQuantityColumn()
{
$connection = env('DB_CONNECTION');
if ($connection == 'mysql') {
$tables = [
env('DB_PREFIX') . 'invoice_items',
env('DB_PREFIX') . 'bill_items'
];
foreach ($tables as $table) {
DB::statement("ALTER TABLE `$table` MODIFY `quantity` DOUBLE(7,2) NOT NULL");
}
} else {
Schema::table('invoice_items', function ($table) {
$table->decimal('quantity', 7, 2)->change();
});
Schema::table('bill_items', function ($table) {
$table->decimal('quantity', 7, 2)->change();
});
}
}
}

View File

@ -1,31 +0,0 @@
<?php
namespace App\Listeners\Update\V12;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use Artisan;
class Version1210 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.2.10';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Update database
Artisan::call('migrate', ['--force' => true]);
}
}

View File

@ -1,31 +0,0 @@
<?php
namespace App\Listeners\Update\V12;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use Artisan;
class Version1211 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.2.11';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Update database
Artisan::call('migrate', ['--force' => true]);
}
}

View File

@ -1,53 +0,0 @@
<?php
namespace App\Listeners\Update\V12;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Auth\Role;
use App\Models\Auth\Permission;
class Version126 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.2.6';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
$permissions = [];
// Create permission
$permissions[] = Permission::firstOrCreate([
'name' => 'read-modules-my',
'display_name' => 'Read Modules My',
'description' => 'Read Modules My',
]);
// Attach permission to roles
$roles = Role::all();
foreach ($roles as $role) {
$allowed = ['admin', 'manager'];
if (!in_array($role->name, $allowed)) {
continue;
}
foreach ($permissions as $permission) {
$role->attachPermission($permission);
}
}
}
}

View File

@ -1,53 +0,0 @@
<?php
namespace App\Listeners\Update\V12;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Auth\Permission;
use File;
use Illuminate\Support\Str;
class Version127 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.2.7';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Update permissions
$permissions = Permission::all();
foreach ($permissions as $permission) {
if (strstr($permission->name, '-companies-companies')) {
$permission->name = str_replace('-companies-companies', '-common-companies', $permission->name);
$permission->save();
}
if (strstr($permission->name, '-items-items')) {
$permission->name = str_replace('-items-items', '-common-items', $permission->name);
$permission->save();
}
}
// Delete folders
$dirs = ['dashboard', 'search', 'companies', 'items'];
foreach ($dirs as $dir) {
File::deleteDirectory(app_path('Filters/' . ucfirst($dir)));
File::deleteDirectory(app_path('Http/Controllers/' . ucfirst($dir)));
File::deleteDirectory(app_path('Http/Requests/' . ucfirst(Str::singular($dir))));
File::deleteDirectory(resource_path('views/' . $dir));
}
}
}

View File

@ -1,31 +0,0 @@
<?php
namespace App\Listeners\Update\V12;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use Artisan;
class Version129 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.2.9';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Update database
Artisan::call('migrate', ['--force' => true]);
}
}

View File

@ -1,165 +0,0 @@
<?php
namespace App\Listeners\Update\V13;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Auth\Role;
use App\Models\Auth\Permission;
use Artisan;
class Version130 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.3.0';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Set new Item Reminder settings
setting()->setExtraColumns(['company_id' => session('company_id')]);
setting(['general.send_item_reminder' => '0']);
setting(['general.schedule_item_stocks' => '3,5,7']);
setting(['general.wizard' => '1']);
setting(['general.invoice_item' => 'settings.invoice.item']);
setting(['general.invoice_price' => 'settings.invoice.price']);
setting(['general.invoice_quantity' => 'settings.invoice.quantity']);
setting()->save();
$this->updatePermissions();
// Update database
Artisan::call('migrate', ['--force' => true]);
}
protected function updatePermissions()
{
$permissions = [];
// Banking Reconciliations
$permissions[] = Permission::firstOrCreate([
'name' => 'read-banking-reconciliations',
'display_name' => 'Read Banking Reconciliations',
'description' => 'Read Banking Reconciliations',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'create-banking-reconciliations',
'display_name' => 'Create Banking Reconciliations',
'description' => 'Create Banking Reconciliations',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'update-banking-reconciliations',
'display_name' => 'Update Banking Reconciliations',
'description' => 'Update Banking Reconciliations',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'delete-banking-reconciliations',
'display_name' => 'Delete Banking Reconciliations',
'description' => 'Delete Banking Reconciliations',
]);
// Create Wizard Permissions
$permissions[] = Permission::firstOrCreate([
'name' => 'create-wizard-companies',
'display_name' => 'Create Wizard Compaines',
'description' => 'Create Wizard Compaines',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'create-wizard-currencies',
'display_name' => 'Create Wizard Currencies',
'description' => 'Create Wizard Currencies',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'create-wizard-taxes',
'display_name' => 'Create Wizard Taxes',
'description' => 'Create Wizard Taxes',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'create-wizard-finish',
'display_name' => 'Create Wizard Finish',
'description' => 'Create Wizard Finish',
]);
// Read Wizard Permissions
$permissions[] = Permission::firstOrCreate([
'name' => 'read-wizard-companies',
'display_name' => 'Read Wizard Compaines',
'description' => 'Read Wizard Compaines',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'read-wizard-currencies',
'display_name' => 'Read Wizard Currencies',
'description' => 'Read Wizard Currencies',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'read-wizard-taxes',
'display_name' => 'Read Wizard Taxes',
'description' => 'Read Wizard Taxes',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'read-wizard-finish',
'display_name' => 'Read Wizard Finish',
'description' => 'Read Wizard Finish',
]);
// Update Wizard Permissions
$permissions[] = Permission::firstOrCreate([
'name' => 'update-wizard-companies',
'display_name' => 'Update Wizard Compaines',
'description' => 'Update Wizard Compaines',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'update-wizard-currencies',
'display_name' => 'Update Wizard Currencies',
'description' => 'Update Wizard Currencies',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'update-wizard-taxes',
'display_name' => 'Update Wizard Taxes',
'description' => 'Update Wizard Taxes',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'update-wizard-finish',
'display_name' => 'Update Wizard Finish',
'description' => 'Update Wizard Finish',
]);
// Attach permission to roles
$roles = Role::all();
foreach ($roles as $role) {
$allowed = ['admin', 'manager'];
if (!in_array($role->name, $allowed)) {
continue;
}
foreach ($permissions as $permission) {
$role->attachPermission($permission);
}
}
}
}

View File

@ -1,62 +0,0 @@
<?php
namespace App\Listeners\Update\V13;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Auth\Role;
use App\Models\Auth\Permission;
use Artisan;
class Version1311 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.3.11';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
$this->updatePermissions();
// Update database
Artisan::call('migrate', ['--force' => true]);
}
protected function updatePermissions()
{
$permissions = [];
// Common Uploads
$permissions[] = Permission::firstOrCreate([
'name' => 'read-common-uploads',
'display_name' => 'Read Common Uploads',
'description' => 'Read Common Uploads',
]);
// Attach permission to roles
$roles = Role::all();
foreach ($roles as $role) {
$allowed = ['admin', 'manager'];
if (!in_array($role->name, $allowed)) {
continue;
}
foreach ($permissions as $permission) {
$role->attachPermission($permission);
}
}
}
}

View File

@ -1,43 +0,0 @@
<?php
namespace App\Listeners\Update\V13;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Common\Company;
use App\Utilities\Installer;
use Artisan;
class Version1313 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.3.13';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
$schedule_time = '09:00';
// Get default locale if only 1 company
if (Company::all()->count() == 1) {
$schedule_time = setting('general.schedule_time', '09:00');
}
// Set default locale
Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $schedule_time . '"']);
// Update database
Artisan::call('migrate', ['--force' => true]);
}
}

View File

@ -1,114 +0,0 @@
<?php
namespace App\Listeners\Update\V13;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Common\Company;
use App\Utilities\Overrider;
use App\Models\Banking\Account;
use Artisan;
use Date;
class Version1316 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.3.16';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Cache Clear
Artisan::call('cache:clear');
$this->setSettings();
// Update database
Artisan::call('migrate', ['--force' => true]);
}
protected function setSettings()
{
$company_id = session('company_id');
// Create new bill statuses
$companies = Company::all();
foreach ($companies as $company) {
// Set settings
setting()->forgetAll();
session(['company_id' => $company->id]);
Overrider::load('settings');
$settings = [
'general.financial_start' => Date::now()->startOfYear()->format('d-m'),
'general.timezone' => 'Europe/London',
'general.date_format' => 'd M Y',
'general.date_separator' => 'space',
'general.percent_position' => 'after',
'general.invoice_number_prefix' => 'INV-',
'general.invoice_number_digit' => '5',
'general.invoice_number_next' => '1',
'general.default_payment_method' => 'offlinepayment.cash.1',
'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.send_item_reminder' => '0',
'general.schedule_item_stocks' => '3,5,7',
'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',
'general.wizard' => '0',
'general.invoice_item' => 'settings.invoice.item',
'general.invoice_price' => 'settings.invoice.price',
'general.invoice_quantity' => 'settings.invoice.quantity',
'offlinepayment.methods' => '[{"code":"offlinepayment.cash.1","name":"Cash","order":"1","description":null},{"code":"offlinepayment.bank_transfer.2","name":"Bank Transfer","order":"2","description":null}]',
];
foreach ($settings as $key => $value) {
if (!empty(setting($key))) {
continue;
}
setting([$key => $value]);
}
if (empty(setting('general.default_account'))) {
$account = Account::where('company_id', $company->id)->first();
if ($account) {
setting()->set('general.default_account', $account->id);
}
}
setting()->save();
}
setting()->forgetAll();
session(['company_id' => $company_id]);
Overrider::load('settings');
}
}

View File

@ -1,80 +0,0 @@
<?php
namespace App\Listeners\Update\V13;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Auth\Role;
use App\Models\Auth\Permission;
use Artisan;
class Version132 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.3.2';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
$this->updatePermissions();
// Update database
Artisan::call('migrate', ['--force' => true]);
}
protected function updatePermissions()
{
$permissions = [];
// Banking Reconciliations
$permissions[] = Permission::firstOrCreate([
'name' => 'read-common-notifications',
'display_name' => 'Read Common Notifications',
'description' => 'Read Common Notifications',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'create-common-notifications',
'display_name' => 'Create Common Notifications',
'description' => 'Create Common Notifications',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'update-common-notifications',
'display_name' => 'Update Common Notifications',
'description' => 'Update Common Notifications',
]);
$permissions[] = Permission::firstOrCreate([
'name' => 'delete-common-notifications',
'display_name' => 'Delete Common Notifications',
'description' => 'Delete Common Notifications',
]);
// Attach permission to roles
$roles = Role::all();
foreach ($roles as $role) {
$allowed = ['admin', 'manager'];
if (!in_array($role->name, $allowed)) {
continue;
}
foreach ($permissions as $permission) {
$role->attachPermission($permission);
}
}
}
}

View File

@ -1,33 +0,0 @@
<?php
namespace App\Listeners\Update\V13;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use Date;
class Version135 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.3.5';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Add financial year start to settings
setting()->setExtraColumns(['company_id' => session('company_id')]);
setting(['general.financial_start' => Date::now()->startOfYear()->format('d F')]);
setting()->save();
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace App\Listeners\Update\V13;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use Date;
class Version138 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.3.8';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
// Re-format financial start
$current_setting = setting('localisation.financial_start', Date::now()->startOfYear()->format('d F'));
setting()->setExtraColumns(['company_id' => session('company_id')]);
setting(['general.financial_start' => Date::parse($current_setting)->format('d-m')]);
setting()->save();
}
}

View File

@ -1,64 +0,0 @@
<?php
namespace App\Listeners\Update\V13;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use App\Models\Income\InvoiceItem;
use App\Models\Income\InvoiceItemTax;
use App\Models\Setting\Tax;
use Artisan;
class Version139 extends Listener
{
const ALIAS = 'core';
const VERSION = '1.3.9';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}
$this->copyOldInvoiceItemTaxes();
// Update database
Artisan::call('migrate', ['--force' => true]);
}
protected function copyOldInvoiceItemTaxes()
{
$company_id = session('company_id');
$invoice_items = InvoiceItem::where('company_id', '<>', '0')->where('tax_id', '<>', '0')->get();
foreach ($invoice_items as $invoice_item) {
session(['company_id' => $invoice_item->company_id]);
$tax = Tax::where('id', $invoice_item->tax_id)->first();
if (empty($tax)) {
continue;
}
InvoiceItemTax::create([
'company_id' => $invoice_item->company_id,
'invoice_id' => $invoice_item->invoice_id,
'invoice_item_id' => $invoice_item->id,
'tax_id' => $invoice_item->tax_id,
'name' => $tax->name,
'amount' => $invoice_item->tax,
]);
}
session(['company_id' => $company_id]);
}
}

View File

@ -48,6 +48,10 @@ class Version200 extends Listener
$this->copyTransactions();
$this->updateInvoices();
$this->updateBills();
$this->copyContacts();
$this->updateModules();
@ -527,6 +531,58 @@ class Version200 extends Listener
DB::table('payments')->delete();
}
public function updateInvoices()
{
DB::table('recurring')
->where('recurable_type', 'App\Models\Income\Invoice')
->update([
'recurable_type' => 'App\Models\Sale\Invoice',
]);
DB::table('mediables')
->where('mediable_type', 'App\Models\Income\Invoice')
->update([
'mediable_type' => 'App\Models\Sale\Invoice',
]);
if (Schema::hasTable('double_entry_ledger')) {
DB::table('double_entry_ledger')
->where('ledgerable_type', 'App\Models\Income\Invoice')
->update([
'ledgerable_type' => 'App\Models\Sale\Invoice',
]);
}
}
public function updateBills()
{
DB::table('recurring')
->where('recurable_type', 'App\Models\Expense\Bill')
->update([
'recurable_type' => 'App\Models\Purchase\Bill',
]);
DB::table('mediables')
->where('mediable_type', 'App\Models\Expense\Bill')
->update([
'mediable_type' => 'App\Models\Purchase\Bill',
]);
DB::table('mediables')
->where('mediable_type', 'App\Models\Expense\Vendor')
->update([
'mediable_type' => 'App\Models\Purchase\Vendor',
]);
if (Schema::hasTable('double_entry_ledger')) {
DB::table('double_entry_ledger')
->where('ledgerable_type', 'App\Models\Expense\Bill')
->update([
'ledgerable_type' => 'App\Models\Purchase\Bill',
]);
}
}
public function copyContacts()
{
$this->copyCustomers();
@ -688,6 +744,15 @@ class Version200 extends Listener
'update-customers-profile',
],
]);
$this->updatePermissionNames([
'expenses-bills' => 'purchases-bills',
'expenses-payments' => 'purchases-payments',
'expenses-vendors' => 'purchases-vendors',
'incomes-customers' => 'sales-customers',
'incomes-invoices' => 'sales-invoices',
'incomes-revenues' => 'sales-revenues',
]);
}
public function attachPermissions($items)
@ -745,6 +810,29 @@ class Version200 extends Listener
}
}
public function updatePermissionNames($items)
{
$prefixes = [
'create',
'read',
'update',
'delete',
];
foreach ($items as $old => $new) {
foreach ($prefixes as $prefix) {
$old_name = $prefix . '-' . $old;
$new_name = $prefix . '-' . $new;
DB::table('permissions')
->where('name', $old_name)
->update([
'name' => $new_name,
]);
}
}
}
public function deleteOldFiles()
{
$files = [
@ -859,8 +947,8 @@ class Version200 extends Listener
'resources/assets/js/components/Example.vue',
'resources/assets/sass/_variables.scss',
'resources/assets/sass/app.scss',
'resources/views/expenses/bills/bill.blade.php',
'resources/views/incomes/invoices/invoice.blade.php',
'resources/views/purchases/bills/bill.blade.php',
'resources/views/sales/invoices/invoice.blade.php',
'resources/views/layouts/customer.blade.php',
'resources/views/layouts/link.blade.php',
'resources/views/modules/token/create.blade.php',
@ -885,12 +973,26 @@ class Version200 extends Listener
$directories = [
'app/Filters',
'app/Http/Controllers/Api/Expenses',
'app/Http/Controllers/Api/Incomes',
'app/Http/Controllers/Expenses',
'app/Http/Controllers/Incomes',
'app/Http/Controllers/Customers',
'app/Http/Controllers/Reports',
'app/Http/Requests/Customer',
'app/Http/Requests/Expense',
'app/Http/Requests/Income',
'app/Jobs/Expense',
'app/Jobs/Income',
'app/Listeners/Incomes',
'app/Listeners/Updates',
'app/Models/Expense',
'app/Models/Income',
'app/Notifications/Expense',
'app/Notifications/Income',
'app/Overrides',
'app/Transformers/Expense',
'app/Transformers/Income',
'modules/OfflinePayment',
'public/js/chartjs',
'public/js/daterangepicker',
@ -898,10 +1000,14 @@ class Version200 extends Listener
'public/js/lightbox',
'public/js/moment',
'resources/views/customers',
'resources/views/expenses',
'resources/views/incomes',
'resources/views/partials/customer',
'resources/views/reports/expense_summary',
'resources/views/reports/income_expense_summary',
'resources/views/reports/income_summary',
'tests/Feature/Expenses',
'tests/Feature/Incomes',
'tests/Feature/Reports',
];