Improvements to client import/export

This commit is contained in:
Hillel Coren 2017-08-03 20:07:16 +03:00
parent 1d1621f11d
commit 0493848d7e
5 changed files with 75 additions and 77 deletions

View File

@ -170,7 +170,7 @@ class ExportController extends BaseController
if ($request->input('include') === 'all' || $request->input('clients')) { if ($request->input('include') === 'all' || $request->input('clients')) {
$data['clients'] = Client::scope() $data['clients'] = Client::scope()
->with('user', 'contacts', 'country') ->with('user', 'contacts', 'country', 'currency')
->withArchived() ->withArchived()
->get(); ->get();
} }

View File

@ -54,54 +54,7 @@ class Client extends EntityModel
'public_notes', 'public_notes',
]; ];
/**
* @var string
*/
public static $fieldName = 'name';
/**
* @var string
*/
public static $fieldPhone = 'work_phone';
/**
* @var string
*/
public static $fieldAddress1 = 'address1';
/**
* @var string
*/
public static $fieldAddress2 = 'address2';
/**
* @var string
*/
public static $fieldCity = 'city';
/**
* @var string
*/
public static $fieldState = 'state';
/**
* @var string
*/
public static $fieldPostalCode = 'postal_code';
/**
* @var string
*/
public static $fieldNotes = 'notes';
/**
* @var string
*/
public static $fieldCountry = 'country';
/**
* @var string
*/
public static $fieldWebsite = 'website';
/**
* @var string
*/
public static $fieldVatNumber = 'vat_number';
/**
* @var string
*/
public static $fieldIdNumber = 'id_number';
/** /**
* @return array * @return array
@ -109,22 +62,28 @@ class Client extends EntityModel
public static function getImportColumns() public static function getImportColumns()
{ {
return [ return [
self::$fieldName, 'name',
self::$fieldPhone, 'work_phone',
self::$fieldAddress1, 'address1',
self::$fieldAddress2, 'address2',
self::$fieldCity, 'city',
self::$fieldState, 'state',
self::$fieldPostalCode, 'postal_code',
self::$fieldCountry, 'public_notes',
self::$fieldNotes, 'private_notes',
self::$fieldWebsite, 'country',
self::$fieldVatNumber, 'website',
self::$fieldIdNumber, 'currency',
Contact::$fieldFirstName, 'vat_number',
Contact::$fieldLastName, 'id_number',
Contact::$fieldPhone, 'custom1',
Contact::$fieldEmail, 'custom2',
'contact_first_name',
'contact_last_name',
'contact_phone',
'contact_email',
'contact_custom1',
'contact_custom2',
]; ];
} }
@ -134,10 +93,11 @@ class Client extends EntityModel
public static function getImportMap() public static function getImportMap()
{ {
return [ return [
'first' => 'first_name', 'first' => 'contact_first_name',
'last' => 'last_name', 'last' => 'contact_last_name',
'email' => 'email', 'email' => 'contact_email',
'mobile|phone' => 'phone', 'work|office' => 'work_phone',
'mobile|phone' => 'contact_phone',
'name|organization' => 'name', 'name|organization' => 'name',
'apt|street2|address2' => 'address2', 'apt|street2|address2' => 'address2',
'street|address|address1' => 'address1', 'street|address|address1' => 'address1',
@ -145,8 +105,10 @@ class Client extends EntityModel
'state|province' => 'state', 'state|province' => 'state',
'zip|postal|code' => 'postal_code', 'zip|postal|code' => 'postal_code',
'country' => 'country', 'country' => 'country',
'note' => 'notes', 'public' => 'public_notes',
'private|note' => 'private_notes',
'site|website' => 'website', 'site|website' => 'website',
'currency' => 'currency',
'vat' => 'vat_number', 'vat' => 'vat_number',
'number' => 'id_number', 'number' => 'id_number',
]; ];

View File

@ -26,22 +26,29 @@ class ClientTransformer extends BaseTransformer
'name' => $this->getString($data, 'name'), 'name' => $this->getString($data, 'name'),
'work_phone' => $this->getString($data, 'work_phone'), 'work_phone' => $this->getString($data, 'work_phone'),
'address1' => $this->getString($data, 'address1'), 'address1' => $this->getString($data, 'address1'),
'address2' => $this->getString($data, 'address2'),
'city' => $this->getString($data, 'city'), 'city' => $this->getString($data, 'city'),
'state' => $this->getString($data, 'state'), 'state' => $this->getString($data, 'state'),
'postal_code' => $this->getString($data, 'postal_code'), 'postal_code' => $this->getString($data, 'postal_code'),
'private_notes' => $this->getString($data, 'notes'), 'public_notes' => $this->getString($data, 'public_notes'),
'private_notes' => $this->getString($data, 'private_notes'),
'website' => $this->getString($data, 'website'), 'website' => $this->getString($data, 'website'),
'vat_number' => $this->getString($data, 'vat_number'), 'vat_number' => $this->getString($data, 'vat_number'),
'id_number' => $this->getString($data, 'id_number'), 'id_number' => $this->getString($data, 'id_number'),
'custom_value1' => $this->getString($data, 'custom1'),
'custom_value2' => $this->getString($data, 'custom2'),
'contacts' => [ 'contacts' => [
[ [
'first_name' => $this->getString($data, 'first_name'), 'first_name' => $this->getString($data, 'contact_first_name'),
'last_name' => $this->getString($data, 'last_name'), 'last_name' => $this->getString($data, 'contact_last_name'),
'email' => $this->getString($data, 'email'), 'email' => $this->getString($data, 'contact_email'),
'phone' => $this->getString($data, 'phone'), 'phone' => $this->getString($data, 'contact_phone'),
'custom_value1' => $this->getString($data, 'contact_custom1'),
'custom_value2' => $this->getString($data, 'contact_custom2'),
], ],
], ],
'country_id' => isset($data->country) ? $this->getCountryId($data->country) : null, 'country_id' => isset($data->country) ? $this->getCountryId($data->country) : null,
'currency_code' => $this->getString($data, 'currency'),
]; ];
}); });
} }

View File

@ -2392,7 +2392,14 @@ $LANG = array(
'tax1' => 'First Tax', 'tax1' => 'First Tax',
'tax2' => 'Second Tax', 'tax2' => 'Second Tax',
'fee_help' => 'Gateway fees are the costs charged for access to the financial networks that handle the processing of online payments.', 'fee_help' => 'Gateway fees are the costs charged for access to the financial networks that handle the processing of online payments.',
'format_export' => 'Exporting format' 'format_export' => 'Exporting format',
'custom1' => 'First Custom',
'custom2' => 'Second Custom',
'contact_first_name' => 'Contact First Name',
'contact_last_name' => 'Contact Last Name',
'contact_custom1' => 'Contact First Custom',
'contact_custom2' => 'Contact Second Custom',
'currency' => 'Currency',
); );

View File

@ -14,7 +14,8 @@
<td>{{ trans('texts.id_number') }}</td> <td>{{ trans('texts.id_number') }}</td>
<td>{{ trans('texts.vat_number') }}</td> <td>{{ trans('texts.vat_number') }}</td>
<td>{{ trans('texts.website') }}</td> <td>{{ trans('texts.website') }}</td>
<td>{{ trans('texts.phone') }}</td> <td>{{ trans('texts.work_phone') }}</td>
<td>{{ trans('texts.currency') }}</td>
<td>{{ trans('texts.public_notes') }}</td> <td>{{ trans('texts.public_notes') }}</td>
<td>{{ trans('texts.private_notes') }}</td> <td>{{ trans('texts.private_notes') }}</td>
@if ($account->custom_client_label1) @if ($account->custom_client_label1)
@ -23,6 +24,16 @@
@if ($account->custom_client_label2) @if ($account->custom_client_label2)
<td>{{ $account->custom_client_label2 }}</td> <td>{{ $account->custom_client_label2 }}</td>
@endif @endif
<td>{{ trans('texts.first_name') }}</td>
<td>{{ trans('texts.last_name') }}</td>
<td>{{ trans('texts.email') }}</td>
<td>{{ trans('texts.phone') }}</td>
@if ($account->custom_contact_label1)
<td>{{ $account->custom_contact_label1 }}</td>
@endif
@if ($account->custom_contact_label2)
<td>{{ $account->custom_contact_label2 }}</td>
@endif
</tr> </tr>
@foreach ($clients as $client) @foreach ($clients as $client)
@ -43,6 +54,7 @@
<td>{{ $client->vat_number }}</td> <td>{{ $client->vat_number }}</td>
<td>{{ $client->website }}</td> <td>{{ $client->website }}</td>
<td>{{ $client->work_phone }}</td> <td>{{ $client->work_phone }}</td>
<td>{{ $client->currency ? $client->currency->code : '' }}</td>
<td>{{ $client->public_notes }}</td> <td>{{ $client->public_notes }}</td>
<td>{{ $client->private_notes }}</td> <td>{{ $client->private_notes }}</td>
@if ($account->custom_client_label1) @if ($account->custom_client_label1)
@ -51,5 +63,15 @@
@if ($account->custom_client_label2) @if ($account->custom_client_label2)
<td>{{ $client->custom_value2 }}</td> <td>{{ $client->custom_value2 }}</td>
@endif @endif
<td>{{ $client->contacts[0]->first_name }}</td>
<td>{{ $client->contacts[0]->last_name }}</td>
<td>{{ $client->contacts[0]->email }}</td>
<td>{{ $client->contacts[0]->phone }}</td>
@if ($account->custom_contact_label1)
<td>{{ $client->contacts[0]->custom_value1 }}</td>
@endif
@if ($account->custom_contact_label2)
<td>{{ $client->contacts[0]->custom_value2 }}</td>
@endif
</tr> </tr>
@endforeach @endforeach