From 85fafae31169c8c40d8d175450e7ccd009097956 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 29 Oct 2025 14:27:44 +0000 Subject: [PATCH] added a server manager --- .gitignore | 3 + app/main.py | 144 +- app/schemas.py | 1 + nohup.out | 4169 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 4246 insertions(+), 71 deletions(-) diff --git a/.gitignore b/.gitignore index af2fa0c..e24e076 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ __pycache__/ .env *.log /uploads +server_manager.sh +server.log +server.pid \ No newline at end of file diff --git a/app/main.py b/app/main.py index 9e60e9a..8f08109 100644 --- a/app/main.py +++ b/app/main.py @@ -731,79 +731,81 @@ async def match_specific_receipts(request: MatchSpecificRequest, db: db_dependen match_responses = [] for result in matching_results: # Get final tax amount from LLM analysis if available, otherwise use receipt's stated tax - final_tax = result.receipt.tax - # if result.tax_analysis and "final_tax_amount" in result.tax_analysis: - # final_tax = result.tax_analysis["final_tax_amount"] + if result.confidence_score > 0: + final_tax = result.receipt.tax + # if result.tax_analysis and "final_tax_amount" in result.tax_analysis: + # final_tax = result.tax_analysis["final_tax_amount"] - # Extract flag_for_review and auto_approve from tax_analysis if available - flag_for_review = None - auto_approve = None - if result.tax_analysis: - flag_for_review = result.tax_analysis.get("flag_for_review") - auto_approve = result.tax_analysis.get("auto_approve") + # Extract flag_for_review and auto_approve from tax_analysis if available + flag_for_review = None + auto_approve = None + if result.tax_analysis: + flag_for_review = result.tax_analysis.get("flag_for_review") + auto_approve = result.tax_analysis.get("auto_approve") - match_response = MatchResponse( - receipt_id=result.receipt.id, - transaction_id=result.transaction.id - if result.transaction - else "no_match", - confidence_score=result.confidence_score * 100, - match_reason=result.match_reason, - receipt_vendor=result.receipt.vendor, - receipt_amount=result.receipt.amount, - receipt_description=result.receipt.description, - receipt_category=result.receipt.category, - receipt_tax_amount=final_tax, - transaction_vendor=result.transaction.vendor - if result.transaction - else "", - transaction_amount=result.transaction.amount - if result.transaction - else 0.0, - tax_analysis=result.tax_analysis, - flag_for_review=flag_for_review, - auto_approve=auto_approve, - # Transaction metadata - transaction_source=result.transaction.source - if result.transaction - else None, - # QuickBooks CSV fields - TxnId=result.transaction.TxnId if result.transaction else None, - AccountType=result.transaction.AccountType - if result.transaction - else None, - AccountNumber=result.transaction.AccountNumber - if result.transaction - else None, - TransactionDate=result.transaction.TransactionDate - if result.transaction - else None, - TransactionType=result.transaction.TransactionType - if result.transaction - else None, - ChequeNumber=result.transaction.ChequeNumber - if result.transaction - else None, - Description1=result.transaction.Description1 - if result.transaction - else None, - Description2=result.transaction.Description2 - if result.transaction - else None, - VendorId=result.transaction.VendorId - if result.transaction - else None, - VendorName=result.transaction.VendorName - if result.transaction - else None, - AccountId=result.transaction.AccountId - if result.transaction - else None, - AccountName=result.transaction.AccountName - if result.transaction - else None, - ) - match_responses.append(match_response) + match_response = MatchResponse( + receipt_id=result.receipt.id, + transaction_id=result.transaction.id + if result.transaction + else "no_match", + confidence_score=result.confidence_score * 100, + match_reason=result.match_reason, + receipt_vendor=result.receipt.vendor, + receipt_amount=result.receipt.amount, + receipt_description=result.receipt.description, + receipt_category=result.receipt.category, + receipt_tax_amount=final_tax, + transaction_vendor=result.transaction.vendor + if result.transaction + else "", + transaction_amount=result.transaction.amount + if result.transaction + else 0.0, + tax_analysis=result.tax_analysis, + flag_for_review=flag_for_review, + auto_approve=auto_approve, + # Transaction metadata + transaction_source=result.transaction.source + if result.transaction + else None, + # QuickBooks CSV fields + TxnId=result.transaction.TxnId if result.transaction else None, + AccountType=result.transaction.AccountType + if result.transaction + else None, + AccountNumber=result.transaction.AccountNumber + if result.transaction + else None, + TransactionDate=result.transaction.TransactionDate + if result.transaction + else None, + TransactionType=result.transaction.TransactionType + if result.transaction + else None, + ChequeNumber=result.transaction.ChequeNumber + if result.transaction + else None, + Description1=result.transaction.Description1 + if result.transaction + else None, + Description2=result.transaction.Description2 + if result.transaction + else None, + VendorId=result.transaction.VendorId + if result.transaction + else None, + VendorName=result.transaction.VendorName + if result.transaction + else None, + AccountId=result.transaction.AccountId + if result.transaction + else None, + AccountName=result.transaction.AccountName + if result.transaction + else None, + Source=result.transaction.source if result.transaction else None, + ) + match_responses.append(match_response) # Calculate statistics high_confidence = len( diff --git a/app/schemas.py b/app/schemas.py index 126354c..c74d6cd 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -181,6 +181,7 @@ class MatchResponse(BaseModel): VendorName: Optional[str] = None AccountId: Optional[str] = None AccountName: Optional[str] = None + Source: Optional[str] = None class MatchingResponse(BaseModel): diff --git a/nohup.out b/nohup.out index b97bb08..3b9aec0 100644 --- a/nohup.out +++ b/nohup.out @@ -94,3 +94,4172 @@ INFO: 199.241.139.243:47824 - "POST /upload-multiple HTTP/1.1" 200 OK INFO:__main__:Request: file_id=None user_location=None ai_rules=[AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "mkd"', action='SET_CATEGORY: technology'), AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "Maple"', action='SET_CATEGORY: Supercar')] INFO:__main__:Receipt for file 1-ocsQytyZP397IrLSEv5j5pco10UTbaq already exists, returning existing record INFO: 199.241.139.243:47832 - "POST /process/1-ocsQytyZP397IrLSEv5j5pco10UTbaq HTTP/1.1" 200 OK +/root/ds_quickbooks_v2/app/main.py:58: DeprecationWarning: + on_event is deprecated, use lifespan event handlers instead. + + Read more about it in the + [FastAPI docs for Lifespan Events](https://fastapi.tiangolo.com/advanced/events/). + + @app.on_event("startup") +INFO: Started server process [60419] +INFO: Waiting for application startup. +INFO:__main__:Starting up application... +INFO:database:Creating database tables... +INFO:database:Database tables created successfully +INFO:__main__:Application startup complete +INFO: Application startup complete. +INFO: Uvicorn running on http://0.0.0.0:8654 (Press CTRL+C to quit) +INFO: Shutting down +INFO: Waiting for application shutdown. +INFO: Application shutdown complete. +INFO: Finished server process [60419] +/root/ds_quickbooks_v2/app/main.py:58: DeprecationWarning: + on_event is deprecated, use lifespan event handlers instead. + + Read more about it in the + [FastAPI docs for Lifespan Events](https://fastapi.tiangolo.com/advanced/events/). + + @app.on_event("startup") +INFO: Started server process [60971] +INFO: Waiting for application startup. +INFO:__main__:Starting up application... +INFO:database:Database tables already exist: ['receipts', 'transactions', 'uploaded_files'] +INFO:__main__:Application startup complete +INFO: Application startup complete. +INFO: Uvicorn running on http://0.0.0.0:8654 (Press CTRL+C to quit) +INFO: 102.89.46.156:6869 - "POST /transactions/import/csv HTTP/1.1" 200 OK +INFO:__main__:Starting match-specific for file IDs: ['1-ocsQytyZP397IrLSEv5j5pco10UTbaq', '1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY', '1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa', '1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E', '1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW', '11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g', '1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl', '1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN'], categorization_id: cat_mh3zluqt_2xp5i1 +INFO:__main__:Found 5 transactions in database +INFO:__main__:Converted 5 transactions +WARNING:__main__:Receipt 1-ocsQytyZP397IrLSEv5j5pco10UTbaq not found in database +WARNING:__main__:Receipt 1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY not found in database +WARNING:__main__:Receipt 1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa not found in database +WARNING:__main__:Receipt 1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E not found in database +WARNING:__main__:Receipt 1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW not found in database +WARNING:__main__:Receipt 11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g not found in database +WARNING:__main__:Receipt 1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl not found in database +WARNING:__main__:Receipt 1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN not found in database +INFO:__main__:Found 0 receipts, 8 missing +WARNING:__main__:Missing files: ['1-ocsQytyZP397IrLSEv5j5pco10UTbaq', '1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY', '1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa', '1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E', '1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW', '11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g', '1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl', '1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN'] +WARNING:__main__:No valid receipts found +INFO: 102.89.46.156:7131 - "POST /match-specific HTTP/1.1" 400 Bad Request +INFO:__main__:filename: photo_2025-10-10_12-09-46.jpg, extension: jpg, google_file_id: 1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN +INFO:__main__:Uploaded new file photo_2025-10-10_12-09-46.jpg with ID 1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN +INFO: 102.89.46.156:921 - "POST /upload-multiple HTTP/1.1" 200 OK +INFO:__main__:Request: file_id=None user_location=None ai_rules=[AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "mkd"', action='SET_CATEGORY: technology'), AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "Maple"', action='SET_CATEGORY: Supercar')] +INFO:services.document_processor:This is the prompt: + Analyze this receipt image and extract the following information in JSON format. + + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "mkd": Set category to "technology" + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "Maple": Set category to "Supercar" + + + JSON Format: + { + "vendor": "Store/company name", + "description": "Detailed description of items/services purchased", + "total_amount": 0.00, + "tax_amount": 0.00, + "date": "YYYY-MM-DD", + "category": "Check rules above first", + "confidence": 0.95, + "currency": "USD", + "location": "Province/State, Country", + "calculated_tax": 0.00, + "is_depreciable": false, + "name_of_asset": null, + "cca_rate": null, + "useful_life": null, + "residual_value": null, + "extraction_success": True + } + + EXTRACTION Rules: + - Extract vendor name as it appears on receipt + - Extract description of items/services purchased (e.g., "Coffee and sandwich", "Gasoline", "Office supplies") + - Total amount should be the final total including tax + - Tax amount is separate tax line if available (if not clearly shown, calculate based on location) + - Date should be the date on the receipt + - Confidence score 0-1 based on how clear the receipt is + - Currency should be the currency used on the receipt (e.g., "USD", "EUR", "CAD") + + + LOCATION & TAX RULES: + - Extract location from receipt (look for store address, province/state, country) + - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") + - If location not shown on receipt, return null for location (system will use user location as fallback) + + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: + * Ontario, Canada: 13% HST + * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total + * British Columbia, Canada: 12% (5% GST + 7% PST) + * Alberta, Canada: 5% GST + * California, USA: ~7.25% (varies by locality) + * New York, USA: ~8.875% (varies by locality) + * Texas, USA: 6.25% + * For other locations, estimate based on typical rates + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value + + DEPRECIATION RULES: + - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) + - Set is_depreciable to true only for capital assets, false for consumables/services + - If is_depreciable is true, provide: + * name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk") + * cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%) + - Class 10 (Vehicles): 30% + - Class 8 (Furniture, equipment): 20% + - Class 50 (Computers, software): 55% + - Class 1 (Buildings): 4% + - Class 10.1 (Passenger vehicles >$30k): 30% + * useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture) + * residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles) + - If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null + + Return only valid JSON. + +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:__main__:Extracted receipt data: {'vendor': 'MAPLE LEAF MOTORS INC.', 'description': 'Vehicle: ROMATOKI', 'total_amount': 38531.87, 'tax_amount': 4432.87, 'date': '2025-10-07', 'category': 'Supercar', 'confidence': 0.95, 'currency': 'CAD', 'location': 'Ontario, Canada', 'calculated_tax': None, 'is_depreciable': True, 'name_of_asset': 'ROMATOKI', 'cca_rate': 0.3, 'useful_life': 8, 'residual_value': 7706.37, 'extraction_success': True} +INFO: 102.89.46.156:921 - "POST /process/1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN HTTP/1.1" 200 OK +INFO:__main__:filename: Gemini_Generated_Image_9xuhxd9xuhxd9xuh.png, extension: png, google_file_id: 1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl +INFO:__main__:Uploaded new file Gemini_Generated_Image_9xuhxd9xuhxd9xuh.png with ID 1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl +INFO: 102.89.46.156:921 - "POST /upload-multiple HTTP/1.1" 200 OK +INFO:__main__:Request: file_id=None user_location=None ai_rules=[AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "mkd"', action='SET_CATEGORY: technology'), AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "Maple"', action='SET_CATEGORY: Supercar')] +INFO:services.document_processor:This is the prompt: + Analyze this receipt image and extract the following information in JSON format. + + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "mkd": Set category to "technology" + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "Maple": Set category to "Supercar" + + + JSON Format: + { + "vendor": "Store/company name", + "description": "Detailed description of items/services purchased", + "total_amount": 0.00, + "tax_amount": 0.00, + "date": "YYYY-MM-DD", + "category": "Check rules above first", + "confidence": 0.95, + "currency": "USD", + "location": "Province/State, Country", + "calculated_tax": 0.00, + "is_depreciable": false, + "name_of_asset": null, + "cca_rate": null, + "useful_life": null, + "residual_value": null, + "extraction_success": True + } + + EXTRACTION Rules: + - Extract vendor name as it appears on receipt + - Extract description of items/services purchased (e.g., "Coffee and sandwich", "Gasoline", "Office supplies") + - Total amount should be the final total including tax + - Tax amount is separate tax line if available (if not clearly shown, calculate based on location) + - Date should be the date on the receipt + - Confidence score 0-1 based on how clear the receipt is + - Currency should be the currency used on the receipt (e.g., "USD", "EUR", "CAD") + + + LOCATION & TAX RULES: + - Extract location from receipt (look for store address, province/state, country) + - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") + - If location not shown on receipt, return null for location (system will use user location as fallback) + + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: + * Ontario, Canada: 13% HST + * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total + * British Columbia, Canada: 12% (5% GST + 7% PST) + * Alberta, Canada: 5% GST + * California, USA: ~7.25% (varies by locality) + * New York, USA: ~8.875% (varies by locality) + * Texas, USA: 6.25% + * For other locations, estimate based on typical rates + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value + + DEPRECIATION RULES: + - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) + - Set is_depreciable to true only for capital assets, false for consumables/services + - If is_depreciable is true, provide: + * name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk") + * cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%) + - Class 10 (Vehicles): 30% + - Class 8 (Furniture, equipment): 20% + - Class 50 (Computers, software): 55% + - Class 1 (Buildings): 4% + - Class 10.1 (Passenger vehicles >$30k): 30% + * useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture) + * residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles) + - If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null + + Return only valid JSON. + +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:__main__:Extracted receipt data: {'vendor': 'MAPLE LEAF MOTORS INC.', 'description': 'Vehicle Purchase', 'total_amount': 38531.87, 'tax_amount': 4432.87, 'date': '2025-10-07', 'category': 'Supercar', 'confidence': 0.95, 'currency': 'CAD', 'location': 'Ontario, Canada', 'calculated_tax': None, 'is_depreciable': True, 'name_of_asset': 'ROMATOKI', 'cca_rate': 0.3, 'useful_life': 8, 'residual_value': 7706.37, 'extraction_success': True} +INFO: 102.89.46.156:921 - "POST /process/1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl HTTP/1.1" 200 OK +INFO:__main__:filename: WhatsApp Image 2025-10-08 at 18.25.20_7f76d34e.jpg, extension: jpg, google_file_id: 11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g +INFO:__main__:Uploaded new file WhatsApp Image 2025-10-08 at 18.25.20_7f76d34e.jpg with ID 11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g +INFO: 102.89.46.156:921 - "POST /upload-multiple HTTP/1.1" 200 OK +INFO:__main__:Request: file_id=None user_location=None ai_rules=[AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "mkd"', action='SET_CATEGORY: technology'), AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "Maple"', action='SET_CATEGORY: Supercar')] +INFO:services.document_processor:This is the prompt: + Analyze this receipt image and extract the following information in JSON format. + + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "mkd": Set category to "technology" + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "Maple": Set category to "Supercar" + + + JSON Format: + { + "vendor": "Store/company name", + "description": "Detailed description of items/services purchased", + "total_amount": 0.00, + "tax_amount": 0.00, + "date": "YYYY-MM-DD", + "category": "Check rules above first", + "confidence": 0.95, + "currency": "USD", + "location": "Province/State, Country", + "calculated_tax": 0.00, + "is_depreciable": false, + "name_of_asset": null, + "cca_rate": null, + "useful_life": null, + "residual_value": null, + "extraction_success": True + } + + EXTRACTION Rules: + - Extract vendor name as it appears on receipt + - Extract description of items/services purchased (e.g., "Coffee and sandwich", "Gasoline", "Office supplies") + - Total amount should be the final total including tax + - Tax amount is separate tax line if available (if not clearly shown, calculate based on location) + - Date should be the date on the receipt + - Confidence score 0-1 based on how clear the receipt is + - Currency should be the currency used on the receipt (e.g., "USD", "EUR", "CAD") + + + LOCATION & TAX RULES: + - Extract location from receipt (look for store address, province/state, country) + - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") + - If location not shown on receipt, return null for location (system will use user location as fallback) + + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: + * Ontario, Canada: 13% HST + * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total + * British Columbia, Canada: 12% (5% GST + 7% PST) + * Alberta, Canada: 5% GST + * California, USA: ~7.25% (varies by locality) + * New York, USA: ~8.875% (varies by locality) + * Texas, USA: 6.25% + * For other locations, estimate based on typical rates + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value + + DEPRECIATION RULES: + - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) + - Set is_depreciable to true only for capital assets, false for consumables/services + - If is_depreciable is true, provide: + * name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk") + * cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%) + - Class 10 (Vehicles): 30% + - Class 8 (Furniture, equipment): 20% + - Class 50 (Computers, software): 55% + - Class 1 (Buildings): 4% + - Class 10.1 (Passenger vehicles >$30k): 30% + * useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture) + * residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles) + - If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null + + Return only valid JSON. + +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:__main__:Extracted receipt data: {'vendor': 'MAPLE LEAF MOTORS INC.', 'description': 'ROMATOKI', 'total_amount': 38531.87, 'tax_amount': 4432.87, 'date': '2025-10-07', 'category': 'Supercar', 'confidence': 0.95, 'currency': 'CAD', 'location': 'Ontario, Canada', 'calculated_tax': None, 'is_depreciable': True, 'name_of_asset': 'ROMATOKI', 'cca_rate': 0.3, 'useful_life': 8, 'residual_value': 7706.37, 'extraction_success': True} +INFO: 102.89.46.156:921 - "POST /process/11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g HTTP/1.1" 200 OK +INFO:__main__:filename: WhatsApp Image 2025-07-04 at 11.52.19.jpeg, extension: jpeg, google_file_id: 1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW +INFO:__main__:Uploaded new file WhatsApp Image 2025-07-04 at 11.52.19.jpeg with ID 1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW +INFO: 102.89.46.156:921 - "POST /upload-multiple HTTP/1.1" 200 OK +INFO:__main__:Request: file_id=None user_location=None ai_rules=[AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "mkd"', action='SET_CATEGORY: technology'), AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "Maple"', action='SET_CATEGORY: Supercar')] +INFO:services.document_processor:This is the prompt: + Analyze this receipt image and extract the following information in JSON format. + + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "mkd": Set category to "technology" + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "Maple": Set category to "Supercar" + + + JSON Format: + { + "vendor": "Store/company name", + "description": "Detailed description of items/services purchased", + "total_amount": 0.00, + "tax_amount": 0.00, + "date": "YYYY-MM-DD", + "category": "Check rules above first", + "confidence": 0.95, + "currency": "USD", + "location": "Province/State, Country", + "calculated_tax": 0.00, + "is_depreciable": false, + "name_of_asset": null, + "cca_rate": null, + "useful_life": null, + "residual_value": null, + "extraction_success": True + } + + EXTRACTION Rules: + - Extract vendor name as it appears on receipt + - Extract description of items/services purchased (e.g., "Coffee and sandwich", "Gasoline", "Office supplies") + - Total amount should be the final total including tax + - Tax amount is separate tax line if available (if not clearly shown, calculate based on location) + - Date should be the date on the receipt + - Confidence score 0-1 based on how clear the receipt is + - Currency should be the currency used on the receipt (e.g., "USD", "EUR", "CAD") + + + LOCATION & TAX RULES: + - Extract location from receipt (look for store address, province/state, country) + - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") + - If location not shown on receipt, return null for location (system will use user location as fallback) + + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: + * Ontario, Canada: 13% HST + * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total + * British Columbia, Canada: 12% (5% GST + 7% PST) + * Alberta, Canada: 5% GST + * California, USA: ~7.25% (varies by locality) + * New York, USA: ~8.875% (varies by locality) + * Texas, USA: 6.25% + * For other locations, estimate based on typical rates + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value + + DEPRECIATION RULES: + - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) + - Set is_depreciable to true only for capital assets, false for consumables/services + - If is_depreciable is true, provide: + * name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk") + * cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%) + - Class 10 (Vehicles): 30% + - Class 8 (Furniture, equipment): 20% + - Class 50 (Computers, software): 55% + - Class 1 (Buildings): 4% + - Class 10.1 (Passenger vehicles >$30k): 30% + * useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture) + * residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles) + - If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null + + Return only valid JSON. + +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:__main__:Extracted receipt data: {'vendor': 'Figma, Inc.', 'description': 'Professional Full seats (monthly) Jun 19 - Jul 19, 2025', 'total_amount': 27.0, 'tax_amount': 0.0, 'date': '2025-06-19', 'category': 'technology', 'confidence': 0.95, 'currency': 'CAD', 'location': 'Ontario, Canada', 'calculated_tax': None, 'is_depreciable': False, 'name_of_asset': None, 'cca_rate': None, 'useful_life': None, 'residual_value': None, 'extraction_success': True} +INFO: 102.89.46.156:921 - "POST /process/1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW HTTP/1.1" 200 OK +INFO:__main__:filename: WhatsApp Image 2025-07-04 at 11.52.19 (2).jpeg, extension: jpeg, google_file_id: 1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E +INFO:__main__:Uploaded new file WhatsApp Image 2025-07-04 at 11.52.19 (2).jpeg with ID 1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E +INFO: 102.89.46.156:921 - "POST /upload-multiple HTTP/1.1" 200 OK +INFO:__main__:Request: file_id=None user_location=None ai_rules=[AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "mkd"', action='SET_CATEGORY: technology'), AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "Maple"', action='SET_CATEGORY: Supercar')] +INFO:services.document_processor:This is the prompt: + Analyze this receipt image and extract the following information in JSON format. + + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "mkd": Set category to "technology" + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "Maple": Set category to "Supercar" + + + JSON Format: + { + "vendor": "Store/company name", + "description": "Detailed description of items/services purchased", + "total_amount": 0.00, + "tax_amount": 0.00, + "date": "YYYY-MM-DD", + "category": "Check rules above first", + "confidence": 0.95, + "currency": "USD", + "location": "Province/State, Country", + "calculated_tax": 0.00, + "is_depreciable": false, + "name_of_asset": null, + "cca_rate": null, + "useful_life": null, + "residual_value": null, + "extraction_success": True + } + + EXTRACTION Rules: + - Extract vendor name as it appears on receipt + - Extract description of items/services purchased (e.g., "Coffee and sandwich", "Gasoline", "Office supplies") + - Total amount should be the final total including tax + - Tax amount is separate tax line if available (if not clearly shown, calculate based on location) + - Date should be the date on the receipt + - Confidence score 0-1 based on how clear the receipt is + - Currency should be the currency used on the receipt (e.g., "USD", "EUR", "CAD") + + + LOCATION & TAX RULES: + - Extract location from receipt (look for store address, province/state, country) + - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") + - If location not shown on receipt, return null for location (system will use user location as fallback) + + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: + * Ontario, Canada: 13% HST + * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total + * British Columbia, Canada: 12% (5% GST + 7% PST) + * Alberta, Canada: 5% GST + * California, USA: ~7.25% (varies by locality) + * New York, USA: ~8.875% (varies by locality) + * Texas, USA: 6.25% + * For other locations, estimate based on typical rates + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value + + DEPRECIATION RULES: + - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) + - Set is_depreciable to true only for capital assets, false for consumables/services + - If is_depreciable is true, provide: + * name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk") + * cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%) + - Class 10 (Vehicles): 30% + - Class 8 (Furniture, equipment): 20% + - Class 50 (Computers, software): 55% + - Class 1 (Buildings): 4% + - Class 10.1 (Passenger vehicles >$30k): 30% + * useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture) + * residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles) + - If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null + + Return only valid JSON. + +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:__main__:Extracted receipt data: {'vendor': 'Google LLC', 'description': 'Google Workspace', 'total_amount': 21.15, 'tax_amount': 2.43, 'date': '2025-05-31', 'category': 'cloud service', 'confidence': 0.95, 'currency': 'CAD', 'location': 'Ontario, Canada', 'calculated_tax': None, 'is_depreciable': False, 'name_of_asset': None, 'cca_rate': None, 'useful_life': None, 'residual_value': None, 'extraction_success': True} +INFO: 102.89.46.156:921 - "POST /process/1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E HTTP/1.1" 200 OK +INFO:__main__:filename: WhatsApp Image 2025-07-04 at 11.52.19 (1).jpeg, extension: jpeg, google_file_id: 1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa +INFO:__main__:Uploaded new file WhatsApp Image 2025-07-04 at 11.52.19 (1).jpeg with ID 1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa +INFO: 102.89.46.156:921 - "POST /upload-multiple HTTP/1.1" 200 OK +INFO:__main__:Request: file_id=None user_location=None ai_rules=[AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "mkd"', action='SET_CATEGORY: technology'), AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "Maple"', action='SET_CATEGORY: Supercar')] +INFO:services.document_processor:This is the prompt: + Analyze this receipt image and extract the following information in JSON format. + + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "mkd": Set category to "technology" + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "Maple": Set category to "Supercar" + + + JSON Format: + { + "vendor": "Store/company name", + "description": "Detailed description of items/services purchased", + "total_amount": 0.00, + "tax_amount": 0.00, + "date": "YYYY-MM-DD", + "category": "Check rules above first", + "confidence": 0.95, + "currency": "USD", + "location": "Province/State, Country", + "calculated_tax": 0.00, + "is_depreciable": false, + "name_of_asset": null, + "cca_rate": null, + "useful_life": null, + "residual_value": null, + "extraction_success": True + } + + EXTRACTION Rules: + - Extract vendor name as it appears on receipt + - Extract description of items/services purchased (e.g., "Coffee and sandwich", "Gasoline", "Office supplies") + - Total amount should be the final total including tax + - Tax amount is separate tax line if available (if not clearly shown, calculate based on location) + - Date should be the date on the receipt + - Confidence score 0-1 based on how clear the receipt is + - Currency should be the currency used on the receipt (e.g., "USD", "EUR", "CAD") + + + LOCATION & TAX RULES: + - Extract location from receipt (look for store address, province/state, country) + - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") + - If location not shown on receipt, return null for location (system will use user location as fallback) + + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: + * Ontario, Canada: 13% HST + * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total + * British Columbia, Canada: 12% (5% GST + 7% PST) + * Alberta, Canada: 5% GST + * California, USA: ~7.25% (varies by locality) + * New York, USA: ~8.875% (varies by locality) + * Texas, USA: 6.25% + * For other locations, estimate based on typical rates + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value + + DEPRECIATION RULES: + - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) + - Set is_depreciable to true only for capital assets, false for consumables/services + - If is_depreciable is true, provide: + * name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk") + * cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%) + - Class 10 (Vehicles): 30% + - Class 8 (Furniture, equipment): 20% + - Class 50 (Computers, software): 55% + - Class 1 (Buildings): 4% + - Class 10.1 (Passenger vehicles >$30k): 30% + * useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture) + * residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles) + - If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null + + Return only valid JSON. + +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:__main__:Extracted receipt data: {'vendor': 'Figma, Inc.', 'description': 'Professional Full seats (monthly) Jun 19 - Jul 19, 2025', 'total_amount': 27.0, 'tax_amount': 0.0, 'date': '2025-06-19', 'category': 'technology', 'confidence': 0.95, 'currency': 'CAD', 'location': 'Ontario, Canada', 'calculated_tax': None, 'is_depreciable': False, 'name_of_asset': None, 'cca_rate': None, 'useful_life': None, 'residual_value': None, 'extraction_success': True} +INFO: 102.89.46.156:921 - "POST /process/1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa HTTP/1.1" 200 OK +INFO:__main__:filename: WhatsApp Image 2025-07-04 at 11.52.18.jpeg, extension: jpeg, google_file_id: 1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY +INFO:__main__:Uploaded new file WhatsApp Image 2025-07-04 at 11.52.18.jpeg with ID 1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY +INFO: 102.89.46.156:921 - "POST /upload-multiple HTTP/1.1" 200 OK +INFO:__main__:Request: file_id=None user_location=None ai_rules=[AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "mkd"', action='SET_CATEGORY: technology'), AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "Maple"', action='SET_CATEGORY: Supercar')] +INFO:services.document_processor:This is the prompt: + Analyze this receipt image and extract the following information in JSON format. + + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "mkd": Set category to "technology" + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "Maple": Set category to "Supercar" + + + JSON Format: + { + "vendor": "Store/company name", + "description": "Detailed description of items/services purchased", + "total_amount": 0.00, + "tax_amount": 0.00, + "date": "YYYY-MM-DD", + "category": "Check rules above first", + "confidence": 0.95, + "currency": "USD", + "location": "Province/State, Country", + "calculated_tax": 0.00, + "is_depreciable": false, + "name_of_asset": null, + "cca_rate": null, + "useful_life": null, + "residual_value": null, + "extraction_success": True + } + + EXTRACTION Rules: + - Extract vendor name as it appears on receipt + - Extract description of items/services purchased (e.g., "Coffee and sandwich", "Gasoline", "Office supplies") + - Total amount should be the final total including tax + - Tax amount is separate tax line if available (if not clearly shown, calculate based on location) + - Date should be the date on the receipt + - Confidence score 0-1 based on how clear the receipt is + - Currency should be the currency used on the receipt (e.g., "USD", "EUR", "CAD") + + + LOCATION & TAX RULES: + - Extract location from receipt (look for store address, province/state, country) + - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") + - If location not shown on receipt, return null for location (system will use user location as fallback) + + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: + * Ontario, Canada: 13% HST + * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total + * British Columbia, Canada: 12% (5% GST + 7% PST) + * Alberta, Canada: 5% GST + * California, USA: ~7.25% (varies by locality) + * New York, USA: ~8.875% (varies by locality) + * Texas, USA: 6.25% + * For other locations, estimate based on typical rates + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value + + DEPRECIATION RULES: + - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) + - Set is_depreciable to true only for capital assets, false for consumables/services + - If is_depreciable is true, provide: + * name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk") + * cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%) + - Class 10 (Vehicles): 30% + - Class 8 (Furniture, equipment): 20% + - Class 50 (Computers, software): 55% + - Class 1 (Buildings): 4% + - Class 10.1 (Passenger vehicles >$30k): 30% + * useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture) + * residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles) + - If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null + + Return only valid JSON. + +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:__main__:Extracted receipt data: {'vendor': 'Bzabaowskyj', 'description': 'Paypal *Bzabaowskyj* 4029357733 On', 'total_amount': 37.55, 'tax_amount': 0.0, 'date': '2024-05-22', 'category': 'cloud service', 'confidence': 0.95, 'currency': 'USD', 'location': None, 'calculated_tax': 0.0, 'is_depreciable': False, 'name_of_asset': None, 'cca_rate': None, 'useful_life': None, 'residual_value': None, 'extraction_success': True} +INFO: 102.89.46.156:921 - "POST /process/1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY HTTP/1.1" 200 OK +INFO:__main__:filename: WhatsApp Image 2025-07-04 at 11.52.18 (1).jpeg, extension: jpeg, google_file_id: 1-ocsQytyZP397IrLSEv5j5pco10UTbaq +INFO:__main__:Uploaded new file WhatsApp Image 2025-07-04 at 11.52.18 (1).jpeg with ID 1-ocsQytyZP397IrLSEv5j5pco10UTbaq +INFO: 102.89.46.156:921 - "POST /upload-multiple HTTP/1.1" 200 OK +INFO:__main__:Request: file_id=None user_location=None ai_rules=[AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "mkd"', action='SET_CATEGORY: technology'), AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "Maple"', action='SET_CATEGORY: Supercar')] +INFO:services.document_processor:This is the prompt: + Analyze this receipt image and extract the following information in JSON format. + + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "mkd": Set category to "technology" + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "Maple": Set category to "Supercar" + + + JSON Format: + { + "vendor": "Store/company name", + "description": "Detailed description of items/services purchased", + "total_amount": 0.00, + "tax_amount": 0.00, + "date": "YYYY-MM-DD", + "category": "Check rules above first", + "confidence": 0.95, + "currency": "USD", + "location": "Province/State, Country", + "calculated_tax": 0.00, + "is_depreciable": false, + "name_of_asset": null, + "cca_rate": null, + "useful_life": null, + "residual_value": null, + "extraction_success": True + } + + EXTRACTION Rules: + - Extract vendor name as it appears on receipt + - Extract description of items/services purchased (e.g., "Coffee and sandwich", "Gasoline", "Office supplies") + - Total amount should be the final total including tax + - Tax amount is separate tax line if available (if not clearly shown, calculate based on location) + - Date should be the date on the receipt + - Confidence score 0-1 based on how clear the receipt is + - Currency should be the currency used on the receipt (e.g., "USD", "EUR", "CAD") + + + LOCATION & TAX RULES: + - Extract location from receipt (look for store address, province/state, country) + - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") + - If location not shown on receipt, return null for location (system will use user location as fallback) + + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: + * Ontario, Canada: 13% HST + * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total + * British Columbia, Canada: 12% (5% GST + 7% PST) + * Alberta, Canada: 5% GST + * California, USA: ~7.25% (varies by locality) + * New York, USA: ~8.875% (varies by locality) + * Texas, USA: 6.25% + * For other locations, estimate based on typical rates + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value + + DEPRECIATION RULES: + - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) + - Set is_depreciable to true only for capital assets, false for consumables/services + - If is_depreciable is true, provide: + * name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk") + * cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%) + - Class 10 (Vehicles): 30% + - Class 8 (Furniture, equipment): 20% + - Class 50 (Computers, software): 55% + - Class 1 (Buildings): 4% + - Class 10.1 (Passenger vehicles >$30k): 30% + * useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture) + * residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles) + - If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null + + Return only valid JSON. + +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:__main__:Extracted receipt data: {'vendor': 'Eleven Labs Inc.', 'description': 'Pro Jun 10 - Jul 10, 2025', 'total_amount': 111.87, 'tax_amount': 12.87, 'date': '2025-06-10', 'category': 'cloud service', 'confidence': 0.95, 'currency': 'USD', 'location': 'New York, United States', 'calculated_tax': None, 'is_depreciable': False, 'name_of_asset': None, 'cca_rate': None, 'useful_life': None, 'residual_value': None, 'extraction_success': True} +INFO: 102.89.46.156:921 - "POST /process/1-ocsQytyZP397IrLSEv5j5pco10UTbaq HTTP/1.1" 200 OK +INFO: 102.89.46.156:421 - "POST /transactions/import/csv HTTP/1.1" 200 OK +INFO:__main__:Starting match-specific for file IDs: ['1-ocsQytyZP397IrLSEv5j5pco10UTbaq', '1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY', '1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa', '1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E', '1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW', '11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g', '1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl', '1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN'], categorization_id: cat_mh3zvv06_9xepht +INFO:__main__:Found 5 transactions in database +INFO:__main__:Converted 5 transactions +INFO:__main__:Successfully loaded receipt for file_id: 1-ocsQytyZP397IrLSEv5j5pco10UTbaq +INFO:__main__:Successfully loaded receipt for file_id: 1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY +INFO:__main__:Successfully loaded receipt for file_id: 1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa +INFO:__main__:Successfully loaded receipt for file_id: 1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E +INFO:__main__:Successfully loaded receipt for file_id: 1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW +INFO:__main__:Successfully loaded receipt for file_id: 11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g +INFO:__main__:Successfully loaded receipt for file_id: 1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl +INFO:__main__:Successfully loaded receipt for file_id: 1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN +INFO:__main__:Found 8 receipts, 0 missing +INFO:__main__:Starting matching with 8 receipts and 5 transactions +INFO:__main__:Using default/provided user_location: Canada +INFO:__main__:Applying 1 custom AI rules to matching +INFO:services.ai_matcher:Starting AI matching for 8 receipts against 5 transactions +INFO:services.ai_matcher:Processing receipt 1/8: Eleven Labs Inc. - $111.87 +INFO:services.ai_matcher:Found 4 candidates for receipt: Eleven Labs Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Eleven Labs Inc. +- Amount: $111.87 +- Date: 2025-06-10 +- Description: Pro Jun 10 - Jul 10, 2025 +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: UPDATESTACK LLC (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $110.37 (98.7%) +INFO:services.ai_matcher:Processing receipt 2/8: Bzabaowskyj - $37.55 +INFO:services.ai_matcher:Found 4 candidates for receipt: Bzabaowskyj +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Bzabaowskyj +- Amount: $37.55 +- Date: 2024-05-22 +- Description: Paypal *Bzabaowskyj* 4029357733 On +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: UPDATESTACK LLC (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - No exact vendor match +INFO:services.ai_matcher:Processing receipt 3/8: Figma, Inc. - $27.0 +INFO:services.ai_matcher:Found 4 candidates for receipt: Figma, Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Figma, Inc. +- Amount: $27.0 +- Date: 2025-06-19 +- Description: Professional Full seats (monthly) Jun 19 - Jul 19, 2025 +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - No exact vendor match +INFO:services.ai_matcher:Processing receipt 4/8: Google LLC - $21.15 +INFO:services.ai_matcher:Found 4 candidates for receipt: Google LLC +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Google LLC +- Amount: $21.15 +- Date: 2025-05-31 +- Description: Google Workspace +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - No exact vendor match +INFO:services.ai_matcher:Processing receipt 5/8: Figma, Inc. - $27.0 +INFO:services.ai_matcher:Found 4 candidates for receipt: Figma, Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Figma, Inc. +- Amount: $27.0 +- Date: 2025-06-19 +- Description: Professional Full seats (monthly) Jun 19 - Jul 19, 2025 +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - No exact vendor match +INFO:services.ai_matcher:Processing receipt 6/8: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 5 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: ROMATOKI +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 4: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 5: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 4: Unknown (score: 0.390) +INFO:services.ai_matcher:Found match: 0.390 - Amount similar (10%) with some matches +INFO:services.ai_matcher:Processing receipt 7/8: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 5 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: Vehicle Purchase +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 4: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 5: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 4: Unknown (score: 0.390) +INFO:services.ai_matcher:Found match: 0.390 - Amount similar (10%) + some matches +INFO:services.ai_matcher:Processing receipt 8/8: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 5 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: Vehicle: ROMATOKI +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 4: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 5: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 4: Unknown (score: 0.690) +INFO:services.ai_matcher:Found match: 0.690 - Amount similar (10%) + some matches +INFO:services.ai_matcher:AI matching completed. Found 8 matches +INFO:services.ai_rules_matcher:Applying AI rules to 8 matches with 1 custom rules +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +ERROR:services.ai_rules_matcher:Failed to parse LLM response as JSON: Unterminated string starting at: line 5 column 17 (char 151) +ERROR:services.ai_rules_matcher:Response text: { + "flag_for_review": true, + "auto_approve": false, + "rules_applied": ["receipt currency differs from transaction currency"], + "reasons": ["Receipt and transaction currencies differ (CAD vs. CAD is not a match, but the currencies are the same, so this rule is not applicable, however, the built-in rule is applied because the currencies are the same, but the rule is not applicable, so we will use the built-in rule which is always applied when currencies differ, but in this case, the currencies are the same, so we will use the built-in rule which is not applicable, but the rule is applied because the currencies are the same, so we will use the built-in rule which is always applied when currencies differ, but in this case, the currencies are the same, so we will use the built-in rule which is not applicable, but the rule is applied because the currencies are the same, so we will use the built-in rule which is always applied when currencies differ, but in this case, the currencies are the same, so we will use the built-in rule which is not applicable, but the rule is applied because the currencies are the same, so we will use the built-in rule which is always applied when currencies differ, but in this case, the currencies are the same, so we will use the built-in rule which is not applicable, but the rule is applied because the currencies are the same, so we will use the built-in rule which is always applied when currencies differ, but in this case, the currencies are the same, so we will use the built-in rule which is not applicable, but the rule is applied because the currencies are the same, so we will use the built-in rule which is always applied when currencies differ, but in this case, the currencies are the same, so we will use the built-in rule which is not applicable, but the rule is applied because the currencies are the same, so we will use the built-in rule which is always applied when currencies differ, but in this case, the currencies are the same, so we will use the built-in rule which is not applicable, but the rule is applied because the currencies are the same, so we will use the built-in rule which is always applied when currencies differ, but in this case, the currencies are the same, so we will use the built-in rule which is not applicable, but the rule is applied because the currencies +INFO:services.ai_rules_matcher:Match receipt_1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN → txn_4: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +ERROR:services.ai_rules_matcher:Failed to parse LLM response as JSON: Unterminated string starting at: line 5 column 17 (char 151) +ERROR:services.ai_rules_matcher:Response text: { + "flag_for_review": true, + "auto_approve": false, + "rules_applied": ["receipt currency differs from transaction currency"], + "reasons": ["Receipt and transaction currencies differ (CAD vs. CAD is not a match, but the currencies are the same, so this rule is not applicable, however, the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same, but the rule is not applicable, so the built-in rule is applied because the currencies are the same +INFO:services.ai_rules_matcher:Match receipt_11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g → txn_4: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl → txn_4: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1-ocsQytyZP397IrLSEv5j5pco10UTbaq → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +ERROR:services.ai_rules_matcher:Failed to parse LLM response as JSON: Unterminated string starting at: line 5 column 17 (char 151) +ERROR:services.ai_rules_matcher:Response text: { + "flag_for_review": true, + "auto_approve": false, + "rules_applied": ["receipt currency differs from transaction currency"], + "reasons": ["Receipt and transaction currencies differ (CAD vs. CAD is not a match, but the currencies are the same so this rule is not triggered by currency difference, however, the built-in rule is triggered because the currencies are the same but the rule is looking for a difference, so it is triggered by the fact that the currencies are the same and the built-in rule is looking for a difference, but the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and the currencies are the same so it is actually triggered by the fact that the built-in rule is looking for a difference and +INFO:services.ai_rules_matcher:Match receipt_1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa → txn_1: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E → txn_1: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW → txn_1: flag_for_review=True, auto_approve=False +INFO:__main__:Matching completed, got 8 results +INFO:__main__:Generated stats: {'total': 8, 'high_confidence': 0, 'low_confidence': 7, 'avg_score': 0.18} +INFO:__main__:Match-specific completed successfully with 8 matches +INFO: 102.89.46.156:2103 - "POST /match-specific HTTP/1.1" 200 OK +INFO: 35.203.211.110:50807 - "GET / HTTP/1.0" 200 OK +INFO: 35.203.210.101:53359 - "GET / HTTP/1.0" 200 OK +INFO: 102.89.46.156:8540 - "POST /transactions/import/csv HTTP/1.1" 200 OK +INFO:__main__:Starting match-specific for file IDs: ['1-ocsQytyZP397IrLSEv5j5pco10UTbaq', '1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY', '1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa', '1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E', '1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW', '11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g', '1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl', '1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN'], categorization_id: cat_mh5264l5_q9n774 +INFO:__main__:Found 5 transactions in database +INFO:__main__:Converted 5 transactions +INFO:__main__:Successfully loaded receipt for file_id: 1-ocsQytyZP397IrLSEv5j5pco10UTbaq +INFO:__main__:Successfully loaded receipt for file_id: 1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY +INFO:__main__:Successfully loaded receipt for file_id: 1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa +INFO:__main__:Successfully loaded receipt for file_id: 1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E +INFO:__main__:Successfully loaded receipt for file_id: 1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW +INFO:__main__:Successfully loaded receipt for file_id: 11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g +INFO:__main__:Successfully loaded receipt for file_id: 1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl +INFO:__main__:Successfully loaded receipt for file_id: 1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN +INFO:__main__:Found 8 receipts, 0 missing +INFO:__main__:Starting matching with 8 receipts and 5 transactions +INFO:__main__:Using default/provided user_location: Canada +INFO:__main__:Applying 1 custom AI rules to matching +INFO:services.ai_matcher:Starting AI matching for 8 receipts against 5 transactions +INFO:services.ai_matcher:Processing receipt 1/8: Eleven Labs Inc. - $111.87 +INFO:services.ai_matcher:Found 4 candidates for receipt: Eleven Labs Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Eleven Labs Inc. +- Amount: $111.87 +- Date: 2025-06-10 +- Description: Pro Jun 10 - Jul 10, 2025 +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: UPDATESTACK LLC (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $110.37 (98.7%) +INFO:services.ai_matcher:Processing receipt 2/8: Bzabaowskyj - $37.55 +INFO:services.ai_matcher:Found 4 candidates for receipt: Bzabaowskyj +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Bzabaowskyj +- Amount: $37.55 +- Date: 2024-05-22 +- Description: Paypal *Bzabaowskyj* 4029357733 On +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: UPDATESTACK LLC (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - No exact vendor match +INFO:services.ai_matcher:Processing receipt 3/8: Figma, Inc. - $27.0 +INFO:services.ai_matcher:Found 4 candidates for receipt: Figma, Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Figma, Inc. +- Amount: $27.0 +- Date: 2025-06-19 +- Description: Professional Full seats (monthly) Jun 19 - Jul 19, 2025 +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - No exact vendor match +INFO:services.ai_matcher:Processing receipt 4/8: Google LLC - $21.15 +INFO:services.ai_matcher:Found 4 candidates for receipt: Google LLC +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Google LLC +- Amount: $21.15 +- Date: 2025-05-31 +- Description: Google Workspace +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - No exact vendor match +INFO:services.ai_matcher:Processing receipt 5/8: Figma, Inc. - $27.0 +INFO:services.ai_matcher:Found 4 candidates for receipt: Figma, Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Figma, Inc. +- Amount: $27.0 +- Date: 2025-06-19 +- Description: Professional Full seats (monthly) Jun 19 - Jul 19, 2025 +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 2: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - No exact vendor match +INFO:services.ai_matcher:Processing receipt 6/8: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 5 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: ROMATOKI +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 5: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $38530.37 (100.0%) +INFO:services.ai_matcher:Processing receipt 7/8: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 5 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: Vehicle Purchase +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 5: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $38530.37 (100.0%) +INFO:services.ai_matcher:Processing receipt 8/8: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 5 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: Vehicle: ROMATOKI +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: UPDATESTACK LLC +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 4: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 5: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $38530.37 (100.0%) +INFO:services.ai_matcher:AI matching completed. Found 8 matches +INFO:services.ai_rules_matcher:Applying AI rules to 8 matches with 1 custom rules +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1-ocsQytyZP397IrLSEv5j5pco10UTbaq → txn_3: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY → txn_3: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN → txn_2: flag_for_review=True, auto_approve=False +INFO:__main__:Matching completed, got 8 results +INFO:__main__:Generated stats: {'total': 8, 'high_confidence': 0, 'low_confidence': 8, 'avg_score': 0.0} +INFO:__main__:Match-specific completed successfully with 8 matches +INFO: 102.89.46.156:6610 - "POST /match-specific HTTP/1.1" 200 OK +INFO: 102.89.46.156:6781 - "POST /transactions/import/csv HTTP/1.1" 200 OK +INFO: 102.89.46.156:344 - "POST /transactions/import/csv HTTP/1.1" 200 OK +INFO: 162.216.150.43:54386 - "GET / HTTP/1.0" 200 OK +INFO: 35.203.211.236:54792 - "GET / HTTP/1.0" 200 OK +INFO: 162.216.150.56:49721 - "GET / HTTP/1.0" 200 OK +INFO: 162.216.149.77:49852 - "GET / HTTP/1.0" 200 OK +INFO: 35.203.211.84:50663 - "GET / HTTP/1.0" 200 OK +INFO:__main__:filename: 1.jpg, extension: jpg, google_file_id: 1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD +INFO:__main__:Uploaded new file 1.jpg with ID 1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD +INFO: 199.241.139.243:42236 - "POST /upload-multiple HTTP/1.1" 200 OK +INFO:__main__:Request: file_id=None user_location=None ai_rules=[AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "mkd"', action='SET_CATEGORY: technology'), AIRules(condition='Vendor CONTAINS "aws"', action='SET_CATEGORY: cloud service'), AIRules(condition='Vendor CONTAINS "Maple"', action='SET_CATEGORY: Supercar')] +INFO:services.document_processor:This is the prompt: + Analyze this receipt image and extract the following information in JSON format. + + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "mkd": Set category to "technology" + If the Vendor name contains "aws": Set category to "cloud service" + If the Vendor name contains "Maple": Set category to "Supercar" + + + JSON Format: + { + "vendor": "Store/company name", + "description": "Detailed description of items/services purchased", + "total_amount": 0.00, + "tax_amount": 0.00, + "date": "YYYY-MM-DD", + "category": "Check rules above first", + "confidence": 0.95, + "currency": "USD", + "location": "Province/State, Country", + "calculated_tax": 0.00, + "is_depreciable": false, + "name_of_asset": null, + "cca_rate": null, + "useful_life": null, + "residual_value": null, + "extraction_success": True + } + + EXTRACTION Rules: + - Extract vendor name as it appears on receipt + - Extract description of items/services purchased (e.g., "Coffee and sandwich", "Gasoline", "Office supplies") + - Total amount should be the final total including tax + - Tax amount is separate tax line if available (if not clearly shown, calculate based on location) + - Date should be the date on the receipt + - Confidence score 0-1 based on how clear the receipt is + - Currency should be the currency used on the receipt (e.g., "USD", "EUR", "CAD") + + + LOCATION & TAX RULES: + - Extract location from receipt (look for store address, province/state, country) + - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") + - If location not shown on receipt, return null for location (system will use user location as fallback) + + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: + * Ontario, Canada: 13% HST + * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total + * British Columbia, Canada: 12% (5% GST + 7% PST) + * Alberta, Canada: 5% GST + * California, USA: ~7.25% (varies by locality) + * New York, USA: ~8.875% (varies by locality) + * Texas, USA: 6.25% + * For other locations, estimate based on typical rates + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value + + DEPRECIATION RULES: + - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) + - Set is_depreciable to true only for capital assets, false for consumables/services + - If is_depreciable is true, provide: + * name_of_asset: Specific name/model of the asset (e.g., "2024 Honda Accord", "Dell Laptop XPS 15", "Office Desk") + * cca_rate: CCA rate as decimal (e.g., 0.30 for 30%, 0.20 for 20%, 0.04 for 4%) + - Class 10 (Vehicles): 30% + - Class 8 (Furniture, equipment): 20% + - Class 50 (Computers, software): 55% + - Class 1 (Buildings): 4% + - Class 10.1 (Passenger vehicles >$30k): 30% + * useful_life: Expected years of use (e.g., 5 for computers, 8 for vehicles, 10 for furniture) + * residual_value: Estimated value at end of life (typically 10% of purchase price for equipment, 20% for vehicles) + - If is_depreciable is false, set name_of_asset, cca_rate, useful_life, and residual_value to null + + Return only valid JSON. + +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:__main__:Extracted receipt data: {'vendor': 'TRANSTAR SANITATION SUPPLY LTD', 'description': 'TWIN JR JUMBO TP DISPENSER', 'total_amount': 411.3, 'tax_amount': 44.07, 'date': '2025-09-24', 'category': 'technology', 'confidence': 0.95, 'currency': 'CAD', 'location': 'British Columbia, Canada', 'calculated_tax': None, 'is_depreciable': False, 'name_of_asset': None, 'cca_rate': None, 'useful_life': None, 'residual_value': None, 'extraction_success': True} +INFO: 199.241.139.243:42238 - "POST /process/1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD HTTP/1.1" 200 OK +INFO: 199.241.139.243:45686 - "POST /transactions/import/csv HTTP/1.1" 200 OK +INFO:__main__:Starting match-specific for file IDs: ['1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD', '1-ocsQytyZP397IrLSEv5j5pco10UTbaq', '1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY', '1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa', '1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E', '1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW', '11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g', '1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl', '1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN'], categorization_id: cat_mh9fv7ab_90aosl +INFO:__main__:Found 3 transactions in database +INFO:__main__:Converted 3 transactions +INFO:__main__:Successfully loaded receipt for file_id: 1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD +INFO:__main__:Successfully loaded receipt for file_id: 1-ocsQytyZP397IrLSEv5j5pco10UTbaq +INFO:__main__:Successfully loaded receipt for file_id: 1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY +INFO:__main__:Successfully loaded receipt for file_id: 1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa +INFO:__main__:Successfully loaded receipt for file_id: 1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E +INFO:__main__:Successfully loaded receipt for file_id: 1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW +INFO:__main__:Successfully loaded receipt for file_id: 11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g +INFO:__main__:Successfully loaded receipt for file_id: 1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl +INFO:__main__:Successfully loaded receipt for file_id: 1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN +INFO:__main__:Found 9 receipts, 0 missing +INFO:__main__:Starting matching with 9 receipts and 3 transactions +INFO:__main__:Using default/provided user_location: Canada +INFO:__main__:Applying 1 custom AI rules to matching +INFO:services.ai_matcher:Starting AI matching for 9 receipts against 3 transactions +INFO:services.ai_matcher:Processing receipt 1/9: TRANSTAR SANITATION SUPPLY LTD - $411.3 +INFO:services.ai_matcher:Found 3 candidates for receipt: TRANSTAR SANITATION SUPPLY LTD +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: TRANSTAR SANITATION SUPPLY LTD +- Amount: $411.3 +- Date: 2025-09-24 +- Description: TWIN JR JUMBO TP DISPENSER +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $23.910000000000025 (5.8%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $409.8 (99.6%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $409.8 (99.6%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.870) +INFO:services.ai_matcher:Found match: 0.870 - Exact amount match with similar vendor +INFO:services.ai_matcher:Processing receipt 2/9: Eleven Labs Inc. - $111.87 +INFO:services.ai_matcher:Found 2 candidates for receipt: Eleven Labs Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Eleven Labs Inc. +- Amount: $111.87 +- Date: 2025-06-10 +- Description: Pro Jun 10 - Jul 10, 2025 +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $110.37 (98.7%) +INFO:services.ai_matcher:Processing receipt 3/9: Bzabaowskyj - $37.55 +INFO:services.ai_matcher:Found 2 candidates for receipt: Bzabaowskyj +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Bzabaowskyj +- Amount: $37.55 +- Date: 2024-05-22 +- Description: Paypal *Bzabaowskyj* 4029357733 On +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount very different (>20%) +INFO:services.ai_matcher:Processing receipt 4/9: Figma, Inc. - $27.0 +INFO:services.ai_matcher:Found 2 candidates for receipt: Figma, Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Figma, Inc. +- Amount: $27.0 +- Date: 2025-06-19 +- Description: Professional Full seats (monthly) Jun 19 - Jul 19, 2025 +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount very different (>20%) +INFO:services.ai_matcher:Processing receipt 5/9: Google LLC - $21.15 +INFO:services.ai_matcher:Found 2 candidates for receipt: Google LLC +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Google LLC +- Amount: $21.15 +- Date: 2025-05-31 +- Description: Google Workspace +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $19.65 (92.9%) +INFO:services.ai_matcher:Processing receipt 6/9: Figma, Inc. - $27.0 +INFO:services.ai_matcher:Found 2 candidates for receipt: Figma, Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Figma, Inc. +- Amount: $27.0 +- Date: 2025-06-19 +- Description: Professional Full seats (monthly) Jun 19 - Jul 19, 2025 +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $25.5 (94.4%) +INFO:services.ai_matcher:Processing receipt 7/9: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 3 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: ROMATOKI +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $38530.37 (100.0%) +INFO:services.ai_matcher:Processing receipt 8/9: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 3 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: Vehicle Purchase +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $38530.37 (100.0%) +INFO:services.ai_matcher:Processing receipt 9/9: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 3 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: Vehicle: ROMATOKI +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount very different (>20%) +INFO:services.ai_matcher:AI matching completed. Found 9 matches +INFO:services.ai_rules_matcher:Applying AI rules to 9 matches with 1 custom rules +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD → txn_1: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1-ocsQytyZP397IrLSEv5j5pco10UTbaq → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN → txn_2: flag_for_review=True, auto_approve=False +INFO:__main__:Matching completed, got 9 results +INFO:__main__:Generated stats: {'total': 9, 'high_confidence': 1, 'low_confidence': 8, 'avg_score': 0.1} +INFO:__main__:Match-specific completed successfully with 9 matches +INFO: 199.241.139.243:45700 - "POST /match-specific HTTP/1.1" 200 OK +INFO: 162.216.150.230:54226 - "GET / HTTP/1.0" 200 OK +INFO:__main__:Starting match-specific for file IDs: ['1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD', '1-ocsQytyZP397IrLSEv5j5pco10UTbaq', '1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY', '1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa', '1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E', '1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW', '11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g', '1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl', '1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN'], categorization_id: cat_mh9fv7ab_90aosl +INFO:__main__:Found 3 transactions in database +INFO:__main__:Converted 3 transactions +INFO:__main__:Successfully loaded receipt for file_id: 1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD +INFO:__main__:Successfully loaded receipt for file_id: 1-ocsQytyZP397IrLSEv5j5pco10UTbaq +INFO:__main__:Successfully loaded receipt for file_id: 1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY +INFO:__main__:Successfully loaded receipt for file_id: 1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa +INFO:__main__:Successfully loaded receipt for file_id: 1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E +INFO:__main__:Successfully loaded receipt for file_id: 1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW +INFO:__main__:Successfully loaded receipt for file_id: 11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g +INFO:__main__:Successfully loaded receipt for file_id: 1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl +INFO:__main__:Successfully loaded receipt for file_id: 1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN +INFO:__main__:Found 9 receipts, 0 missing +INFO:__main__:Starting matching with 9 receipts and 3 transactions +INFO:__main__:Using default/provided user_location: Canada +INFO:__main__:Applying 1 custom AI rules to matching +INFO:services.ai_matcher:Starting AI matching for 9 receipts against 3 transactions +INFO:services.ai_matcher:Processing receipt 1/9: TRANSTAR SANITATION SUPPLY LTD - $411.3 +INFO:services.ai_matcher:Found 3 candidates for receipt: TRANSTAR SANITATION SUPPLY LTD +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: TRANSTAR SANITATION SUPPLY LTD +- Amount: $411.3 +- Date: 2025-09-24 +- Description: TWIN JR JUMBO TP DISPENSER +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $23.910000000000025 (5.8%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $409.8 (99.6%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $409.8 (99.6%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.870) +INFO:services.ai_matcher:Found match: 0.870 - Exact amount match with similar vendor +INFO:services.ai_matcher:Processing receipt 2/9: Eleven Labs Inc. - $111.87 +INFO:services.ai_matcher:Found 2 candidates for receipt: Eleven Labs Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Eleven Labs Inc. +- Amount: $111.87 +- Date: 2025-06-10 +- Description: Pro Jun 10 - Jul 10, 2025 +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $110.37 (98.7%) +INFO:services.ai_matcher:Processing receipt 3/9: Bzabaowskyj - $37.55 +INFO:services.ai_matcher:Found 2 candidates for receipt: Bzabaowskyj +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Bzabaowskyj +- Amount: $37.55 +- Date: 2024-05-22 +- Description: Paypal *Bzabaowskyj* 4029357733 On +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - No exact vendor match +INFO:services.ai_matcher:Processing receipt 4/9: Figma, Inc. - $27.0 +INFO:services.ai_matcher:Found 2 candidates for receipt: Figma, Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Figma, Inc. +- Amount: $27.0 +- Date: 2025-06-19 +- Description: Professional Full seats (monthly) Jun 19 - Jul 19, 2025 +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $25.5 (94.4%) +INFO:services.ai_matcher:Processing receipt 5/9: Google LLC - $21.15 +INFO:services.ai_matcher:Found 2 candidates for receipt: Google LLC +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Google LLC +- Amount: $21.15 +- Date: 2025-05-31 +- Description: Google Workspace +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $19.65 (92.9%) +INFO:services.ai_matcher:Processing receipt 6/9: Figma, Inc. - $27.0 +INFO:services.ai_matcher:Found 2 candidates for receipt: Figma, Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Figma, Inc. +- Amount: $27.0 +- Date: 2025-06-19 +- Description: Professional Full seats (monthly) Jun 19 - Jul 19, 2025 +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount very different (>20%) +INFO:services.ai_matcher:Processing receipt 7/9: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 3 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: ROMATOKI +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount very different (>20%) +INFO:services.ai_matcher:Processing receipt 8/9: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 3 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: Vehicle Purchase +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount very different (>20%) +INFO:services.ai_matcher:Processing receipt 9/9: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 3 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: Vehicle: ROMATOKI +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $38530.37 (100.0%) +INFO:services.ai_matcher:AI matching completed. Found 9 matches +INFO:services.ai_rules_matcher:Applying AI rules to 9 matches with 1 custom rules +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +ERROR:services.ai_rules_matcher:Failed to parse LLM response as JSON: Unterminated string starting at: line 5 column 17 (char 151) +ERROR:services.ai_rules_matcher:Response text: { + "flag_for_review": true, + "auto_approve": false, + "rules_applied": ["receipt currency differs from transaction currency"], + "reasons": ["Receipt and transaction currencies differ (CAD vs. CAD is not a match, but the currencies are the same, so this rule is not applicable, however, the built-in rule is applied because the currencies are the same but the rule is based on the fact that they are different, but in this case they are the same, so the built-in rule is not applied, however, the rule is applied because the currencies are the same, but the rule is based on the fact that they are different, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is not applied, but the rule is applied because the currencies are the same, so the built-in rule is +INFO:services.ai_rules_matcher:Match receipt_1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD → txn_1: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1-ocsQytyZP397IrLSEv5j5pco10UTbaq → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +ERROR:services.ai_rules_matcher:Failed to parse LLM response as JSON: Invalid control character at: line 5 column 211 (char 345) +ERROR:services.ai_rules_matcher:Response text: { + "flag_for_review": true, + "auto_approve": false, + "rules_applied": ["receipt currency differs from transaction currency"], + "reasons": ["Receipt and transaction currencies differ (CAD vs. CAD is not a match, but the currencies are the same, so this rule is actually not applicable, however, the built-in rule is applied instead.)] +} +INFO:services.ai_rules_matcher:Match receipt_1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl → txn_2: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +ERROR:services.ai_rules_matcher:Failed to parse LLM response as JSON: Unterminated string starting at: line 5 column 17 (char 151) +ERROR:services.ai_rules_matcher:Response text: { + "flag_for_review": true, + "auto_approve": false, + "rules_applied": ["receipt currency differs from transaction currency"], + "reasons": ["Receipt currency (CAD) differs from transaction currency (CAD) is not possible, but built-in rule applies due to different currency being used in the match details, however, the currencies are the same, but the built-in rule still applies because of the difference in the match quality reason which is amount difference, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference which is a different scenario, but the currencies are the same, so the built-in rule applies because of the amount difference +INFO:services.ai_rules_matcher:Match receipt_1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN → txn_2: flag_for_review=True, auto_approve=False +INFO:__main__:Matching completed, got 9 results +INFO:__main__:Generated stats: {'total': 9, 'high_confidence': 1, 'low_confidence': 8, 'avg_score': 0.1} +INFO:__main__:Match-specific completed successfully with 9 matches +INFO: 199.241.139.243:57876 - "POST /match-specific HTTP/1.1" 200 OK +INFO: 199.241.139.243:59418 - "POST /transactions/import/csv HTTP/1.1" 200 OK +INFO:__main__:Starting match-specific for file IDs: ['1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD', '1-ocsQytyZP397IrLSEv5j5pco10UTbaq', '1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY', '1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa', '1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E', '1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW', '11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g', '1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl', '1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN'], categorization_id: cat_mh9gzb86_y6r8h0 +INFO:__main__:Found 7 transactions in database +INFO:__main__:Converted 7 transactions +INFO:__main__:Successfully loaded receipt for file_id: 1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD +INFO:__main__:Successfully loaded receipt for file_id: 1-ocsQytyZP397IrLSEv5j5pco10UTbaq +INFO:__main__:Successfully loaded receipt for file_id: 1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY +INFO:__main__:Successfully loaded receipt for file_id: 1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa +INFO:__main__:Successfully loaded receipt for file_id: 1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E +INFO:__main__:Successfully loaded receipt for file_id: 1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW +INFO:__main__:Successfully loaded receipt for file_id: 11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g +INFO:__main__:Successfully loaded receipt for file_id: 1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl +INFO:__main__:Successfully loaded receipt for file_id: 1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN +INFO:__main__:Found 9 receipts, 0 missing +INFO:__main__:Starting matching with 9 receipts and 7 transactions +INFO:__main__:Using default/provided user_location: Canada +INFO:__main__:Applying 1 custom AI rules to matching +INFO:services.ai_matcher:Starting AI matching for 9 receipts against 7 transactions +INFO:services.ai_matcher:Processing receipt 1/9: TRANSTAR SANITATION SUPPLY LTD - $411.3 +INFO:services.ai_matcher:Found 6 candidates for receipt: TRANSTAR SANITATION SUPPLY LTD +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: TRANSTAR SANITATION SUPPLY LTD +- Amount: $411.3 +- Date: 2025-09-24 +- Description: TWIN JR JUMBO TP DISPENSER +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $674.08 (absolute: $674.08) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $262.78000000000003 (63.9%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1025.07 (absolute: $1025.07) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $613.77 (149.2%) + +Candidate 3: +- Vendor: Unknown +- Amount: $841.63 (absolute: $841.63) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $430.33 (104.6%) + +Candidate 4: +- Vendor: Unknown +- Amount: $300.0 (absolute: $300.0) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $111.30000000000001 (27.1%) + +Candidate 5: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $23.910000000000025 (5.8%) + +Candidate 6: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (177 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $409.8 (99.6%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 5: Unknown (score: 0.580) +INFO:services.ai_matcher:Found match: 0.580 - Amount match with similar vendor and close date +INFO:services.ai_matcher:Processing receipt 2/9: Eleven Labs Inc. - $111.87 +INFO:services.ai_matcher:Found 2 candidates for receipt: Eleven Labs Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Eleven Labs Inc. +- Amount: $111.87 +- Date: 2025-06-10 +- Description: Pro Jun 10 - Jul 10, 2025 +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $300.0 (absolute: $300.0) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $188.13 (168.2%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (71 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $110.37 (98.7%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 2: Unknown (score: 0.290) +INFO:services.ai_matcher:Found match: 0.290 - Amount similar (98.7%) with no other matches +INFO:services.ai_matcher:Processing receipt 3/9: Bzabaowskyj - $37.55 +INFO:services.ai_matcher:Found 1 candidates for receipt: Bzabaowskyj +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Bzabaowskyj +- Amount: $37.55 +- Date: 2024-05-22 +- Description: Paypal *Bzabaowskyj* 4029357733 On +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (313 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $36.05 (96.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.290) +INFO:services.ai_matcher:Found match: 0.290 - Amount difference: $36.05 (96.0%) +INFO:services.ai_matcher:Processing receipt 4/9: Figma, Inc. - $27.0 +INFO:services.ai_matcher:Found 1 candidates for receipt: Figma, Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Figma, Inc. +- Amount: $27.0 +- Date: 2025-06-19 +- Description: Professional Full seats (monthly) Jun 19 - Jul 19, 2025 +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $25.5 (94.4%) +INFO:services.ai_matcher:Processing receipt 5/9: Google LLC - $21.15 +INFO:services.ai_matcher:Found 1 candidates for receipt: Google LLC +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Google LLC +- Amount: $21.15 +- Date: 2025-05-31 +- Description: Google Workspace +- Category: cloud service + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (61 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $19.65 (92.9%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount very different (>20%) +INFO:services.ai_matcher:Processing receipt 6/9: Figma, Inc. - $27.0 +INFO:services.ai_matcher:Found 1 candidates for receipt: Figma, Inc. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: Figma, Inc. +- Amount: $27.0 +- Date: 2025-06-19 +- Description: Professional Full seats (monthly) Jun 19 - Jul 19, 2025 +- Category: technology + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (80 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $25.5 (94.4%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 1: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $25.5 (94.4%) +INFO:services.ai_matcher:Processing receipt 7/9: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 7 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: ROMATOKI +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $674.08 (absolute: $674.08) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37857.79 (98.3%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1025.07 (absolute: $1025.07) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37506.8 (97.3%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1443.42 (absolute: $1443.42) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37088.450000000004 (96.3%) + +Candidate 4: +- Vendor: Unknown +- Amount: $841.63 (absolute: $841.63) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37690.240000000005 (97.8%) + +Candidate 5: +- Vendor: Unknown +- Amount: $300.0 (absolute: $300.0) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38231.87 (99.2%) + +Candidate 6: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 7: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 7: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: 0.01% +INFO:services.ai_matcher:Processing receipt 8/9: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 7 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: Vehicle Purchase +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $674.08 (absolute: $674.08) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37857.79 (98.3%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1025.07 (absolute: $1025.07) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37506.8 (97.3%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1443.42 (absolute: $1443.42) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37088.450000000004 (96.3%) + +Candidate 4: +- Vendor: Unknown +- Amount: $841.63 (absolute: $841.63) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37690.240000000005 (97.8%) + +Candidate 5: +- Vendor: Unknown +- Amount: $300.0 (absolute: $300.0) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38231.87 (99.2%) + +Candidate 6: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 7: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 7: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: 0.01% +INFO:services.ai_matcher:Processing receipt 9/9: MAPLE LEAF MOTORS INC. - $38531.87 +INFO:services.ai_matcher:Found 7 candidates for receipt: MAPLE LEAF MOTORS INC. +INFO:services.ai_matcher:This is the prompt: You are an expert at matching receipts to bank transactions. Analyze the receipt below against ALL the candidate transactions and return the BEST match. + +RECEIPT TO MATCH: +- Vendor: MAPLE LEAF MOTORS INC. +- Amount: $38531.87 +- Date: 2025-10-07 +- Description: Vehicle: ROMATOKI +- Category: Supercar + +CANDIDATE TRANSACTIONS: + +Candidate 1: +- Vendor: Unknown +- Amount: $674.08 (absolute: $674.08) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37857.79 (98.3%) + +Candidate 2: +- Vendor: Unknown +- Amount: $1025.07 (absolute: $1025.07) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37506.8 (97.3%) + +Candidate 3: +- Vendor: Unknown +- Amount: $1443.42 (absolute: $1443.42) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37088.450000000004 (96.3%) + +Candidate 4: +- Vendor: Unknown +- Amount: $841.63 (absolute: $841.63) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $37690.240000000005 (97.8%) + +Candidate 5: +- Vendor: Unknown +- Amount: $300.0 (absolute: $300.0) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38231.87 (99.2%) + +Candidate 6: +- Vendor: Unknown +- Amount: $387.39 (absolute: $387.39) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank e-Transfer sent +- Amount difference: $38144.48 (99.0%) + +Candidate 7: +- Vendor: Unknown +- Amount: $1.5 (absolute: $1.5) +- Date: 2025-03-31 (190 days difference) +- Notes: Bank INTERAC e-Transfer fee +- Amount difference: $38530.37 (100.0%) + + +SCORING CRITERIA (Amount is the PRIMARY factor): + +Amount Similarity (MOST IMPORTANT - 60% weight): +- Exact match or within 1%: Start at 0.9-1.0 +- Within 5%: Start at 0.75-0.89 +- Within 10%: Start at 0.5-0.74 +- Within 20%: Start at 0.3-0.49 +- More than 20% difference: Start at 0.0-0.29 + +Then adjust UP or DOWN based on: +- Vendor similarity (20% weight): Exact or similar name increases score +- Date proximity (15% weight): Within 7 days increases score, within 30 days moderate increase +- Description/notes match (5% weight): Relevant keywords increase score + +EXAMPLES: +- Amount match + vendor match + close date = 0.95-1.0 (Perfect match) +- Amount match + different vendor + close date = 0.85-0.94 (High confidence) +- Amount match + different vendor + far date = 0.70-0.84 (Medium-high confidence) +- Amount similar (5%) + vendor match = 0.75-0.85 (Medium-high confidence) +- Amount similar (10%) + some matches = 0.50-0.69 (Medium confidence) +- Amount very different (>20%) = 0.0-0.29 regardless of other factors + +CRITICAL: You MUST return valid JSON only. No explanations, no text before or after. + +Return format: +{"candidate_number": 1, "confidence_score": 0.87, "reason": "Exact amount match with similar vendor"} + +Another example: +{"candidate_number": 3, "confidence_score": 0.15, "reason": "Poor match but best available"} + +Return ONLY JSON for the best candidate: +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_matcher:AI selected candidate 7: Unknown (score: 0.000) +INFO:services.ai_matcher:Found match: 0.000 - Amount difference: $38530.37 (100.0%) +INFO:services.ai_matcher:AI matching completed. Found 9 matches +INFO:services.ai_rules_matcher:Applying AI rules to 9 matches with 1 custom rules +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1AIfenLjekjpZbiH-D3OHZkh2hdWo84BD → txn_6: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1-ocsQytyZP397IrLSEv5j5pco10UTbaq → txn_7: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1IPNowE0xtbWUt1aqG8YPPVhqhBaPJsBY → txn_7: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1j6guW-2aBy9pqCOzQGR1_iSCARR3KTGa → txn_7: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1ygCC6SwLP13OY3Tv8UmKYKCfqHZQIO-E → txn_7: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1elaDnpZhtFJezqXZraFbaWxhJMqC9IfW → txn_7: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_11m5rdg47YPr41BKYIMvYdmPnZYnb0K4g → txn_7: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1pjzC6yldJGxbL6n7Q2N6Dthp3e5rWCwl → txn_7: flag_for_review=True, auto_approve=False +INFO:httpx:HTTP Request: POST https://api.groq.com/openai/v1/chat/completions "HTTP/1.1 200 OK" +INFO:services.ai_rules_matcher:Match receipt_1Iv7JThQ59ZunCuUiz6YKRl2OTgbwLtkN → txn_7: flag_for_review=True, auto_approve=False +INFO:__main__:Matching completed, got 9 results +INFO:__main__:Generated stats: {'total': 9, 'high_confidence': 0, 'low_confidence': 8, 'avg_score': 0.13} +INFO:__main__:Match-specific completed successfully with 9 matches +INFO: 199.241.139.243:59430 - "POST /match-specific HTTP/1.1" 200 OK +INFO: 35.203.211.104:55370 - "GET / HTTP/1.0" 200 OK +INFO: 35.203.211.171:53878 - "GET / HTTP/1.0" 200 OK +INFO: 162.216.149.48:53815 - "GET / HTTP/1.0" 200 OK +INFO: Shutting down +INFO: Waiting for application shutdown. +INFO: Application shutdown complete. +INFO: Finished server process [60971] +/root/ds_quickbooks_v2/app/main.py:58: DeprecationWarning: + on_event is deprecated, use lifespan event handlers instead. + + Read more about it in the + [FastAPI docs for Lifespan Events](https://fastapi.tiangolo.com/advanced/events/). + + @app.on_event("startup") +INFO: Started server process [14740] +INFO: Waiting for application startup. +INFO:__main__:Starting up application... +INFO:database:Database tables already exist: ['receipts', 'transactions', 'uploaded_files'] +INFO:__main__:Application startup complete +INFO: Application startup complete. +INFO: Uvicorn running on http://0.0.0.0:8654 (Press CTRL+C to quit)