forked from magonicolas/Ethereum-Solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSallary.sol
More file actions
102 lines (86 loc) · 2.83 KB
/
Sallary.sol
File metadata and controls
102 lines (86 loc) · 2.83 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
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
pragma solidity ^0.4.0;
contract Salary {
uint256 public amountToPay;
address owner;
event Status(string _msg, address user, uint amount);
struct Employee {
string name;
uint256 salary;
bool isActive;
address account;
}
Employee[] public employees;
function Salary() payable {
owner = msg.sender;
}
modifier onlyOwner {
if (msg.sender != owner) {
revert();
} else {
_;
}
}
function regiterEmployee(string _name) {
employees.push(Employee({
name: _name,
salary: 0,
isActive: false,
account: msg.sender
}));
Status('Registered employee', msg.sender, msg.value);
}
function setSallary(address employeeAddress, uint256 _salary) onlyOwner {
for(uint i = 0; i < employees.length; i++) {
if (employees[i].account == employeeAddress) {
employees[i].isActive = true;
employees[i].salary = _salary;
Status('Salary Set', msg.sender, msg.value);
}
}
}
function quit(address employeeAddress) {
for(uint i = 0; i < employees.length; i++) {
if (employees[i].account == employeeAddress) {
employees[i].isActive = false;
employees[i].salary = 0;
Status('Employee has quit', employeeAddress, msg.value);
}
}
}
function fired(address employeeAddress) {
for(uint i = 0; i < employees.length; i++) {
if (employees[i].account == employeeAddress) {
employees[i].isActive = false;
employees[i].salary = 0;
Status('Employee Fired', employeeAddress, msg.value);
}
}
}
function updateAmountToPay() {
amountToPay = 0;
for(uint i = 0; i < employees.length; i++) {
if(employees[i].isActive == true) {
amountToPay += employees[i].salary;
}
}
Status('Amount Updated', msg.sender, msg.value);
}
function payDay() onlyOwner payable {
updateAmountToPay();
if(this.balance >= amountToPay) {
for(uint j = 0; j < employees.length; j++) {
if(employees[j].isActive == true) {
employees[j].account.transfer(employees[j].salary);
}
}
Status('Pay Day Executed Succesfully', msg.sender, msg.value);
} else {
Status('Pay Day Failed, not enought Balance', msg.sender, msg.value);
revert();
}
}
function kill() onlyOwner {
Status('Contracted Killed, not longer avaikable to use', msg.sender, msg.value);
suicide(owner);
}
}