Spaces:
Sleeping

doluong6 commited on
Commit
c4ee47d
·
verified ·
1 Parent(s): 3ffc93b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -696,7 +696,7 @@ async def quan_ly_hoa_chat():
696
  df = pd.read_excel(file_path, sheet_name="HOA CHAT SU DUNG")
697
  df = df.fillna("")
698
 
699
- # Cột Ngày nhập kho và Ngày hết hạn có thể là datetime
700
  def xu_ly_tinh_trang(row):
701
  try:
702
  ngay_nhap = pd.to_datetime(row['NGÀY NHẬP KHO'])
@@ -704,13 +704,25 @@ async def quan_ly_hoa_chat():
704
  hom_nay = pd.Timestamp.today()
705
  con_lai = (het_han - hom_nay).days
706
  if con_lai < 0:
707
- return f"HẾT HẠN ({ngay_nhap.date()} - {het_han.date()})"
 
 
708
  else:
709
- return f"CÒN: {con_lai} NGÀY ({ngay_nhap.date()} - {het_han.date()})"
710
  except:
711
- return row.get("TÌNH TRẠNG", "") # fallback
712
 
713
- df["TÌNH TRẠNG"] = df.apply(xu_ly_tinh_trang, axis=1)
 
 
 
 
 
 
 
 
 
 
714
 
715
  columns = df.columns.tolist()
716
  rows = df.astype(str).values.tolist()
@@ -719,3 +731,4 @@ async def quan_ly_hoa_chat():
719
 
720
  except Exception as e:
721
  raise HTTPException(status_code=500, detail=f"Lỗi đọc danh sách hóa chất: {str(e)}")
 
 
696
  df = pd.read_excel(file_path, sheet_name="HOA CHAT SU DUNG")
697
  df = df.fillna("")
698
 
699
+ # === Xử lý tình trạng + màu sắc ===
700
  def xu_ly_tinh_trang(row):
701
  try:
702
  ngay_nhap = pd.to_datetime(row['NGÀY NHẬP KHO'])
 
704
  hom_nay = pd.Timestamp.today()
705
  con_lai = (het_han - hom_nay).days
706
  if con_lai < 0:
707
+ return f"HẾT HẠN ({ngay_nhap.date()} - {het_han.date()})", "red"
708
+ elif con_lai <= 30:
709
+ return f"SẮP HẾT HẠN ({con_lai} ngày)", "orange"
710
  else:
711
+ return f"CÒN: {con_lai} NGÀY", ""
712
  except:
713
+ return row.get("TÌNH TRẠNG", ""), ""
714
 
715
+ # Áp dụng cho từng dòng
716
+ tinh_trang = []
717
+ colors = []
718
+
719
+ for _, row in df.iterrows():
720
+ tt, mau = xu_ly_tinh_trang(row)
721
+ tinh_trang.append(tt)
722
+ colors.append(mau)
723
+
724
+ df["TÌNH TRẠNG"] = tinh_trang
725
+ df["MÀU"] = colors # Thêm cột màu vào kết quả
726
 
727
  columns = df.columns.tolist()
728
  rows = df.astype(str).values.tolist()
 
731
 
732
  except Exception as e:
733
  raise HTTPException(status_code=500, detail=f"Lỗi đọc danh sách hóa chất: {str(e)}")
734
+