-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
178 lines (153 loc) · 6.26 KB
/
app.py
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
import streamlit as st
import yagmail
from reportlab.lib.pagesizes import letter
from reportlab.lib import colors
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Image, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
import os
from datetime import datetime
import requests
from PIL import Image as PILImage
from io import BytesIO
from reportlab.graphics.shapes import Drawing, Rect
def send_email(recipient, subject, content, attachment):
yag = yagmail.SMTP('aunraza021@gmail.com', 'dozjccrjcqdltrbz')
yag.send(to=recipient, subject=subject, contents=content, attachments=attachment)
def generate_salary_slip_pdf(name, salary, filename, logo_url):
document = SimpleDocTemplate(filename, pagesize=letter)
styles = getSampleStyleSheet()
elements = []
# Download logo
response = requests.get(logo_url)
img = PILImage.open(BytesIO(response.content))
img.save("logo_temp.png")
# Add logo and title
logo = Image("logo_temp.png", 1.5*inch, 1*inch)
elements.append(logo)
elements.append(Spacer(1, 12))
title = Paragraph("<b>Sinecure AI</b>", styles['Title'])
elements.append(title)
# Add date and designation
current_date = datetime.now().strftime("%B %d, %Y")
date_paragraph = Paragraph(f"Pay Date: {current_date}", styles['Normal'])
designation_paragraph = Paragraph(f"Designation: Software Engineer", styles['Normal'])
elements.append(date_paragraph)
elements.append(designation_paragraph)
elements.append(Spacer(1, 12))
# Add candidate details in a table
data = [
['Name', name],
['Gross Salary', f"${salary}"],
['Basic Salary', f"${salary}"],
]
table = Table(data, colWidths=[2*inch, 4*inch])
table.setStyle(TableStyle([
('BACKGROUND', (0, 0), (1, 0), colors.lightblue),
('TEXTCOLOR', (0, 0), (1, 0), colors.whitesmoke),
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
('FONTSIZE', (0, 0), (-1, 0), 14),
('BOTTOMPADDING', (0, 0), (-1, 0), 12),
('BACKGROUND', (0, 1), (-1, -1), colors.beige),
('GRID', (0, 0), (-1, -1), 1, colors.black),
('BOX', (0, 0), (-1, -1), 2, colors.black),
]))
elements.append(table)
# Build PDF with background border
def on_page(canvas, doc):
canvas.saveState()
d = Drawing(550, 700)
d.add(Rect(0, 0, 550, 700, strokeColor=colors.black, fillColor=None, strokeWidth=1))
d.drawOn(canvas, 0, 0)
canvas.restoreState()
document.build(elements, onFirstPage=on_page, onLaterPages=on_page)
os.remove("logo_temp.png") # Clean up temporary logo file
def main():
st.set_page_config(page_title="Sinecure AI", page_icon=":moneybag:", layout="centered")
# Add custom CSS for styling
st.markdown("""
<style>
body {
background-color: #F0F8FF;
}
.header {
display: flex;
justify-content: left;
align-items: center;
background-color: #4682B4; /* Slightly more blue */
padding: 10px;
border-radius: 10px;
color: white;
}
.header img {
max-width: 60px; /* Adjust logo size */
margin-right: 20px;
}
.header h1 {
font-size: 2.5em;
margin: 0;
margin-left: 50px; /* Slightly right */
}
.container {
max-width: 700px;
margin: auto;
padding: 20px;
background-color: white;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
}
.button {
background-color: #87CEFA;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.button:hover {
background-color: #4682B4;
}
</style>
""", unsafe_allow_html=True)
# Create the header with a logo
logo_url = "https://i.ibb.co/yXLFZVV/logo.png"
st.markdown(f"""
<div class="header">
<img src="{logo_url}" alt="Logo">
<h1>Sinecure AI</h1>
</div>
""", unsafe_allow_html=True)
st.markdown('<div class="container">', unsafe_allow_html=True)
st.header("Enter the details for Employees")
candidate_names = ["Aun", "Sajjad", "Uma", "Shivani"]
default_email = "joel@sinecure.ai"
if 'candidates' not in st.session_state:
st.session_state.candidates = []
if 'current_candidate' not in st.session_state:
st.session_state.current_candidate = 0
current_candidate = st.session_state.current_candidate
if current_candidate < 4:
st.subheader(f"Employee {current_candidate + 1}")
name = st.selectbox("Select name", candidate_names, key=f"name_{current_candidate}")
salary = st.number_input("Enter salary", min_value=0, key=f"salary_{current_candidate}")
if st.button("Next"):
st.session_state.candidates.append({"name": name, "email": default_email, "salary": salary})
st.session_state.current_candidate += 1
st.experimental_rerun()
else:
st.subheader("Review and Modify Salaries")
for i, candidate in enumerate(st.session_state.candidates):
new_salary = st.number_input(f"Modify salary for {candidate['name']}", value=candidate['salary'], key=f"modify_salary_{i}")
st.session_state.candidates[i]['salary'] = new_salary
if st.button("Send Salary Slips"):
for candidate in st.session_state.candidates:
filename = f"{candidate['name']}_salary_slip.pdf"
generate_salary_slip_pdf(candidate['name'], candidate['salary'], filename, logo_url)
slip_content = f"Dear {candidate['name']},\n\nPlease find attached your salary slip for this month.\n\nBest regards,\nSinecure AI"
send_email(candidate['email'], "Your Salary Slip", slip_content, filename)
os.remove(filename) # Remove the file after sending email to clean up
st.success(f"Salary slip sent to {candidate['email']}")
st.markdown('</div>', unsafe_allow_html=True)
if __name__ == "__main__":
main()