Spaces:
Sleeping

doluong6 commited on
Commit
262562c
·
verified ·
1 Parent(s): b948787

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -31
app.py CHANGED
@@ -482,38 +482,42 @@ def doanh_thu_theo_thang():
482
  except Exception as e:
483
  return {"error": str(e)}
484
  @app.get("/doanh_thu_noi_bo")
485
- def doanh_thu_noi_bo():
486
- # Tải file từ dataset
487
- file_path = hf_hub_download(
488
- repo_id="doluong6/Quatest1",
489
- filename="Theo doi DTNB & DT 2025.xlsx",
490
- repo_type="dataset"
491
- )
492
-
493
- df = pd.read_excel(file_path, sheet_name="Nội bộ", header=None)
494
-
495
- data = []
496
- tong_chuyen_den = 0
497
- tong_chuyen_di = 0
498
-
499
- for row in df.itertuples(index=False):
500
- phong = str(row[1]).strip() if len(row) > 6 else None # Cột B
501
- chuyen_den = row[5] if isinstance(row[5], (int, float)) else 0 # Cột F
502
- chuyen_di = row[6] if isinstance(row[6], (int, float)) else 0 # Cột G
503
-
504
- if phong and phong != "None" and row[0] >= 4:
505
  data.append({
506
  "Phòng": phong,
507
- "Chuyển đến": chuyen_den,
508
- "Chuyển đi": chuyen_di
509
  })
510
- tong_chuyen_den += chuyen_den
511
- tong_chuyen_di += chuyen_di
512
-
513
- return {
514
- "data": data,
515
- "tong": {
516
- "Tổng chuyển đến": tong_chuyen_den,
517
- "Tổng chuyển đi": tong_chuyen_di
 
 
518
  }
519
- }
 
 
 
 
482
  except Exception as e:
483
  return {"error": str(e)}
484
  @app.get("/doanh_thu_noi_bo")
485
+ async def doanh_thu_noi_bo():
486
+ try:
487
+ ds = hf_hub_download(repo_id="doluong6/Quatest1", filename="Theo doi DTNB & DT 2025.xlsx")
488
+ wb = openpyxl.load_workbook(ds, data_only=True)
489
+ ws = wb["Nội bộ"]
490
+
491
+ data = []
492
+ tong_cd = 0
493
+ tong_di = 0
494
+
495
+ for row in ws.iter_rows(min_row=4):
496
+ phong = row[1].value # cột B
497
+ chuyen_den = row[5].value # cột F
498
+ chuyen_di = row[6].value # cột G
499
+
500
+ if not phong: continue
501
+ cd = chuyen_den if isinstance(chuyen_den, (int, float)) else 0
502
+ di = chuyen_di if isinstance(chuyen_di, (int, float)) else 0
503
+
 
504
  data.append({
505
  "Phòng": phong,
506
+ "Chuyển đến": cd,
507
+ "Chuyển đi": di
508
  })
509
+
510
+ tong_cd += cd
511
+ tong_di += di
512
+
513
+ return {
514
+ "data": data,
515
+ "tong": {
516
+ "Tổng chuyển đến": tong_cd,
517
+ "Tổng chuyển đi": tong_di
518
+ }
519
  }
520
+ except Exception as e:
521
+ print("❌ Lỗi xử lý doanh_thu_noi_bo:", e)
522
+ traceback.print_exc()
523
+ return JSONResponse(status_code=500, content={"error": str(e)})