-
Notifications
You must be signed in to change notification settings - Fork 1
Handling source files that have an amount field vs files with separate credit & debit fields
klequis edited this page Oct 3, 2020
·
12 revisions
description | debit | credit |
---|---|---|
Grocery Store | 30 | |
Store Refund | -50 |
- Determine if the row is a credit or debit by checking the values in both fields
- if credit === (0 || '') it is a debit
- if debit === (0 || '') it is a credit
- Return the value from credit or debit that is not (0 || '')
if fidleName === 'amount'
if hasCreditDebitField === true
creditValue = // get from doc using colMap
debitValue = // get from doc using colMap
if creditValue === (0 || '') && debitValue === (0 || '')
// That's an error. Not sure how that would impact rest of data
// transformation so throw an error
if creditValue !== (0 || '') && debitValue !== (0 || '')
// Also error as above
let finalValue
// is it a debit
if creditValue === (0 || '') && debitValue !== (0 || '')
// it is a debit
if debitValue > 0
debitValue = debitValue * -1
finalValue = debitValue
// is it a credit
if debitValue === (0 || '') && creditValue !== (0 || '')
if creditValue < 0
creditValue = creditValue * -1
finalValue = creditValue
description | debit | credit |
---|---|---|
Grocery Store | 30 | |
Store Refund | -50 |
The following must happen to move this data to the transactions collection debit
- A debit must be made negative before put into the debit column
- A zero must be placed in the credit column
credit
- A credit must be made positive before put into the credit column
- A zero must be placed in the debit column
Logic In this case credit and debit have their own columns so we don't need to know if the value is a credit or debit and therefore the fieldValue will be the value as per fieldName. However, two other considerations come in:
- we must take into consideration the value of account.reverseSignAmount.
- if an empty string is passed it zero should be retuned
// if receive empty string return 0
if (R.isEmpty(fieldValue) {
return 0
}
// reverse sign or don't
return reverseSignAmount ? fieldValue * -1 : fieldValue
Note: I have not yet seen a case that had separate debit & credit columns where debits were negative and credits were positive.
description | amount |
---|---|
Grocery Store | -30 |
Store Refund | 50 |
The following must happen
If a negative value in amount column
- The value goes in transactions.debit and a zero is put in transactions.credit
If a positive value in the amount column
- The value goes in the credit column and a zero goes in transactions.debit
logic
// In this case we need to make different decisions for credit and debit. If the
if (fieldName === 'credit') {
// fieldName='credit' but fieldValue is negative, fieldValue is not a credit so return 0.
return fieldValue > 0 ? fieldValue : 0
}
if (fieldName = 'debit' {
// if fieldName='debit' but findValue is positive, fieldValue is not a debit so return 0.
return fieldValue < 0 ? fieldValue : 0
}
Note: I have not seen a case that had a single amount field and credits were negative and debits positive.