2 Commits

Author SHA1 Message Date
1febdc3e04 2026.3.5 2026-03-09 20:52:38 -04:00
d1f8f027c0 Allow doing math in price field for each markups 2026-03-09 20:45:26 -04:00
4 changed files with 38 additions and 3 deletions

View File

@@ -23,9 +23,10 @@
</td>
<td data-label="<%= t :label_price %>">
<%= f.number_field :unit_price,
step: 0.01,
<%= f.text_field :unit_price,
class: "price-field",
inputmode: "decimal",
autocomplete: "off",
no_label: true,
disabled: readonly %>
</td>

View File

@@ -0,0 +1,33 @@
function evaluateMathExpression(expr) {
if (!expr) return null;
// allow only digits, decimal, operators, parentheses, spaces
if (!/^[0-9+\-*/().\s]+$/.test(expr)) {
return null;
}
try {
return Function('"use strict"; return (' + expr + ')')();
} catch {
return null;
}
}
document.addEventListener("blur", function(e) {
if (!e.target.classList.contains("price-field")) return;
const field = e.target;
const value = field.value.trim();
const result = evaluateMathExpression(value);
if (result !== null && !isNaN(result)) {
field.value = Number(result).toFixed(2);
}
if (typeof updateLineItemTotals === "function") {
updateLineItemTotals();
}
}, true);

View File

@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo_lineitems do
name 'Redmine QBO Line Items plugin'
author 'Rick Barrette'
description 'A plugin for Redmine to extend the capabilitys of the Redmine QuickBooks Online plugin to attach billable line items to an isuue'
version '2026.3.4'
version '2026.3.5'
url 'https://github.com/rickbarrette/redmine_qbo_lineitems'
author_url 'https://barrettefabrication.com'
requires_redmine version_or_higher: '6.1.0'

View File

@@ -19,6 +19,7 @@ module RedmineQboLineItems
javascript_include_tag( 'nested_form_controller', plugin: :redmine_qbo_lineitems),
javascript_include_tag("line_items", plugin: :redmine_qbo_lineitems),
javascript_include_tag("autocomplete", plugin: :redmine_qbo_lineitems),
javascript_include_tag("blur", plugin: :redmine_qbo_lineitems),
stylesheet_link_tag("line_items", plugin: :redmine_qbo_lineitems)
])
end