-
Notifications
You must be signed in to change notification settings - Fork 0
/
FIR.sol
199 lines (187 loc) · 5.78 KB
/
FIR.sol
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract Complaint {
address public officer;
address public owner;
uint256 public nextId;
uint256 public noApprovedComplaint;
uint256 public noSolvedComplaint;
uint256 public noDiscardComplaint;
constructor(address _officer) {
owner = msg.sender;
officer = _officer;
nextId = 1;
noApprovedComplaint=0;
noSolvedComplaint=0;
noDiscardComplaint=0;
}
modifier onlyOwner() {
require(
msg.sender == owner,
"You are not the owner of this smart contract"
);
_;
}
modifier onlyOfficer() {
require(
msg.sender == officer,
"You are not registered officer of this smart contract"
);
_;
}
struct complaint {
uint256 id;
address complaintRegisteredBy;
string title;
string description;
string approvalRemark;
string resolutionRemark;
bool isApproved;
bool isResolved;
bool exists;
uint timestamp;
}
mapping(uint256 => complaint) public Complaints;
complaint[] pendingApprovals;
complaint[] pendingResolutions;
complaint[] solvedComplaints;
complaint[] discardComplaints;
event complaintFiled(
uint256 id,
address complaintRegisteredBy,
string title
);
function fileComplaint(string memory _title, string memory _description)
public
{
complaint storage newComplaint = Complaints[nextId];
newComplaint.id = nextId;
newComplaint.complaintRegisteredBy = msg.sender;
newComplaint.title = _title;
newComplaint.description = _description;
newComplaint.approvalRemark = "Pending Approval";
newComplaint.resolutionRemark = "Pending Resolution";
newComplaint.isApproved = false;
newComplaint.isResolved = false;
newComplaint.exists = true;
newComplaint.timestamp=block.timestamp;
pendingApprovals.push(newComplaint);
pendingResolutions.push(newComplaint);
emit complaintFiled(nextId, msg.sender, _title);
nextId++;
}
function approveComplaint(uint256 _id, string memory _approvalRemark)
public
onlyOfficer
{
require(
Complaints[_id].exists == true,
"This complaint id does not exist"
);
require(
Complaints[_id].isApproved == false,
"Complaint is already approved"
);
Complaints[_id].isApproved = true;
delete pendingApprovals;
for (uint256 i = 1; i < nextId; i++) {
if (
Complaints[i].isApproved == false &&
Complaints[i].exists == true
) {
pendingApprovals.push(Complaints[i]);
}
}
Complaints[_id].approvalRemark = _approvalRemark;
noApprovedComplaint++;
}
function discardComplaint(uint256 _id, string memory _approvalRemark)
public
onlyOfficer
{
require(
Complaints[_id].exists == true,
"This complaint id does not exist"
);
require(
Complaints[_id].isApproved == false,
"Complaint is already approved"
);
Complaints[_id].exists = false;
delete discardComplaints;
for (uint256 i = 1; i < nextId; i++) {
if (
Complaints[i].exists == false
) {
discardComplaints.push(Complaints[i]);
}
}
delete pendingApprovals;
for (uint256 i = 1; i < nextId; i++) {
if (
Complaints[i].isApproved == false &&
Complaints[i].exists == true
) {
pendingApprovals.push(Complaints[i]);
}
}
Complaints[_id].approvalRemark = _approvalRemark;
noDiscardComplaint++;
}
function resolveComplaint(uint256 _id, string memory _resolutionRemark)
public
onlyOfficer
{
require(
Complaints[_id].exists == true,
"This complaint id does not exist"
);
require(
Complaints[_id].isApproved == true,
"Complaint is not yet approved"
);
require(
Complaints[_id].isResolved == false,
"Complaint is already resolved"
);
Complaints[_id].isResolved = true;
delete pendingResolutions;
for (uint256 i = 1; i < nextId; i++) {
if (
Complaints[i].isResolved == false &&
Complaints[i].exists == true
) {
pendingResolutions.push(Complaints[i]);
}
}
delete solvedComplaints;
for (uint256 i = 1; i < nextId; i++) {
if (
Complaints[i].isResolved ==true &&
Complaints[i].exists == true
) {
solvedComplaints.push(Complaints[i]);
}
}
Complaints[_id].resolutionRemark = _resolutionRemark;
noSolvedComplaint++;
}
function getMonth(uint id) public view returns(uint){
return Complaints[id].timestamp;
}
function getAllPendingApprovals() public view returns(complaint[] memory){
return pendingApprovals;
}
function getAllNotResolvedComplaint() public view returns(complaint[] memory){
return pendingResolutions;
}
function getSolvedComplaints() public view returns(complaint[] memory){
return solvedComplaints;
}
function getDiscardedComplaints() public view returns(complaint[] memory){
return discardComplaints;
}
function setOfficerAddress(address _officer) public onlyOwner {
officer = _officer;
}
}