From 5220417caa81cc9b6852240baf1f4d067be4926b Mon Sep 17 00:00:00 2001
From: Aji Kamaludin
Date: Mon, 5 Jun 2023 01:36:23 +0700
Subject: [PATCH] verified customer
---
TODO.md | 10 +-
.../Controllers/Customer/AuthController.php | 4 +-
.../Controllers/Customer/CartController.php | 4 +
.../Customer/DepositController.php | 2 +
app/Http/Controllers/CustomerController.php | 29 ++-
app/Http/Controllers/DepositController.php | 1 +
app/Http/Controllers/SettingController.php | 1 +
.../Controllers/VerificationController.php | 24 +-
app/Models/Customer.php | 13 +-
database/seeders/InstallationSeed.php | 2 +
resources/js/Customer/Coin/Detail.jsx | 2 +-
resources/js/Customer/Coin/Index.jsx | 2 +-
resources/js/Customer/Index/BalanceBanner.jsx | 3 +-
resources/js/Customer/Index/UserBanner.jsx | 2 +-
resources/js/Customer/Profile/Index.jsx | 11 +-
resources/js/Layouts/CustomerLayout.jsx | 2 +-
resources/js/Pages/Customer/Form.jsx | 243 ++++++++++++------
resources/js/Pages/Setting/Index.jsx | 19 +-
resources/js/Pages/Verification/Form.jsx | 39 ++-
routes/admin.php | 1 +
20 files changed, 309 insertions(+), 105 deletions(-)
diff --git a/TODO.md b/TODO.md
index 77419d0..93968e4 100644
--- a/TODO.md
+++ b/TODO.md
@@ -13,12 +13,12 @@
- [x] Setting Level Customer (view levels, edit name of level,minimal saldo, max amount saldo, max hutang)
- [x] Deposit Menu (view daftar histori deposit)
- [x] Manual Approve Deposit
-- [ ] List Customer Verification
-- [ ] Manual Approve Verification -> mendapatkan limit hutang
+- [x] List Customer Verification
+- [x] Manual Approve Verification -> mendapatkan limit hutang
- [ ] Setting Bonus Coin (memasukan amount bonus coin yang didapat dengan level dan harga voucher) - bonus coin
- [ ] Voucher Sales
- [ ] Dashboard (gafik hasil penjualan : disorting tanggal, lokasi dan customer)
-- [ ] Notification (manual deposit, stock voucher)
+- [ ] Notification (manual deposit, deposit success, stock voucher, sale)
- [ ] View Customer Coin History
- [ ] Voucher - harga per level
- [ ] Voucher - harga coin
@@ -42,7 +42,7 @@
- [x] Customer Share Buyed Voucher, via WA dll
- [x] Register Refferal
- [x] Customer View Coin History
-- [ ] Verified Akun
-- [ ] Paylater
+- [x] Verified Akun
+- [ ] Paylater: index paylater, payment cart, deposite repay
- [ ] Coin Explorer
- [ ] Notification (purchase success, deposit success)
diff --git a/app/Http/Controllers/Customer/AuthController.php b/app/Http/Controllers/Customer/AuthController.php
index 3d38b77..c978f05 100644
--- a/app/Http/Controllers/Customer/AuthController.php
+++ b/app/Http/Controllers/Customer/AuthController.php
@@ -138,9 +138,9 @@ class AuthController extends Controller
public function destroy()
{
- Auth::logout();
+ session()->remove('carts');
- session()->flush();
+ Auth::logout();
return redirect()->route('customer.login')
->with('message', ['type' => 'success', 'message' => 'you are logged out, see you next time']);
diff --git a/app/Http/Controllers/Customer/CartController.php b/app/Http/Controllers/Customer/CartController.php
index 139a787..984472e 100644
--- a/app/Http/Controllers/Customer/CartController.php
+++ b/app/Http/Controllers/Customer/CartController.php
@@ -29,6 +29,8 @@ class CartController extends Controller
return inertia('Cart/Index', [
'carts' => $carts,
'total' => $total,
+ 'allow_process' => '', //TODO: check allow process payment
+ 'is_paylater' => '', //check is transaction use paylater
]);
}
@@ -138,6 +140,8 @@ class CartController extends Controller
}
}
+ // TODO: is use paylater track the paylater
+ // TODO: if use paylater credit all deposit if available
$deposit = $customer->deposites()->create([
'credit' => $total,
'description' => 'Pembayaran #' . $sale->code,
diff --git a/app/Http/Controllers/Customer/DepositController.php b/app/Http/Controllers/Customer/DepositController.php
index e9f5c84..646354f 100644
--- a/app/Http/Controllers/Customer/DepositController.php
+++ b/app/Http/Controllers/Customer/DepositController.php
@@ -106,6 +106,7 @@ class DepositController extends Controller
if ($transaction_status == 'settlement' || $transaction_status == 'capture') {
$is_valid = DepositHistory::STATUS_VALID;
$deposit->update_customer_balance();
+ // TODO: add paylater check
} elseif ($transaction_status == 'pending') {
$is_valid = DepositHistory::STATUS_WAIT_PAYMENT;
} else {
@@ -136,6 +137,7 @@ class DepositController extends Controller
if ($request->transaction_status == 'settlement' || $request->transaction_status == 'capture') {
$deposit->fill(['payment_status' => DepositHistory::STATUS_VALID]);
$deposit->update_customer_balance();
+ // TODO: add paylater check
} elseif ($request->transaction_status == 'pending') {
$deposit->fill(['payment_status' => DepositHistory::STATUS_WAIT_PAYMENT]);
} else {
diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php
index 9b04f5c..1b80398 100644
--- a/app/Http/Controllers/CustomerController.php
+++ b/app/Http/Controllers/CustomerController.php
@@ -3,13 +3,14 @@
namespace App\Http\Controllers;
use App\Models\Customer;
+use App\Models\CustomerLevel;
use Illuminate\Http\Request;
class CustomerController extends Controller
{
public function index(Request $request)
{
- $query = Customer::query()->with(['level']);
+ $query = Customer::query()->with(['level'])->orderBy('updated_at', 'desc');
if ($request->q != '') {
$query->where('name', 'like', "%$request->q%")
@@ -57,14 +58,15 @@ class CustomerController extends Controller
public function edit(Customer $customer)
{
return inertia('Customer/Form', [
- 'customer' => $customer,
+ 'customer' => $customer->load(['level']),
+ 'levels' => CustomerLevel::all()
]);
}
public function update(Request $request, Customer $customer)
{
$request->validate([
- 'username' => 'required|string|min:5|alpha_dash|unique:customers,username,'.$customer->id,
+ 'username' => 'required|string|min:5|alpha_dash|unique:customers,username,' . $customer->id,
'password' => 'nullable|string|min:8',
'name' => 'required|string',
'fullname' => 'required|string',
@@ -104,4 +106,25 @@ class CustomerController extends Controller
return redirect()->route('customer.index')
->with('message', ['type' => 'success', 'message' => 'Item has beed deleted']);
}
+
+ public function update_level(Request $request, Customer $customer)
+ {
+ $request->validate([
+ 'level' => 'required|exists:customer_levels,key',
+ 'paylater_limit' => 'required|numeric',
+ ]);
+
+ $level = CustomerLevel::where('key', $request->level)->first();
+
+ $customer->update(['customer_level_id' => $level->id]);
+
+ $customer->paylater()->updateOrCreate([
+ 'customer_id' => $customer->id,
+ ], [
+ 'limit' => $request->paylater_limit
+ ]);
+
+ return redirect()->route('customer.index')
+ ->with('message', ['type' => 'success', 'message' => 'Item has beed updated']);
+ }
}
diff --git a/app/Http/Controllers/DepositController.php b/app/Http/Controllers/DepositController.php
index b10dab1..695f990 100644
--- a/app/Http/Controllers/DepositController.php
+++ b/app/Http/Controllers/DepositController.php
@@ -55,6 +55,7 @@ class DepositController extends Controller
]);
if ($request->status == DepositHistory::STATUS_VALID) {
$deposit->update_customer_balance();
+ // TODO: add paylater check
}
DB::commit();
diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php
index d71dc52..4b89073 100644
--- a/app/Http/Controllers/SettingController.php
+++ b/app/Http/Controllers/SettingController.php
@@ -21,6 +21,7 @@ class SettingController extends Controller
public function update(Request $request)
{
$request->validate([
+ 'VOUCHER_STOCK_NOTIFICATION' => 'required|numeric',
'AFFILATE_ENABLED' => 'required|in:0,1',
'AFFILATE_COIN_AMOUNT' => 'required|numeric',
'MIDTRANS_SERVER_KEY' => 'required|string',
diff --git a/app/Http/Controllers/VerificationController.php b/app/Http/Controllers/VerificationController.php
index 4a27b9b..e0a23b9 100644
--- a/app/Http/Controllers/VerificationController.php
+++ b/app/Http/Controllers/VerificationController.php
@@ -34,9 +34,25 @@ class VerificationController extends Controller
public function update(Request $request, Customer $customer)
{
- // TODO: here
- $request->validate([]);
- //
- $customer->update([]);
+ $request->validate([
+ 'level' => 'required|exists:customer_levels,key',
+ 'paylater_limit' => 'required|numeric',
+ ]);
+
+ $level = CustomerLevel::where('key', $request->level)->first();
+
+ $customer->update([
+ 'customer_level_id' => $level->id,
+ 'identity_verified' => Customer::VERIFIED
+ ]);
+
+ $customer->paylater()->updateOrCreate([
+ 'customer_id' => $customer->id,
+ ], [
+ 'limit' => $request->paylater_limit
+ ]);
+
+ return redirect()->route('customer-verification.index')
+ ->with('message', ['type' => 'success', 'message' => 'Item has beed updated']);
}
}
diff --git a/app/Models/Customer.php b/app/Models/Customer.php
index 0eed2c8..71ecd47 100644
--- a/app/Models/Customer.php
+++ b/app/Models/Customer.php
@@ -51,6 +51,7 @@ class Customer extends Authenticatable
'display_coin',
'display_phone',
'paylater_limit',
+ 'is_allow_paylater'
];
protected static function booted(): void
@@ -145,7 +146,17 @@ class Customer extends Authenticatable
public function paylaterLimit(): Attribute
{
return Attribute::make(get: function () {
- return $this->paylater?->limit ?? '';
+ if ($this->is_allow_paylater) {
+ return $this->paylater->limit;
+ }
+ return '';
+ });
+ }
+
+ public function isAllowPaylater(): Attribute
+ {
+ return Attribute::make(get: function () {
+ return [CustomerLevel::GOLD => true, CustomerLevel::PLATINUM => true][$this->level->key] ?? false;
});
}
diff --git a/database/seeders/InstallationSeed.php b/database/seeders/InstallationSeed.php
index a0fdd11..78b6a9f 100644
--- a/database/seeders/InstallationSeed.php
+++ b/database/seeders/InstallationSeed.php
@@ -28,6 +28,8 @@ class InstallationSeed extends Seeder
['key' => 'MIDTRANS_MERCHANT_ID', 'value' => 'G561244367', 'type' => 'text'],
['key' => 'MIDTRANS_LOGO', 'value' => 'sample/midtrans_logo.png', 'type' => 'image'],
['key' => 'MIDTRANS_ENABLED', 'value' => '0', 'type' => 'text'],
+
+ ['key' => 'VOUCHER_STOCK_NOTIFICATION', 'value' => '10', 'type' => 'text'],
];
foreach ($settings as $setting) {
diff --git a/resources/js/Customer/Coin/Detail.jsx b/resources/js/Customer/Coin/Detail.jsx
index 0a8ec40..6d781d2 100644
--- a/resources/js/Customer/Coin/Detail.jsx
+++ b/resources/js/Customer/Coin/Detail.jsx
@@ -7,7 +7,7 @@ import CustomerLayout from '@/Layouts/CustomerLayout'
export default function Detail({ coin }) {
return (
-
+
{user.fullname}
diff --git a/resources/js/Customer/Index/BalanceBanner.jsx b/resources/js/Customer/Index/BalanceBanner.jsx
index e021457..422a7b7 100644
--- a/resources/js/Customer/Index/BalanceBanner.jsx
+++ b/resources/js/Customer/Index/BalanceBanner.jsx
@@ -1,3 +1,4 @@
+import { formatIDR } from '@/utils'
import { router } from '@inertiajs/react'
import { HiOutlineCash } from 'react-icons/hi'
@@ -25,7 +26,7 @@ export default function BalanceBanner({ user }) {
{user.level.name} Member
-
{user.paylater_limit}
+
{formatIDR(user.paylater_limit)}
diff --git a/resources/js/Customer/Index/UserBanner.jsx b/resources/js/Customer/Index/UserBanner.jsx
index 306981e..ae4db45 100644
--- a/resources/js/Customer/Index/UserBanner.jsx
+++ b/resources/js/Customer/Index/UserBanner.jsx
@@ -20,7 +20,7 @@ export default function UserBanner({ user }) {
diff --git a/resources/js/Customer/Profile/Index.jsx b/resources/js/Customer/Profile/Index.jsx
index 5860dac..e87037f 100644
--- a/resources/js/Customer/Profile/Index.jsx
+++ b/resources/js/Customer/Profile/Index.jsx
@@ -84,11 +84,12 @@ export default function Index({ auth: { user } }) {
- {/* menu hanya muncul untuk member gold atau platinum */}
-
+ {user.is_allow_paylater && (
+
+ )}
diff --git a/resources/js/Layouts/CustomerLayout.jsx b/resources/js/Layouts/CustomerLayout.jsx
index f075dbf..8663a59 100644
--- a/resources/js/Layouts/CustomerLayout.jsx
+++ b/resources/js/Layouts/CustomerLayout.jsx
@@ -43,7 +43,7 @@ export default function CustomerLayout({ children }) {
-
+
{
+ const {
+ props: { customer },
+ } = usePage()
const { data, setData, post, processing, errors } = useForm({
username: '',
@@ -56,6 +58,167 @@ export default function Form(props) {
}
}, [customer])
+ return (
+
}
+ name="phone"
+ value={data.phone}
+ onChange={handleOnChange}
+ error={errors.phone}
+ formClassName={'pl-10'}
+ label="Whatsapp"
+ />
+
+
+
+
setData('image', e.target.files[0])}
+ error={errors.image}
+ preview={
+ isEmpty(data.image_url) === false && (
+
+ )
+ }
+ />
+
+
+
+
+
+ )
+}
+
+const Identity = () => {
+ const {
+ props: { customer },
+ } = usePage()
+
+ if (isEmpty(customer.identity_image)) {
+ return
+ }
+
+ return (
+
+
KTP
+
+
+ )
+}
+
+const Paylater = () => {
+ const {
+ props: { customer, levels },
+ } = usePage()
+ const { data, setData, post, processing, errors } = useForm({
+ level: customer.level.key,
+ paylater_limit: +customer.paylater_limit,
+ })
+
+ const handleOnChange = (event) => {
+ setData(
+ event.target.name,
+ event.target.type === 'checkbox'
+ ? event.target.checked
+ ? 1
+ : 0
+ : event.target.value
+ )
+ }
+
+ const handleSubmit = () => {
+ post(route('customer.update_level', customer))
+ }
+
+ return (
+
+
+
Level
+
+ {errors.level && (
+
+ {errors.level}
+
+ )}
+
+
+
+
+
+
+
+
+ )
+}
+
+export default function Form(props) {
return (
}
- name="phone"
- value={data.phone}
- onChange={handleOnChange}
- error={errors.phone}
- formClassName={'pl-10'}
- label="Whatsapp"
- />
-
-
-
-
- setData('image', e.target.files[0])
- }
- error={errors.image}
- preview={
- isEmpty(data.image_url) === false && (
-
- )
- }
- />
-
-
-
-
+
+
+
diff --git a/resources/js/Pages/Setting/Index.jsx b/resources/js/Pages/Setting/Index.jsx
index d1ca87a..8034e55 100644
--- a/resources/js/Pages/Setting/Index.jsx
+++ b/resources/js/Pages/Setting/Index.jsx
@@ -12,6 +12,10 @@ import { extractValue } from './utils'
export default function General(props) {
const { setting, midtrans_notification_url } = props
const { data, setData, post, reset, processing, errors } = useForm({
+ VOUCHER_STOCK_NOTIFICATION: extractValue(
+ setting,
+ 'VOUCHER_STOCK_NOTIFICATION'
+ ),
AFFILATE_ENABLED: extractValue(setting, 'AFFILATE_ENABLED'),
AFFILATE_COIN_AMOUNT: extractValue(setting, 'AFFILATE_COIN_AMOUNT'),
MIDTRANS_SERVER_KEY: extractValue(setting, 'MIDTRANS_SERVER_KEY'),
@@ -56,10 +60,20 @@ export default function General(props) {
Setting
-
-
Affilate
+
Notification
+
+
+
+
Midtrans Payment
diff --git a/resources/js/Pages/Verification/Form.jsx b/resources/js/Pages/Verification/Form.jsx
index dc60ffe..bc45418 100644
--- a/resources/js/Pages/Verification/Form.jsx
+++ b/resources/js/Pages/Verification/Form.jsx
@@ -4,13 +4,14 @@ import { isEmpty } from 'lodash'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import Button from '@/Components/Button'
+import FormInput from '@/Components/FormInput'
export default function Form(props) {
const { customer, levels } = props
const { data, setData, post, processing, errors, reset, clearErrors } =
useForm({
- level: '',
- image_prove_url: '',
+ level: customer.level.key,
+ paylater_limit: +customer.paylater_limit,
})
const handleOnChange = (event) => {
@@ -56,7 +57,22 @@ export default function Form(props) {
customer
)}
>
- {customer.name}
+ {customer.fullname} (
+ {customer.username})
+
+
+
+
+ Whatsapp |
+ : |
+
+
+ {customer.phone}
|
@@ -70,7 +86,7 @@ export default function Form(props) {
/>
-
+
Level Upgrade
+ {errors.level && (
+
+ {errors.level}
+
+ )}
+
+
+