74 lines
3.4 KiB
JavaScript
74 lines
3.4 KiB
JavaScript
/// <reference path="../pb_data/types.d.ts" />
|
|
|
|
/**
|
|
* Foundation for accounting-software export (QFX/OFX to start, Xero's
|
|
* own formats later - see CLAUDE.md's "QFX export" entry) - a bank
|
|
* account's own identifying info (routing number, account identifier,
|
|
* account type) that QBO/Xero need in every exported file's own
|
|
* <BANKACCTFROM> block, but which this app's own extraction pipeline
|
|
* never reads off a statement itself.
|
|
*
|
|
* A real, explicit design goal: a user doing several extractions a
|
|
* month from the SAME real-world account should never have to retype
|
|
* this. `bankAccountProfiles` is a reusable, project-scoped profile
|
|
* (same pattern `categorizationRules` already established) - created
|
|
* once per real account, then just SELECTED on each export going
|
|
* forward (see `documents.bankAccountProfile` below, which remembers
|
|
* which profile a given document last used). Project-scoped, not
|
|
* fingerprint/shared like layoutMappings - a bank account profile has
|
|
* no cross-user "two independent confirmations" promotion scenario,
|
|
* the same reasoning categorizationRules' own migration already gives.
|
|
*
|
|
* `accountId` is deliberately NOT labeled or treated as "the real
|
|
* account number" - QBO/Xero only need this to be a STABLE, UNIQUE
|
|
* string per account for matching/dedup, not the literal banking
|
|
* number. The field is free text so a user can use a last-4-digits
|
|
* form or an internal reference code instead of real account PII,
|
|
* without this schema forcing either choice - see
|
|
* bankAccountProfilesService.js's own UI copy for the actual guidance
|
|
* given at creation time.
|
|
*/
|
|
migrate((app) => {
|
|
let users = app.findCollectionByNameOrId('users')
|
|
let projects = app.findCollectionByNameOrId('projects')
|
|
let documents = app.findCollectionByNameOrId('documents')
|
|
|
|
let bankAccountProfiles = new Collection({
|
|
type: 'base',
|
|
name: 'bankAccountProfiles',
|
|
listRule: 'owner = @request.auth.id',
|
|
viewRule: 'owner = @request.auth.id',
|
|
createRule: 'owner = @request.auth.id',
|
|
updateRule: 'owner = @request.auth.id',
|
|
deleteRule: 'owner = @request.auth.id',
|
|
fields: [
|
|
{ type: 'relation', name: 'owner', collectionId: users.id, required: true, maxSelect: 1 },
|
|
{ type: 'relation', name: 'project', collectionId: projects.id, required: true, maxSelect: 1 },
|
|
{ type: 'text', name: 'name', required: true },
|
|
// OFX BANKID - the bank's own routing/transit number.
|
|
{ type: 'text', name: 'bankId', required: true },
|
|
// OFX ACCTID - see this migration's own docstring above for why
|
|
// this is deliberately NOT required to be the real account number.
|
|
{ type: 'text', name: 'accountId', required: true },
|
|
// OFX ACCTTYPE's own fixed vocabulary.
|
|
{
|
|
type: 'select', name: 'accountType', maxSelect: 1, required: true,
|
|
values: ['CHECKING', 'SAVINGS', 'MONEYMRKT', 'CREDITLINE'],
|
|
},
|
|
{ type: 'autodate', name: 'created', onCreate: true },
|
|
{ type: 'autodate', name: 'updated', onCreate: true, onUpdate: true },
|
|
],
|
|
})
|
|
app.save(bankAccountProfiles)
|
|
|
|
documents.fields.add(new Field({
|
|
type: 'relation', name: 'bankAccountProfile', collectionId: bankAccountProfiles.id, maxSelect: 1,
|
|
}))
|
|
app.save(documents)
|
|
}, (app) => {
|
|
let documents = app.findCollectionByNameOrId('documents')
|
|
documents.fields.removeByName('bankAccountProfile')
|
|
app.save(documents)
|
|
try { app.delete(app.findCollectionByNameOrId('bankAccountProfiles')) } catch (e) {}
|
|
})
|