Skip to content

Commit

Permalink
feat(Transactions): add accounting category to CSV (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree authored Jan 18, 2024
1 parent 21d7032 commit 6fe6897
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/server/controllers/account-transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export const transactionsFragment = gqlV2/* GraphQL */ `
payoutMethod {
type
}
accountingCategory @include(if: $hasAccountingCategoryField) {
id
code
name
}
}
isRefund
isRefunded
Expand Down Expand Up @@ -153,6 +158,7 @@ const transactionsQuery = gqlV2/* GraphQL */ `
$fetchPaymentProcessorFee: Boolean
$fetchTax: Boolean
$fullDescription: Boolean
$hasAccountingCategoryField: Boolean!
) {
transactions(
includeDebts: true
Expand Down Expand Up @@ -196,6 +202,7 @@ const hostTransactionsQuery = gqlV2/* GraphQL */ `
$fetchTax: Boolean
$fullDescription: Boolean
$account: [AccountReferenceInput!]
$hasAccountingCategoryField: Boolean!
) {
transactions(
includeDebts: true
Expand Down Expand Up @@ -241,7 +248,16 @@ const formatAccountName = (account) => {
}
};

const formatAccountingCategory = (accountingCategory) => {
if (!accountingCategory) {
return '';
} else {
return `${accountingCategory.code} - ${accountingCategory.name}`;
}
};

const csvMapping = {
accountingCategory: (t) => formatAccountingCategory(get(t, 'expense.accountingCategory')),
date: (t) => moment.utc(t.createdAt).format('YYYY-MM-DD'),
datetime: (t) => moment.utc(t.createdAt).format('YYYY-MM-DDTHH:mm:ss'),
id: 'id',
Expand Down Expand Up @@ -512,6 +528,9 @@ const accountTransactions = async (req, res) => {

const fetchAll = variables.offset ? false : parseToBooleanDefaultFalse(req.query.fetchAll);

// Add fields info to the query, to prevent fetching what's not needed
variables.hasAccountingCategoryField = fields.includes('accountingCategory');

try {
// Forward Api Key or Authorization header
const headers = {};
Expand Down

0 comments on commit 6fe6897

Please sign in to comment.