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