From f60e507029171d1caca1cf0261ae018fed5fff2a Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 17 Mar 2026 21:23:29 -0400 Subject: [PATCH] Updated settings page --- app/controllers/employee_controller.rb | 26 ++++ app/controllers/estimate_controller.rb | 5 + app/views/qbo/_settings.html.erb | 160 ++++++++++--------------- config/locales/en.yml | 4 + config/routes.rb | 2 + 5 files changed, 101 insertions(+), 96 deletions(-) create mode 100644 app/controllers/employee_controller.rb diff --git a/app/controllers/employee_controller.rb b/app/controllers/employee_controller.rb new file mode 100644 index 0000000..5b273c0 --- /dev/null +++ b/app/controllers/employee_controller.rb @@ -0,0 +1,26 @@ +#The MIT License (MIT) +# +#Copyright (c) 2016 - 2026 rick barrette +# +#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +class EmployeeController < ApplicationController + include AuthHelper + + before_action :require_user, unless: -> { session[:token].nil? } + + def sync + Employee.sync + redirect_to :home, flash: { notice: I18n.t(:label_syncing) } + end + + private + + # Logs messages with a consistent prefix for easier debugging. + def log(msg) + Rails.logger.info "[EmployeeController] #{msg}" + end +end \ No newline at end of file diff --git a/app/controllers/estimate_controller.rb b/app/controllers/estimate_controller.rb index 19685fb..b5d055c 100644 --- a/app/controllers/estimate_controller.rb +++ b/app/controllers/estimate_controller.rb @@ -24,6 +24,11 @@ class EstimateController < ApplicationController render_pdf(@estimate) end + def sync + Estimate.sync + redirect_to :home, flash: { notice: I18n.t(:label_syncing) } + end + private # Loads the estimate based on ID or doc number, with a fallback to sync if not found locally. diff --git a/app/views/qbo/_settings.html.erb b/app/views/qbo/_settings.html.erb index 9bcd5f7..cb15355 100644 --- a/app/views/qbo/_settings.html.erb +++ b/app/views/qbo/_settings.html.erb @@ -1,111 +1,79 @@ - - - - - - - +
+

+ + <%= text_field_tag 'settings[settingsOAuthConsumerKey]', settings['settingsOAuthConsumerKey'], size: 50 %> +

+ +

+ + <%= password_field_tag 'settings[settingsOAuthConsumerSecret]', settings['settingsOAuthConsumerSecret'], size: 50 %> +

-
- - - +

+ + <%= text_field_tag 'settings[settingsWebhookToken]', settings['settingsWebhookToken'], size: 50 %> +

- - - - - - - - - +

+ + <%= check_box_tag 'settings[sandbox]', 1, settings[:sandbox] %> +

- - - - +
- - - - - - - +

+ + + <%= Qbo.oauth2_access_token_expires_at || 'N/A' %> + +

- -
<%=t(:label_client_id)%> - -
<%=t(:label_client_secret)%> - -
<%=t(:label_webhook_token)%> - -
<%=t(:label_sandbox)%> - <%= check_box_tag 'settings[sandbox]', @settings[:sandbox], @settings[:sandbox] %> -
<%=t(:label_oauth_expires)%><%= Qbo.oauth2_access_token_expires_at %> -
<%=t(:label_oauth2_refresh_token_expires_at)%><%= Qbo.oauth2_refresh_token_expires_at %> -
+

+ + <%= Customer.count %> + (@ <%= Customer.last_sync %>) +

-
-<%=t(:label_oauth_note)%> -
-
+

+ + <%= Employee.count %> + (@ <%= Employee.last_sync %>) +

- - +

+ + <%= Invoice.count %> + (@ <%= Item.last_sync %>) +

-
-
+

+ + <%= Estimate.count %> + (@ <%= Account.last_sync %>) +

-
- <%=t(:label_customer_count)%>: <%= Customer.count%> @ <%= Customer.last_sync %> -
- -
- <%=t(:label_employee_count)%>: <%= Employee.count %> @ <%= Employee.last_sync %> -
- -
- <%=t(:label_invoice_count)%>: <%= Invoice.count %> @ <%= Invoice.last_sync%> -
- -
- <%=t(:label_estimate_count)%>: <%= Estimate.count %> @ <%= Estimate.last_sync %> -
- -
- -
- <%=t(:label_last_sync)%> <%= Qbo.last_sync if Qbo.exists? %> <%= link_to t(:label_sync_now), qbo_sync_path(full_sync: true) %> +

+ + <%= Qbo.exists? ? Qbo.last_sync : 'Never synced' %> +

+ +
+ Management & Synchronization + +
+ +
+ +
+ <%= link_to t(:label_sync_now_customers), customers_sync_path(full_sync: true), class: 'button icon icon-reload' %> + <%= link_to t(:label_sync_now_employees), employees_sync_path, class: 'button icon icon-reload' %> + <%= link_to t(:label_sync_now_invoices), invoices_sync_path(full_sync: true), class: 'button icon icon-reload' %> + <%= link_to t(:label_sync_now_estimate), estimates_sync_path, class: 'button icon icon-reload' %> +
+
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 9b372c9..c43a458 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -82,6 +82,10 @@ en: label_shipping_address: "Shipping Address" label_sync: "Sync" label_sync_now: "Sync Now" + label_sync_now_customers: "Sync Customers" + label_sync_now_employees: "Sync Employees" + label_sync_now_invoices: "Sync Invoices" + label_sync_now_estimate: "Sync Estimates" label_syncing: "Syncing QuickBooks" label_trim: "Trim" label_webhook_token: "Intuit QBO Webhook Token" diff --git a/config/routes.rb b/config/routes.rb index d8016eb..390d9d9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,8 @@ get 'qbo/oauth_callback', to: 'qbo#oauth_callback' #manual sync get 'qbo/sync', to: 'qbo#sync' +get 'customers/sync', to: 'customers#sync' +get 'employees/sync', to: 'employee#sync' get 'invoices/sync', to: 'invoice#sync' get 'estimates/sync', to: 'estimate#sync'