Add structural row edits: flip, insert, split, merge, delete (R.4)
Frontend-only, as planned - /api/recheck already accepts any
transactions array regardless of length. Four extractionStore.js
actions: flipTransactionSign, deleteTransaction,
insertTransactionAfter(index, template?), mergeWithNext.
Two deliberate scope deviations, both for the same reason - don't
build something that doesn't actually apply:
- No separate splitTransaction action. "Split this row" is
insertTransactionAfter(index, {...row}) - duplicates the row's own
current values into a new row right after it rather than guessing
where to divide the amount, same "never silently correct" rule as
everywhere else. The user edits both rows manually afterward.
- No "bulk column fix" (date-format swap) - R.3 already established
this pipeline's dates have no day/month ambiguity left by the time a
transaction reaches this layer, so there's nothing for a bulk date
fix to do.
All four live behind a new "more actions" popover on TransactionRow.vue
rather than more always-visible icons - these are rarer, and two are
destructive. Delete and merge each go through the same ConfirmModal
(danger/busy) pattern every other destructive action in this app
already uses. mergeWithNext concatenates descriptions, sums amounts,
keeps the later row's own balance, and unions source_bbox when both
rows share a page, so "Show on source" still boxes the full merged area
afterward.
A new shared persistAndRecheck() in TransactionRow.vue replaces what
R.3's applySuggestedFix had inline - one function all five of this
component's own mutation paths now call.
Verified: all four actions executed directly against real Pinia plus
the real running backend - flip-then-restore, an insert-then-delete
round trip, and a real merge checked field-by-field (description
concatenation, summed amount, later row's own balance, unioned bbox),
including persisting the resulting shorter array for real and
confirming both /api/recheck and the PocketBase record itself accept
and reflect a 31-row statement that started at 32. measure.py
unaffected (no backend touched).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
54055ca92d
commit
9adf3d8fca
67
CLAUDE.md
67
CLAUDE.md
|
|
@ -30,7 +30,7 @@ to rough effort:
|
|||
| Phase | Contains | Status here |
|
||||
|---|---|---|
|
||||
| **1** | Extraction + 6 checks + Excel export, dual-engine, measurement harness | **In progress — see gaps below** |
|
||||
| 2 | Review screen, suggested-fix patterns, OCR, 2nd+ bank support | OCR routing + working Docling-fallback (`raw_ocr_extract.py`) built and verified against a real multi-page scan 2026-10-11 — one known single-page edge case remains unreliable, see "OCR / scanned statements" below — review screen **in progress, staged R.1-R.5** (see "Review screen"/"R.2"/"R.3" under Key decisions & lessons) — R.1 (source-position capture + the pdf.js highlighting viewer), R.2 (plain-language flags + jump-to-flagged navigation), and R.3 (the suggested-fix engine - debit/credit swap, transposed digits, OCR digit misread) all shipped 2026-10-13; "date format swapped" investigated and found not to apply to this pipeline's own data shape (see R.3's own entry); R.4's structural row edits and R.5's accept/acknowledge + edit log are not started yet |
|
||||
| 2 | Review screen, suggested-fix patterns, OCR, 2nd+ bank support | OCR routing + working Docling-fallback (`raw_ocr_extract.py`) built and verified against a real multi-page scan 2026-10-11 — one known single-page edge case remains unreliable, see "OCR / scanned statements" below — review screen **in progress, staged R.1-R.5** (see "Review screen"/"R.2"/"R.3"/"R.4" under Key decisions & lessons) — R.1 (source-position capture + the pdf.js highlighting viewer), R.2 (plain-language flags + jump-to-flagged navigation), R.3 (the suggested-fix engine - debit/credit swap, transposed digits, OCR digit misread), and R.4 (structural row edits - flip sign, insert, split, merge, delete, behind a "more actions" menu) all shipped 2026-10-13; "date format swapped" and a separate "bulk column fix" both investigated and found not to apply to this pipeline's own data shape (see R.3/R.4's own entries); only R.5 (accept/acknowledge + edit log) remains, not started yet |
|
||||
| 3 | Layout mapper (fingerprinting, versioning, drift detection) | Not started |
|
||||
| 4 | Multi-tenant practice/client accounts, Frappe data model | Not started |
|
||||
| 5 | Free front door, public accuracy page | Not started |
|
||||
|
|
@ -345,6 +345,14 @@ security only, not the full SaaS-shaped doc — and the judgment call on what co
|
|||
re-settles `activeIndex` to keep pointing at the right
|
||||
document after a splice, see "Document delete/rename..."
|
||||
under Key decisions & lessons for the exact rules.
|
||||
`applyCheckResults` also sets `suggestions` as of R.3 (not
|
||||
just `status`/`checks`), re-applied on every recheck so a
|
||||
stale one a manual edit already resolved disappears on its
|
||||
own. `flipTransactionSign`/`deleteTransaction`/
|
||||
`insertTransactionAfter(index, template?)`/`mergeWithNext`
|
||||
(NEW 2026-10-13, review screen R.4 - see that entry under
|
||||
Key decisions & lessons for the full record, including why
|
||||
there's no separate `splitTransaction` action).
|
||||
uiStore.js — `resultsOpen`/`toggleResultsOpen()`/`closeResultsOpen()`
|
||||
(renamed from `resultExpanded`/`toggleResultExpanded` -
|
||||
2026-10-13, now drives TransactionsTable's own Results
|
||||
|
|
@ -1720,6 +1728,57 @@ unaffected. Not machine-verified: the actual click-through - the flag icon, the
|
|||
evidence text, the "Apply fix" button - Claude-in-Chrome still did not connect this
|
||||
session.
|
||||
|
||||
**R.4 — structural row edits, shipped 2026-10-13.** Frontend-only, as planned -
|
||||
`/api/recheck` already accepted any `transactions` array regardless of length, so
|
||||
add/delete/merge/split only needed new `extractionStore.js` actions:
|
||||
`flipTransactionSign`, `deleteTransaction`, `insertTransactionAfter(index, template?)`,
|
||||
`mergeWithNext`.
|
||||
|
||||
**Two deliberate deviations from the original plan, both decided for the same reason -
|
||||
don't build something that doesn't actually apply or doesn't actually need building:**
|
||||
- **No separate `splitTransaction` action.** "Split this row" is
|
||||
`insertTransactionAfter(index, {...row})` - duplicates the row's OWN current values
|
||||
into a new row right after it, rather than guessing where to divide the amount (the
|
||||
same "never silently correct" rule as everywhere else in this app) - the user then
|
||||
edits both rows manually to the real figures. One action, two UI entry points ("Insert
|
||||
row after" passes no template - blank, for a row the extractor genuinely missed;
|
||||
"Split this row" passes the current row's own values as the template).
|
||||
- **No "bulk column fix" (date-format swap).** R.3 already established this pipeline's
|
||||
dates have no day/month ambiguity left by the time a transaction reaches this layer
|
||||
(already normalized to `"DD Mon YYYY"` at extraction time) - there was nothing left
|
||||
for a bulk date fix to do, so it was dropped from scope rather than built as a
|
||||
no-op.
|
||||
|
||||
All four actions live behind a new "more actions" popover menu on `TransactionRow.vue`
|
||||
(`.row-menu`, opened by a new `row-btn.more` icon) rather than more always-visible row
|
||||
icons - these are rarer than edit/flag, and two are destructive. Delete and merge each
|
||||
go through the same `ConfirmModal` (`danger`/`busy`) pattern every other destructive
|
||||
action in this app already uses (move-to-project, document delete, project delete) -
|
||||
flip/insert/split don't need one (additive, or trivially reversible by doing it again).
|
||||
`mergeWithNext` concatenates descriptions, sums amounts, keeps the LATER row's own
|
||||
balance (it reflects the cumulative state after both), and unions `source_bbox` when
|
||||
both rows share a page, so "Show on source" still boxes the full merged area afterward,
|
||||
not just the first row's original position.
|
||||
|
||||
A new shared `persistAndRecheck()` in `TransactionRow.vue` replaces what R.3's
|
||||
`applySuggestedFix` had inline - now one function all five of this component's own
|
||||
mutation paths (suggestion apply + the four structural actions) call, instead of a
|
||||
sixth near-duplicate copy of the same three steps (manual field edits keep using
|
||||
`useRowEditing.js`'s own separate copy, since that composable has its own draft/
|
||||
cancel state these don't need).
|
||||
|
||||
Verified: all four actions executed directly against real Pinia plus the real running
|
||||
backend, not reimplemented - flip-then-restore (status returns to original), an
|
||||
insert-then-delete round trip (status returns to original), and a real merge checked
|
||||
field-by-field (description concatenation, summed amount, the later row's own balance,
|
||||
and the unioned bbox's own top/bottom both confirmed against the two original rows'
|
||||
real values) - including persisting the resulting SHORTER array for real and confirming
|
||||
both `/api/recheck` and the PocketBase record itself correctly accept and reflect a
|
||||
31-row statement that started at 32. `measure.py` re-run, unaffected (no backend
|
||||
touched). Not machine-verified: the actual "more actions" menu, the two confirm
|
||||
modals, and the resulting table row changes - Claude-in-Chrome still did not connect
|
||||
this session.
|
||||
|
||||
**Governing rule: never silently correct or exclude data.** This shows up in several
|
||||
concrete places, not just as an abstract principle:
|
||||
- A row with an unusual status (e.g. HSBC's "Cancelled" wires) stays in the output and is
|
||||
|
|
@ -2101,6 +2160,12 @@ restructure; the behavior itself predates it and is unchanged:
|
|||
note the fix can apply to a DIFFERENT row than the one the panel was opened from
|
||||
(the balance-chain check's own bridging logic means the row that's actually wrong
|
||||
isn't always the one the mismatch is reported against - see R.3's own entry).
|
||||
- Every row also has a "more actions" popover (added 2026-10-13, review screen R.4,
|
||||
`row-btn.more`) with structural edits: flip debit/credit, insert a row after (blank,
|
||||
for one the extractor missed), split this row (duplicates the row's own values into
|
||||
a new one right after - the user divides them manually, nothing is auto-split),
|
||||
merge with the next row, delete this row. Delete and merge each confirm via the same
|
||||
`ConfirmModal` pattern every other destructive action in this app uses.
|
||||
- All numeric displays are comma-formatted (`formatService.js`'s `fmtMoney`/`fmtNum`).
|
||||
- Edits persist to PocketBase (`documentsService.js`'s `saveDocument`/`updateDocument` -
|
||||
as of 2026-10-13, replacing the earlier localStorage-only version entirely, not
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ tr.editing .cell-input:not(:read-only):focus{ outline:none; border-color:var(--b
|
|||
}
|
||||
td.amt .cell-input{ text-align:right; font-family:var(--fm); }
|
||||
|
||||
.row-actions{ width:54px; padding:3px 0 3px 4px !important; white-space:nowrap; }
|
||||
.row-actions{ width:74px; padding:3px 0 3px 4px !important; white-space:nowrap; }
|
||||
.row-btn{
|
||||
background:transparent; border:none; cursor:pointer; padding:4px; border-radius:5px;
|
||||
font-size:13px; line-height:1; color:var(--t4); transition:color .15s, background .15s;
|
||||
|
|
@ -255,6 +255,32 @@ td.amt .cell-input{ text-align:right; font-family:var(--fm); }
|
|||
.row-btn.flag-toggle.active:hover{ background:var(--amber); color:var(--navy-2); }
|
||||
tr.editing td{ background:rgba(37,99,235,.03); }
|
||||
|
||||
/* Structural row edits (review screen R.4) - a small popover menu off
|
||||
the row's own "more actions" icon, not Teleported (unlike the app's
|
||||
modals - see ConfirmModal.vue's own comment on why those need to
|
||||
escape their ancestor's stacking context entirely): this only needs
|
||||
to sit above nearby rows within the SAME table, which plain z-index
|
||||
already handles. Known, accepted limitation: opened on a row flush
|
||||
against the scrollable table's own bottom edge, the menu can get
|
||||
clipped by .table-wrap's overflow-y:auto - not fixed here, revisit if
|
||||
it's ever actually reported as a real problem. */
|
||||
.row-btn.more{ font-size:12px; }
|
||||
.row-menu-wrap{ position:relative; display:inline-block; }
|
||||
.row-menu{
|
||||
position:absolute; top:100%; right:0; z-index:5; width:180px; margin-top:4px;
|
||||
background:var(--navy-2); border:1px solid var(--border); border-radius:8px; box-shadow:var(--shadow-h);
|
||||
padding:4px; display:flex; flex-direction:column; gap:1px;
|
||||
}
|
||||
.row-menu button{
|
||||
display:flex; align-items:center; gap:9px; width:100%; text-align:left; background:transparent; border:none;
|
||||
cursor:pointer; padding:7px 9px; border-radius:5px; font-size:12.5px; color:var(--t2); font-family:var(--fb);
|
||||
}
|
||||
.row-menu button i{ width:14px; text-align:center; color:var(--t4); font-size:11px; flex-shrink:0; }
|
||||
.row-menu button:hover{ background:rgba(37,99,235,.08); color:var(--blue); }
|
||||
.row-menu button:hover i{ color:var(--blue); }
|
||||
.row-menu button.row-menu-danger:hover{ background:var(--red-l); color:var(--red); }
|
||||
.row-menu button.row-menu-danger:hover i{ color:var(--red); }
|
||||
|
||||
/* The review screen's plain-language flag explanation - a second <tr>
|
||||
TransactionRow.vue renders beneath the flagged row itself when its own
|
||||
flag-toggle is active (Vue 3 components can have multiple root nodes,
|
||||
|
|
|
|||
|
|
@ -23,6 +23,14 @@
|
|||
* already uses (useRowEditing.js), so there's one path for "a value on
|
||||
* this row changed," not two that could quietly diverge.
|
||||
*
|
||||
* Also hosts the structural row edits (review screen R.4) behind a
|
||||
* "more actions" menu - flip debit/credit, insert a row (for one the
|
||||
* extractor genuinely missed), split this row (duplicate + divide
|
||||
* manually), merge with the next row, delete this row. Kept behind a
|
||||
* menu rather than more always-visible icons, since these are rarer and
|
||||
* some are destructive - delete/merge go through the same ConfirmModal
|
||||
* pattern every other destructive action in this app already uses.
|
||||
*
|
||||
* Data flow:
|
||||
* index (number) - this row's position in currentResult.transactions
|
||||
* transaction (object) - {date, description, amount, balance, status, source_page, source_bbox}
|
||||
|
|
@ -36,6 +44,7 @@ import { useAutoGrow } from '../composables/useAutoGrow'
|
|||
import { flagsForIndex } from '../services/flagCatalogService'
|
||||
import * as extractionService from '../services/extractionService'
|
||||
import * as documentsService from '../services/documentsService'
|
||||
import ConfirmModal from './ConfirmModal.vue'
|
||||
|
||||
const props = defineProps({
|
||||
index: { type: Number, required: true },
|
||||
|
|
@ -95,21 +104,18 @@ const suggestion = computed(
|
|||
const applyingFix = ref(false)
|
||||
|
||||
/**
|
||||
* Applies the backend-named field change, then persists and rechecks -
|
||||
* the exact same three-step pipeline useRowEditing.js's own saveEdit()
|
||||
* already runs for a manual cell edit, reused directly rather than
|
||||
* duplicated, since accepting a suggestion IS an edit, just one the
|
||||
* engine proposed instead of the user typing it.
|
||||
* Persists currentResult and rechecks - the same round trip
|
||||
* useRowEditing.js's own saveEdit() runs after a manual cell edit.
|
||||
* Shared here since structural edits (below) and the suggested-fix
|
||||
* apply all need the identical sequence after their own store mutation,
|
||||
* rather than five near-duplicate copies of the same three steps.
|
||||
*/
|
||||
async function applySuggestedFix() {
|
||||
if (!suggestion.value || applyingFix.value) return
|
||||
applyingFix.value = true
|
||||
async function persistAndRecheck() {
|
||||
extractionStore.clearError()
|
||||
extractionStore.saveRowEdit(suggestion.value.index, { [suggestion.value.fix.field]: suggestion.value.fix.value })
|
||||
try {
|
||||
await documentsService.updateDocument(extractionStore.activeDocument.pbId, { result: extractionStore.currentResult })
|
||||
} catch (e) {
|
||||
extractionStore.setError('Could not save the fix: ' + e.message)
|
||||
extractionStore.setError('Could not save the change: ' + e.message)
|
||||
}
|
||||
try {
|
||||
const checkResult = await extractionService.recheck(
|
||||
|
|
@ -122,8 +128,78 @@ async function applySuggestedFix() {
|
|||
} catch (e) {
|
||||
extractionStore.setError('Network error: ' + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
/** Accepting a suggestion IS an edit, just one the engine proposed instead of the user typing it - same pipeline either way. */
|
||||
async function applySuggestedFix() {
|
||||
if (!suggestion.value || applyingFix.value) return
|
||||
applyingFix.value = true
|
||||
extractionStore.saveRowEdit(suggestion.value.index, { [suggestion.value.fix.field]: suggestion.value.fix.value })
|
||||
await persistAndRecheck()
|
||||
applyingFix.value = false
|
||||
}
|
||||
|
||||
// ── Structural row edits (review screen R.4) ────────────────────────
|
||||
const showRowMenu = ref(false)
|
||||
const busy = ref(false)
|
||||
function toggleRowMenu() {
|
||||
showRowMenu.value = !showRowMenu.value
|
||||
}
|
||||
function closeRowMenu() {
|
||||
showRowMenu.value = false
|
||||
}
|
||||
|
||||
async function handleFlipSign() {
|
||||
closeRowMenu()
|
||||
busy.value = true
|
||||
extractionStore.flipTransactionSign(props.index)
|
||||
await persistAndRecheck()
|
||||
busy.value = false
|
||||
}
|
||||
|
||||
/** A row the extractor genuinely missed - blank, the user fills in what the source shows. */
|
||||
async function handleInsertAfter() {
|
||||
closeRowMenu()
|
||||
busy.value = true
|
||||
extractionStore.insertTransactionAfter(props.index)
|
||||
await persistAndRecheck()
|
||||
busy.value = false
|
||||
}
|
||||
|
||||
/** One printed line that was really two transactions - duplicates THIS row's own values into a new one right after, rather than guessing how to divide the amount; the user edits both manually to the real figures. */
|
||||
async function handleSplit() {
|
||||
closeRowMenu()
|
||||
busy.value = true
|
||||
extractionStore.insertTransactionAfter(props.index, { ...props.transaction })
|
||||
await persistAndRecheck()
|
||||
busy.value = false
|
||||
}
|
||||
|
||||
const showMergeConfirm = ref(false)
|
||||
function requestMerge() {
|
||||
closeRowMenu()
|
||||
showMergeConfirm.value = true
|
||||
}
|
||||
async function confirmMerge() {
|
||||
busy.value = true
|
||||
extractionStore.mergeWithNext(props.index)
|
||||
await persistAndRecheck()
|
||||
showMergeConfirm.value = false
|
||||
busy.value = false
|
||||
}
|
||||
|
||||
const showDeleteRowConfirm = ref(false)
|
||||
function requestDeleteRow() {
|
||||
closeRowMenu()
|
||||
showDeleteRowConfirm.value = true
|
||||
}
|
||||
async function confirmDeleteRow() {
|
||||
busy.value = true
|
||||
extractionStore.deleteTransaction(props.index)
|
||||
await persistAndRecheck()
|
||||
showDeleteRowConfirm.value = false
|
||||
busy.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -141,6 +217,18 @@ async function applySuggestedFix() {
|
|||
<button class="row-btn save" title="Save this row" @click="saveEdit"><i class="fa-solid fa-check"></i></button>
|
||||
<button class="row-btn cancel" title="Discard changes" @click="cancelEdit"><i class="fa-solid fa-xmark"></i></button>
|
||||
</template>
|
||||
<div v-if="!isEditing" class="row-menu-wrap" @mouseleave="closeRowMenu">
|
||||
<button class="row-btn more" title="More row actions" :disabled="busy" @click="toggleRowMenu">
|
||||
<i class="fa-solid" :class="busy ? 'fa-spinner fa-spin' : 'fa-ellipsis-vertical'"></i>
|
||||
</button>
|
||||
<div v-if="showRowMenu" class="row-menu">
|
||||
<button type="button" @click="handleFlipSign"><i class="fa-solid fa-right-left"></i>Flip debit/credit</button>
|
||||
<button type="button" @click="handleInsertAfter"><i class="fa-solid fa-plus"></i>Insert row after</button>
|
||||
<button type="button" @click="handleSplit"><i class="fa-solid fa-scissors"></i>Split this row</button>
|
||||
<button type="button" @click="requestMerge"><i class="fa-solid fa-arrows-to-dot"></i>Merge with next row</button>
|
||||
<button type="button" class="row-menu-danger" @click="requestDeleteRow"><i class="fa-solid fa-trash"></i>Delete row</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
|
|
@ -215,4 +303,28 @@ async function applySuggestedFix() {
|
|||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<ConfirmModal
|
||||
:visible="showMergeConfirm"
|
||||
title="Merge with next row?"
|
||||
title-icon="fa-arrows-to-dot"
|
||||
:message="`Merge this row into the next one? Descriptions will be combined, amounts summed, and the next row removed. This can't be undone automatically.`"
|
||||
confirm-label="Merge"
|
||||
confirm-icon="fa-arrows-to-dot"
|
||||
:busy="busy"
|
||||
@confirm="confirmMerge"
|
||||
@cancel="showMergeConfirm = false"
|
||||
/>
|
||||
<ConfirmModal
|
||||
:visible="showDeleteRowConfirm"
|
||||
title="Delete this row?"
|
||||
title-icon="fa-trash"
|
||||
message="Delete this transaction row permanently? This can't be undone."
|
||||
confirm-label="Delete"
|
||||
confirm-icon="fa-trash"
|
||||
:danger="true"
|
||||
:busy="busy"
|
||||
@confirm="confirmDeleteRow"
|
||||
@cancel="showDeleteRowConfirm = false"
|
||||
/>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -195,6 +195,86 @@ export const useExtractionStore = defineStore('extraction', {
|
|||
Object.assign(doc.result.transactions[idx], fields)
|
||||
},
|
||||
|
||||
// ── Structural row edits (review screen R.4) ──────────────────────
|
||||
// Each one mutates currentResult.transactions only - TransactionRow.vue
|
||||
// is the one place that calls these, always followed by the same
|
||||
// persist+recheck round trip saveRowEdit's own callers already use
|
||||
// (not duplicated per action - see TransactionRow.vue's own
|
||||
// persistAndRecheck()). /api/recheck already accepts a transactions
|
||||
// array of any length, so none of this needed a new backend endpoint.
|
||||
|
||||
/** "Flip debit/credit" - negates a row's own amount in place. */
|
||||
flipTransactionSign(index) {
|
||||
const doc = this.activeDocument
|
||||
const t = doc?.result.transactions[index]
|
||||
if (t && t.amount !== null && t.amount !== undefined) t.amount = Math.round(-t.amount * 100) / 100
|
||||
},
|
||||
|
||||
/** Removes transaction `index` outright - e.g. an accidental duplicate row. */
|
||||
deleteTransaction(index) {
|
||||
const doc = this.activeDocument
|
||||
if (!doc) return
|
||||
doc.result.transactions.splice(index, 1)
|
||||
this.recomputeFlags()
|
||||
},
|
||||
|
||||
/**
|
||||
* Inserts a new row right after `index` - blank (for a row the
|
||||
* extractor genuinely missed, the user fills in what the source
|
||||
* shows) or seeded from `template` (TransactionRow.vue's own "Split
|
||||
* this row" passes the CURRENT row's own values, so splitting one
|
||||
* printed line into two starts from a duplicate the user then
|
||||
* divides manually, rather than guessing how to split the amount
|
||||
* itself - the spec's own "never silently correct" rule applies
|
||||
* here too, this doesn't invent a split point).
|
||||
*/
|
||||
insertTransactionAfter(index, template = {}) {
|
||||
const doc = this.activeDocument
|
||||
if (!doc) return
|
||||
const txns = doc.result.transactions
|
||||
txns.splice(index + 1, 0, {
|
||||
date: template.date ?? txns[index]?.date ?? '',
|
||||
description: template.description ?? '',
|
||||
amount: template.amount ?? null,
|
||||
balance: template.balance ?? null,
|
||||
status: template.status ?? 'Posted',
|
||||
source_page: template.source_page ?? null,
|
||||
source_bbox: template.source_bbox ?? null,
|
||||
})
|
||||
this.recomputeFlags()
|
||||
},
|
||||
|
||||
/**
|
||||
* Folds transaction `index + 1` into `index` - descriptions
|
||||
* concatenated, amounts summed (one real transaction that printed
|
||||
* as two lines), the LATER row's own balance kept (it reflects the
|
||||
* cumulative state after both), and source_bbox unioned (so "Show
|
||||
* on source" still boxes the full merged area, not just the first
|
||||
* row's own original position) when both rows share a page.
|
||||
*/
|
||||
mergeWithNext(index) {
|
||||
const doc = this.activeDocument
|
||||
if (!doc) return
|
||||
const txns = doc.result.transactions
|
||||
if (index < 0 || index + 1 >= txns.length) return
|
||||
const a = txns[index]
|
||||
const b = txns[index + 1]
|
||||
a.description = [a.description, b.description].filter(Boolean).join(' ')
|
||||
if (a.amount !== null && b.amount !== null) a.amount = Math.round((a.amount + b.amount) * 100) / 100
|
||||
else if (b.amount !== null) a.amount = b.amount
|
||||
if (b.balance !== null && b.balance !== undefined) a.balance = b.balance
|
||||
if (a.source_bbox && b.source_bbox && a.source_page === b.source_page) {
|
||||
a.source_bbox = {
|
||||
x0: Math.min(a.source_bbox.x0, b.source_bbox.x0),
|
||||
x1: Math.max(a.source_bbox.x1, b.source_bbox.x1),
|
||||
top: Math.min(a.source_bbox.top, b.source_bbox.top),
|
||||
bottom: Math.max(a.source_bbox.bottom, b.source_bbox.bottom),
|
||||
}
|
||||
}
|
||||
txns.splice(index + 1, 1)
|
||||
this.recomputeFlags()
|
||||
},
|
||||
|
||||
/** Updates the active document's own `project` after a successful ProjectSidebar.vue "Move to project." */
|
||||
setActiveDocumentProject(projectId) {
|
||||
const doc = this.activeDocument
|
||||
|
|
|
|||
Loading…
Reference in New Issue