Total Complexity | 10 |
Total Lines | 111 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class CustomerNoteController extends Controller |
||
13 | { |
||
14 | /** |
||
15 | * Store a new customer note |
||
16 | */ |
||
17 | public function store(CustomerNoteRequest $request) |
||
18 | { |
||
19 | $cust = Customer::findOrFail($request->cust_id); |
||
20 | $cust_id = $cust->cust_id; |
||
21 | |||
22 | // If the equipment is shared, it must be assigned to the parent site |
||
23 | if($request->shared && $cust->parent_id > 0) |
||
24 | { |
||
25 | $cust_id = $cust->parent_id; |
||
26 | } |
||
27 | |||
28 | CustomerNote::create([ |
||
29 | 'cust_id' => $cust_id, |
||
30 | 'created_by' => $request->user()->user_id, |
||
31 | 'urgent' => $request->urgent, |
||
32 | 'shared' => $request->shared, |
||
33 | 'subject' => $request->subject, |
||
34 | 'details' => $request->details, |
||
35 | ]); |
||
36 | |||
37 | Log::channel('cust')->info('New Customer Note created for Customer '.$cust->name.' by '.Auth::user()->username); |
||
1 ignored issue
–
show
|
|||
38 | return response()->noContent(); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Get all of the notes for a customer |
||
43 | */ |
||
44 | public function show($id) |
||
45 | { |
||
46 | $cust = Customer::findOrFail($id); |
||
47 | |||
48 | return CustomerNote::where('cust_id', $id) |
||
49 | ->when($cust->parent_id, function($q) use ($cust) |
||
50 | { |
||
51 | $q->orWhere('cust_id', $cust->parent_id)->where('shared', true); |
||
52 | }) |
||
53 | ->orderBy('urgent', 'DESC') |
||
54 | ->get(); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Modify an existing note |
||
59 | */ |
||
60 | public function update(CustomerNoteRequest $request, $id) |
||
61 | { |
||
62 | $cust = Customer::findOrFail($request->cust_id); |
||
63 | $cust_id = $cust->cust_id; |
||
64 | |||
65 | // If the equipment is shared, it must be assigned to the parent site |
||
66 | if($request->shared && $cust->parent_id > 0) |
||
67 | { |
||
68 | $cust_id = $cust->parent_id; |
||
69 | } |
||
70 | |||
71 | CustomerNote::find($id)->update([ |
||
72 | 'cust_id' => $cust_id, |
||
73 | 'updated_by' => $request->user()->user_id, |
||
74 | 'urgent' => $request->urgent, |
||
75 | 'shared' => $request->shared, |
||
76 | 'subject' => $request->subject, |
||
77 | 'details' => $request->details, |
||
78 | ]); |
||
79 | |||
80 | Log::channel('cust')->info('Customer Note ID '.$id.' updated for Customer '.$cust->name.' by '.Auth::user()->username); |
||
1 ignored issue
–
show
|
|||
81 | return response()->noContent(); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Delete a customer Note |
||
86 | */ |
||
87 | public function destroy($id) |
||
88 | { |
||
89 | $this->authorize('delete', CustomerNote::class); |
||
90 | |||
91 | CustomerNote::find($id)->delete(); |
||
92 | |||
93 | Log::channel('cust')->notice('Customer Note ID '.$id.' deleted by '.Auth::user()->username); |
||
1 ignored issue
–
show
|
|||
94 | return response()->noContent(); |
||
95 | } |
||
96 | |||
97 | /* |
||
98 | * Restore a deleted note |
||
99 | */ |
||
100 | public function restore($id) |
||
108 | } |
||
109 | |||
110 | /* |
||
111 | * Permanently delete a note |
||
112 | */ |
||
113 | public function forceDelete($id) |
||
123 | } |
||
124 | } |
||
125 |