done setting

dev
Aji Kamaludin 1 year ago
parent d3a470b9fc
commit d9a40b1895
No known key found for this signature in database
GPG Key ID: 19058F67F0083AD3

@ -6,11 +6,12 @@
- [x] CRUD Banner - [x] CRUD Banner
- [x] CRUD Rekening / Account - [x] CRUD Rekening / Account
- [x] CRUD Customer - [x] CRUD Customer
- [ ] CRUD Lokasi
- [ ] CRUD Voucher - [ ] CRUD Voucher
- [ ] Import Voucher - [ ] Import Voucher
- [ ] Deposit Menu (view daftar histori deposit) - [ ] Deposit Menu (view daftar histori deposit)
- [ ] Manual Approve Deposit - [ ] Manual Approve Deposit
- [ ] Setting Web (enable affilate, amount bonus affilate) - [x] Setting Web (enable affilate, amount bonus affilate)
- [ ] Setting Bonus Coin (memasukan amount bonus coin yang didapat dengan level dan harga voucher) - coin rewards - [ ] Setting Bonus Coin (memasukan amount bonus coin yang didapat dengan level dan harga voucher) - coin rewards
- [ ] Setting Level Customer (view levels, edit name of level,minimal saldo, max amount saldo, max hutang) - [ ] Setting Level Customer (view levels, edit name of level,minimal saldo, max amount saldo, max hutang)
- [ ] View Customer Coin History - [ ] View Customer Coin History

@ -0,0 +1,10 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class LocationController extends Controller
{
//
}

@ -0,0 +1,48 @@
<?php
namespace App\Http\Controllers;
use App\Models\Setting;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class SettingController extends Controller
{
public function index()
{
$setting = Setting::all();
return inertia('Setting/Index', [
'setting' => $setting,
'midtrans_notification_url' => route('api.midtrans.notification')
]);
}
public function update(Request $request)
{
$request->validate([
'AFFILATE_ENABLED' => 'required|in:0,1',
'AFFILATE_COIN_AMOUNT' => 'required|numeric',
'MIDTRANS_SERVER_KEY' => 'required|string',
'MIDTRANS_CLIENT_KEY' => 'required|string',
'MIDTRANS_MERCHANT_ID' => 'required|string',
'MIDTRANS_ENABLED' => 'required|in:0,1',
'midtrans_logo_file' => 'nullable|image',
]);
DB::beginTransaction();
foreach ($request->except(['midtrans_logo_file']) as $key => $value) {
Setting::where('key', $key)->update(['value' => $value]);
}
if ($request->hasFile('midtrans_logo_file')) {
$file = $request->file('midtrans_logo_file');
$file->store('uploads', 'public');
Setting::where('key', 'MIDTRANS_LOGO')->update(['value' => $file->hashName('uploads')]);
}
DB::commit();
session()->flash('message', ['type' => 'success', 'message' => 'Setting has beed saved']);
}
}

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Concerns\HasUlids; use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
@ -16,4 +17,19 @@ class Setting extends Model
'value', 'value',
'type', 'type',
]; ];
protected $appends = [
'url',
];
protected function url(): Attribute
{
return Attribute::make(get: function () {
if ($this->type == 'image') {
return asset($this->value);
}
return '';
});
}
} }

