Spaces:
Sleeping

doluong6 commited on
Commit
ea43bf1
·
verified ·
1 Parent(s): 1520ceb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -348,3 +348,35 @@ async def ds_pyc_cho_xu_ly():
348
 
349
  except Exception as e:
350
  return JSONResponse(content={"error": str(e)}, status_code=500)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
 
349
  except Exception as e:
350
  return JSONResponse(content={"error": str(e)}, status_code=500)
351
+ @app.get("/doanh_thu_dich_vu")
352
+ def doanh_thu_dich_vu():
353
+ all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
354
+
355
+ pyc_files = [f for f in all_files if "Phieu_yeu_cau" in f and f.endswith(".xlsx")]
356
+
357
+ tong = {"HC": 0, "KĐ": 0, "ĐTN": 0}
358
+
359
+ for path in pyc_files:
360
+ try:
361
+ file_path = hf_hub_download(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN, filename=path, local_dir="/tmp")
362
+ wb = openpyxl.load_workbook(file_path, data_only=True)
363
+ sheet = wb.active
364
+
365
+ phan_tich = sheet["AV22"].value
366
+ thanh_tien = sheet["BX24"].value or 0
367
+
368
+ if not isinstance(thanh_tien, (int, float)):
369
+ continue
370
+
371
+ if phan_tich:
372
+ if "HC" in phan_tich.upper():
373
+ tong["HC"] += thanh_tien
374
+ if "KĐ" in phan_tich.upper():
375
+ tong["KĐ"] += thanh_tien
376
+ if "ĐTN" in phan_tich.upper() or "ĐO" in phan_tich.upper():
377
+ tong["ĐTN"] += thanh_tien
378
+
379
+ except Exception as e:
380
+ print(f"Lỗi đọc {path}: {e}")
381
+
382
+ return tong