Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 681
0.00% covered (danger)
0.00%
0 / 61
CRAP
0.00% covered (danger)
0.00%
0 / 1
Configurations
0.00% covered (danger)
0.00%
0 / 681
0.00% covered (danger)
0.00%
0 / 61
24806
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 list_customer_types
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 list_segments
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 list_reasons
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 list_budget_types
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 list_budget_type_groups
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 list_visit_types
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 list_visit_type_groups
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 list_budget_status
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 list_source
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 list_reason_for_not_following_up
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 list_reason_for_rejection
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 customer_types
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 segments
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 reasons
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 budget_types
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 budget_type_groups
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 visit_types
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 visit_type_groups
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 budget_status
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 source
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 reason_for_not_following_up
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 reason_for_rejection
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 add_customer_types
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 add_segments
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 add_reasons
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 add_budget_types
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 add_budget_type_groups
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 add_visit_types
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 add_visit_type_groups
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 add_budget_status
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 add_source
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 add_reason_for_not_following_up
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 add_reason_for_rejection
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 update_customer_types
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
30
 update_segments
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
30
 update_reasons
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
30
 update_budget_types
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
30
 update_budget_type_groups
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
30
 update_visit_types
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
30
 update_visit_type_groups
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
30
 update_budget_status
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
30
 update_source
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
30
 update_reason_for_not_following_up
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
30
 update_reason_for_rejection
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
30
 delete_customer_types
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 delete_segments
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 delete_reasons
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 delete_budget_types
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 delete_budget_type_groups
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 delete_visit_types
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 delete_visit_type_groups
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 delete_budget_status
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 delete_source
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 delete_reason_for_not_following_up
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 delete_reason_for_rejection
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 list_work_status
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 work_status
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 update_work_status
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
30
 delete_work_status
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
12
 add_work_status
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace App\Http\Controllers;
4
5use App\Models\TblBudgetStatus;
6use App\Models\TblBudgetTypeGroups;
7use App\Models\TblBudgetTypes;
8use App\Models\TblCustomerTypes;
9use App\Models\TblOngoingJobs;
10use App\Models\TblPipelines;
11use App\Models\TblQuotations;
12use App\Models\TblReasonForNotFollowingUp;
13use App\Models\TblReasonForRejection;
14use App\Models\TblReasons;
15use App\Models\TblSegments;
16use App\Models\TblSources;
17use App\Models\TblVisitTypeGroups;
18use App\Models\TblVisitTypes;
19use App\Models\TblWorkStatus;
20use Illuminate\Http\Request;
21use Illuminate\Support\Facades\App;
22use Illuminate\Support\Facades\Cache;
23use Illuminate\Support\Facades\DB;
24
25class Configurations extends Controller
26{
27    private $locale;
28
29    private $customer_types = [];
30
31    private $segments = [];
32
33    private $reasons = [];
34
35    private $budget_types = [];
36
37    private $budget_status = [];
38
39    private $budget_type_groups = [];
40
41    private $source = [];
42
43    private $reason_for_not_following_up = [];
44
45    private $reason_for_rejection = [];
46
47    private $work_status = [];
48
49    private $visit_types = [];
50
51    private $visit_type_groups = [];
52
53    public function __construct()
54    {
55        $this->locale = @getallheaders()['Locale-ID'];
56
57        App::setLocale($this->locale);
58    }
59
60    public function list_customer_types()
61    {
62
63        try {
64
65            $this->customer_types();
66
67            return response([
68                'message' => 'OK',
69                'data' => $this->customer_types,
70            ]);
71
72        } catch (\Exception $e) {
73            /** @disregard P1014 */
74            $e->exceptionCode = 'LIST_CUSTOMER_TYPES_EXCEPTION';
75            report($e);
76
77            return response(['message' => 'KO', 'error' => $e->getMessage()]);
78        }
79
80    }
81
82    public function list_segments()
83    {
84
85        try {
86
87            $this->segments();
88
89            return response([
90                'message' => 'OK',
91                'data' => $this->segments,
92            ]);
93
94        } catch (\Exception $e) {
95            /** @disregard P1014 */
96            $e->exceptionCode = 'LIST_SEGMENTS_EXCEPTION';
97            report($e);
98
99            return response(['message' => 'KO', 'error' => $e->getMessage()]);
100        }
101
102    }
103
104    public function list_reasons()
105    {
106
107        try {
108
109            $this->reasons();
110
111            return response([
112                'message' => 'OK',
113                'data' => $this->reasons,
114            ]);
115
116        } catch (\Exception $e) {
117            /** @disregard P1014 */
118            $e->exceptionCode = 'LIST_REASONS_EXCEPTION';
119            report($e);
120
121            return response(['message' => 'KO', 'error' => $e->getMessage()]);
122        }
123
124    }
125
126    public function list_budget_types()
127    {
128
129        try {
130
131            $this->budget_types();
132
133            return response([
134                'message' => 'OK',
135                'data' => $this->budget_types,
136            ]);
137
138        } catch (\Exception $e) {
139            /** @disregard P1014 */
140            $e->exceptionCode = 'LIST_BUDGET_TYPES_EXCEPTION';
141            report($e);
142
143            return response(['message' => 'KO', 'error' => $e->getMessage()]);
144        }
145
146    }
147
148    public function list_budget_type_groups()
149    {
150
151        try {
152
153            $this->budget_type_groups();
154
155            return response([
156                'message' => 'OK',
157                'data' => $this->budget_type_groups,
158            ]);
159
160        } catch (\Exception $e) {
161            /** @disregard P1014 */
162            $e->exceptionCode = 'LIST_BUDGET_TYPE_GROUPS_EXCEPTION';
163            report($e);
164
165            return response(['message' => 'KO', 'error' => $e->getMessage()]);
166        }
167
168    }
169
170    public function list_visit_types()
171    {
172
173        try {
174
175            $this->visit_types();
176
177            return response([
178                'message' => 'OK',
179                'data' => $this->visit_types,
180            ]);
181
182        } catch (\Exception $e) {
183            /** @disregard P1014 */
184            $e->exceptionCode = 'LIST_VISIT_TYPES_EXCEPTION';
185            report($e);
186
187            return response(['message' => 'KO', 'error' => $e->getMessage()]);
188        }
189
190    }
191
192    public function list_visit_type_groups()
193    {
194
195        try {
196
197            $this->visit_type_groups();
198
199            return response([
200                'message' => 'OK',
201                'data' => $this->visit_type_groups,
202            ]);
203
204        } catch (\Exception $e) {
205            /** @disregard P1014 */
206            $e->exceptionCode = 'LIST_VISIT_TYPE_GROUPS_EXCEPTION';
207            report($e);
208
209            return response(['message' => 'KO', 'error' => $e->getMessage()]);
210        }
211
212    }
213
214    public function list_budget_status()
215    {
216
217        try {
218
219            $this->budget_status();
220
221            return response([
222                'message' => 'OK',
223                'data' => $this->budget_status,
224            ]);
225
226        } catch (\Exception $e) {
227            /** @disregard P1014 */
228            $e->exceptionCode = 'LIST_BUDGET_STATUS_EXCEPTION';
229            report($e);
230
231            return response(['message' => 'KO', 'error' => $e->getMessage()]);
232        }
233
234    }
235
236    public function list_source()
237    {
238
239        try {
240
241            $this->source();
242
243            return response([
244                'message' => 'OK',
245                'data' => $this->source,
246            ]);
247
248        } catch (\Exception $e) {
249            /** @disregard P1014 */
250            $e->exceptionCode = 'LIST_SOURCE_EXCEPTION';
251            report($e);
252
253            return response(['message' => 'KO', 'error' => $e->getMessage()]);
254        }
255
256    }
257
258    public function list_reason_for_not_following_up()
259    {
260
261        try {
262
263            $this->reason_for_not_following_up();
264
265            return response([
266                'message' => 'OK',
267                'data' => $this->reason_for_not_following_up,
268            ]);
269
270        } catch (\Exception $e) {
271            /** @disregard P1014 */
272            $e->exceptionCode = 'LIST_REASON_FOR_NOT_FOLLOWING_UP_EXCEPTION';
273            report($e);
274
275            return response(['message' => 'KO', 'error' => $e->getMessage()]);
276        }
277
278    }
279
280    public function list_reason_for_rejection()
281    {
282
283        try {
284
285            $this->reason_for_rejection();
286
287            return response([
288                'message' => 'OK',
289                'data' => $this->reason_for_rejection,
290            ]);
291
292        } catch (\Exception $e) {
293            /** @disregard P1014 */
294            $e->exceptionCode = 'LIST_REASON_FOR_REJECTION_EXCEPTION';
295            report($e);
296
297            return response(['message' => 'KO', 'error' => $e->getMessage()]);
298        }
299
300    }
301
302    public function customer_types()
303    {
304
305        $this->customer_types = TblCustomerTypes::orderByRaw('ISNULL(priority), priority ASC')->get();
306
307    }
308
309    public function segments()
310    {
311
312        $this->segments = TblSegments::orderByRaw('ISNULL(priority), priority ASC')->get();
313
314    }
315
316    public function reasons()
317    {
318
319        $this->reasons = TblReasons::orderByRaw('ISNULL(priority), priority ASC')->get();
320
321    }
322
323    public function budget_types()
324    {
325
326        $query = "SELECT
327                    bt.budget_type_id,
328                    bt.name,
329                    bt.duration,
330                    bt.priority,
331                    bt.color,
332                    bt.include,
333                    bt.budget_type_group_id,
334                    btg.name budget_type_group,
335                    bt.disabled,
336                    bt.created_by,
337                    bt.created_at
338                FROM tbl_budget_types bt
339                LEFT JOIN tbl_budget_type_groups btg
340                    ON bt.budget_type_group_id = btg.budget_type_group_id
341                WHERE bt.name != ''
342                ORDER BY ISNULL(bt.priority), bt.priority ASC";
343
344        $this->budget_types = DB::select($query);
345
346    }
347
348    public function budget_type_groups()
349    {
350
351        $this->budget_type_groups = TblBudgetTypeGroups::orderByRaw('ISNULL(priority), priority ASC')->get();
352
353    }
354
355    public function visit_types()
356    {
357
358        $query = 'SELECT
359                    vt.visit_type_id,
360                    vt.name,
361                    vt.priority,
362                    vt.visit_type_group_id,
363                    vtg.name visit_type_group,
364                    vt.disabled,
365                    vt.created_by,
366                    vt.created_at
367                FROM tbl_visit_types vt
368                LEFT JOIN tbl_visit_type_groups vtg
369                    ON vt.visit_type_group_id = vtg.visit_type_group_id
370                ORDER BY ISNULL(vt.priority), vt.priority ASC';
371
372        $this->visit_types = DB::select($query);
373
374    }
375
376    public function visit_type_groups()
377    {
378
379        $this->visit_type_groups = TblVisitTypeGroups::orderByRaw('ISNULL(priority), priority ASC')->get();
380
381    }
382
383    public function budget_status()
384    {
385
386        $this->budget_status = TblBudgetStatus::orderByRaw('ISNULL(priority), priority ASC')->get();
387
388    }
389
390    public function source()
391    {
392
393        $this->source = TblSources::orderByRaw('ISNULL(priority), priority ASC')->get();
394
395    }
396
397    public function reason_for_not_following_up()
398    {
399
400        $this->reason_for_not_following_up = TblReasonForNotFollowingUp::orderByRaw('ISNULL(priority), priority ASC')->get();
401
402    }
403
404    public function reason_for_rejection()
405    {
406
407        $this->reason_for_rejection = TblReasonForRejection::orderByRaw('ISNULL(priority), priority ASC')->get();
408
409    }
410
411    public function add_customer_types(Request $request)
412    {
413
414        try {
415
416            $data = $request->all();
417
418            TblCustomerTypes::create($data);
419
420            $this->customer_types();
421
422            return response([
423                'message' => 'OK',
424                'data' => $this->customer_types,
425            ]);
426
427        } catch (\Exception $e) {
428            /** @disregard P1014 */
429            $e->exceptionCode = 'ADD_CUSTOMER_TYPES_EXCEPTION';
430            report($e);
431
432            return response(['message' => 'KO', 'error' => $e->getMessage()]);
433        }
434
435    }
436
437    public function add_segments(Request $request)
438    {
439
440        try {
441
442            $data = $request->all();
443
444            TblSegments::create($data);
445
446            $this->segments();
447
448            return response([
449                'message' => 'OK',
450                'data' => $this->segments,
451            ]);
452
453        } catch (\Exception $e) {
454            /** @disregard P1014 */
455            $e->exceptionCode = 'ADD_SEGMENTS_EXCEPTION';
456            report($e);
457
458            return response(['message' => 'KO', 'error' => $e->getMessage()]);
459        }
460
461    }
462
463    public function add_reasons(Request $request)
464    {
465
466        try {
467
468            $data = $request->all();
469
470            TblReasons::create($data);
471
472            $this->reasons();
473
474            return response([
475                'message' => 'OK',
476                'data' => $this->reasons,
477            ]);
478
479        } catch (\Exception $e) {
480            /** @disregard P1014 */
481            $e->exceptionCode = 'ADD_REASONS_EXCEPTION';
482            report($e);
483
484            return response(['message' => 'KO', 'error' => $e->getMessage()]);
485        }
486
487    }
488
489    public function add_budget_types(Request $request)
490    {
491
492        try {
493
494            $data = $request->all();
495
496            TblBudgetTypes::create($data);
497
498            $this->budget_types();
499
500            return response([
501                'message' => 'OK',
502                'data' => $this->budget_types,
503            ]);
504
505        } catch (\Exception $e) {
506            /** @disregard P1014 */
507            $e->exceptionCode = 'ADD_BUDGET_TYPES_EXCEPTION';
508            report($e);
509
510            return response(['message' => 'KO', 'error' => $e->getMessage()]);
511        }
512
513    }
514
515    public function add_budget_type_groups(Request $request)
516    {
517
518        try {
519
520            $data = $request->all();
521
522            TblBudgetTypeGroups::create($data);
523
524            $this->budget_type_groups();
525
526            return response([
527                'message' => 'OK',
528                'data' => $this->budget_type_groups,
529            ]);
530
531        } catch (\Exception $e) {
532            /** @disregard P1014 */
533            $e->exceptionCode = 'ADD_BUDGET_TYPE_GROUPS_EXCEPTION';
534            report($e);
535
536            return response(['message' => 'KO', 'error' => $e->getMessage()]);
537        }
538
539    }
540
541    public function add_visit_types(Request $request)
542    {
543
544        try {
545
546            $data = $request->all();
547
548            TblVisitTypes::create($data);
549
550            $this->visit_types();
551
552            return response([
553                'message' => 'OK',
554                'data' => $this->visit_types,
555            ]);
556
557        } catch (\Exception $e) {
558            /** @disregard P1014 */
559            $e->exceptionCode = 'ADD_VISIT_TYPES_EXCEPTION';
560            report($e);
561
562            return response(['message' => 'KO', 'error' => $e->getMessage()]);
563        }
564
565    }
566
567    public function add_visit_type_groups(Request $request)
568    {
569
570        try {
571
572            $data = $request->all();
573
574            TblVisitTypeGroups::create($data);
575
576            $this->visit_type_groups();
577
578            return response([
579                'message' => 'OK',
580                'data' => $this->visit_type_groups,
581            ]);
582
583        } catch (\Exception $e) {
584            /** @disregard P1014 */
585            $e->exceptionCode = 'ADD_VISIT_TYPE_GROUPS_EXCEPTION';
586            report($e);
587
588            return response(['message' => 'KO', 'error' => $e->getMessage()]);
589        }
590
591    }
592
593    public function add_budget_status(Request $request)
594    {
595
596        try {
597
598            $data = $request->all();
599
600            TblBudgetStatus::create($data);
601
602            $this->budget_status();
603
604            return response([
605                'message' => 'OK',
606                'data' => $this->budget_status,
607            ]);
608
609        } catch (\Exception $e) {
610            /** @disregard P1014 */
611            $e->exceptionCode = 'ADD_BUDGET_STATUS_EXCEPTION';
612            report($e);
613
614            return response(['message' => 'KO', 'error' => $e->getMessage()]);
615        }
616
617    }
618
619    public function add_source(Request $request)
620    {
621
622        try {
623
624            $data = $request->all();
625
626            TblSources::create($data);
627
628            $this->source();
629
630            return response([
631                'message' => 'OK',
632                'data' => $this->source,
633            ]);
634
635        } catch (\Exception $e) {
636            /** @disregard P1014 */
637            $e->exceptionCode = 'ADD_SOURCE_EXCEPTION';
638            report($e);
639
640            return response(['message' => 'KO', 'error' => $e->getMessage()]);
641        }
642
643    }
644
645    public function add_reason_for_not_following_up(Request $request)
646    {
647
648        try {
649
650            $data = $request->all();
651
652            TblReasonForNotFollowingUp::create($data);
653
654            $this->reason_for_not_following_up();
655
656            return response([
657                'message' => 'OK',
658                'data' => $this->reason_for_not_following_up,
659            ]);
660
661        } catch (\Exception $e) {
662            /** @disregard P1014 */
663            $e->exceptionCode = 'ADD_REASON_FOR_NOT_FOLLOWING_UP_EXCEPTION';
664            report($e);
665
666            return response(['message' => 'KO', 'error' => $e->getMessage()]);
667        }
668
669    }
670
671    public function add_reason_for_rejection(Request $request)
672    {
673
674        try {
675
676            $data = $request->all();
677
678            TblReasonForRejection::create($data);
679
680            $this->reason_for_rejection();
681
682            return response([
683                'message' => 'OK',
684                'data' => $this->reason_for_rejection,
685            ]);
686
687        } catch (\Exception $e) {
688            /** @disregard P1014 */
689            $e->exceptionCode = 'ADD_REASON_FOR_REJECTION_EXCEPTION';
690            report($e);
691
692            return response(['message' => 'KO', 'error' => $e->getMessage()]);
693        }
694
695    }
696
697    public function update_customer_types(Request $request, $customerTypeId)
698    {
699
700        try {
701
702            $data = $request->all();
703            $customerTypeId = intval($customerTypeId);
704
705            if (isset($data['data'])) {
706                $priority = $data['data'];
707                if (count($priority) > 0) {
708                    foreach ($priority as $item) {
709                        TblCustomerTypes::where('customer_type_id', $item['customer_type_id'])->update(['priority' => $item['priority']]);
710                    }
711                }
712            } else {
713                TblCustomerTypes::where('customer_type_id', $customerTypeId)->update($data);
714            }
715
716            $this->customer_types();
717
718            return response([
719                'message' => 'OK',
720                'data' => $this->customer_types,
721            ]);
722
723        } catch (\Exception $e) {
724            /** @disregard P1014 */
725            $e->exceptionCode = 'UPDATE_CUSTOMER_TYPES_EXCEPTION';
726            report($e);
727
728            return response(['message' => 'KO', 'error' => $e->getMessage()]);
729        }
730
731    }
732
733    public function update_segments(Request $request, $segmentId)
734    {
735
736        try {
737
738            $data = $request->all();
739            $segmentId = intval($segmentId);
740
741            if (isset($data['data'])) {
742                $priority = $data['data'];
743                if (count($priority) > 0) {
744                    foreach ($priority as $item) {
745                        TblSegments::where('segment_id', $item['segment_id'])->update(['priority' => $item['priority']]);
746                    }
747                }
748            } else {
749                TblSegments::where('segment_id', $segmentId)->update($data);
750            }
751
752            $this->segments();
753
754            return response([
755                'message' => 'OK',
756                'data' => $this->segments,
757            ]);
758
759        } catch (\Exception $e) {
760            /** @disregard P1014 */
761            $e->exceptionCode = 'UPDATE_SEGMENTS_EXCEPTION';
762            report($e);
763
764            return response(['message' => 'KO', 'error' => $e->getMessage()]);
765        }
766
767    }
768
769    public function update_reasons(Request $request, $reasonId)
770    {
771
772        try {
773
774            $data = $request->all();
775            $reasonId = intval($reasonId);
776
777            if (isset($data['data'])) {
778                $priority = $data['data'];
779                if (count($priority) > 0) {
780                    foreach ($priority as $item) {
781                        TblReasons::where('reason_id', $item['reason_id'])->update(['priority' => $item['priority']]);
782                    }
783                }
784            } else {
785                TblReasons::where('reason_id', $reasonId)->update($data);
786            }
787
788            $this->reasons();
789
790            return response([
791                'message' => 'OK',
792                'data' => $this->reasons,
793            ]);
794
795        } catch (\Exception $e) {
796            /** @disregard P1014 */
797            $e->exceptionCode = 'UPDATE_REASONS_EXCEPTION';
798            report($e);
799
800            return response(['message' => 'KO', 'error' => $e->getMessage()]);
801        }
802
803    }
804
805    public function update_budget_types(Request $request, $budgetTypeId)
806    {
807
808        try {
809
810            $data = $request->all();
811            $budgetTypeId = intval($budgetTypeId);
812
813            if (isset($data['data'])) {
814                $priority = $data['data'];
815                if (count($priority) > 0) {
816                    foreach ($priority as $item) {
817                        TblBudgetTypes::where('budget_type_id', $item['budget_type_id'])->update(['priority' => $item['priority']]);
818                    }
819                }
820            } else {
821                TblBudgetTypes::where('budget_type_id', $budgetTypeId)->update($data);
822            }
823
824            Cache::flush();
825            $this->budget_types();
826
827            return response([
828                'message' => 'OK',
829                'data' => $this->budget_types,
830            ]);
831
832        } catch (\Exception $e) {
833            /** @disregard P1014 */
834            $e->exceptionCode = 'UPDATE_BUDGET_TYPES_EXCEPTION';
835            report($e);
836
837            return response(['message' => 'KO', 'error' => $e->getMessage()]);
838        }
839
840    }
841
842    public function update_budget_type_groups(Request $request, $budgetTypeGroupId)
843    {
844
845        try {
846
847            $data = $request->all();
848            $budgetTypeGroupId = intval($budgetTypeGroupId);
849
850            if (isset($data['data'])) {
851                $priority = $data['data'];
852                if (count($priority) > 0) {
853                    foreach ($priority as $item) {
854                        TblBudgetTypeGroups::where('budget_type_group_id', $item['budget_type_group_id'])->update(['priority' => $item['priority']]);
855                    }
856                }
857            } else {
858                TblBudgetTypeGroups::where('budget_type_group_id', $budgetTypeGroupId)->update($data);
859            }
860
861            Cache::flush();
862            $this->budget_type_groups();
863
864            return response([
865                'message' => 'OK',
866                'data' => $this->budget_type_groups,
867            ]);
868
869        } catch (\Exception $e) {
870            /** @disregard P1014 */
871            $e->exceptionCode = 'UPDATE_BUDGET_TYPE_GROUPS_EXCEPTION';
872            report($e);
873
874            return response(['message' => 'KO', 'error' => $e->getMessage()]);
875        }
876
877    }
878
879    public function update_visit_types(Request $request, $visitTypeId)
880    {
881
882        try {
883
884            $data = $request->all();
885            $visitTypeId = intval($visitTypeId);
886
887            if (isset($data['data'])) {
888                $priority = $data['data'];
889                if (count($priority) > 0) {
890                    foreach ($priority as $item) {
891                        TblVisitTypes::where('visit_type_id', $item['visit_type_id'])->update(['priority' => $item['priority']]);
892                    }
893                }
894            } else {
895                TblVisitTypes::where('visit_type_id', $visitTypeId)->update($data);
896            }
897
898            $this->visit_types();
899
900            return response([
901                'message' => 'OK',
902                'data' => $this->visit_types,
903            ]);
904
905        } catch (\Exception $e) {
906            /** @disregard P1014 */
907            $e->exceptionCode = 'UPDATE_VISIT_TYPES_EXCEPTION';
908            report($e);
909
910            return response(['message' => 'KO', 'error' => $e->getMessage()]);
911        }
912
913    }
914
915    public function update_visit_type_groups(Request $request, $visitTypeGroupId)
916    {
917
918        try {
919
920            $data = $request->all();
921            $visitTypeGroupId = intval($visitTypeGroupId);
922
923            if (isset($data['data'])) {
924                $priority = $data['data'];
925                if (count($priority) > 0) {
926                    foreach ($priority as $item) {
927                        TblVisitTypeGroups::where('visit_type_group_id', $item['visit_type_group_id'])->update(['priority' => $item['priority']]);
928                    }
929                }
930            } else {
931                TblVisitTypeGroups::where('visit_type_group_id', $visitTypeGroupId)->update($data);
932            }
933
934            Cache::flush();
935            $this->visit_type_groups();
936
937            return response([
938                'message' => 'OK',
939                'data' => $this->visit_type_groups,
940            ]);
941
942        } catch (\Exception $e) {
943            /** @disregard P1014 */
944            $e->exceptionCode = 'UPDATE_VISIT_TYPE_GROUPS_EXCEPTION';
945            report($e);
946
947            return response(['message' => 'KO', 'error' => $e->getMessage()]);
948        }
949
950    }
951
952    public function update_budget_status(Request $request, $budgetStatusId)
953    {
954
955        try {
956
957            $data = $request->all();
958            $budgetStatusId = intval($budgetStatusId);
959
960            if (isset($data['data'])) {
961                $priority = $data['data'];
962                if (count($priority) > 0) {
963                    foreach ($priority as $item) {
964                        TblBudgetStatus::where('budget_status_id', $item['budget_status_id'])->update(['priority' => $item['priority']]);
965                    }
966                }
967            } else {
968                TblBudgetStatus::where('budget_status_id', $budgetStatusId)->update($data);
969            }
970
971            $this->budget_status();
972
973            return response([
974                'message' => 'OK',
975                'data' => $this->budget_status,
976            ]);
977
978        } catch (\Exception $e) {
979            /** @disregard P1014 */
980            $e->exceptionCode = 'UPDATE_BUDGET_STATUS_EXCEPTION';
981            report($e);
982
983            return response(['message' => 'KO', 'error' => $e->getMessage()]);
984        }
985
986    }
987
988    public function update_source(Request $request, $sourceId)
989    {
990
991        try {
992
993            $data = $request->all();
994            $sourceId = intval($sourceId);
995
996            if (isset($data['data'])) {
997                $priority = $data['data'];
998                if (count($priority) > 0) {
999                    foreach ($priority as $item) {
1000                        TblSources::where('source_id', $item['source_id'])->update(['priority' => $item['priority']]);
1001                    }
1002                }
1003            } else {
1004                TblSources::where('source_id', $sourceId)->update($data);
1005            }
1006
1007            $this->source();
1008
1009            return response([
1010                'message' => 'OK',
1011                'data' => $this->source,
1012            ]);
1013
1014        } catch (\Exception $e) {
1015            /** @disregard P1014 */
1016            $e->exceptionCode = 'UPDATE_SOURCE_EXCEPTION';
1017            report($e);
1018
1019            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1020        }
1021
1022    }
1023
1024    public function update_reason_for_not_following_up(Request $request, $reasonForNotFollowingUpId)
1025    {
1026
1027        try {
1028
1029            $data = $request->all();
1030            $reasonForNotFollowingUpId = intval($reasonForNotFollowingUpId);
1031
1032            if (isset($data['data'])) {
1033                $priority = $data['data'];
1034                if (count($priority) > 0) {
1035                    foreach ($priority as $item) {
1036                        TblSources::where('reason_for_not_following_up_id', $item['reason_for_not_following_up_id'])->update(['priority' => $item['priority']]);
1037                    }
1038                }
1039            } else {
1040                TblReasonForNotFollowingUp::where('reason_for_not_following_up_id', $reasonForNotFollowingUpId)->update($data);
1041            }
1042
1043            $this->reason_for_not_following_up();
1044
1045            return response([
1046                'message' => 'OK',
1047                'data' => $this->reason_for_not_following_up,
1048            ]);
1049
1050        } catch (\Exception $e) {
1051            /** @disregard P1014 */
1052            $e->exceptionCode = 'UPDATE_REASON_FOR_NOT_FOLLOWING_UP_EXCEPTION';
1053            report($e);
1054
1055            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1056        }
1057
1058    }
1059
1060    public function update_reason_for_rejection(Request $request, $reasonForRejectionId)
1061    {
1062
1063        try {
1064
1065            $data = $request->all();
1066            $reasonForRejectionId = intval($reasonForRejectionId);
1067
1068            if (isset($data['data'])) {
1069                $priority = $data['data'];
1070                if (count($priority) > 0) {
1071                    foreach ($priority as $item) {
1072                        TblReasonForRejection::where('reason_for_rejection_id', $item['reason_for_rejection_id'])->update(['priority' => $item['priority']]);
1073                    }
1074                }
1075            } else {
1076                TblReasonForRejection::where('reason_for_rejection_id', $reasonForRejectionId)->update($data);
1077            }
1078
1079            $this->reason_for_rejection();
1080
1081            return response([
1082                'message' => 'OK',
1083                'data' => $this->reason_for_rejection,
1084            ]);
1085
1086        } catch (\Exception $e) {
1087            /** @disregard P1014 */
1088            $e->exceptionCode = 'UPDATE_REASON_FOR_REJECTION_EXCEPTION';
1089            report($e);
1090
1091            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1092        }
1093
1094    }
1095
1096    public function delete_customer_types($customerTypeId)
1097    {
1098
1099        try {
1100
1101            $customerTypeId = intval($customerTypeId);
1102
1103            $budgets = TblQuotations::where('customer_type_id', $customerTypeId)->count();
1104
1105            if ($budgets > 0) {
1106                return response([
1107                    'message' => 'KO',
1108                    'error' => __('language.customer_types.delete_message.message1').' '.$budgets.' '.__('language.customer_types.delete_message.message2'),
1109                ]);
1110            }
1111
1112            $customerType = TblCustomerTypes::where('customer_type_id', $customerTypeId)->first();
1113            TblCustomerTypes::where('customer_type_id', $customerTypeId)->delete();
1114
1115            $this->customer_types();
1116
1117            return response([
1118                'message' => 'OK',
1119                'data' => $this->customer_types,
1120            ]);
1121
1122        } catch (\Exception $e) {
1123            /** @disregard P1014 */
1124            $e->exceptionCode = 'DELETE_CUSTOMER_TYPES_EXCEPTION';
1125            report($e);
1126
1127            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1128        }
1129
1130    }
1131
1132    public function delete_segments($segmentId)
1133    {
1134
1135        try {
1136
1137            $segmentId = intval($segmentId);
1138
1139            $budgets = TblQuotations::where('segment_id', $segmentId)->count();
1140
1141            if ($budgets > 0) {
1142                return response([
1143                    'message' => 'KO',
1144                    'error' => __('language.segments.delete_message.message1').' '.$budgets.' '.__('language.segments.delete_message.message2'),
1145                ]);
1146            }
1147
1148            $segment = TblSegments::where('segment_id', $segmentId)->first();
1149            TblSegments::where('segment_id', $segmentId)->delete();
1150
1151            $this->segments();
1152
1153            return response([
1154                'message' => 'OK',
1155                'data' => $this->segments,
1156            ]);
1157
1158        } catch (\Exception $e) {
1159            /** @disregard P1014 */
1160            $e->exceptionCode = 'DELETE_SEGMENTS_EXCEPTION';
1161            report($e);
1162
1163            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1164        }
1165
1166    }
1167
1168    public function delete_reasons($reasonId)
1169    {
1170
1171        try {
1172
1173            $reasonId = intval($reasonId);
1174
1175            $budgets = TblQuotations::where('reason_id', $reasonId)->count();
1176
1177            if ($budgets > 0) {
1178                return response([
1179                    'message' => 'KO',
1180                    'error' => __('language.reasons.delete_message.message1').' '.$budgets.' '.__('language.reasons.delete_message.message2'),
1181                ]);
1182            }
1183
1184            $reasons = TblReasons::where('reason_id', $reasonId)->first();
1185            TblReasons::where('reason_id', $reasonId)->delete();
1186
1187            $this->reasons();
1188
1189            return response([
1190                'message' => 'OK',
1191                'data' => $this->reasons,
1192            ]);
1193
1194        } catch (\Exception $e) {
1195            /** @disregard P1014 */
1196            $e->exceptionCode = 'DELETE_REASONS_EXCEPTION';
1197            report($e);
1198
1199            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1200        }
1201
1202    }
1203
1204    public function delete_budget_types($budgetTypeId)
1205    {
1206
1207        try {
1208
1209            $budgetTypeId = intval($budgetTypeId);
1210
1211            $budgets = TblQuotations::where('budget_type_id', $budgetTypeId)->count();
1212
1213            if ($budgets > 0) {
1214                return response([
1215                    'message' => 'KO',
1216                    'error' => __('language.budget_types.delete_message.message1').' '.$budgets.' '.__('language.budget_types.delete_message.message2'),
1217                ]);
1218            }
1219
1220            $budgetType = TblBudgetTypes::where('budget_type_id', $budgetTypeId)->first();
1221            TblBudgetTypes::where('budget_type_id', $budgetTypeId)->delete();
1222
1223            $this->budget_types();
1224
1225            return response([
1226                'message' => 'OK',
1227                'data' => $this->budget_types,
1228            ]);
1229
1230        } catch (\Exception $e) {
1231            /** @disregard P1014 */
1232            $e->exceptionCode = 'DELETE_BUDGET_TYPES_EXCEPTION';
1233            report($e);
1234
1235            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1236        }
1237
1238    }
1239
1240    public function delete_budget_type_groups($budgetTypeGroupId)
1241    {
1242
1243        try {
1244
1245            $budgetTypeGroupId = intval($budgetTypeGroupId);
1246
1247            $budgets = TblBudgetTypes::where('budget_type_group_id', $budgetTypeGroupId)->count();
1248
1249            if ($budgets > 0) {
1250                return response([
1251                    'message' => 'KO',
1252                    'error' => __('language.budget_type_groups.delete_message.message1').' '.$budgets.' '.__('language.budget_type_groups.delete_message.message2'),
1253                ]);
1254            }
1255
1256            $budgetTypeGroups = TblBudgetTypeGroups::where('budget_type_group_id', $budgetTypeGroupId)->first();
1257            TblBudgetTypeGroups::where('budget_type_group_id', $budgetTypeGroupId)->delete();
1258
1259            $this->budget_type_groups();
1260
1261            return response([
1262                'message' => 'OK',
1263                'data' => $this->budget_type_groups,
1264            ]);
1265
1266        } catch (\Exception $e) {
1267            /** @disregard P1014 */
1268            $e->exceptionCode = 'DELETE_BUDGET_TYPE_GROUPS_EXCEPTION';
1269            report($e);
1270
1271            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1272        }
1273
1274    }
1275
1276    public function delete_visit_types($visitTypeId)
1277    {
1278
1279        try {
1280
1281            $visitTypeId = intval($visitTypeId);
1282
1283            $pipeline = TblPipelines::where('visit_type_id', $visitTypeId)->count();
1284
1285            if ($pipeline > 0) {
1286                return response([
1287                    'message' => 'KO',
1288                    'error' => __('language.visit_types.delete_message.message1').' '.$pipeline.' '.__('language.visit_types.delete_message.message2'),
1289                ]);
1290            }
1291
1292            $visitType = TblVisitTypes::where('visit_type_id', $visitTypeId)->first();
1293            TblVisitTypes::where('visit_type_id', $visitTypeId)->delete();
1294
1295            $this->visit_types();
1296
1297            return response([
1298                'message' => 'OK',
1299                'data' => $this->visit_types,
1300            ]);
1301
1302        } catch (\Exception $e) {
1303            /** @disregard P1014 */
1304            $e->exceptionCode = 'DELETE_VISIT_TYPES_EXCEPTION';
1305            report($e);
1306
1307            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1308        }
1309
1310    }
1311
1312    public function delete_visit_type_groups($visitTypeGroupId)
1313    {
1314
1315        try {
1316
1317            $visitTypeGroupId = intval($visitTypeGroupId);
1318
1319            $visitType = TblVisitTypes::where('visit_type_group_id', $visitTypeGroupId)->count();
1320
1321            if ($visitType > 0) {
1322                return response([
1323                    'message' => 'KO',
1324                    'error' => __('language.visit_type_groups.delete_message.message1').' '.$visitType.' '.__('language.visit_type_groups.delete_message.message2'),
1325                ]);
1326            }
1327
1328            $visitTypeGroups = TblVisitTypeGroups::where('visit_type_group_id', $visitTypeGroupId)->first();
1329            TblVisitTypeGroups::where('visit_type_group_id', $visitTypeGroupId)->delete();
1330
1331            $this->visit_type_groups();
1332
1333            return response([
1334                'message' => 'OK',
1335                'data' => $this->visit_type_groups,
1336            ]);
1337
1338        } catch (\Exception $e) {
1339            /** @disregard P1014 */
1340            $e->exceptionCode = 'DELETE_VISIT_TYPE_GROUPS_EXCEPTION';
1341            report($e);
1342
1343            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1344        }
1345
1346    }
1347
1348    public function delete_budget_status($budgetStatusId)
1349    {
1350
1351        try {
1352
1353            $budgetStatusId = intval($budgetStatusId);
1354
1355            $budgets = TblQuotations::where('budget_status_id', $budgetStatusId)->count();
1356
1357            if ($budgets > 0) {
1358                return response([
1359                    'message' => 'KO',
1360                    'error' => __('language.budget_status.delete_message.message1').' '.$budgets.' '.__('language.budget_status.delete_message.message2'),
1361                ]);
1362            }
1363
1364            $budgetStatus = TblBudgetStatus::where('budget_status_id', $budgetStatusId)->first();
1365            TblBudgetStatus::where('budget_status_id', $budgetStatusId)->delete();
1366
1367            $this->budget_status();
1368
1369            return response([
1370                'message' => 'OK',
1371                'data' => $this->budget_status,
1372            ]);
1373
1374        } catch (\Exception $e) {
1375            /** @disregard P1014 */
1376            $e->exceptionCode = 'DELETE_BUDGET_STATUS_EXCEPTION';
1377            report($e);
1378
1379            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1380        }
1381
1382    }
1383
1384    public function delete_source($sourceId)
1385    {
1386
1387        try {
1388
1389            $sourceId = intval($sourceId);
1390
1391            $budgets = TblQuotations::where('source_id', $sourceId)->count();
1392
1393            if ($budgets > 0) {
1394                return response([
1395                    'message' => 'KO',
1396                    'error' => __('language.source.delete_message.message1').' '.$budgets.' '.__('language.source.delete_message.message2'),
1397                ]);
1398            }
1399
1400            $source = TblSources::where('source_id', $sourceId)->first();
1401            TblSources::where('source_id', $sourceId)->delete();
1402
1403            $this->source();
1404
1405            return response([
1406                'message' => 'OK',
1407                'data' => $this->source,
1408            ]);
1409
1410        } catch (\Exception $e) {
1411            /** @disregard P1014 */
1412            $e->exceptionCode = 'DELETE_SOURCE_EXCEPTION';
1413            report($e);
1414
1415            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1416        }
1417
1418    }
1419
1420    public function delete_reason_for_not_following_up($reasonForNotFollowingUpId)
1421    {
1422
1423        try {
1424
1425            $reasonForNotFollowingUpId = intval($reasonForNotFollowingUpId);
1426
1427            $budgets = TblQuotations::where('reason_for_not_following_up_id', $reasonForNotFollowingUpId)->count();
1428
1429            if ($budgets > 0) {
1430                return response([
1431                    'message' => 'KO',
1432                    'error' => __('language.source.delete_message.message1').' '.$budgets.' '.__('language.source.delete_message.message2'),
1433                ]);
1434            }
1435
1436            $reasonForNotFollowingUp = TblReasonForNotFollowingUp::where('reason_for_not_following_up_id', $reasonForNotFollowingUpId)->first();
1437            TblReasonForNotFollowingUp::where('reason_for_not_following_up_id', $reasonForNotFollowingUpId)->delete();
1438
1439            $this->reason_for_not_following_up();
1440
1441            return response([
1442                'message' => 'OK',
1443                'data' => $this->reason_for_not_following_up,
1444            ]);
1445
1446        } catch (\Exception $e) {
1447            /** @disregard P1014 */
1448            $e->exceptionCode = 'DELETE_REASON_FOR_NOT_FOLLOWING_UP_EXCEPTION';
1449            report($e);
1450
1451            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1452        }
1453
1454    }
1455
1456    public function delete_reason_for_rejection($reasonForRejectionId)
1457    {
1458
1459        try {
1460
1461            $reasonForRejectionId = intval($reasonForRejectionId);
1462
1463            $budgets = TblQuotations::where('reason_for_rejection_id', $reasonForRejectionId)->count();
1464
1465            if ($budgets > 0) {
1466                return response([
1467                    'message' => 'KO',
1468                    'error' => __('language.source.delete_message.message1').' '.$budgets.' '.__('language.source.delete_message.message2'),
1469                ]);
1470            }
1471
1472            $reasonForRejection = TblReasonForRejection::where('reason_for_rejection_id', $reasonForRejectionId)->first();
1473            TblReasonForRejection::where('reason_for_rejection_id', $reasonForRejectionId)->delete();
1474
1475            $this->reason_for_rejection();
1476
1477            return response([
1478                'message' => 'OK',
1479                'data' => $this->reason_for_rejection,
1480            ]);
1481
1482        } catch (\Exception $e) {
1483            /** @disregard P1014 */
1484            $e->exceptionCode = 'DELETE_REASON_FOR_REJECTION_EXCEPTION';
1485            report($e);
1486
1487            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1488        }
1489
1490    }
1491
1492    public function list_work_status()
1493    {
1494
1495        try {
1496
1497            $this->work_status();
1498
1499            return response([
1500                'message' => 'OK',
1501                'data' => $this->work_status,
1502            ]);
1503
1504        } catch (\Exception $e) {
1505            /** @disregard P1014 */
1506            $e->exceptionCode = 'LIST_WORK_STATUS_EXCEPTION';
1507            report($e);
1508
1509            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1510        }
1511
1512    }
1513
1514    public function work_status()
1515    {
1516
1517        $this->work_status = TblWorkStatus::orderByRaw('ISNULL(priority), priority ASC')->get();
1518
1519    }
1520
1521    public function update_work_status(Request $request, $workStatusId)
1522    {
1523
1524        try {
1525
1526            $data = $request->all();
1527            $workStatusId = intval($workStatusId);
1528
1529            if (isset($data['data'])) {
1530                $priority = $data['data'];
1531                if (count($priority) > 0) {
1532                    foreach ($priority as $item) {
1533                        TblWorkStatus::where('work_status_id', $item['work_status_id'])->update(['priority' => $item['priority']]);
1534                    }
1535                }
1536            } else {
1537                TblWorkStatus::where('work_status_id', $workStatusId)->update($data);
1538            }
1539
1540            $this->work_status();
1541
1542            return response([
1543                'message' => 'OK',
1544                'data' => $this->work_status,
1545            ]);
1546
1547        } catch (\Exception $e) {
1548            /** @disregard P1014 */
1549            $e->exceptionCode = 'UPDATE_WORK_STATUS_EXCEPTION';
1550            report($e);
1551
1552            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1553        }
1554
1555    }
1556
1557    public function delete_work_status($workStatusId)
1558    {
1559
1560        try {
1561
1562            $workStatusId = intval($workStatusId);
1563
1564            $job = TblOngoingJobs::where('work_status_id', $workStatusId)->count();
1565
1566            if ($job > 0) {
1567                return response([
1568                    'message' => 'KO',
1569                    'error' => __('language.work_status.delete_message.message1').' '.$job.' '.__('language.work_status.delete_message.message2'),
1570                ]);
1571            }
1572
1573            $workStatus = TblWorkStatus::where('work_status_id', $workStatusId)->first();
1574            TblWorkStatus::where('work_status_id', $workStatusId)->delete();
1575
1576            $this->work_status();
1577
1578            return response([
1579                'message' => 'OK',
1580                'data' => $this->work_status,
1581            ]);
1582
1583        } catch (\Exception $e) {
1584            /** @disregard P1014 */
1585            $e->exceptionCode = 'DELETE_WORK_STATUS_EXCEPTION';
1586            report($e);
1587
1588            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1589        }
1590
1591    }
1592
1593    public function add_work_status(Request $request)
1594    {
1595
1596        try {
1597
1598            $data = $request->all();
1599
1600            TblWorkStatus::create($data);
1601
1602            $this->work_status();
1603
1604            return response([
1605                'message' => 'OK',
1606                'data' => $this->work_status,
1607            ]);
1608
1609        } catch (\Exception $e) {
1610            /** @disregard P1014 */
1611            $e->exceptionCode = 'ADD_WORK_STATUS_EXCEPTION';
1612            report($e);
1613
1614            return response(['message' => 'KO', 'error' => $e->getMessage()]);
1615        }
1616
1617    }
1618}