diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index 6fde46cd16..55002d9f9c 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -45,9 +45,11 @@ class ImportController extends BaseController return View::make('accounts.import_map', ['data' => $data]); } elseif ($source === IMPORT_JSON) { - $results = $this->importService->importJSON($files[IMPORT_JSON]); + $includeData = filter_var(Input::get('data'), FILTER_VALIDATE_BOOLEAN); + $includeSettings = filter_var(Input::get('settings'), FILTER_VALIDATE_BOOLEAN); + $results = $this->importService->importJSON($files[IMPORT_JSON], $includeData, $includeSettings); - return $this->showResult($results); + return $this->showResult($results, $includeSettings); } else { $results = $this->importService->importFiles($source, $files); @@ -78,11 +80,15 @@ class ImportController extends BaseController } } - private function showResult($results) + private function showResult($results, $includeSettings = false) { $message = ''; $skipped = []; + if ($includeSettings) { + $message = trans('texts.imported_settings') . '
'; + } + foreach ($results as $entityType => $entityResults) { if ($count = count($entityResults[RESULT_SUCCESS])) { $message .= trans("texts.created_{$entityType}s", ['count' => $count]) . '
'; diff --git a/app/Models/Account.php b/app/Models/Account.php index 17a040f672..9d7bc43e8c 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -48,50 +48,128 @@ class Account extends Eloquent * @var array */ protected $fillable = [ + 'timezone_id', + 'date_format_id', + 'datetime_format_id', + 'currency_id', 'name', - 'id_number', - 'vat_number', - 'work_email', - 'website', - 'work_phone', 'address1', 'address2', 'city', 'state', 'postal_code', 'country_id', - 'size_id', - 'industry_id', + 'invoice_terms', 'email_footer', - 'timezone_id', - 'date_format_id', - 'datetime_format_id', - 'currency_id', - 'language_id', - 'military_time', + 'industry_id', + 'size_id', 'invoice_taxes', 'invoice_item_taxes', + 'invoice_design_id', + 'work_phone', + 'work_email', + 'language_id', + 'custom_label1', + 'custom_value1', + 'custom_label2', + 'custom_value2', + 'custom_client_label1', + 'custom_client_label2', + 'fill_products', + 'update_products', + 'primary_color', + 'secondary_color', + 'hide_quantity', + 'hide_paid_to_date', + 'custom_invoice_label1', + 'custom_invoice_label2', + 'custom_invoice_taxes1', + 'custom_invoice_taxes2', + 'vat_number', + 'invoice_number_prefix', + 'invoice_number_counter', + 'quote_number_prefix', + 'quote_number_counter', + 'share_counter', + 'id_number', + 'email_template_invoice', + 'email_template_quote', + 'email_template_payment', + 'token_billing_type_id', + 'invoice_footer', + 'pdf_email_attachment', + 'font_size', + 'invoice_labels', + 'custom_design', 'show_item_taxes', + 'military_time', + 'email_subject_invoice', + 'email_subject_quote', + 'email_subject_payment', + 'email_subject_reminder1', + 'email_subject_reminder2', + 'email_subject_reminder3', + 'email_template_reminder1', + 'email_template_reminder2', + 'email_template_reminder3', + 'enable_reminder1', + 'enable_reminder2', + 'enable_reminder3', + 'num_days_reminder1', + 'num_days_reminder2', + 'num_days_reminder3', + 'custom_invoice_text_label1', + 'custom_invoice_text_label2', 'default_tax_rate_id', - 'enable_second_tax_rate', - 'include_item_taxes_inline', - 'start_of_week', - 'financial_year_start', - 'enable_client_portal', - 'enable_client_portal_dashboard', + 'recurring_hour', + 'invoice_number_pattern', + 'quote_number_pattern', + 'quote_terms', + 'email_design_id', + 'enable_email_markup', + 'website', + 'direction_reminder1', + 'direction_reminder2', + 'direction_reminder3', + 'field_reminder1', + 'field_reminder2', + 'field_reminder3', + 'header_font_id', + 'body_font_id', + 'auto_convert_quote', + 'all_pages_footer', + 'all_pages_header', + 'show_currency_code', 'enable_portal_password', 'send_portal_password', + 'custom_invoice_item_label1', + 'custom_invoice_item_label2', + 'recurring_invoice_number_prefix', + 'enable_client_portal', + 'invoice_fields', + 'invoice_embed_documents', + 'document_email_attachment', + 'enable_client_portal_dashboard', + 'page_size', + 'live_preview', + 'invoice_number_padding', + 'enable_second_tax_rate', + 'auto_bill_on_due_date', + 'start_of_week', 'enable_buy_now_buttons', + 'include_item_taxes_inline', + 'financial_year_start', + 'enabled_modules', + 'enabled_dashboard_sections', 'show_accept_invoice_terms', 'show_accept_quote_terms', 'require_invoice_signature', 'require_quote_signature', - 'pdf_email_attachment', - 'document_email_attachment', - 'email_design_id', - 'enable_email_markup', - 'domain_id', + 'client_number_prefix', + 'client_number_counter', + 'client_number_pattern', 'payment_terms', + 'reset_counter_frequency_id', 'payment_type_id', 'gateway_fee_location', ]; diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index 2dcecfe002..8691118b7b 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -136,6 +136,7 @@ class AccountTransformer extends EntityTransformer { return [ 'account_key' => $account->account_key, + 'logo' => $account->logo, 'name' => $account->present()->name, 'id_number' => $account->id_number, 'currency_id' => (int) $account->currency_id, @@ -172,7 +173,97 @@ class AccountTransformer extends EntityTransformer 'custom_label2' => $account->custom_label2, 'custom_value1' => $account->custom_value1, 'custom_value2' => $account->custom_value2, - 'logo' => $account->logo, + 'primary_color' => $account->primary_color, + 'secondary_color' => $account->secondary_color, + 'custom_client_label1' => $account->custom_client_label1, + 'custom_client_label2' => $account->custom_client_label2, + 'hide_quantity' => (bool) $account->hide_quantity, + 'hide_paid_to_date' => (bool) $account->hide_paid_to_date, + 'invoice_number_prefix' => $account->invoice_number_prefix, + 'invoice_number_counter' => $account->invoice_number_counter, + 'quote_number_prefix' => $account->quote_number_prefix, + 'quote_number_counter' => $account->quote_number_counter, + 'share_counter' => (bool) $account->share_counter, + 'email_template_invoice' => $account->email_template_invoice, + 'email_template_quote' => $account->email_template_quote, + 'email_template_payment' => $account->email_template_payment, + 'token_billing_type_id' => (int) $account->token_billing_type_id, + 'invoice_footer' => $account->invoice_footer, + 'pdf_email_attachment' => (bool) $account->pdf_email_attachment, + 'font_size' => $account->font_size, + 'invoice_labels' => $account->invoice_labels, + 'custom_design' => $account->custom_design, + 'show_item_taxes' => (bool) $account->show_item_taxes, + 'military_time' => (bool) $account->military_time, + 'email_subject_invoice' => $account->email_subject_invoice, + 'email_subject_quote' => $account->email_subject_quote, + 'email_subject_payment' => $account->email_subject_payment, + 'email_subject_reminder1' => $account->email_subject_reminder1, + 'email_subject_reminder2' => $account->email_subject_reminder2, + 'email_subject_reminder3' => $account->email_subject_reminder3, + 'email_template_reminder1' => $account->email_template_reminder1, + 'email_template_reminder2' => $account->email_template_reminder2, + 'email_template_reminder3' => $account->email_template_reminder3, + 'enable_reminder1' => $account->enable_reminder1, + 'enable_reminder2' => $account->enable_reminder2, + 'enable_reminder3' => $account->enable_reminder3, + 'num_days_reminder1' => $account->num_days_reminder1, + 'num_days_reminder2' => $account->num_days_reminder2, + 'num_days_reminder3' => $account->num_days_reminder3, + 'custom_invoice_text_label1' => $account->custom_invoice_text_label1, + 'custom_invoice_text_label2' => $account->custom_invoice_text_label2, + 'default_tax_rate_id' => $account->default_tax_rate_id, + 'recurring_hour' => $account->recurring_hour, + 'invoice_number_pattern' => $account->invoice_number_pattern, + 'quote_number_pattern' => $account->quote_number_pattern, + 'quote_terms' => $account->quote_terms, + 'email_design_id' => $account->email_design_id, + 'enable_email_markup' => (bool) $account->enable_email_markup, + 'website' => $account->website, + 'direction_reminder1' => (int) $account->direction_reminder1, + 'direction_reminder2' => (int) $account->direction_reminder2, + 'direction_reminder3' => (int) $account->direction_reminder3, + 'field_reminder1' => (int) $account->field_reminder1, + 'field_reminder2' => (int) $account->field_reminder2, + 'field_reminder3' => (int) $account->field_reminder3, + 'header_font_id' => (int) $account->header_font_id, + 'body_font_id' => (int) $account->body_font_id, + 'auto_convert_quote' => (bool) $account->auto_convert_quote, + 'all_pages_footer' => (bool) $account->all_pages_footer, + 'all_pages_header' => (bool) $account->all_pages_header, + 'show_currency_code' => (bool) $account->show_currency_code, + 'enable_portal_password' => (bool) $account->enable_portal_password, + 'send_portal_password' => (bool) $account->send_portal_password, + 'custom_invoice_item_label1' => $account->custom_invoice_item_label1, + 'custom_invoice_item_label2' => $account->custom_invoice_item_label2, + 'recurring_invoice_number_prefix' => $account->recurring_invoice_number_prefix, + 'enable_client_portal' => (bool) $account->enable_client_portal, + 'invoice_fields' => $account->invoice_fields, + 'invoice_embed_documents' => (bool) $account->invoice_embed_documents, + 'document_email_attachment' => (bool) $account->document_email_attachment, + 'enable_client_portal_dashboard' => (bool) $account->enable_client_portal_dashboard, + 'page_size' => $account->page_size, + 'live_preview' => (bool) $account->live_preview, + 'invoice_number_padding' => (int) $account->invoice_number_padding, + 'enable_second_tax_rate' => (bool) $account->enable_second_tax_rate, + 'auto_bill_on_due_date' => (bool) $account->auto_bill_on_due_date, + 'start_of_week' => $account->start_of_week, + 'enable_buy_now_buttons' => (bool) $account->enable_buy_now_buttons, + 'include_item_taxes_inline' => (bool) $account->include_item_taxes_inline, + 'financial_year_start' => $account->financial_year_start, + 'enabled_modules' => (int) $account->enabled_modules, + 'enabled_dashboard_sections' => (int) $account->enabled_dashboard_sections, + 'show_accept_invoice_terms' => (bool) $account->show_accept_invoice_terms, + 'show_accept_quote_terms' => (bool) $account->show_accept_quote_terms, + 'require_invoice_signature' => (bool) $account->require_invoice_signature, + 'require_quote_signature' => (bool) $account->require_quote_signature, + 'client_number_prefix' => $account->client_number_prefix, + 'client_number_counter' => (int) $account->client_number_counter, + 'client_number_pattern' => $account->client_number_pattern, + 'payment_terms' => (int) $account->payment_terms, + 'reset_counter_frequency_id' => (int) $account->reset_counter_frequency_id, + 'payment_type_id' => (int) $account->payment_type_id, + 'gateway_fee_location' => $account->gateway_fee_location, ]; } } diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 5d32feacf0..351b9597ca 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -145,7 +145,7 @@ class ImportService * * @return array */ - public function importJSON($file) + public function importJSON($file, $includeData, $includeSettings) { $this->initMaps(); @@ -156,52 +156,70 @@ class ImportService $this->checkClientCount(count($json['clients'])); - foreach ($json['products'] as $jsonProduct) { - if ($transformer->hasProduct($jsonProduct['product_key'])) { - continue; - } - if (EntityModel::validate($jsonProduct, ENTITY_PRODUCT) === true) { - $product = $this->productRepo->save($jsonProduct); - $this->addProductToMaps($product); - $this->addSuccess($product); - } else { - $this->addFailure(ENTITY_PRODUCT, $jsonProduct); - continue; + if ($includeSettings) { + // remove blank id values + $settings = []; + foreach ($json as $field => $value) { + if (strstr($field, '_id') && ! $value) { + // continue; + } else { + $settings[$field] = $value; + } } + //dd($settings); + $account = Auth::user()->account; + $account->fill($settings); + $account->save(); } - foreach ($json['clients'] as $jsonClient) { - if (EntityModel::validate($jsonClient, ENTITY_CLIENT) === true) { - $client = $this->clientRepo->save($jsonClient); - $this->addClientToMaps($client); - $this->addSuccess($client); - } else { - $this->addFailure(ENTITY_CLIENT, $jsonClient); - continue; + if ($includeData) { + foreach ($json['products'] as $jsonProduct) { + if ($transformer->hasProduct($jsonProduct['product_key'])) { + continue; + } + if (EntityModel::validate($jsonProduct, ENTITY_PRODUCT) === true) { + $product = $this->productRepo->save($jsonProduct); + $this->addProductToMaps($product); + $this->addSuccess($product); + } else { + $this->addFailure(ENTITY_PRODUCT, $jsonProduct); + continue; + } } - foreach ($jsonClient['invoices'] as $jsonInvoice) { - $jsonInvoice['client_id'] = $client->id; - if (EntityModel::validate($jsonInvoice, ENTITY_INVOICE) === true) { - $invoice = $this->invoiceRepo->save($jsonInvoice); - $this->addInvoiceToMaps($invoice); - $this->addSuccess($invoice); + foreach ($json['clients'] as $jsonClient) { + if (EntityModel::validate($jsonClient, ENTITY_CLIENT) === true) { + $client = $this->clientRepo->save($jsonClient); + $this->addClientToMaps($client); + $this->addSuccess($client); } else { - $this->addFailure(ENTITY_INVOICE, $jsonInvoice); + $this->addFailure(ENTITY_CLIENT, $jsonClient); continue; } - foreach ($jsonInvoice['payments'] as $jsonPayment) { - $jsonPayment['invoice_id'] = $invoice->public_id; - if (EntityModel::validate($jsonPayment, ENTITY_PAYMENT) === true) { - $jsonPayment['client_id'] = $client->id; - $jsonPayment['invoice_id'] = $invoice->id; - $payment = $this->paymentRepo->save($jsonPayment); - $this->addSuccess($payment); + foreach ($jsonClient['invoices'] as $jsonInvoice) { + $jsonInvoice['client_id'] = $client->id; + if (EntityModel::validate($jsonInvoice, ENTITY_INVOICE) === true) { + $invoice = $this->invoiceRepo->save($jsonInvoice); + $this->addInvoiceToMaps($invoice); + $this->addSuccess($invoice); } else { - $this->addFailure(ENTITY_PAYMENT, $jsonPayment); + $this->addFailure(ENTITY_INVOICE, $jsonInvoice); continue; } + + foreach ($jsonInvoice['payments'] as $jsonPayment) { + $jsonPayment['invoice_id'] = $invoice->public_id; + if (EntityModel::validate($jsonPayment, ENTITY_PAYMENT) === true) { + $jsonPayment['client_id'] = $client->id; + $jsonPayment['invoice_id'] = $invoice->id; + $payment = $this->paymentRepo->save($jsonPayment); + $this->addSuccess($payment); + } else { + $this->addFailure(ENTITY_PAYMENT, $jsonPayment); + continue; + } + } } } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index ca0be9d752..5b8deb37f3 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2427,7 +2427,8 @@ $LANG = array( 'logo_warning_invalid' => 'There was a problem reading the image file, please try a different format.', 'error_refresh_page' => 'An error occurred, please refresh the page and try again.', - + 'data' => 'Data', + 'imported_settings' => 'Successfully imported settings', ); return $LANG; diff --git a/resources/views/accounts/import_export.blade.php b/resources/views/accounts/import_export.blade.php index 26b4535766..3ad3cb257b 100644 --- a/resources/views/accounts/import_export.blade.php +++ b/resources/views/accounts/import_export.blade.php @@ -30,11 +30,26 @@ ->options(array_combine(\App\Services\ImportService::$sources, \App\Services\ImportService::$sources)) ->style('width: 200px') !!} +
@foreach (\App\Services\ImportService::$entityTypes as $entityType) {!! Former::file("{$entityType}_file") ->addGroupClass("import-file {$entityType}-file") !!} @endforeach + +
+ {!! Former::actions( Button::info(trans('texts.upload'))->submit()->large()->appendIcon(Icon::create('open'))) !!} {!! Former::close() !!} @@ -57,34 +72,36 @@ ->help('
' . trans('texts.export_help')) !!} - {!! Former::inline_radios('include_radio') - ->onchange('setCheckboxesEnabled()') - ->label(trans('texts.include')) - ->radios([ - trans('texts.all') . '   ' => ['value' => 'all', 'name' => 'include'], - trans('texts.selected') => ['value' => 'selected', 'name' => 'include'], - ])->check('all') !!} +
+ {!! Former::inline_radios('include_radio') + ->onchange('setCheckboxesEnabled()') + ->label(trans('texts.include')) + ->radios([ + trans('texts.all') . '   ' => ['value' => 'all', 'name' => 'include'], + trans('texts.selected') => ['value' => 'selected', 'name' => 'include'], + ])->check('all') !!} -
- -
- @include('partials/checkbox', ['field' => 'clients']) - @include('partials/checkbox', ['field' => 'contacts']) - @include('partials/checkbox', ['field' => 'credits']) - @include('partials/checkbox', ['field' => 'tasks']) -
-
- @include('partials/checkbox', ['field' => 'invoices']) - @include('partials/checkbox', ['field' => 'quotes']) - @include('partials/checkbox', ['field' => 'recurring']) - @include('partials/checkbox', ['field' => 'payments']) -
-
- @include('partials/checkbox', ['field' => 'products']) - @include('partials/checkbox', ['field' => 'expenses']) - @include('partials/checkbox', ['field' => 'vendors']) - @include('partials/checkbox', ['field' => 'vendor_contacts']) +
+ +
+ @include('partials/checkbox', ['field' => 'clients']) + @include('partials/checkbox', ['field' => 'contacts']) + @include('partials/checkbox', ['field' => 'credits']) + @include('partials/checkbox', ['field' => 'tasks']) +
+
+ @include('partials/checkbox', ['field' => 'invoices']) + @include('partials/checkbox', ['field' => 'quotes']) + @include('partials/checkbox', ['field' => 'recurring']) + @include('partials/checkbox', ['field' => 'payments']) +
+
+ @include('partials/checkbox', ['field' => 'products']) + @include('partials/checkbox', ['field' => 'expenses']) + @include('partials/checkbox', ['field' => 'vendors']) + @include('partials/checkbox', ['field' => 'vendor_contacts']) +

@@ -101,18 +118,28 @@ }); function setCheckboxesEnabled() { - var $checkboxes = $('input[type=checkbox]'); + var $checkboxes = $('.entity-types input[type=checkbox]'); var include = $('input[name=include]:checked').val() var format = $('#format').val(); - if (include === 'all' || format === 'JSON') { + if (include === 'all') { $checkboxes.attr('disabled', true); } else { $checkboxes.removeAttr('disabled'); } + if (format === 'JSON') { + $('#csvIncludes').hide(); + } else { + $('#csvIncludes').show(); + } } function setFileTypesVisible() { var val = $('#source').val(); + if (val === 'JSON') { + $('#jsonIncludes').show(); + } else { + $('#jsonIncludes').hide(); + } @foreach (\App\Services\ImportService::$entityTypes as $entityType) $('.{{ $entityType }}-file').hide(); @endforeach