bank done

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

@ -0,0 +1,63 @@
<?php
namespace App\Http\Controllers;
use App\Models\Account;
use Illuminate\Http\Request;
class AccountController extends Controller
{
public function index()
{
$query = Account::orderBy('updated_at', 'desc')->paginate();
return inertia('Account/Index', [
'query' => $query
]);
}
public function store(Request $request)
{
$request->validate([
'name' => 'required|string',
'bank_name' => 'required|string',
'holder_name' => 'required|string',
'account_number' => 'required|string',
]);
Account::create([
'name' => $request->name,
'bank_name' => $request->bank_name,
'holder_name' => $request->holder_name,
'account_number' => $request->account_number,
]);
session()->flash('message', ['type' => 'success', 'message' => 'Item has been saved']);
}
public function update(Request $request, Account $account)
{
$request->validate([
'name' => 'required|string',
'bank_name' => 'required|string',
'holder_name' => 'required|string',
'account_number' => 'required|string',
]);
$account->update([
'name' => $request->name,
'bank_name' => $request->bank_name,
'holder_name' => $request->holder_name,
'account_number' => $request->account_number,
]);
session()->flash('message', ['type' => 'success', 'message' => 'Item has been updated']);
}
public function destroy(Account $account)
{
$account->delete();
session()->flash('message', ['type' => 'success', 'message' => 'Item has been deleted']);
}
}

@ -14,7 +14,11 @@ class Authenticate extends Middleware
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
if (!$request->expectsJson()) {
$uri = $request->getRequestUri();
if (str_contains($uri, 'admin')) {
return route('admin.login');
}
return route('customer.login');
}
}

@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Models\Account;
use App\Models\Banner;
use App\Models\Info;
use Illuminate\Database\Seeder;
@ -17,6 +18,7 @@ class DummySeeder extends Seeder
{
$this->info();
$this->banner();
$this->account();
}
public function info()
@ -38,4 +40,21 @@ class DummySeeder extends Seeder
]);
}
}
public function account()
{
$banks = [
['name' => 'BRI', 'bank_name' => 'Bank Rakyat Indonesia', 'holder_name' => 'Aji Kamaludin', 'account_number' => '187391738129'],
['name' => 'Jago', 'bank_name' => 'Bank Jago', 'holder_name' => 'Aji Kamaludin', 'account_number' => '718297389172']
];
foreach ($banks as $bank) {
Account::create([
'name' => $bank['name'],
'bank_name' => $bank['bank_name'],
'holder_name' => $bank['holder_name'],
'account_number' => $bank['account_number'],
]);
}
}
}

