Ninad077 commited on
Commit
795abe6
Β·
verified Β·
1 Parent(s): b88b965

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +7 -1
  2. splitter.py +112 -0
app.py CHANGED
@@ -62,7 +62,8 @@ menu_options = [
62
  {"label": "Internal users", "icon": "πŸ“„", "description": "Upload a document and schedule it for email"},
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
  ]
67
 
68
  # Create the custom option menu
@@ -393,4 +394,9 @@ elif selected_option == "Manual BQ upload":
393
  with open('bq.py') as file:
394
  exec(file.read())
395
 
 
 
 
 
 
396
 
 
62
  {"label": "Internal users", "icon": "πŸ“„", "description": "Upload a document and schedule it for email"},
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
 
394
  with open('bq.py') as file:
395
  exec(file.read())
396
 
397
+ elif selected_option == "Invoice splitter":
398
+ with open('splitter.py') as file:
399
+ exec(file.read())
400
+
401
+
402
 
splitter.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import os
4
+ from io import BytesIO
5
+ from zipfile import ZipFile
6
+
7
+ html_subject = """
8
+ <html>
9
+ <head>
10
+ <style>
11
+ .button {
12
+ display: inline-block;
13
+ padding: 10px 20px;
14
+ border-radius: 12px;
15
+ background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
16
+ box-shadow:
17
+ 0 6px 12px rgba(0, 0, 0, 0.3),
18
+ 0 8px 16px rgba(0, 0, 0, 0.2),
19
+ inset 0 -2px 4px rgba(255, 255, 255, 0.6);
20
+ text-align: center;
21
+ position: relative;
22
+ transform: translateY(4px);
23
+ transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
24
+ cursor: pointer;
25
+ user-select: none;
26
+ }
27
+ .button:hover {
28
+ box-shadow:
29
+ 0 8px 16px rgba(0, 0, 0, 0.3),
30
+ 0 12px 24px rgba(0, 0, 0, 0.2);
31
+ transform: translateY(2px);
32
+ }
33
+ .button:active {
34
+ box-shadow:
35
+ 0 4px 8px rgba(0, 0, 0, 0.3),
36
+ 0 6px 12px rgba(0, 0, 0, 0.2);
37
+ transform: translateY(0);
38
+ }
39
+ </style>
40
+ </head>
41
+ <body>
42
+ <div class="button">
43
+ <h3 style="
44
+ font-size: 20px;
45
+ color: #ffffff;
46
+ background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
47
+ background-clip: text;
48
+ -webkit-background-clip: text;
49
+ text-fill-color: transparent;
50
+ -webkit-text-fill-color: transparent;
51
+ margin: 0;
52
+ text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
53
+ ">Upload a CSV file</h3>
54
+ </div>
55
+ </body>
56
+ </html>
57
+ """
58
+
59
+ st.markdown(html_subject, unsafe_allow_html=True)
60
+
61
+ # Step 1: Upload CSV file
62
+ uploaded_file = st.file_uploader("", type=["csv"])
63
+
64
+ if uploaded_file is not None:
65
+ # Step 2: Read the CSV file into a DataFrame
66
+ df = pd.read_csv(uploaded_file)
67
+
68
+ if 'Invoice_No' not in df.columns:
69
+ st.error("The uploaded CSV does not contain the 'Invoice_No' column.")
70
+ else:
71
+ # Step 3: Split the DataFrame based on unique Invoice_No values
72
+ invoice_groups = df.groupby('Invoice_No')
73
+
74
+ # Step 4: Generate CSV files for each Invoice_No and add them to a ZIP archive
75
+ zip_buffer = BytesIO()
76
+ with ZipFile(zip_buffer, "a") as zip_file:
77
+ for invoice_no, group in invoice_groups:
78
+ csv_buffer = BytesIO()
79
+ group.to_csv(csv_buffer, index=False)
80
+ zip_file.writestr(f"{invoice_no}.csv", csv_buffer.getvalue())
81
+
82
+ zip_buffer.seek(0) # Move to the beginning of the buffer
83
+
84
+ # Step 5: Provide a download button for the ZIP file
85
+ button_styles = """
86
+ <style>
87
+ div.stDownloadButton > button {
88
+ color: #ffffff; /* Text color */
89
+ font-size: 30px;
90
+ background-image: linear-gradient(to right, #800000, #ff0000); /* Maroon to light red gradient */
91
+ border: none;
92
+ padding: 10px 20px;
93
+ cursor: pointer;
94
+ border-radius: 15px;
95
+ display: inline-block;
96
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 8px 15px rgba(0, 0, 0, 0.1); /* Box shadow */
97
+ transition: all 0.3s ease; /* Smooth transition on hover */
98
+ }
99
+ div.stDownloadButton > button:hover {
100
+ background-color: #00ff00; /* Hover background color */
101
+ color: #ff0000; /* Hover text color */
102
+ box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2), 0 12px 20px rgba(0, 0, 0, 0.2); /* Box shadow on hover */
103
+ }
104
+ </style>
105
+ """
106
+ st.markdown(button_styles, unsafe_allow_html=True)
107
+ st.download_button(
108
+ label="Download Invoices ZIP",
109
+ data=zip_buffer,
110
+ file_name="invoices.zip",
111
+ mime="application/zip"
112
+ )