File size: 10,896 Bytes
1a150a4
9b11096
1a150a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b11096
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a150a4
9b11096
 
 
 
 
 
 
 
 
 
1
2
3
4
5
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import streamlit as st
import pandas as pd
from group import CSVtoXMLgroup
from jv import journal_vouchers
from sale import CSVtoXMLsale
from tally import CSVtoXMLtally
from payment import CSVtoXMLpayment
from cn import CSVtoXMLcn
from ledgers import CSVtoXMLledger
from dn import debit_note
from pixel_sale import CSVtoXMLpixel
from alter_ledgers import CSVtoXMLalter
from pixel_bin_cn import CSVtoXMLbin

import os
import tempfile
import base64

# URL of your background image
background_image_url = "https://media2.giphy.com/media/v1.Y2lkPTc5MGI3NjExY3Yxdzl2ZzZoa2N0amdnNHVsMjF4bmxudHQ1ZGN3MmpheHh6aXN6cyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/ENeLuI1PyqUnJv4NMl/giphy.webp"  # Replace this with the direct image URL


# Inject CSS with Streamlit
st.markdown(
    f"""
    <style>
    .stApp {{
        background-image: url("{background_image_url}");
         background-size: 20% auto;
        background-size: cover;
        background-position: left;
        background-attachment: fixed;
        opacity: 1.0; /* Adjust the opacity to control the fade level */
        z-index: -1; /* Ensure the background is behind the content */
    }}
    </style>
    """,
    unsafe_allow_html=True
)



# # Custom gradient title

# text_0 = """
# <div style="font-size: 24px; font-weight: bold;">
#     <h1>CSV to XML converter</h1>
# </div>
# """

# # Display the text with the increased font size
# st.markdown(text_0, unsafe_allow_html=True)

st.write("")
st.write("")
st.write("")
st.write("")
st.write("")
st.write("")
st.write("")
st.write("")


col1, col2, col3 = st.columns([25.0, 0.01, 1.0])


