- Backend: FastAPI app with all models, services, schemas, routes - Admin Panel: Next.js dashboard with all modules (CRM, POS, repairs, warranties, billing, notifications, etc.) - Ecommerce: storefront (submodule) + product catalog - AI Agents: .agents/ skill library for Antigravity IDE - Docs: architecture, billing, notification gateway markdown - Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
86 lines
3.3 KiB
Python
86 lines
3.3 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, Query, status, Request
|
|
from sqlalchemy.orm import Session
|
|
from typing import List, Optional, Any
|
|
|
|
from app.core.database.db_session import get_db
|
|
from app.core.permissions.RoleChecker import get_current_user
|
|
from app.models.UserModel import User
|
|
from app.services.BillingFinanceService import BillingFinanceService
|
|
from app.schemas.BillingFinance import (
|
|
CrmBulkQuotationCreate, CrmBulkQuotationResponse,
|
|
CrmGstInvoiceCreate, CrmGstInvoiceResponse, CrmRecordPayment
|
|
)
|
|
|
|
router = APIRouter(prefix="/api/v1/billing-finance", tags=["Billing & GST Finance Management"])
|
|
|
|
|
|
def get_billing_service(request: Request, db: Session = Depends(get_db)) -> BillingFinanceService:
|
|
tenant_id = getattr(request.state, "tenant_id", "tenant_default")
|
|
return BillingFinanceService(db=db, tenant_id=tenant_id)
|
|
|
|
|
|
# --- BULK QUOTATION ENDPOINTS ---
|
|
@router.post("/quotations", response_model=CrmBulkQuotationResponse, status_code=status.HTTP_201_CREATED)
|
|
def create_bulk_quotation(
|
|
payload: CrmBulkQuotationCreate,
|
|
svc: BillingFinanceService = Depends(get_billing_service),
|
|
current_user: User = Depends(get_current_user)
|
|
) -> Any:
|
|
"""Creates a formal B2B bulk quotation estimate."""
|
|
return svc.create_quotation(payload)
|
|
|
|
|
|
@router.get("/quotations", response_model=List[CrmBulkQuotationResponse])
|
|
def list_bulk_quotations(
|
|
svc: BillingFinanceService = Depends(get_billing_service),
|
|
current_user: User = Depends(get_current_user)
|
|
) -> Any:
|
|
"""Lists all B2B bulk quotations."""
|
|
return svc.list_quotations()
|
|
|
|
|
|
@router.post("/quotations/{quote_id}/convert", response_model=CrmGstInvoiceResponse)
|
|
def convert_quotation_to_invoice(
|
|
quote_id: str,
|
|
svc: BillingFinanceService = Depends(get_billing_service),
|
|
current_user: User = Depends(get_current_user)
|
|
) -> Any:
|
|
"""Converts an approved B2B bulk quotation into a formal GST Tax Invoice."""
|
|
res = svc.convert_quote_to_invoice(quote_id)
|
|
if not res or (isinstance(res, dict) and "error" in res):
|
|
raise HTTPException(status_code=404, detail="Quotation not found or already converted")
|
|
return res
|
|
|
|
|
|
# --- GST TAX INVOICE ENDPOINTS ---
|
|
@router.post("/invoices", response_model=CrmGstInvoiceResponse, status_code=status.HTTP_201_CREATED)
|
|
def create_gst_invoice(
|
|
payload: CrmGstInvoiceCreate,
|
|
svc: BillingFinanceService = Depends(get_billing_service),
|
|
current_user: User = Depends(get_current_user)
|
|
) -> Any:
|
|
"""Creates a new GST Tax Invoice with itemized IMEI warranty stamping and CGST/SGST/IGST calculation."""
|
|
return svc.create_invoice(payload)
|
|
|
|
|
|
@router.get("/invoices", response_model=List[CrmGstInvoiceResponse])
|
|
def list_gst_invoices(
|
|
svc: BillingFinanceService = Depends(get_billing_service),
|
|
current_user: User = Depends(get_current_user)
|
|
) -> Any:
|
|
"""Lists all GST Tax Invoices."""
|
|
return svc.list_invoices()
|
|
|
|
|
|
@router.post("/invoices/{invoice_id}/payment", response_model=CrmGstInvoiceResponse)
|
|
def record_invoice_payment(
|
|
invoice_id: str,
|
|
payload: CrmRecordPayment,
|
|
svc: BillingFinanceService = Depends(get_billing_service),
|
|
current_user: User = Depends(get_current_user)
|
|
) -> Any:
|
|
"""Records payment for a GST Tax Invoice."""
|
|
invoice = svc.record_payment(invoice_id, payload)
|
|
if not invoice:
|
|
raise HTTPException(status_code=404, detail="GST Invoice not found")
|
|
return invoice
|