fork download
  1. import tkinter as tk
  2. from tkinter import ttk, messagebox
  3. import sqlite3
  4. from datetime import datetime
  5. from openpyxl import Workbook
  6.  
  7. class AdvancedHRMS:
  8. def __init__(self, root):
  9. self.root = root
  10. self.root.title("نظام إدارة الموارد البشرية المتقدم")
  11. self.root.geometry("1400x900")
  12.  
  13. self.create_database()
  14. self.create_widgets()
  15. self.load_initial_data()
  16.  
  17. self.current_emp_id = None
  18.  
  19. def create_database(self):
  20. self.conn = sqlite3.connect('advanced_hrms.db')
  21. self.cursor = self.conn.cursor()
  22.  
  23. tables = [
  24. '''CREATE TABLE IF NOT EXISTS employees (
  25. id TEXT PRIMARY KEY,
  26. name TEXT,
  27. dob TEXT,
  28. nationality TEXT,
  29. hire_date TEXT,
  30. department TEXT,
  31. salary REAL)''',
  32.  
  33. '''CREATE TABLE IF NOT EXISTS attendance (
  34. id INTEGER PRIMARY KEY AUTOINCREMENT,
  35. emp_id TEXT,
  36. date TEXT,
  37. check_in TEXT,
  38. check_out TEXT)''',
  39.  
  40. '''CREATE TABLE IF NOT EXISTS salaries (
  41. id INTEGER PRIMARY KEY AUTOINCREMENT,
  42. emp_id TEXT,
  43. month TEXT,
  44. basic REAL,
  45. deductions REAL,
  46. allowances REAL,
  47. net REAL)''',
  48.  
  49. '''CREATE TABLE IF NOT EXISTS leaves (
  50. id INTEGER PRIMARY KEY AUTOINCREMENT,
  51. emp_id TEXT,
  52. start_date TEXT,
  53. end_date TEXT,
  54. type TEXT,
  55. status TEXT DEFAULT 'معلق')''',
  56.  
  57. '''CREATE TABLE IF NOT EXISTS performance (
  58. id INTEGER PRIMARY KEY AUTOINCREMENT,
  59. emp_id TEXT,
  60. date TEXT,
  61. productivity REAL,
  62. teamwork REAL,
  63. comments TEXT)'''
  64. ]
  65.  
  66. for table in tables:
  67. self.cursor.execute(table)
  68. self.conn.commit()
  69.  
  70. def create_widgets(self):
  71. toolbar = ttk.Frame(self.root)
  72. toolbar.pack(side='top', fill='x')
  73.  
  74. self.emp_selector = ttk.Combobox(toolbar, postcommand=self.update_emp_list)
  75. self.emp_selector.pack(side='left', padx=5, pady=5)
  76. self.emp_selector.bind('<<ComboboxSelected>>', self.select_employee)
  77.  
  78. ttk.Button(toolbar, text="تصدير Excel", command=self.export_to_excel).pack(side='right', padx=5)
  79.  
  80. self.tab_control = ttk.Notebook(self.root)
  81.  
  82. self.tab_employees = self.create_employee_tab()
  83. self.tab_control.add(self.tab_employees, text='الموظفين')
  84.  
  85. self.tab_attendance = self.create_attendance_tab()
  86. self.tab_control.add(self.tab_attendance, text='الحضور')
  87.  
  88. self.tab_salaries = self.create_salary_tab()
  89. self.tab_control.add(self.tab_salaries, text='الرواتب')
  90.  
  91. self.tab_leaves = self.create_leave_tab()
  92. self.tab_control.add(self.tab_leaves, text='الإجازات')
  93.  
  94. self.tab_performance = self.create_performance_tab()
  95. self.tab_control.add(self.tab_performance, text='التقييم')
  96.  
  97. self.tab_control.pack(expand=1, fill='both')
  98.  
  99. def create_employee_tab(self):
  100. tab = ttk.Frame(self.tab_control)
  101.  
  102. # ... (Rest of the employee tab code - same as before)
  103.  
  104. return tab
  105.  
  106. def create_attendance_tab(self):
  107. tab = ttk.Frame(self.tab_control)
  108.  
  109. # ... (Rest of the attendance tab code - same as before)
  110.  
  111. return tab
  112.  
  113. def create_salary_tab(self):
  114. tab = ttk.Frame(self.tab_control)
  115.  
  116. # ... (Rest of the salary tab code - same as before)
  117.  
  118. return tab
  119.  
  120. def create_leave_tab(self):
  121. tab = ttk.Frame(self.tab_control)
  122.  
  123. # ... (Rest of the leave tab code - same as before)
  124.  
  125. return tab
  126.  
  127. def create_performance_tab(self):
  128. tab = ttk.Frame(self.tab_control)
  129.  
  130. # ... (Rest of the performance tab code - same as before)
  131.  
  132. return tab
  133.  
  134.  
  135. def export_to_excel(self):
  136. try:
  137. wb = Workbook()
  138.  
  139. # تصدير الموظفين
  140. ws_emp = wb.active
  141. ws_emp.title = "الموظفين"
  142. ws_emp.append(['الرقم الوظيفي', 'الاسم', 'تاريخ الميلاد', 'الجنسية', 'تاريخ التعيين', 'القسم', 'الراتب']) # Include all columns
  143. employees = self.cursor.execute("SELECT id, name, dob, nationality, hire_date, department, salary FROM employees").fetchall() # Select all columns
  144. for emp in employees:
  145. ws_emp.append(emp)
  146.  
  147. # تصدير الرواتب
  148. ws_sal = wb.create_sheet("الرواتب")
  149. ws_sal.append(['الشهر', 'الأساسي', 'الخصومات', 'المكافآت', 'الصافي'])
  150. salaries = self.cursor.execute("SELECT month, basic, deductions, allowances, net FROM salaries").fetchall()
  151. for sal in salaries:
  152. ws_sal.append(sal)
  153.  
  154. # ... (Export other tables - attendance, leaves, performance)
  155.  
  156. wb.save("hr_export.xlsx")
  157. messagebox.showinfo("نجاح", "تم التصدير إلى hr_export.xlsx")
  158. except Exception as e:
  159. messagebox.showerror("خطأ", f"خطأ في التصدير: {str(e)}")
  160.  
  161. def update_emp_list(self):
  162. try:
  163. self.emp_selector['values'] = [row[0] for row in self.cursor.execute("SELECT id FROM employees").fetchall()]
  164. except Exception as e:
  165. messagebox.showerror("خطأ", str(e))
  166.  
  167. def select_employee(self, event):
  168. self.current_emp_id = self.emp_selector.get()
  169. # ... (Load and display details for the selected employee in the appropriate tabs) ...
  170.  
  171. def load_initial_data(self):
  172. self.update_emp_list() # Load employee list at start
  173. self.refresh_employee_table() # Refresh the employee table
  174.  
  175. def refresh_employee_table(self):
  176. try:
  177. self.employee_tree.delete(*self.employee_tree.get_children()) # Clear existing data
  178. employees = self.cursor.execute("SELECT id, name, dob, nationality, hire_date, department, salary FROM employees").fetchall()
  179. for employee in employees:
  180. self.employee_tree.insert("", tk.END, values=employee)
  181. except Exception as e:
  182. messagebox.showerror("Error", str(e))
  183.  
  184. # ... (Add other data loading/refresh functions for attendance, salaries, etc.)
  185.  
  186. def add_employee(self):
  187. try:
  188. data = [self.entries[label].get() for label in ['الرقم الوظيفي', 'الاسم', 'تاريخ الميلاد', 'الجنسية', 'تاريخ التعيين', 'القسم', 'الراتب']]
  189. self.cursor.execute("INSERT INTO employees VALUES (?, ?, ?, ?, ?, ?, ?)", data)
  190. self.conn.commit()
  191. self.refresh_employee_table() # Refresh the table after adding
  192. messagebox.showinfo("نجاح", "تمت إضافة الموظف.")
  193. # Clear the entry fields after adding (optional)
  194. for entry in self.entries.values():
  195. entry.delete(0, tk.END)
  196. except Exception as e:
  197. self.conn.rollback()
  198. messagebox.showerror("خطأ", str(e))
  199.  
  200. # ... (Implement update_employee, delete_employee, check_in, check_out, calculate_salary, submit_leave, save_performance)
  201.  
  202. if __name__ == "__main__":
  203. root = tk.Tk()
  204. app = AdvancedHRMS(root)
  205. root.mainloop()
  206.  
  207.  
