Compare commits

...

21 Commits

Author SHA1 Message Date
139f5dd618 render partial on footer 2026-02-13 22:39:54 -05:00
9c11704d03 Added label_create_estimate 2026-02-13 20:45:59 -05:00
2ae53adf08 added needed trailing space 2026-02-13 20:37:42 -05:00
877c1b78a5 removed old comment 2026-02-13 18:38:42 -05:00
1d47703206 fixed indentiation 2026-02-13 18:37:12 -05:00
a069556ed9 Alphabetized: All keys are now in A-Z order for easier maintenance.
Branding: Changed "Quickbooks" to QuickBooks (capitalized B) to match official branding.

Grammar:

warn_ru_sure: Changed "You sure?" to "Are you sure?"

label_no_customers: Refined to "There are no customers matching the search term(s)."

label_billing_error: Added punctuation and clarified the phrasing.

Cleanup: Removed unnecessary spaces inside quotes (e.g., " Make" and "Matching ").
2026-02-13 18:33:48 -05:00
359c582e22 Fixed partial billing and added flash messages 2026-02-13 18:25:07 -05:00
e63b9e4217 use safe_join 2026-02-13 07:32:20 -05:00
6fd355d8cc 2026.2.7 2026-02-12 19:00:55 -05:00
e6b57392d1 Merge branch '422' 2026-02-12 18:59:32 -05:00
331c1eabeb seems to work without overiding the main issues _form 2026-02-11 19:59:41 -05:00
167385bb99 override issues form to add passing @project to issues hook 2026-02-11 19:31:01 -05:00
11b9876d4f Removed unused controller_issues_new_before_save that was used for finding the 422 error 2026-02-11 08:09:00 -05:00
9cf72821b0 2026.2.6 2026-02-11 08:05:28 -05:00
57adcce431 Refactor JavaScript path handling for issue form updates to help prevent 422 errors on new issue creation 2026-02-11 07:59:18 -05:00
7fdb15f7e8 more logging 2026-02-10 22:09:16 -05:00
6e11e05a24 2026.2.5 2026-02-09 21:54:01 -05:00
a6751d3f41 simplified appointment link javascript 2026-02-09 21:43:29 -05:00
8944e92ffc Use html data attributes 2026-02-09 20:52:27 -05:00
f0c0a42c96 2026.2.4 2026-02-09 20:04:47 -05:00
a4b51457bb moved controller_issues_new_before_save nito issues_hook_listener 2026-02-09 20:04:16 -05:00
11 changed files with 126 additions and 147 deletions

View File

@@ -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
redirect_to i, flash: { notice: I18n.t(:label_billed_success) + i.customer.name }
if i.bill_time
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

View File

@@ -2,7 +2,7 @@
<% estimates.sort.reverse.each do |estimate| %> <% estimates.sort.reverse.each do |estimate| %>
<div class="row"> <div class="row">
<%= check_box_tag "estimate_ids[]", estimate.id, false, onchange: "updateLink()", class: "estimate-checkbox" %> <%= check_box_tag "estimate_ids[]", estimate.id, false, onchange: "updateLink()", data: { url: estimate_path(estimate), text: "Estimate ##{estimate.to_s}" }, class: "estimate-checkbox appointment" %>
<b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %> <b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %>
</div> </div>
<% end %> <% end %>

View File

@@ -12,7 +12,7 @@
<% invoices.sort.reverse.each do |invoice| %> <% invoices.sort.reverse.each do |invoice| %>
<div class="row"> <div class="row">
<%= check_box_tag "invoice_ids[]", invoice.id, false, onchange: "updateLink()", class: "invoice-checkbox" if invoices.count > 1 %> <%= check_box_tag "invoice_ids[]", invoice.id, false, onchange: "updateLink()", data: { url: invoice_path(invoice), text: "Invoice ##{invoice.to_s}" }, class: "invoice-checkbox appointment" if invoices.count > 1 %>
<b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %> <b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %>
</div> </div>
<% end %> <% end %>

View File

@@ -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>

View File

@@ -1,31 +1,20 @@
function updateLink() { function updateLink() {
console.log("updateLink called");
const linkElement = document.getElementById("appointment_link"); const linkElement = document.getElementById("appointment_link");
const regex = /((?:<br\/>|%3Cbr\/?%3E))([\s\S]*?)(&dates)/gi; const regex = /((?:<br\/>|%3Cbr\/?%3E))([\s\S]*?)(&dates)/gi;
linkElement.href = linkElement.href.replace(regex, `$1${getSelectedDocs()}$3`); linkElement.href = linkElement.href.replace(regex, `$1${getSelectedDocs()}$3`);
} }
function getSelectedDocs() { function getSelectedDocs() {
const invoices = document.querySelectorAll('.invoice-checkbox'); const appointent_extras = document.querySelectorAll('.appointment');
const estimates = document.querySelectorAll('.estimate-checkbox');
const invoiceIds = Array.from(invoices)
.filter(checkbox => checkbox.checked)
.map(checkbox => checkbox.value);
const estimateIds = Array.from(estimates)
.filter(checkbox => checkbox.checked)
.map(checkbox => checkbox.value);
let output = ''; let output = '';
for (const item of appointent_extras) {
for (const value of invoiceIds) { if (item.checked) {
output += `%0A<a href="${window.location.origin}/invoices/${value}">Invoice:%20${value}</a>%0A`; console.log(`Checked item: ${item.dataset.text} with URL: ${item.dataset.url}`);
output += `%0A`+ encodeURIComponent(`<a href="${window.location.origin}${item.dataset.url}">${item.dataset.text}</a>`) +`%0A`;
}
} }
for (const value of estimateIds) {
output += `%0A<a href="${window.location.origin}/estimates/${value}">Estimate:%20${value}</a>%0A`;
}
// You can return the array or use it as needed
return output; return output;
} }

