From b3bdb097095c1d43fa426ae71c078c443e6dc4a4 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Mon, 27 May 2024 07:34:53 +0300 Subject: [PATCH] Implement main flow for lookup trx with required start-end --- .../sync/transaction.tax.report/index.js | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/workers/loc.api/sync/transaction.tax.report/index.js b/workers/loc.api/sync/transaction.tax.report/index.js index 93ddde25..e6b86268 100644 --- a/workers/loc.api/sync/transaction.tax.report/index.js +++ b/workers/loc.api/sync/transaction.tax.report/index.js @@ -1,9 +1,12 @@ 'use strict' +const { pushLargeArr } = require('../../helpers/utils') + const { TRX_TAX_STRATEGIES, remapTrades, - remapMovements + remapMovements, + lookUpTrades } = require('./helpers') const { decorateInjectable } = require('../../di/utils') @@ -102,8 +105,39 @@ class TransactionTaxReport { }) : { trxs: [] } - // TODO: - return [] + const isBackIterativeSaleLookUp = isFIFO && !isLIFO + const isBackIterativeBuyLookUp = isFIFO && !isLIFO + + const { buyTradesWithUnrealizedProfit } = await lookUpTrades( + trxsForPrevPeriod, + { + isBackIterativeSaleLookUp, + isBackIterativeBuyLookUp, + isBuyTradesWithUnrealizedProfitRequired: true, + isNotGainOrLossRequired: true + } + ) + + pushLargeArr(trxsForCurrPeriod, buyTradesWithUnrealizedProfit) + pushLargeArr( + trxsForConvToUsd, + buyTradesWithUnrealizedProfit + .filter((trx) => ( + !Number.isFinite(trx?.firstSymbPriceUsd) || + !Number.isFinite(trx?.lastSymbPriceUsd) + )) + ) + await this.#convertCurrencies(trxsForConvToUsd) + + const { saleTradesWithRealizedProfit } = await lookUpTrades( + trxsForCurrPeriod, + { + isBackIterativeSaleLookUp, + isBackIterativeBuyLookUp + } + ) + + return saleTradesWithRealizedProfit } async #getTrxs (params) { @@ -163,6 +197,9 @@ class TransactionTaxReport { } } + // TODO: + async #convertCurrencies (trxs, opts) {} + async #getTrades ({ user, start,