Add payment terms per company (#3759)

* remove first name last name required

* Working on check update script

* Add payment terms per company

* set enabled modules on company creation

* Add payment terms to migration
This commit is contained in:
David Bomba 2020-05-27 09:49:06 +10:00 committed by GitHub
parent 703ef51685
commit 8512db6b1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 101 additions and 4 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Jobs\Company;
use App\DataMapper\CompanySettings;
use App\Events\UserSignedUp;
use App\Models\Company;
use App\Models\PaymentTerm;
use App\Utils\Traits\MakesHash;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Request;
class CreateCompanyPaymentTerms
{
use MakesHash;
use Dispatchable;
protected $company;
protected $user;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($company, $user)
{
$this->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);
}
}

View File

@ -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();

View File

@ -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'

View File

@ -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();

View File

@ -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');

View File

@ -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' => ''],