import streamlit as st import pandas as pd import requests from datetime import datetime import pytz # SheetDB API Endpoint for Timecard Data SHEETDB_API_URL_TIMECARD = "https://sheetdb.io/api/v1/jsh4nri7t8rko" # Replace with your SheetDB API URL for timecard # Define password PASSWORD = "ma_12345" # Replace with your desired password # Hardcoded Metadata METADATA = { "Employee Names": [ "Ubaid Bashir", "Shoaib Ahmad", "Rumaan Hassan Alamgeer", "Sana Sanaullah", "Aafreen Mushtaq", "Andleeb Gul" ], "Project Names": [ "ICCL", "Reston", "BAC","Stormwater", "NISA Engineering", "Paramount", "Preng", "Misc.", "Marketing" ], "Project Codes": [ "US 001", "US 003", "US 004", "US 005", "US 006", 'US 008',"IND 001", "IND 007" ] } # Load timecard data from SheetDB def load_data(): response = requests.get(SHEETDB_API_URL_TIMECARD) if response.status_code == 200: return pd.DataFrame(response.json()) else: return pd.DataFrame(columns=["Employee Name", "Project Name", "Project Code", "Date", "Hours", "Notes"]) # Save timecard data to SheetDB def save_data(employee_name, project_name, project_code, hours, notes): # Automatically set the date to the current date ist = pytz.timezone('Asia/Kolkata') ist_now = datetime.now(ist) # Format to get only the date formatted_date = ist_now.date().isoformat() new_entry = { "Employee Name": employee_name, "Project Name": project_name, "Project Code": project_code, "Date": formatted_date, "Hours": hours, "Notes": notes } response = requests.post(SHEETDB_API_URL_TIMECARD, json=new_entry) if response.status_code == 201: st.success("Entry added successfully!") else: st.error("Failed to add entry. Please try again.") # Custom Cyberpunk CSS (Less Glowy) st.markdown( """ """, unsafe_allow_html=True ) # Password authentication if "authenticated" not in st.session_state: st.session_state.authenticated = False if not st.session_state.authenticated: st.markdown("

Munshi Associates Dashboard

", unsafe_allow_html=True) st.markdown("

Please enter the password to access the application.

", unsafe_allow_html=True) password = st.text_input("Password", type="password") if st.button("Login"): if password == PASSWORD: st.session_state.authenticated = True st.success("Login successful!") else: st.error("Incorrect password. Please try again.") else: # Display company logo and title in the sidebar st.sidebar.image("ma_logo.png") # Replace with your logo st.sidebar.markdown("

Munshi Associates Dashboard

", unsafe_allow_html=True) st.sidebar.markdown("

Employee Timecard Management System

", unsafe_allow_html=True) # Main section st.markdown("

Employee Time Card Management

", unsafe_allow_html=True) st.markdown("

Welcome to the Munshi Associates Time Card Management System

", unsafe_allow_html=True) # Load metadata (hardcoded) employee_names = METADATA["Employee Names"] project_names = METADATA["Project Names"] project_codes = METADATA["Project Codes"] # Form for adding timecard entries st.markdown("

Add Timecard Entry

", unsafe_allow_html=True) with st.form("timecard_form"): st.markdown("

Fill out the form below to add a new entry.

", unsafe_allow_html=True) col1, col2 = st.columns(2) with col1: employee_name = st.selectbox("Select Employee Name", employee_names) project_name = st.selectbox("Select Project Name", project_names) project_code = st.selectbox("Select Project Code", project_codes) with col2: hours = st.number_input("Hours Worked", min_value=0.0, step=0.5) notes = st.text_area("Notes", placeholder="Add any relevant notes here...") submitted = st.form_submit_button("Add Entry") if submitted: save_data(employee_name, project_name, project_code, hours, notes) # Display existing timecard data st.markdown("

Existing Time Card Data

", unsafe_allow_html=True) data = load_data() st.dataframe(data, use_container_width=True) # Option to download the data st.markdown("

Download Time Card Data

", unsafe_allow_html=True) st.download_button( label="Download CSV", data=data.to_csv(index=False), file_name="timecard_data.csv", mime="text/csv" )