Last active
July 1, 2021 13:41
-
-
Save zartilas/32dcbce9175aafde1aad1f765be7bcd2 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.4+commit.c7e474f2.js&optimize=false&runs=200&gist=
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
REMIX SMART CONTRACT BETTWEEN EMPLOYEES AND EMPLOYER | |
Remix SMART CONTRACT BETTWEEN EMPLOYEES AND EMPLOYER project is present when Remix loads very first time or there are no files existing in the File Explorer. | |
It contains 2 directories: | |
1. 'contracts': Holds two contracts with different complexity level, denoted with number prefix in file name. | |
2. 'Libraries': Holds two libraries to deploy the contracts. | |
To run a script, right click on file name in the file explorer and click 'Run'. Remember, Solidity file must already be compiled. | |
Output from script will appear in remix terminal. | |
Project for the Blockchain technologies course. | |
UNIVERSITY OF PIRAEUS 2021, DEPARMETS OF INFORMATICS | |
Development Team: | |
1. Zartilas Vasilios | |
2. Theodoridis Andreas | |
3. Pateras Nikolas | |
Copyleft © 2021 |
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
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0; | |
contract Supervisor{ | |
address supervisor; | |
modifier onlySupervisor() { | |
require(msg.sender == supervisor); | |
_; | |
} | |
constructor() { | |
supervisor = msg.sender; | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0; | |
import "../libraries/EmployeeValues.sol"; | |
import "../libraries/PromotionValues.sol"; | |
import "./Supervisor.sol"; | |
contract Employee is Supervisor { | |
//Employee mapping | |
using EmployeeValues for EmployeeValues.EmployeeInfo; | |
mapping(uint => EmployeeValues.EmployeeInfo) employeeStructs; | |
//Ids Strart from 1000 | |
uint256 employeeCrateId = 1000; | |
//Pronotes Available | |
uint private constant allPromotes = 20; | |
uint private promoteCount = 0; | |
function insertEmployee ( | |
string memory firstName, | |
string memory lastName, | |
string memory workingPosition, | |
uint256 workingPeriod, | |
uint256 wage) public returns (uint256 ID) { | |
employeeCrateId += 1; | |
employeeStructs[employeeCrateId] = EmployeeValues.EmployeeInfo(employeeCrateId, firstName, lastName,workingPosition,workingPeriod,wage,true,0); | |
return employeeCrateId; | |
} | |
function takeLeave(uint256 ID, bool sickleave,uint256 leaveDays) public returns(bool successLeave){ | |
if (employeeStructs[ID].isEmployee){ | |
if(!sickleave){ | |
if(employeeStructs[ID].leave >= leaveDays){ | |
employeeStructs[ID].leave = employeeStructs[ID].leave - leaveDays; | |
return true; | |
} return false; | |
}else if(sickleave){ | |
return true; | |
} | |
} return false; | |
} | |
function approveLeave(uint256 IDEmployee, uint256 leaveDays) public onlySupervisor returns(bool successLeave){ | |
if (employeeStructs[IDEmployee].isEmployee){ | |
if(0 < leaveDays){ | |
employeeStructs[IDEmployee].leave = employeeStructs[IDEmployee].leave + leaveDays; | |
return true; | |
} | |
return false; | |
} | |
} | |
function editEmployee(uint256 ID, | |
string memory editfirstName, | |
string memory editlastName, | |
string memory editworkingPosition, | |
uint256 editworkingPeriod, | |
uint256 editwage) public returns (bool successEdit){ | |
if (employeeStructs[ID].isEmployee){ | |
employeeStructs[ID].firstName = editfirstName; | |
employeeStructs[ID].lastName = editlastName; | |
employeeStructs[ID].workingPosition = editworkingPosition; | |
employeeStructs[ID].workingPeriod = editworkingPeriod; | |
employeeStructs[ID].wage = editwage; | |
return true; | |
} | |
return false; | |
} | |
function deleteEmployee(uint256 ID) public onlySupervisor returns(bool successDelete){ | |
if (employeeStructs[ID].isEmployee){ | |
delete employeeStructs[ID]; | |
promoteCount -= 1; | |
return true; | |
} | |
return false; | |
} | |
function promoteAvailable() internal returns (bool isAvailablePromote) { | |
if (promoteCount < allPromotes) { | |
promoteCount += 1; | |
return true ; | |
} | |
return false ; | |
} | |
function givePromotion(uint256 ID) public payable returns(string memory NEWPOSITION,uint256 WAGE) { | |
if(promoteAvailable()){ | |
if( keccak256(abi.encodePacked(employeeStructs[ID].workingPosition)) == keccak256(abi.encodePacked(PromotionValues.workingPositionJunior)) | |
&& employeeStructs[ID].workingPeriod >= 5) { | |
employeeStructs[ID].workingPosition = PromotionValues.workingPositionSenior; | |
employeeStructs[ID].wage = employeeStructs[ID].wage + PromotionValues.wage500; | |
}else if( keccak256(abi.encodePacked(employeeStructs[ID].workingPosition)) == keccak256(abi.encodePacked(PromotionValues.workingPositionSenior)) | |
&& employeeStructs[ID].workingPeriod >= 8) { | |
employeeStructs[ID].workingPosition = PromotionValues.workingPositionHead; | |
employeeStructs[ID].wage = employeeStructs[ID].wage + PromotionValues.wage700; | |
}else if( keccak256(abi.encodePacked(employeeStructs[ID].workingPosition)) == keccak256(abi.encodePacked(PromotionValues.workingPositionHead)) | |
&& employeeStructs[ID].workingPeriod >= 10) { | |
employeeStructs[ID].workingPosition = PromotionValues.workingPositionDirector; | |
employeeStructs[ID].wage = employeeStructs[ID].wage + PromotionValues.wage1000; | |
}else if( keccak256(abi.encodePacked(employeeStructs[ID].workingPosition)) == keccak256(abi.encodePacked(PromotionValues.workingPositionDirector)) | |
&& employeeStructs[ID].workingPeriod >= 15) { | |
employeeStructs[ID].workingPosition = PromotionValues.workingPositionCeo; | |
employeeStructs[ID].wage = employeeStructs[ID].wage +PromotionValues.wage1500; | |
}else{ | |
require(true,"No Promote Available"); | |
} | |
return (employeeStructs[ID].workingPosition, employeeStructs[ID].wage); | |
} | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0; | |
library EmployeeValues { | |
struct EmployeeInfo{ | |
uint id; | |
string firstName; | |
string lastName; | |
string workingPosition; | |
uint256 workingPeriod; | |
uint256 wage; | |
bool isEmployee; | |
uint256 leave; | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0; | |
library PromotionValues { | |
// Promotions | |
string public constant workingPositionJunior = "Junior"; | |
string public constant workingPositionSenior = "Senior"; | |
string public constant workingPositionHead = "Head"; | |
string public constant workingPositionDirector = "Director"; | |
string public constant workingPositionCeo = "Ceo"; | |
// Wage | |
uint public constant wage500 = 500; | |
uint public constant wage700 = 700; | |
uint public constant wage1000 = 1000; | |
uint public constant wage1500 = 1500; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment