diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php
index 2f8a4572108e..eff17eebade1 100644
--- a/app/DataMapper/CompanySettings.php
+++ b/app/DataMapper/CompanySettings.php
@@ -151,7 +151,37 @@ class CompanySettings extends BaseSettings
public $require_invoice_signature = false;
public $require_quote_signature = false;
+
+ /* Company Meta data that we can use to build sub companies*/
+
+ public $name;
+ public $logo_url;
+ public $website;
+ public $address1;
+ public $address2;
+ public $city;
+ public $state;
+ public $postal_code;
+ public $phone;
+ public $email;
+ public $country_id;
+ public $vat_number;
+ public $id_number;
+
public static $casts = [
+ 'name' => 'string',
+ 'logo_url' => 'string',
+ 'website' => 'string',
+ 'address1' => 'string',
+ 'address2' => 'string',
+ 'city' => 'string',
+ 'state' => 'string',
+ 'postal_code' => 'string',
+ 'phone' => 'string',
+ 'email' => 'string',
+ 'country_id' => 'string',
+ 'vat_number' => 'string',
+ 'id_number' => 'string',
'has_custom_design1' => 'bool',
'has_custom_design2' => 'bool',
'has_custom_design3' => 'bool',
@@ -263,6 +293,7 @@ class CompanySettings extends BaseSettings
$data->date_format_id = (string)config('ninja.i18n.date_format_id');
$data->start_of_week = (int) config('ninja.i18n.start_of_week');
$data->financial_year_start = (int)config('ninja.i18n.financial_year_start');
+ $data->country_id = (int)config('ninja.i18n.country_id');
$data->translations = (object) [];
return self::setCasts($data, self::$casts);
@@ -288,7 +319,9 @@ class CompanySettings extends BaseSettings
$settings->{$key} = self::castAttribute($key, $company_settings->{$key});
}
+
return $settings;
+
}
}
diff --git a/app/Factory/CompanyFactory.php b/app/Factory/CompanyFactory.php
index 3658f9ff1725..f6d744ba2c0e 100644
--- a/app/Factory/CompanyFactory.php
+++ b/app/Factory/CompanyFactory.php
@@ -23,7 +23,7 @@ class CompanyFactory
{
$company = new Company;
- $company->name = '';
+// $company->name = '';
$company->account_id = $account_id;
$company->company_key = $this->createHash();
$company->settings = CompanySettings::defaults();
diff --git a/app/Models/Company.php b/app/Models/Company.php
index 84cd7cbed73a..34ecb4340645 100644
--- a/app/Models/Company.php
+++ b/app/Models/Company.php
@@ -43,20 +43,20 @@ class Company extends BaseModel
protected $presenter = 'App\Models\Presenters\CompanyPresenter';
protected $fillable = [
- 'name',
- 'logo',
+ // 'name',
+ // 'logo',
'industry_id',
- 'address1',
- 'address2',
- 'city',
- 'state',
- 'postal_code',
- 'phone',
- 'email',
- 'country_id',
+ // 'address1',
+ // 'address2',
+ // 'city',
+ // 'state',
+ // 'postal_code',
+ // 'phone',
+ // 'email',
+ // 'country_id',
'domain',
- 'vat_number',
- 'id_number',
+ // 'vat_number',
+ // 'id_number',
'size_id',
'settings',
];
@@ -157,7 +157,8 @@ class Company extends BaseModel
*/
public function country()
{
- return $this->belongsTo(Country::class);
+ //return $this->belongsTo(Country::class);
+ return Country::find($this->settings->country_id);
}
public function group_settings()
diff --git a/app/Models/Presenters/CompanyPresenter.php b/app/Models/Presenters/CompanyPresenter.php
index 146e6789d3c8..c4daa75d9462 100644
--- a/app/Models/Presenters/CompanyPresenter.php
+++ b/app/Models/Presenters/CompanyPresenter.php
@@ -36,26 +36,43 @@ class CompanyPresenter extends EntityPresenter
$str = '';
$company = $this->entity;
- if ($address1 = $company->address1) {
+ if ($address1 = $company->settings->address1) {
$str .= e($address1) . '
';
}
- if ($address2 = $company->address2) {
+ if ($address2 = $company->settings->address2) {
$str .= e($address2) . '
';
}
- if ($cityState = $this->getCityState()) {
+ if ($cityState = $this->getCompanyCityState()) {
$str .= e($cityState) . '
';
}
- if ($country = $company->country) {
+ if ($country = $company->country()) {
$str .= e($country->name) . '
';
}
- if ($company->phone) {
- $str .= ctrans('texts.work_phone') . ": ". e($company->phone) .'
';
+ if ($company->settings->phone) {
+ $str .= ctrans('texts.work_phone') . ": ". e($company->settings->phone) .'
';
}
- if ($company->email) {
- $str .= ctrans('texts.work_email') . ": ". e($company->email) .'
';
+ if ($company->settings->email) {
+ $str .= ctrans('texts.work_email') . ": ". e($company->settings->email) .'
';
}
return $str;
}
+ public function getCompanyCityState()
+ {
+ $company = $this->entity;
+
+ $swap = $company->country() && $company->country()->swap_postal_code;
+
+ $city = e($company->settings->city);
+ $state = e($company->settings->state);
+ $postalCode = e($company->settings->postal_code);
+
+ if ($city || $state || $postalCode) {
+ return $this->cityStateZip($city, $state, $postalCode, $swap);
+ } else {
+ return false;
+ }
+ }
+
}
diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php
index be5f256a2ea4..1e27cc7457c9 100644
--- a/app/Transformers/CompanyTransformer.php
+++ b/app/Transformers/CompanyTransformer.php
@@ -65,20 +65,20 @@ class CompanyTransformer extends EntityTransformer
{
return [
'id' => (string)$this->encodePrimaryKey($company->id),
- 'name' => (string)$company->name ?: '',
- 'website' => (string)$company->website ?: '',
- 'logo_url' => (string)$company->getLogo(),
+ // 'name' => (string)$company->name ?: '',
+ // 'website' => (string)$company->website ?: '',
+ // 'logo_url' => (string)$company->getLogo(),
'company_key' => (string)$company->company_key ?: '',
- 'address1' => (string)$company->address1 ?: '',
- 'address2' => (string)$company->address2 ?: '',
- 'city' => (string)$company->city ?: '',
- 'state' => (string)$company->state ?: '',
- 'postal_code' => (string)$company->postal_code ?: '',
- 'phone' => (string)$company->phone ?: '',
- 'email' => (string)$company->email ?: '',
- 'country_id' => (string) $company->country_id ?: '',
- 'vat_number' => (string)$company->vat_number ?: '',
- 'id_number' => (string)$company->id_number ?: '',
+ // 'address1' => (string)$company->address1 ?: '',
+ // 'address2' => (string)$company->address2 ?: '',
+ // 'city' => (string)$company->city ?: '',
+ // 'state' => (string)$company->state ?: '',
+ // 'postal_code' => (string)$company->postal_code ?: '',
+ // 'phone' => (string)$company->phone ?: '',
+ // 'email' => (string)$company->email ?: '',
+ // 'country_id' => (string) $company->country_id ?: '',
+ // 'vat_number' => (string)$company->vat_number ?: '',
+ // 'id_number' => (string)$company->id_number ?: '',
'size_id' => (string) $company->size_id ?: '',
'industry_id' => (string) $company->industry_id ?: '',
'settings' => $company->settings ?: '',
diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php
index 1701680155c3..74874067e48f 100644
--- a/app/Utils/Traits/MakesInvoiceValues.php
+++ b/app/Utils/Traits/MakesInvoiceValues.php
@@ -211,7 +211,7 @@ trait MakesInvoiceValues
$data['$company_city'] = $this->company->city;
$data['$company_state'] = $this->company->state;
$data['$company_postal_code'] = $this->company->postal_code;
- $data['$company_country'] = $this->company->country ? $this->company->country->name : '';
+ $data['$company_country'] = $this->company->country() ? $this->company->country()->name : '';
$data['$company_phone'] = $this->company->phone;
$data['$company_email'] = $this->company->email;
$data['$company_vat_number'] = $this->company->vat_number;
diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php
index a162517f2174..5e6e137e1600 100644
--- a/database/factories/CompanyFactory.php
+++ b/database/factories/CompanyFactory.php
@@ -5,19 +5,19 @@ use Faker\Generator as Faker;
$factory->define(App\Models\Company::class, function (Faker $faker) {
return [
- 'name' => $faker->name,
+ //'name' => $faker->name,
'company_key' => strtolower(\Illuminate\Support\Str::random(config('ninja.key_length'))),
'ip' => $faker->ipv4,
'db' => config('database.default'),
'settings' => CompanySettings::defaults(),
- 'address1' => $faker->secondaryAddress,
- 'address2' => $faker->address,
- 'city' => $faker->city,
- 'state' => $faker->state,
- 'postal_code' => $faker->postcode,
- 'country_id' => 4,
- 'phone' => $faker->phoneNumber,
- 'email' => $faker->safeEmail,
- 'logo' => 'https://www.invoiceninja.com/wp-content/themes/invoice-ninja/images/logo.png',
+ // 'address1' => $faker->secondaryAddress,
+ // 'address2' => $faker->address,
+ // 'city' => $faker->city,
+ // 'state' => $faker->state,
+ // 'postal_code' => $faker->postcode,
+ // 'country_id' => 4,
+ // 'phone' => $faker->phoneNumber,
+ // 'email' => $faker->safeEmail,
+ // 'logo' => 'https://www.invoiceninja.com/wp-content/themes/invoice-ninja/images/logo.png',
];
});
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 872c794c3a5c..3e340cb203e5 100644
--- a/database/migrations/2014_10_13_000000_create_users_table.php
+++ b/database/migrations/2014_10_13_000000_create_users_table.php
@@ -127,24 +127,25 @@ class CreateUsersTable extends Migration
Schema::create('companies', function (Blueprint $table) {
$table->increments('id');
- $table->string('name')->nullable();
+ //$table->string('name')->nullable();
$table->unsignedInteger('account_id')->index();
$table->unsignedInteger('industry_id')->nullable();
$table->string('ip')->nullable();
$table->string('company_key',100)->unique();
$table->string('logo')->nullable();
- $table->string('address1')->nullable();
- $table->string('address2')->nullable();
- $table->string('city')->nullable();
- $table->string('state')->nullable();
- $table->string('postal_code')->nullable();
- $table->string('phone')->nullable();
- $table->string('email')->nullable();
- $table->unsignedInteger('country_id')->nullable();
+ // $table->string('website')->nullable();
+ // $table->string('address1')->nullable();
+ // $table->string('address2')->nullable();
+ // $table->string('city')->nullable();
+ // $table->string('state')->nullable();
+ // $table->string('postal_code')->nullable();
+ // $table->string('phone')->nullable();
+ // $table->string('email')->nullable();
+ // $table->unsignedInteger('country_id')->nullable();
$table->string('domain')->nullable();
$table->string('db')->nullable();
- $table->string('vat_number')->nullable();
- $table->string('id_number')->nullable();
+ // $table->string('vat_number')->nullable();
+ // $table->string('id_number')->nullable();
$table->unsignedInteger('size_id')->nullable();
$table->string('start_of_week')->nullable();
$table->string('financial_year_start')->nullable();
@@ -154,7 +155,7 @@ class CreateUsersTable extends Migration
$table->timestamps(6);
$table->softDeletes();
- $table->foreign('country_id')->references('id')->on('countries');
+ //$table->foreign('country_id')->references('id')->on('countries');
$table->foreign('industry_id')->references('id')->on('industries');
$table->foreign('size_id')->references('id')->on('sizes');
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');