diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index f64e9043fa9f..798f780e2229 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -20,6 +20,7 @@ use App\Http\Requests\Company\StoreCompanyRequest; use App\Http\Requests\Company\UpdateCompanyRequest; use App\Http\Requests\SignupRequest; use App\Jobs\Company\CreateCompany; +use App\Jobs\Company\CreateCompanyPaymentTerms; use App\Jobs\Company\CreateCompanyToken; use App\Jobs\Ninja\RefundCancelledAccount; use App\Jobs\RegisterNewAccount; @@ -204,6 +205,8 @@ class CompanyController extends BaseController $company = CreateCompany::dispatchNow($request->all(), auth()->user()->company()->account); + CreateCompanyPaymentTerms::dispatchNow($company, auth()->user()); + $company = $this->company_repo->save($request->all(), $company); $this->uploadLogo($request->file('company_logo'), $company, $company); diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index 349d255e489b..2c9a74e6b937 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -3,6 +3,7 @@ namespace App\Jobs\Account; use App\Events\Account\AccountCreated; use App\Jobs\Company\CreateCompany; +use App\Jobs\Company\CreateCompanyPaymentTerms; use App\Jobs\Company\CreateCompanyToken; use App\Jobs\User\CreateUser; use App\Models\Account; @@ -60,6 +61,8 @@ class CreateAccount $spaa9f78 = CreateUser::dispatchNow($this->request, $sp794f3f, $sp035a66, true); + CreateCompanyPaymentTerms::dispatchNow($sp035a66, $spaa9f78); + if ($spaa9f78) { auth()->login($spaa9f78, false); } diff --git a/app/Jobs/Company/CreateCompany.php b/app/Jobs/Company/CreateCompany.php index dcd7e2be1777..a1e017117fca 100644 --- a/app/Jobs/Company/CreateCompany.php +++ b/app/Jobs/Company/CreateCompany.php @@ -57,10 +57,10 @@ class CreateCompany $company->ip = request()->ip(); $company->settings = $settings; $company->db = config('database.default'); + $company->enabled_modules = config('ninja.enabled_modules'); $company->subdomain = isset($this->request['subdomain']) ? $this->request['subdomain'] : ''; $company->save(); - return $company; } } diff --git a/app/Jobs/Company/CreateCompanyPaymentTerms.php b/app/Jobs/Company/CreateCompanyPaymentTerms.php new file mode 100644 index 000000000000..35e5f73f6cfc --- /dev/null +++ b/app/Jobs/Company/CreateCompanyPaymentTerms.php @@ -0,0 +1,66 @@ +company = $company; + + $this->user = $user; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + + $paymentTerms = [ + ['num_days' => 0, 'name' => 'Net 0', 'company_id' => $this->company->id, 'user_id' => $this->user->id], + ['num_days' => 7, 'name' => '', 'company_id' => $this->company->id, 'user_id' => $this->user->id], + ['num_days' => 10, 'name' => '', 'company_id' => $this->company->id, 'user_id' => $this->user->id], + ['num_days' => 14, 'name' => '', 'company_id' => $this->company->id, 'user_id' => $this->user->id], + ['num_days' => 15, 'name' => '', 'company_id' => $this->company->id, 'user_id' => $this->user->id], + ['num_days' => 30, 'name' => '', 'company_id' => $this->company->id, 'user_id' => $this->user->id], + ['num_days' => 60, 'name' => '', 'company_id' => $this->company->id, 'user_id' => $this->user->id], + ['num_days' => 90, 'name' => '', 'company_id' => $this->company->id, 'user_id' => $this->user->id], + ]; + + PaymentTerm::insert($paymentTerms); + + } +} diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 5980825ad515..c01f2bc85d5c 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -38,6 +38,7 @@ use App\Models\Credit; use App\Models\Document; use App\Models\Invoice; use App\Models\Payment; +use App\Models\PaymentTerm; use App\Models\Product; use App\Models\Quote; use App\Models\TaxRate; @@ -86,6 +87,7 @@ class Import implements ShouldQueue private $available_imports = [ 'company', 'users', + 'payment_terms', 'tax_rates', 'clients', 'products', @@ -695,6 +697,28 @@ class Import implements ShouldQueue $data = null; } + private function processPaymentTerms(array $data) :void + { + + PaymentTerm::unguard(); + + $modified = collect($data)->map(function ($item){ + + $item['user_id'] = $this->user->id; + $item['company_id'] = $this->company->id; + + return $item; + + })->toArray(); + + PaymentTerm::insert($modified); + + PaymentTerm::reguard(); + + /*Improve memory handling by setting everything to null when we have finished*/ + $data = null; + } + private function processCompanyGateways(array $data) :void { CompanyGateway::unguard(); diff --git a/config/ninja.php b/config/ninja.php index 493a01d25f8f..0d166c960aa3 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -25,6 +25,7 @@ return [ 'company_id' => 0, 'hash_salt' => env('HASH_SALT', ''), 'currency_converter_api_key' => env('OPENEXCHANGE_APP_ID',''), + 'enabled_modules' => 4095, 'environment' => env('NINJA_ENVIRONMENT', 'selfhost'), // 'hosted', 'development', 'selfhost', 'reseller' diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 00556724d1db..5c773db50605 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -1046,7 +1046,7 @@ class CreateUsersTable extends Migration Schema::create('payment_terms', function ($table) { $table->increments('id'); - $table->integer('num_days'); + $table->integer('num_days')->nullable(); $table->string('name')->nullable(); $table->unsignedInteger('company_id')->nullable(); $table->unsignedInteger('user_id')->nullable(); diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 191679ce3ff7..2f9dd5c22978 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -28,7 +28,7 @@ class DatabaseSeeder extends Seeder $this->call('LanguageSeeder'); $this->call('CountriesSeeder'); $this->call('IndustrySeeder'); - $this->call('PaymentTermsSeeder'); + //$this->call('PaymentTermsSeeder'); $this->call('PaymentTypesSeeder'); $this->call('GatewayTypesSeeder'); $this->call('DateFormatsSeeder'); diff --git a/database/seeds/PaymentTermsSeeder.php b/database/seeds/PaymentTermsSeeder.php index 8679671df5dc..899e3e8ac6b3 100644 --- a/database/seeds/PaymentTermsSeeder.php +++ b/database/seeds/PaymentTermsSeeder.php @@ -10,7 +10,7 @@ class PaymentTermsSeeder extends Seeder Eloquent::unguard(); $paymentTerms = [ - ['num_days' => -1, 'name' => 'Net 0'], + ['num_days' => 0, 'name' => 'Net 0'], ['num_days' => 7, 'name' => ''], ['num_days' => 10, 'name' => ''], ['num_days' => 14, 'name' => ''],