-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from chavi362/adding-freelance-helper
adding freelance helper
- Loading branch information
Showing
3 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# freelance-help-program | ||
This software is designed to help freelancers calculate their payment based on hours worked. It takes an Excel file as input, where the start time is written in the first column and the end time is written in the second column. The software calculates the total time and the amount to be paid according to the hourly payment entered by the user. | ||
|
||
## Installation | ||
|
||
Layer the repository or download the code files. | ||
Install the required dependencies by running the following command: | ||
pip install openpyxl | ||
|
||
## Usage | ||
|
||
1. Run the program by executing the following command: | ||
python calculate_payment.py | ||
|
||
The program will open a graphical user interface (GUI) window. | ||
Click the "Browse" button to select the Excel file containing the time values. | ||
Enter the hourly rate in the appropriate input field. | ||
Click the "Calculate" button to calculate the payment. | ||
The program will display a message box with the total payment amount. | ||
The modified Excel file with the calculated results will be saved as "modified_[original_file_name].xlsx". | ||
|
||
Note: Make sure the Excel file has the correct format, with the start time in the first column and the end time in the second column. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import openpyxl | ||
from datetime import datetime | ||
from tkinter import * | ||
from tkinter import filedialog, messagebox | ||
from openpyxl.utils import get_column_letter | ||
from openpyxl import Workbook | ||
|
||
|
||
class CalculateApp: | ||
|
||
def __init__(self, root): | ||
self.root = root | ||
self.file_entry = StringVar() | ||
head_label = Label(root, text="Let's calculate the payment and hours", | ||
padx=15, | ||
pady=15, | ||
font="SegoeUI 14", | ||
bg="palegreen1", | ||
fg="red") | ||
head_label.grid(row=1, | ||
column=1, | ||
pady=10, | ||
padx=5, | ||
columnspan=3) | ||
|
||
file_label = Label(root, text="XL File Path:", font="SegoeUI 12", bg="PaleGreen1") | ||
file_label.grid(row=2, column=1, pady=10, padx=5) | ||
|
||
self.file_entry = Entry(root, width=30) | ||
self.file_entry.grid(row=2, column=2, pady=10, padx=5) | ||
|
||
browse_button = Button(root, text="Browse", font="SegoeUI 12", bg="PaleGreen1", command=self.browse) | ||
browse_button.grid(row=2, column=3, pady=10, padx=5) | ||
|
||
pay_label = Label(root, text="Pay per Hour:", font="SegoeUI 12", bg="PaleGreen1") | ||
pay_label.grid(row=3, column=1, pady=10, padx=5) | ||
|
||
self.pay_entry = Entry(root, width=30) | ||
self.pay_entry.grid(row=3, column=2, pady=10, padx=5) | ||
|
||
calculate_button = Button(root, text="Calculate", font="SegoeUI 12", bg="PaleGreen1", | ||
command=self.calculate_button_clicked) | ||
calculate_button.grid(row=4, column=1, pady=10, padx=5, columnspan=3) | ||
|
||
def browse(self): | ||
# Presenting the user with a pop-up for directory selection | ||
file_path = filedialog.askopenfilename(title="Select XL File") | ||
# Checking if the selected file has a valid Excel file extension | ||
if file_path.endswith('.xlsx') or file_path.endswith('.xls'): | ||
self.file_entry.delete(0, END) # Clearing any existing text | ||
self.file_entry.insert(0, file_path) | ||
else: | ||
self.file_entry.delete(0, END) | ||
self.file_entry.insert(0, "Invalid file format") | ||
|
||
def calculate_payment(self, file_path, pay_per_hour): | ||
try: | ||
# Implement your logic to calculate the payment based on the hours in the xl file | ||
wb = openpyxl.load_workbook(file_path) | ||
sheet = wb.active | ||
total_price = 0 | ||
for row in range(2, sheet.max_row + 1): | ||
cellStart = sheet.cell(row, 1) | ||
cellFinish = sheet.cell(row, 2) | ||
start_time = datetime.combine(datetime.now().date(), cellStart.value) | ||
finish_time = datetime.combine(datetime.now().date(), cellFinish.value) | ||
total_time = finish_time - start_time | ||
total_time_cell = sheet.cell(row, 3) | ||
total_time_cell.value = total_time.total_seconds() / 3600 | ||
price = pay_per_hour * (total_time.total_seconds() / 3600) | ||
price_cell = sheet.cell(row, 4) | ||
price_cell.value = price | ||
price_cell.number_format = '0.00' # Set the number format to display as a double in shekels | ||
total_price += price | ||
|
||
total_price_cell = sheet.cell(sheet.max_row + 1, 4) # Place the total price in the fifth cell | ||
total_price_cell.value = total_price | ||
total_price_cell.number_format = '0.00' # Set the number format to display as a double in shekels | ||
# Save the updated Excel file | ||
modified_file_path = f"modified_{file_path}" | ||
wb.save(modified_file_path) | ||
|
||
messagebox.showinfo("Calculation Complete", f"Total Payment: {total_price:.2f} Shekels") | ||
except Exception as e: | ||
messagebox.showerror("Error", f"An error occurred: {str(e)}") | ||
|
||
def calculate_button_clicked(self): | ||
file_path = self.file_entry.get() | ||
pay_per_hour = self.pay_entry.get() | ||
if not file_path: | ||
messagebox.showerror("Error", "Please select an Excel file.") | ||
elif not pay_per_hour: | ||
messagebox.showerror("Error", "Please enter the pay per hour.") | ||
else: | ||
try: | ||
pay_per_hour = float(pay_per_hour) | ||
self.calculate_payment(file_path, pay_per_hour) | ||
except ValueError: | ||
messagebox.showerror("Error", "Invalid pay per hour value. Please enter a number.") | ||
|
||
|
||
def main(): | ||
root = Tk() | ||
# Set the title, background color, and size of the tkinter window and disabling the resizing property | ||
root.geometry("520x280") | ||
root.resizable(False, False) | ||
root.title("Freelance help software") | ||
root.config(background="PaleGreen1") | ||
# Creating an instance of CalculateApp class | ||
app = CalculateApp(root) | ||
# Running the application | ||
root.mainloop() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |