Spaces:
Sleeping
Sleeping
yroo changes da washo
Browse files- __pycache__/main.cpython-313.pyc +0 -0
- api/__pycache__/__init__.cpython-313.pyc +0 -0
- api/__pycache__/invoices.cpython-313.pyc +0 -0
- api/invoices.py +11 -2
- core/__pycache__/__init__.cpython-313.pyc +0 -0
- core/__pycache__/database.cpython-313.pyc +0 -0
- main.py +39 -2
- models/__pycache__/__init__.cpython-313.pyc +0 -0
- models/__pycache__/invoice.cpython-313.pyc +0 -0
- models/invoice.py +3 -1
__pycache__/main.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/main.cpython-313.pyc and b/__pycache__/main.cpython-313.pyc differ
|
|
|
api/__pycache__/__init__.cpython-313.pyc
CHANGED
|
Binary files a/api/__pycache__/__init__.cpython-313.pyc and b/api/__pycache__/__init__.cpython-313.pyc differ
|
|
|
api/__pycache__/invoices.cpython-313.pyc
CHANGED
|
Binary files a/api/__pycache__/invoices.cpython-313.pyc and b/api/__pycache__/invoices.cpython-313.pyc differ
|
|
|
api/invoices.py
CHANGED
|
@@ -15,6 +15,8 @@ except ImportError:
|
|
| 15 |
router = APIRouter(prefix="/invoices", tags=["Invoices"])
|
| 16 |
|
| 17 |
class ItemCreate(BaseModel):
|
|
|
|
|
|
|
| 18 |
description: str
|
| 19 |
quantity: int
|
| 20 |
price_per_unit: float
|
|
@@ -34,14 +36,17 @@ class InvoiceCreate(BaseModel):
|
|
| 34 |
def create_invoice(data: InvoiceCreate, db: Session = Depends(get_db)):
|
| 35 |
# 1. Calculate total
|
| 36 |
total = sum(item.quantity * item.price_per_unit for item in data.items)
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# 2. Create the invoice object
|
| 39 |
new_invoice = Invoice(
|
| 40 |
date=data.date or datetime.utcnow(),
|
| 41 |
doctor_name=data.doctor_name,
|
| 42 |
clinic_name=data.clinic_name,
|
| 43 |
-
patient_name=
|
| 44 |
-
shade=
|
| 45 |
total_amount=total,
|
| 46 |
received_amount=data.received_amount,
|
| 47 |
remaining_balance=total - data.received_amount,
|
|
@@ -62,6 +67,8 @@ def create_invoice(data: InvoiceCreate, db: Session = Depends(get_db)):
|
|
| 62 |
for item in data.items:
|
| 63 |
db.add(InvoiceItem(
|
| 64 |
invoice_id=new_invoice.id,
|
|
|
|
|
|
|
| 65 |
description=item.description,
|
| 66 |
quantity=item.quantity,
|
| 67 |
price_per_unit=item.price_per_unit,
|
|
@@ -97,6 +104,8 @@ def get_invoice(invoice_id: int, db: Session = Depends(get_db)):
|
|
| 97 |
"remaining_balance": invoice.remaining_balance,
|
| 98 |
"items": [
|
| 99 |
{
|
|
|
|
|
|
|
| 100 |
"description": item.description,
|
| 101 |
"quantity": item.quantity,
|
| 102 |
"price_per_unit": item.price_per_unit,
|
|
|
|
| 15 |
router = APIRouter(prefix="/invoices", tags=["Invoices"])
|
| 16 |
|
| 17 |
class ItemCreate(BaseModel):
|
| 18 |
+
patient_name: str
|
| 19 |
+
shade: str
|
| 20 |
description: str
|
| 21 |
quantity: int
|
| 22 |
price_per_unit: float
|
|
|
|
| 36 |
def create_invoice(data: InvoiceCreate, db: Session = Depends(get_db)):
|
| 37 |
# 1. Calculate total
|
| 38 |
total = sum(item.quantity * item.price_per_unit for item in data.items)
|
| 39 |
+
first_item = data.items[0] if data.items else None
|
| 40 |
+
invoice_patient = data.patient_name or (first_item.patient_name if first_item else "")
|
| 41 |
+
invoice_shade = data.shade or (first_item.shade if first_item else "")
|
| 42 |
|
| 43 |
# 2. Create the invoice object
|
| 44 |
new_invoice = Invoice(
|
| 45 |
date=data.date or datetime.utcnow(),
|
| 46 |
doctor_name=data.doctor_name,
|
| 47 |
clinic_name=data.clinic_name,
|
| 48 |
+
patient_name=invoice_patient,
|
| 49 |
+
shade=invoice_shade,
|
| 50 |
total_amount=total,
|
| 51 |
received_amount=data.received_amount,
|
| 52 |
remaining_balance=total - data.received_amount,
|
|
|
|
| 67 |
for item in data.items:
|
| 68 |
db.add(InvoiceItem(
|
| 69 |
invoice_id=new_invoice.id,
|
| 70 |
+
patient_name=item.patient_name,
|
| 71 |
+
shade=item.shade,
|
| 72 |
description=item.description,
|
| 73 |
quantity=item.quantity,
|
| 74 |
price_per_unit=item.price_per_unit,
|
|
|
|
| 104 |
"remaining_balance": invoice.remaining_balance,
|
| 105 |
"items": [
|
| 106 |
{
|
| 107 |
+
"patient_name": item.patient_name,
|
| 108 |
+
"shade": item.shade,
|
| 109 |
"description": item.description,
|
| 110 |
"quantity": item.quantity,
|
| 111 |
"price_per_unit": item.price_per_unit,
|
core/__pycache__/__init__.cpython-313.pyc
CHANGED
|
Binary files a/core/__pycache__/__init__.cpython-313.pyc and b/core/__pycache__/__init__.cpython-313.pyc differ
|
|
|
core/__pycache__/database.cpython-313.pyc
CHANGED
|
Binary files a/core/__pycache__/database.cpython-313.pyc and b/core/__pycache__/database.cpython-313.pyc differ
|
|
|
main.py
CHANGED
|
@@ -3,6 +3,9 @@ import sys
|
|
| 3 |
from pathlib import Path
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
sys.path.append(str(Path(__file__).parent))
|
| 8 |
|
|
@@ -15,8 +18,42 @@ except ImportError:
|
|
| 15 |
|
| 16 |
Base.metadata.create_all(bind=engine)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
app = FastAPI(title="SmiloCAD API", redirect_slashes=False)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
app.add_middleware(
|
| 21 |
CORSMiddleware,
|
| 22 |
allow_origins=[
|
|
@@ -28,6 +65,6 @@ app.add_middleware(
|
|
| 28 |
|
| 29 |
@app.get("/")
|
| 30 |
def root():
|
| 31 |
-
return
|
| 32 |
|
| 33 |
-
app.include_router(invoice_router, prefix="/api")
|
|
|
|
| 3 |
from pathlib import Path
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
+
from fastapi.responses import FileResponse
|
| 7 |
+
from fastapi.staticfiles import StaticFiles
|
| 8 |
+
from sqlalchemy import inspect, text
|
| 9 |
|
| 10 |
sys.path.append(str(Path(__file__).parent))
|
| 11 |
|
|
|
|
| 18 |
|
| 19 |
Base.metadata.create_all(bind=engine)
|
| 20 |
|
| 21 |
+
def _ensure_schema():
|
| 22 |
+
inspector = inspect(engine)
|
| 23 |
+
|
| 24 |
+
migrations = {
|
| 25 |
+
"invoices": {
|
| 26 |
+
"patient_name": "VARCHAR",
|
| 27 |
+
"shade": "VARCHAR",
|
| 28 |
+
},
|
| 29 |
+
"invoice_items": {
|
| 30 |
+
"patient_name": "VARCHAR",
|
| 31 |
+
"shade": "VARCHAR",
|
| 32 |
+
},
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
with engine.begin() as conn:
|
| 36 |
+
for table_name, columns in migrations.items():
|
| 37 |
+
if not inspector.has_table(table_name):
|
| 38 |
+
continue
|
| 39 |
+
|
| 40 |
+
existing_columns = {col["name"] for col in inspector.get_columns(table_name)}
|
| 41 |
+
for column_name, column_type in columns.items():
|
| 42 |
+
if column_name in existing_columns:
|
| 43 |
+
continue
|
| 44 |
+
conn.execute(text(f"ALTER TABLE {table_name} ADD COLUMN {column_name} {column_type}"))
|
| 45 |
+
|
| 46 |
+
_ensure_schema()
|
| 47 |
+
|
| 48 |
app = FastAPI(title="SmiloCAD API", redirect_slashes=False)
|
| 49 |
|
| 50 |
+
BASE_DIR = Path(__file__).resolve().parent.parent
|
| 51 |
+
FRONTEND_DIR = BASE_DIR / "frontend"
|
| 52 |
+
|
| 53 |
+
app.mount("/css", StaticFiles(directory=FRONTEND_DIR / "css"), name="css")
|
| 54 |
+
app.mount("/js", StaticFiles(directory=FRONTEND_DIR / "js"), name="js")
|
| 55 |
+
app.mount("/img", StaticFiles(directory=FRONTEND_DIR / "img"), name="img")
|
| 56 |
+
|
| 57 |
app.add_middleware(
|
| 58 |
CORSMiddleware,
|
| 59 |
allow_origins=[
|
|
|
|
| 65 |
|
| 66 |
@app.get("/")
|
| 67 |
def root():
|
| 68 |
+
return FileResponse(FRONTEND_DIR / "index.html")
|
| 69 |
|
| 70 |
+
app.include_router(invoice_router, prefix="/api")
|
models/__pycache__/__init__.cpython-313.pyc
CHANGED
|
Binary files a/models/__pycache__/__init__.cpython-313.pyc and b/models/__pycache__/__init__.cpython-313.pyc differ
|
|
|
models/__pycache__/invoice.cpython-313.pyc
CHANGED
|
Binary files a/models/__pycache__/invoice.cpython-313.pyc and b/models/__pycache__/invoice.cpython-313.pyc differ
|
|
|
models/invoice.py
CHANGED
|
@@ -33,9 +33,11 @@ class InvoiceItem(Base):
|
|
| 33 |
|
| 34 |
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
| 35 |
invoice_id = Column(Integer, ForeignKey("invoices.id"))
|
|
|
|
|
|
|
| 36 |
description = Column(String)
|
| 37 |
quantity = Column(Integer)
|
| 38 |
price_per_unit = Column(Float)
|
| 39 |
total_price = Column(Float)
|
| 40 |
|
| 41 |
-
invoice = relationship("Invoice", back_populates="items")
|
|
|
|
| 33 |
|
| 34 |
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
| 35 |
invoice_id = Column(Integer, ForeignKey("invoices.id"))
|
| 36 |
+
patient_name = Column(String)
|
| 37 |
+
shade = Column(String)
|
| 38 |
description = Column(String)
|
| 39 |
quantity = Column(Integer)
|
| 40 |
price_per_unit = Column(Float)
|
| 41 |
total_price = Column(Float)
|
| 42 |
|
| 43 |
+
invoice = relationship("Invoice", back_populates="items")
|