mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
Imported time replaces its own line, not one block at the first
Importing time with "Replace these lines" put all the time where the first ticked line was and removed the others, so ticking several lines jumbled the invoice (time out of order, subtotals over the wrong lines). Each time entry now takes the place of one ticked line: the one whose description is its issue's subject (issues created from an estimate are named after the line: "Install #134: Install Lift Kit" replaces "Install Lift Kit"), then any others in order. Extra time goes after the last replaced line; extra ticked lines are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
3 files changed
+37
-10
No files matched your search
@@ -119,7 +119,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
|
|||||||
|
|
||||||
* **Create invoice** on an estimate's page makes an invoice from it (customer, lines, subtotals, custom fields), like QuickBooks' "Create invoice". **Create invoice** on the customer page starts a blank one, and the Edit link next to each invoice on the customer page opens it.
|
* **Create invoice** on an estimate's page makes an invoice from it (customer, lines, subtotals, custom fields), like QuickBooks' "Create invoice". **Create invoice** on the customer page starts a blank one, and the Edit link next to each invoice on the customer page opens it.
|
||||||
* **Import time & estimates** lists the customer's billable QuickBooks time (the time activities redmine_qbo makes from an issue's time entries) and their open estimates (e.g. the ones redmine_qbo_lineitems makes for parts that weren't quoted).
|
* **Import time & estimates** lists the customer's billable QuickBooks time (the time activities redmine_qbo makes from an issue's time entries) and their open estimates (e.g. the ones redmine_qbo_lineitems makes for parts that weren't quoted).
|
||||||
* Tick the time to bill and, under **Replace these lines**, the lines it replaces (e.g. the estimate's labor lines). Only lines with one of the **labor products/services** from the plugin settings are offered there. The time goes where the first ticked line was and the ticked lines are removed, so the invoice reads in the same order.
|
* Tick the time to bill and, under **Replace these lines**, the lines it replaces (e.g. the estimate's labor lines). Only lines with one of the **labor products/services** from the plugin settings are offered there. Each time entry takes the place of one ticked line: the one whose description is its issue's subject (issues created from an estimate are named after the line, so "Install #134: Install Lift Kit" replaces the "Install Lift Kit" line), then any others in order. Extra time goes after the last replaced line and extra ticked lines are removed, so the invoice keeps the estimate's order and subtotals.
|
||||||
* Ticked estimates go right after the time for the same issue: a redmine_qbo_lineitems estimate starting "Added from: Install #116: …" lands after the time for #116, without that note line, since the time line already names the issue. Estimates with no matching time keep the note and go at the end.
|
* Ticked estimates go right after the time for the same issue: a redmine_qbo_lineitems estimate starting "Added from: Install #116: …" lands after the time for #116, without that note line, since the time line already names the issue. Estimates with no matching time keep the note and go at the end.
|
||||||
* **Undo import** puts the lines back until the invoice is saved.
|
* **Undo import** puts the lines back until the invoice is saved.
|
||||||
* **An estimate is billed once**: an estimate that's on an invoice (linked to one, or closed) or was rejected can't be made into an invoice or imported, and its page shows the invoice it's billed on. This is checked against QuickBooks again when the invoice is saved, so an estimate invoiced meanwhile (in another tab, by someone else, or in QuickBooks) stops the save.
|
* **An estimate is billed once**: an estimate that's on an invoice (linked to one, or closed) or was rejected can't be made into an invoice or imported, and its page shows the invoice it's billed on. This is checked against QuickBooks again when the invoice is saved, so an estimate invoiced meanwhile (in another tab, by someone else, or in QuickBooks) stops the save.
|
||||||
|
|||||||
@@ -548,6 +548,24 @@ $(function () {
|
|||||||
return ids;
|
return ids;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Pairs imported time with the invoice lines ticked under "Replace these lines": first by description,
|
||||||
|
// since issues created from an estimate take the line's description as their subject and the time names
|
||||||
|
// it ("Install #134: Install Lift Kit" <-> "Install Lift Kit"); what's left is paired in order.
|
||||||
|
// Returns { pairs: [{ time, line }], extraTimes: [...], extraLines: [...] }.
|
||||||
|
var pairTimeWithLines = function (times, lines) {
|
||||||
|
var norm = function (text) { return String(text || '').split('\n')[0].toLowerCase().replace(/\s+/g, ' ').trim(); };
|
||||||
|
var subject = function (activity) { return norm(String(activity.description || '').replace(/^[^\n]*?#\d+:\s*/, '')); };
|
||||||
|
var lineText = function (line) { return norm($(line).find('.qbo-line-description-input').val()); };
|
||||||
|
var freeTimes = times.slice(), freeLines = [], pairs = [];
|
||||||
|
lines.forEach(function (line) {
|
||||||
|
var text = lineText(line);
|
||||||
|
var i = text ? freeTimes.findIndex(function (t) { return subject(t) === text; }) : -1;
|
||||||
|
if (i >= 0) { pairs.push({ time: freeTimes[i], line: line }); freeTimes.splice(i, 1); } else { freeLines.push(line); }
|
||||||
|
});
|
||||||
|
while (freeTimes.length && freeLines.length) pairs.push({ time: freeTimes.shift(), line: freeLines.shift() });
|
||||||
|
return { pairs: pairs, extraTimes: freeTimes, extraLines: freeLines };
|
||||||
|
};
|
||||||
|
|
||||||
// Rows go after the last filled line, above the spare empty rows
|
// Rows go after the last filled line, above the spare empty rows
|
||||||
var insertAfterFilled = function ($rows) {
|
var insertAfterFilled = function ($rows) {
|
||||||
var $filled = rows().filter(function () { return !rowIsBlank($(this)); });
|
var $filled = rows().filter(function () { return !rowIsBlank($(this)); });
|
||||||
@@ -642,15 +660,24 @@ $(function () {
|
|||||||
// Kept so the import can be undone before saving (clones keep what was typed)
|
// Kept so the import can be undone before saving (clones keep what was typed)
|
||||||
undoState = { rows: rows().clone(), linked: $('#qbo-linked-estimates').children().clone() };
|
undoState = { rows: rows().clone(), linked: $('#qbo-linked-estimates').children().clone() };
|
||||||
|
|
||||||
// Time goes where the first ticked line was; the ticked lines are removed
|
// Each time entry replaces one ticked line, in that line's place (see pairTimeWithLines). Time left over
|
||||||
|
// goes after the last replaced line; ticked lines left over are removed (ticked means replace).
|
||||||
if (times.length) {
|
if (times.length) {
|
||||||
var $timeRows = $(times.map(function (activity) {
|
var ticked = $('#qbo-import-replace input:checked').map(function () { return $(this).data('row')[0]; }).get();
|
||||||
return makeRow($.extend({}, activity, { time_activity_id: activity.id }))[0];
|
ticked = rows().get().filter(function (row) { return ticked.indexOf(row) >= 0; }); // table order
|
||||||
}));
|
var pairing = pairTimeWithLines(times, ticked);
|
||||||
var $replaced = $('#qbo-import-replace input:checked').map(function () { return $(this).data('row')[0]; });
|
var timeRow = function (activity) { return makeRow($.extend({}, activity, { time_activity_id: activity.id })); };
|
||||||
var $anchor = rows().filter(function () { return $replaced.index(this) >= 0; }).first();
|
var $last = $();
|
||||||
if ($anchor.length) { $anchor.before($timeRows); } else { insertAfterFilled($timeRows); }
|
pairing.pairs.forEach(function (pair) {
|
||||||
$replaced.remove();
|
var $row = timeRow(pair.time);
|
||||||
|
$(pair.line).replaceWith($row);
|
||||||
|
if (!$last.length || $row.index() > $last.index()) $last = $row;
|
||||||
|
});
|
||||||
|
pairing.extraLines.forEach(function (line) { $(line).remove(); });
|
||||||
|
if (pairing.extraTimes.length) {
|
||||||
|
var $extra = $(pairing.extraTimes.map(function (activity) { return timeRow(activity)[0]; }));
|
||||||
|
if ($last.length) { $last.after($extra); } else { insertAfterFilled($extra); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Each estimate's lines go right after the time for the same issue (e.g. lineitems' "Added from:
|
// Each estimate's lines go right after the time for the same issue (e.g. lineitems' "Added from:
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ en:
|
|||||||
text_email_invoice_confirmation: "Email invoice #%{number} 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_from_estimate: "Made from estimate #%{number}. The estimate is closed when the invoice is saved."
|
||||||
text_line_bills_time: "Bills a QuickBooks time activity; saving marks the time as billed"
|
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). The time goes where the first ticked line is."
|
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."
|
||||||
|
|
||||||
# Issues from estimates (moved from redmine_qbo_calendar)
|
# Issues from estimates (moved from redmine_qbo_calendar)
|
||||||
button_create_estimate_issues_submit: "Create issues"
|
button_create_estimate_issues_submit: "Create issues"
|
||||||
|
|||||||
Reference in new issue
Block a user