diff --git a/app/models/customer.rb b/app/models/customer.rb index 6259cf7..b633783 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -11,8 +11,9 @@ class Customer < ActiveRecord::Base include Redmine::Acts::Searchable - include Redmine::Acts::Event - + include Redmine::Acts::Event + include Redmine::I18n + has_many :issues has_many :invoices has_many :estimates @@ -49,6 +50,12 @@ class Customer < ActiveRecord::Base @details.email_address = s end + # Returns the last sync time formatted for display. If no sync has occurred, returns a default message. + def self.last_sync + return I18n.t(:label_qbo_never_synced) unless maximum(:updated_at) + format_time(maximum(:updated_at)) + end + # Convenience Method # returns the customer's primary phone def primary_phone diff --git a/app/models/employee.rb b/app/models/employee.rb index 9c5358b..92c837b 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -10,11 +10,19 @@ class Employee < ActiveRecord::Base + include Redmine::I18n + has_many :users validates_presence_of :id, :name self.primary_key = :id + # Returns the last sync time formatted for display. If no sync has occurred, returns a default message. + def self.last_sync + return I18n.t(:label_qbo_never_synced) unless maximum(:updated_at) + format_time(maximum(:updated_at)) + end + # Sync all employees, typically triggered by a scheduled task or manual sync request def self.sync EmployeeSyncJob.perform_later(full_sync: true) diff --git a/app/models/estimate.rb b/app/models/estimate.rb index 1abb31c..745beb2 100644 --- a/app/models/estimate.rb +++ b/app/models/estimate.rb @@ -10,11 +10,19 @@ class Estimate < ActiveRecord::Base + include Redmine::I18n + has_and_belongs_to_many :issues belongs_to :customer validates_presence_of :doc_number, :id self.primary_key = :id + # Returns the last sync time formatted for display. If no sync has occurred, returns a default message. + def self.last_sync + return I18n.t(:label_qbo_never_synced) unless maximum(:updated_at) + format_time(maximum(:updated_at)) + end + # returns a human readable string def to_s return self[:doc_number] diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 3eeb638..c1e9eea 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -9,6 +9,9 @@ #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 Invoice < ActiveRecord::Base + + include Redmine::I18n + has_and_belongs_to_many :issues belongs_to :customer @@ -17,6 +20,12 @@ class Invoice < ActiveRecord::Base self.primary_key = :id + # Returns the last sync time formatted for display. If no sync has occurred, returns a default message. + def self.last_sync + return I18n.t(:label_qbo_never_synced) unless maximum(:updated_at) + format_time(maximum(:updated_at)) + end + # Return the invoice's document number as its string representation def to_s doc_number diff --git a/app/views/qbo/_settings.html.erb b/app/views/qbo/_settings.html.erb index ad98c83..932d9f5 100644 --- a/app/views/qbo/_settings.html.erb +++ b/app/views/qbo/_settings.html.erb @@ -89,19 +89,19 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
- <%=t(:label_customer_count)%>: <%= Customer.count%> + <%=t(:label_customer_count)%>: <%= Customer.count%> @ <%= Customer.last_sync %>
- <%=t(:label_employee_count)%>: <%= Employee.count %> + <%=t(:label_employee_count)%>: <%= Employee.count %> @ <%= Employee.last_sync %>
- <%=t(:label_invoice_count)%>: <%= Invoice.count %> + <%=t(:label_invoice_count)%>: <%= Invoice.count %> @ <%= Invoice.last_sync%>
- <%=t(:label_estimate_count)%>: <%= Estimate.count %> + <%=t(:label_estimate_count)%>: <%= Estimate.count %> @ <%= Estimate.last_sync %>