Passed
Push — dev5 ( 8481ee...a622eb )
by Ron
03:52 queued 01:34
created

SetCustomerNotes::deleteNote()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Domains\Customers;
4
5
use Illuminate\Support\Facades\Log;
6
use Illuminate\Support\Facades\Auth;
7
8
use App\Customers;
9
use App\CustomerNotes;
10
11
use App\Http\Requests\CustomerEditNoteRequest;
12
use App\Http\Requests\CustomerNewNoteRequest;
13
14
class SetCustomerNotes
15
{
16
    protected $custID;
17
18 10
    public function __construct($custID)
19
    {
20 10
        $this->custID = $custID;
21 10
    }
22
23
    //  Create a new note for the customer
24 4
    public function createNote(CustomerNewNoteRequest $request)
25
    {
26 4
        CustomerNotes::create([
27 4
            'cust_id'     => $request->cust_id,
28 4
            'user_id'     => Auth::user()->user_id,
29 4
            'shared'      => $request->shared,
30 4
            'urgent'      => $request->urgent,
31 4
            'subject'     => $request->subject,
32 4
            'description' => $request->description,
33
        ]);
34
35 4
        Log::info('New Customer Note Created for Customer ID - '.$this->custID.' by '.Auth::user()->full_name.'.  Note details - ', array($request));
36 4
        return true;
37
    }
38
39
    //  Update an existing note for the customer
40 4
    public function updateNote(CustomerEditNoteRequest $request, $noteID)
41
    {
42 4
        if($request->shared)
43
        {
44 2
            $this->checkParent();
45
        }
46
47 4
        CustomerNotes::find($noteID)->update([
48 4
            'cust_id'     => $request->cust_id,
49 4
            'shared'      => $request->shared,
50 4
            'urgent'      => $request->urgent,
51 4
            'subject'     => $request->subject,
52 4
            'description' => $request->description,
53
        ]);
54
55 4
        Log::info('Customer Note updated for Customer ID '.$this->custID.' updated by '.Auth::user()->full_name.'. Note Details - ', array($request));
56 4
        return true;
57
    }
58
59
    //  Delete an existing note for the customer
60 2
    public function deleteNote($noteID)
61
    {
62 2
        CustomerNotes::find($noteID)->delete();
63 2
        Log::notice('Customer Note ID - '.$noteID.' deleted by '.Auth::user()->full_name);
64 2
        return true;
65
    }
66
67
    //  Verify if the parent should get the note
68 2
    protected function checkParent()
69
    {
70 2
        $parent = Customers::find($this->custID)->parent_id;
71 2
        if($parent)
72
        {
73 2
            $this->custID = $parent;
74
        }
75 2
    }
76
}
77