Optional shipping address #1088

This commit is contained in:
Hillel Coren 2017-11-19 14:52:42 +02:00
parent 4de9b614dc
commit b202b62a23
10 changed files with 166 additions and 28 deletions

View File

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

View File

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

View File

@ -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
*/

View File

@ -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) . '<br/>';
}
if ($address2 = $client->{$prefix . 'address2'}) {
$str .= e($address2) . '<br/>';
}
if ($cityState = $this->getCityState($addressType)) {
$str .= e($cityState) . '<br/>';
}
if ($country = $client->{$prefix . 'country'}) {
$str .= e($country->name) . '<br/>';
}
if ($str) {
$str = '<b>' . trans('texts.' . $addressType) . '</b><br/>' . $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
*/

View File

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

View File

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

View File

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

View File

@ -68,19 +68,42 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{!! trans('texts.address') !!}</h3>
</div>
<div class="panel-body">
{!! 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') !!}
<div role="tabpanel">
<ul class="nav nav-tabs" role="tablist" style="border: none">
<li role="presentation" class="active">
<a href="#billing_address" aria-controls="billing_address" role="tab" data-toggle="tab">{{ trans('texts.billing_address') }}</a>
</li>
<li role="presentation">
<a href="#shipping_address" aria-controls="shipping_address" role="tab" data-toggle="tab">{{ trans('texts.shipping_address') }}</a>
</li>
</ul>
</div>
<div class="tab-content" style="padding-top:24px;">
<div role="tabpanel" class="tab-pane active" id="billing_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') !!}
</div>
<div role="tabpanel" class="tab-pane" id="shipping_address">
{!! 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') !!}
</div>
</div>
</div>
</div>
@ -233,7 +256,7 @@
<script type="text/javascript">
$(function() {
$('#country_id').combobox();
$('#country_id, #shipping_country_id').combobox();
});
function ContactModel(data) {

View File

@ -98,18 +98,8 @@
<p><i class="fa fa-vat-number" style="width: 20px"></i>{{ trans('texts.vat_number').': '.$client->vat_number }}</p>
@endif
@if ($client->address1)
{{ $client->address1 }}<br/>
@endif
@if ($client->address2)
{{ $client->address2 }}<br/>
@endif
@if ($client->getCityState())
{{ $client->getCityState() }}<br/>
@endif
@if ($client->country)
{{ $client->country->name }}<br/>
@endif
{!! $client->present()->address(ADDRESS_BILLING) !!}
{!! $client->present()->address(ADDRESS_SHIPPING) !!}
<br/>

View File

@ -5,12 +5,18 @@
@endif
<td>{{ trans('texts.balance') }}</td>
<td>{{ trans('texts.paid_to_date') }}</td>
<td>{{ trans('texts.address1') }}</td>
<td>{{ trans('texts.address2') }}</td>
<td>{{ trans('texts.city') }}</td>
<td>{{ trans('texts.state') }}</td>
<td>{{ trans('texts.postal_code') }}</td>
<td>{{ trans('texts.country') }}</td>
<td>{{ trans('texts.billing_address1') }}</td>
<td>{{ trans('texts.billing_address2') }}</td>
<td>{{ trans('texts.billing_city') }}</td>
<td>{{ trans('texts.billing_state') }}</td>
<td>{{ trans('texts.billing_postal_code') }}</td>
<td>{{ trans('texts.billing_country') }}</td>
<td>{{ trans('texts.shipping_address1') }}</td>
<td>{{ trans('texts.shipping_address2') }}</td>
<td>{{ trans('texts.shipping_city') }}</td>
<td>{{ trans('texts.shipping_state') }}</td>
<td>{{ trans('texts.shipping_postal_code') }}</td>
<td>{{ trans('texts.shipping_country') }}</td>
<td>{{ trans('texts.id_number') }}</td>
<td>{{ trans('texts.vat_number') }}</td>
<td>{{ trans('texts.website') }}</td>
@ -50,6 +56,12 @@
<td>{{ $client->state }}</td>
<td>{{ $client->postal_code }}</td>
<td>{{ $client->present()->country }}</td>
<td>{{ $client->shipping_address1 }}</td>
<td>{{ $client->shipping_address2 }}</td>
<td>{{ $client->shipping_city }}</td>
<td>{{ $client->shipping_state }}</td>
<td>{{ $client->shipping_postal_code }}</td>
<td>{{ $client->present()->shipping_country }}</td>
<td>{{ $client->id_number }}</td>
<td>{{ $client->vat_number }}</td>
<td>{{ $client->website }}</td>