diff --git a/app/Http/Controllers/LogoutController.php b/app/Http/Controllers/LogoutController.php new file mode 100644 index 000000000000..eda0c48d991c --- /dev/null +++ b/app/Http/Controllers/LogoutController.php @@ -0,0 +1,72 @@ +whereRaw('BINARY `token`= ?', [$request->header('X-API-TOKEN')]) + ->company + ->tokens() + ->where('is_system', true) + ->forceDelete(); + + return response()->json(['message' => 'All tokens deleted'], 200); + } + +} diff --git a/app/Http/Controllers/SelfUpdateController.php b/app/Http/Controllers/SelfUpdateController.php index ae46dbe8bcc8..70e3e03698a9 100644 --- a/app/Http/Controllers/SelfUpdateController.php +++ b/app/Http/Controllers/SelfUpdateController.php @@ -66,7 +66,7 @@ class SelfUpdateController extends BaseController throw new FilePermissionsFailure('Cannot update system because files are not writable!'); // Check if new version is available - if($updater->source()->isNewVersionAvailable()) { + //if($updater->source()->isNewVersionAvailable()) { // Get the new version available $versionAvailable = $updater->source()->getVersionAvailable(); @@ -76,7 +76,7 @@ class SelfUpdateController extends BaseController $updater->source()->update($release); - } + //} $cacheCompiled = base_path('bootstrap/cache/compiled.php'); if (file_exists($cacheCompiled)) { unlink ($cacheCompiled); } diff --git a/app/Http/Controllers/SubdomainController.php b/app/Http/Controllers/SubdomainController.php index 73733e382c7c..9606da46187f 100644 --- a/app/Http/Controllers/SubdomainController.php +++ b/app/Http/Controllers/SubdomainController.php @@ -28,9 +28,8 @@ class SubdomainController extends BaseController */ public function index() { - $subdomain_exists = MultiDB::findAndSetDbByDomain(request()->input('subdomain')); - if($subdomain_exists) + if( MultiDB::findAndSetDbByDomain(request()->input('subdomain')) ) return response()->json(['message' => 'Domain not available'] , 401); return response()->json(['message' => 'Domain available'], 200); diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index fdb46be634dd..a50b64db9383 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -192,6 +192,15 @@ class Import implements ShouldQueue $array = json_decode(file_get_contents($this->file_path), 1); $data = $array['data']; + + // disable some functionality here: + // 1. disable update_products + + $update_product_state = $this->company->update_products; + + $this->company->update_products = false; + $this->company->save(); + foreach ($this->available_imports as $import) { if (! array_key_exists($import, $data)) { //throw new ResourceNotAvailableForMigration("Resource {$key} is not available for migration."); @@ -211,9 +220,10 @@ class Import implements ShouldQueue // $this->fixClientBalances(); $check_data = CheckCompanyData::dispatchNow($this->company, md5(time())); - // if($check_data['status'] == 'errors') - // throw new ProcessingMigrationArchiveFailed(implode("\n", $check_data)); - + //reset functionality here + $this->company->update_products = $update_product_state; + $this->company->save(); + try{ Mail::to($this->user->email, $this->user->name()) ->send(new MigrationCompleted($this->company, implode("
",$check_data))); @@ -224,7 +234,12 @@ class Import implements ShouldQueue /*After a migration first some basic jobs to ensure the system is up to date*/ VersionCheck::dispatch(); - CompanySizeCheck::dispatch(); + + //company size check + if ($this->company->invoices()->count() > 1000 || $this->company->products()->count() > 1000 || $this->company->clients()->count() > 1000) { + $company->is_large = true; + $company->save(); + } info('CompletedπŸš€πŸš€πŸš€πŸš€πŸš€ at '.now()); diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 7b69e223894b..92132a118be2 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -16,6 +16,7 @@ use App\Models\ClientContact; use App\Models\Company; use App\Models\CompanyToken; use App\Models\User; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; /** @@ -293,10 +294,17 @@ class MultiDB { /* This will set the database connection for the request */ config(['database.default' => $database]); + + // for some reason this breaks everything _hard_ + // DB::purge($database); + // DB::reconnect($database); } public static function setDefaultDatabase() { config(['database.default' => config('ninja.db.default')]); + + // DB::purge(config('ninja.db.default')); + // DB::reconnect(config('ninja.db.default')); } } diff --git a/app/Models/Task.php b/app/Models/Task.php index 3e3d902dcbdd..b34f9f062a4c 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -74,6 +74,11 @@ class Task extends BaseModel return $this->belongsTo(Client::class); } + public function status() + { + return $this->belongsTo(TaskStatus::class); + } + public function invoice() { return $this->belongsTo(Invoice::class); diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index 778b695763ae..45f1cf20b884 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -22,6 +22,7 @@ class TaskRepository extends BaseRepository { use GeneratesCounter; + public $new_task = true; /** * Saves the task and its contacts. @@ -33,10 +34,15 @@ class TaskRepository extends BaseRepository */ public function save(array $data, Task $task) : ?Task { + if($task->id) + $this->new_task = false; $task->fill($data); $task->save(); + if($this->new_task && !$task->status_id) + $this->setDefaultStatus($task); + $task->number = empty($task->number) || !array_key_exists('number', $data) ? $this->getNextTaskNumber($task) : $data['number']; if (isset($data['description'])) { @@ -103,6 +109,19 @@ class TaskRepository extends BaseRepository } + private function setDefaultStatus(Task $task) + { + $first_status = $task->company->task_statuses() + ->whereNull('deleted_at') + ->orderBy('id','asc') + ->first(); + + if($first_status) + return $first_status->id; + + return null; + } + /** * Sorts the task status order IF the old status has changed between requests * diff --git a/database/factories/ProductFactory.php b/database/factories/ProductFactory.php index 12f41ccd03cc..3ef22ae4bade 100644 --- a/database/factories/ProductFactory.php +++ b/database/factories/ProductFactory.php @@ -35,12 +35,12 @@ class ProductFactory extends Factory 'cost' => $this->faker->numberBetween(1, 1000), 'price' => $this->faker->numberBetween(1, 1000), 'quantity' => $this->faker->numberBetween(1, 100), - 'tax_name1' => 'GST', - 'tax_rate1' => 10, - 'tax_name2' => 'VAT', - 'tax_rate2' => 17.5, - 'tax_name3' => 'THIRDTAX', - 'tax_rate3' => 5, + // 'tax_name1' => 'GST', + // 'tax_rate1' => 10, + // 'tax_name2' => 'VAT', + // 'tax_rate2' => 17.5, + // 'tax_name3' => 'THIRDTAX', + // 'tax_rate3' => 5, 'custom_value1' => $this->faker->text(20), 'custom_value2' => $this->faker->text(20), 'custom_value3' => $this->faker->text(20), diff --git a/routes/api.php b/routes/api.php index 1dd0e044e87b..2e84a7977cc1 100644 --- a/routes/api.php +++ b/routes/api.php @@ -90,6 +90,8 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::put('invoices/{invoice}/upload', 'InvoiceController@upload')->name('invoices.upload'); Route::get('invoice/{invitation_key}/download', 'InvoiceController@downloadPdf')->name('invoices.downloadPdf'); Route::post('invoices/bulk', 'InvoiceController@bulk')->name('invoices.bulk'); + + Route::post('logout', 'LogoutController@index')->name('logout'); Route::post('migrate', 'MigrationController@index')->name('migrate.start');