bank done
parent
c6abdf69d3
commit
fa0d534a8e
@ -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']);
|
||||
}
|
||||
}
|
@ -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>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue