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