diff --git a/app/Constants.php b/app/Constants.php index b1634af99de4..7ca6382aab75 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -451,6 +451,9 @@ if (! defined('APP_NAME')) { define('FILTER_INVOICE_DATE', 'invoice_date'); define('FILTER_PAYMENT_DATE', 'payment_date'); + define('ADDRESS_BILLING', 'billing_address'); + define('ADDRESS_SHIPPING', 'shipping_address'); + define('SOCIAL_GOOGLE', 'Google'); define('SOCIAL_FACEBOOK', 'Facebook'); define('SOCIAL_GITHUB', 'GitHub'); diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php index 65cccabfcfc6..4ca491d7bab5 100644 --- a/app/Http/Controllers/ExportController.php +++ b/app/Http/Controllers/ExportController.php @@ -170,7 +170,7 @@ class ExportController extends BaseController if ($request->input('include') === 'all' || $request->input('clients')) { $data['clients'] = Client::scope() - ->with('user', 'contacts', 'country', 'currency') + ->with('user', 'contacts', 'country', 'currency', 'shipping_country') ->withArchived() ->get(); } diff --git a/app/Models/Client.php b/app/Models/Client.php index 3213e3d17026..104325b080a9 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -53,6 +53,12 @@ class Client extends EntityModel 'quote_number_counter', 'public_notes', 'task_rate', + 'shipping_address1', + 'shipping_address2', + 'shipping_city', + 'shipping_state', + 'shipping_postal_code', + 'shipping_country_id', ]; @@ -179,6 +185,14 @@ class Client extends EntityModel return $this->belongsTo('App\Models\Country'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function shipping_country() + { + return $this->belongsTo('App\Models\Country'); + } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Ninja/Presenters/ClientPresenter.php b/app/Ninja/Presenters/ClientPresenter.php index 6bc87ebb46c1..d66c490b28b2 100644 --- a/app/Ninja/Presenters/ClientPresenter.php +++ b/app/Ninja/Presenters/ClientPresenter.php @@ -11,6 +11,11 @@ class ClientPresenter extends EntityPresenter return $this->entity->country ? $this->entity->country->name : ''; } + public function shipping_country() + { + return $this->entity->shipping_country ? $this->entity->shipping_country->name : ''; + } + public function balance() { $client = $this->entity; @@ -51,6 +56,49 @@ class ClientPresenter extends EntityPresenter return sprintf('%s: %s %s', trans('texts.payment_terms'), trans('texts.payment_terms_net'), $client->defaultDaysDue()); } + public function address($addressType = ADDRESS_BILLING) + { + $str = ''; + $prefix = $addressType == ADDRESS_BILLING ? '' : 'shipping_'; + $client = $this->entity; + + if ($address1 = $client->{$prefix . 'address1'}) { + $str .= e($address1) . '
'; + } + if ($address2 = $client->{$prefix . 'address2'}) { + $str .= e($address2) . '
'; + } + if ($cityState = $this->getCityState($addressType)) { + $str .= e($cityState) . '
'; + } + if ($country = $client->{$prefix . 'country'}) { + $str .= e($country->name) . '
'; + } + + if ($str) { + $str = '' . trans('texts.' . $addressType) . '
' . $str; + } + + return $str; + } + + /** + * @return string + */ + public function getCityState($addressType = ADDRESS_BILLING) + { + $client = $this->entity; + $prefix = $addressType == ADDRESS_BILLING ? '' : 'shipping_'; + $swap = $client->{$prefix . 'country'} && $client->{$prefix . 'country'}->swap_postal_code; + + $city = e($client->{$prefix . 'city'}); + $state = e($client->{$prefix . 'state'}); + $postalCode = e($client->{$prefix . 'post_code'}); + + return Utils::cityStateZip($city, $state, $postalCode, $swap); + } + + /** * @return string */ diff --git a/app/Ninja/Transformers/ClientTransformer.php b/app/Ninja/Transformers/ClientTransformer.php index e6814a287f5e..a4277045a9b5 100644 --- a/app/Ninja/Transformers/ClientTransformer.php +++ b/app/Ninja/Transformers/ClientTransformer.php @@ -38,6 +38,12 @@ class ClientTransformer extends EntityTransformer * @SWG\Property(property="id_number", type="string", example="123456") * @SWG\Property(property="language_id", type="integer", example=1) * @SWG\Property(property="task_rate", type="number", format="float", example=10) + * @SWG\Property(property="shipping_address1", type="string", example="10 Main St.") + * @SWG\Property(property="shipping_address2", type="string", example="1st Floor") + * @SWG\Property(property="shipping_city", type="string", example="New York") + * @SWG\Property(property="shipping_state", type="string", example="NY") + * @SWG\Property(property="shipping_postal_code", type="string", example=10010) + * @SWG\Property(property="shipping_country_id", type="integer", example=840) */ protected $defaultIncludes = [ 'contacts', @@ -137,6 +143,12 @@ class ClientTransformer extends EntityTransformer 'invoice_number_counter' => (int) $client->invoice_number_counter, 'quote_number_counter' => (int) $client->quote_number_counter, 'task_rate' => (float) $client->task_rate, + 'shipping_address1' => $client->shipping_address1, + 'shipping_address2' => $client->shipping_address2, + 'shipping_city' => $client->shipping_city, + 'shipping_state' => $client->shipping_state, + 'shipping_postal_code' => $client->shipping_postal_code, + 'shipping_country_id' => (int) $client->shipping_country_id, ]); } } diff --git a/database/migrations/2017_11_15_114422_add_subdomain_to_lookups.php b/database/migrations/2017_11_15_114422_add_subdomain_to_lookups.php index 773e4c2981db..23522d925241 100644 --- a/database/migrations/2017_11_15_114422_add_subdomain_to_lookups.php +++ b/database/migrations/2017_11_15_114422_add_subdomain_to_lookups.php @@ -26,6 +26,18 @@ class AddSubdomainToLookups extends Migration $table->decimal('exchange_rate', 13, 4)->default(1)->change(); }); + Schema::table('clients', function ($table) { + $table->string('shipping_address1')->nullable(); + $table->string('shipping_address2')->nullable(); + $table->string('shipping_city')->nullable(); + $table->string('shipping_state')->nullable(); + $table->string('shipping_postal_code')->nullable(); + $table->unsignedInteger('shipping_country_id')->nullable(); + }); + + Schema::table('clients', function ($table) { + $table->foreign('shipping_country_id')->references('id')->on('currencies'); + }); } /** @@ -43,5 +55,15 @@ class AddSubdomainToLookups extends Migration $table->dropColumn('exchange_rate'); $table->dropColumn('exchange_currency_id'); }); + + Schema::table('clients', function ($table) { + $table->dropForeign('clients_shipping_country_id_foreign'); + $table->dropColumn('shipping_address1'); + $table->dropColumn('shipping_address2'); + $table->dropColumn('shipping_city'); + $table->dropColumn('shipping_state'); + $table->dropColumn('shipping_postal_code'); + $table->dropColumn('shipping_country_id'); + }); } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 17e59c463340..bf0962a59a65 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2526,6 +2526,20 @@ $LANG = array( 'client_login' => 'Client Login', 'converted_amount' => 'Converted Amount', 'default' => 'Default', + 'shipping_address' => 'Shipping Address', + 'bllling_address' => 'Billing Address', + 'billing_address1' => 'Billing Street', + 'billing_address2' => 'Billing Apt/Suite', + 'billing_city' => 'Billing City', + 'billing_state' => 'Billing State/Province', + 'billing_postal_code' => 'Billing Postal Code', + 'billing_country' => 'Billing Country', + 'shipping_address1' => 'Shipping Street', + 'shipping_address2' => 'Shipping Apt/Suite', + 'shipping_city' => 'Shipping City', + 'shipping_state' => 'Shipping State/Province', + 'shipping_postal_code' => 'Shipping Postal Code', + 'shipping_country' => 'Shipping Country', ); diff --git a/resources/views/clients/edit.blade.php b/resources/views/clients/edit.blade.php index 32c091fbb19b..38fd0fbae51b 100644 --- a/resources/views/clients/edit.blade.php +++ b/resources/views/clients/edit.blade.php @@ -68,19 +68,42 @@ -
+

{!! trans('texts.address') !!}

- {!! Former::text('address1') !!} - {!! Former::text('address2') !!} - {!! Former::text('city') !!} - {!! Former::text('state') !!} - {!! Former::text('postal_code') !!} - {!! Former::select('country_id')->addOption('','') - ->fromQuery($countries, 'name', 'id') !!} +
+ +
+
+
+ {!! Former::text('address1') !!} + {!! Former::text('address2') !!} + {!! Former::text('city') !!} + {!! Former::text('state') !!} + {!! Former::text('postal_code') !!} + {!! Former::select('country_id')->addOption('','') + ->fromQuery($countries, 'name', 'id') !!} +
+
+ {!! Former::text('shipping_address1')->label('address1') !!} + {!! Former::text('shipping_address2')->label('address2') !!} + {!! Former::text('shipping_city')->label('city') !!} + {!! Former::text('shipping_state')->label('state') !!} + {!! Former::text('shipping_postal_code')->label('postal_code') !!} + {!! Former::select('shipping_country_id')->addOption('','') + ->fromQuery($countries, 'name', 'id')->label('country_id') !!} +
+
@@ -233,7 +256,7 @@