mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-19 10:40:36 -05:00
Compare commits
9
Commits
2026.11.6
...
2026.11.10
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cfc8a370e | ||
|
|
d2cdd798cd | ||
|
|
159420fac1 | ||
|
|
dbee228cdf | ||
|
|
ec00684edd | ||
|
|
839ac976e6 | ||
|
|
dc72b11766 | ||
|
|
778111825b | ||
|
|
4ba96e2dfd |
No files matched your search
@@ -116,13 +116,19 @@ class QboEstimatesController < ApplicationController
|
||||
customer = Customer.find_by(id: params[:customer_id])
|
||||
return render(json: {}, status: :not_found) unless customer
|
||||
|
||||
render json: {
|
||||
info = {
|
||||
id: customer.id,
|
||||
name: customer.name,
|
||||
email: RedmineQboBilling::EstimateWriter.customer_email(customer),
|
||||
billing_address: RedmineQboBilling::EstimateWriter.customer_address(customer),
|
||||
field_options: RedmineQboBilling.field_options(customer)
|
||||
}
|
||||
# A new invoice warns about the customer's open issues
|
||||
if params[:document] == 'invoice'
|
||||
info[:open_issues_html] = render_to_string(partial: 'qbo_invoices/open_issues', formats: [:html],
|
||||
locals: { customer: customer })
|
||||
end
|
||||
render json: info
|
||||
end
|
||||
|
||||
# Product/service search for the line table (the QuickBooks item list)
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#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.
|
||||
|
||||
# Estimates, invoices and payments on Redmine's activity page. They come from QuickBooks and belong to no
|
||||
# project, so they show on the overall activity page only (not a project's, nor a user's), and each kind only to
|
||||
# users with one of its global permissions.
|
||||
module QboActivity
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
# event_type: the activity type registered in init.rb (e.g. 'qbo_estimates'); icon: the event's CSS class
|
||||
# and icon in this plugin's sprite (assets/images/icons.svg); permissions: any one of these shows it
|
||||
def qbo_activity(event_type, icon:, permissions:, title:, description:, url:)
|
||||
# These models can load before Redmine adds acts_as_event to every model
|
||||
include Redmine::Acts::Event unless respond_to?(:acts_as_event)
|
||||
acts_as_event title: title, description: description, url: url, type: icon,
|
||||
datetime: :activity_datetime, author: nil
|
||||
class_attribute :qbo_activity_permissions, instance_writer: false, default: permissions
|
||||
class_attribute :qbo_activity_event_type, instance_writer: false, default: event_type
|
||||
end
|
||||
|
||||
def qbo_activity_visible_to?(user)
|
||||
qbo_activity_permissions.any? { |permission| user.allowed_to?(permission, nil, global: true) }
|
||||
end
|
||||
|
||||
# What Redmine::Activity::Fetcher reads for a project's activity page; these never show there
|
||||
def activity_provider_options
|
||||
{ qbo_activity_event_type => { permission: qbo_activity_permissions.first } }
|
||||
end
|
||||
|
||||
# Documents dated from..to (the page's days, to not included), newest first. From the QuickBooks date, so
|
||||
# a sync bringing in old documents doesn't pile them onto the day it ran.
|
||||
def find_events(event_type, user, from, to, options)
|
||||
return [] if options[:project] || options[:author] || !qbo_activity_visible_to?(user)
|
||||
|
||||
scope = includes(:customer).where.not(txn_date: nil)
|
||||
scope = scope.where('txn_date >= ?', from.to_date) if from
|
||||
scope = scope.where('txn_date < ?', to.to_date) if to
|
||||
scope = scope.order(txn_date: :desc, id: :desc).limit(options[:limit]) if options[:limit]
|
||||
scope.to_a
|
||||
end
|
||||
end
|
||||
|
||||
# When it happened: the time it reached Redmine when that was its QuickBooks date (created or changed in
|
||||
# QuickBooks and sent by the webhook moments later), else midday on its QuickBooks date (e.g. a full sync)
|
||||
def activity_datetime
|
||||
return created_at if created_at && created_at.getlocal.to_date == txn_date
|
||||
|
||||
Time.local(txn_date.year, txn_date.month, txn_date.day, 12)
|
||||
end
|
||||
|
||||
# Activity events have a project; these don't
|
||||
def project
|
||||
nil
|
||||
end
|
||||
|
||||
def activity_money(amount)
|
||||
ActiveSupport::NumberHelper.number_to_currency(amount) if amount
|
||||
end
|
||||
|
||||
def activity_customer
|
||||
customer&.name.presence || I18n.t(:label_none)
|
||||
end
|
||||
end
|
||||
@@ -17,6 +17,12 @@ class Estimate < QboBaseModel
|
||||
self.primary_key = :id
|
||||
qbo_sync push: false
|
||||
|
||||
include QboActivity
|
||||
qbo_activity 'qbo_estimates', icon: 'qbo-estimate', permissions: %i[view_customers write_estimates],
|
||||
title: ->(e) { I18n.t(:label_activity_estimate, number: e.doc_number, customer: e.activity_customer) },
|
||||
description: ->(e) { [e.activity_money(e[:total_amount]), e[:txn_status]].compact.join(' · ') },
|
||||
url: ->(e) { { controller: 'estimates', action: 'show', id: e.id } }
|
||||
|
||||
def name
|
||||
to_s
|
||||
end
|
||||
|
||||
@@ -17,11 +17,26 @@ class Invoice < QboBaseModel
|
||||
self.primary_key = :id
|
||||
qbo_sync push: false
|
||||
|
||||
include QboActivity
|
||||
qbo_activity 'qbo_invoices', icon: 'qbo-invoice', permissions: %i[view_customers write_invoices],
|
||||
title: ->(i) { I18n.t(:label_activity_invoice, number: i.doc_number, customer: i.activity_customer) },
|
||||
description: ->(i) { i.activity_description },
|
||||
url: ->(i) { { controller: 'invoices', action: 'show', id: i.id } }
|
||||
|
||||
# Return the invoice's document number as its string representation
|
||||
def to_s
|
||||
doc_number
|
||||
end
|
||||
|
||||
# Amount and where it stands, e.g. "$1,250.00 · Partially paid ($400.00 owed)"
|
||||
def activity_description
|
||||
state = status
|
||||
owed = activity_money(self[:balance]) if state && self[:balance].to_d.positive?
|
||||
[activity_money(self[:total_amount]),
|
||||
(I18n.t(:"label_invoice_status_#{state}", default: state.to_s.humanize) if state),
|
||||
(I18n.t(:text_activity_invoice_owed, amount: owed) if owed && state != :open && state != :overdue)].compact.join(' · ')
|
||||
end
|
||||
|
||||
# Paid, partially paid, overdue, open or voided, from the cached total, balance and due date
|
||||
# (RedmineQboBilling::InvoiceStatus); nil when the balance isn't cached
|
||||
def status(today: User.current.today)
|
||||
|
||||
@@ -18,6 +18,19 @@ class Payment < QboBaseModel
|
||||
self.primary_key = :id
|
||||
qbo_sync push: false
|
||||
|
||||
include QboActivity
|
||||
qbo_activity 'qbo_payments', icon: 'qbo-payment', permissions: %i[view_payments receive_payments],
|
||||
title: ->(p) { I18n.t(:label_activity_payment, customer: p.activity_customer, amount: p.activity_money(p.total_amount)) },
|
||||
description: ->(p) { p.activity_description },
|
||||
url: ->(p) { { controller: 'qbo_payments', action: 'show', id: p.id } }
|
||||
|
||||
# Money not yet applied to an invoice, when there is some
|
||||
def activity_description
|
||||
return '' unless unapplied_amount.to_d.positive?
|
||||
|
||||
I18n.t(:text_activity_payment_unapplied, amount: activity_money(unapplied_amount))
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{txn_date} #{total_amount}"
|
||||
end
|
||||
|
||||
@@ -27,6 +27,7 @@ class InvoiceAttachmentService
|
||||
unless issue.invoices.exists?(@invoice.id)
|
||||
issue.invoices << @invoice
|
||||
issue.save! if issue.changed?
|
||||
journalize(issue)
|
||||
log "Attached invoice ##{@invoice.id} to issue ##{issue.id}"
|
||||
end
|
||||
end
|
||||
@@ -34,6 +35,18 @@ class InvoiceAttachmentService
|
||||
|
||||
private
|
||||
|
||||
# Records the new invoice in the issue's history (shown by RedmineQbo::Patches::IssuesHelperPatch).
|
||||
# The webhook has no Redmine user, so the entry is by Anonymous. Saving the journal also sends
|
||||
# Redmine's usual issue-updated emails.
|
||||
def journalize(issue)
|
||||
journal = Journal.new(journalized: issue, user: User.anonymous, notes: '')
|
||||
journal.details << JournalDetail.new(property: 'invoice', prop_key: @invoice.id.to_s, value: @invoice.to_s.presence || @invoice.id.to_s)
|
||||
journal.save
|
||||
rescue => e
|
||||
# The invoice is attached either way; a missing history entry shouldn't fail the sync
|
||||
log "Couldn't add invoice ##{@invoice.id} to the history of issue ##{issue.id}: #{e.message}"
|
||||
end
|
||||
|
||||
# Extract issue IDs from the invoice's private note and line descriptions
|
||||
def extract_issue_ids
|
||||
ids = []
|
||||
|
||||
@@ -415,10 +415,18 @@ $(function () {
|
||||
});
|
||||
|
||||
$('#qbo-estimate-clear-lines').on('click', function () {
|
||||
if (!window.confirm($(this).data('confirmText'))) return;
|
||||
rows().remove();
|
||||
addRow(); addRow();
|
||||
changed();
|
||||
function clearLines() {
|
||||
rows().remove();
|
||||
addRow(); addRow();
|
||||
changed();
|
||||
}
|
||||
// redmine_dark_mode asks in a dark dialog on dark pages; otherwise the browser's own box
|
||||
var message = $(this).data('confirmText');
|
||||
if (window.RedmineDarkMode && window.RedmineDarkMode.confirm) {
|
||||
window.RedmineDarkMode.confirm(message, clearLines);
|
||||
} else if (window.confirm(message)) {
|
||||
clearLines();
|
||||
}
|
||||
});
|
||||
|
||||
// Drag lines by the handle to reorder them; they're saved in table order
|
||||
@@ -446,7 +454,9 @@ $(function () {
|
||||
var id = $(this).val();
|
||||
if (!id) return;
|
||||
dirty = true;
|
||||
$.getJSON($form.data('customerInfoUrl'), { customer_id: id }).done(function (info) {
|
||||
$.getJSON($form.data('customerInfoUrl'), { customer_id: id, document: $form.data('document') }).done(function (info) {
|
||||
// A new invoice's open issues notice follows the customer
|
||||
if (info.open_issues_html !== undefined) $('#qbo-open-issues').replaceWith(info.open_issues_html);
|
||||
// Replace the email only if it was the previous customer's (or empty)
|
||||
if (!$email.val().trim() || $email.val() === loadedEmail) $email.val(info.email || '');
|
||||
loadedEmail = info.email || '';
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<%# A new invoice's customer still has open issues (work orders), so they're not left behind once billed.
|
||||
Replaced when the customer is changed (customer_info's open_issues_html). %>
|
||||
<%
|
||||
issues = customer ? customer.issues.open.visible.order(id: :desc).to_a : []
|
||||
%>
|
||||
<div id="qbo-open-issues">
|
||||
<% if issues.any? %>
|
||||
<div class="warning qbo-estimate-notice">
|
||||
<%= l(:text_invoice_customer_open_issues, count: issues.size) %>
|
||||
<ul>
|
||||
<% issues.each do |issue| %>
|
||||
<li><%= link_to_issue(issue, truncate: 60) %> (<%= issue.status %>)</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,4 +1,5 @@
|
||||
<% html_title l(:label_new_invoice) %>
|
||||
|
||||
<%= render partial: 'qbo_estimates/header', locals: { form: @form } %>
|
||||
<%= render partial: 'qbo_invoices/open_issues', locals: { customer: (Customer.find_by(id: @form.customer_id) if @form.customer_id.present?) } %>
|
||||
<%= render partial: 'qbo_estimates/form', locals: { form: @form } %>
|
||||
@@ -289,9 +289,28 @@
|
||||
return 'rgba(' + (n >> 16 & 255) + ',' + (n >> 8 & 255) + ',' + (n & 255) + ',0.45)';
|
||||
}
|
||||
|
||||
// Grid lines and text from the page's colours, so a dark mode (e.g. redmine_dark_mode) can set
|
||||
// --qbo-chart-grid and --qbo-chart-text; Chart.js' own colours otherwise
|
||||
function chartColors() {
|
||||
var style = getComputedStyle(document.documentElement);
|
||||
return { grid: style.getPropertyValue('--qbo-chart-grid').trim() || 'rgba(0,0,0,0.1)',
|
||||
text: style.getPropertyValue('--qbo-chart-text').trim() || '#666' };
|
||||
}
|
||||
function applyColors(chart) {
|
||||
var c = chartColors();
|
||||
['x', 'y'].forEach(function(axis) {
|
||||
var scale = chart.options.scales[axis];
|
||||
scale.grid.color = c.grid;
|
||||
scale.border.color = c.grid;
|
||||
scale.ticks.color = c.text;
|
||||
});
|
||||
chart.options.plugins.legend.labels.color = c.text;
|
||||
}
|
||||
|
||||
function draw(Chart, canvas, compare) {
|
||||
var series = JSON.parse(canvas.getAttribute('data-series'));
|
||||
var isMoney = canvas.getAttribute('data-kind') === 'money';
|
||||
var colors = chartColors();
|
||||
var datasets = [];
|
||||
series.forEach(function(s) {
|
||||
datasets.push({ label: s.label, data: s.current, borderColor: s.color, backgroundColor: s.color,
|
||||
@@ -317,6 +336,7 @@
|
||||
position: 'bottom',
|
||||
labels: {
|
||||
boxWidth: 12,
|
||||
color: colors.text,
|
||||
generateLabels: function(chart) {
|
||||
var items = Chart.defaults.plugins.legend.labels.generateLabels(chart).filter(function(item) {
|
||||
return !chart.data.datasets[item.datasetIndex].previous;
|
||||
@@ -355,7 +375,9 @@
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
y: { beginAtZero: true, ticks: { precision: isMoney ? 0 : 1, callback: function(v) { return isMoney ? money(v, 0) : v; } } }
|
||||
x: { grid: { color: colors.grid }, border: { color: colors.grid }, ticks: { color: colors.text } },
|
||||
y: { beginAtZero: true, grid: { color: colors.grid }, border: { color: colors.grid },
|
||||
ticks: { color: colors.text, precision: isMoney ? 0 : 1, callback: function(v) { return isMoney ? money(v, 0) : v; } } }
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -406,6 +428,10 @@
|
||||
$('.qbo-report-chart').hide();
|
||||
});
|
||||
$compare.on('change', function() { setCompare(this.checked); });
|
||||
// Switching between light and dark (redmine_dark_mode) recolours the charts
|
||||
document.addEventListener('redmine:color-scheme', function() {
|
||||
charts.forEach(function(chart) { applyColors(chart); chart.update('none'); });
|
||||
});
|
||||
});
|
||||
})();
|
||||
<% end %>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- Activity icons (Tabler outline icons, MIT), in the layout of Redmine's own sprite -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon--sprite">
|
||||
<defs>
|
||||
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--qbo-estimate">
|
||||
<path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2"/>
|
||||
<path d="M9 5a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"/>
|
||||
<path d="M9 12h.01"/>
|
||||
<path d="M13 12h2"/>
|
||||
<path d="M9 16h.01"/>
|
||||
<path d="M13 16h2"/>
|
||||
</symbol>
|
||||
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--qbo-invoice">
|
||||
<path d="M14 3v4a1 1 0 0 0 1 1h4"/>
|
||||
<path d="M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z"/>
|
||||
<path d="M9 7h1"/>
|
||||
<path d="M9 13h6"/>
|
||||
<path d="M13 17h2"/>
|
||||
</symbol>
|
||||
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--qbo-payment">
|
||||
<path d="M7 11a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v6a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2z"/>
|
||||
<path d="M12 14a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"/>
|
||||
<path d="M17 9v-2a2 2 0 0 0 -2 -2h-10a2 2 0 0 0 -2 2v6a2 2 0 0 0 2 2h2"/>
|
||||
</symbol>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -12,3 +12,8 @@
|
||||
margin: -4px 0 10px;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
/* Estimates, invoices and payments on the activity page belong to no project: no " - " after an empty name */
|
||||
div#activity span.project:empty:after {
|
||||
content: none;
|
||||
}
|
||||
@@ -256,6 +256,9 @@ en:
|
||||
notice_invoice_sent: "Invoice #%{number} emailed to %{email}"
|
||||
text_email_invoice_confirmation: "Email invoice #%{number} to %{email}?"
|
||||
text_invoice_from_estimate: "Made from estimate #%{number}. The estimate is closed when the invoice is saved."
|
||||
text_invoice_customer_open_issues:
|
||||
one: "This customer has an open issue. Make sure its work is finished and billed so it isn't left open:"
|
||||
other: "This customer has %{count} open issues. Make sure their work is finished and billed so none are left open:"
|
||||
text_line_bills_time: "Bills a QuickBooks time activity; saving marks the time as billed"
|
||||
text_replace_lines: "Tick the lines the time replaces (e.g. the estimate's labor lines). Each time entry takes the place of the line with its issue's description (e.g. Install Lift Kit), then any others in order."
|
||||
|
||||
@@ -355,3 +358,13 @@ en:
|
||||
text_payment_pick_invoices: "Tick invoices to fill in the amount and pay just those. With none ticked, the payment goes on the oldest invoices first."
|
||||
text_payment_reference: "e.g. the check number"
|
||||
text_payment_unapplied_deposit: "Not applied to any invoice: it's a credit on the customer's account."
|
||||
|
||||
# Activity page
|
||||
label_qbo_estimate_plural: "Estimates"
|
||||
label_qbo_invoice_plural: "Invoices"
|
||||
label_qbo_payment_plural: "Payments"
|
||||
label_activity_estimate: "Estimate #%{number}: %{customer}"
|
||||
label_activity_invoice: "Invoice #%{number}: %{customer}"
|
||||
label_activity_payment: "Payment from %{customer}: %{amount}"
|
||||
text_activity_invoice_owed: "%{amount} owed"
|
||||
text_activity_payment_unapplied: "%{amount} not applied to an invoice"
|
||||
@@ -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.6'
|
||||
version '2026.11.10'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||
author_url 'https://barrettefabrication.com'
|
||||
settings default: {empty: true}, partial: 'qbo/settings'
|
||||
@@ -52,6 +52,13 @@ Redmine::Plugin.register :redmine_qbo do
|
||||
permission :view_business_reports, { qbo_reports: [:index] }, global: true
|
||||
# The product/service list, accounts and their syncs are admin-only (see ItemsController, AccountsController)
|
||||
|
||||
# Estimates, invoices and payments on the activity page (QboActivity): the overall page only, for users with
|
||||
# View customers or Write estimates / invoices, and View or Receive payments
|
||||
# (plugin: picks their icons from this plugin's sprite, assets/images/icons.svg)
|
||||
activity_provider :qbo_estimates, class_name: 'Estimate', plugin: :redmine_qbo
|
||||
activity_provider :qbo_invoices, class_name: 'Invoice', plugin: :redmine_qbo
|
||||
activity_provider :qbo_payments, class_name: 'Payment', plugin: :redmine_qbo
|
||||
|
||||
# Register top menu items
|
||||
menu :top_menu, :customers, { controller: :customers, action: :index }, caption: :label_customers, if: Proc.new {User.current.allowed_to?(:view_customers, nil, global: true)}
|
||||
menu :top_menu, :qbo_reports, { controller: :qbo_reports, action: :index }, caption: :label_business_report,
|
||||
|
||||
@@ -18,11 +18,15 @@ module RedmineQbo
|
||||
IssueQuery.prepend RedmineQbo::Patches::QueryPatch
|
||||
TimeEntryQuery.prepend RedmineQbo::Patches::TimeEntryQueryPatch
|
||||
|
||||
# === Activity: estimates, invoices and payments, for users who may see them ===
|
||||
Redmine::Activity::Fetcher.prepend RedmineQbo::Patches::ActivityFetcherPatch
|
||||
|
||||
# === Controllers ===
|
||||
RedmineQbo::Patches::IssuesControllerPatch.apply
|
||||
RedmineQbo::Patches::AttachmentsControllerPatch.apply
|
||||
|
||||
# === Helpers / Exports ===
|
||||
IssuesHelper.prepend RedmineQbo::Patches::IssuesHelperPatch
|
||||
Redmine::Export::PDF::IssuesPdfHelper.prepend RedmineQbo::Patches::PdfPatch
|
||||
|
||||
# === Hooks ===
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#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.
|
||||
|
||||
module RedmineQbo
|
||||
module Patches
|
||||
# The activity page lists every activity type for the whole site, and a project's page those its members may
|
||||
# see. QuickBooks estimates, invoices and payments (QboActivity) belong to no project: they're kept to the
|
||||
# overall page, and to users with one of their permissions, so nobody gets a checkbox for activity they can't see.
|
||||
module ActivityFetcherPatch
|
||||
def event_types
|
||||
return @event_types if @qbo_activity_checked
|
||||
|
||||
@qbo_activity_checked = true
|
||||
@event_types = super.select do |event_type|
|
||||
providers = Redmine::Activity.providers[event_type].map(&:constantize)
|
||||
qbo = providers.select { |provider| provider.respond_to?(:qbo_activity_visible_to?) }
|
||||
qbo.empty? || (project.nil? && qbo.any? { |provider| provider.qbo_activity_visible_to?(user) })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,69 @@
|
||||
#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.
|
||||
|
||||
module RedmineQbo
|
||||
module Patches
|
||||
# Shows the customer and estimate by name, and invoices attached by the QuickBooks webhook, in an
|
||||
# issue's history, emails and PDF. Redmine records the customer and estimate by id, like its own
|
||||
# fields, but only looks up names for the fields it knows about. The ids stay in the database, so
|
||||
# existing history entries show names too.
|
||||
module IssuesHelperPatch
|
||||
JOURNAL_NAMED_FIELDS = { 'customer_id' => 'Customer', 'estimate_id' => 'Estimate' }.freeze
|
||||
|
||||
def show_detail(detail, no_html = false, options = {})
|
||||
return qbo_invoice_detail(detail, no_html, options) if detail.property == 'invoice'
|
||||
|
||||
model = detail.property == 'attr' && JOURNAL_NAMED_FIELDS[detail.prop_key]
|
||||
return super unless model
|
||||
|
||||
# Hand Redmine a copy with names in place of ids, so it formats it like any other change
|
||||
named = JournalDetail.new(property: detail.property, prop_key: detail.prop_key,
|
||||
old_value: qbo_journal_name(model, detail.old_value),
|
||||
value: qbo_journal_name(model, detail.value))
|
||||
named.id = detail.id
|
||||
named.journal_id = detail.journal_id
|
||||
super(named, no_html, options)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# "Invoice 1042 added", recorded when the QuickBooks webhook attaches an invoice to the issue
|
||||
# (see InvoiceAttachmentService). The number links to the invoice PDF while the invoice exists.
|
||||
def qbo_invoice_detail(detail, no_html, options)
|
||||
label = l(:field_invoice)
|
||||
value = detail.value
|
||||
old_value = detail.old_value
|
||||
|
||||
unless no_html
|
||||
label = content_tag('strong', label)
|
||||
if value.present?
|
||||
value = Invoice.exists?(detail.prop_key) ? link_to(value, invoice_url(detail.prop_key, only_path: options[:only_path] != false)) : content_tag('i', value)
|
||||
end
|
||||
old_value = content_tag('del', content_tag('i', old_value)) if old_value.present?
|
||||
end
|
||||
|
||||
if detail.value.present?
|
||||
l(:text_journal_added, label: label, value: value).html_safe
|
||||
else
|
||||
l(:text_journal_deleted, label: label, old: old_value).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
# The record's name, or the id when it no longer exists. Cached for the request, since a
|
||||
# history can mention the same customer many times.
|
||||
def qbo_journal_name(model, id)
|
||||
return id if id.blank?
|
||||
|
||||
@qbo_journal_names ||= {}
|
||||
@qbo_journal_names[[model, id]] ||= model.constantize.find_by(id: id)&.to_s.presence || id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user