@ -78,6 +78,11 @@ class PermissionSeeder extends Seeder
['id' => Str::ulid(), 'label' => 'Update Coin Reward', 'name' => 'update-coin-reward'],
['id' => Str::ulid(), 'label' => 'View Coin Reward', 'name' => 'view-coin-reward'],
['id' => Str::ulid(), 'label' => 'Delete Coin Reward', 'name' => 'delete-coin-reward'],
['id' => Str::ulid(), 'label' => 'Create Bank Account', 'name' => 'create-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' => 'Delete Bank Account', 'name' => 'delete-account'],
];
foreach ($permissions as $permission) {

@ -5,7 +5,7 @@ import {
HiUserGroup,
HiInformationCircle,
} from 'react-icons/hi'
import { HiQuestionMarkCircle } from 'react-icons/hi2'
import { HiBanknotes, HiQuestionMarkCircle } from 'react-icons/hi2'
export default [
{
@ -16,6 +16,14 @@ export default [
active: 'dashboard',
permission: 'view-dashboard',
},
{
name: 'Bank Akun',
show: true,
icon: HiBanknotes,
route: route('account.index'),
active: 'account.*',
permission: 'view-account',
},
{
name: 'Banner',
show: true,

@ -0,0 +1,108 @@
import React, { useEffect } from 'react'
import Modal from '@/Components/Modal'
import { useForm } from '@inertiajs/react'
import Button from '@/Components/Button'
import FormInput from '@/Components/FormInput'
import RoleSelectionInput from '../Role/SelectionInput'
import { isEmpty } from 'lodash'
export default function FormModal(props) {
const { modalState } = props
const { data, setData, post, put, processing, errors, reset, clearErrors } =
useForm({
name: '',
bank_name: '',
holder_name: '',
account_number: '',
})
const handleOnChange = (event) => {
setData(
event.target.name,
event.target.type === 'checkbox'
? event.target.checked
? 1
: 0
: event.target.value
)
}
const handleReset = () => {
modalState.setData(null)
reset()
clearErrors()
}
const handleClose = () => {
handleReset()
modalState.toggle()
}
const handleSubmit = () => {
const account = modalState.data
if (account !== null) {
put(route('account.update', account), {
onSuccess: () => handleClose(),
})
return
}
post(route('account.store'), {
onSuccess: () => handleClose(),
})
}
useEffect(() => {
const account = modalState.data
if (isEmpty(account) === false) {
setData({
name: account.name,
bank_name: account.bank_name,
holder_name: account.holder_name,
account_number: account.account_number,
})
return
}
}, [modalState])
return (
<Modal isOpen={modalState.isOpen} toggle={handleClose} title={'Info'}>
<FormInput
name="name"
value={data.name}
onChange={handleOnChange}
label="Nama"
error={errors.name}
/>
<FormInput
name="bank_name"
value={data.bank_name}
onChange={handleOnChange}
label="Nama Bank"
error={errors.bank_name}
/>
<FormInput
name="holder_name"
value={data.holder_name}
onChange={handleOnChange}
label="Atas Nama Rekening"
error={errors.holder_name}
/>
<FormInput
name="account_number"
value={data.account_number}
onChange={handleOnChange}
label="Nomor Rekening"
error={errors.account_number}
/>
<div className="flex items-center">
<Button onClick={handleSubmit} processing={processing}>
Simpan
</Button>
<Button onClick={handleClose} type="secondary">
Batal
</Button>
</div>
</Modal>
)
}

@ -0,0 +1,172 @@
import React, { useEffect, useState } from 'react'
import { router } from '@inertiajs/react'
import { usePrevious } from 'react-use'
import { Head } from '@inertiajs/react'
import { Button, Dropdown } from 'flowbite-react'
import { HiPencil, HiTrash } from 'react-icons/hi'
import { useModalState } from '@/hooks'
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
import Pagination from '@/Components/Pagination'
import ModalConfirm from '@/Components/ModalConfirm'
import FormModal from './FormModal'
import { hasPermission } from '@/utils'
export default function Account(props) {
const {
query: { links, data },
auth,
} = props
const confirmModal = useModalState()
const formModal = useModalState()
const toggleFormModal = (account = null) => {
formModal.setData(account)
formModal.toggle()
}
const handleDeleteClick = (account) => {
confirmModal.setData(account)
confirmModal.toggle()
}
const onDelete = () => {
if (confirmModal.data !== null) {
router.delete(route('account.destroy', confirmModal.data.id))
}
}
const canCreate = hasPermission(auth, 'create-account')
const canUpdate = hasPermission(auth, 'update-account')
const canDelete = hasPermission(auth, 'delete-account')
return (
<AuthenticatedLayout
auth={props.auth}
errors={props.errors}
flash={props.flash}
page={'Bank Akun'}
action={''}
>
<Head title="Bank Akun" />
<div>
<div className="mx-auto sm:px-6 lg:px-8 ">
<div className="p-6 overflow-hidden shadow-sm sm:rounded-lg bg-gray-200 dark:bg-gray-800 space-y-4">
<div className="flex justify-between">
{canCreate && (
<Button
size="sm"
onClick={() => toggleFormModal()}
>
Tambah
</Button>
)}
</div>
<div className="overflow-auto">
<div>
<table className="w-full text-sm text-left text-gray-500 dark:text-gray-400 mb-4">
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th
scope="col"
className="py-3 px-6"
>
Nama
</th>
<th
scope="col"
className="py-3 px-6"
>
Atas Nama Rekening
</th>
<th
scope="col"
className="py-3 px-6"
>
Nomor Rekening
</th>
<th
scope="col"
className="py-3 px-6"
/>
</tr>
</thead>
<tbody>
{data.map((account) => (
<tr
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700"
key={account.id}
>
<td
scope="row"
className="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white"
>
{account.name}
</td>
<td className="py-4 px-6">
{account.holder_name}
</td>
<td className="py-4 px-6">
{account.account_number}
</td>
<td className="py-4 px-6 flex justify-end">
<Dropdown
label={'Opsi'}
floatingArrow={true}
arrowIcon={true}
dismissOnClick={true}
size={'sm'}
>
{canUpdate && (
<Dropdown.Item
onClick={() =>
toggleFormModal(
account
)
}
>
<div className="flex space-x-1 items-center">
<HiPencil />
<div>
Ubah
</div>
</div>
</Dropdown.Item>
)}
{canDelete && (
<Dropdown.Item
onClick={() =>
handleDeleteClick(
account
)
}
>
<div className="flex space-x-1 items-center">
<HiTrash />
<div>
Hapus
</div>
</div>
</Dropdown.Item>
)}
</Dropdown>
</td>
</tr>
))}
</tbody>
</table>
</div>
<div className="w-full flex items-center justify-center">
<Pagination links={links} />
</div>
</div>
</div>
</div>
</div>
<ModalConfirm modalState={confirmModal} onConfirm={onDelete} />
<FormModal modalState={formModal} />
</AuthenticatedLayout>
)
}

@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\AccountController;
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\BannerController;
use App\Http\Controllers\GeneralController;
@ -49,6 +50,12 @@ Route::middleware(['http_secure_aware', 'inertia.admin'])
Route::put('/infos/{info}', [InfoController::class, 'update'])->name('info.update');
Route::delete('/infos/{info}', [InfoController::class, 'destroy'])->name('info.destroy');
// Account
Route::get('/accounts', [AccountController::class, 'index'])->name('account.index');
Route::post('/accounts', [AccountController::class, 'store'])->name('account.store');
Route::put('/accounts/{account}', [AccountController::class, 'update'])->name('account.update');
Route::delete('/accounts/{account}', [AccountController::class, 'destroy'])->name('account.destroy');
// upload
Route::post('/upload', [GeneralController::class, 'upload'])->name('post.upload');

@ -14,4 +14,14 @@ export default defineConfig({
}),
react(),
],
// build: {
// // chunkSizeWarningLimit: 1024 * 2048, //2MB
// rollupOptions: {
// output: {
// manualChunks: {
// chunk1: ['tinymce', /tinymce/],
// },
// },
// },
// },
})

Loading…
Cancel
Save