Skip to content

Commit

Permalink
fix: etl buy transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Zorkin committed Jan 14, 2025
1 parent 994ce63 commit 06e08dc
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions etl/nifi_scripts/transfer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def SOURCE_QUERY = """
ct.date_of_written_agreement AS agreement_date,
ct.trade_effective_date AS transaction_effective_date,
ct.fair_market_value_per_credit AS price_per_unit,
ctt.the_type as the_type,
ct.number_of_credits AS quantity,
ct.create_user_id as create_user,
ct.update_user_id as update_user,
Expand Down Expand Up @@ -146,6 +147,7 @@ def SOURCE_QUERY = """
ctc.category,
cts.status,
ctzr.description,
ctt.the_type,
internal_comment.role_names;
"""

Expand Down Expand Up @@ -354,15 +356,27 @@ def processTransactions(String currentStatus, ResultSet rs, PreparedStatement st
def fromTransactionId = null
def toTransactionId = null

def transferType = rs.getString('the_type')
def isBuy = (transferType == 'Buy')

switch (currentStatus) {
case ['Draft', 'Deleted', 'Refused', 'Declined', 'Rescinded']:
break
case ['Sent', 'Submitted', 'Recommended']:
fromTransactionId = insertTransaction(stmt, rs, 'Reserved', rs.getInt('from_organization_id'), true)
if (isBuy) {
fromTransactionId = insertTransaction(stmt, rs, 'Reserved', rs.getInt('from_organization_id'), false)
} else {
fromTransactionId = insertTransaction(stmt, rs, 'Reserved', rs.getInt('from_organization_id'), true)
}
break
case 'Recorded':
fromTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('from_organization_id'), true)
toTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('to_organization_id'), false)
if (isBuy) {
fromTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('from_organization_id'), false)
toTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('to_organization_id'), true)
} else {
fromTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('from_organization_id'), true)
toTransactionId = insertTransaction(stmt, rs, 'Adjustment', rs.getInt('to_organization_id'), false)
}
break
}

Expand Down

0 comments on commit 06e08dc

Please sign in to comment.