diff --git a/TODO.md b/TODO.md index ab2ee25..c5adff5 100644 --- a/TODO.md +++ b/TODO.md @@ -38,7 +38,7 @@ tambah batas bayar -> after save redirect history penambahan batas bayar) - [x] menu mitra wbb ada tombol tambah mitra untuk registrasi dengan full form - [x] menu pembayaran hutang [admin dapat melakukan pembayaran hutang dari customer, atau mengkonfirmasi pembayaran yang dilakukan custoemr] +- [x] ubah filter di mitra list dan customer list menjadi seperti di sale index - [ ] untuk detail mitra nanti akan ada button untuk (transaksi mitra dengan cakupan: pembelian voucher, pembayaran hutang, topuplimit, penambahan batas bayar, history deposit) -- [ ] ubah filter di mitra list dan customer list menjadi seperti di sale index - [ ] tambah floating button untuk notifikasi deposit (angka saja), di dashboard tambahkan list deposit terbaru diff --git a/app/Http/Controllers/Admin/CustomerController.php b/app/Http/Controllers/Admin/CustomerController.php index 83d97c3..ad0fc53 100644 --- a/app/Http/Controllers/Admin/CustomerController.php +++ b/app/Http/Controllers/Admin/CustomerController.php @@ -31,23 +31,30 @@ class CustomerController extends Controller }); } - if ($request->location_id != '') { - $query->whereHas('locationFavorites', fn ($q) => $q->where('id', $request->location_id)); + if ($request->location_ids != '') { + $query->whereHas('locationFavorites', fn ($q) => $q->whereIn('id', $request->location_ids)); } - if ($request->level_id != '') { - $query->where('customer_level_id', $request->level_id); + if ($request->levels != '') { + $query->whereIn('customer_level_id', $request->levels); } + $sortBy = 'updated_at'; + $sortRule = 'desc'; if ($request->sortBy != '' && $request->sortRule != '') { - $query->orderBy($request->sortBy, $request->sortRule); - } else { - $query->orderBy('updated_at', 'desc'); + $sortBy = $request->sortBy; + $sortRule = $request->sortRule; } + $query->orderBy($sortBy, $sortRule); + return inertia('Customer/Index', [ 'query' => $query->paginate(), 'stats' => $stats, + 'levels' => CustomerLevel::all(), + '_search' => $request->q, + '_sortBy' => $sortBy, + '_sortOrder' => $sortRule, ]); } @@ -108,8 +115,8 @@ class CustomerController extends Controller public function update(Request $request, Customer $customer) { $request->validate([ - 'email' => 'nullable|email|unique:customers,email,'.$customer->id, - 'username' => 'required|string|min:5|alpha_dash|unique:customers,username,'.$customer->id, + 'email' => 'nullable|email|unique:customers,email,' . $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', @@ -189,7 +196,6 @@ class CustomerController extends Controller 'items.*.type' => 'required|in:text,file', 'items.*.value' => 'nullable|string', ]); - // $partner = CustomerAsDataPartner::updateOrCreate([ 'customer_id' => $customer->id, diff --git a/app/Http/Controllers/Admin/CustomerMitraController.php b/app/Http/Controllers/Admin/CustomerMitraController.php index c002713..ae76626 100644 --- a/app/Http/Controllers/Admin/CustomerMitraController.php +++ b/app/Http/Controllers/Admin/CustomerMitraController.php @@ -51,23 +51,30 @@ class CustomerMitraController extends Controller }); } - if ($request->location_id != '') { - $query->whereHas('locationFavorites', fn ($q) => $q->where('id', $request->location_id)); + if ($request->location_ids != '') { + $query->whereHas('locationFavorites', fn ($q) => $q->whereIn('id', $request->location_ids)); } - if ($request->level_id != '') { - $query->where('customer_level_id', $request->level_id); + if ($request->levels != '') { + $query->whereIn('customer_level_id', $request->levels); } + $sortBy = 'updated_at'; + $sortRule = 'desc'; if ($request->sortBy != '' && $request->sortRule != '') { - $query->orderBy($request->sortBy, $request->sortRule); - } else { - $query->orderBy('updated_at', 'desc'); + $sortBy = $request->sortBy; + $sortRule = $request->sortRule; } + $query->orderBy($sortBy, $sortRule); + return inertia('CustomerMitra/Index', [ 'query' => $query->paginate(), 'stats' => $stats, + 'levels' => CustomerLevel::all(), + '_search' => $request->q, + '_sortBy' => $sortBy, + '_sortOrder' => $sortRule, ]); } @@ -213,8 +220,8 @@ class CustomerMitraController extends Controller public function update(Request $request, Customer $customer) { $request->validate([ - 'email' => 'nullable|email|unique:customers,email,'.$customer->id, - 'username' => 'required|string|min:5|alpha_dash|unique:customers,username,'.$customer->id, + 'email' => 'nullable|email|unique:customers,email,' . $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', diff --git a/resources/js/Pages/Customer/Index.jsx b/resources/js/Pages/Customer/Index.jsx index cefd842..919e32e 100644 --- a/resources/js/Pages/Customer/Index.jsx +++ b/resources/js/Pages/Customer/Index.jsx @@ -3,7 +3,7 @@ import { Link, 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 { HiOutlineFilter, HiPencil, HiTrash } from 'react-icons/hi' import { useModalState } from '@/hooks' import { formatIDR, hasPermission } from '@/utils' @@ -11,9 +11,8 @@ import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' import Pagination from '@/Components/Pagination' import ModalConfirm from '@/Components/ModalConfirm' import SearchInput from '@/Components/SearchInput' -import LocationSelectionInput from '../Location/SelectionInput' -import LevelSelectionInput from '../CustomerLevel/SelectionInput' import ThSort from '@/Components/ThSortComponent' +import ModalFilter from './ModalFilter' export default function Customer(props) { const { @@ -25,16 +24,15 @@ export default function Customer(props) { _sortOrder, } = props - const [location, setLocation] = useState(null) - const [level, setLevel] = useState(null) const [search, setSearch] = useState({ q: _search, sortBy: _sortBy, sortOrder: _sortOrder, }) - const preValue = usePrevious(`${search}${location}${level}`) + const preValue = usePrevious(`${search}`) const confirmModal = useModalState() + const filterModal = useModalState() const handleDeleteClick = (customer) => { confirmModal.setData(customer) @@ -70,19 +68,23 @@ export default function Customer(props) { }) } - const params = { q: search, location_id: location, level_id: level } + const handleFilter = (filter) => { + setSearch({ ...search, ...filter }) + } + + const params = { ...search } useEffect(() => { if (preValue) { router.get( route(route().current()), - { ...search, location_id: location, level_id: level }, + { ...search }, { replace: true, preserveState: true, } ) } - }, [search, location, level]) + }, [search]) const canCreate = hasPermission(auth, 'create-customer') const canUpdate = hasPermission(auth, 'update-customer') @@ -132,29 +134,17 @@ export default function Customer(props) { )}