mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-19 10:40:36 -05:00
Compare commits
5
Commits
2026.11.22
...
2026.11.23
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56859d1794 | ||
|
|
671afa2436 | ||
|
|
30c1f5181e | ||
|
|
0d143e6eb1 | ||
|
|
92f9eb1bc7 |
No files matched your search
@@ -75,10 +75,22 @@ The plugin provides basic Customer management:
|
||||
* Search Customers by **name or phone number**: the best matches come first (click a column to sort them instead), and a single match opens that Customer
|
||||
|
||||
* View and edit Customer information
|
||||
|
||||
* On the customer page, ticking an estimate (or a redmine_qbo_vehicles vehicle) adds it to the **New issue** link and to redmine_qbo_calendar's **Add appointment** link, one of each at a time
|
||||
|
||||
|
||||
Customers are synchronized with QuickBooks.
|
||||
|
||||
### Sharing an issue with the customer
|
||||
|
||||
**Share** on an issue (permission **Share issues with customers**) opens a link the customer can open without logging in: the issue with its history, attachments, estimate and invoices. A link lasts a month; sharing the issue again while it's valid gives the same link.
|
||||
|
||||
Expired links, and links whose issue was deleted, are deleted whenever a new link is made. To delete them now (or on a schedule):
|
||||
|
||||
```
|
||||
bundle exec rake redmine_qbo:purge_customer_tokens RAILS_ENV=production
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Webhook Support
|
||||
@@ -128,7 +140,7 @@ Estimates and invoices keep their number, date, customer, total, sales tax and *
|
||||
* Time lines are linked to their time activities, so QuickBooks marks the time as billed. Estimates the invoice was made from, or imported into it, are linked and closed when it's saved.
|
||||
* **Custom fields from the work orders**: the issues behind an invoice are the ones its time lines and lineitems estimates name. Plugins can fill custom fields from them when they're imported, and block a save (e.g. redmine_qbo_vehicles fills the VIN and mileage and allows one vehicle per invoice). On its own, redmine_qbo leaves the boxes as typed.
|
||||
* **Sales person**: an invoice credits the sales person on the estimate it was made from (the first linked estimate that names one); if none does, the user who writes the invoice.
|
||||
* Invoices show their status, worked out from the balance and due date like QuickBooks' invoice list: **Paid**, **Partially paid**, **Overdue**, **Open** or **Voided** (a zero total), on the customer page's invoice list and the invoice page. A paid invoice shows the day it was paid in full (e.g. **Paid 11/03/2026**): the later of its date and the last payment or credit memo applied to it.
|
||||
* Invoices show their status, worked out from the balance and due date like QuickBooks' invoice list: **Paid**, **Partially paid**, **Overdue**, **Open** or **Voided** (a zero total), on the customer page's invoice list and the invoice page. A paid invoice shows when it was paid in full (the later of its date and the last payment or credit memo applied to it): on the customer page's list, **Paid** when it was paid the day it was written, or **Paid +3d** when it was paid in full 3 days after its date, with the date when hovering over it; on the invoice page, the date (e.g. **Paid 11/03/2026**).
|
||||
* Invoices with a payment applied open read-only. The due date is left to QuickBooks (from the customer's terms) unless one is picked. The "default message shown on invoices" fills in the message.
|
||||
|
||||
### Payments
|
||||
@@ -208,6 +220,7 @@ Administration → Items lists the QuickBooks product/service list (synced from
|
||||
* **Write invoices**: create and edit invoices, and import time and estimates into them
|
||||
* **Email invoices**: email invoices to customers
|
||||
* **Issue refunds**: the Refund page, refunds and their PDFs
|
||||
* **Share issues with customers**: the Share link on issues (see Sharing an issue with the customer)
|
||||
|
||||
2. Settings (Administration -> Plugins -> Configure)
|
||||
* **Estimates expire after (days)**: new estimates get an expiration date this many days after the estimate date (e.g. 30). Leave blank for none.
|
||||
@@ -250,7 +263,7 @@ Hook|:qbo_billing_issues_created, { estimate:, issues:, params: } | Called after
|
||||
Hook|:qbo_billing_field_defaults, { customer:, issues: } | Return `{ field_id => value }` for a document's work orders: used when an invoice is made from an estimate, for the fields it leaves blank. New estimates and invoices start blank (redmine_qbo_vehicles: the work orders' VIN and highest mileage)
|
||||
Hook|:qbo_billing_field_options, { customer: } | Return `{ field_id => [{ value:, label: }, ...] }` to suggest in the editor's custom field boxes for a customer (redmine_qbo_vehicles: the customer's vehicles for the VIN box)
|
||||
View|:view_qbo_estimate_form_bottom, { form:, document: } | Add your plugin's script to the estimate/invoice editor. It can use `window.qboEditor` (`field(id)`, `fieldNamed(/name/)`, `setFieldOptions(id, options)`) and listen for `qbo:customer-changed` and `qbo:imported` on the form (redmine_qbo_vehicles fills the VIN and mileage)
|
||||
View|checkboxes with `data-new-issue-param="issue[field]"` on the customer page | Ticking one adds `issue[field]=value` to the New issue link, one per field (redmine_qbo's estimates, redmine_qbo_vehicles' vehicles)
|
||||
View|checkboxes with `data-new-issue-param="issue[field]"` and `data-appointment-param="field"` on the customer page | Ticking one adds `issue[field]=value` to the New issue link and `field=value` to redmine_qbo_calendar's Add appointment link (`#appointment_link`), one per field (redmine_qbo's estimates: `estimate_id`, redmine_qbo_vehicles' vehicles: `vehicle_id`)
|
||||
View Hook|:view_qbo_estimate_contextual, { estimate_id:, customer_id:, custom_fields:, doc_number: } | Adds links to an estimate page's action area (e.g. redmine_qbo_calendar's Add appointment); `custom_fields` is `{ field_id => value }`
|
||||
View Hook|:view_qbo_invoice_contextual, { invoice_id:, customer_id:, doc_number: } | Adds links to an invoice page's action area (e.g. redmine_qbo_labels' Print label)
|
||||
|
||||
|
||||
@@ -33,36 +33,6 @@ class CustomersController < ApplicationController
|
||||
before_action :require_admin, only: :sync
|
||||
skip_before_action :verify_authenticity_token, :check_if_login_required, only: [:view]
|
||||
|
||||
def address_to_s(address)
|
||||
return if address.nil?
|
||||
|
||||
lines = [
|
||||
address.line1,
|
||||
address.line2,
|
||||
address.line3,
|
||||
address.line4,
|
||||
address.line5
|
||||
].compact_blank
|
||||
|
||||
city_line = [
|
||||
address.city,
|
||||
address.country_sub_division_code,
|
||||
address.postal_code
|
||||
].compact_blank.join(" ")
|
||||
|
||||
lines << city_line unless city_line.blank?
|
||||
|
||||
lines.join("\n")
|
||||
end
|
||||
|
||||
def add_customer
|
||||
global_check_permission(:add_customers)
|
||||
end
|
||||
|
||||
def allowed_params
|
||||
params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number, :notes)
|
||||
end
|
||||
|
||||
# Used for autocomplete forms. Fuzzy matching (nicknames, typos, word order, phone digits) helps
|
||||
# staff spot an existing customer before creating a duplicate. See CustomerSearchService.
|
||||
def autocomplete
|
||||
@@ -109,14 +79,6 @@ class CustomersController < ApplicationController
|
||||
render_404
|
||||
end
|
||||
|
||||
def filter_estimates_by_customer
|
||||
@filtered_estimates = Estimate.all.where(customer_id: params[:selected_customer])
|
||||
end
|
||||
|
||||
def filter_invoices_by_customer
|
||||
@filtered_invoices = Invoice.all.where(customer_id: params[:selected_customer])
|
||||
end
|
||||
|
||||
# Most matches a search lists (best first)
|
||||
SEARCH_LIMIT = 200
|
||||
|
||||
@@ -146,29 +108,6 @@ class CustomersController < ApplicationController
|
||||
@issue_counts = Issue.where(customer_id: @customers.map(&:id)).group(:customer_id).count
|
||||
end
|
||||
|
||||
def load_issue_data
|
||||
@journals = @issue.journals.preload(:details).preload(user: :email_address).reorder(:created_on, :id).to_a
|
||||
|
||||
@journals.each_with_index { |j, i| j.indice = i + 1 }
|
||||
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
|
||||
Journal.preload_journals_details_custom_fields(@journals)
|
||||
@journals.select! { |journal| journal.notes? || journal.visible_details.any? }
|
||||
@journals.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
|
||||
@changesets = @issue.changesets.visible.preload(:repository, :user).to_a
|
||||
@changesets.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
|
||||
@relations = @issue.relations.select { |r| r.other_issue(@issue)&.visible? }
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
@priorities = IssuePriority.active
|
||||
@time_entry = TimeEntry.new(issue: @issue, project: @issue.project)
|
||||
@relation = IssueRelation.new
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[CustomersController] #{msg}"
|
||||
end
|
||||
|
||||
def new
|
||||
@customer = Customer.new
|
||||
|
||||
@@ -253,8 +192,41 @@ class CustomersController < ApplicationController
|
||||
render_403
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_customer
|
||||
global_check_permission(:add_customers)
|
||||
end
|
||||
|
||||
def allowed_params
|
||||
params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number, :notes)
|
||||
end
|
||||
|
||||
def load_issue_data
|
||||
@journals = @issue.journals.preload(:details).preload(user: :email_address).reorder(:created_on, :id).to_a
|
||||
|
||||
@journals.each_with_index { |j, i| j.indice = i + 1 }
|
||||
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
|
||||
Journal.preload_journals_details_custom_fields(@journals)
|
||||
@journals.select! { |journal| journal.notes? || journal.visible_details.any? }
|
||||
@journals.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
|
||||
@changesets = @issue.changesets.visible.preload(:repository, :user).to_a
|
||||
@changesets.reverse! if User.current.wants_comments_in_reverse_order?
|
||||
|
||||
@relations = @issue.relations.select { |r| r.other_issue(@issue)&.visible? }
|
||||
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||||
@priorities = IssuePriority.active
|
||||
@time_entry = TimeEntry.new(issue: @issue, project: @issue.project)
|
||||
@relation = IssueRelation.new
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[CustomersController] #{msg}"
|
||||
end
|
||||
|
||||
def view_customer
|
||||
global_check_permission(:view_customers)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -31,28 +31,6 @@ module AuthHelper
|
||||
require_login
|
||||
end
|
||||
|
||||
# Kept for plugins that still call it (e.g. redmine_qbo_vehicles): requires a logged-in user.
|
||||
# The old version effectively never ran; share-link customers use require_login_or_customer_token.
|
||||
def require_user
|
||||
return true if User.current.logged?
|
||||
|
||||
require_login
|
||||
end
|
||||
|
||||
def allowed_to?(action)
|
||||
return false if User.current.nil?
|
||||
project = Project.find_by(id: params[:project_id])
|
||||
return false if project.nil?
|
||||
User.current.allowed_to?(action, project)
|
||||
end
|
||||
|
||||
def check_permission(permission)
|
||||
if !allowed_to?(permission)
|
||||
flash[:error] = t :notice_forbidden
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def global_check_permission(permission)
|
||||
if !globaly_allowed_to?(permission)
|
||||
flash[:error] = t :notice_forbidden
|
||||
|
||||
@@ -21,17 +21,8 @@ class CustomerToken < ApplicationRecord
|
||||
|
||||
TOKEN_EXPIRATION = 1.month
|
||||
|
||||
# Check if the token has expired
|
||||
def expired?
|
||||
expires_at.present? && expires_at <= Time.current
|
||||
end
|
||||
|
||||
# Remove expired tokens from the database
|
||||
def self.remove_expired_tokens
|
||||
where("expires_at <= ?", Time.current).delete_all
|
||||
end
|
||||
|
||||
# Get or create a token for the given issue
|
||||
# Get or create a token for the given issue. Making a new one also clears out the share links that have expired
|
||||
# or whose issue was deleted, so they don't pile up.
|
||||
def self.get_token(issue)
|
||||
return unless issue
|
||||
return unless User.current.allowed_to?(:view_issues, issue.project)
|
||||
@@ -39,9 +30,17 @@ class CustomerToken < ApplicationRecord
|
||||
token = active.find_by(issue_id: issue.id)
|
||||
return token if token
|
||||
|
||||
purge_expired
|
||||
create!(issue: issue)
|
||||
end
|
||||
|
||||
# Deletes the share links that have expired or whose issue no longer exists; returns how many
|
||||
def self.purge_expired
|
||||
where('expires_at <= ?', Time.current)
|
||||
.or(where.not(issue_id: Issue.select(:id)))
|
||||
.delete_all
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Generate a unique token for the customer
|
||||
|
||||
@@ -79,12 +79,6 @@ class QboBaseModel < ActiveRecord::Base
|
||||
QboSyncJob.perform_later(entity: model_name.name, id: id)
|
||||
end
|
||||
|
||||
# Flag used to update local without pushing to QBO.
|
||||
# This is used to prevent loops with the webhook
|
||||
def skip_qbo_push?
|
||||
!!skip_qbo_push
|
||||
end
|
||||
|
||||
def self.qbo_sync(push: true)
|
||||
self.qbo_push_enabled = push
|
||||
end
|
||||
|
||||
@@ -31,14 +31,6 @@ class QboDraft < ApplicationRecord
|
||||
where(document: documents)
|
||||
}
|
||||
|
||||
def self.writable_document?(document, user = User.current)
|
||||
case document.to_s
|
||||
when 'estimate' then RedmineQboBilling.writer?(user)
|
||||
when 'invoice' then RedmineQboBilling.invoice_writer?(user)
|
||||
else false
|
||||
end
|
||||
end
|
||||
|
||||
# The editor's fields as posted (estimate[...])
|
||||
def fields
|
||||
parsed = JSON.parse(data.presence || '{}')
|
||||
|
||||
@@ -80,15 +80,6 @@ class SyncServiceBase
|
||||
false
|
||||
end
|
||||
|
||||
def extract_value(remote, remote_attr)
|
||||
case remote_attr
|
||||
when Proc
|
||||
remote_attr.call(remote)
|
||||
else
|
||||
remote.public_send(remote_attr)
|
||||
end
|
||||
end
|
||||
|
||||
# Attribute Mapping DSL
|
||||
#
|
||||
# This DSL defines how attributes from a QuickBooks Online (QBO) entity
|
||||
@@ -157,7 +148,6 @@ class SyncServiceBase
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def map_attribute(local_attr, remote_attr = nil, &block)
|
||||
attribute_map[local_attr] =
|
||||
if block_given?
|
||||
|
||||
@@ -1,45 +1,58 @@
|
||||
<%#
|
||||
Adds what's ticked on the customer page to the "New issue" link (#dynamic-new-issue-link in the contextual
|
||||
area). Any checkbox with data-new-issue-param="issue[field]" takes part, one ticked per field: this plugin's
|
||||
estimates (issue[estimate_id]), and other plugins' lists (e.g. redmine_qbo_vehicles' issue[vehicle_id]).
|
||||
Adds what's ticked on the customer page to its links: "New issue" (#dynamic-new-issue-link in the contextual area)
|
||||
and redmine_qbo_calendar's "Add appointment" (#appointment_link). A checkbox takes part with
|
||||
data-new-issue-param="issue[field]" (New issue) and data-appointment-param="field" (Add appointment); one is
|
||||
ticked per field: this plugin's estimates (estimate_id), and other plugins' lists (e.g. redmine_qbo_vehicles'
|
||||
vehicle_id).
|
||||
%>
|
||||
<script>
|
||||
function newIssueParamBoxes(param) {
|
||||
return Array.prototype.filter.call(document.querySelectorAll('input[data-new-issue-param]'), function (cb) {
|
||||
return !param || cb.getAttribute('data-new-issue-param') === param;
|
||||
});
|
||||
}
|
||||
(function () {
|
||||
var LINKS = [['dynamic-new-issue-link', 'data-new-issue-param'], ['appointment_link', 'data-appointment-param']];
|
||||
var ANY = 'input[data-new-issue-param], input[data-appointment-param]';
|
||||
|
||||
// One box per field: ticking one unticks the others for the same field
|
||||
document.addEventListener('change', function (event) {
|
||||
var box = event.target;
|
||||
if (!box.matches || !box.matches('input[data-new-issue-param]')) return;
|
||||
if (box.checked) {
|
||||
newIssueParamBoxes(box.getAttribute('data-new-issue-param')).forEach(function (cb) {
|
||||
if (cb !== box) cb.checked = false;
|
||||
function boxes(attr, param) {
|
||||
return Array.prototype.filter.call(document.querySelectorAll('input[' + attr + ']'), function (cb) {
|
||||
return !param || cb.getAttribute(attr) === param;
|
||||
});
|
||||
}
|
||||
updateLink();
|
||||
});
|
||||
|
||||
function updateLink() {
|
||||
var link = document.getElementById('dynamic-new-issue-link');
|
||||
if (!link) return;
|
||||
|
||||
// Cache the pristine base URL on first run
|
||||
if (!link.dataset.baseUrl) link.dataset.baseUrl = link.getAttribute('href');
|
||||
var url = new URL(link.dataset.baseUrl, window.location.origin);
|
||||
|
||||
newIssueParamBoxes().forEach(function (cb) {
|
||||
var param = cb.getAttribute('data-new-issue-param');
|
||||
var ticked = newIssueParamBoxes(param).filter(function (b) { return b.checked; })[0];
|
||||
if (ticked) {
|
||||
url.searchParams.set(param, ticked.value);
|
||||
} else {
|
||||
url.searchParams.delete(param);
|
||||
// Boxes for the same field (the same estimate list, the same vehicle list)
|
||||
function sameField(box) {
|
||||
for (var i = 0; i < LINKS.length; i++) {
|
||||
var attr = LINKS[i][1], param = box.getAttribute(attr);
|
||||
if (param) return boxes(attr, param);
|
||||
}
|
||||
});
|
||||
return [box];
|
||||
}
|
||||
|
||||
link.setAttribute('href', url.toString());
|
||||
}
|
||||
function updateLinks() {
|
||||
LINKS.forEach(function (pair) {
|
||||
var link = document.getElementById(pair[0]);
|
||||
if (!link) return;
|
||||
// Cache the pristine base URL on first run
|
||||
if (!link.dataset.baseUrl) link.dataset.baseUrl = link.getAttribute('href');
|
||||
var url = new URL(link.dataset.baseUrl, window.location.origin);
|
||||
boxes(pair[1]).forEach(function (cb) {
|
||||
var param = cb.getAttribute(pair[1]);
|
||||
var ticked = boxes(pair[1], param).filter(function (b) { return b.checked; })[0];
|
||||
if (ticked) {
|
||||
url.searchParams.set(param, ticked.value);
|
||||
} else {
|
||||
url.searchParams.delete(param);
|
||||
}
|
||||
});
|
||||
link.setAttribute('href', url.toString());
|
||||
});
|
||||
}
|
||||
|
||||
// One box per field: ticking one unticks the others for the same field
|
||||
document.addEventListener('change', function (event) {
|
||||
var box = event.target;
|
||||
if (!box.matches || !box.matches(ANY)) return;
|
||||
if (box.checked) {
|
||||
sameField(box).forEach(function (cb) { if (cb !== box) cb.checked = false; });
|
||||
}
|
||||
updateLinks();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
@@ -1 +0,0 @@
|
||||
$('select#issue_estimate_id').html('<%= j content_tag(:option,'',value:"")+options_from_collection_for_select(@filtered_estimates, :id, :doc_number) %>');
|
||||
@@ -52,7 +52,7 @@
|
||||
<div class="splitcontent">
|
||||
<div class="splitcontentleft">
|
||||
<h4><%=t(:estimates)%>:</h4>
|
||||
<%= render partial: 'estimates/list', locals: {estimates: @customer.estimates} %>
|
||||
<%= render partial: 'estimates/list', locals: {estimates: @customer.estimates, new_issue_checkboxes: true} %>
|
||||
</div>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
|
||||
@@ -3,14 +3,19 @@
|
||||
<%= render partial: 'qbo_estimates/status_styles' %>
|
||||
<div class="qbo-estimate-list">
|
||||
<% estimates.sort.reverse.each do |estimate| %>
|
||||
<%# One cell each (qbo_estimates/_status_styles lines them up in columns, so the icons line up) %>
|
||||
<div class="row">
|
||||
<%= check_box_tag "estimate_ids[]", estimate.id, false, onchange: "updateLink()", data: { text: "Estimate ##{estimate.doc_number}", new_issue_param: 'issue[estimate_id]' }, class: "estimate-checkbox appointment" %>
|
||||
<b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %>
|
||||
<%# Ticking an estimate adds it to the customer page's New issue and Add appointment links (customers/_new_issue_link_script) %>
|
||||
<span class="qbo-list-check"><%= check_box_tag "estimate_ids[]", estimate.id, false, data: { new_issue_param: 'issue[estimate_id]', appointment_param: 'estimate_id' }, class: "estimate-checkbox" if local_assigns[:new_issue_checkboxes] %></span>
|
||||
<b class="qbo-list-number"><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b>
|
||||
<span class="qbo-list-date"><%= estimate.txn_date %></span>
|
||||
<%# QuickBooks status, cached by the estimate sync (kept current by the webhook) %>
|
||||
<% if estimate.txn_status.present? %>
|
||||
<span class="qbo-estimate-status qbo-estimate-status-<%= estimate.txn_status.downcase %>"><%= estimate.txn_status %></span>
|
||||
<% end %>
|
||||
<%= render partial: 'qbo_estimates/estimate_actions', locals: { estimate: estimate } if RedmineQboBilling.writer? %>
|
||||
<span class="qbo-list-status">
|
||||
<% if estimate.txn_status.present? %>
|
||||
<span class="qbo-estimate-status qbo-estimate-status-<%= estimate.txn_status.downcase %>"><%= estimate.txn_status %></span>
|
||||
<% end %>
|
||||
</span>
|
||||
<span class="qbo-list-actions"><%= render partial: 'qbo_estimates/estimate_actions', locals: { estimate: estimate } if RedmineQboBilling.writer? %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -13,14 +13,19 @@
|
||||
|
||||
<div class="qbo-invoice-list">
|
||||
<% invoices.sort.reverse.each do |invoice| %>
|
||||
<%# One cell each (qbo_estimates/_status_styles lines them up in columns, so the icons line up) %>
|
||||
<div class="row">
|
||||
<%= 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 %>
|
||||
<%# Paid / partially paid / overdue / open / voided, from the cached balance and due date %>
|
||||
<% if (status = invoice.status) %>
|
||||
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status, paid_on: invoice.paid_on) %></span>
|
||||
<% end %>
|
||||
<%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %>
|
||||
<span class="qbo-list-check"><%= check_box_tag "invoice_ids[]", invoice.id, false, class: "invoice-checkbox" if invoices.count > 1 %></span>
|
||||
<b class="qbo-list-number"><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b>
|
||||
<span class="qbo-list-date"><%= invoice.txn_date %></span>
|
||||
<%# Paid / partially paid / overdue / open / voided, from the cached balance and due date; short so the list
|
||||
stays narrow: "Paid", or "Paid +3d" when paid in full days after its date (the date on hover) %>
|
||||
<span class="qbo-list-status">
|
||||
<% if (status = invoice.status) %>
|
||||
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>" title="<%= RedmineQboBilling::InvoiceStatus.title(status, paid_on: invoice.paid_on) %>"><%= RedmineQboBilling::InvoiceStatus.short_label(status, paid_on: invoice.paid_on, invoice_date: invoice.txn_date) %></span>
|
||||
<% end %>
|
||||
</span>
|
||||
<span class="qbo-list-actions"><%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -14,4 +14,11 @@
|
||||
.qbo-invoice-status-open { background: #e8eefa; color: #0d47a1; }
|
||||
.qbo-invoice-status-voided { background: #eceef1; color: #6b6c72; text-decoration: line-through; }
|
||||
.qbo-invoice-list .qbo-estimate-status { font-size: .8em; padding: 1px 7px; margin-left: 4px; }
|
||||
/* The estimate and invoice lists: checkbox, number, date, status and actions in columns, so the edit/view icons
|
||||
line up; a list wider than its column scrolls instead of wrapping */
|
||||
.qbo-estimate-list, .qbo-invoice-list { display: grid; grid-template-columns: repeat(5, max-content); column-gap: .35em;
|
||||
row-gap: 2px; align-items: center; overflow-x: auto; }
|
||||
.qbo-estimate-list .row, .qbo-invoice-list .row { display: contents; }
|
||||
.qbo-estimate-list .row > *, .qbo-invoice-list .row > * { white-space: nowrap; }
|
||||
.qbo-list-status .qbo-estimate-status { margin-left: 0; }
|
||||
</style>
|
||||
@@ -1,20 +0,0 @@
|
||||
function updateLink() {
|
||||
console.log("updateLink called");
|
||||
const linkElement = document.getElementById("appointment_link");
|
||||
const regex = /((?:<br\/>|%3Cbr\/?%3E))([\s\S]*?)(&dates)/gi;
|
||||
linkElement.href = linkElement.href.replace(regex, `$1${getSelectedDocs()}$3`);
|
||||
}
|
||||
|
||||
function getSelectedDocs() {
|
||||
const appointent_extras = document.querySelectorAll('.appointment');
|
||||
|
||||
let output = '';
|
||||
for (const item of appointent_extras) {
|
||||
if (item.checked) {
|
||||
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`;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -1,8 +1,3 @@
|
||||
/* Keep Redmine default look, just enhance metadata */
|
||||
.ui-autocomplete .autocomplete-meta {
|
||||
color: #888;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
/* Contextual links on their own line under the page title (customer and vehicle pages), where a long title and
|
||||
many links would otherwise crowd each other */
|
||||
#content .contextual.qbo-under-title {
|
||||
|
||||
+2
-28
@@ -29,14 +29,11 @@ en:
|
||||
field_invoice: "Invoice"
|
||||
field_notes: "Notes"
|
||||
label_account_balance: "Account Balance"
|
||||
label_actions: "Actions"
|
||||
label_amount: "Amount"
|
||||
label_appointment: "Add Appointment"
|
||||
label_balance_with_jobs: "Balance With Jobs"
|
||||
label_bill_time: "Bill Time"
|
||||
label_billing_address: "Billing Address"
|
||||
label_billing_enqueued: "Billing has been enqueued for issue"
|
||||
label_billed_success: "Successfully billed "
|
||||
label_client_id: "Intuit QBO OAuth2 Client ID"
|
||||
label_client_secret: "Intuit QBO OAuth2 Client Secret"
|
||||
label_closed_issues: "Closed Issues"
|
||||
@@ -45,23 +42,17 @@ en:
|
||||
label_customer_link_expires: "This customer link expires in"
|
||||
label_customer: "Customer"
|
||||
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_error: "Error"
|
||||
label_estimate_404: "Estimate not found"
|
||||
label_estimate: "Estimate"
|
||||
label_estimates: "Estimates"
|
||||
label_hours: "Hours"
|
||||
label_invoice_404: "Invoice not found"
|
||||
label_invoices: "Invoices"
|
||||
label_last_sync: "Last Sync"
|
||||
label_load_customer: "Load Customer"
|
||||
label_make: "Make"
|
||||
label_matching: "Matching"
|
||||
label_mobile_phone: "Mobile Phone"
|
||||
@@ -74,13 +65,9 @@ en:
|
||||
text_customers_best_match: "%{count} best matches, closest first. Click a column to sort them by it instead."
|
||||
label_no_estimates: "No Estimates"
|
||||
label_no_invoices: "No Invoices"
|
||||
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
|
||||
label_oauth_expires: "OAuth2 Access Token Expires At"
|
||||
label_oauth_note: "Note: You need to authenticate with QuickBooks after saving your key and secret above."
|
||||
label_open_issues: "Open Issues"
|
||||
label_primary_phone: "Primary Phone"
|
||||
label_qbo_sync_success: "Successfully synced to QuickBooks"
|
||||
label_redmine_qbo: "Redmine QuickBooks"
|
||||
label_sandbox: "Sandbox"
|
||||
label_search: "Search"
|
||||
label_search_customers: "Search Customers"
|
||||
@@ -97,23 +84,11 @@ en:
|
||||
notice_billing_error_no_customer: "Cannot bill without an assigned customer."
|
||||
notice_billing_error_no_employee: "Cannot bill without an assigned employee."
|
||||
notice_billing_error_no_qbo: "Cannot bill without a QuickBooks connection. Please connect to QuickBooks and try again."
|
||||
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_issue_not_found: "The issue could not be found. Please check the issue and try again."
|
||||
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, we are syncing with QuickBooks to find it. Please check back shortly."
|
||||
notice_estimate_updated: "Estimate 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_updated: "Invoice updated in QuickBooks"
|
||||
notice_issue_not_found: "Issue not found"
|
||||
warn_ru_sure: "Are you sure?"
|
||||
|
||||
# ---- Billing: estimates, invoices, payments, items and accounts ----
|
||||
label_billing_settings: "Billing"
|
||||
@@ -247,7 +222,6 @@ en:
|
||||
label_default_account: "Default Item Income Account"
|
||||
label_description: "Description"
|
||||
label_edit_item: "Edit Item"
|
||||
label_item: "Item"
|
||||
label_item_new: "New Item"
|
||||
label_items: "Items"
|
||||
label_management_and_sync: "Synchronization"
|
||||
@@ -261,9 +235,7 @@ en:
|
||||
text_qbo_sync_info: "Sync changes reads what changed in QuickBooks since the last sync; Full sync and each type's Sync re-read every record (e.g. after changing the labor products/services, sync estimates and invoices). Webhooks keep things current in between."
|
||||
text_default_account_info: "New products/services go in this income account; set it on the Accounts page."
|
||||
label_never_synced: "Never synced"
|
||||
label_no: "No"
|
||||
label_type: "Type"
|
||||
label_yes: "Yes"
|
||||
error_default_account_not_selected: "Select an account to make it the default."
|
||||
notice_default_account_updated: "Default account updated."
|
||||
|
||||
@@ -290,6 +262,8 @@ en:
|
||||
label_invoice_no: "Invoice no."
|
||||
label_invoice_status_paid: "Paid"
|
||||
label_invoice_status_paid_on: "Paid %{date}"
|
||||
label_invoice_status_paid_days: "Paid +%{days}d"
|
||||
text_invoice_paid_in_full: "Paid in full %{date}"
|
||||
label_invoice_status_partial: "Partially paid"
|
||||
label_invoice_status_overdue: "Overdue"
|
||||
label_invoice_status_open: "Open"
|
||||
|
||||
+2
-6
@@ -33,11 +33,7 @@ post 'bill/:id', to: 'qbo#bill', as: :bill
|
||||
get 'customers/view/:token', to: 'customers#view', as: :view
|
||||
get 'customers/share/:id', to: 'customers#share', as: :share
|
||||
|
||||
#java script routes
|
||||
get 'filter_estimates_by_customer' => 'customers#filter_estimates_by_customer'
|
||||
get 'filter_invoices_by_customer' => 'customers#filter_invoices_by_customer'
|
||||
|
||||
resources :customers do
|
||||
resources :customers, except: [:destroy] do
|
||||
collection do
|
||||
get :autocomplete
|
||||
get :sync
|
||||
@@ -99,7 +95,7 @@ resources :items do
|
||||
end
|
||||
|
||||
# QuickBooks income accounts
|
||||
resources :accounts do
|
||||
resources :accounts, only: [:index] do
|
||||
collection do
|
||||
patch :set_default
|
||||
get :sync
|
||||
|
||||
@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo do
|
||||
name 'Redmine QBO plugin'
|
||||
author 'Rick Barrette'
|
||||
description 'A pluging for Redmine to connect with QuickBooks Online: customers, time activities for billable hours when an issue is closed, and estimates, invoices and payments written in Redmine'
|
||||
version '2026.11.22'
|
||||
version '2026.11.23'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||
author_url 'https://barrettefabrication.com'
|
||||
settings default: {empty: true}, partial: 'qbo/settings'
|
||||
@@ -28,9 +28,8 @@ Redmine::Plugin.register :redmine_qbo do
|
||||
TimeEntry.safe_attributes :billed
|
||||
|
||||
# Global Permissions
|
||||
# autocomplete and the filter_* actions feed the customer, estimate and invoice pickers on issue forms
|
||||
permission :view_customers, { customers: [:index, :show, :autocomplete,
|
||||
:filter_estimates_by_customer, :filter_invoices_by_customer] }, global: true
|
||||
# autocomplete feeds the customer pickers (issue forms, estimates, invoices, payments)
|
||||
permission :view_customers, { customers: [:index, :show, :autocomplete] }, global: true
|
||||
permission :add_customers, { customers: [:new, :create] }, global: true
|
||||
permission :edit_customers, { customers: [:edit, :update] }, global: true
|
||||
permission :share_issues_with_customers, { customers: [:share] }, global: true
|
||||
|
||||
@@ -16,7 +16,6 @@ module RedmineQbo
|
||||
# Load the javascript to support the autocomplete forms
|
||||
def view_layouts_base_html_head(context = {})
|
||||
safe_join([
|
||||
javascript_include_tag( 'application.js', plugin: :redmine_qbo),
|
||||
javascript_include_tag( 'autocomplete.js', plugin: :redmine_qbo),
|
||||
javascript_include_tag( 'checkbox_controller.js', plugin: :redmine_qbo),
|
||||
stylesheet_link_tag( 'autocomplete', plugin: :redmine_qbo)
|
||||
|
||||
@@ -15,7 +15,6 @@ module RedmineQbo
|
||||
|
||||
prepended do
|
||||
belongs_to :customer
|
||||
belongs_to :customer_token
|
||||
belongs_to :estimate
|
||||
has_and_belongs_to_many :invoices
|
||||
|
||||
|
||||
@@ -42,6 +42,26 @@ module RedmineQboBilling
|
||||
I18n.t("label_invoice_status_#{status}")
|
||||
end
|
||||
|
||||
# The invoice list's short badge: "Paid", or "Paid +3d" when it was paid in full 3 days after its date
|
||||
def short_label(status, paid_on: nil, invoice_date: nil)
|
||||
days = days_to_pay(invoice_date, paid_on) if status == :paid
|
||||
return I18n.t(:label_invoice_status_paid_days, days: days) if days&.positive?
|
||||
|
||||
label(status)
|
||||
end
|
||||
|
||||
# The badge's tooltip: "Paid in full 11/19/2025" (nil unless it's paid with a known day)
|
||||
def title(status, paid_on: nil)
|
||||
I18n.t(:text_invoice_paid_in_full, date: I18n.l(paid_on)) if status == :paid && paid_on
|
||||
end
|
||||
|
||||
# Days from the invoice's date to the day it was paid in full
|
||||
def days_to_pay(invoice_date, paid_on)
|
||||
return nil unless invoice_date && paid_on
|
||||
|
||||
(paid_on.to_date - invoice_date.to_date).to_i
|
||||
end
|
||||
|
||||
def to_d(value)
|
||||
BigDecimal(value.to_s.presence || '0')
|
||||
rescue ArgumentError
|
||||
|
||||
@@ -21,4 +21,9 @@ namespace :redmine_qbo do
|
||||
|
||||
puts "Checked #{estimates.size} estimate(s), created #{total} relation(s)."
|
||||
end
|
||||
|
||||
desc "Delete customer share links that have expired or whose issue was deleted (also done whenever a link is made)"
|
||||
task purge_customer_tokens: :environment do
|
||||
puts "Deleted #{CustomerToken.purge_expired} customer share link(s)."
|
||||
end
|
||||
end
|
||||
@@ -65,4 +65,18 @@ class BusinessReportTest < ActiveSupport::TestCase
|
||||
assert_equal 105.0, r.chart[:current][:tax_invoiced].compact.sum
|
||||
assert_equal 70.0, r.chart[:current][:tax_collected].compact.sum
|
||||
end
|
||||
|
||||
def test_short_paid_badge
|
||||
status = RedmineQboBilling::InvoiceStatus
|
||||
nov18 = Date.new(2026, 11, 18)
|
||||
assert_equal 'Paid', status.short_label(:paid, paid_on: nov18, invoice_date: nov18)
|
||||
assert_equal 'Paid +1d', status.short_label(:paid, paid_on: nov18 + 1, invoice_date: nov18)
|
||||
assert_equal 'Paid +34d', status.short_label(:paid, paid_on: nov18 + 34, invoice_date: nov18)
|
||||
assert_equal 'Paid', status.short_label(:paid, paid_on: nil, invoice_date: nov18)
|
||||
# A deposit taken before the invoice: paid in full on its date
|
||||
assert_equal 'Paid', status.short_label(:paid, paid_on: nov18, invoice_date: nov18 + 2)
|
||||
assert_equal 'Open', status.short_label(:open, paid_on: nov18 + 3, invoice_date: nov18)
|
||||
assert_match(/\APaid in full \S+/, status.title(:paid, paid_on: nov18))
|
||||
assert_nil status.title(:open, paid_on: nov18)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,48 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 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.
|
||||
|
||||
require File.expand_path('../test_helper', __dir__)
|
||||
|
||||
class CustomerTokenTest < ActiveSupport::TestCase
|
||||
fixtures :projects, :users, :email_addresses, :members, :member_roles, :roles, :issues, :trackers,
|
||||
:projects_trackers, :issue_statuses, :enabled_modules, :enumerations
|
||||
|
||||
def setup
|
||||
CustomerToken.delete_all
|
||||
User.current = User.find(1)
|
||||
end
|
||||
|
||||
def token(issue_id, expires_at)
|
||||
CustomerToken.create!(issue_id: issue_id, expires_at: expires_at)
|
||||
end
|
||||
|
||||
def test_purge_expired
|
||||
active = token(1, 1.week.from_now)
|
||||
token(2, 1.day.ago)
|
||||
token(3, 1.month.ago)
|
||||
token(99_999, 1.week.from_now) # its issue was deleted
|
||||
assert_equal 3, CustomerToken.purge_expired
|
||||
assert_equal [active.id], CustomerToken.pluck(:id)
|
||||
end
|
||||
|
||||
def test_a_new_share_link_clears_out_old_ones
|
||||
token(2, 1.day.ago)
|
||||
link = CustomerToken.get_token(Issue.find(1))
|
||||
assert link.expires_at > Time.current
|
||||
assert_equal [link.id], CustomerToken.pluck(:id)
|
||||
end
|
||||
|
||||
def test_an_active_link_is_reused
|
||||
active = token(1, 1.week.from_now)
|
||||
token(2, 1.day.ago)
|
||||
assert_equal active, CustomerToken.get_token(Issue.find(1))
|
||||
assert_equal 2, CustomerToken.count # nothing new made, nothing cleared
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user