Completed
Push — master ( 72282c...462347 )
by
unknown
9s
created

TransaksiController::store()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 27
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 38
rs 8.8571
1
<?php
2
3
namespace Bantenprov\PelayananKesehatan\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Http\Request;
7
8
/* Model */
9
use Bantenprov\PelayananKesehatan\Facades\PelayananKesehatan;
10
use Bantenprov\PelayananKesehatan\Models\TarifModel;
11
use Bantenprov\PelayananKesehatan\Models\TransaksiModel;
12
use Bantenprov\MasterTarif\Models\MasterTarifModel;
13
use Bantenprov\DaftarRetribusi\Models\DaftarRetribusiModel;
14
15
/* ETC */
16
use Ramsey\Uuid\Uuid;
17
18
/**
19
 * The TransaksiController class.
20
 *
21
 * @package Bantenprov\PelayananKesehatan
22
 * @author  bantenprov <[email protected]>
23
 */
24
25
class TransaksiController extends Controller
26
{
27
    public function index()
28
    {
29
        $transaksis = TransaksiModel::all();
30
31
        return view('pelayanan-kesehatan::transaksi.index', compact('transaksis'));
32
    }
33
34
    public function create()
35
    {
36
        $random_number = rand(1000000, 9999999). rand(1000000, 9999999);
37
        $nomor = str_shuffle($random_number);
38
39
        session(['nomor' => $nomor]);
40
41
        $daftar_retribusis = DaftarRetribusiModel::all();
42
43
44
        return view('pelayanan-kesehatan::transaksi.create', compact('nomor','daftar_retribusis'));
45
    }
46
47
    public function store(Request $request)
48
    {
49
        $request->validate([
50
            'nomor'                     => 'unique:transaksies,nomor',
51
            'total'                     => 'required',
52
            'grandtotal'                => 'required',
53
            'denda'                     => 'required',
54
            'potongan'                  => 'required',
55
            'daftar_retribusi_id'       => 'required',
56
        ]);
57
58
        $daftar_retribusi = DaftarRetribusiModel::find($request->daftar_retribusi_id);
59
60
        $master_tarif = MasterTarifModel::where('daftar_retribusi_id', '=', $daftar_retribusi->id)->where('status', '=', '1');
61
62
        if($master_tarif->count() == 0){
63
            return redirect()->back()->withErrors('Master retribusi not found.');
64
        }
65
66
        TransaksiModel::create([
67
            'uuid'                      => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bantenprov.go.id'.date('YmdHis')),
68
            'nomor'                     => session('nomor'),
69
            'total'                     => $request->total,
70
            'grandtotal'                => $request->grandtotal,
71
            'denda'                     => $request->denda,
72
            'potongan'                  => $request->potongan,
73
            'admin_id'                  => \Auth::user()->id,
74
            'customer_transaksi_id'     => 1,
75
            'tarif_id'                  => $master_tarif->first()->id,
76
            'admin_uuid'                => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bantenprov.go.id'.date('YmdHis')),
77
            'customer_transaksi_uuid'   => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bantenprov.go.id'.date('YmdHis')),
78
            'tarif_uuid'                => $master_tarif->first()->uuid,
79
        ]);
80
81
        $request->session()->flash('message', 'Success add new transaksi');
82
83
        return redirect()->route('transaksi.index');
84
    }
85
86
    public function show($id)
87
    {
88
        $transaksi = TransaksiModel::find($id);
89
90
        return view('pelayanan-kesehatan::transaksi.show', compact('transaksi'));
91
    }
92
93
    public function edit()
94
    {
95
96
        return view('pelayanan-kesehatan::transaksi.edit');
97
    }
98
99
    public function update()
100
    {
101
102
        return view('pelayanan-kesehatan::transaksi.index');
103
    }
104
105
    public function destroy($id)
106
    {
107
        $transaksi = TransaksiModel::find($id)->delete();
0 ignored issues
show
Unused Code introduced by
$transaksi is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
108
109
        return redirect()->route('transaksi.index')->with('message', 'Success delete transaksi.');
110
    }
111
}
112