77 lines
1.9 KiB
JavaScript
77 lines
1.9 KiB
JavaScript
const BaseFinancialRepository = require('./BaseFinancialRepository');
|
|
|
|
/**
|
|
* Bank Statement Transaction Repository
|
|
*
|
|
* Manages individual transactions on bank statements.
|
|
*/
|
|
class BankStatementTransactionRepository extends BaseFinancialRepository {
|
|
constructor() {
|
|
super('pg_fn_bank_statement_transactions');
|
|
}
|
|
|
|
/**
|
|
* Find transactions by statement ID
|
|
* @param {string} statementId - Statement ID
|
|
* @returns {Promise<Array>} Array of transactions
|
|
*/
|
|
async findByStatementId(statementId) {
|
|
try {
|
|
return await this.findAll({ bank_statement_id: statementId });
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Find unmatched transactions
|
|
* @param {string} statementId - Statement ID
|
|
* @returns {Promise<Array>} Array of unmatched transactions
|
|
*/
|
|
async findUnmatched(statementId) {
|
|
try {
|
|
return await this.findAll({
|
|
bank_statement_id: statementId,
|
|
is_matched: false
|
|
});
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Match transaction with ledger transaction
|
|
* @param {string} transactionId - Bank statement transaction ID
|
|
* @param {string} ledgerTransactionId - Ledger transaction ID
|
|
* @returns {Promise<Object>} Updated transaction
|
|
*/
|
|
async matchTransaction(transactionId, ledgerTransactionId) {
|
|
try {
|
|
return await this.updateById(transactionId, {
|
|
is_matched: true,
|
|
matched_transaction_id: ledgerTransactionId
|
|
});
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Unmatch transaction
|
|
* @param {string} transactionId - Bank statement transaction ID
|
|
* @returns {Promise<Object>} Updated transaction
|
|
*/
|
|
async unmatchTransaction(transactionId) {
|
|
try {
|
|
return await this.updateById(transactionId, {
|
|
is_matched: false,
|
|
matched_transaction_id: null
|
|
});
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = BankStatementTransactionRepository;
|
|
|