Upload 3 files
Browse files- app.py +6 -1
- query_seller_sale.py +58 -0
- seller.py +204 -0
app.py
CHANGED
@@ -63,7 +63,8 @@ menu_options = [
|
|
63 |
{"label": "External users", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
64 |
{"label": "Recon checking", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
65 |
{"label": "Manual BQ upload", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
66 |
-
{"label": "Invoice splitter", "icon": "π", "description": "Schedule an email with BigQuery data"}
|
|
|
67 |
]
|
68 |
|
69 |
# Create the custom option menu
|
@@ -398,5 +399,9 @@ elif selected_option == "Invoice splitter":
|
|
398 |
with open('splitter.py') as file:
|
399 |
exec(file.read())
|
400 |
|
|
|
|
|
|
|
|
|
401 |
|
402 |
|
|
|
63 |
{"label": "External users", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
64 |
{"label": "Recon checking", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
65 |
{"label": "Manual BQ upload", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
66 |
+
{"label": "Invoice splitter", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
67 |
+
{"label": "Seller sale validation", "icon": "π", "description": "Schedule an email with BigQuery data"}
|
68 |
]
|
69 |
|
70 |
# Create the custom option menu
|
|
|
399 |
with open('splitter.py') as file:
|
400 |
exec(file.read())
|
401 |
|
402 |
+
elif selected_option == "Seller sale validation":
|
403 |
+
with open('seller.py') as file:
|
404 |
+
exec(file.read())
|
405 |
+
|
406 |
|
407 |
|
query_seller_sale.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# query_seller_sale.py
|
2 |
+
queries = {
|
3 |
+
"query": """
|
4 |
+
select
|
5 |
+
*,
|
6 |
+
(seller_sale_cc - tds_cc - tcs_cc) as seller_net_cc,
|
7 |
+
round((seller_sale_cc - tds_cc - tcs_cc - seller_net_collection),2) as net_diff_cc,
|
8 |
+
Concat(bag_id,",")as conccat,
|
9 |
+
COUNT(bag_cc) as comment,
|
10 |
+
concat(company_id,'_',segement_code, '_', settlement_model_code, '_', order_type) as ledger_name
|
11 |
+
from
|
12 |
+
(
|
13 |
+
select
|
14 |
+
company_id,
|
15 |
+
company_name,
|
16 |
+
ordering_channel,
|
17 |
+
segement_code,
|
18 |
+
sales_channel,
|
19 |
+
settlement_model,
|
20 |
+
settlement_model_code,
|
21 |
+
order_type,
|
22 |
+
recon_status,
|
23 |
+
fiscal_Year,
|
24 |
+
bag_id,
|
25 |
+
settlement_type,
|
26 |
+
Concat(bag_id,settlement_type) as bag_cc ,
|
27 |
+
mrp,
|
28 |
+
seller_discounts,
|
29 |
+
store_discount_amount,
|
30 |
+
bca,
|
31 |
+
vog,
|
32 |
+
tds_on_bca,
|
33 |
+
tcs_on_vog,
|
34 |
+
seller_fees,
|
35 |
+
seller_tender_value,
|
36 |
+
seller_net_collection,
|
37 |
+
mrp - seller_discounts -store_discount_amount as bca_cc,
|
38 |
+
bca - (mrp - seller_discounts -store_discount_amount) as diff_bca_cc,
|
39 |
+
round((mrp - seller_discounts -store_discount_amount)*100/(100 +product_gst_perc),2) as vog_cc,
|
40 |
+
vog - (round((mrp - seller_discounts -store_discount_amount)*100/(100 +product_gst_perc),2)) as diff_vog_cc,
|
41 |
+
CASE
|
42 |
+
WHEN segement_code = 'FY' or segement_code = 'UN' THEN (mrp - seller_discounts -store_discount_amount)*0.01
|
43 |
+
ELSE 0
|
44 |
+
END as tds_cc,
|
45 |
+
CASE
|
46 |
+
WHEN segement_code = 'FY' or segement_code = 'UN' THEN (round((mrp - seller_discounts -store_discount_amount)*100/(100 +product_gst_perc),2))*0.005
|
47 |
+
ELSE 0
|
48 |
+
END as tcs_cc,
|
49 |
+
(mrp - seller_discounts -store_discount_amount - seller_tender_value + seller_fees) as seller_sale_cc
|
50 |
+
from
|
51 |
+
`fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
|
52 |
+
where
|
53 |
+
expected_payout_date between "2024-09-03"
|
54 |
+
and "2024-09-09"
|
55 |
+
) as A
|
56 |
+
group by all
|
57 |
+
"""
|
58 |
+
}
|
seller.py
ADDED
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from google.cloud import bigquery
|
2 |
+
import functions_framework
|
3 |
+
from query_seller_sale import queries
|
4 |
+
from google.oauth2 import service_account
|
5 |
+
import json
|
6 |
+
import requests
|
7 |
+
import streamlit as st
|
8 |
+
import pyperclip
|
9 |
+
from ap import send_message_via_webhook, Webhook_urls
|
10 |
+
import pandas as pd
|
11 |
+
import io
|
12 |
+
import time
|
13 |
+
|
14 |
+
# Dropdown for channels/members
|
15 |
+
# webhook_url = list(Webhook_urls.keys())
|
16 |
+
html_subject = """
|
17 |
+
<html>
|
18 |
+
<head>
|
19 |
+
<style>
|
20 |
+
.button {
|
21 |
+
display: inline-block;
|
22 |
+
padding: 10px 20px;
|
23 |
+
border-radius: 12px;
|
24 |
+
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
|
25 |
+
box-shadow:
|
26 |
+
0 6px 12px rgba(0, 0, 0, 0.3),
|
27 |
+
0 8px 16px rgba(0, 0, 0, 0.2),
|
28 |
+
inset 0 -2px 4px rgba(255, 255, 255, 0.6);
|
29 |
+
text-align: center;
|
30 |
+
position: relative;
|
31 |
+
transform: translateY(4px);
|
32 |
+
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
|
33 |
+
cursor: pointer;
|
34 |
+
user-select: none;
|
35 |
+
}
|
36 |
+
.button:hover {
|
37 |
+
box-shadow:
|
38 |
+
0 8px 16px rgba(0, 0, 0, 0.3),
|
39 |
+
0 12px 24px rgba(0, 0, 0, 0.2);
|
40 |
+
transform: translateY(2px);
|
41 |
+
}
|
42 |
+
.button:active {
|
43 |
+
box-shadow:
|
44 |
+
0 4px 8px rgba(0, 0, 0, 0.3),
|
45 |
+
0 6px 12px rgba(0, 0, 0, 0.2);
|
46 |
+
transform: translateY(0);
|
47 |
+
}
|
48 |
+
.progress-bar {
|
49 |
+
height: 20px; /* Adjusted thickness */
|
50 |
+
width: 100%;
|
51 |
+
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
|
52 |
+
border-radius: 12px;
|
53 |
+
position: relative;
|
54 |
+
overflow: hidden;
|
55 |
+
}
|
56 |
+
.progress-bar span {
|
57 |
+
display: block;
|
58 |
+
height: 100%;
|
59 |
+
width: 0%;
|
60 |
+
background: linear-gradient(to right, #ff0000, #ff4d4d); /* Red gradient */
|
61 |
+
transition: width 0.3s ease;
|
62 |
+
}
|
63 |
+
</style>
|
64 |
+
</head>
|
65 |
+
</html>
|
66 |
+
"""
|
67 |
+
|
68 |
+
st.markdown(html_subject, unsafe_allow_html=True)
|
69 |
+
# selection = st.multiselect("", webhook_url)
|
70 |
+
|
71 |
+
def check_duplicates(credentials_file):
|
72 |
+
"""Check for duplicates using BigQuery with the provided credentials file."""
|
73 |
+
results = {}
|
74 |
+
credentials = service_account.Credentials.from_service_account_info(json.loads(credentials_file))
|
75 |
+
client = bigquery.Client(credentials=credentials, project=credentials.project_id)
|
76 |
+
|
77 |
+
query = queries["query"] # Access the query string from the dictionary
|
78 |
+
|
79 |
+
# Show a loading spinner
|
80 |
+
with st.spinner(":red[Performing seller sale validation...]"):
|
81 |
+
# Create a custom progress bar
|
82 |
+
progress_bar = st.empty()
|
83 |
+
progress_bar.markdown(
|
84 |
+
"""
|
85 |
+
<div class="progress-bar">
|
86 |
+
<span id="progress"></span>
|
87 |
+
</div>
|
88 |
+
""", unsafe_allow_html=True
|
89 |
+
)
|
90 |
+
|
91 |
+
try:
|
92 |
+
query_job = client.query(query)
|
93 |
+
# Simulate loading progress
|
94 |
+
for percent_complete in range(0, 101, 10):
|
95 |
+
time.sleep(0.1) # Simulate work being done
|
96 |
+
progress_bar.markdown(
|
97 |
+
f"""
|
98 |
+
<div class="progress-bar">
|
99 |
+
<span style="width: {percent_complete}%;"></span>
|
100 |
+
</div>
|
101 |
+
""", unsafe_allow_html=True
|
102 |
+
)
|
103 |
+
df = query_job.result().to_dataframe()
|
104 |
+
st.write("", df)
|
105 |
+
except Exception as e:
|
106 |
+
st.error(f"An error occurred: {e}")
|
107 |
+
return results
|
108 |
+
|
109 |
+
if not df.empty:
|
110 |
+
results["Query Result"] = df
|
111 |
+
|
112 |
+
return results
|
113 |
+
|
114 |
+
# Streamlit UI
|
115 |
+
html_subject = """
|
116 |
+
<html>
|
117 |
+
<head>
|
118 |
+
<style>
|
119 |
+
.button {
|
120 |
+
display: inline-block;
|
121 |
+
padding: 10px 20px;
|
122 |
+
border-radius: 12px;
|
123 |
+
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
|
124 |
+
box-shadow:
|
125 |
+
0 6px 12px rgba(0, 0, 0, 0.3),
|
126 |
+
0 8px 16px rgba(0, 0, 0, 0.2),
|
127 |
+
inset 0 -2px 4px rgba(255, 255, 255, 0.6);
|
128 |
+
text-align: center;
|
129 |
+
position: relative;
|
130 |
+
transform: translateY(4px);
|
131 |
+
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
|
132 |
+
cursor: pointer;
|
133 |
+
user-select: none;
|
134 |
+
}
|
135 |
+
.button:hover {
|
136 |
+
box-shadow:
|
137 |
+
0 8px 16px rgba(0, 0, 0, 0.3),
|
138 |
+
0 12px 24px rgba(0, 0, 0, 0.2);
|
139 |
+
transform: translateY(2px);
|
140 |
+
}
|
141 |
+
.button:active {
|
142 |
+
box-shadow:
|
143 |
+
0 4px 8px rgba(0, 0, 0, 0.3),
|
144 |
+
0 6px 12px rgba(0, 0, 0, 0.2);
|
145 |
+
transform: translateY(0);
|
146 |
+
}
|
147 |
+
</style>
|
148 |
+
</head>
|
149 |
+
<body>
|
150 |
+
<div class="button">
|
151 |
+
<h3 style="
|
152 |
+
font-size: 20px;
|
153 |
+
color: #ffffff;
|
154 |
+
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
|
155 |
+
background-clip: text;
|
156 |
+
-webkit-background-clip: text;
|
157 |
+
text-fill-color: transparent;
|
158 |
+
-webkit-text-fill-color: transparent;
|
159 |
+
margin: 0;
|
160 |
+
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
|
161 |
+
">Upload service a/c credentials</h3>
|
162 |
+
</div>
|
163 |
+
</body>
|
164 |
+
</html>
|
165 |
+
"""
|
166 |
+
|
167 |
+
st.markdown(html_subject, unsafe_allow_html=True)
|
168 |
+
|
169 |
+
# Upload credentials file
|
170 |
+
credentials_file = st.file_uploader("", type="json")
|
171 |
+
|
172 |
+
if credentials_file is not None:
|
173 |
+
# Read the credentials file
|
174 |
+
credentials_data = credentials_file.read().decode("utf-8")
|
175 |
+
|
176 |
+
# Check for duplicates
|
177 |
+
results = check_duplicates(credentials_data)
|
178 |
+
|
179 |
+
if "Query Result" in results:
|
180 |
+
df = results["Query Result"]
|
181 |
+
|
182 |
+
# Download buttons
|
183 |
+
csv = df.to_csv(index=False)
|
184 |
+
excel = io.BytesIO()
|
185 |
+
with pd.ExcelWriter(excel, engine='openpyxl') as writer:
|
186 |
+
df.to_excel(writer, index=False)
|
187 |
+
excel.seek(0)
|
188 |
+
|
189 |
+
col1, col2 = st.columns([0.125, 0.5])
|
190 |
+
with col1:
|
191 |
+
st.download_button(
|
192 |
+
label=":red[Download CSV]",
|
193 |
+
data=csv,
|
194 |
+
file_name="seller_sale_recon.csv",
|
195 |
+
mime="text/csv"
|
196 |
+
)
|
197 |
+
|
198 |
+
with col2:
|
199 |
+
st.download_button(
|
200 |
+
label=":red[Download Excel]",
|
201 |
+
data=excel,
|
202 |
+
file_name="seller_sale_recon.xlsx",
|
203 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
204 |
+
)
|