Skip to content

fix: correct column/table names in daily_operations_report#14

Open
coder-contrib-bot wants to merge 1 commit into
mainfrom
claude-code/fix-daily-operations-report/k8m2f9x1
Open

fix: correct column/table names in daily_operations_report#14
coder-contrib-bot wants to merge 1 commit into
mainfrom
claude-code/fix-daily-operations-report/k8m2f9x1

Conversation

@coder-contrib-bot
Copy link
Copy Markdown
Collaborator

Summary\n\nFixes the GET /api/reports/daily-operations endpoint which was returning a 500 Internal Server Error due to SQL queries referencing non-existent columns and tables.\n\nRoot cause: The raw SQL queries in daily_operations_report used generic column names (id, created_at, category) and table names (sale_items, payments) that don't match the actual database schema.\n\nFixes applied:\n- sales_invoices: idinvoice_id, created_atinvoice_date\n- sale_itemssales_invoice_items, quantitysold_quantity\n- purchase_invoices: idpurchase_invoice_id, created_atpurchase_date\n- expenses: idexpense_id, categoryexpense_category\n- payments (non-existent table) → customer_payments / supplier_payments\n- customers: idcustomer_id, created_atcreated_date\n- products: idproduct_id, nameproduct_name\n- Returns query: use sales_returns table instead of filtering sales_invoices by a non-existent status column\n\n## Test plan\n\n- [ ] Restart the backend container and hit GET /api/reports/daily-operations\n- [ ] Verify the endpoint returns a 200 with the expected JSON structure\n- [ ] Verify sales, purchases, expenses, returns, payments, and top products data is populated correctly from the database\n\n---\n\nAuthor: GIT_AUTHOR_NAME=Contrib, GIT_AUTHOR_EMAIL=coder.github.robot@gmail.com\n\nThis PR was generated by an AI Agent (Claude Code, Opus 4.7).\n\n🤖 Generated with Claude Code"

The daily_operations_report endpoint was using incorrect column and table
names that don't match the actual database schema, causing a 500 error.

Fixes:
- sales_invoices: id → invoice_id, created_at → invoice_date
- sale_items → sales_invoice_items, quantity → sold_quantity
- purchase_invoices: id → purchase_invoice_id, created_at → purchase_date
- expenses: id → expense_id, category → expense_category
- payments table → customer_payments/supplier_payments (separate tables)
- customers: id → customer_id, created_at → created_date
- products: id → product_id, name → product_name
- returns: use sales_returns table instead of cancelled sales_invoices

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant