-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPayrollSystem.sol
More file actions
66 lines (51 loc) · 1.94 KB
/
Copy pathPayrollSystem.sol
File metadata and controls
66 lines (51 loc) · 1.94 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
contract PayrollSystem {
address public owner;
struct Employee {
string name;
uint salary;
uint lastPaid;
bool active;
}
mapping(address => Employee) public employees;
address[] public employeeList;
event EmployeeAdded(address employee, string name, uint salary);
event EmployeeRemoved(address employee);
event SalaryPaid(address employee, uint amount);
modifier onlyOwner() {
require(msg.sender == owner, "Not authorized");
_;
}
constructor() {
owner = msg.sender;
}
function addEmployee(address _employee, string memory _name, uint _salary) public onlyOwner {
require(!employees[_employee].active, "Already added");
employees[_employee] = Employee(_name, _salary, 0, true);
employeeList.push(_employee);
emit EmployeeAdded(_employee, _name, _salary);
}
function removeEmployee(address _employee) public onlyOwner {
require(employees[_employee].active, "Not active");
employees[_employee].active = false;
emit EmployeeRemoved(_employee);
}
function deposit() public payable onlyOwner {}
function payEmployee(address _employee) public onlyOwner {
Employee storage emp = employees[_employee];
require(emp.active, "Not active");
require(address(this).balance >= emp.salary, "Not enough balance");
emp.lastPaid = block.timestamp;
payable(_employee).transfer(emp.salary);
emit SalaryPaid(_employee, emp.salary);
}
function getEmployee(address _employee) public view returns (string memory, uint, uint, bool) {
Employee memory emp = employees[_employee];
return (emp.name, emp.salary, emp.lastPaid, emp.active);
}
function getContractBalance() public view returns (uint) {
return address(this).balance;
}
receive() external payable {}
}