Skip to content

Commit f3a0129

Browse files
committed
2 parents cd4d9b3 + 531525e commit f3a0129

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Source Code Explanation
2+
3+
1. **Import Necessary Libraries**
4+
5+
6+
7+
```
8+
from reportlab.platypus import SimpleDocTemplate, Table, Paragraph, TableStyle
9+
from reportlab.lib import colors
10+
from reportlab.lib.pagesizes import A4
11+
from reportlab.lib.styles import getSampleStyleSheet
12+
from datetime import datetime
13+
import win10toast
14+
```
15+
16+
- `reportlab` is used for creating PDF documents.
17+
- `datetime` is used to get the current date and time.
18+
- `win10toast` is used for showing desktop notifications on Windows.
19+
2. **Define `store_products` Function**
20+
21+
22+
```
23+
def store_products():
24+
print('=====> WELCOME TO MY-SCHOOL <=====')
25+
```
26+
27+
- This function displays available courses, allows the user to purchase them, and generates a receipt in PDF format.
28+
3. **Initialize Default Courses**
29+
30+
31+
32+
```
33+
default_courses = [
34+
...
35+
]
36+
```
37+
38+
- This list contains dictionaries representing different courses available for purchase. Each dictionary includes the course name, duration, access type, and price.
39+
4. **Display Available Courses**
40+
41+
42+
43+
```
44+
for i, data in enumerate(default_courses, start=0):
45+
print(f'--> Course : {i}')
46+
...
47+
```
48+
49+
- This loop prints the details of each available course with an index.
50+
5. **Initialize Template for Receipt**
51+
52+
53+
54+
```
55+
templete = [
56+
['Date', 'Name', 'Duration', 'Access', 'Price']
57+
]
58+
```
59+
60+
- This list will be used to store the details of the purchased courses and will be used to generate the PDF receipt.
61+
6. **Start Purchasing Loop**
62+
63+
64+
65+
```
66+
course_index = -1
67+
parchasing = True
68+
totalFee = 0
69+
discount = 3000
70+
while(parchasing):
71+
...
72+
```
73+
74+
- This loop allows the user to select courses to purchase. It continues until the user decides to exit.
75+
7. **Get User Input for Course Selection**
76+
77+
78+
79+
```
80+
buy_course = int(input("Which Course Do you wan to Buy (0, 1, 2....) : "))
81+
if(buy_course > len(default_courses)):
82+
...
83+
```
84+
85+
- The user inputs the index of the course they want to purchase. If the index is invalid, an error message is displayed.
86+
8. **Add Selected Course to Template**
87+
88+
89+
90+
```
91+
course = default_courses[buy_course]
92+
current_date = datetime.now()
93+
formated_time = current_date.strftime('%d/%m/%Y')
94+
buy_date = [{'date': formated_time}]
95+
date = buy_date[0]
96+
97+
templete.append([
98+
date['date'],
99+
course['Course'],
100+
course['Duration'],
101+
course['Access'],
102+
course['Price']
103+
])
104+
...
105+
```
106+
107+
- The selected course details, along with the current date, are added to the `templete` list.
108+
9. **Calculate Total Fee**
109+
110+
```
111+
if course['Price'] != 'Free':
112+
totalFee += course['Price']
113+
```
114+
115+
- The total fee is calculated by summing the prices of all purchased courses, excluding free courses.
116+
117+
10. **Exit Option**
118+
119+
```
120+
exit = input("\nDo you want to exit (0 - exit - No) : ")
121+
if(exit == 'exit' or exit == '0'):
122+
parchasing = False
123+
```
124+
125+
- The user can choose to exit the purchasing loop by entering '0' or 'exit'.
126+
127+
11. **Add Discount and Total Fee to Template**
128+
129+
```
130+
templete.append([
131+
("Discount"),
132+
(""),
133+
(""),
134+
(""),
135+
(discount),
136+
])
137+
templete.append([
138+
("Total"),
139+
(""),
140+
(""),
141+
(""),
142+
(totalFee-discount),
143+
])
144+
```
145+
146+
- The discount and total fee (after discount) are added to the `templete` list.
147+
148+
12. **Generate PDF Receipt**
149+
150+
```
151+
pdf = SimpleDocTemplate('Receipt.pdf', pagesize = A4)
152+
toaster = win10toast.ToastNotifier()
153+
t_title = "Courses Reciept Ready!"
154+
message = "Courses has been parchased from My-School"
155+
toaster.show_toast(t_title, message)
156+
styles = getSampleStyleSheet()
157+
title_style = styles['Heading1']
158+
title_style.alignment = 1
159+
title = Paragraph('My-School Courses', title_style)
160+
style = TableStyle(
161+
...
162+
)
163+
table = Table(templete, style=style)
164+
pdf.build([title, table])
165+
```
166+
167+
- A PDF receipt is created using `reportlab`. The receipt includes a title and a table with the details of the purchased courses.
168+
- A desktop notification is shown to inform the user that the receipt is ready.
169+
170+
13. **Call the Function**
171+
172+
173+
174+
`store_products()`
175+
176+
177+
### How to Use
178+
179+
1. **Run the Script**
180+
181+
- Simply run the script using a Python interpreter.
182+
- The script will display the available courses and prompt you to select which courses you want to buy.
183+
2. **Select Courses**
184+
185+
- Enter the index number of the course you wish to purchase.
186+
- Continue selecting courses until you are done. Enter '0' or 'exit' to stop purchasing.
187+
3. **Generate Receipt**
188+
189+
- Once you exit the purchasing loop, a PDF receipt will be generated and saved as `Receipt.pdf` in the current directory.
190+
- A desktop notification will inform you that the receipt is ready.
191+
192+
### Features
193+
194+
- **Course Listing**: Displays a list of available courses with details.
195+
- **Course Selection**: Allows users to select multiple courses to purchase.
196+
- **Receipt Generation**: Generates a PDF receipt with the details of the purchased courses.
197+
- **Discount Calculation**: Applies a discount to the total fee.
198+
- **Desktop Notification**: Notifies the user when the receipt is ready.
199+
200+
This explanation should help GitHub viewers understand how the function works and how to use it. Feel free to customize the explanation further based on your specific needs.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This repository includes various Python projects:
1818
| 10. [Life Span Calculator](https://github.com/JawadSher/Python-Projects-Beginner-to-Advance/tree/main/Project%2010%20-%20Life%20Span%20Calculator) | A basic project by using the PyWebIO framework to build web app to calculate person total age span. |
1919
| 11. [Python Code Editor](https://github.com/JawadSher/Python-Projects-Beginner-to-Advance/tree/main/Project%2011%20-%20Python%20Code%20Editor) | A Python Code Editor web application Built with PyWebIO framework. |
2020
| 12. [File Encryptor - Decryptor](https://github.com/JawadSher/Python-Projects-Beginner-to-Advance/tree/main/Project%2012%20-%20File%20Encryptor%20Decryptor) | A Python project that securely encrypts and decrypts files using the cryptography.fernet library.
21+
| 13. [Generating Payment Receipts](https://github.com/JawadSher/Python-Projects-Beginner-to-Advance/tree/main/Project%2013%20-%20Generating%20Payment%20Receipts) | This Python project generates product receipts after purchases and notifies users upon completion.
2122

2223
## Introduction
2324

0 commit comments

Comments
 (0)