AnnasBlackHat commited on
Commit
e31db5b
1 Parent(s): 6f80885
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +21 -5
  3. requirements.txt +22 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
app.py CHANGED
@@ -2,12 +2,23 @@ import streamlit as st
2
  import pandas as pd
3
  import requests
4
  from datetime import datetime
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # Function to make API request
7
  # @st.cache_data
8
  def make_api_request(product_name, outlet_name, start_date):
9
  # Replace the following URL with your actual API endpoint
10
- api_url = "https://api-report.uniq-dev.xyz/v1/simulation/fifo"
11
 
12
  start_date_str = start_date.strftime("%Y-%m-%d")
13
  print('--- timestamp', start_date_str)
@@ -48,7 +59,7 @@ with st.form("my_form"):
48
  # Input fields
49
  product_name = st.text_input("Product Name")
50
  outlet_name = st.text_input("Outlet Name")
51
- start_date = st.date_input("Start Date (stock in)")
52
 
53
  # Checkbox to show/hide detail table
54
  show_detail = st.checkbox("Show Detail Table")
@@ -65,6 +76,8 @@ with st.form("my_form"):
65
 
66
  if api_data and api_data["data"]:
67
  # st.json(api_data)
 
 
68
  # Convert API response to DataFrame
69
  df = pd.json_normalize(api_data["data"])
70
  # Check if column exists
@@ -124,7 +137,7 @@ with st.form("my_form"):
124
 
125
  with st.form("edit_form"):
126
  st.write("## Edit the data")
127
- stock_key = st.text_input("Stock Key (e.g. stock_opname #802)")
128
  stock_in = st.number_input("Updated Qty Stock In", min_value=0)
129
  update = st.form_submit_button("Update")
130
  if update:
@@ -140,7 +153,7 @@ with st.form("edit_form"):
140
  print('--- update: ', data)
141
 
142
  # API endpoint
143
- api_url = "https://api-report.uniq-dev.xyz/v1/simulation/fifo"
144
 
145
  # Make the PUT request
146
  response = requests.put(api_url, data=data)
@@ -148,4 +161,7 @@ with st.form("edit_form"):
148
  if response.status_code == 200:
149
  st.success("Update successful!")
150
  else:
151
- st.error(f"Update failed. Status code: {response.status_code}")
 
 
 
 
2
  import pandas as pd
3
  import requests
4
  from datetime import datetime
5
+ from dotenv import load_dotenv
6
+ import os
7
+ import time
8
+ from datetime import datetime, date
9
+
10
+
11
+ load_dotenv()
12
+ base_url = os.getenv("BASE_URL")
13
+
14
+ # Cache to store requests
15
+ cache = {}
16
 
17
  # Function to make API request
18
  # @st.cache_data
19
  def make_api_request(product_name, outlet_name, start_date):
20
  # Replace the following URL with your actual API endpoint
21
+ api_url = base_url + "/v1/simulation/fifo"
22
 
23
  start_date_str = start_date.strftime("%Y-%m-%d")
24
  print('--- timestamp', start_date_str)
 
59
  # Input fields
60
  product_name = st.text_input("Product Name")
61
  outlet_name = st.text_input("Outlet Name")
62
+ start_date = st.date_input("Start Date (stock in)", value = date.today().replace(day = 1))
63
 
64
  # Checkbox to show/hide detail table
65
  show_detail = st.checkbox("Show Detail Table")
 
76
 
77
  if api_data and api_data["data"]:
78
  # st.json(api_data)
79
+ timestamp = time.strftime("%H:%M:%S")
80
+ cache[timestamp] = api_data['data']
81
  # Convert API response to DataFrame
82
  df = pd.json_normalize(api_data["data"])
83
  # Check if column exists
 
137
 
138
  with st.form("edit_form"):
139
  st.write("## Edit the data")
140
+ stock_key = st.text_input("Table Key (e.g. stock_opname #802)")
141
  stock_in = st.number_input("Updated Qty Stock In", min_value=0)
142
  update = st.form_submit_button("Update")
143
  if update:
 
153
  print('--- update: ', data)
154
 
155
  # API endpoint
156
+ api_url = base_url + "/v1/simulation/fifo"
157
 
158
  # Make the PUT request
159
  response = requests.put(api_url, data=data)
 
161
  if response.status_code == 200:
162
  st.success("Update successful!")
163
  else:
164
+ st.error(f"Update failed. Status code: {response.status_code}")
165
+
166
+ st.write("### History")
167
+ # Create tabs
requirements.txt ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.2.0
2
+ blinker==1.7.0
3
+ cachetools==5.3.2
4
+ click==8.1.7
5
+ importlib-metadata==6.11.0
6
+ numpy==1.26.2
7
+ pandas==2.1.4
8
+ Pillow==10.1.0
9
+ protobuf==4.25.1
10
+ pyarrow==14.0.2
11
+ pydeck==0.8.1b0
12
+ python-dotenv==1.0.0
13
+ pytz==2023.3.post1
14
+ streamlit==1.29.0
15
+ streamlit-option-menu==0.3.6
16
+ tenacity==8.2.3
17
+ toml==0.10.2
18
+ toolz==0.12.0
19
+ tzdata==2023.3
20
+ tzlocal==5.2
21
+ validators==0.22.0
22
+ watchdog==3.0.0