A local-first personal finance app
add historical transfers applier
winklevos175cf80927d4
diff --git a/docs/Accounts/transfers.md b/docs/Accounts/transfers.mdindex f441c3cc3b..ccccbe1adb 100644--- a/docs/Accounts/transfers.md+++ b/docs/Accounts/transfers.md@@ -10,7 +10,9 @@ When you create a transfer in Actual, those two transactions are linked and updaIn the **Payee** field of a transaction, choose the account in the dropdown you want to transfer to/from. You can press **Make Transfer** if you want to just see a list of accounts and hide other payees.+:::cautionA transaction in the corresponding account will automatically be created.+:::If you are importing files, it is recommended to import into a single account and create the transfer first, and then import the second account. This way the transaction in the second account is automatically reconciled to the transfer transaction. If you imported to both accounts first, creating the transfer would create a duplicate transaction.diff --git a/docs/Getting-Started/migration/bulk-migration-updates/modify-transfers.md b/docs/Getting-Started/migration/bulk-migration-updates/modify-transfers.mdnew file mode 100644index 0000000000..96c43066ac--- /dev/null+++ b/docs/Getting-Started/migration/bulk-migration-updates/modify-transfers.md@@ -0,0 +1,176 @@+---+title: 'Identify and apply transfers historically'+---++These SQL scripts modify transactions as to apply [transfers](docs/Accounts/transfers.md) historically over migrated data without duplicating transactions. This is useful when you have migrated multiple accounts.++:::caution+Before executing any actions, make sure you have a complete [backup](docs\Backup-Restore\Backups.md).+:::++:::note+This process will only apply when the below conditions are met++- The two transactions are related to different accounts+- The amounts are exactly the same but inverted e.g. `-1.00` and `1.00`+- The transaction dates are within 3 days of each other++- The match only occurs once. This means transfers of equal value following the pattern below will not be applied.++ `Account A` -> `Account B` -> `Account A/C`++ As we cannot reliable tell the order of the transfers.+:::++## How To++1. Create a second copy of the backup+2. Extract the backup+3. Open the `db.sqlite` file with your preferred tool [sqlite3 cli](https://www.sqlite.org/cli.html), [heidiSQL](https://www.heidisql.com/), ect+4. Run the below query to first view the impacted transactions++ ``` sql+ SELECT t.id,+ acct,+ a.name,+ amount,+ t.date,+ imported_description,+ t.description,+ t.transferred_id,+ (+ SELECT id+ FROM transactions s+ WHERE s.tombstone = 0+ AND s.id != t.id+ AND starting_balance_flag = 0+ AND s.amount = (t.amount * -1)+ AND s.acct != t.acct+ AND (+ (+ s.date >= t.date+ AND s.date <= (t.date + 3)+ )+ OR (+ s.date <= t.date+ AND s.date >= (t.date -3)+ )+ )+ ) AS "transferred_id_new",+ (+ SELECT pa.id+ FROM transactions s+ LEFT JOIN payees pa ON s.acct = pa.transfer_acct+ WHERE s.tombstone = 0+ AND s.id != t.id+ AND starting_balance_flag = 0+ AND s.amount = (t.amount * -1)+ AND s.acct != t.acct+ AND (+ (+ s.date >= t.date+ AND s.date <= (t.date + 3)+ )+ OR (+ s.date <= t.date+ AND s.date >= (t.date -3)+ )+ )+ ) AS "description_new"+ FROM transactions t+ LEFT JOIN accounts a ON t.acct = a.id+ LEFT JOIN payees p ON t.description = p.id+ LEFT JOIN accounts ta ON p.transfer_acct = ta.id+ WHERE t.tombstone = 0+ AND starting_balance_flag = 0+ AND (+ SELECT COUNT(*)+ FROM transactions s+ WHERE s.tombstone = 0+ AND s.id != t.id+ AND starting_balance_flag = 0+ AND s.amount = (t.amount * -1)+ AND s.acct != t.acct+ AND (+ (+ s.date >= t.date+ AND s.date <= (t.date + 3)+ )+ OR (+ s.date <= t.date+ AND s.date >= (t.date -3)+ )+ )+ ) = 1+ ORDER BY DATE DESC;+ ```++5. Run the below query to update the transactions++ ``` sql+ UPDATE transactions+ SET transferred_id = (+ SELECT s.id+ FROM transactions s+ WHERE s.tombstone = 0+ AND s.id != transactions.id+ AND starting_balance_flag = 0+ AND s.amount = (transactions.amount * -1)+ AND s.acct != transactions.acct+ AND (+ (+ s.date >= transactions.date+ AND s.date <= (transactions.date + 3)+ )+ OR (+ s.date <= transactions.date+ AND s.date >= (transactions.date -3)+ )+ )+ ),+ description = (+ SELECT pa.id+ FROM transactions s+ LEFT JOIN payees pa ON s.acct = pa.transfer_acct+ WHERE s.tombstone = 0+ AND s.id != transactions.id+ AND starting_balance_flag = 0+ AND s.amount = (transactions.amount * -1)+ AND s.acct != transactions.acct+ AND (+ (+ s.date >= transactions.date+ AND s.date <= (transactions.date + 3)+ )+ OR (+ s.date <= transactions.date+ AND s.date >= (transactions.date -3)+ )+ )+ )+ WHERE tombstone = 0+ AND starting_balance_flag = 0+ AND (+ SELECT COUNT(*)+ FROM transactions s+ WHERE s.tombstone = 0+ AND s.id != transactions.id+ AND starting_balance_flag = 0+ AND s.amount = (transactions.amount * -1)+ AND s.acct != transactions.acct+ AND (+ (+ s.date >= transactions.date+ AND s.date <= (transactions.date + 3)+ )+ OR (+ s.date <= transactions.date+ AND s.date >= (transactions.date -3)+ )+ )+ ) = 1;+ ```++6. Zip the `db.sqlite` file with the original `metadata.json` file+7. Follow the [restore](docs\Backup-Restore\Restore.md) process to apply these into your Actual Server instance+8. Verify your balances are correct and you see the correct transactions marked as transfers!diff --git a/sidebars.js b/sidebars.jsindex 60e5113f7d..ac788c8fbe 100644--- a/sidebars.js+++ b/sidebars.js@@ -112,12 +112,21 @@ const sidebars = {{type: 'category',label: 'Migrating From Other Apps',- items: [+ items: ['Getting-Started/migration/ynab4',- unavailable('nYNAB'),+ unavailable('nYNAB')]- },+ },'Getting-Started/migration/simple-sync',+ {+ type: 'category',+ label: 'Advanced Migration Actions',+ items: [+ 'Getting-Started/migration/bulk-migration-updates/modify-transfers'+ ]+ },++]},],@@ -142,7 +151,7 @@ const sidebars = {'Budgeting/rules/rules-custom',],},- 'Budgeting/schedules',+ 'Budgeting/schedules','Budgeting/returnsandreimbursements','Budgeting/creditcards','Budgeting/jointaccounts',@@ -160,12 +169,12 @@ const sidebars = {{type: 'category',label: 'Transactions',- collapsed: true,+ collapsed: true,items: ['Accounts/Transactions/importing-trans','Accounts/Transactions/bulk-editing-transactions',],- },+ },unavailable('Connecting Your Bank'),'Accounts/payees','Accounts/transfers',@@ -204,7 +213,7 @@ const sidebars = {type: 'link',label: 'Issue Board',href: 'https://github.com/orgs/actualbudget/projects/1',- },+ },'Developers/project-layout','Developers/releasing','Developers/Building-Windows',