Skip to content

Commit 09fff45

Browse files
committed
Merge branch 'Discount'
2 parents 4ed706d + 7706e3f commit 09fff45

File tree

13 files changed

+551
-11
lines changed

13 files changed

+551
-11
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Discount;
7+
use Illuminate\Http\Request;
8+
use App\Http\Requests\Admin\Discount\Store;
9+
use App\Http\Requests\Admin\Discount\Update;
10+
11+
class DiscountController extends Controller
12+
{
13+
/**
14+
* Display a listing of the resource.
15+
*
16+
* @return \Illuminate\Http\Response
17+
*/
18+
public function index()
19+
{
20+
$discounts = Discount::all();
21+
return view('admin.discount.index',
22+
[
23+
'discounts' => $discounts
24+
]);
25+
}
26+
27+
/**
28+
* Show the form for creating a new resource.
29+
*
30+
* @return \Illuminate\Http\Response
31+
*/
32+
public function create()
33+
{
34+
return view('admin.discount.create');
35+
}
36+
37+
/**
38+
* Store a newly created resource in storage.
39+
*
40+
* @param \Illuminate\Http\Request $request
41+
* @return \Illuminate\Http\Response
42+
*/
43+
public function store(Store $request)
44+
{
45+
$discount = Discount::create($request->all());
46+
$request->session()->flash('success', 'A new discount has been created');
47+
return redirect(route('admin.discount.index'));
48+
}
49+
50+
/**
51+
* Display the specified resource.
52+
*
53+
* @param \App\Models\Discount $discount
54+
* @return \Illuminate\Http\Response
55+
*/
56+
public function show(Discount $discount)
57+
{
58+
//
59+
}
60+
61+
/**
62+
* Show the form for editing the specified resource.
63+
*
64+
* @param \App\Models\Discount $discount
65+
* @return \Illuminate\Http\Response
66+
*/
67+
public function edit(Discount $discount)
68+
{
69+
return view('admin.discount.edit',
70+
[
71+
'discount' => $discount
72+
]);
73+
}
74+
75+
/**
76+
* Update the specified resource in storage.
77+
*
78+
* @param \Illuminate\Http\Request $request
79+
* @param \App\Models\Discount $discount
80+
* @return \Illuminate\Http\Response
81+
*/
82+
public function update(Update $request, Discount $discount)
83+
{
84+
$discount->update($request->all());
85+
$request->session()->flash('success', "Discount {$discount->name} has been updated!");
86+
return redirect(route('admin.discount.index'));
87+
}
88+
89+
/**
90+
* Remove the specified resource from storage.
91+
*
92+
* @param \App\Models\Discount $discount
93+
* @return \Illuminate\Http\Response
94+
*/
95+
public function destroy(Request $request, Discount $discount)
96+
{
97+
$discount->delete();
98+
$request->session()->flash('error', "Discount {$discount->name} has been deleted!");
99+
return redirect(route('admin.discount.index'));
100+
}
101+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Http\Requests\Admin\Discount;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
use Auth;
7+
8+
class Store extends FormRequest
9+
{
10+
/**
11+
* Determine if the user is authorized to make this request.
12+
*
13+
* @return bool
14+
*/
15+
public function authorize()
16+
{
17+
return Auth::check() && Auth::user()->is_admin;
18+
}
19+
20+
/**
21+
* Get the validation rules that apply to the request.
22+
*
23+
* @return array
24+
*/
25+
public function rules()
26+
{
27+
return [
28+
'name' => 'required|string',
29+
'code' => 'required|string|max:5|unique:discounts',
30+
'description' => 'nullable|string',
31+
'percentage' => 'required|min:1|max:100|numeric',
32+
];
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Http\Requests\Admin\Discount;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
use Auth;
7+
8+
class Update extends FormRequest
9+
{
10+
/**
11+
* Determine if the user is authorized to make this request.
12+
*
13+
* @return bool
14+
*/
15+
public function authorize()
16+
{
17+
return Auth::check() && Auth::user()->is_admin;
18+
}
19+
20+
/**
21+
* Get the validation rules that apply to the request.
22+
*
23+
* @return array
24+
*/
25+
public function rules()
26+
{
27+
return [
28+
'name' => 'required|string',
29+
'code' => 'required|string|max:5|unique:discounts,code,'.$this->id.',id',
30+
'description' => 'nullable|string',
31+
'percentage' => 'required|min:1|max:100|numeric',
32+
];
33+
}
34+
}

app/Models/Checkout.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ class Checkout extends Model
1616
'camp_id',
1717
'payment_status',
1818
'midtrans_url',
19-
'midtrans_booking_code'
19+
'midtrans_booking_code',
20+
'discount_id',
21+
'discount_percentage',
22+
'total'
2023
];
2124

2225
// Dah Kaga dipake

app/Models/Discount.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\SoftDeletes;
8+
9+
class Discount extends Model
10+
{
11+
use HasFactory;
12+
13+
protected $fillable = [
14+
'name',
15+
'code',
16+
'description',
17+
'percentage'
18+
];
19+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateDiscountsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('discounts', function (Blueprint $table) {
17+
$table->id();
18+
$table->string('name', 100);
19+
$table->string('code', 5)->unique();
20+
$table->text('description')->nullable();
21+
$table->unsignedInteger('percentage');
22+
$table->timestamps();
23+
$table->softDeletes();
24+
});
25+
}
26+
27+
/**
28+
* Reverse the migrations.
29+
*
30+
* @return void
31+
*/
32+
public function down()
33+
{
34+
Schema::dropIfExists('discounts');
35+
}
36+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddDiscountIdAndDiscountPercentageAndTotalOnCheckoutsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('checkouts', function (Blueprint $table) {
17+
$table->foreignId('discount_id')->nullable()->after('camp_id');
18+
$table->unsignedInteger('discount_percentage')->nullable()->after('midtrans_booking_code');
19+
$table->unsignedInteger('total')->default(0)->after('discount_percentage');
20+
$table->foreign('discount_id')->references('id')->on('discounts');
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*
27+
* @return void
28+
*/
29+
public function down()
30+
{
31+
Schema::table('checkouts', function (Blueprint $table) {
32+
33+
$table->dropForeign('checkouts_discount_id_foreign');
34+
35+
$table->dropColumn(
36+
[
37+
'discount_id',
38+
'discount_percentage',
39+
'total'
40+
]);
41+
42+
});
43+
}
44+
}

resources/views/admin/dashboard.blade.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</div>
2020
<div class="row my-5">
2121
@include('components.alert')
22-
<table class="table table-bordered">
22+
<table class="table">
2323
<thead class="bg-dark text-white">
2424
<tr class="align-middle">
2525
<th>Camp</th>
@@ -57,10 +57,12 @@
5757
</td>
5858
</tr>
5959
@empty
60-
<tr class="align-middle">
61-
<div class="alert alert-info" role="alert">
62-
No Data!
63-
</div>
60+
<tr class="bg-light">
61+
<td colspan="7" class="text-center">
62+
<h6 class="text-secondary">
63+
No Data!
64+
</h5>
65+
</td>
6466
</tr>
6567
@endforelse
6668
</tbody>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@extends('layouts.app')
2+
3+
@section('title')
4+
Create Discount
5+
@endsection
6+
7+
@section('content')
8+
<section class="dashboard my-5">
9+
<div class="container">
10+
<div class="row text-left">
11+
<div class=" col-lg-12 col-12 header-wrap mt-4">
12+
<p class="story">
13+
Discount
14+
</p>
15+
<h2 class="primary-header ">
16+
Create Discount
17+
</h2>
18+
</div>
19+
</div>
20+
<div class="my-4">
21+
@include('components.alert')
22+
<div class="card border-primary">
23+
<div class="card-header p-4 fw-bold">
24+
Details
25+
</div>
26+
<div class="card-body p-4">
27+
<form action="{{route('admin.discount.store')}}" method="POST">
28+
@csrf
29+
<div class="mb-3">
30+
<label class="form-label fw-semibold">Name</label>
31+
<input type="text" name="name" class="form-control {{$errors->has('name') ? 'is-invalid' : '' }}" id="name" value="{{old('name') ?: ''}}" required>
32+
@if ($errors->has('name'))
33+
<p class="text-danger">{{$errors->first('name')}}</p>
34+
@endif
35+
</div>
36+
<div class="mb-3">
37+
<label class="form-label fw-semibold">Code</label>
38+
<input type="text" name="code" class="form-control {{$errors->has('code') ? 'is-invalid' : '' }}" id="code" value="{{old('code') ?: ''}}" required>
39+
@if ($errors->has('code'))
40+
<p class="text-danger">{{$errors->first('code')}}</p>
41+
@endif
42+
</div>
43+
<div class="mb-3">
44+
<label class="form-label fw-semibold">Description</label>
45+
<textarea class="form-control" name="description" id="description" rows="3">{{old('code')}}</textarea>
46+
</div>
47+
<div class="mb-3 col-md-3">
48+
<label class="form-label fw-semibold">Percentage</label>
49+
<div class="input-group {{$errors->has('percentage') ? 'is-invalid' : '' }}">
50+
<input type="number" name="percentage" class="form-control" id="percentage" min="1" max="200" value="{{old('percentage') ?: ''}}" required>
51+
<span class="input-group-text">%</span>
52+
</div>
53+
@if ($errors->has('percentage'))
54+
<p class="text-danger">{{$errors->first('percentage')}}</p>
55+
@endif
56+
</div>
57+
<div class="d-grid">
58+
<button type="submit" class="btn btn-primary">Submit</button>
59+
</div>
60+
</form>
61+
</div>
62+
</div>
63+
</div>
64+
</div>
65+
</section>
66+
@endsection

0 commit comments

Comments
 (0)