Upload 2 files
Browse files- query_seller_sale.py +138 -92
- seller.py +164 -78
query_seller_sale.py
CHANGED
|
@@ -1,102 +1,148 @@
|
|
| 1 |
-
# query_seller_sale.py\
|
| 2 |
-
|
| 3 |
queries = {
|
| 4 |
-
"
|
| 5 |
WITH seller_net_data AS (
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
),
|
| 63 |
|
| 64 |
-
-- Subquery to count occurrences of each bag_id and concatenation of bag_id and settlement_type
|
| 65 |
-
bag_con_count_data AS (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
SELECT
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
FROM
|
| 73 |
-
seller_net_data
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
SELECT
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
"""
|
| 102 |
}
|
|
|
|
|
|
|
|
|
|
| 1 |
queries = {
|
| 2 |
+
"query_seller_net_data": """
|
| 3 |
WITH seller_net_data AS (
|
| 4 |
+
SELECT
|
| 5 |
+
company_id,
|
| 6 |
+
company_name,
|
| 7 |
+
ordering_channel,
|
| 8 |
+
segement_code,
|
| 9 |
+
sales_channel,
|
| 10 |
+
settlement_model,
|
| 11 |
+
settlement_model_code,
|
| 12 |
+
order_type,
|
| 13 |
+
order_date,
|
| 14 |
+
fiscal_year,
|
| 15 |
+
bag_id,
|
| 16 |
+
settlement_type,
|
| 17 |
+
recon_status,
|
| 18 |
+
return_window_date,
|
| 19 |
+
payout_window_date,
|
| 20 |
+
expected_payout_date,
|
| 21 |
+
sett_no,
|
| 22 |
+
sett_id,
|
| 23 |
+
mrp,
|
| 24 |
+
seller_discounts,
|
| 25 |
+
store_discount_amount,
|
| 26 |
+
bca,
|
| 27 |
+
product_gst_perc,
|
| 28 |
+
round(vog,2) as vog,
|
| 29 |
+
tds_on_bca,
|
| 30 |
+
tcs_on_vog,
|
| 31 |
+
seller_fees,
|
| 32 |
+
seller_tender_value,
|
| 33 |
+
round(seller_net_collection,2) as seller_net_collection,
|
| 34 |
+
ROUND(mrp - seller_discounts - store_discount_amount,2) AS bca_cc,
|
| 35 |
+
ROUND(bca - (mrp - seller_discounts - store_discount_amount),2) AS diff_bca_cc,
|
| 36 |
+
ROUND((mrp - seller_discounts - store_discount_amount) * 100 / (100 + ABS(product_gst_perc)), 2) AS vog_cc,
|
| 37 |
+
ROUND(vog - ROUND((mrp - seller_discounts - store_discount_amount) * 100 / (100 + ABS(product_gst_perc)), 2),2) AS diff_vog_cc,
|
| 38 |
|
| 39 |
+
-- TDS calculation logic
|
| 40 |
+
CASE
|
| 41 |
+
WHEN segement_code IN ("FY", "UN") AND DATE(order_date) >= '2024-10-01' THEN
|
| 42 |
+
ROUND((mrp - seller_discounts - store_discount_amount), 2) * 0.001
|
| 43 |
+
WHEN segement_code IN ("FY", "UN") AND DATE(order_date) < '2024-10-01' THEN
|
| 44 |
+
ROUND((mrp - seller_discounts - store_discount_amount), 2) * 0.01
|
| 45 |
+
ELSE 0
|
| 46 |
+
END AS tds_cc,
|
| 47 |
|
| 48 |
+
-- TCS calculation logic
|
| 49 |
+
CASE
|
| 50 |
+
WHEN segement_code IN ("FY", "UN") AND DATE(order_date) >= '2024-07-10' THEN
|
| 51 |
+
ROUND((mrp - seller_discounts - store_discount_amount) * 100 / (100 + ABS(product_gst_perc)), 2) * 0.005
|
| 52 |
+
WHEN segement_code IN ("FY", "UN") AND DATE(order_date) < '2024-07-10' THEN
|
| 53 |
+
ROUND((mrp - seller_discounts - store_discount_amount) * 100 / (100 + ABS(product_gst_perc)), 2) * 0.01
|
| 54 |
+
ELSE 0
|
| 55 |
+
END AS tcs_cc
|
| 56 |
+
FROM
|
| 57 |
+
`fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
|
| 58 |
+
WHERE
|
| 59 |
+
expected_payout_date BETWEEN "{start_date}" AND "{end_date}"
|
| 60 |
+
),
|
| 61 |
|
| 62 |
+
-- Subquery to count occurrences of each bag_id and concatenation of bag_id and settlement_type
|
| 63 |
+
bag_con_count_data AS (
|
| 64 |
+
SELECT
|
| 65 |
+
bag_id,
|
| 66 |
+
settlement_type,
|
| 67 |
+
COUNT(*) AS bagg_count,
|
| 68 |
+
CONCAT(bag_id, settlement_type) AS bag_settlement_concat,
|
| 69 |
+
COUNT(CONCAT(bag_id, settlement_type)) AS bag_settlement_concat_count -- Count of concatenated values
|
| 70 |
+
FROM
|
| 71 |
+
seller_net_data
|
| 72 |
+
GROUP BY
|
| 73 |
+
bag_id, settlement_type
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
-- Final query
|
| 77 |
SELECT
|
| 78 |
+
sd.*,
|
| 79 |
+
ROUND((tds_cc - tds_on_bca), 2) AS diff_tds,
|
| 80 |
+
ROUND((tcs_cc - tcs_on_vog), 2) AS diff_tcs,
|
| 81 |
+
ROUND((mrp - seller_discounts - store_discount_amount - seller_tender_value + seller_fees),2) AS seller_sale_cc,
|
| 82 |
+
ROUND(((mrp - seller_discounts - store_discount_amount - seller_tender_value + seller_fees) - tds_cc - tcs_cc),2) AS seller_net_cc,
|
| 83 |
+
ROUND(((mrp - seller_discounts - store_discount_amount - seller_tender_value + seller_fees) - tds_cc - tcs_cc - seller_net_collection), 2) AS net_diff_cc,
|
| 84 |
+
CONCAT(sd.bag_id, ",") AS conccat, -- Concatenated bag_id
|
| 85 |
+
CONCAT(sd.bag_id, sd.settlement_type) AS bag_cc, -- Bag ID with settlement type
|
| 86 |
+
bcc.bagg_count AS bag_count, -- Count of each bag_id and settlement type
|
| 87 |
+
bcc.bag_settlement_concat AS bag_con, -- Concatenated bag_id and settlement_type
|
| 88 |
+
bcc.bag_settlement_concat_count AS bag_con_count, -- Count of concatenated values
|
| 89 |
+
CASE
|
| 90 |
+
WHEN order_type = 'COD' THEN CONCAT(company_id, '_', segement_code, '_', settlement_model_code, '_', order_type, '_V')
|
| 91 |
+
WHEN order_type = 'PPD' THEN CONCAT(company_id, '_', segement_code, '_', settlement_model_code, '_', order_type, '_C')
|
| 92 |
+
END AS ledger_name
|
| 93 |
FROM
|
| 94 |
+
seller_net_data sd
|
| 95 |
+
LEFT JOIN
|
| 96 |
+
bag_con_count_data bcc
|
| 97 |
+
ON
|
| 98 |
+
sd.bag_id = bcc.bag_id AND sd.settlement_type = bcc.settlement_type;
|
| 99 |
+
""",
|
| 100 |
|
| 101 |
+
"query_brand_accounting_entries": """
|
| 102 |
+
SELECT
|
| 103 |
+
DENSE_RANK() OVER (ORDER BY expected_payout_date,company_id,VOUCHERTYPENAME,sales_channel,expected_payout_date,order_type ASC) entry_code,
|
| 104 |
+
DATE,
|
| 105 |
+
Mode,
|
| 106 |
+
VOUCHERTYPENAME,
|
| 107 |
+
Narration,
|
| 108 |
+
DebitLedger,
|
| 109 |
+
AmountDebitLedger,
|
| 110 |
+
CreditLedger,
|
| 111 |
+
AmountCreditLedger
|
| 112 |
+
FROM (
|
| 113 |
+
WITH
|
| 114 |
+
Truth_table AS (SELECT * FROM `fynd-db.Brand_Accounting_Entries_Asia.Brand_Seller_Sale_FY25_Table`)
|
| 115 |
+
SELECT
|
| 116 |
+
expected_payout_date,
|
| 117 |
+
format_date('%Y%m%d', expected_payout_date) as DATE,
|
| 118 |
+
"Journal" as Mode,
|
| 119 |
+
VOUCHERTYPENAME,
|
| 120 |
+
CONCAT(Narration," for ", sales_channel, " for the period ",expected_payout_date ) AS Narration,
|
| 121 |
+
entry_Type,
|
| 122 |
+
order_type,
|
| 123 |
+
A.segement_code,
|
| 124 |
+
company_id,
|
| 125 |
+
sales_channel,
|
| 126 |
+
CASE WHEN seller_sales_amount > 0 AND B.ordering_channel IN ("FY", "FP", "FS", "UN", "OE","OM") AND entity = "seller" AND mop = "COD" THEN ledger_name WHEN seller_sales_amount > 0 AND B.ordering_channel IN ("FY", "FP", "FS", "UN", "OE","OM") AND entity = "seller" AND mop = "PPD" THEN ledger_name ELSE Credit_Ledger END AS DebitLedger,
|
| 127 |
+
CASE WHEN seller_sales_amount > 0 THEN ROUND(seller_sales_amount*-1) ELSE ROUND(seller_sales_amount) END AS AmountDebitLedger,
|
| 128 |
+
CASE WHEN seller_sales_amount < 0 AND B.ordering_channel IN ("FY", "FP", "FS", "UN", "OE","OM") AND entity = "seller" AND mop = "COD" THEN ledger_name WHEN seller_sales_amount < 0 AND B.ordering_channel IN ("FY", "FP", "FS", "UN", "OE","OM") AND entity = "seller" AND mop = "PPD" THEN ledger_name ELSE Credit_Ledger END AS CreditLedger,
|
| 129 |
+
CASE WHEN seller_sales_amount < 0 THEN ROUND(seller_sales_amount)*-1 ELSE ROUND(seller_sales_amount) END AS AmountCreditLedger
|
| 130 |
+
FROM
|
| 131 |
+
`fynd-db.Brand_Accounting_Entries_Asia.Seller_sale_Logic` AS A
|
| 132 |
+
LEFT JOIN
|
| 133 |
+
Truth_table as B
|
| 134 |
+
ON
|
| 135 |
+
A.segement_code = B.ordering_channel
|
| 136 |
+
AND A.entry_Type = B.Status
|
| 137 |
+
AND A.order_type = B.mop
|
| 138 |
+
WHERE
|
| 139 |
+
order_type = 'COD'
|
| 140 |
+
AND expected_payout_date BETWEEN '{start_date}' AND '{end_date}'
|
| 141 |
+
GROUP BY
|
| 142 |
+
1,2,3,4,5,6,7,8,9,10,11,12,13,14
|
| 143 |
+
ORDER BY
|
| 144 |
+
expected_payout_date,company_id,VOUCHERTYPENAME,sales_channel,order_type ASC
|
| 145 |
+
)
|
| 146 |
+
ORDER BY entry_code ASC
|
| 147 |
"""
|
| 148 |
}
|
seller.py
CHANGED
|
@@ -11,8 +11,7 @@ import pandas as pd
|
|
| 11 |
import io
|
| 12 |
import time
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
# webhook_url = list(Webhook_urls.keys())
|
| 16 |
html_subject = """
|
| 17 |
<html>
|
| 18 |
<head>
|
|
@@ -66,53 +65,107 @@ html_subject = """
|
|
| 66 |
"""
|
| 67 |
|
| 68 |
st.markdown(html_subject, unsafe_allow_html=True)
|
| 69 |
-
# selection = st.multiselect("", webhook_url)
|
| 70 |
-
|
| 71 |
|
| 72 |
def check_duplicates(credentials_file):
|
| 73 |
"""Check for duplicates using BigQuery with the provided credentials file."""
|
| 74 |
results = {}
|
| 75 |
credentials = service_account.Credentials.from_service_account_info(json.loads(credentials_file))
|
|
|
|
|
|
|
| 76 |
client = bigquery.Client(credentials=credentials, project=credentials.project_id)
|
| 77 |
-
|
| 78 |
-
query = queries["query"].format(start_date = start_date_str, end_date = end_date_str) # Access the query string from the dictionary
|
| 79 |
|
| 80 |
-
#
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
"""
|
| 86 |
-
<div class="progress-bar">
|
| 87 |
-
<span id="progress"></span>
|
| 88 |
-
</div>
|
| 89 |
-
""", unsafe_allow_html=True
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
try:
|
| 93 |
-
query_job = client.query(
|
| 94 |
-
# Simulate loading progress
|
| 95 |
-
for percent_complete in range(0, 101, 10):
|
| 96 |
-
time.sleep(0.1) # Simulate work being done
|
| 97 |
-
progress_bar.markdown(
|
| 98 |
-
f"""
|
| 99 |
-
<div class="progress-bar">
|
| 100 |
-
<span style="width: {percent_complete}%;"></span>
|
| 101 |
-
</div>
|
| 102 |
-
""", unsafe_allow_html=True
|
| 103 |
-
)
|
| 104 |
df = query_job.result().to_dataframe()
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
except Exception as e:
|
| 107 |
-
st.error(f"An error occurred: {e}")
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
return results
|
| 114 |
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
html_subject = """
|
| 117 |
<html>
|
| 118 |
<head>
|
|
@@ -159,22 +212,21 @@ html_subject = """
|
|
| 159 |
-webkit-text-fill-color: transparent;
|
| 160 |
margin: 0;
|
| 161 |
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
|
| 162 |
-
">Upload
|
| 163 |
</div>
|
| 164 |
</body>
|
| 165 |
</html>
|
| 166 |
"""
|
| 167 |
|
| 168 |
-
st.markdown(html_subject, unsafe_allow_html=True)
|
| 169 |
-
|
| 170 |
|
| 171 |
-
|
| 172 |
-
# Upload credentials file
|
| 173 |
credentials_file = st.file_uploader("", type="json")
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
| 178 |
<html>
|
| 179 |
<head>
|
| 180 |
<style>
|
|
@@ -220,23 +272,73 @@ html_subject = """
|
|
| 220 |
-webkit-text-fill-color: transparent;
|
| 221 |
margin: 0;
|
| 222 |
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
|
| 223 |
-
">
|
| 224 |
</div>
|
| 225 |
</body>
|
| 226 |
</html>
|
| 227 |
"""
|
| 228 |
|
| 229 |
-
st.markdown(
|
| 230 |
-
|
|
|
|
| 231 |
|
| 232 |
-
|
| 233 |
-
col1, col2 = st.columns([0.118, 0.125])
|
| 234 |
-
with col1:
|
| 235 |
-
start_date = st.date_input("Start date", value = None)
|
| 236 |
with col2:
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
|
|
|
|
|
|
|
|
|
| 240 |
if credentials_file is not None:
|
| 241 |
if start_date and end_date: # Ensure dates are selected
|
| 242 |
start_date_str = start_date.strftime("%Y-%m-%d")
|
|
@@ -248,31 +350,15 @@ if credentials_file is not None:
|
|
| 248 |
# Check for duplicates
|
| 249 |
results = check_duplicates(credentials_data)
|
| 250 |
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
col1, col2 = st.columns([0.125, 0.5])
|
| 262 |
-
with col1:
|
| 263 |
-
st.download_button(
|
| 264 |
-
label=":red[Download CSV]",
|
| 265 |
-
data=csv,
|
| 266 |
-
file_name="seller_sale_recon.csv",
|
| 267 |
-
mime="text/csv"
|
| 268 |
-
)
|
| 269 |
-
|
| 270 |
-
with col2:
|
| 271 |
-
st.download_button(
|
| 272 |
-
label=":red[Download Excel]",
|
| 273 |
-
data=excel,
|
| 274 |
-
file_name="seller_sale_recon.xlsx",
|
| 275 |
-
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 276 |
-
)
|
| 277 |
else:
|
| 278 |
st.warning("Please select both the start and end dates to proceed.")
|
|
|
|
| 11 |
import io
|
| 12 |
import time
|
| 13 |
|
| 14 |
+
# HTML for button styles and progress bar
|
|
|
|
| 15 |
html_subject = """
|
| 16 |
<html>
|
| 17 |
<head>
|
|
|
|
| 65 |
"""
|
| 66 |
|
| 67 |
st.markdown(html_subject, unsafe_allow_html=True)
|
|
|
|
|
|
|
| 68 |
|
| 69 |
def check_duplicates(credentials_file):
|
| 70 |
"""Check for duplicates using BigQuery with the provided credentials file."""
|
| 71 |
results = {}
|
| 72 |
credentials = service_account.Credentials.from_service_account_info(json.loads(credentials_file))
|
| 73 |
+
scopes = ['https://www.googleapis.com/auth/cloud-platform',
|
| 74 |
+
'https://www.googleapis.com/auth/drive']
|
| 75 |
client = bigquery.Client(credentials=credentials, project=credentials.project_id)
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
# Format and execute all queries
|
| 78 |
+
for query_name, query_template in queries.items():
|
| 79 |
+
formatted_query = query_template.format(start_date=start_date_str, end_date=end_date_str)
|
| 80 |
+
|
| 81 |
+
# Execute the query
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
try:
|
| 83 |
+
query_job = client.query(formatted_query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
df = query_job.result().to_dataframe()
|
| 85 |
+
results[query_name] = df # Store the DataFrame in the results dictionary
|
| 86 |
+
|
| 87 |
+
# Display the DataFrame in the UI
|
| 88 |
+
subheader_html = f"""
|
| 89 |
+
<div style="background-image: linear-gradient(to right, #800000, #ff0000);
|
| 90 |
+
-webkit-background-clip: text;
|
| 91 |
+
-webkit-text-fill-color: transparent;
|
| 92 |
+
margin: 10px 0;">
|
| 93 |
+
<h4 style="margin: 0; font-size: 20px;">Results for {query_name}</h4> <!-- Change h2 to h4 -->
|
| 94 |
+
</div>
|
| 95 |
+
"""
|
| 96 |
+
|
| 97 |
+
# Render the subheader
|
| 98 |
+
st.markdown(subheader_html, unsafe_allow_html=True)
|
| 99 |
+
st.dataframe(df) # Display each DataFrame in the Streamlit app
|
| 100 |
+
|
| 101 |
except Exception as e:
|
| 102 |
+
st.error(f"An error occurred while querying {query_name}: {e}")
|
| 103 |
+
|
| 104 |
+
# Check if the expected DataFrames are available for downloading
|
| 105 |
+
if 'query_seller_net_data' in results and 'query_brand_accounting_entries' in results:
|
| 106 |
+
df_net_data = results['query_seller_net_data']
|
| 107 |
+
df_brand_entries = results['query_brand_accounting_entries']
|
| 108 |
|
| 109 |
+
# Save both DataFrames to an Excel file with different sheets
|
| 110 |
+
excel_buffer = io.BytesIO()
|
| 111 |
+
with pd.ExcelWriter(excel_buffer, engine='openpyxl') as writer:
|
| 112 |
+
df_net_data.to_excel(writer, sheet_name='ss_data', index=False) # Changed to Net Data
|
| 113 |
+
df_brand_entries.to_excel(writer, sheet_name='ss_entry', index=False) # Changed to Brand Accounting
|
| 114 |
|
| 115 |
+
excel_buffer.seek(0)
|
| 116 |
+
|
| 117 |
+
# Create a CSV output with both DataFrames
|
| 118 |
+
csv_buffer = io.StringIO()
|
| 119 |
+
df_net_data.to_csv(csv_buffer, index=False, header=True) # Write first DataFrame to CSV
|
| 120 |
+
csv_buffer.write("\n") # Add a new line to separate the sections
|
| 121 |
+
df_net_data.to_csv(csv_buffer, index=False)
|
| 122 |
+
df_brand_entries.to_csv(csv_buffer, index=False, header=True) # Write second DataFrame to CSV
|
| 123 |
+
csv_buffer.seek(0)
|
| 124 |
+
|
| 125 |
+
# # Buttons to download the Excel and CSV files
|
| 126 |
+
col1, col2 = st.columns(2)
|
| 127 |
+
with col1:
|
| 128 |
+
button_styles = """
|
| 129 |
+
<style>
|
| 130 |
+
div.stButton > button {
|
| 131 |
+
color: #ffffff; /* Text color */
|
| 132 |
+
font-size: 30px;
|
| 133 |
+
background-image: linear-gradient(to right, #800000, #ff0000); /* Maroon to light red gradient */
|
| 134 |
+
border: none;
|
| 135 |
+
padding: 10px 20px;
|
| 136 |
+
cursor: pointer;
|
| 137 |
+
border-radius: 15px;
|
| 138 |
+
display: inline-block;
|
| 139 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 8px 15px rgba(0, 0, 0, 0.1); /* Box shadow */
|
| 140 |
+
transition: all 0.3s ease; /* Smooth transition on hover */
|
| 141 |
+
}
|
| 142 |
+
div.stButton > button:hover {
|
| 143 |
+
background-color: #00ff00; /* Hover background color */
|
| 144 |
+
color: #ff0000; /* Hover text color */
|
| 145 |
+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2), 0 12px 20px rgba(0, 0, 0, 0.2); /* Box shadow on hover */
|
| 146 |
+
}
|
| 147 |
+
</style>
|
| 148 |
+
"""
|
| 149 |
+
# Inject styles into the app
|
| 150 |
+
st.markdown(button_styles, unsafe_allow_html=True)
|
| 151 |
+
|
| 152 |
+
# Display the download button
|
| 153 |
+
st.download_button(
|
| 154 |
+
label="Download Excel file",
|
| 155 |
+
data=excel_buffer, # Use the base64 data URL for the file
|
| 156 |
+
file_name="query_results.xlsx",
|
| 157 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 158 |
+
key="download_excel" # Optionally specify a key for the button
|
| 159 |
+
)
|
| 160 |
return results
|
| 161 |
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
# Streamlit UI for uploading credentials
|
| 166 |
+
st.markdown(html_subject, unsafe_allow_html=True)
|
| 167 |
+
|
| 168 |
+
# Upload credentials file
|
| 169 |
html_subject = """
|
| 170 |
<html>
|
| 171 |
<head>
|
|
|
|
| 212 |
-webkit-text-fill-color: transparent;
|
| 213 |
margin: 0;
|
| 214 |
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
|
| 215 |
+
">Upload the JSON file</h3>
|
| 216 |
</div>
|
| 217 |
</body>
|
| 218 |
</html>
|
| 219 |
"""
|
| 220 |
|
|
|
|
|
|
|
| 221 |
|
| 222 |
+
st.markdown(html_subject, unsafe_allow_html=True)
|
|
|
|
| 223 |
credentials_file = st.file_uploader("", type="json")
|
| 224 |
|
| 225 |
+
st.write("")
|
| 226 |
+
col1, col2 = st.columns([0.118, 0.125])
|
| 227 |
+
# First column for Start Date
|
| 228 |
+
with col1:
|
| 229 |
+
html_subject_start = """
|
| 230 |
<html>
|
| 231 |
<head>
|
| 232 |
<style>
|
|
|
|
| 272 |
-webkit-text-fill-color: transparent;
|
| 273 |
margin: 0;
|
| 274 |
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
|
| 275 |
+
">Start date</h3>
|
| 276 |
</div>
|
| 277 |
</body>
|
| 278 |
</html>
|
| 279 |
"""
|
| 280 |
|
| 281 |
+
st.markdown(html_subject_start, unsafe_allow_html=True)
|
| 282 |
+
date_input_key_start = "start_date_input"
|
| 283 |
+
start_date = st.date_input("", value=None, key=date_input_key_start)
|
| 284 |
|
| 285 |
+
# Second column for End Date
|
|
|
|
|
|
|
|
|
|
| 286 |
with col2:
|
| 287 |
+
html_subject_end = """
|
| 288 |
+
<html>
|
| 289 |
+
<head>
|
| 290 |
+
<style>
|
| 291 |
+
.button {
|
| 292 |
+
display: inline-block;
|
| 293 |
+
padding: 10px 20px;
|
| 294 |
+
border-radius: 12px;
|
| 295 |
+
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
|
| 296 |
+
box-shadow:
|
| 297 |
+
0 6px 12px rgba(0, 0, 0, 0.3),
|
| 298 |
+
0 8px 16px rgba(0, 0, 0, 0.2),
|
| 299 |
+
inset 0 -2px 4px rgba(255, 255, 255, 0.6);
|
| 300 |
+
text-align: center;
|
| 301 |
+
position: relative;
|
| 302 |
+
transform: translateY(4px);
|
| 303 |
+
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
|
| 304 |
+
cursor: pointer;
|
| 305 |
+
user-select: none;
|
| 306 |
+
}
|
| 307 |
+
.button:hover {
|
| 308 |
+
box-shadow:
|
| 309 |
+
0 8px 16px rgba(0, 0, 0, 0.3),
|
| 310 |
+
0 12px 24px rgba(0, 0, 0, 0.2);
|
| 311 |
+
transform: translateY(2px);
|
| 312 |
+
}
|
| 313 |
+
.button:active {
|
| 314 |
+
box-shadow:
|
| 315 |
+
0 4px 8px rgba(0, 0, 0, 0.3),
|
| 316 |
+
0 6px 12px rgba(0, 0, 0, 0.2);
|
| 317 |
+
transform: translateY(0);
|
| 318 |
+
}
|
| 319 |
+
</style>
|
| 320 |
+
</head>
|
| 321 |
+
<body>
|
| 322 |
+
<div class="button">
|
| 323 |
+
<h3 style="
|
| 324 |
+
font-size: 20px;
|
| 325 |
+
color: #ffffff;
|
| 326 |
+
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
|
| 327 |
+
background-clip: text;
|
| 328 |
+
-webkit-background-clip: text;
|
| 329 |
+
text-fill-color: transparent;
|
| 330 |
+
-webkit-text-fill-color: transparent;
|
| 331 |
+
margin: 0;
|
| 332 |
+
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
|
| 333 |
+
">End date</h3>
|
| 334 |
+
</div>
|
| 335 |
+
</body>
|
| 336 |
+
</html>
|
| 337 |
+
"""
|
| 338 |
|
| 339 |
+
st.markdown(html_subject_end, unsafe_allow_html=True)
|
| 340 |
+
date_input_key_end = "end_date_input" # Changed key to be unique
|
| 341 |
+
end_date = st.date_input("", value=None, key=date_input_key_end)
|
| 342 |
if credentials_file is not None:
|
| 343 |
if start_date and end_date: # Ensure dates are selected
|
| 344 |
start_date_str = start_date.strftime("%Y-%m-%d")
|
|
|
|
| 350 |
# Check for duplicates
|
| 351 |
results = check_duplicates(credentials_data)
|
| 352 |
|
| 353 |
+
# Prepare to save results in an Excel file
|
| 354 |
+
if results:
|
| 355 |
+
excel_buffer = io.BytesIO()
|
| 356 |
+
with pd.ExcelWriter(excel_buffer, engine='openpyxl') as writer:
|
| 357 |
+
if 'query_seller_net_data' in results:
|
| 358 |
+
results['query_seller_net_data'].to_excel(writer, sheet_name='Net Data', index=False)
|
| 359 |
+
if 'query_brand_accounting_entries' in results:
|
| 360 |
+
results['query_brand_accounting_entries'].to_excel(writer, sheet_name='Brand Accounting', index=False)
|
| 361 |
+
else:
|
| 362 |
+
st.error("No results found.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
else:
|
| 364 |
st.warning("Please select both the start and end dates to proceed.")
|