Skip to content

Commit

Permalink
Sort csv output by date
Browse files Browse the repository at this point in the history
  • Loading branch information
psyraxaus committed Jul 18, 2023
1 parent 73a1414 commit 2185fd4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ const _saveExportedFile = async (db, targetWindow, file, csvFormat, walletSource
AND vouts <> transactions.address`

allTransactionsStr = await _formatTransactionsForExport(targetWindow, nodePayFromAddrs, db, nonConsolSqlQuery, consoldateSqlQuery, consolidateIntTxnsQuery, walletSourceName, addressStr);
dateFormat = 'Timestamp (UTC)';
break;
case "Cointracking":
csvFields = ['Type', 'Buy Amount', 'Buy Currency', 'Sell Amount', 'Sell Currency', 'Fee', 'Fee Currency', 'Exchange', 'Trade-Group', 'Comment', 'Date', "Tx-ID", "Buy Value in Account Currrency", "Sell Value in Account Currency" ];
Expand Down Expand Up @@ -315,6 +316,7 @@ const _saveExportedFile = async (db, targetWindow, file, csvFormat, walletSource
AND vouts <> transactions.address`;

allTransactionsStr = await _formatTransactionsForExport(targetWindow, nodePayFromAddrs, db, nonConsolSqlQuery, consoldateSqlQuery, consolidateIntTxnsQuery, walletSourceName, addressStr);
dateFormat = 'Date';
break;
case "Koinly":
csvFields = ['Date', 'Sent Amount', 'Sent Currency', 'Received Amount', 'Received Currency', 'Fee Amount', 'Fee Currency', 'Net Worth Amount', 'Net Worth Currency', 'Label', 'Description', 'TxHash' ];
Expand Down Expand Up @@ -380,6 +382,7 @@ const _saveExportedFile = async (db, targetWindow, file, csvFormat, walletSource
AND vouts <> transactions.address`;

allTransactionsStr = await _formatTransactionsForExport(targetWindow, nodePayFromAddrs, db, nonConsolSqlQuery, consoldateNodeSqlQuery, consolidateIntTxnsQuery, walletSourceName, addressStr);
dateFormat = 'Date';
break;
case "Accointing":
csvFields = ['transactionType', 'date', 'inBuyAmount', 'inBuyAsset', 'outSellAmount', 'outSellAsset', 'feeAmount (optional)', 'feeAsset (optional)', 'classification (optional)', 'operationId (optional)', 'comments (optional)' ];
Expand Down Expand Up @@ -442,6 +445,7 @@ const _saveExportedFile = async (db, targetWindow, file, csvFormat, walletSource
AND vouts <> transactions.address`;

allTransactionsStr = await _formatTransactionsForExport(targetWindow, nodePayFromAddrs, db, nonConsolSqlQuery, consoldateSqlQuery, consolidateIntTxnsQuery, walletSourceName, addressStr);
dateFormat = 'date';
break;
case "Unformatted":
csvFields = ['Timestamp (UTC)', 'Type','Amount Transacted', 'Currency', 'Fee Amount', 'Fee Currency', 'From Address', 'To', 'Transaction ID', 'Wallet Source', 'Description' ];
Expand Down Expand Up @@ -501,10 +505,26 @@ const _saveExportedFile = async (db, targetWindow, file, csvFormat, walletSource
AND vouts <> transactions.address`;

allTransactionsStr = await _formatTransactionsForExport(targetWindow, nodePayFromAddrs, db, nonConsolSqlQuery, consoldateSqlQuery, consolidateIntTxnsQuery, walletSourceName, addressStr);
dateFormat = 'Time (UTC)';
break;
}

const jsonTransactions = JSON.parse(allTransactionsStr.replace(/\]\[/g, ","));

//Comparer Function
function GetSortOrder(prop) {
return function(a, b) {
if (a[prop] > b[prop]) {
return 1;
} else if (a[prop] < b[prop]) {
return -1;
}
return 0;
}
}

jsonTransactions.sort(GetSortOrder(dateFormat));

const json2csvParser = new Json2csvParser({ csvFields });
const csv = json2csvParser.parse(jsonTransactions);

Expand Down

0 comments on commit 2185fd4

Please sign in to comment.