View File

@@ -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: "

View File

@@ -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.3' version '2026.2.7'
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'

View File

@@ -14,23 +14,15 @@ module RedmineQbo
include IssuesHelper include IssuesHelper
# Check the new issue form for a valid project.
# This is added to help prevent 422 unprocessable entity errors when creating an issue
# See https://github.com/redmine/redmine/blob/84483d63828d0cb2efbf5bd786a2f0d22e34c93d/app/controllers/issues_controller.rb#L179
def controller_issues_new_before_save(context={})
if context[:issue].project.nil?
context[:issue].project = projects_for_select(context[:issue]).first
context[:controller].flash[:error] = I18n.t(:notice_error_project_nil) + context[:issue].project.to_s
end
return context
end
# Edit Issue Form # Edit Issue Form
# Here we build the required form components before passing them to a partial view formatting. # Here we build the required form components before passing them to a partial view formatting.
def view_issues_form_details_bottom(context={}) def view_issues_form_details_bottom(context={})
Rails.logger.debug "RedmineQbo::Hooks::IssuesHookListener.view_issues_form_details_bottom: Building form components for quickbooks customer, estimate, and invoice data"
f = context[:form] f = context[:form]
issue = context[:issue] issue = context[:issue]
project = context[:project]
Rails.logger.debug issue.inspect
Rails.logger.debug project.inspect
# Customer Name Text Box with database backed autocomplete # Customer Name Text Box with database backed autocomplete
# onchange event will update the hidden customer_id field # onchange event will update the hidden customer_id field
@@ -42,11 +34,23 @@ module RedmineQbo
value: '#issue_customer' value: '#issue_customer'
} }
# We need to handle 3 cases for the onchange event of the customer name field:
# 1. New issue Withough project: /issues/new.js
# 2. New issue With project: /projects/rmt/issues/new.js
# 3. Existing issue: /issues/<ID>/edit.js
# The built in helper update_issue_form_path requires a project object to determine the correct path for new vs existing issues,
# but it doesn't work for issue.project when creating new issues not in a project i.e. http://redmine.domain.com/issues/new .
# So we need to figure out how to get a the @project from the controller calling the hook.
#
# If this is not handled correctly, it leads to a 422 error when creating a new issue and selecting a customer.
js_path = "updateIssueFrom('#{escape_javascript update_issue_form_path(project, issue)}', this)"
Rails.logger.debug js_path
# This hidden field is used for the customer ID for the issue # This hidden field is used for the customer ID for the issue
# the onchange event will reload the issue form via ajax to update the available estimates # the onchange event will reload the issue form via ajax to update the available estimates
customer_id = f.hidden_field :customer_id, customer_id = f.hidden_field :customer_id,
id: "issue_customer_id", id: "issue_customer_id",
onchange: "updateIssueFrom('#{escape_javascript update_issue_form_path(issue.project, issue)}', this)".html_safe onchange: js_path.html_safe
# Generate the drop down list of quickbooks estimates owned by the selected customer # Generate the drop down list of quickbooks estimates owned by the selected customer
select_estimate = f.select :estimate_id, select_estimate = f.select :estimate_id,

View File

@@ -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"

View File

@@ -44,10 +44,9 @@ 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 ##{id}"
return unless status.is_closed? return false if assigned_to.nil?
return if assigned_to.nil? return false unless Qbo.first
return unless Qbo.first return false unless customer
return unless customer
Thread.new do Thread.new do
spent_time = time_entries.where(billed: [false, nil]) spent_time = time_entries.where(billed: [false, nil])
@@ -102,6 +101,7 @@ module RedmineQbo
end end
end end
end end
return true
end end
end end

View File

@@ -14,27 +14,6 @@ module RedmineQbo
module IssuesControllerPatch module IssuesControllerPatch
module Helper module Helper
# Check the new issue form for a valid project.
# This is added to help prevent 422 unprocessable entity errors when creating an issue
# See https://github.com/redmine/redmine/blob/84483d63828d0cb2efbf5bd786a2f0d22e34c93d/app/controllers/issues_controller.rb#L179
def controller_issues_new_before_save(context={})
if context[:issue].project.nil?
context[:issue].project = projects_for_select(context[:issue]).first
Rails.logger.error I18n.t(:notice_error_project_nil) + context[:issue].project.to_s
context[:controller].flash[:error] = I18n.t(:notice_error_project_nil) + context[:issue].project.to_s
end
if context[:issue].tracker.nil?
context[:issue].tracker = trackers_for_select(context[:issue]).first
context[:issue].tracker = Tracker.first if context[:issue].tracker.nil?
Rails.logger.error I18n.t(:notice_error_tracker_nil) + context[:issue].tracker.to_s
context[:controller].flash[:error] = I18n.t(:notice_error_tracker_nil) + context[:issue].tracker.to_s
end
return context
end
def watcher_link(issue, user) def watcher_link(issue, user)
link = '' link = ''
link = link_to(I18n.t(:label_bill_time), bill_path( issue.id ), method: :get, class: 'icon icon-email-add') if user.admin? link = link_to(I18n.t(:label_bill_time), bill_path( issue.id ), method: :get, class: 'icon icon-email-add') if user.admin?