Replies: 1 comment
-
Hi, Looks like your bank is using a somewhat uncommon way of formatting debit/credit amounts. Are you comfortable writing a bit of javascript code? I'll provide an example below, but you will likely need to adjust it before it works for you. Here's how it works in general: 1. Get the hooks.js fileFirst you'll have to download the hooks.js file and add it ynab-buddy's config folder. 2. Adjust the hooks fileThe hook we're interested in is // {
// Date: '1/1/2020',
// Payee: 'Payee 1',
// Amount: 10,
// Memo: 'Memo 1',
// Other_column: 'Other value',
// }
function onRecord(record) {
// To skip the record, return null
console.log(record);
return record;
} For your use-case, you might adjust function onRecord(record) {
// Get the value of the AMOUNT column
const columnTitle = 'AMOUNT'; // Make sure this matches the name of the column in your CSV file
const amountRaw = record[columnTitle].toString() // We'll get its value as a string
// For debugging purposes, log the amount we found to the console
// This will appear in ynab-buddy's output
console.log(columnTitle, ":", amountRaw);
// To find out if the amount is credit or debit,
// we'll check if the string contains "cr"
const isCredit = amountRaw.toLowerCase().includes('cr');
// Remove all non-numeric characters from the amount to get the actual value
// Note: The code assumes that your CSV uses a period (`.`) as the decimal separator.
// If your bank uses a comma (`,`), you'll need to adjust the `parseFloat` line accordingly to handle this difference.
const amount = parseFloat(amountRaw.replace(/[^0-9.-]+/g,""));
// If the transaction is debit, make the amount negative
if (isCredit) {
record[columnTitle] = amount;
} else {
record[columnTitle] = -amount;
}
// For debugging purposes, log the record to the console
console.log("Changed", amountRaw, "to", amount);
console.log(record);
// Return the modified record
return record;
} Final NoteThe code snippet above is a starting point and may not work perfectly without some adjustments. If you encounter any issues or need help adjusting the script further, just let me know. 🙂 Good luck! |
Beta Was this translation helpful? Give feedback.
-
Hi,
Almost everything is working, for my bank import, but there is one thing I cannot make work.
When I have an amount being imported it is all good if it is a debit on the account, however the way the bank structures their CSV a credit-amount is in the same column as a debit, but postponed by a CR in the same column
As example the table structure of the CSV
DATE PAYEE CURRENCY AMOUNT (In Currency) Amount in local Currency
01/01/24. "DEBIT PAYEE NAME" USD 10 20
01/02/24. "Credit Payee Name" 10 Cr
When importing it is not clear to me how I can reflect if it is Credit or debit on the transaction
Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions