From a73c0d3cc2689bb7b1158196a0d83d1badbf8fdd Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Wed, 3 Jul 2024 15:30:26 +0300 Subject: [PATCH] Consider ledger entries with platform payments as a deposit for taxes --- workers/loc.api/sync/movements/index.js | 31 ++++++++++++------- .../sync/transaction.tax.report/index.js | 6 ++-- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/workers/loc.api/sync/movements/index.js b/workers/loc.api/sync/movements/index.js index 8ab02648..6f9ca590 100644 --- a/workers/loc.api/sync/movements/index.js +++ b/workers/loc.api/sync/movements/index.js @@ -43,7 +43,8 @@ class Movements { isExcludePrivate = true, isWithdrawals = false, isDeposits = false, - isMovementsWithoutSATransferLedgers = false + isMovementsWithoutSATransferLedgers = false, + areExtraPaymentsIncluded = false } = params ?? {} const user = await this.authenticator @@ -96,7 +97,8 @@ class Movements { sort: ledgersOrder, isWithdrawals, isDeposits, - isExcludePrivate + isExcludePrivate, + areExtraPaymentsIncluded }) if (isMovementsWithoutSATransferLedgers) { @@ -229,7 +231,8 @@ class Movements { exclude = ['user_id'], isExcludePrivate = true, isWithdrawals = false, - isDeposits = false + isDeposits = false, + areExtraPaymentsIncluded = false } = params ?? {} const withdrawalsFilter = isWithdrawals @@ -244,19 +247,25 @@ class Movements { depositsFilter, _filter ) + const extraPaymentsFilter = areExtraPaymentsIncluded + ? { + $or: { + $eq: { + _isInvoicePayOrder: 1, + _isAirdropOnWallet: 1, + _isMarginFundingPayment: 1, + _isAffiliateRebate: 1, + _isStakingPayments: 1 + } + } + } + : { $or: { $eq: { _isInvoicePayOrder: 1 } } } return this.dao.getElemsInCollBy( this.ALLOWED_COLLS.LEDGERS, { subQuery: { - filter: { - $or: { - $eq: { - _isInvoicePayOrder: 1, - _isAirdropOnWallet: 1 - } - } - } + filter: extraPaymentsFilter }, filter: { $lte: { mts: end }, diff --git a/workers/loc.api/sync/transaction.tax.report/index.js b/workers/loc.api/sync/transaction.tax.report/index.js index a45d7495..ebc1db96 100644 --- a/workers/loc.api/sync/transaction.tax.report/index.js +++ b/workers/loc.api/sync/transaction.tax.report/index.js @@ -183,14 +183,16 @@ class TransactionTaxReport { start, end, isWithdrawals: true, - isExcludePrivate: false + isExcludePrivate: false, + areExtraPaymentsIncluded: true }) const depositsPromise = this.movements.getMovements({ auth: user, start, end, isDeposits: true, - isExcludePrivate: false + isExcludePrivate: false, + areExtraPaymentsIncluded: true }) const [