with col1:
    text = """
<div style="
    font-size: 30px;
    font-weight: bold;
    color: #dea713;
    background-color: white; /* White background for the button */
    padding: 15px 30px; /* Padding around the text */
    border-radius: 12px; /* Rounded corners for a softer look */
    display: inline-block; /* Ensures the button size fits the text */
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3), 0 4px 8px rgba(255, 255, 255, 0.5) inset; /* 3D shadow with inset effect for depth */
    text-align: center; /* Centers the text */
    position: relative; /* Needed for pseudo-element positioning */
    cursor: pointer; /* Shows a pointer cursor on hover */
    transition: all 0.3s ease; /* Smooth transition for hover effect */
    border: 1px solid #ccc; /* Light border to define button edges */
">
    Transform CSV to Tally XML seamlessly.
</div>


    """




    # Display the text with the increased font size
    st.markdown(text, unsafe_allow_html=True)

    st.write('')
    st.write('')


    text_2 = """
    <div style="font-size: 20px; font-weight: bold; color: #54abed">
        Currently supporting XML conversion for the CSV templates listed in the dropdown
    </div>
    """

    st.markdown(text_2, unsafe_allow_html= True)




    options = st.selectbox("Please select a CSV template", ['', 'Alter Ledgers','Credit Note', 'Debit Note','Group Creation','Journal Entries','Ledger Creation','Payment Entries', 'Export Credit Note', 'Export Sale', 'Sale', 'Purchase'])

    if options == 'Alter Ledgers':
        df = pd.read_csv('alter_ledgers.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'alter_ledgers.csv',
            mime = 'text/csv'
        )

    elif options == 'Credit Note':
        df = pd.read_csv('cn.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'cn.csv',
            mime = 'text/csv'
        )

    elif options == 'Debit Note':
        df = pd.read_csv('dn.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'dn.csv',
            mime = 'text/csv'
        )

    elif options == 'Group Creation':
        df = pd.read_csv('group.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'group.csv',
            mime = 'text/csv'
        )

    elif options == 'Journal Entries':
        df = pd.read_csv('jv.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'jv.csv',
            mime = 'text/csv'
        )

    elif options == 'Ledger Creation':
        df = pd.read_csv('ledgers.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'ledgers.csv',
            mime = 'text/csv'
        )

    elif options == 'Payment Entries':
        df = pd.read_csv('payment.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'payment.csv',
            mime = 'text/csv'
        )

    elif options == 'Export Credit Note':
        df = pd.read_csv('pixel_bin_cn.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'pixel_bin_cn.csv',
            mime = 'text/csv'
        )

    elif options == 'Export Sale':
        df = pd.read_csv('pixel_sale.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'pixel_sale.csv',
            mime = 'text/csv'
        )

    elif options == 'Sale':
        df = pd.read_csv('sale.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'sale.csv',
            mime = 'text/csv'
        )

    elif options == 'Purchase':
        df = pd.read_csv('tally.csv')
        df = df.head(1)
        st.dataframe(df)
        csv = df.to_csv(index = False)

        st.download_button(
            label = "Download template",
            data = csv,
            file_name= 'tally.csv',
            mime = 'text/csv'
        )



    # Upload file
    uploaded_file = st.file_uploader("Choose a CSV file", type='csv')

    if uploaded_file is not None:
        try:
            # Save the uploaded file to a temporary file
            with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as temp_csv_file:
                temp_csv_path = temp_csv_file.name
                temp_csv_file.write(uploaded_file.read())

            st.write(f'Temporary CSV file path: {temp_csv_path}')  # Debug print
            
            if uploaded_file.name.lower() == 'group.csv':
                # Process Group CSV file
                output_file = CSVtoXMLgroup(temp_csv_path)
                file_label = 'Group XML'
            
            elif uploaded_file.name.lower() == 'jv.csv':
                # Process Journal Vouchers CSV file
                output_file = journal_vouchers(temp_csv_path)
                file_label = 'Journal Vouchers XML'
            
            elif uploaded_file.name.lower() == 'sale.csv':
                # Process Sale CSV file
                output_file = CSVtoXMLsale(temp_csv_path)
                file_label = 'Sale XML'
            
            elif uploaded_file.name.lower() == 'tally.csv':
                # Process Tally CSV file
                output_file = CSVtoXMLtally(temp_csv_path)
                file_label = 'Tally XML'

            elif uploaded_file.name.lower() == 'payment.csv':
                # Process Payment CSV file
                output_file = CSVtoXMLpayment(temp_csv_path)
                file_label = 'Payment XML'

            elif uploaded_file.name.lower() == 'cn.csv':
                # Process CN CSV file
                output_file = CSVtoXMLcn(temp_csv_path)
                file_label = 'CN XML'

            elif uploaded_file.name.lower() == 'ledgers.csv':
                # Process Ledger CSV file
                output_file = CSVtoXMLledger(temp_csv_path)
                file_label = 'Ledger XML'

            elif uploaded_file.name.lower() == 'dn.csv':
                # Process Debit Note CSV file
                output_file = debit_note(temp_csv_path)
                file_label = 'Debit Note XML'

            elif uploaded_file.name.lower() == 'pixel_sale.csv':
                # Process Pixel Sale CSV file
                output_file = CSVtoXMLpixel(temp_csv_path)
                file_label = 'Pixel Sale XML'

            elif uploaded_file.name.lower() == 'alter_ledgers.csv':
                # Process Alter Ledgers CSV file
                output_file = CSVtoXMLalter(temp_csv_path)
                file_label = 'Alter Ledger XML'

            elif uploaded_file.name.lower() == 'pixel_bin_cn.csv':
                # Process Pixel Bin CN CSV file
                output_file = CSVtoXMLbin(temp_csv_path)
                file_label = 'Pixel Bin CN XML'

            else:
                st.error('Please upload a valid CSV file named group.csv, jv.csv, or sale.csv')
                output_file = None

            if output_file and os.path.exists(output_file):
                # Read the file and encode it in base64
                with open(output_file, 'rb') as file:
                    file_data = file.read()
                    b64_file_data = base64.b64encode(file_data).decode()

                # Provide a download link with the styled button
                download_link = f"""
                <a href="data:application/xml;base64,{b64_file_data}" download="{os.path.basename(output_file)}" class="custom-download-button">
                    Download {file_label}
                </a>
                """
                st.markdown(download_link, unsafe_allow_html=True)
            else:
                st.error('No output file was created.')

        except Exception as e:
            st.error(f'Error: {e}')
        
        finally:
            # Clean up temporary files
            if os.path.exists(temp_csv_path):
                os.remove(temp_csv_path)
            if output_file and os.path.exists(output_file):
                os.remove(output_file)


with col3:
    st.image("tally_prime_logo.png")