-
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #524 from bigcapitalhq/fix-cashflow-transactions-type
fix: Cashflow transactions types
- Loading branch information
Showing
7 changed files
with
113 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...se/migrations/20240709122347_move_cashflow_transaction_type_to_transaction_type_column.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
exports.up = function (knex) { | ||
return knex('accounts_transactions') | ||
.whereIn('referenceType', [ | ||
'OtherIncome', | ||
'OtherExpense', | ||
'OwnerDrawing', | ||
'OwnerContribution', | ||
'TransferToAccount', | ||
'TransferFromAccount', | ||
]) | ||
.update({ | ||
transactionType: knex.raw(` | ||
CASE | ||
WHEN REFERENCE_TYPE = 'OtherIncome' THEN 'OtherIncome' | ||
WHEN REFERENCE_TYPE = 'OtherExpense' THEN 'OtherExpense' | ||
WHEN REFERENCE_TYPE = 'OwnerDrawing' THEN 'OwnerDrawing' | ||
WHEN REFERENCE_TYPE = 'OwnerContribution' THEN 'OwnerContribution' | ||
WHEN REFERENCE_TYPE = 'TransferToAccount' THEN 'TransferToAccount' | ||
WHEN REFERENCE_TYPE = 'TransferFromAccount' THEN 'TransferFromAccount' | ||
END | ||
`), | ||
referenceType: knex.raw(` | ||
CASE | ||
WHEN REFERENCE_TYPE IN ('OtherIncome', 'OtherExpense', 'OwnerDrawing', 'OwnerContribution', 'TransferToAccount', 'TransferFromAccount') THEN 'CashflowTransaction' | ||
ELSE REFERENCE_TYPE | ||
END | ||
`), | ||
}); | ||
}; | ||
|
||
exports.down = function (knex) { | ||
return knex('accounts_transactions') | ||
.whereIn('transactionType', [ | ||
'OtherIncome', | ||
'OtherExpense', | ||
'OwnerDrawing', | ||
'OwnerContribution', | ||
'TransferToAccount', | ||
'TransferFromAccount', | ||
]) | ||
.update({ | ||
referenceType: knex.raw(` | ||
CASE | ||
WHEN TRANSACTION_TYPE = 'OtherIncome' THEN 'OtherIncome' | ||
WHEN TRANSACTION_TYPE = 'OtherExpense' THEN 'OtherExpense' | ||
WHEN TRANSACTION_TYPE = 'OwnerDrawing' THEN 'OwnerDrawing' | ||
WHEN TRANSACTION_TYPE = 'OwnerContribution' THEN 'OwnerContribution' | ||
WHEN TRANSACTION_TYPE = 'TransferToAccount' THEN 'TransferToAccount' | ||
WHEN TRANSACTION_TYPE = 'TransferFromAccount' THEN 'TransferFromAccount' | ||
ELSE REFERENCE_TYPE | ||
END | ||
`), | ||
transactionType: knex.raw(` | ||
CASE | ||
WHEN TRANSACTION_TYPE IN ('OtherIncome', 'OtherExpense', 'OwnerDrawing', 'OwnerContribution', 'TransferToAccount', 'TransferFromAccount') THEN NULL | ||
ELSE TRANSACTION_TYPE | ||
END | ||
`), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,36 @@ | ||
import { TransactionTypes } from '@/data/TransactionTypes'; | ||
import { isObject, upperFirst, camelCase } from 'lodash'; | ||
import { | ||
TransactionTypes, | ||
CashflowTransactionTypes, | ||
} from '@/data/TransactionTypes'; | ||
|
||
export const getTransactionTypeLabel = (transactionType: string) => { | ||
return TransactionTypes[transactionType]; | ||
/** | ||
* Retrieves the formatted type of account transaction. | ||
* @param {string} referenceType | ||
* @param {string} transactionType | ||
* @returns {string} | ||
*/ | ||
export const getTransactionTypeLabel = ( | ||
referenceType: string, | ||
transactionType?: string | ||
) => { | ||
const _referenceType = upperFirst(camelCase(referenceType)); | ||
const _transactionType = upperFirst(camelCase(transactionType)); | ||
|
||
return isObject(TransactionTypes[_referenceType]) | ||
? TransactionTypes[_referenceType][_transactionType] | ||
: TransactionTypes[_referenceType] || null; | ||
}; | ||
|
||
/** | ||
* Retrieves the formatted type of cashflow transaction. | ||
* @param {string} transactionType | ||
* @returns {string¿} | ||
*/ | ||
export const getCashflowTransactionFormattedType = ( | ||
transactionType: string | ||
) => { | ||
const _transactionType = upperFirst(camelCase(transactionType)); | ||
|
||
return CashflowTransactionTypes[_transactionType] || null; | ||
}; |