1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Customers; |
4
|
|
|
|
5
|
|
|
use App\CustomerNotes; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Illuminate\Support\Facades\Log; |
8
|
|
|
use Illuminate\Support\Facades\Auth; |
9
|
|
|
use App\Http\Controllers\Controller; |
10
|
|
|
use Illuminate\Support\Facades\Route; |
11
|
|
|
|
12
|
|
|
class CustomerNotesController extends Controller |
13
|
|
|
{ |
14
|
|
|
|
15
|
20 |
|
public function __construct() |
16
|
|
|
{ |
17
|
20 |
|
$this->middleware('auth'); |
18
|
20 |
|
} |
19
|
|
|
|
20
|
|
|
// Store a new customer note |
21
|
4 |
|
public function store(Request $request) |
22
|
|
|
{ |
23
|
4 |
|
$request->validate([ |
24
|
4 |
|
'cust_id' => 'required|numeric', |
25
|
|
|
'title' => 'required', |
26
|
|
|
'note' => 'required' |
27
|
|
|
]); |
28
|
|
|
|
29
|
2 |
|
$noteID = CustomerNotes::create([ |
30
|
2 |
|
'cust_id' => $request->cust_id, |
31
|
2 |
|
'user_id' => Auth::user()->user_id, |
32
|
2 |
|
'urgent' => $request->urgent, |
33
|
2 |
|
'subject' => $request->title, |
34
|
2 |
|
'description' => $request->note |
35
|
|
|
]); |
36
|
|
|
|
37
|
2 |
|
Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
38
|
2 |
|
Log::debug('Submitted Data - ', $request->toArray()); |
39
|
2 |
|
Log::info('New Customer Note Created for Customer ID-'.$request->custID.' by User ID-'.Auth::user()->user_id.'. New Note ID-'.$noteID->note_id); |
40
|
|
|
|
41
|
2 |
|
return response()->json(['success' => true]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// Get the customer notes |
45
|
2 |
|
public function show($id) |
46
|
|
|
{ |
47
|
2 |
|
$notes = CustomerNotes::where('cust_id', $id)->orderBy('urgent', 'desc')->get(); |
48
|
|
|
|
49
|
2 |
|
Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
50
|
2 |
|
Log::debug('Fetched Data - ', $notes->toArray()); |
51
|
2 |
|
return $notes; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// Update a customer note |
55
|
4 |
|
public function update(Request $request, $id) |
56
|
|
|
{ |
57
|
4 |
|
$request->validate([ |
58
|
4 |
|
'cust_id' => 'required', |
59
|
|
|
'title' => 'required', |
60
|
|
|
'note' => 'required' |
61
|
|
|
]); |
62
|
|
|
|
63
|
2 |
|
CustomerNotes::find($id)->update( |
64
|
|
|
[ |
65
|
2 |
|
'urgent' => $request->urgent, |
66
|
2 |
|
'subject' => $request->title, |
67
|
2 |
|
'description' => $request->note |
68
|
|
|
]); |
69
|
|
|
|
70
|
2 |
|
Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
71
|
2 |
|
Log::debug('Submitted Data - ', $request->toArray()); |
72
|
2 |
|
Log::info('Customer Note ID-'.$id.' updated by User ID-'.Auth::user()->user_id); |
73
|
2 |
|
return response()->json(['success' => true]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// Delete a customer note |
77
|
2 |
|
public function destroy($id) |
78
|
|
|
{ |
79
|
2 |
|
CustomerNotes::find($id)->delete(); |
80
|
|
|
|
81
|
2 |
|
Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
82
|
2 |
|
Log::notice('Customer Note ID-'.$id.' deleted by User ID-'.Auth::user()->user_id); |
83
|
|
|
|
84
|
2 |
|
return response()->json(['success' => true]); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|