Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b38f850df3 | |||
| 138e55933b | |||
| 5fbc169ade | |||
| d6737a6747 | |||
| 65db8f00a8 | |||
| 0197dc2a30 | |||
| cd1caa502d | |||
| 4b45d24a75 | |||
| 64a4526aa4 | |||
| 3514401808 | |||
| 3deafd8a6d | |||
| a54de28db5 | |||
| 6434eea906 | |||
| 9b656534ae | |||
| 659a1fbcf0 | |||
| 4dc1f5d0bd | |||
| 02f34582f4 | |||
| 2f9ef6304f | |||
| 886d5f4ace | |||
| 1ade938eb3 | |||
| 3111f391f3 | |||
| d2b9113914 | |||
| 447e048819 | |||
| e7dfc3f2ad | |||
| 139f5dd618 | |||
| 9c11704d03 | |||
| 2ae53adf08 | |||
| 877c1b78a5 | |||
| 1d47703206 | |||
| a069556ed9 | |||
| 359c582e22 | |||
| e63b9e4217 |
BIN
Screenshots/issue.png
Normal file
|
After Width: | Height: | Size: 724 KiB |
BIN
Screenshots/issue_form.png
Normal file
|
After Width: | Height: | Size: 520 KiB |
|
Before Width: | Height: | Size: 346 KiB After Width: | Height: | Size: 672 KiB |
|
Before Width: | Height: | Size: 303 KiB After Width: | Height: | Size: 538 KiB |
|
Before Width: | Height: | Size: 240 KiB |
|
Before Width: | Height: | Size: 512 KiB |
@@ -30,8 +30,6 @@ class CustomersController < ApplicationController
|
|||||||
before_action :view_customer, except: [:new, :view]
|
before_action :view_customer, except: [:new, :view]
|
||||||
skip_before_action :verify_authenticity_token, :check_if_login_required, only: [:view]
|
skip_before_action :verify_authenticity_token, :check_if_login_required, only: [:view]
|
||||||
|
|
||||||
default_search_scope :names
|
|
||||||
|
|
||||||
autocomplete :customer, :name, full: true, extra_data: [:id]
|
autocomplete :customer, :name, full: true, extra_data: [:id]
|
||||||
|
|
||||||
def allowed_params
|
def allowed_params
|
||||||
|
|||||||
@@ -15,18 +15,31 @@ class EstimateController < ApplicationController
|
|||||||
skip_before_action :verify_authenticity_token, :check_if_login_required, unless: proc {|c| session[:token].nil? }
|
skip_before_action :verify_authenticity_token, :check_if_login_required, unless: proc {|c| session[:token].nil? }
|
||||||
|
|
||||||
def get_estimate
|
def get_estimate
|
||||||
|
|
||||||
|
e = Estimate.find_by_doc_number(params[:search]) if params[:search]
|
||||||
|
e = Estimate.find_by_id(params[:id]) if params[:id]
|
||||||
|
|
||||||
# Force sync for estimate by doc number if not found
|
# Force sync for estimate by doc number if not found
|
||||||
if Estimate.find_by_doc_number(params[:search]).nil?
|
if e.nil? && params[:search]
|
||||||
begin
|
begin
|
||||||
Estimate.sync_by_doc_number(params[:search]) if params[:search]
|
Estimate.sync_by_doc_number(params[:search])
|
||||||
|
e = Estimate.find_by_doc_number(params[:search])
|
||||||
rescue
|
rescue
|
||||||
logger.info "Estimate.find_by_doc_number failed"
|
logger.info "Estimate.find_by_doc_number failed"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
estimate = Estimate.find_by_id(params[:id]) if params[:id]
|
# Force sync for estimate by id if not found
|
||||||
estimate = Estimate.find_by_doc_number(params[:search]) if params[:search]
|
if e.nil? && params[:id]
|
||||||
return estimate
|
begin
|
||||||
|
Estimate.sync_by_id(params[:id])
|
||||||
|
e = Estimate.find_by_id(params[:id])
|
||||||
|
rescue
|
||||||
|
logger.info "Estimate.find_by_id failed"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return e
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -64,11 +64,16 @@ class QboController < ApplicationController
|
|||||||
def bill
|
def bill
|
||||||
i = Issue.find_by_id params[:id]
|
i = Issue.find_by_id params[:id]
|
||||||
if i.customer
|
if i.customer
|
||||||
i.bill_time
|
billed = i.bill_time
|
||||||
|
|
||||||
|
if i.bill_time
|
||||||
redirect_to i, flash: { notice: I18n.t( :label_billed_success ) + i.customer.name }
|
redirect_to i, flash: { notice: I18n.t( :label_billed_success ) + i.customer.name }
|
||||||
else
|
else
|
||||||
redirect_to i, flash: { error: I18n.t(:label_billing_error) }
|
redirect_to i, flash: { error: I18n.t(:label_billing_error) }
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
redirect_to i, flash: { error: I18n.t(:label_billing_error_no_customer) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Quickbooks Webhook Callback
|
# Quickbooks Webhook Callback
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
class Customer < ActiveRecord::Base
|
class Customer < ActiveRecord::Base
|
||||||
|
|
||||||
|
include Redmine::Acts::Searchable
|
||||||
|
include Redmine::Acts::Event
|
||||||
|
|
||||||
has_many :issues
|
has_many :issues
|
||||||
has_many :invoices
|
has_many :invoices
|
||||||
has_many :estimates
|
has_many :estimates
|
||||||
@@ -18,10 +21,15 @@ class Customer < ActiveRecord::Base
|
|||||||
|
|
||||||
self.primary_key = :id
|
self.primary_key = :id
|
||||||
|
|
||||||
# returns a human readable string
|
acts_as_searchable columns: %w[name phone_number mobile_phone_number ],
|
||||||
def to_s
|
scope: ->(_context) { left_joins(:project) },
|
||||||
return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}"
|
date_column: :updated_at
|
||||||
end
|
|
||||||
|
acts_as_event :title => Proc.new {|o| "#{o}"},
|
||||||
|
:url => Proc.new {|o| { :controller => 'customers', :action => 'show', :id => o.id} },
|
||||||
|
:type => :to_s,
|
||||||
|
:description => Proc.new {|o| "#{I18n.t :label_primary_phone}: #{o.phone_number} #{I18n.t:label_mobile_phone}: #{o.mobile_phone_number}"},
|
||||||
|
:datetime => Proc.new {|o| o.updated_at || o.created_at}
|
||||||
|
|
||||||
# Convenience Method
|
# Convenience Method
|
||||||
# returns the customer's email
|
# returns the customer's email
|
||||||
@@ -63,6 +71,12 @@ class Customer < ActiveRecord::Base
|
|||||||
update_phone_number
|
update_phone_number
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Customers are not bound by a project
|
||||||
|
# but we need to implement this method for the Redmine::Acts::Searchable interface
|
||||||
|
def project
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
# Convenience Method
|
# Convenience Method
|
||||||
# returns the customer's mobile phone
|
# returns the customer's mobile phone
|
||||||
def mobile_phone
|
def mobile_phone
|
||||||
@@ -167,12 +181,29 @@ class Customer < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Searchs the database for a customer by name or phone number with out special chars
|
|
||||||
def self.search(search)
|
def self.search(search)
|
||||||
|
search = sanitize_sql_like(search)
|
||||||
customers = where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%")
|
customers = where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%")
|
||||||
return customers.order(:name)
|
return customers.order(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Override the defult redmine seach method to rank results by id
|
||||||
|
def self.search_result_ranks_and_ids(tokens, user, project = nil, options = {})
|
||||||
|
return {} if tokens.blank?
|
||||||
|
|
||||||
|
scope = self.all
|
||||||
|
|
||||||
|
tokens.each do |token|
|
||||||
|
q = "%#{sanitize_sql_like(token)}%"
|
||||||
|
scope = where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{q}%", "%#{q}%", "%#{q}%")
|
||||||
|
end
|
||||||
|
|
||||||
|
ids = scope.distinct.limit(options[:limit] || 100).pluck(:id)
|
||||||
|
|
||||||
|
# Assign simple uniform ranking
|
||||||
|
ids.each_with_object({}) { |id, h| h[id] = id }
|
||||||
|
end
|
||||||
|
|
||||||
# proforms a bruteforce sync operation
|
# proforms a bruteforce sync operation
|
||||||
# This needs to be simplified
|
# This needs to be simplified
|
||||||
def self.sync_by_id(id)
|
def self.sync_by_id(id)
|
||||||
@@ -200,19 +231,29 @@ class Customer < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns a human readable string
|
||||||
|
def to_s
|
||||||
|
return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}"
|
||||||
|
end
|
||||||
|
|
||||||
# Push the updates
|
# Push the updates
|
||||||
def save_with_push
|
def save_with_push
|
||||||
begin
|
begin
|
||||||
qbo = Qbo.first
|
qbo = Qbo.first
|
||||||
@details = qbo.perform_authenticated_request do |access_token|
|
@details = qbo.perform_authenticated_request do |access_token|
|
||||||
service = Quickbooks::Service::Customer.new(company_id: qbo.realm_id, access_token: access_token)
|
service = Quickbooks::Service::Customer.new(
|
||||||
|
company_id: qbo.realm_id,
|
||||||
|
access_token: access_token
|
||||||
|
)
|
||||||
service.update(@details)
|
service.update(@details)
|
||||||
end
|
end
|
||||||
#raise "QBO Fault" if @details.fault?
|
|
||||||
self.id = @details.id
|
self.id = @details.id
|
||||||
rescue Exception => e
|
rescue => e
|
||||||
errors.add(e.message)
|
errors.add(:base, e.message)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
save_without_push
|
save_without_push
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<%= form_tag(customers_path, method: "get", id: "search-form") do %>
|
<%= form_tag(customers_path, method: "get", id: "customer-search-form") do %>
|
||||||
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_customers), autocomplete: "off" %>
|
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_customers), autocomplete: "off" %>
|
||||||
<%= submit_tag t(:label_search) %>
|
<%= submit_tag t(:label_search) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<%= form_tag(estimate_doc_path, method: "get") do %>
|
<%= form_tag(estimate_doc_path, method: "get", id: "estimate-search-form") do %>
|
||||||
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_estimates), autocomplete: "off" %>
|
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_estimates), autocomplete: "off" %>
|
||||||
<%= submit_tag t(:label_search), formtarget: "_blank" %>
|
<%= submit_tag t(:label_search), formtarget: "_blank" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
"<div id='footer' align='center'>
|
<div id='footer' align='center'>
|
||||||
<b><%=I18n.translate(:label_last_sync)%>: </b> <%=Qbo.last_sync if Qbo.exists?%>
|
<%= render partial: 'qbo/last_sync' %>
|
||||||
</div>"
|
</div>
|
||||||
@@ -16,7 +16,5 @@ for (const item of appointent_extras) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// You can return the array or use it as needed
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,94 +11,95 @@
|
|||||||
# English strings go here for Rails i18n
|
# English strings go here for Rails i18n
|
||||||
# Usage I18n.t(:label)
|
# Usage I18n.t(:label)
|
||||||
en:
|
en:
|
||||||
field_customer: "Customer"
|
button_bulk_pdf: "Bulk PDF"
|
||||||
field_employee: "Employee"
|
customer_details: "Customer Details"
|
||||||
field_invoice: "Invoice"
|
|
||||||
field_estimate: "Estimate"
|
|
||||||
field_notes: "Notes"
|
|
||||||
field_billed: "Billed"
|
field_billed: "Billed"
|
||||||
label_week: "Week"
|
field_customer: "Customer"
|
||||||
label_search_estimates: "Search Estimates"
|
field_customers: "Customers"
|
||||||
label_search: "Search"
|
field_employee: "Employee"
|
||||||
label_estimates: "Estimates"
|
field_estimate: "Estimate"
|
||||||
warn_ru_sure: "You sure?"
|
field_invoice: "Invoice"
|
||||||
label_delete: "Delete"
|
field_notes: "Notes"
|
||||||
label_edit: "Edit"
|
|
||||||
label_year: "Year"
|
|
||||||
label_make: " Make"
|
|
||||||
label_model: "Model"
|
|
||||||
label_no_customers: "There are no customers containing the term(s)"
|
|
||||||
label_matching: "Matching "
|
|
||||||
label_open_issues: "Open Issues"
|
|
||||||
label_closed_issues: "Closed Issues"
|
|
||||||
label_sync: "Sync"
|
|
||||||
label_new_customer: "New Customer"
|
|
||||||
label_search_customers: "Search Customers"
|
|
||||||
label_customers: "Customers"
|
|
||||||
label_edit_customer: "Edit Customer"
|
|
||||||
label_email: "Email"
|
|
||||||
label_primary_phone: "Primary Phone"
|
|
||||||
label_mobile_phone: "Mobile Phone"
|
|
||||||
label_billing_address: "Billing Address"
|
|
||||||
label_shipping_address: "Shipping Address"
|
|
||||||
label_account_balance: "Account Balance"
|
label_account_balance: "Account Balance"
|
||||||
label_balance_with_jobs: "Balance With Jobs"
|
label_actions: "Actions"
|
||||||
label_display_name: "Display Name"
|
|
||||||
label_details: "Details"
|
|
||||||
label_customer_link_expires: "This customer link expires in"
|
|
||||||
label_amount: "Amount"
|
label_amount: "Amount"
|
||||||
label_deposit_into: "Deposit to Account"
|
label_appointment: "Add Appointment"
|
||||||
label_last_sync: "Last Sync"
|
label_balance_with_jobs: "Balance With Jobs"
|
||||||
label_redmine_qbo: "Redmine Quickbooks"
|
label_bill_time: "Bill Time"
|
||||||
label_customer_count: "Customer Count"
|
label_billing_address: "Billing Address"
|
||||||
label_invoice_count: "Invoice Count"
|
label_billing_error: "Customer could not be billed. Check for Customer or Assignee and try again."
|
||||||
label_estimate_count: "Estimate Count"
|
label_billing_error_no_customer: "Cannot bill without an assigned customer."
|
||||||
label_employee_count: "Employee Count"
|
label_billed_success: "Successfully billed "
|
||||||
label_client_id: "Intuit QBO OAuth2 Client ID"
|
label_client_id: "Intuit QBO OAuth2 Client ID"
|
||||||
label_client_secret: "Intuit QBO OAuth2 Client Secret"
|
label_client_secret: "Intuit QBO OAuth2 Client Secret"
|
||||||
label_webhook_token: "Intuit QBO Webhook Token"
|
label_closed_issues: "Closed Issues"
|
||||||
label_oauth_expires: "OAuth2 Access Token Expires At"
|
label_connected: "Successfully connected to QuickBooks"
|
||||||
label_oauth_note: "Note: You need to authenticate with Quickbooks after saving your key and secret above"
|
label_create_estimate: "Create Estimate"
|
||||||
field_customers: "Customers"
|
label_customer_count: "Customer Count"
|
||||||
|
label_customer_link_expires: "This customer link expires in"
|
||||||
|
label_customers: "Customers"
|
||||||
|
label_delete: "Delete"
|
||||||
|
label_deposit_into: "Deposit to Account"
|
||||||
|
label_details: "Details"
|
||||||
|
label_display_name: "Display Name"
|
||||||
|
label_door: "Door"
|
||||||
|
label_edit: "Edit"
|
||||||
|
label_edit_customer: "Edit Customer"
|
||||||
|
label_email: "Email"
|
||||||
|
label_employee_count: "Employee Count"
|
||||||
|
label_error: "Error"
|
||||||
|
label_estimate_404: "Estimate not found"
|
||||||
|
label_estimate_count: "Estimate Count"
|
||||||
|
label_estimates: "Estimates"
|
||||||
|
label_hours: "Hours"
|
||||||
|
label_invoice_404: "Invoice not found"
|
||||||
|
label_invoice_count: "Invoice Count"
|
||||||
|
label_invoices: "Invoices"
|
||||||
|
label_last_sync: "Last Sync"
|
||||||
|
label_load_customer: "Load Customer"
|
||||||
|
label_make: "Make"
|
||||||
|
label_matching: "Matching"
|
||||||
|
label_mobile_phone: "Mobile Phone"
|
||||||
|
label_model: "Model"
|
||||||
|
label_name: "Name"
|
||||||
|
label_new_customer: "New Customer"
|
||||||
|
label_no_customers: "There are no customers matching the search term(s)."
|
||||||
label_no_estimates: "No Estimates"
|
label_no_estimates: "No Estimates"
|
||||||
label_no_invoices: "No Invoices"
|
label_no_invoices: "No Invoices"
|
||||||
label_invoices: "Invoices"
|
|
||||||
label_load_customer: "Load Customer"
|
|
||||||
label_door: "Door"
|
|
||||||
label_trim: "Trim"
|
|
||||||
label_bill_time: "Bill Time"
|
|
||||||
label_share: "Share"
|
|
||||||
label_sync_now: "Sync Now"
|
|
||||||
label_invoice_404: "Invoice not found"
|
|
||||||
label_estimate_404: "Estimate not found"
|
|
||||||
label_connected: "Successfully connected to Quickbooks"
|
|
||||||
label_error: "Error"
|
|
||||||
label_billed_success: "Successfully Billed "
|
|
||||||
label_billing_error: "Cannot bill without a customer assigned"
|
|
||||||
label_qbo_sync_success: "Successfully synced to Quickbooks"
|
|
||||||
label_hours: "Hours"
|
|
||||||
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
|
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
|
||||||
label_name: "Name"
|
label_oauth_expires: "OAuth2 Access Token Expires At"
|
||||||
label_appointment: "Add Appointment"
|
label_oauth_note: "Note: You need to authenticate with QuickBooks after saving your key and secret above."
|
||||||
label_actions: "Actions"
|
label_open_issues: "Open Issues"
|
||||||
label_create_estimate: "Create Estimate"
|
label_primary_phone: "Primary Phone"
|
||||||
label_syncing: "Syncing Quickbooks"
|
label_qbo_sync_success: "Successfully synced to QuickBooks"
|
||||||
|
label_redmine_qbo: "Redmine QuickBooks"
|
||||||
label_sandbox: "Sandbox"
|
label_sandbox: "Sandbox"
|
||||||
button_bulk_pdf: "Bulk PDF"
|
label_search: "Search"
|
||||||
|
label_search_customers: "Search Customers"
|
||||||
|
label_search_estimates: "Search Estimates"
|
||||||
label_select_all: "Select All"
|
label_select_all: "Select All"
|
||||||
notice_customer_created: "Customer created in Quickbooks"
|
label_share: "Share"
|
||||||
notice_customer_updated: "Customer updated in Quickbooks"
|
label_shipping_address: "Shipping Address"
|
||||||
notice_customer_not_found: "Customer not found in Quickbooks"
|
label_sync: "Sync"
|
||||||
notice_customer_not_deleted: "Customer could not be deleted in Quickbooks"
|
label_sync_now: "Sync Now"
|
||||||
notice_customer_deleted: "Customer deleted in Quickbooks"
|
label_syncing: "Syncing QuickBooks"
|
||||||
notice_estimate_created: "Estimate created in Quickbooks"
|
label_trim: "Trim"
|
||||||
notice_estimate_updated: "Estimate updated in Quickbooks"
|
label_webhook_token: "Intuit QBO Webhook Token"
|
||||||
|
label_week: "Week"
|
||||||
|
label_year: "Year"
|
||||||
|
notice_customer_created: "Customer created in QuickBooks"
|
||||||
|
notice_customer_deleted: "Customer deleted in QuickBooks"
|
||||||
|
notice_customer_not_deleted: "Customer could not be deleted in QuickBooks"
|
||||||
|
notice_customer_not_found: "Customer not found in QuickBooks"
|
||||||
|
notice_customer_updated: "Customer updated in QuickBooks"
|
||||||
|
notice_error_project_nil: "The issue's project is nil. Set project to:"
|
||||||
|
notice_error_tracker_nil: "The issue's tracker is nil. Set tracker to:"
|
||||||
|
notice_estimate_created: "Estimate created in QuickBooks"
|
||||||
notice_estimate_not_found: "Estimate not found"
|
notice_estimate_not_found: "Estimate not found"
|
||||||
notice_invoice_created: "Invoice created in Quickbooks"
|
notice_estimate_updated: "Estimate updated in QuickBooks"
|
||||||
notice_invoice_updated: "Invoice updated in Quickbooks"
|
notice_forbidden: "You do not have permission to access this resource."
|
||||||
|
notice_invoice_created: "Invoice created in QuickBooks"
|
||||||
notice_invoice_not_found: "Invoice not found"
|
notice_invoice_not_found: "Invoice not found"
|
||||||
notice_forbidden: "You do not have permission to access this resource"
|
notice_invoice_updated: "Invoice updated in QuickBooks"
|
||||||
notice_issue_not_found: "Issue not found"
|
notice_issue_not_found: "Issue not found"
|
||||||
customer_details: "Customer Details"
|
warn_ru_sure: "Are you sure?"
|
||||||
notice_error_project_nil: "The issue's project is nil, set project to: "
|
|
||||||
notice_error_tracker_nil: "The issue's tracker is nil, set tracker to: "
|
|
||||||
15
db/migrate/038_add_customers_timestamp.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#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 AddCustomersTimestamp < ActiveRecord::Migration[5.1]
|
||||||
|
def change
|
||||||
|
add_timestamps(:customers, null: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
16
db/migrate/039_add_full_text_index_to_customers.rb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#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 AddFullTextIndexToCustomers < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
# This creates a combined index for name and phone fields
|
||||||
|
add_index :customers, [:name, :phone_number, :mobile_phone_number], type: :fulltext, name: 'ft_search_idx'
|
||||||
|
end
|
||||||
|
end
|
||||||
6
init.rb
@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo do
|
|||||||
name 'Redmine QBO plugin'
|
name 'Redmine QBO plugin'
|
||||||
author 'Rick Barrette'
|
author 'Rick Barrette'
|
||||||
description 'A pluging for Redmine to connect with QuickBooks Online to create Time Activity Entries for billable hours logged when an Issue is closed'
|
description 'A pluging for Redmine to connect with QuickBooks Online to create Time Activity Entries for billable hours logged when an Issue is closed'
|
||||||
version '2026.2.7'
|
version '2026.2.15'
|
||||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||||
author_url 'https://barrettefabrication.com'
|
author_url 'https://barrettefabrication.com'
|
||||||
settings default: {empty: true}, partial: 'qbo/settings'
|
settings default: {empty: true}, partial: 'qbo/settings'
|
||||||
@@ -37,6 +37,10 @@ Redmine::Plugin.register :redmine_qbo do
|
|||||||
# Register top menu items
|
# Register top menu items
|
||||||
menu :top_menu, :customers, { controller: :customers, action: :index }, caption: :label_customers, if: Proc.new {User.current.logged?}
|
menu :top_menu, :customers, { controller: :customers, action: :index }, caption: :label_customers, if: Proc.new {User.current.logged?}
|
||||||
|
|
||||||
|
Redmine::Search.map do |search|
|
||||||
|
search.register :customers
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Dynamically load all Hooks & Patches recursively
|
# Dynamically load all Hooks & Patches recursively
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ module RedmineQbo
|
|||||||
|
|
||||||
# Load the javascript to support the autocomplete forms
|
# Load the javascript to support the autocomplete forms
|
||||||
def view_layouts_base_html_head(context = {})
|
def view_layouts_base_html_head(context = {})
|
||||||
js = javascript_include_tag 'application.js', plugin: :redmine_qbo
|
safe_join([
|
||||||
js += javascript_include_tag 'autocomplete-rails.js', plugin: :redmine_qbo
|
javascript_include_tag( 'application.js', plugin: :redmine_qbo),
|
||||||
js += javascript_include_tag 'checkbox_controller.js', plugin: :redmine_qbo
|
javascript_include_tag( 'autocomplete-rails.js', plugin: :redmine_qbo),
|
||||||
return js
|
javascript_include_tag( 'checkbox_controller.js', plugin: :redmine_qbo)
|
||||||
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
render_on :view_layouts_base_sidebar, partial: "qbo/sidebar"
|
render_on :view_layouts_base_sidebar, partial: "qbo/sidebar"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ module RedmineQbo
|
|||||||
|
|
||||||
# Same as typing in the class
|
# Same as typing in the class
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
belongs_to :customer, primary_key: :id
|
belongs_to :customer, class_name: 'Customer', foreign_key: :customer_id, optional: true
|
||||||
belongs_to :customer_token, primary_key: :id
|
belongs_to :customer_token, primary_key: :id
|
||||||
belongs_to :estimate, primary_key: :id
|
belongs_to :estimate, primary_key: :id
|
||||||
has_and_belongs_to_many :invoices
|
has_and_belongs_to_many :invoices
|
||||||
@@ -43,16 +43,19 @@ module RedmineQbo
|
|||||||
|
|
||||||
# Create billable time entries
|
# Create billable time entries
|
||||||
def bill_time
|
def bill_time
|
||||||
logger.debug "QBO: Billing time for issue ##{id}"
|
logger.debug "QBO: Billing time for issue ##{self.id}"
|
||||||
return unless status.is_closed?
|
logger.debug "Issue is closed? #{self.closed?}"
|
||||||
return if assigned_to.nil?
|
|
||||||
return unless Qbo.first
|
return false if self.assigned_to.nil?
|
||||||
return unless customer
|
return false unless Qbo.first
|
||||||
|
return false unless self.customer
|
||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
spent_time = time_entries.where(billed: [false, nil])
|
spent_time = self.time_entries.where(billed: [false, nil])
|
||||||
spent_hours ||= spent_time.sum(:hours) || 0
|
spent_hours ||= spent_time.sum(:hours) || 0
|
||||||
|
|
||||||
|
logger.debug "Issue has spent hours: #{spent_hours}"
|
||||||
|
|
||||||
if spent_hours > 0 then
|
if spent_hours > 0 then
|
||||||
|
|
||||||
# Prepare to create a new Time Activity
|
# Prepare to create a new Time Activity
|
||||||
@@ -74,20 +77,23 @@ module RedmineQbo
|
|||||||
|
|
||||||
# Now letes upload our totals for each activity as their own billable time entry
|
# Now letes upload our totals for each activity as their own billable time entry
|
||||||
h.each do |key, val|
|
h.each do |key, val|
|
||||||
|
logger.debug "Processing activity '#{key}' with #{val.to_i} hours for issue ##{self.id}"
|
||||||
|
|
||||||
# Convert float spent time to hours and minutes
|
# Convert float spent time to hours and minutes
|
||||||
hours = val.to_i
|
hours = val.to_i
|
||||||
minutesDecimal = (( val - hours) * 60)
|
minutesDecimal = (( val - hours) * 60)
|
||||||
minutes = minutesDecimal.to_i
|
minutes = minutesDecimal.to_i
|
||||||
|
|
||||||
|
logger.debug "Converted #{val.to_i} hours to #{hours} hours and #{minutes} minutes"
|
||||||
|
|
||||||
# Lets match the activity to an qbo item
|
# Lets match the activity to an qbo item
|
||||||
item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first
|
item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first
|
||||||
next if item.nil?
|
next if item.nil?
|
||||||
|
|
||||||
# Create the new billable time entry and upload it
|
# Create the new billable time entry and upload it
|
||||||
time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}"
|
time_entry.description = "#{self.tracker} ##{self.id}: #{self.subject} #{"(Partial @ #{self.done_ratio}%)" unless self.closed?}"
|
||||||
time_entry.employee_id = assigned_to.employee_id
|
time_entry.employee_id = self.assigned_to.employee_id
|
||||||
time_entry.customer_id = customer_id
|
time_entry.customer_id = self.customer_id
|
||||||
time_entry.billable_status = "Billable"
|
time_entry.billable_status = "Billable"
|
||||||
time_entry.hours = hours
|
time_entry.hours = hours
|
||||||
time_entry.minutes = minutes
|
time_entry.minutes = minutes
|
||||||
@@ -102,6 +108,7 @@ module RedmineQbo
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,20 @@ module RedmineQbo
|
|||||||
module Patches
|
module Patches
|
||||||
module QueryPatch
|
module QueryPatch
|
||||||
|
|
||||||
|
def base_scope
|
||||||
|
scope = super
|
||||||
|
|
||||||
|
if filters['customer_name'].present?
|
||||||
|
scope = scope.left_outer_joins(:customer)
|
||||||
|
end
|
||||||
|
|
||||||
|
if has_column?(:customer) || filters['customer_name'].present?
|
||||||
|
scope = scope.includes(:customer)
|
||||||
|
end
|
||||||
|
|
||||||
|
scope
|
||||||
|
end
|
||||||
|
|
||||||
# Add qbo options to the aviable columns
|
# Add qbo options to the aviable columns
|
||||||
def available_columns
|
def available_columns
|
||||||
unless @available_columns
|
unless @available_columns
|
||||||
@@ -26,10 +40,27 @@ module RedmineQbo
|
|||||||
|
|
||||||
# Add customers to filters
|
# Add customers to filters
|
||||||
def initialize_available_filters
|
def initialize_available_filters
|
||||||
#add_available_filter "customer", type: :text
|
#add_available_filter "customer_id", type: :list, name: l(:field_customer), :values => lambda {Customer.pluck(:name, :id).map {|name, id| [name, id.to_s]}}
|
||||||
|
add_available_filter( 'customer_name', type: :text, name: l(:field_customer))
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sql_for_customer_name_field(field, operator, value)
|
||||||
|
pattern = "%#{value.first}%"
|
||||||
|
|
||||||
|
sql = case operator
|
||||||
|
when '~'
|
||||||
|
"#{Customer.table_name}.name LIKE ?"
|
||||||
|
when '!~'
|
||||||
|
"#{Customer.table_name}.name NOT LIKE ?"
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
Issue.joins(:customer).sanitize_sql_for_conditions([sql, pattern])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add module to Issue
|
# Add module to Issue
|
||||||
|
|||||||