Success #stdin #stdout 0.03s 26060KB
stdin
Standard input is empty
stdout
import tkinter as tk
from tkinter import ttk, messagebox
import sqlite3
from datetime import datetime
from openpyxl import Workbook

class AdvancedHRMS:
    def __init__(self, root):
        self.root = root
        self.root.title("نظام إدارة الموارد البشرية المتقدم")
        self.root.geometry("1400x900")

        self.create_database()
        self.create_widgets()
        self.load_initial_data()

        self.current_emp_id = None

    def create_database(self):
        self.conn = sqlite3.connect('advanced_hrms.db')
        self.cursor = self.conn.cursor()

        tables = [
            '''CREATE TABLE IF NOT EXISTS employees (
                id TEXT PRIMARY KEY,
                name TEXT,
                dob TEXT,
                nationality TEXT,
                hire_date TEXT,
                department TEXT,
                salary REAL)''',

            '''CREATE TABLE IF NOT EXISTS attendance (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                emp_id TEXT,
                date TEXT,
                check_in TEXT,
                check_out TEXT)''',

            '''CREATE TABLE IF NOT EXISTS salaries (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                emp_id TEXT,
                month TEXT,
                basic REAL,
                deductions REAL,
                allowances REAL,
                net REAL)''',

            '''CREATE TABLE IF NOT EXISTS leaves (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                emp_id TEXT,
                start_date TEXT,
                end_date TEXT,
                type TEXT,
                status TEXT DEFAULT 'معلق')''',

            '''CREATE TABLE IF NOT EXISTS performance (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                emp_id TEXT,
                date TEXT,
                productivity REAL,
                teamwork REAL,
                comments TEXT)'''
        ]

        for table in tables:
            self.cursor.execute(table)
        self.conn.commit()

    def create_widgets(self):
        toolbar = ttk.Frame(self.root)
        toolbar.pack(side='top', fill='x')

        self.emp_selector = ttk.Combobox(toolbar, postcommand=self.update_emp_list)
        self.emp_selector.pack(side='left', padx=5, pady=5)
        self.emp_selector.bind('<<ComboboxSelected>>', self.select_employee)

        ttk.Button(toolbar, text="تصدير Excel", command=self.export_to_excel).pack(side='right', padx=5)

        self.tab_control = ttk.Notebook(self.root)

        self.tab_employees = self.create_employee_tab()
        self.tab_control.add(self.tab_employees, text='الموظفين')

        self.tab_attendance = self.create_attendance_tab()
        self.tab_control.add(self.tab_attendance, text='الحضور')

        self.tab_salaries = self.create_salary_tab()
        self.tab_control.add(self.tab_salaries, text='الرواتب')

        self.tab_leaves = self.create_leave_tab()
        self.tab_control.add(self.tab_leaves, text='الإجازات')

        self.tab_performance = self.create_performance_tab()
        self.tab_control.add(self.tab_performance, text='التقييم')

        self.tab_control.pack(expand=1, fill='both')

    def create_employee_tab(self):
        tab = ttk.Frame(self.tab_control)

        # ... (Rest of the employee tab code - same as before)

        return tab

    def create_attendance_tab(self):
        tab = ttk.Frame(self.tab_control)

        # ... (Rest of the attendance tab code - same as before)

        return tab

    def create_salary_tab(self):
        tab = ttk.Frame(self.tab_control)

        # ... (Rest of the salary tab code - same as before)

        return tab

    def create_leave_tab(self):
        tab = ttk.Frame(self.tab_control)

        # ... (Rest of the leave tab code - same as before)

        return tab

    def create_performance_tab(self):
        tab = ttk.Frame(self.tab_control)

        # ... (Rest of the performance tab code - same as before)

        return tab


    def export_to_excel(self):
        try:
            wb = Workbook()

            # تصدير الموظفين
            ws_emp = wb.active
            ws_emp.title = "الموظفين"
            ws_emp.append(['الرقم الوظيفي', 'الاسم', 'تاريخ الميلاد', 'الجنسية', 'تاريخ التعيين', 'القسم', 'الراتب'])  # Include all columns
            employees = self.cursor.execute("SELECT id, name, dob, nationality, hire_date, department, salary FROM employees").fetchall() # Select all columns
            for emp in employees:
                ws_emp.append(emp)

            # تصدير الرواتب
            ws_sal = wb.create_sheet("الرواتب")
            ws_sal.append(['الشهر', 'الأساسي', 'الخصومات', 'المكافآت', 'الصافي'])
            salaries = self.cursor.execute("SELECT month, basic, deductions, allowances, net FROM salaries").fetchall()
            for sal in salaries:
                ws_sal.append(sal)

            # ... (Export other tables - attendance, leaves, performance)

            wb.save("hr_export.xlsx")
            messagebox.showinfo("نجاح", "تم التصدير إلى hr_export.xlsx")
        except Exception as e:
            messagebox.showerror("خطأ", f"خطأ في التصدير: {str(e)}")

    def update_emp_list(self):
        try:
            self.emp_selector['values'] = [row[0] for row in self.cursor.execute("SELECT id FROM employees").fetchall()]
        except Exception as e:
            messagebox.showerror("خطأ", str(e))

    def select_employee(self, event):
        self.current_emp_id = self.emp_selector.get()
        # ... (Load and display details for the selected employee in the appropriate tabs) ...

    def load_initial_data(self):
        self.update_emp_list()  # Load employee list at start
        self.refresh_employee_table() # Refresh the employee table

    def refresh_employee_table(self):
        try:
            self.employee_tree.delete(*self.employee_tree.get_children())  # Clear existing data
            employees = self.cursor.execute("SELECT id, name, dob, nationality, hire_date, department, salary FROM employees").fetchall()
            for employee in employees:
                self.employee_tree.insert("", tk.END, values=employee)
        except Exception as e:
            messagebox.showerror("Error", str(e))

    # ... (Add other data loading/refresh functions for attendance, salaries, etc.)

    def add_employee(self):
        try:
            data = [self.entries[label].get() for label in ['الرقم الوظيفي', 'الاسم', 'تاريخ الميلاد', 'الجنسية', 'تاريخ التعيين', 'القسم', 'الراتب']]
            self.cursor.execute("INSERT INTO employees VALUES (?, ?, ?, ?, ?, ?, ?)", data)
            self.conn.commit()
            self.refresh_employee_table()  # Refresh the table after adding
            messagebox.showinfo("نجاح", "تمت إضافة الموظف.")
            # Clear the entry fields after adding (optional)
            for entry in self.entries.values():
                entry.delete(0, tk.END)
        except Exception as e:
            self.conn.rollback()
            messagebox.showerror("خطأ", str(e))

    # ... (Implement update_employee, delete_employee, check_in, check_out, calculate_salary, submit_leave, save_performance)

if __name__ == "__main__":
    root = tk.Tk()
    app = AdvancedHRMS(root)
    root.mainloop()