Fix transaction deduplication
Address the issue where duplicate transactions are still being created after the previous fix.
This commit is contained in:
@@ -107,16 +107,19 @@ const BatchTransactionForm: React.FC<BatchTransactionFormProps> = ({ onClose, on
|
||||
const lines = value.trim().split('\n');
|
||||
const pasteTransactionMap = new Map<string, ParsedTransaction>();
|
||||
|
||||
console.log('=== STEP 1: Processing pasted lines ===');
|
||||
// STEP 1: First combine all identical transactions within the pasted data
|
||||
lines.forEach((line, index) => {
|
||||
const parsed = parseTransactionLine(line);
|
||||
if (parsed) {
|
||||
const transactionKey = createTransactionKey(parsed);
|
||||
console.log(`Line ${index + 1}: Key = ${transactionKey}`);
|
||||
|
||||
// Check if this exact transaction already exists in our paste data
|
||||
if (pasteTransactionMap.has(transactionKey)) {
|
||||
// Merge with existing transaction in paste
|
||||
const existing = pasteTransactionMap.get(transactionKey)!;
|
||||
console.log(`Merging duplicate: adding ${parsed.quantity} to existing ${existing.quantity}`);
|
||||
existing.quantity += parsed.quantity;
|
||||
existing.totalPrice += Math.abs(parsed.totalAmount);
|
||||
} else {
|
||||
@@ -133,25 +136,31 @@ const BatchTransactionForm: React.FC<BatchTransactionFormProps> = ({ onClose, on
|
||||
wallet: parsed.wallet
|
||||
};
|
||||
pasteTransactionMap.set(transactionKey, newTransaction);
|
||||
console.log(`Added new transaction: ${parsed.itemName} x${parsed.quantity}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
console.log('=== STEP 2: Checking against existing transactions ===');
|
||||
// STEP 2: Now check combined transactions against existing job transactions
|
||||
const existingTransactionKeys = new Set<string>();
|
||||
eligibleJobs.forEach(job => {
|
||||
job.income.forEach(tx => {
|
||||
const key = createTransactionKeyFromRecord(tx);
|
||||
existingTransactionKeys.add(key);
|
||||
console.log(`Existing transaction key: ${key}`);
|
||||
});
|
||||
});
|
||||
|
||||
let duplicates = 0;
|
||||
console.log('=== STEP 3: Marking duplicates and assigning jobs ===');
|
||||
// Update each combined transaction with duplicate status and job assignment
|
||||
pasteTransactionMap.forEach((transaction, key) => {
|
||||
const isDuplicate = existingTransactionKeys.has(key);
|
||||
transaction.isDuplicate = isDuplicate;
|
||||
|
||||
console.log(`Transaction ${transaction.itemName}: isDuplicate = ${isDuplicate}`);
|
||||
|
||||
if (isDuplicate) {
|
||||
duplicates++;
|
||||
transaction.assignedJobId = undefined;
|
||||
|
Reference in New Issue
Block a user