mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-14 20:00:33 +00:00
Merge pull request #524 from bigcapitalhq/fix-cashflow-transactions-type
fix: Cashflow transactions types
This commit is contained in:
@@ -38,15 +38,7 @@ export class BankingRulesController extends BaseController {
|
||||
body('conditions.*.value').exists(),
|
||||
|
||||
// Assign
|
||||
body('assign_category')
|
||||
.isString()
|
||||
.isIn([
|
||||
'interest_income',
|
||||
'other_income',
|
||||
'deposit',
|
||||
'expense',
|
||||
'owner_drawings',
|
||||
]),
|
||||
body('assign_category').isString(),
|
||||
body('assign_account_id').isInt({ min: 0 }),
|
||||
body('assign_payee').isString().optional({ nullable: true }),
|
||||
body('assign_memo').isString().optional({ nullable: true }),
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
export const CashflowTransactionTypes = {
|
||||
OtherIncome: 'Other income',
|
||||
OtherExpense: 'Other expense',
|
||||
OwnerDrawing: 'Owner drawing',
|
||||
OwnerContribution: 'Owner contribution',
|
||||
TransferToAccount: 'Transfer to account',
|
||||
TransferFromAccount: 'Transfer from account',
|
||||
};
|
||||
|
||||
export const TransactionTypes = {
|
||||
SaleInvoice: 'Sale invoice',
|
||||
SaleReceipt: 'Sale receipt',
|
||||
PaymentReceive: 'Payment receive',
|
||||
PaymentReceive: 'Payment received',
|
||||
Bill: 'Bill',
|
||||
BillPayment: 'Payment made',
|
||||
VendorOpeningBalance: 'Vendor opening balance',
|
||||
@@ -17,12 +26,10 @@ export const TransactionTypes = {
|
||||
OtherExpense: 'Other expense',
|
||||
OwnerDrawing: 'Owner drawing',
|
||||
InvoiceWriteOff: 'Invoice write-off',
|
||||
|
||||
CreditNote: 'transaction_type.credit_note',
|
||||
VendorCredit: 'transaction_type.vendor_credit',
|
||||
|
||||
RefundCreditNote: 'transaction_type.refund_credit_note',
|
||||
RefundVendorCredit: 'transaction_type.refund_vendor_credit',
|
||||
|
||||
LandedCost: 'transaction_type.landed_cost',
|
||||
CashflowTransaction: CashflowTransactionTypes,
|
||||
};
|
||||
|
||||
@@ -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
|
||||
`),
|
||||
});
|
||||
};
|
||||
@@ -10,6 +10,7 @@ export default class AccountTransaction extends TenantModel {
|
||||
debit: number;
|
||||
exchangeRate: number;
|
||||
taxRate: number;
|
||||
transactionType: string;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
@@ -53,7 +54,7 @@ export default class AccountTransaction extends TenantModel {
|
||||
* @return {string}
|
||||
*/
|
||||
get referenceTypeFormatted() {
|
||||
return getTransactionTypeLabel(this.referenceType);
|
||||
return getTransactionTypeLabel(this.referenceType, this.transactionType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
getCashflowTransactionType,
|
||||
} from '@/services/Cashflow/utils';
|
||||
import { CASHFLOW_DIRECTION } from '@/services/Cashflow/constants';
|
||||
import { getTransactionTypeLabel } from '@/utils/transactions-types';
|
||||
import { getCashflowTransactionFormattedType } from '@/utils/transactions-types';
|
||||
|
||||
export default class CashflowTransaction extends TenantModel {
|
||||
transactionType: string;
|
||||
@@ -64,7 +64,7 @@ export default class CashflowTransaction extends TenantModel {
|
||||
* @returns {string}
|
||||
*/
|
||||
get transactionTypeFormatted() {
|
||||
return getTransactionTypeLabel(this.transactionType);
|
||||
return getCashflowTransactionFormattedType(this.transactionType);
|
||||
}
|
||||
|
||||
get typeMeta() {
|
||||
@@ -159,8 +159,7 @@ export default class CashflowTransaction extends TenantModel {
|
||||
to: 'accounts_transactions.referenceId',
|
||||
},
|
||||
filter(builder) {
|
||||
const referenceTypes = getCashflowAccountTransactionsTypes();
|
||||
builder.whereIn('reference_type', referenceTypes);
|
||||
builder.where('reference_type', 'CashflowTransaction');
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { upperFirst, camelCase } from 'lodash';
|
||||
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||
import { getTransactionTypeLabel } from '@/utils/transactions-types';
|
||||
import { getCashflowTransactionFormattedType } from '@/utils/transactions-types';
|
||||
|
||||
export class GetBankRulesTransformer extends Transformer {
|
||||
/**
|
||||
@@ -29,8 +28,7 @@ export class GetBankRulesTransformer extends Transformer {
|
||||
* @returns {string}
|
||||
*/
|
||||
protected assignCategoryFormatted(bankRule: any) {
|
||||
const assignCategory = upperFirst(camelCase(bankRule.assignCategory));
|
||||
return getTransactionTypeLabel(assignCategory);
|
||||
return getCashflowTransactionFormattedType(bankRule.assignCategory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user