Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 109 |
|
0.00% |
0 / 14 |
CRAP | |
0.00% |
0 / 1 |
| Approvals | |
0.00% |
0 / 109 |
|
0.00% |
0 / 14 |
930 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| get_approvals | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| update_approval | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| list_approvers | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |||
| list_workflow_approvers | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| create_approver | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| create_approver_v2 | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| create_workflow_approver | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| delete_approver | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| delete_approver_v2 | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| delete_workflow_approver | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| list_approval_budget_types | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| create_approval_budget_type | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| delete_approval_budget_type | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers; |
| 4 | |
| 5 | use App\Models\TblApprovalBudgetTypes; |
| 6 | use App\Models\TblApprovers; |
| 7 | use App\Models\TblApproversV2; |
| 8 | use App\Models\TblWorkflowApprover; |
| 9 | use App\Models\TblUsers; |
| 10 | use App\Models\TblBudgetTypes; |
| 11 | use App\Models\TblApprovals; |
| 12 | use Illuminate\Http\Request; |
| 13 | use Illuminate\Support\Facades\DB; |
| 14 | use Illuminate\Support\Facades\App; |
| 15 | |
| 16 | class Approvals extends Controller |
| 17 | { |
| 18 | public function __construct(){ |
| 19 | $this->locale = @getallheaders()['Locale-ID']; |
| 20 | $this->userId = @getallheaders()['User-ID']; |
| 21 | |
| 22 | App::setLocale($this->locale); |
| 23 | } |
| 24 | |
| 25 | function get_approvals(){ |
| 26 | |
| 27 | try { |
| 28 | |
| 29 | $result = TblApprovals::first(); |
| 30 | |
| 31 | return response([ |
| 32 | 'message' => 'OK', |
| 33 | 'data' => $result |
| 34 | ]); |
| 35 | |
| 36 | } catch (\Exception $e) { |
| 37 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 38 | } |
| 39 | |
| 40 | } |
| 41 | |
| 42 | function update_approval(Request $request, $approvalId){ |
| 43 | |
| 44 | try { |
| 45 | |
| 46 | $data = $request->all(); |
| 47 | $approvalId = addslashes($approvalId); |
| 48 | |
| 49 | $data['updated_at'] = date('Y-m-d H:i:s'); |
| 50 | $result = TblApprovals::where('approval_id', $approvalId)->update($data); |
| 51 | |
| 52 | return response([ |
| 53 | 'message' => 'OK', |
| 54 | 'data' => $result |
| 55 | ]); |
| 56 | |
| 57 | } catch (\Exception $e) { |
| 58 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 59 | } |
| 60 | |
| 61 | } |
| 62 | |
| 63 | |
| 64 | function list_approvers($companyId){ |
| 65 | |
| 66 | try { |
| 67 | |
| 68 | $companyId = addslashes($companyId); |
| 69 | |
| 70 | $query = "SELECT |
| 71 | a.id, |
| 72 | a.name, |
| 73 | a.email |
| 74 | FROM |
| 75 | tbl_users a |
| 76 | LEFT JOIN tbl_approvers b |
| 77 | ON a.id = b.user_id |
| 78 | WHERE b.company_id = {$companyId} |
| 79 | ORDER BY a.name ASC"; |
| 80 | |
| 81 | $result = DB::select($query); |
| 82 | |
| 83 | |
| 84 | $query = "SELECT |
| 85 | a.id, |
| 86 | a.name, |
| 87 | a.email |
| 88 | FROM |
| 89 | tbl_users a |
| 90 | LEFT JOIN tbl_approvers_v2 b |
| 91 | ON a.id = b.user_id |
| 92 | WHERE b.company_id = {$companyId} |
| 93 | ORDER BY a.name ASC"; |
| 94 | |
| 95 | $resultV2 = DB::select($query); |
| 96 | |
| 97 | return response([ |
| 98 | 'message' => 'OK', |
| 99 | 'data' => $result, |
| 100 | 'dataV2' => $resultV2 |
| 101 | ]); |
| 102 | |
| 103 | } catch (\Exception $e) { |
| 104 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 105 | } |
| 106 | |
| 107 | } |
| 108 | |
| 109 | function list_workflow_approvers($companyId){ |
| 110 | |
| 111 | try { |
| 112 | |
| 113 | $companyId = addslashes($companyId); |
| 114 | |
| 115 | $query = "SELECT |
| 116 | a.id, |
| 117 | a.name, |
| 118 | a.email, |
| 119 | ( |
| 120 | SELECT |
| 121 | approver_id |
| 122 | FROM |
| 123 | tbl_workflow_approvers |
| 124 | WHERE |
| 125 | user_id = a.id |
| 126 | AND company_id = {$companyId} |
| 127 | ) is_selected |
| 128 | FROM |
| 129 | tbl_users a |
| 130 | ORDER BY a.name ASC"; |
| 131 | |
| 132 | $result = DB::select($query); |
| 133 | |
| 134 | return response([ |
| 135 | 'message' => 'OK', |
| 136 | 'data' => $result |
| 137 | ]); |
| 138 | |
| 139 | } catch (\Exception $e) { |
| 140 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 141 | } |
| 142 | |
| 143 | } |
| 144 | |
| 145 | function create_approver(Request $request){ |
| 146 | |
| 147 | try { |
| 148 | |
| 149 | $data = $request->all(); |
| 150 | |
| 151 | $count = TblApprovers::where('user_id', $data['user_id'])->where('company_id', $data['company_id'])->count(); |
| 152 | |
| 153 | if($count == 0){ |
| 154 | TblApprovers::create($data); |
| 155 | } |
| 156 | |
| 157 | TblApproversV2::where('user_id', $data['user_id'])->where('company_id', $data['company_id'])->delete(); |
| 158 | |
| 159 | $result = $this->list_approvers($data['company_id']); |
| 160 | |
| 161 | return $result; |
| 162 | |
| 163 | } catch (\Exception $e) { |
| 164 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 165 | } |
| 166 | |
| 167 | } |
| 168 | |
| 169 | function create_approver_v2(Request $request){ |
| 170 | |
| 171 | try { |
| 172 | |
| 173 | $data = $request->all(); |
| 174 | |
| 175 | $count = TblApproversV2::where('user_id', $data['user_id'])->where('company_id', $data['company_id'])->count(); |
| 176 | |
| 177 | if($count == 0){ |
| 178 | TblApproversV2::create($data); |
| 179 | } |
| 180 | |
| 181 | TblApprovers::where('user_id', $data['user_id'])->where('company_id', $data['company_id'])->delete(); |
| 182 | |
| 183 | $result = $this->list_approvers($data['company_id']); |
| 184 | |
| 185 | return $result; |
| 186 | |
| 187 | } catch (\Exception $e) { |
| 188 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 189 | } |
| 190 | |
| 191 | } |
| 192 | |
| 193 | function create_workflow_approver(Request $request){ |
| 194 | |
| 195 | try { |
| 196 | |
| 197 | $data = $request->all(); |
| 198 | |
| 199 | $count = TblWorkflowApprover::where('user_id', $data['user_id'])->where('company_id', $data['company_id'])->count(); |
| 200 | |
| 201 | if($count == 0){ |
| 202 | TblWorkflowApprover::create($data); |
| 203 | } |
| 204 | |
| 205 | $result = $this->list_workflow_approvers($data['company_id']); |
| 206 | |
| 207 | return $result; |
| 208 | |
| 209 | } catch (\Exception $e) { |
| 210 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 211 | } |
| 212 | |
| 213 | } |
| 214 | |
| 215 | function delete_approver($userId){ |
| 216 | |
| 217 | try { |
| 218 | |
| 219 | $userId = addslashes($userId); |
| 220 | |
| 221 | TblApprovers::where('user_id', $userId)->delete(); |
| 222 | |
| 223 | return response(['message' => 'OK']); |
| 224 | |
| 225 | } catch (\Exception $e) { |
| 226 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 227 | } |
| 228 | |
| 229 | } |
| 230 | |
| 231 | function delete_approver_v2($userId){ |
| 232 | |
| 233 | try { |
| 234 | |
| 235 | $userId = addslashes($userId); |
| 236 | |
| 237 | TblApproversV2::where('user_id', $userId)->delete(); |
| 238 | |
| 239 | return response(['message' => 'OK']); |
| 240 | |
| 241 | } catch (\Exception $e) { |
| 242 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 243 | } |
| 244 | |
| 245 | } |
| 246 | |
| 247 | function delete_workflow_approver($userId){ |
| 248 | |
| 249 | try { |
| 250 | |
| 251 | $userId = addslashes($userId); |
| 252 | |
| 253 | TblWorkflowApprover::where('user_id', $userId)->delete(); |
| 254 | |
| 255 | return response(['message' => 'OK']); |
| 256 | |
| 257 | } catch (\Exception $e) { |
| 258 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 259 | } |
| 260 | |
| 261 | } |
| 262 | |
| 263 | function list_approval_budget_types(){ |
| 264 | |
| 265 | try { |
| 266 | |
| 267 | $query = "SELECT |
| 268 | a.budget_type_id, |
| 269 | a.name, |
| 270 | ( |
| 271 | SELECT |
| 272 | id |
| 273 | FROM |
| 274 | tbl_approval_budget_types |
| 275 | WHERE |
| 276 | budget_type_id = a.budget_type_id |
| 277 | ) is_selected |
| 278 | FROM |
| 279 | tbl_budget_types a |
| 280 | ORDER BY a.name ASC"; |
| 281 | |
| 282 | $result = DB::select($query); |
| 283 | |
| 284 | return response([ |
| 285 | 'message' => 'OK', |
| 286 | 'data' => $result |
| 287 | ]); |
| 288 | |
| 289 | } catch (\Exception $e) { |
| 290 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 291 | } |
| 292 | |
| 293 | } |
| 294 | |
| 295 | function create_approval_budget_type(Request $request){ |
| 296 | |
| 297 | try { |
| 298 | |
| 299 | $data = $request->all(); |
| 300 | |
| 301 | TblApprovalBudgetTypes::create($data); |
| 302 | |
| 303 | $result = $this->list_approval_budget_types(); |
| 304 | |
| 305 | return $result; |
| 306 | |
| 307 | } catch (\Exception $e) { |
| 308 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 309 | } |
| 310 | |
| 311 | } |
| 312 | |
| 313 | function delete_approval_budget_type($budgetTypeId){ |
| 314 | |
| 315 | try { |
| 316 | |
| 317 | $budgetTypeId = addslashes($budgetTypeId); |
| 318 | |
| 319 | TblApprovalBudgetTypes::where('budget_type_id', $budgetTypeId)->delete(); |
| 320 | |
| 321 | $result = $this->list_approval_budget_types(); |
| 322 | |
| 323 | return $result; |
| 324 | |
| 325 | } catch (\Exception $e) { |
| 326 | return response(['message' => 'KO', 'error' => $e->getMessage()]); |
| 327 | } |
| 328 | |
| 329 | } |
| 330 | } |