╔══════════════════ DATABASE SCHEMA SUMMARY ══════════════════════════════╗ ║ 1. parties — Party master: id, name, phone, city, party_type, ║ ║ past_due, is_active, previous_names (JSON) ║ ║ 2. mirchi_types — Mirchi varieties: id, name, is_active ║ ║ 3. transactions — Awaak/Jawaak bills: bill_number, bill_date, ║ ║ bill_type(awaak|jawaak), party_id, total_amount, ║ ║ paid_amount, balance_amount, expenses(JSON), ║ ║ lot_number, is_mixed, is_return ║ ║ 4. transaction_items — Line items: mirchi_name, poti_count, ║ ║ poti_weights, net_weight, rate_per_kg, amount ║ ║ 5. transaction_payments — Payments per bill: amount, mode, reference, ║ ║ is_reversed ║ ║ 6. patti_transactions — Patti bills (patti_awaak|patti_jawaak): ║ ║ same as transactions + gross_weight, ║ ║ verified_net_weight ║ ║ 7. patti_transaction_items — Same structure as transaction_items ║ ║ 8. party_jama_entries — Standalone payments: party_id, date, amount, ║ ║ reference, notes ║ ║ 9. stock_ledger — Stock movements: mirchi_name, movement_type ║ ║ (IN|OUT|RETURN_IN|RETURN_OUT), quantity_in/out, ║ ║ balance_after, lot_number ║ ║ 10.bill_number_sequences — Auto-numbering: bill_type, year, batch(A-Z),║ ║ current_number (resets at 500 → next batch) ║ ╚═════════════════════════════════════════════════════════════════════════╝ ============================================================ LIVE DATABASE TABLES (11 tables found) ============================================================ 📋 ALEMBIC_VERSION (1 rows) Column Type Nullable ----------------------------------- ------------------------- -------- version_num character varying NO 📋 BILL_NUMBER_SEQUENCES (4 rows) Column Type Nullable ----------------------------------- ------------------------- -------- id integer NO bill_type character varying NO year integer NO batch character varying NO current_number integer NO is_full boolean NO created_at timestamp with time zone NO updated_at timestamp with time zone NO 📋 MIRCHI_TYPES (5 rows) Column Type Nullable ----------------------------------- ------------------------- -------- id character varying NO name character varying NO is_active boolean NO created_at timestamp with time zone NO updated_at timestamp with time zone NO 📋 PARTIES (6 rows) Column Type Nullable ----------------------------------- ------------------------- -------- id character varying NO name character varying NO previous_names json YES phone character varying NO city character varying YES party_type USER-DEFINED NO past_due double precision NO notes text YES is_active boolean NO created_at timestamp with time zone NO updated_at timestamp with time zone NO 📋 PARTY_JAMA_ENTRIES (12 rows) Column Type Nullable ----------------------------------- ------------------------- -------- id character varying NO party_id character varying NO date character varying NO amount double precision NO reference character varying YES notes text YES created_at timestamp with time zone NO updated_at timestamp with time zone NO 📋 PATTI_TRANSACTION_ITEMS (6 rows) Column Type Nullable ----------------------------------- ------------------------- -------- id character varying NO transaction_id character varying NO mirchi_name character varying NO mirchi_id character varying YES poti_count integer NO poti_weights text YES net_weight double precision NO rate_per_kg double precision NO amount double precision NO 📋 PATTI_TRANSACTIONS (6 rows) Column Type Nullable ----------------------------------- ------------------------- -------- id character varying NO bill_number character varying NO bill_date character varying NO bill_type USER-DEFINED NO party_id character varying NO party_name character varying NO party_name_current character varying NO party_phone character varying NO subtotal double precision NO total_amount double precision NO paid_amount double precision NO balance_amount double precision NO expenses json YES lot_number character varying YES gross_weight double precision YES verified_net_weight double precision YES is_return boolean NO original_bill_id character varying YES return_bill_id character varying YES created_at timestamp with time zone NO updated_at timestamp with time zone NO payment_method character varying YES 📋 STOCK_LEDGER (19 rows) Column Type Nullable ----------------------------------- ------------------------- -------- id character varying NO mirchi_name character varying NO mirchi_id character varying YES transaction_id character varying YES patti_transaction_id character varying YES movement_type character varying NO quantity_in double precision NO quantity_out double precision NO balance_after double precision NO lot_number character varying YES created_at timestamp with time zone NO 📋 TRANSACTION_ITEMS (13 rows) Column Type Nullable ----------------------------------- ------------------------- -------- id character varying NO transaction_id character varying NO mirchi_name character varying NO mirchi_id character varying YES poti_count integer NO poti_weights text YES net_weight double precision NO rate_per_kg double precision NO amount double precision NO source character varying YES 📋 TRANSACTION_PAYMENTS (14 rows) Column Type Nullable ----------------------------------- ------------------------- -------- id character varying NO transaction_id character varying NO amount double precision NO mode character varying NO reference character varying YES paid_at character varying YES is_reversed boolean NO reversed_at timestamp with time zone YES created_at timestamp with time zone NO 📋 TRANSACTIONS (11 rows) Column Type Nullable ----------------------------------- ------------------------- -------- id character varying NO bill_number character varying NO bill_date character varying NO bill_type USER-DEFINED NO party_id character varying NO party_name character varying NO party_name_current character varying NO party_phone character varying NO subtotal double precision NO total_amount double precision NO paid_amount double precision NO balance_amount double precision NO expenses json YES lot_number character varying YES is_mixed boolean NO is_return boolean NO original_bill_id character varying YES return_bill_id character varying YES created_at timestamp with time zone NO updated_at timestamp with time zone NO payment_method character varying YES ====================================================================== MIRCHI TRADING — ALL API ENDPOINTS + EXAMPLE RESPONSES ====================================================================== Base URL: http://localhost:8000 [01] GET /api/parties ↳ List all parties (with live current_balance) Params: party_type, search, skip, limit Response: { "success": true, "data": [ { "id": "p-abc123", "name": "रामलाल ट्रेडर्स", "phone": "9876543210", "city": "नांदेड", "party_type": "both", ... ───────────────────────────────────────────────────────────────── [02] GET /api/parties/{party_id} ↳ Single party with computed current_balance Response: { "success": true, "data": { "id": "p-abc123", "name": "रामलाल ट्रेडर्स", "phone": "9876543210", "city": "नांदेड", "party_type": "both", "past_due": 5000.0, "current_balanc... ───────────────────────────────────────────────────────────────── [03] GET /api/parties/{party_id}/name-history ↳ Full rename history for a party Response: { "party_id": "p-abc123", "current_name": "रामलाल ट्रेडर्स", "name_history": [ "रामलाल", "रामलाल एंटरप्रायझेस" ] } ───────────────────────────────────────────────────────────────── [04] POST /api/parties ↳ Create a new party Body: { "name": "श्याम ट्रेडर्स", "phone": "9988776655", "city": "लातूर", "party_type": "jawaak", "past_due": 0.0 } Response: { "success": true, "message": "Party created successfully", "data": { "id": "p-xyz789", "name": "श्याम ट्रेडर्स" } } ───────────────────────────────────────────────────────────────── [05] PUT /api/parties/{party_id} ↳ Update party (rename auto-saves to history) Body: { "name": "श्याम एंटरप्रायझेस", "phone": "9988776655" } Response: { "success": true, "message": "Party updated successfully" } ───────────────────────────────────────────────────────────────── [06] DELETE /api/parties/{party_id} ↳ Soft-delete a party (sets is_active=False) Response: { "success": true, "message": "Party deactivated successfully" } ───────────────────────────────────────────────────────────────── [07] GET /api/mirchi-types ↳ List mirchi varieties Params: active_only=true, skip, limit Response: { "success": true, "data": [ { "id": "m-aaa111", "name": "लाल मिरची", "is_active": true }, { "id": "m-bbb222", "name... ───────────────────────────────────────────────────────────────── [08] GET /api/mirchi-types/{mirchi_id} ↳ Single mirchi type by ID Response: { "success": true, "data": { "id": "m-aaa111", "name": "लाल मिरची", "is_active": true } } ───────────────────────────────────────────────────────────────── [09] POST /api/mirchi-types ↳ Create new mirchi type Body: { "name": "काळी मिरची" } Response: { "success": true, "message": "Mirchi type created successfully", "data": { "id": "m-ccc333", "name": "काळी मिरची" } } ───────────────────────────────────────────────────────────────── [10] PUT /api/mirchi-types/{mirchi_id} ↳ Update mirchi type name or active status Body: { "name": "काळी मिरची XL", "is_active": true } Response: { "success": true, "message": "Mirchi type updated successfully" } ───────────────────────────────────────────────────────────────── [11] DELETE /api/mirchi-types/{mirchi_id} ↳ Hard delete a mirchi type Response: { "success": true, "message": "Mirchi type deleted successfully" } ───────────────────────────────────────────────────────────────── [12] GET /api/transactions ↳ List all transactions with filters Params: bill_type(awaak|jawaak), party_id, search, start_date, end_date, skip, limit Response: { "success": true, "data": [ { "id": "t-111aaa", "bill_number": "A2025A001", "bill_date": "2025-03-15", "bill_type": "awaak", "party_id": "p-abc123"... ───────────────────────────────────────────────────────────────── [13] GET /api/transactions/next-bill-number ↳ Get next auto-generated bill number Params: bill_type=awaak Response: { "success": true, "bill_number": "A2025A002" } ───────────────────────────────────────────────────────────────── [14] GET /api/transactions/bill-number-info ↳ Batch/sequence info for bill numbering Params: bill_type=awaak&year=2025 Response: { "success": true, "bill_type": "awaak", "year": 2025, "current_batch": "A", "current_number": 2, "remaining": 498 } ───────────────────────────────────────────────────────────────── [15] GET /api/transactions/{transaction_id} ↳ Get single transaction by ID with items & payments Response: { "success": true, "data": { "id": "t-111aaa", "bill_number": "A2025A001" } } ───────────────────────────────────────────────────────────────── [16] POST /api/transactions ↳ Create a new Awaak or Jawaak transaction Body: { "bill_type": "awaak", "bill_date": "2025-03-15", "party_id": "p-abc123", "lot_number": "LOT001", "items": [ { "mirchi_... Response: { "success": true, "message": "Transaction created successfully", "data": { "id": "t-111aaa", "bill_number": "A2025A001", "total_amount": 15200.0 } } ───────────────────────────────────────────────────────────────── [17] POST /api/transactions/{transaction_id}/payment ↳ Add payment to a transaction Params: amount=5000 Response: { "success": true, "message": "Payment updated successfully" } ───────────────────────────────────────────────────────────────── [18] POST /api/transactions/{transaction_id}/revert ↳ Revert a transaction (creates return bill, reverses stock) Response: { "success": true, "message": "Transaction reverted successfully" } ───────────────────────────────────────────────────────────────── [19] DELETE /api/transactions/{transaction_id} ↳ Delete a transaction Response: { "success": true, "message": "Transaction deleted successfully" } ───────────────────────────────────────────────────────────────── [20] GET /api/patti-transactions ↳ List all patti transactions Params: bill_type(patti_awaak|patti_jawaak), party_id, search, start_date, end_date, skip, limit Response: { "success": true, "data": [ { "id": "pt-222bbb", "bill_number": "PA2025A001", "bill_type": "patti_awaak", "party_name": "गणेश पाटील", "lot_number":... ───────────────────────────────────────────────────────────────── [21] GET /api/patti-transactions/lots/available/{mirchi_id} ↳ Get available patti lots for Jawaak billing (with weight/bag info) Response: { "success": true, "data": [ { "id": "patti-lot-PLOT001", "lot_number": "PLOT001", "mirchi_name": "लाल मिरची", "gross_weight": 1000.0, "remaining_qu... ───────────────────────────────────────────────────────────────── [22] GET /api/patti-transactions/next-bill-number ↳ Get next patti bill number Params: bill_type=patti_awaak Response: { "success": true, "bill_number": "PA2025A001" } ───────────────────────────────────────────────────────────────── [23] POST /api/patti-transactions ↳ Create a patti_awaak or patti_jawaak transaction Body: { "bill_type": "patti_awaak", "bill_date": "2025-03-15", "party_id": "p-abc123", "lot_number": "PLOT001", "gross_weight": 1000.0, "verified_net_weight":... Response: { "success": true, "message": "Patti transaction created successfully", "data": { "id": "pt-222bbb", "bill_number": "PA2025A001" } } ───────────────────────────────────────────────────────────────── [24] POST /api/patti-transactions/{transaction_id}/payment ↳ Add payment to patti transaction Params: amount=10000 Response: { "success": true, "message": "Payment updated successfully" } ───────────────────────────────────────────────────────────────── [25] POST /api/patti-transactions/{transaction_id}/revert ↳ Revert patti transaction (reverses stock from patti holdings) Response: { "success": true, "message": "Patti transaction reverted successfully" } ───────────────────────────────────────────────────────────────── [26] DELETE /api/patti-transactions/{transaction_id} ↳ Delete a patti transaction Response: { "success": true, "message": "Patti transaction deleted successfully" } ───────────────────────────────────────────────────────────────── [27] GET /api/stock-ledger ↳ List all stock movement entries Params: mirchi_name, movement_type(IN|OUT|RETURN_IN|RETURN_OUT), lot_number, start_date, end_date, skip, limit Response: { "success": true, "data": [ { "id": "sl-333ccc", "mirchi_name": "लाल मिरची", "movement_type": "IN", "quantity_in": 500.0, "quantity_out": 0.0, ... ───────────────────────────────────────────────────────────────── [28] GET /api/stock-ledger/summary ↳ Summary of current stock by mirchi type Response: { "success": true, "data": [ { "mirchi_name": "लाल मिरची", "balance": 500.0, "total_in": 1000.0, "total_out": 500.0 } ] } ───────────────────────────────────────────────────────────────── [29] GET /api/stock-ledger/lots ↳ Lot-wise stock summary (patti lot tracking) Params: mirchi_name (optional) Response: { "success": true, "data": [ { "mirchi_name": "लाल मिरची", "lot_number": "PLOT001", "balance": 480.0, "total_in": 980.0, "total_out": 500.0 ... ───────────────────────────────────────────────────────────────── [30] GET /api/stock-ledger/available/{mirchi_id} ↳ Available lots for Jawaak billing (balance > 0) Response: { "success": true, "data": [ { "id": "lot-PLOT001", "lot_number": "PLOT001", "remaining_quantity": 480.0, "poti_count": 9, "display": "PLOT001 | 480... ───────────────────────────────────────────────────────────────── [31] GET /api/stock-ledger/balance/{mirchi_name} ↳ Get current balance for a specific mirchi (optionally by lot) Params: lot_number (optional) Response: { "success": true, "data": { "mirchi_name": "लाल मिरची", "lot_number": null, "current_balance": 500.0 } } ───────────────────────────────────────────────────────────────── [32] GET /api/stock-ledger/analysis ↳ Lot-wise P&L analysis (buy qty/amt vs sell qty/amt) Response: { "success": true, "data": [ { "lot_number": "LOT001", "mirchi_name": "लाल मिरची", "farmer_name": "रामलाल ट्रेडर्स", "buy_qty": 500.0, "buy_amt": 15... ───────────────────────────────────────────────────────────────── [33] GET /api/stock-ledger/{ledger_id} ↳ Single stock ledger entry by ID Response: { "success": true, "data": { "id": "sl-333ccc", "movement_type": "IN" } } ───────────────────────────────────────────────────────────────── [34] GET /api/party-jama ↳ List all standalone jama (payment) entries Params: party_id, start_date, end_date, skip, limit Response: { "success": true, "data": [ { "id": "pj-444ddd", "party_id": "p-abc123", "date": "2025-03-14", "amount": 5000.0, "reference": "UPI-123", ... ───────────────────────────────────────────────────────────────── [35] GET /api/party-jama/party/{party_id}/balance ↳ Party's computed balance (transactions + jama) Response: { "success": true, "data": { "party_id": "p-abc123", "past_due": 5000.0, "regular_balance": 7500.0, "patti_balance": 0.0, "jama_total": 2000.0, "current_balance": 10500.0 } } ───────────────────────────────────────────────────────────────── [36] GET /api/party-jama/party/{party_id}/ledger ↳ Full chronological party ledger (bills + jama entries merged) Params: start_date, end_date Response: { "success": true, "data": { "party": { "id": "p-abc123", "name": "रामलाल ट्रेडर्स" }, "entries": [ { "date": "2025-03-10", ... ───────────────────────────────────────────────────────────────── [37] POST /api/party-jama ↳ Create a standalone jama (payment) entry Body: { "party_id": "p-abc123", "date": "2025-03-15", "amount": 5000.0, "reference": "UPI-456", "notes": "आगाऊ रक्कम" } Response: { "success": true, "message": "Jama entry created successfully", "data": { "id": "pj-555eee" } } ───────────────────────────────────────────────────────────────── [38] PUT /api/party-jama/{entry_id} ↳ Update a jama entry Body: { "amount": 6000.0, "notes": "सुधारित रक्कम" } Response: { "success": true, "message": "Jama entry updated successfully" } ───────────────────────────────────────────────────────────────── [39] DELETE /api/party-jama/{entry_id} ↳ Delete a jama entry Response: { "success": true, "message": "Jama entry deleted successfully" } ───────────────────────────────────────────────────────────────── [40] GET /health ↳ App health check Response: { "status": "healthy", "app": "Mirchi Trading API", "version": "1.0.0" } ───────────────────────────────────────────────────────────────── [41] GET / ↳ Root info endpoint Response: { "message": "Welcome to Mirchi Trading API", "version": "1.0.0", "docs": "/docs" } ───────────────────────────────────────────────────────────────── ====================================================================== TOTAL ENDPOINTS: 41 ====================================================================== ✅ Documentation complete. API docs also available at: http://localhost:8000/docs