mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 16:34:36 -04:00
Fixes for importing Ninja clients/contacts
This commit is contained in:
parent
f188fada5e
commit
c43d122e91
@ -14,8 +14,10 @@ namespace App\Http\Requests\Company;
|
|||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
use App\Http\ValidationRules\Company\ValidCompanyQuantity;
|
use App\Http\ValidationRules\Company\ValidCompanyQuantity;
|
||||||
|
use App\Http\ValidationRules\Company\ValidSubdomain;
|
||||||
use App\Http\ValidationRules\ValidSettingsRule;
|
use App\Http\ValidationRules\ValidSettingsRule;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
class StoreCompanyRequest extends Request
|
class StoreCompanyRequest extends Request
|
||||||
@ -45,7 +47,13 @@ class StoreCompanyRequest extends Request
|
|||||||
if (isset($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) {
|
if (isset($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) {
|
||||||
$rules['portal_domain'] = 'sometimes|url';
|
$rules['portal_domain'] = 'sometimes|url';
|
||||||
} else {
|
} else {
|
||||||
$rules['subdomain'] = 'nullable|alpha_num';
|
|
||||||
|
if(Ninja::isHosted()){
|
||||||
|
$rules['subdomain'] = ['nullable|alpha_num', new ValidSubdomain($this->all())];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$rules['subdomain'] = 'nullable|alpha_num';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
|
@ -13,7 +13,9 @@ namespace App\Http\Requests\Company;
|
|||||||
|
|
||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
|
use App\Http\ValidationRules\Company\ValidSubdomain;
|
||||||
use App\Http\ValidationRules\ValidSettingsRule;
|
use App\Http\ValidationRules\ValidSettingsRule;
|
||||||
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
class UpdateCompanyRequest extends Request
|
class UpdateCompanyRequest extends Request
|
||||||
@ -46,7 +48,12 @@ class UpdateCompanyRequest extends Request
|
|||||||
if (isset($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) {
|
if (isset($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) {
|
||||||
$rules['portal_domain'] = 'sometimes|url';
|
$rules['portal_domain'] = 'sometimes|url';
|
||||||
} else {
|
} else {
|
||||||
$rules['subdomain'] = 'nullable|alpha_num';
|
|
||||||
|
if(Ninja::isHosted()){
|
||||||
|
$rules['subdomain'] = ['nullable|alpha_num', new ValidSubdomain($this->all())];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$rules['subdomain'] = 'nullable|alpha_num';
|
||||||
}
|
}
|
||||||
|
|
||||||
// if($this->company->account->isPaidHostedClient()) {
|
// if($this->company->account->isPaidHostedClient()) {
|
||||||
|
50
app/Http/ValidationRules/Company/ValidSubdomain.php
Normal file
50
app/Http/ValidationRules/Company/ValidSubdomain.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Http\ValidationRules\Company;
|
||||||
|
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
|
use Illuminate\Contracts\Validation\Rule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ValidCompanyQuantity.
|
||||||
|
*/
|
||||||
|
class ValidSubdomain implements Rule
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $attribute
|
||||||
|
* @param mixed $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
|
||||||
|
private $input;
|
||||||
|
|
||||||
|
public function __construct($input)
|
||||||
|
{
|
||||||
|
$this->input = $input;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function passes($attribute, $value)
|
||||||
|
{
|
||||||
|
if(empty($input['subdomain']))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return MultiDB::checkDomainAvailable($input['subdomain']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function message()
|
||||||
|
{
|
||||||
|
return ctrans('texts.subdomain_taken');
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,7 @@ use App\Exceptions\MigrationValidatorFailed;
|
|||||||
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
||||||
use App\Exceptions\ResourceDependencyMissing;
|
use App\Exceptions\ResourceDependencyMissing;
|
||||||
use App\Exceptions\ResourceNotAvailableForMigration;
|
use App\Exceptions\ResourceNotAvailableForMigration;
|
||||||
|
use App\Factory\ClientContactFactory;
|
||||||
use App\Factory\ClientFactory;
|
use App\Factory\ClientFactory;
|
||||||
use App\Factory\CompanyLedgerFactory;
|
use App\Factory\CompanyLedgerFactory;
|
||||||
use App\Factory\CreditFactory;
|
use App\Factory\CreditFactory;
|
||||||
@ -1641,9 +1642,60 @@ class Import implements ShouldQueue
|
|||||||
return $response->getBody();
|
return $response->getBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildNewUserPlan() :Client
|
||||||
|
{
|
||||||
|
$local_company = Company::find($this->company->id);
|
||||||
|
$owner = $local_company->owner();
|
||||||
|
|
||||||
|
$ninja_company = Company::on('db-ninja-01')->find(config('ninja.ninja_default_company_id'));
|
||||||
|
|
||||||
|
/* If we already have a record of this user - move along. */
|
||||||
|
if($client_contact = ClientContact::on('db-ninja-01')->where(['email' => $owner->email, 'company_id' => $ninja_company->id)->exists())
|
||||||
|
return $client_contact->client;
|
||||||
|
|
||||||
|
$ninja_client = ClientFactory::create($ninja_company->id, $ninja_company->owner()->id);
|
||||||
|
$ninja_client->setConnection('db-ninja-01');
|
||||||
|
$ninja_client->name = $owner->present()->name();
|
||||||
|
$ninja_client->address1 = $local_company->settings->address1;
|
||||||
|
$ninja_client->address2 = $local_company->settings->address2;
|
||||||
|
$ninja_client->city = $local_company->settings->city;
|
||||||
|
$ninja_client->postal_code = $local_company->settings->postal_code;
|
||||||
|
$ninja_client->state = $local_company->settings->state;
|
||||||
|
$ninja_client->country_id = $local_company->settings->country_id;
|
||||||
|
|
||||||
|
$ninja_client->save();
|
||||||
|
|
||||||
|
$ninja_client_contact = ClientContactFactory::create($ninja_company->id, $ninja_company->owner()->id);
|
||||||
|
$ninja_client_contact->setConnection('db-ninja-01');
|
||||||
|
$ninja_client_contact->first_name = $owner->first_name;
|
||||||
|
$ninja_client_contact->last_name = $owner->last_name;
|
||||||
|
$ninja_client_contact->client_id = $ninja_client->id;
|
||||||
|
$ninja_client_contact->email = $owner->email;
|
||||||
|
$ninja_client_contact->phone = $owner->phone;
|
||||||
|
$ninja_client_contact->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private function processNinjaTokens(array $data)
|
private function processNinjaTokens(array $data)
|
||||||
{
|
{
|
||||||
|
if(count($data) == 0)
|
||||||
|
$ninja_client = $this->buildNewUserPlan();
|
||||||
|
|
||||||
|
foreach($data as $token)
|
||||||
|
{
|
||||||
|
//get invoiceninja company_id
|
||||||
|
$ninja_company = Company::on('db-ninja-01')->where('id', config('ninja.ninja_default_company_id'))->first();
|
||||||
|
|
||||||
|
$token['company_id'] = $ninja_client->company_id;
|
||||||
|
$token['client_id'] = $ninja_client->id;
|
||||||
|
$token['user_id'] = $ninja_client->user_id;
|
||||||
|
$token['company_gateway_id'] = config('ninja.ninja_default_company_gateway_id')
|
||||||
|
//todo
|
||||||
|
|
||||||
|
$cgt = ClientGatewayToken::Create($token);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In V4 we use negative invoices (credits) and add then into the client balance. In V5, these sit off ledger and are applied later.
|
/* In V4 we use negative invoices (credits) and add then into the client balance. In V5, these sit off ledger and are applied later.
|
||||||
|
@ -56,6 +56,7 @@ class MultiDB
|
|||||||
return Company::whereSubdomain($subdomain)->get()->count() == 0;
|
return Company::whereSubdomain($subdomain)->get()->count() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//multi-db active
|
//multi-db active
|
||||||
foreach (self::$dbs as $db) {
|
foreach (self::$dbs as $db) {
|
||||||
if (Company::on($db)->whereSubdomain($subdomain)->get()->count() >= 1) {
|
if (Company::on($db)->whereSubdomain($subdomain)->get()->count() >= 1) {
|
||||||
@ -63,7 +64,7 @@ class MultiDB
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self::setDefaultDatabase();
|
//self::setDefaultDatabase();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -150,6 +150,8 @@ return [
|
|||||||
'ninja_stripe_key' => env('NINJA_STRIPE_KEY', null),
|
'ninja_stripe_key' => env('NINJA_STRIPE_KEY', null),
|
||||||
'ninja_stripe_publishable_key' => env('NINJA_PUBLISHABLE_KEY', null),
|
'ninja_stripe_publishable_key' => env('NINJA_PUBLISHABLE_KEY', null),
|
||||||
'ninja_stripe_client_id' => env('NINJA_STRIPE_CLIENT_ID', null),
|
'ninja_stripe_client_id' => env('NINJA_STRIPE_CLIENT_ID', null),
|
||||||
|
'ninja_default_company_id' => env('NINJA_COMPANY_ID', null),
|
||||||
|
'ninja_default_company_gateway_id' => env('NINJA_COMPANY_GATEWAY_ID', null),
|
||||||
'pdf_generator' => env('PDF_GENERATOR', false),
|
'pdf_generator' => env('PDF_GENERATOR', false),
|
||||||
'internal_queue_enabled' => env('INTERNAL_QUEUE_ENABLED', true),
|
'internal_queue_enabled' => env('INTERNAL_QUEUE_ENABLED', true),
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user