@ -20,14 +20,14 @@ class InstallationSeed extends Seeder
public function settings() public function settings()
{ {
$settings = [ $settings = [
['key' => 'AFFILATE_ENABLE', 'value' => '0', 'type' => 'checkbox'], ['key' => 'AFFILATE_ENABLED', 'value' => '0', 'type' => 'checkbox'],
['key' => 'AFFILATE_AMOUNT', 'value' => '0', 'type' => 'text'], ['key' => 'AFFILATE_COIN_AMOUNT', 'value' => '0', 'type' => 'text'],
['key' => 'MIDTRANS_SERVER_KEY', 'value' => 'SB-Mid-server-UA0LQbY4aALV0CfLLX1v7xs8', 'type' => 'text'], ['key' => 'MIDTRANS_SERVER_KEY', 'value' => 'SB-Mid-server-UA0LQbY4aALV0CfLLX1v7xs8', 'type' => 'text'],
['key' => 'MIDTRANS_CLIENT_KEY', 'value' => 'SB-Mid-client-xqqkspzoZOM10iUG', 'type' => 'text'], ['key' => 'MIDTRANS_CLIENT_KEY', 'value' => 'SB-Mid-client-xqqkspzoZOM10iUG', 'type' => 'text'],
['key' => 'MIDTRANS_MERCHANT_ID', 'value' => 'G561244367', 'type' => 'text'], ['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'],
]; ];
foreach ($settings as $setting) { foreach ($settings as $setting) {

@ -83,6 +83,11 @@ class PermissionSeeder extends Seeder
['id' => Str::ulid(), 'label' => 'Update Bank Account', 'name' => 'update-account'], ['id' => Str::ulid(), 'label' => 'Update Bank Account', 'name' => 'update-account'],
['id' => Str::ulid(), 'label' => 'View Bank Account', 'name' => 'view-account'], ['id' => Str::ulid(), 'label' => 'View Bank Account', 'name' => 'view-account'],
['id' => Str::ulid(), 'label' => 'Delete Bank Account', 'name' => 'delete-account'], ['id' => Str::ulid(), 'label' => 'Delete Bank Account', 'name' => 'delete-account'],
['id' => Str::ulid(), 'label' => 'Create Lokasi', 'name' => 'create-location'],
['id' => Str::ulid(), 'label' => 'Update Lokasi', 'name' => 'update-location'],
['id' => Str::ulid(), 'label' => 'View Lokasi', 'name' => 'view-location'],
['id' => Str::ulid(), 'label' => 'Delete Lokasi', 'name' => 'delete-location'],
]; ];
foreach ($permissions as $permission) { foreach ($permissions as $permission) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

@ -4,6 +4,7 @@ import {
HiUsers, HiUsers,
HiUserGroup, HiUserGroup,
HiInformationCircle, HiInformationCircle,
HiCog,
} from 'react-icons/hi' } from 'react-icons/hi'
import { import {
HiBanknotes, HiBanknotes,
@ -37,6 +38,14 @@ export default [
active: 'account.*', active: 'account.*',
permission: 'view-account', permission: 'view-account',
}, },
{
name: 'Setting',
show: true,
icon: HiCog,
route: route('setting.index'),
active: 'setting.*',
permission: 'view-setting',
},
{ {
name: 'Front Home', name: 'Front Home',
show: true, show: true,

@ -0,0 +1,146 @@
import React from 'react'
import { Head, router, useForm } from '@inertiajs/react'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import FormInput from '@/Components/FormInput'
import Button from '@/Components/Button'
import TextArea from '@/Components/TextArea'
import FormFile from '@/Components/FormFile'
import Checkbox from '@/Components/Checkbox'
import { extractValue } from './utils'
export default function General(props) {
const { setting, midtrans_notification_url } = props
const { data, setData, post, reset, processing, errors } = useForm({
AFFILATE_ENABLED: extractValue(setting, 'AFFILATE_ENABLED'),
AFFILATE_COIN_AMOUNT: extractValue(setting, 'AFFILATE_COIN_AMOUNT'),
MIDTRANS_SERVER_KEY: extractValue(setting, 'MIDTRANS_SERVER_KEY'),
MIDTRANS_CLIENT_KEY: extractValue(setting, 'MIDTRANS_CLIENT_KEY'),
MIDTRANS_MERCHANT_ID: extractValue(setting, 'MIDTRANS_MERCHANT_ID'),
MIDTRANS_LOGO: extractValue(setting, 'MIDTRANS_LOGO'),
MIDTRANS_ENABLED: extractValue(setting, 'MIDTRANS_ENABLED'),
midtrans_logo_file: null,
})
const handleOnChange = (event) => {
setData(
event.target.name,
event.target.type === 'checkbox'
? event.target.checked
? 1
: 0
: event.target.value
)
}
const handleSubmit = () => {
post(route('setting.update'), {
onSuccess: () => {
setTimeout(() => router.get(route(route().current())), 3000)
},
})
}
return (
<AuthenticatedLayout
auth={props.auth}
errors={props.errors}
flash={props.flash}
page={'Setting'}
action={''}
parent={route(route().current())}
>
<Head title="Setting" />
<div>
<div className="mx-auto sm:px-6 lg:px-8">
<div className="overflow-hidden p-4 shadow-sm sm:rounded-lg bg-white dark:bg-gray-800 flex flex-col">
<div className="text-xl font-bold mb-4">Setting</div>
<div className="p-2 border rounded-xl">
<div className="font-bold mb-2">Affilate</div>
<FormInput
type={'number'}
name="AFFILATE_COIN_AMOUNT"
value={data.AFFILATE_COIN_AMOUNT}
onChange={handleOnChange}
label="Jumlah Bonus Koin"
error={errors.AFFILATE_COIN_AMOUNT}
/>
<Checkbox
label="Enable"
value={+data.AFFILATE_ENABLED === 1}
onChange={handleOnChange}
name="AFFILATE_ENABLED"
/>
</div>
<div className="mt-2 p-2 border rounded-xl">
<div className="font-bold mb-2">
Midtrans Payment
</div>
<FormInput
name="MIDTRANS_MERCHANT_ID"
value={data.MIDTRANS_MERCHANT_ID}
onChange={handleOnChange}
label="Merchant ID"
error={errors.MIDTRANS_MERCHANT_ID}
/>
<FormInput
name="MIDTRANS_SERVER_KEY"
value={data.MIDTRANS_SERVER_KEY}
onChange={handleOnChange}
label="Server Key"
error={errors.MIDTRANS_SERVER_KEY}
/>
<FormInput
name="MIDTRANS_CLIENT_KEY"
value={data.MIDTRANS_CLIENT_KEY}
onChange={handleOnChange}
label="Client Key"
error={errors.MIDTRANS_CLIENT_KEY}
/>
<FormFile
label={'Logo'}
onChange={(e) =>
setData(
'midtrans_logo_file',
e.target.files[0]
)
}
error={errors.midtrans_logo_file}
preview={
<img
src={`${data.MIDTRANS_LOGO}`}
className="w-40 mb-1"
alt="site logo"
/>
}
/>
<FormInput
value={midtrans_notification_url}
label="Notification URL"
readOnly={true}
/>
<Checkbox
label="Enable"
value={+data.MIDTRANS_ENABLED === 1}
onChange={handleOnChange}
name="MIDTRANS_ENABLED"
/>
</div>
<div className="mt-4">
<Button
onClick={handleSubmit}
processing={processing}
>
Simpan
</Button>
</div>
</div>
</div>
</div>
</AuthenticatedLayout>
)
}

@ -0,0 +1,12 @@
import { isEmpty } from 'lodash'
export const extractValue = (set, key) => {
const find = set.find((s) => s.key === key)
if (isEmpty(find) === false) {
if (find.type === 'image') {
return find?.url
}
return find?.value
}
return ''
}

@ -8,6 +8,7 @@ use App\Http\Controllers\GeneralController;
use App\Http\Controllers\InfoController; use App\Http\Controllers\InfoController;
use App\Http\Controllers\ProfileController; use App\Http\Controllers\ProfileController;
use App\Http\Controllers\RoleController; use App\Http\Controllers\RoleController;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\UserController; use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
@ -75,5 +76,9 @@ Route::middleware(['http_secure_aware', 'inertia.admin'])
Route::get('/customers/{customer}', [CustomerController::class, 'edit'])->name('customer.edit'); Route::get('/customers/{customer}', [CustomerController::class, 'edit'])->name('customer.edit');
Route::post('/customers/{customer}', [CustomerController::class, 'update'])->name('customer.update'); Route::post('/customers/{customer}', [CustomerController::class, 'update'])->name('customer.update');
Route::delete('/customers/{customer}', [CustomerController::class, 'destroy'])->name('customer.destroy'); Route::delete('/customers/{customer}', [CustomerController::class, 'destroy'])->name('customer.destroy');
// setting
Route::get('/settings', [SettingController::class, 'index'])->name('setting.index');
Route::post('/settings', [SettingController::class, 'update'])->name('setting.update');
}); });
}); });

@ -20,3 +20,4 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
}); });
Route::get('/roles', [RoleController::class, 'index'])->name('api.role.index'); Route::get('/roles', [RoleController::class, 'index'])->name('api.role.index');
Route::post('mindtrans/notification', fn () => 'Ok!')->name('api.midtrans.notification');

Loading…
Cancel
Save