From 73ccee5dd35b6ef1ccbe7c6ce1af53b1b062a3ba Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Wed, 9 Jul 2025 19:26:31 +0000 Subject: [PATCH] Fix batch expenditure form and add autofocus Fixed the batch expenditure form to correctly recognize transactions. Added autofocus to the input forms in both batch income and expenditure forms. --- src/components/BatchExpenditureForm.tsx | 46 +++++++++++++--- src/components/TransactionForm.tsx | 12 ++++- src/utils/priceUtils.ts | 72 +++++++++++++++++++------ 3 files changed, 104 insertions(+), 26 deletions(-) diff --git a/src/components/BatchExpenditureForm.tsx b/src/components/BatchExpenditureForm.tsx index 7c3f45b..9577e8e 100644 --- a/src/components/BatchExpenditureForm.tsx +++ b/src/components/BatchExpenditureForm.tsx @@ -1,5 +1,4 @@ - -import { useState } from 'react'; +import { useState, useRef, useEffect } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; @@ -28,6 +27,14 @@ const BatchExpenditureForm: React.FC = ({ onClose, on const [pastedData, setPastedData] = useState(''); const [transactionGroups, setTransactionGroups] = useState([]); const [duplicatesFound, setDuplicatesFound] = useState(0); + const textareaRef = useRef(null); + + // Auto focus the textarea when component mounts + useEffect(() => { + if (textareaRef.current) { + textareaRef.current.focus(); + } + }, []); // Filter jobs that are in acquisition status const eligibleJobs = jobs.filter(job => job.status === IndJobStatusOptions.Acquisition); @@ -84,19 +91,35 @@ const BatchExpenditureForm: React.FC = ({ onClose, on }; const handlePaste = (value: string) => { + console.log('Handling paste with value:', value); setPastedData(value); - const lines = value.trim().split('\n'); + const lines = value.trim().split('\n').filter(line => line.trim().length > 0); + console.log('Processing lines:', lines); + const pasteTransactionMap = new Map(); // STEP 1: Combine identical transactions within the pasted data - lines.forEach((line) => { + lines.forEach((line, index) => { + console.log(`Processing line ${index}:`, line); const parsed: PastedTransaction | null = parseTransactionLine(line); - if (parsed && parsed.totalPrice < 0) { // Only process expenditures (negative amounts) - // Convert to positive values for expenditures - parsed.totalPrice = Math.abs(parsed.totalPrice); - parsed.unitPrice = Math.abs(parsed.unitPrice); + + if (parsed) { + console.log('Parsed transaction:', parsed); + + // For expenditures, we expect negative amounts, but handle both cases + const isExpenditure = parsed.totalPrice < 0; + if (isExpenditure) { + // Convert to positive values for expenditures + parsed.totalPrice = Math.abs(parsed.totalPrice); + parsed.unitPrice = Math.abs(parsed.unitPrice); + } else { + // If it's positive, we might still want to treat it as expenditure + // based on context, but let's keep it as is for now + console.log('Transaction has positive amount, treating as expenditure anyway'); + } const transactionKey: string = createTransactionKey(parsed); + console.log('Transaction key:', transactionKey); if (pasteTransactionMap.has(transactionKey)) { const existing = pasteTransactionMap.get(transactionKey)!; @@ -108,9 +131,13 @@ const BatchExpenditureForm: React.FC = ({ onClose, on } else { pasteTransactionMap.set(transactionKey, parsed); } + } else { + console.log('Failed to parse line:', line); } }); + console.log('Parsed transactions map:', pasteTransactionMap); + // STEP 2: Identify which jobs these transactions belong to const relevantJobIds = new Set(); pasteTransactionMap.forEach((transaction) => { @@ -147,6 +174,7 @@ const BatchExpenditureForm: React.FC = ({ onClose, on }); const transactionList = Array.from(pasteTransactionMap.values()); + console.log('Final transaction list:', transactionList); setDuplicatesFound(duplicates); // Create individual transaction groups @@ -157,6 +185,7 @@ const BatchExpenditureForm: React.FC = ({ onClose, on totalValue: tx.totalPrice })); + console.log('Transaction groups:', groups); setTransactionGroups(groups); }; @@ -216,6 +245,7 @@ const BatchExpenditureForm: React.FC = ({ onClose, on Paste EVE expenditure data (negative amounts):