vanitha commited on
Commit
e40c590
Β·
1 Parent(s): 199a6f1

implemented get api for eligible bill items

Browse files
app/wallet/controllers/wallet_router.py CHANGED
@@ -52,7 +52,7 @@ router = APIRouter(
52
  # Read APIs - Wallet Information
53
  # ────────────────────────────────────────────────────────────────────────────────
54
  @router.get(
55
- "/wallet/eligible-bill-items",
56
  response_model=List[EligibleBillItemResponseSchema]
57
  )
58
  async def get_eligible_bill_items(
@@ -60,7 +60,7 @@ async def get_eligible_bill_items(
60
  ):
61
  return await WalletService.get_eligible_bill_items(
62
  merchant_id=current_user.merchant_id,
63
- staff_id=current_user.user_id
64
  )
65
 
66
  @router.get("/summary/{staff_id}", response_model=WalletSummarySchema)
 
52
  # Read APIs - Wallet Information
53
  # ────────────────────────────────────────────────────────────────────────────────
54
  @router.get(
55
+ "/eligible-bill-items",
56
  response_model=List[EligibleBillItemResponseSchema]
57
  )
58
  async def get_eligible_bill_items(
 
60
  ):
61
  return await WalletService.get_eligible_bill_items(
62
  merchant_id=current_user.merchant_id,
63
+ user_id=current_user.user_id
64
  )
65
 
66
  @router.get("/summary/{staff_id}", response_model=WalletSummarySchema)
app/wallet/schemas/wallet_schema.py CHANGED
@@ -37,9 +37,9 @@ class EligibleBillItemResponseSchema(BaseModel):
37
  sale_id: UUID
38
  bill_number: str
39
  sale_date: datetime
40
- item_id: UUID
41
  item_name: str
42
- quantity: int
43
  amount: float
44
  staff_id: UUID
45
 
 
37
  sale_id: UUID
38
  bill_number: str
39
  sale_date: datetime
40
+ sale_item_id: UUID
41
  item_name: str
42
+ qty: int
43
  amount: float
44
  staff_id: UUID
45
 
app/wallet/services/wallet_service.py CHANGED
@@ -29,25 +29,52 @@ logger = get_logger(__name__)
29
 
30
  class WalletService:
31
  """Service class for staff wallet operations."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  @staticmethod
34
  async def get_eligible_bill_items(
35
  merchant_id: UUID,
36
- staff_id: UUID
37
  ) -> List[dict]:
38
- """
39
- Get eligible bill items for wallet scan screen
40
- - Today's bills
41
- - Staff tagged items
42
- - Not yet claimed
43
- """
44
  async with get_postgres_session() as session:
 
 
 
 
 
 
 
45
  result = await session.execute(
46
  text("""
47
  SELECT
48
  s.sale_id,
49
  s.sale_code AS bill_number,
50
- s.created_at As sale_date,
51
  si.sale_item_id,
52
  si.item_name,
53
  si.qty,
 
29
 
30
  class WalletService:
31
  """Service class for staff wallet operations."""
32
+ @staticmethod
33
+ async def get_staff_id_by_user(
34
+ session,
35
+ merchant_id: UUID,
36
+ user_id: UUID
37
+ ) -> UUID | None:
38
+ result = await session.execute(
39
+ text("""
40
+ SELECT staff_id
41
+ FROM trans.pos_staff_ref
42
+ WHERE merchant_id = :merchant_id
43
+ AND user_id = :user_id
44
+ """),
45
+ {
46
+ "merchant_id": str(merchant_id),
47
+ "user_id": str(user_id)
48
+ }
49
+ )
50
+
51
+ row = result.first()
52
+
53
+ if not row:
54
+ return None
55
+
56
+ return row.staff_id
57
+
58
 
59
  @staticmethod
60
  async def get_eligible_bill_items(
61
  merchant_id: UUID,
62
+ user_id: UUID
63
  ) -> List[dict]:
 
 
 
 
 
 
64
  async with get_postgres_session() as session:
65
+ staff_id = await WalletService.get_staff_id_by_user(
66
+ session=session,
67
+ merchant_id=merchant_id,
68
+ user_id=user_id
69
+ )
70
+ if not staff_id:
71
+ return []
72
  result = await session.execute(
73
  text("""
74
  SELECT
75
  s.sale_id,
76
  s.sale_code AS bill_number,
77
+ s.created_at AS sale_date,
78
  si.sale_item_id,
79
  si.item_name,
80
  si.qty,