AhmadYarAI commited on
Commit
dce516f
·
1 Parent(s): b415e0c

feat: add invoice creation logic with SQLAlchemy

Browse files
Files changed (1) hide show
  1. api/invoices.py +25 -0
api/invoices.py CHANGED
@@ -61,4 +61,29 @@ def create_invoice(data: InvoiceCreate, db: Session = Depends(get_db)):
61
  "id": new_invoice.id,
62
  "invoice_no": new_invoice.invoice_number,
63
  "status": "success"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  }
 
61
  "id": new_invoice.id,
62
  "invoice_no": new_invoice.invoice_number,
63
  "status": "success"
64
+ }
65
+
66
+
67
+ @router.get("/{invoice_id}")
68
+ def get_invoice(invoice_id: int, db: Session = Depends(get_db)):
69
+ # Look for the invoice and include its items
70
+ invoice = db.query(Invoice).filter(Invoice.id == invoice_id).first()
71
+
72
+ if not invoice:
73
+ raise HTTPException(status_code=404, detail="Invoice not found")
74
+
75
+ return {
76
+ "invoice_no": invoice.invoice_number,
77
+ "doctor": invoice.doctor_name,
78
+ "clinic": invoice.clinic_name,
79
+ "patient": invoice.patient_name,
80
+ "total": invoice.total_amount,
81
+ "items": [
82
+ {
83
+ "desc": item.description,
84
+ "qty": item.quantity,
85
+ "price": item.price_per_unit,
86
+ "subtotal": item.total_price
87
+ } for item in invoice.items
88
+ ]
89
  }