diff --git a/TODO.md b/TODO.md
index 42a22d4..c4ba83b 100644
--- a/TODO.md
+++ b/TODO.md
@@ -4,8 +4,8 @@
- [x] CRUD Info
- [x] CRUD Banner
-- [ ] CRUD Rekening / Account
-- [ ] CRUD Customer
+- [x] CRUD Rekening / Account
+- [x] CRUD Customer
- [ ] CRUD Voucher
- [ ] Import Voucher
- [ ] Deposit Menu (view daftar histori deposit)
diff --git a/app/Http/Controllers/Customer/AuthController.php b/app/Http/Controllers/Customer/AuthController.php
index 507e671..88ea783 100644
--- a/app/Http/Controllers/Customer/AuthController.php
+++ b/app/Http/Controllers/Customer/AuthController.php
@@ -62,13 +62,12 @@ class AuthController extends Controller
->user();
} catch (\Exception $e) {
return redirect()->route('customer.login')
- ->with('message', ['type' => 'error', 'message' => 'something went wrong']);
+ ->with('message', ['type' => 'error', 'message' => 'Google authentication fail, please try again']);
}
$customer = Customer::where('google_id', $user->id)->first();
if ($customer == null) {
DB::beginTransaction();
- $basic = CustomerLevel::where('key', CustomerLevel::BASIC)->first();
$customer = Customer::create([
'fullname' => $user->name,
'name' => $user->nickname,
@@ -76,13 +75,6 @@ class AuthController extends Controller
'username' => Str::slug($user->name . '_' . Str::random(5), '_'),
'google_id' => $user->id,
'google_oauth_response' => json_encode($user),
- 'customer_level_id' => $basic->id,
- ]);
-
- CustomerLevelHistory::create([
- 'customer_id' => $customer->id,
- 'customer_level_id' => $basic->id,
- 'date_time' => now(),
]);
DB::commit();
}
@@ -103,13 +95,12 @@ class AuthController extends Controller
'fullname' => 'required|string',
'name' => 'required|string',
'address' => 'required|string',
- 'phone' => 'required|string|numeric',
+ 'phone' => 'required|numeric',
'username' => 'required|string|min:5|alpha_dash|unique:customers,username',
'password' => 'required|string|min:8|confirmed',
]);
DB::beginTransaction();
- $basic = CustomerLevel::where('key', CustomerLevel::BASIC)->first();
$customer = Customer::create([
'fullname' => $request->fullname,
'name' => $request->name,
@@ -117,12 +108,6 @@ class AuthController extends Controller
'phone' => $request->phone,
'username' => $request->username,
'password' => bcrypt($request->password),
- 'customer_level_id' => $basic->id,
- ]);
- CustomerLevelHistory::create([
- 'customer_id' => $customer->id,
- 'customer_level_id' => $basic->id,
- 'date_time' => now(),
]);
DB::commit();
diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php
new file mode 100644
index 0000000..2025941
--- /dev/null
+++ b/app/Http/Controllers/CustomerController.php
@@ -0,0 +1,107 @@
+with(['level']);
+
+ if ($request->q != '') {
+ $query->where('name', 'like', "%$request->q%")
+ ->orWhere('fullname', 'like', "%$request->q%")
+ ->orWhere('email', 'like', "%$request->q%")
+ ->orWhere('phone', 'like', "%$request->q%");
+ }
+
+ return inertia('Customer/Index', [
+ 'query' => $query->paginate(),
+ ]);
+ }
+
+ public function create()
+ {
+ return inertia('Customer/Form');
+ }
+
+ public function store(Request $request)
+ {
+ $request->validate([
+ 'username' => 'required|string|min:5|alpha_dash|unique:customers,username',
+ 'password' => 'required|string|min:8',
+ 'name' => 'required|string',
+ 'fullname' => 'required|string',
+ 'address' => 'required|string',
+ 'phone' => 'required|string',
+ 'image' => 'nullable|string',
+ ]);
+
+ Customer::create([
+ 'username' => $request->username,
+ 'password' => bcrypt($request->password),
+ 'name' => $request->name,
+ 'fullname' => $request->fullname,
+ 'address' => $request->address,
+ 'phone' => $request->phone,
+ 'image' => $request->image,
+ ]);
+
+ return redirect()->route('customer.index')
+ ->with('message', ['type' => 'success', 'message' => 'Item has beed saved']);
+ }
+
+ public function edit(Customer $customer)
+ {
+ return inertia('Customer/Form', [
+ 'customer' => $customer
+ ]);
+ }
+
+ public function update(Request $request, Customer $customer)
+ {
+ $request->validate([
+ 'username' => 'required|string|min:5|alpha_dash|unique:customers,username,' . $customer->id,
+ 'password' => 'nullable|string|min:8',
+ 'name' => 'required|string',
+ 'fullname' => 'required|string',
+ 'address' => 'required|string',
+ 'phone' => 'required|string',
+ 'image' => 'nullable|image',
+ ]);
+
+ if ($request->password != '') {
+ $customer->password = bcrypt($request->password);
+ }
+
+ if ($request->hasFile('image')) {
+ $file = $request->file('image');
+ $file->store('uploads', 'public');
+ $customer->image = $file->hashName('uploads');
+ }
+
+ $customer->update([
+ 'username' => $request->username,
+ 'password' => $customer->password,
+ 'name' => $request->name,
+ 'fullname' => $request->fullname,
+ 'address' => $request->address,
+ 'phone' => $request->phone,
+ 'image' => $customer->image,
+ ]);
+
+ return redirect()->route('customer.index')
+ ->with('message', ['type' => 'success', 'message' => 'Item has beed updated']);
+ }
+
+ public function destroy(Customer $customer)
+ {
+ $customer->delete();
+
+ return redirect()->route('customer.index')
+ ->with('message', ['type' => 'success', 'message' => 'Item has beed deleted']);
+ }
+}
diff --git a/app/Models/Customer.php b/app/Models/Customer.php
index f896616..1d7e06a 100644
--- a/app/Models/Customer.php
+++ b/app/Models/Customer.php
@@ -44,6 +44,37 @@ class Customer extends Authenticatable
'display_phone'
];
+ protected static function booted(): void
+ {
+ static::creating(function (Customer $customer) {
+ if ($customer->customer_level_id == null) {
+ $basic = CustomerLevel::where('key', CustomerLevel::BASIC)->first();
+
+ $customer->customer_level_id = $basic->id;
+
+ CustomerLevelHistory::create([
+ 'customer_id' => $customer->id,
+ 'customer_level_id' => $basic->id,
+ 'date_time' => now(),
+ ]);
+ }
+ });
+
+ static::updating(function (Customer $customer) {
+ if ($customer->isDirty('customer_level_id')) {
+ $level = CustomerLevel::find($customer->customer_level_id);
+
+ $customer->customer_level_id = $level->id;
+
+ CustomerLevelHistory::create([
+ 'customer_id' => $customer->id,
+ 'customer_level_id' => $level->id,
+ 'date_time' => now(),
+ ]);
+ }
+ });
+ }
+
public function imageUrl(): Attribute
{
return Attribute::make(
diff --git a/public/uploads/4tdHUpx78fokdCMK8uZZfBO5ARXzllmhvSUv1OqF.png b/public/uploads/4tdHUpx78fokdCMK8uZZfBO5ARXzllmhvSUv1OqF.png
deleted file mode 100644
index b36f112..0000000
Binary files a/public/uploads/4tdHUpx78fokdCMK8uZZfBO5ARXzllmhvSUv1OqF.png and /dev/null differ
diff --git a/public/uploads/5Cb26LsXe6x8o2C1NDeqPhpvK305Y05HmzWz6OlX.png b/public/uploads/5Cb26LsXe6x8o2C1NDeqPhpvK305Y05HmzWz6OlX.png
deleted file mode 100644
index b36f112..0000000
Binary files a/public/uploads/5Cb26LsXe6x8o2C1NDeqPhpvK305Y05HmzWz6OlX.png and /dev/null differ
diff --git a/public/uploads/GXhu1GNCg4KpAgAVZvS1Bu4X24GRYhU6VBkWtFe9.png b/public/uploads/GXhu1GNCg4KpAgAVZvS1Bu4X24GRYhU6VBkWtFe9.png
deleted file mode 100644
index b36f112..0000000
Binary files a/public/uploads/GXhu1GNCg4KpAgAVZvS1Bu4X24GRYhU6VBkWtFe9.png and /dev/null differ
diff --git a/public/uploads/2FlN0wGNWeaxv9kFA9SOoh9JeTwRvUEiV5a8faRx.png b/public/uploads/HJ7nplQVetjWYeMH02TeI4CqZCaRcxGueiylrRFH.png
similarity index 100%
rename from public/uploads/2FlN0wGNWeaxv9kFA9SOoh9JeTwRvUEiV5a8faRx.png
rename to public/uploads/HJ7nplQVetjWYeMH02TeI4CqZCaRcxGueiylrRFH.png
diff --git a/public/uploads/SSc8CDMHsShkIUFWol8WrYSu7coHDD2rWHPXS9z7.png b/public/uploads/SSc8CDMHsShkIUFWol8WrYSu7coHDD2rWHPXS9z7.png
deleted file mode 100644
index b36f112..0000000
Binary files a/public/uploads/SSc8CDMHsShkIUFWol8WrYSu7coHDD2rWHPXS9z7.png and /dev/null differ
diff --git a/public/uploads/XM0gJaggvM5SrW1xBLomgn0vmOkCgUbQm3DUUE1m.png b/public/uploads/XM0gJaggvM5SrW1xBLomgn0vmOkCgUbQm3DUUE1m.png
deleted file mode 100644
index ac64794..0000000
Binary files a/public/uploads/XM0gJaggvM5SrW1xBLomgn0vmOkCgUbQm3DUUE1m.png and /dev/null differ
diff --git a/public/uploads/kjFUmhXj0s0xAkhf4IRQT470njODmLgMlJyw0x37.png b/public/uploads/kjFUmhXj0s0xAkhf4IRQT470njODmLgMlJyw0x37.png
deleted file mode 100644
index 80ff33a..0000000
Binary files a/public/uploads/kjFUmhXj0s0xAkhf4IRQT470njODmLgMlJyw0x37.png and /dev/null differ
diff --git a/resources/js/Layouts/Partials/routes.js b/resources/js/Layouts/Partials/routes.js
index cde5bdb..5a12b28 100644
--- a/resources/js/Layouts/Partials/routes.js
+++ b/resources/js/Layouts/Partials/routes.js
@@ -5,7 +5,12 @@ import {
HiUserGroup,
HiInformationCircle,
} from 'react-icons/hi'
-import { HiBanknotes, HiQuestionMarkCircle } from 'react-icons/hi2'
+import {
+ HiBanknotes,
+ HiOutlineGlobeAlt,
+ HiQuestionMarkCircle,
+ HiUserCircle,
+} from 'react-icons/hi2'
export default [
{
@@ -16,6 +21,14 @@ export default [
active: 'dashboard',
permission: 'view-dashboard',
},
+ {
+ name: 'Customer',
+ show: true,
+ icon: HiUserCircle,
+ route: route('customer.index'),
+ active: 'customer.*',
+ permission: 'view-customer',
+ },
{
name: 'Bank Akun',
show: true,
@@ -25,20 +38,27 @@ export default [
permission: 'view-account',
},
{
- name: 'Banner',
+ name: 'Front Home',
show: true,
- icon: HiInformationCircle,
- route: route('banner.index'),
- active: 'banner.*',
- permission: 'view-banner',
- },
- {
- name: 'Info',
- show: true,
- icon: HiQuestionMarkCircle,
- route: route('info.index'),
- active: 'info.index',
- permission: 'view-info',
+ icon: HiOutlineGlobeAlt,
+ items: [
+ {
+ name: 'Banner',
+ show: true,
+ icon: HiInformationCircle,
+ route: route('banner.index'),
+ active: 'banner.*',
+ permission: 'view-banner',
+ },
+ {
+ name: 'Info',
+ show: true,
+ icon: HiQuestionMarkCircle,
+ route: route('info.index'),
+ active: 'info.index',
+ permission: 'view-info',
+ },
+ ],
},
{
name: 'User',
diff --git a/resources/js/Pages/Customer/Form.jsx b/resources/js/Pages/Customer/Form.jsx
new file mode 100644
index 0000000..579a58a
--- /dev/null
+++ b/resources/js/Pages/Customer/Form.jsx
@@ -0,0 +1,149 @@
+import React, { useEffect, Suspense } from 'react'
+import { isEmpty } from 'lodash'
+
+import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
+import FormInput from '@/Components/FormInput'
+import Button from '@/Components/Button'
+import { Head, useForm } from '@inertiajs/react'
+import FormFile from '@/Components/FormFile'
+import FormInputWith from '@/Components/FormInputWith'
+import TextArea from '@/Components/TextArea'
+
+export default function Form(props) {
+ const { customer } = props
+
+ const { data, setData, post, processing, errors } = useForm({
+ username: '',
+ password: '',
+ name: '',
+ fullname: '',
+ address: '',
+ phone: '',
+ image: '',
+ image_url: '',
+ })
+
+ const handleOnChange = (event) => {
+ setData(
+ event.target.name,
+ event.target.type === 'checkbox'
+ ? event.target.checked
+ ? 1
+ : 0
+ : event.target.value
+ )
+ }
+ const handleSubmit = () => {
+ if (isEmpty(customer) === false) {
+ post(route('customer.update', customer))
+ return
+ }
+ post(route('customer.store'))
+ }
+
+ useEffect(() => {
+ if (isEmpty(customer) === false) {
+ setData({
+ username: customer.username,
+ password: customer.password,
+ name: customer.name,
+ fullname: customer.fullname,
+ address: customer.address,
+ phone: customer.phone,
+ image: customer.image,
+ image_url: customer.image_url,
+ })
+ }
+ }, [customer])
+
+ return (
+
+ Nama + | ++ Level + | ++ Deposit + | ++ Coin + | ++ |
---|---|---|---|---|
+ {customer.name} + | ++ {customer.level.name} + | ++ {customer.display_deposit} + | ++ {customer.display_coin} + | +
+
+ Ubah
+
+
+
+
+
+ Hapus
+
+ |
+