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