From d42065944bbf35b0c28d50593b15aacf7efadc1e Mon Sep 17 00:00:00 2001 From: Aji Kamaludin Date: Thu, 29 Jun 2023 11:06:47 +0700 Subject: [PATCH] form mitra done --- .../Controllers/Admin/CustomerController.php | 10 +-- .../Admin/CustomerMitraController.php | 51 ++++++++--- .../Controllers/Admin/DepositController.php | 8 +- .../Controllers/Admin/LocationController.php | 2 +- .../Admin/LocationProfileController.php | 4 +- app/Http/Controllers/Admin/RoleController.php | 2 +- app/Http/Controllers/Admin/SaleController.php | 8 +- app/Http/Controllers/Admin/UserController.php | 2 +- .../Controllers/Admin/VoucherController.php | 12 +-- .../Controllers/Api/CustomerController.php | 6 +- .../Controllers/Api/LocationController.php | 2 +- .../Api/LocationProfileController.php | 6 +- app/Http/Controllers/Api/RoleController.php | 2 +- app/Models/Setting.php | 2 +- resources/js/Customer/Verification/Index.jsx | 2 +- resources/js/Pages/CustomerMitra/Form.jsx | 86 ++++++++++++++++++- resources/js/Pages/CustomerMitra/Index.jsx | 78 +++++++++++++++++ .../js/Pages/CustomerMitra/LocationModal.jsx | 86 +++++++++++++++++++ 18 files changed, 319 insertions(+), 50 deletions(-) create mode 100644 resources/js/Pages/CustomerMitra/LocationModal.jsx diff --git a/app/Http/Controllers/Admin/CustomerController.php b/app/Http/Controllers/Admin/CustomerController.php index a5e2826..bc0612a 100644 --- a/app/Http/Controllers/Admin/CustomerController.php +++ b/app/Http/Controllers/Admin/CustomerController.php @@ -24,10 +24,10 @@ class CustomerController extends Controller if ($request->q != '') { $query->where(function ($query) use ($request) { - $query->where('name', 'like', "%$request->q%") - ->orWhere('fullname', 'like', "%$request->q%") - ->orWhere('email', 'like', "%$request->q%") - ->orWhere('phone', 'like', "%$request->q%"); + $query->where('name', 'ilike', "%$request->q%") + ->orWhere('fullname', 'ilike', "%$request->q%") + ->orWhere('email', 'ilike', "%$request->q%") + ->orWhere('phone', 'ilike', "%$request->q%"); }); } @@ -158,7 +158,7 @@ class CustomerController extends Controller $request->validate([ 'level' => 'required|exists:customer_levels,key', 'paylater_limit' => 'required|numeric', - 'day_deadline' => 'required|numeric', + 'day_deadline' => 'required|numeric|max:365', ]); $level = CustomerLevel::where('key', $request->level)->first(); diff --git a/app/Http/Controllers/Admin/CustomerMitraController.php b/app/Http/Controllers/Admin/CustomerMitraController.php index 25038ae..ff84bbd 100644 --- a/app/Http/Controllers/Admin/CustomerMitraController.php +++ b/app/Http/Controllers/Admin/CustomerMitraController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Customer; use App\Models\CustomerLevel; +use App\Models\Location; use App\Models\PaylaterCustomer; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -43,10 +44,10 @@ class CustomerMitraController extends Controller if ($request->q != '') { $query->where(function ($query) use ($request) { - $query->where('name', 'like', "%$request->q%") - ->orWhere('fullname', 'like', "%$request->q%") - ->orWhere('email', 'like', "%$request->q%") - ->orWhere('phone', 'like', "%$request->q%"); + $query->where('name', 'ilike', "%$request->q%") + ->orWhere('fullname', 'ilike', "%$request->q%") + ->orWhere('email', 'ilike', "%$request->q%") + ->orWhere('phone', 'ilike', "%$request->q%"); }); } @@ -70,15 +71,22 @@ class CustomerMitraController extends Controller ]); } - public function create() + public function create(Request $request) { $levels = CustomerLevel::where('key', CustomerLevel::GOLD) ->orWhere('key', CustomerLevel::PLATINUM) ->get(); + $locations = Location::query(); + + if ($request->location_q != '') { + $locations->where('name', 'ilike', "%$request->location_q%"); + } + return inertia('CustomerMitra/Form', [ 'levels' => $levels, - 'statuses' => Customer::STATUS + 'statuses' => Customer::STATUS, + 'locations' => $locations->paginate(10), ]); } @@ -98,7 +106,7 @@ class CustomerMitraController extends Controller // 'level' => 'required|exists:customer_levels,key', 'paylater_limit' => 'required|numeric', - 'day_deadline' => 'required|numeric', + 'day_deadline' => 'required|numeric|max:365', // 'id_number' => 'nullable|string', 'job' => 'nullable|string', @@ -109,6 +117,8 @@ class CustomerMitraController extends Controller 'items.*.name' => 'nullable|string', 'items.*.type' => 'required|in:text,file', 'items.*.value' => 'nullable|string', + 'locations' => 'nullable|array', + 'locations.*.id' => 'nullable|exists:locations,id', ]); $level = CustomerLevel::where('key', $request->level)->first(); @@ -141,6 +151,10 @@ class CustomerMitraController extends Controller $customer->save(); + foreach (collect($request->locations) as $location) { + $customer->locationFavorites()->attach($location['id']); + } + $customer->paylater()->create([ 'limit' => $request->paylater_limit, 'day_deadline' => $request->day_deadline @@ -149,7 +163,7 @@ class CustomerMitraController extends Controller $partner = $customer->partner()->create([ 'id_number' => $request->id_number, 'job' => $request->job, - 'additional_json' => json_encode($request->items), + 'additional_json' => json_encode($request->items ?? []), ]); if ($request->hasFile('image_selfie')) { @@ -175,16 +189,24 @@ class CustomerMitraController extends Controller ->with('message', ['type' => 'success', 'message' => 'Item has beed created']); } - public function edit(Customer $customer) + public function edit(Request $request, Customer $customer) { $levels = CustomerLevel::where('key', CustomerLevel::GOLD) ->orWhere('key', CustomerLevel::PLATINUM) ->get(); + $locations = Location::query(); + + if ($request->location_q != '') { + $locations->where('name', 'ilike', "%$request->location_q%"); + } + return inertia('CustomerMitra/Form', [ - 'customer' => $customer->load(['paylater', 'partner']), + 'customer' => $customer->load(['paylater', 'partner', 'locationFavorites']), 'levels' => $levels, - 'statuses' => Customer::STATUS + 'statuses' => Customer::STATUS, + 'locations' => $locations->paginate(10), + ]); } @@ -250,6 +272,11 @@ class CustomerMitraController extends Controller $customer->save(); + $customer->locationFavorites()->detach(); + foreach (collect($request->locations) as $location) { + $customer->locationFavorites()->attach($location['id']); + } + $customer->paylater()->updateOrCreate([ 'customer_id' => $customer->id, ], [ @@ -262,7 +289,7 @@ class CustomerMitraController extends Controller ], [ 'id_number' => $request->id_number, 'job' => $request->job, - 'additional_json' => json_encode($request->items), + 'additional_json' => json_encode($request->items ?? []), ]); if ($request->hasFile('image_selfie')) { diff --git a/app/Http/Controllers/Admin/DepositController.php b/app/Http/Controllers/Admin/DepositController.php index a57e231..7a78a31 100644 --- a/app/Http/Controllers/Admin/DepositController.php +++ b/app/Http/Controllers/Admin/DepositController.php @@ -20,11 +20,11 @@ class DepositController extends Controller if ($request->q != '') { $query->where(function ($query) use ($request) { - $query->where('description', 'like', "%$request->q%") + $query->where('description', 'ilike', "%$request->q%") ->orWhereHas('customer', function ($query) use ($request) { - $query->where('fullname', 'like', "%$request->q%") - ->orWhere('email', 'like', "%$request->q%") - ->orWhere('phone', 'like', "%$request->q%"); + $query->where('fullname', 'ilike', "%$request->q%") + ->orWhere('email', 'ilike', "%$request->q%") + ->orWhere('phone', 'ilike', "%$request->q%"); }); }); } diff --git a/app/Http/Controllers/Admin/LocationController.php b/app/Http/Controllers/Admin/LocationController.php index 068fba9..f166548 100644 --- a/app/Http/Controllers/Admin/LocationController.php +++ b/app/Http/Controllers/Admin/LocationController.php @@ -13,7 +13,7 @@ class LocationController extends Controller $query = Location::orderBy('updated_at', 'desc'); if ($request->q != '') { - $query->where('name', 'like', "%$request->q%"); + $query->where('name', 'ilike', "%$request->q%"); } return inertia('Location/Index', [ diff --git a/app/Http/Controllers/Admin/LocationProfileController.php b/app/Http/Controllers/Admin/LocationProfileController.php index 7092dd8..659c149 100644 --- a/app/Http/Controllers/Admin/LocationProfileController.php +++ b/app/Http/Controllers/Admin/LocationProfileController.php @@ -19,8 +19,8 @@ class LocationProfileController extends Controller } if ($request->q != '') { - $query->where('name', 'like', "%$request->q%") - ->orWhere('display_note', 'like', "%$request->q%"); + $query->where('name', 'ilike', "%$request->q%") + ->orWhere('display_note', 'ilike', "%$request->q%"); } return inertia('LocationProfile/Index', [ diff --git a/app/Http/Controllers/Admin/RoleController.php b/app/Http/Controllers/Admin/RoleController.php index 9c3188c..e493fc4 100644 --- a/app/Http/Controllers/Admin/RoleController.php +++ b/app/Http/Controllers/Admin/RoleController.php @@ -20,7 +20,7 @@ class RoleController extends Controller $query = Role::query()->with(['users']); if ($request->q) { - $query->where('name', 'like', "%{$request->q}%"); + $query->where('name', 'ilike', "%{$request->q}%"); } $query->orderBy('created_at', 'desc'); diff --git a/app/Http/Controllers/Admin/SaleController.php b/app/Http/Controllers/Admin/SaleController.php index e1aec70..2f5876f 100644 --- a/app/Http/Controllers/Admin/SaleController.php +++ b/app/Http/Controllers/Admin/SaleController.php @@ -15,11 +15,11 @@ class SaleController extends Controller ->orderBy('updated_at', 'desc'); if ($request->q != '') { - $query->where('code', 'like', "%$request->q%") + $query->where('code', 'ilike', "%$request->q%") ->orWhereHas('customer', function ($query) use ($request) { - $query->where('name', 'like', "%$request->q%") - ->orWhere('fullname', 'like', "%$request->q%") - ->orWhere('username', 'like', "%$request->q%"); + $query->where('name', 'ilike', "%$request->q%") + ->orWhere('fullname', 'ilike', "%$request->q%") + ->orWhere('username', 'ilike', "%$request->q%"); }); } diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index ce85b01..a914122 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -15,7 +15,7 @@ class UserController extends Controller $query = User::query()->with(['role']); if ($request->q) { - $query->where('name', 'like', "%{$request->q}%"); + $query->where('name', 'ilike', "%{$request->q}%"); } $query->orderBy('created_at', 'desc'); diff --git a/app/Http/Controllers/Admin/VoucherController.php b/app/Http/Controllers/Admin/VoucherController.php index 596f571..a73e10e 100644 --- a/app/Http/Controllers/Admin/VoucherController.php +++ b/app/Http/Controllers/Admin/VoucherController.php @@ -20,7 +20,7 @@ class VoucherController extends Controller $query = Location::orderBy('updated_at', 'desc'); if ($request->q != '') { - $query->where('name', 'like', "%$request->q%"); + $query->where('name', 'ilike', "%$request->q%"); } return inertia('Voucher/Location', [ @@ -38,8 +38,8 @@ class VoucherController extends Controller } if ($request->q != '') { - $query->where('name', 'like', "%$request->q%") - ->orWhere('display_note', 'like', "%$request->q%"); + $query->where('name', 'ilike', "%$request->q%") + ->orWhere('display_note', 'ilike', "%$request->q%"); } return inertia('Voucher/Profile', [ @@ -55,9 +55,9 @@ class VoucherController extends Controller ->where('location_profile_id', $profile->id); if ($request->q != '') { - $query->where('username', 'like', "%$request->q%") - ->orWhere('comment', 'like', "%$request->q%") - ->orWhere('profile', 'like', "%$request->q%"); + $query->where('username', 'ilike', "%$request->q%") + ->orWhere('comment', 'ilike', "%$request->q%") + ->orWhere('profile', 'ilike', "%$request->q%"); } if ($request->sortBy != '' && $request->sortRule != '') { diff --git a/app/Http/Controllers/Api/CustomerController.php b/app/Http/Controllers/Api/CustomerController.php index c2efaf5..fc6f09b 100644 --- a/app/Http/Controllers/Api/CustomerController.php +++ b/app/Http/Controllers/Api/CustomerController.php @@ -13,9 +13,9 @@ class CustomerController extends Controller $query = Customer::orderBy('updated_at', 'desc'); if ($request->q != '') { - $query->where('name', 'like', "%$request->q%") - ->orWhere('fullname', 'like', "%$request->q%") - ->orWhere('username', 'like', "%$request->q%"); + $query->where('name', 'ilike', "%$request->q%") + ->orWhere('fullname', 'ilike', "%$request->q%") + ->orWhere('username', 'ilike', "%$request->q%"); } return $query->limit(100)->get(); diff --git a/app/Http/Controllers/Api/LocationController.php b/app/Http/Controllers/Api/LocationController.php index 2bfe7ce..1af4333 100644 --- a/app/Http/Controllers/Api/LocationController.php +++ b/app/Http/Controllers/Api/LocationController.php @@ -13,7 +13,7 @@ class LocationController extends Controller $query = Location::orderBy('updated_at', 'desc'); if ($request->q != '') { - $query->where('name', 'like', "%$request->q%"); + $query->where('name', 'ilike', "%$request->q%"); } return $query->limit(100)->get(); diff --git a/app/Http/Controllers/Api/LocationProfileController.php b/app/Http/Controllers/Api/LocationProfileController.php index efce319..bb70691 100644 --- a/app/Http/Controllers/Api/LocationProfileController.php +++ b/app/Http/Controllers/Api/LocationProfileController.php @@ -14,9 +14,9 @@ class LocationProfileController extends Controller ->orderBy('updated_at', 'desc'); if ($request->q != '') { - $query->where('name', 'like', "%$request->q%") - ->orWhere('display_note', 'like', "%$request->q%") - ->orWhereHas('location', fn ($q) => $q->where('name', 'like', "%$request->q%")); + $query->where('name', 'ilike', "%$request->q%") + ->orWhere('display_note', 'ilike', "%$request->q%") + ->orWhereHas('location', fn ($q) => $q->where('name', 'ilike', "%$request->q%")); } return $query->limit(100)->get(); diff --git a/app/Http/Controllers/Api/RoleController.php b/app/Http/Controllers/Api/RoleController.php index 7f7ebe2..9b70fa6 100644 --- a/app/Http/Controllers/Api/RoleController.php +++ b/app/Http/Controllers/Api/RoleController.php @@ -13,7 +13,7 @@ class RoleController extends Controller $query = Role::query(); if ($request->q) { - $query->where('name', 'like', "%{$request->q}%"); + $query->where('name', 'ilike', "%{$request->q}%"); } return $query->limit(100)->get(); diff --git a/app/Models/Setting.php b/app/Models/Setting.php index b65c5d2..3f8a725 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -51,7 +51,7 @@ class Setting extends Model { $data = Cache::get('settings'); if ($data == null) { - $settings = Setting::where('key', 'like', 'OPEN%')->get(); + $settings = Setting::where('key', 'ilike', 'OPEN%')->get(); foreach ($settings as $setting) { $data[$setting->key] = $setting->value; } diff --git a/resources/js/Customer/Verification/Index.jsx b/resources/js/Customer/Verification/Index.jsx index 6ae785b..0789f6e 100644 --- a/resources/js/Customer/Verification/Index.jsx +++ b/resources/js/Customer/Verification/Index.jsx @@ -43,7 +43,7 @@ const VerificationForm = () => { preview={ ktp image diff --git a/resources/js/Pages/CustomerMitra/Form.jsx b/resources/js/Pages/CustomerMitra/Form.jsx index ef6d5ab..6099388 100644 --- a/resources/js/Pages/CustomerMitra/Form.jsx +++ b/resources/js/Pages/CustomerMitra/Form.jsx @@ -11,9 +11,13 @@ import TextArea from '@/Components/TextArea' import FormFile from '@/Components/FormFile' import Button from '@/Components/Button' import FormInputNumeric from '@/Components/FormInputNumeric' +import { useModalState } from '@/hooks' +import LocationModal from './LocationModal' export default function Form(props) { - const { customer, statuses, levels, csrf_token } = props + const { customer, statuses, levels, locations, csrf_token } = props + + const locationModal = useModalState() const [uploadIndex, setUploadIndex] = useState(null) const [loading, setLoading] = useState(false) @@ -121,6 +125,21 @@ export default function Form(props) { : event.target.value ) } + + const handleItemClick = (location) => { + const isExist = data.locations.find((l) => l.id === location.id) + if (isEmpty(isExist)) { + setData('locations', data.locations.concat(location)) + } + } + + const removeLocation = (location) => { + setData( + 'locations', + data.locations.filter((l) => l.id !== location.id) + ) + } + const handleSubmit = () => { if (isEmpty(customer) === false) { post(route('mitra.update', customer)) @@ -132,8 +151,10 @@ export default function Form(props) { useEffect(() => { if (isEmpty(customer) === false) { let items = [] - if (isEmpty(customer.partner) == false) { - items = JSON.parse(customer.partner.additional_json) + if (isEmpty(customer.partner) === false) { + if (customer.partner.additional_json !== null) { + items = JSON.parse(customer.partner.additional_json) + } } setData({ email: customer.email, @@ -155,6 +176,7 @@ export default function Form(props) { file_statement_url: customer?.partner?.file_statement_url, file_agreement_url: customer?.partner?.file_agreement_url, items: items, + locations: customer.location_favorites, }) } }, [customer]) @@ -184,7 +206,6 @@ export default function Form(props) { label="Nama Panggilan" error={errors.name} /> - +62} @@ -548,6 +569,58 @@ export default function Form(props) { )} +
+
+
+ Lokasi Favorit +
+
+ +
+
+
+ + + + + + + + + {data.locations.map((location) => ( + + + + + + ))} + +
+ Nama + + Deskripsi + +
+ {location.name} + + {location.description} + +
+ removeLocation( + location + ) + } + > + +
+
+
+
+ ) } diff --git a/resources/js/Pages/CustomerMitra/Index.jsx b/resources/js/Pages/CustomerMitra/Index.jsx index afe91a1..745070d 100644 --- a/resources/js/Pages/CustomerMitra/Index.jsx +++ b/resources/js/Pages/CustomerMitra/Index.jsx @@ -14,6 +14,7 @@ import SearchInput from '@/Components/SearchInput' import LocationSelectionInput from '../Location/SelectionInput' import LevelSelectionInput from '../CustomerLevel/SelectionInput' import ThSort from '@/Components/ThSortComponent' +import { HiEye } from 'react-icons/hi2' export default function Customer(props) { const { @@ -361,6 +362,83 @@ export default function Customer(props) { dismissOnClick={true} size={'sm'} > + + + +
+ Transaksi + Pembelian +
+ +
+ + + +
+ Riwayat + Hutang +
+ +
+ + + +
+ Riwayat + Topup limit +
+ +
+ + + +
+ Riwayat + penambahan + tenor +
+ +
+ + + +
+ Riwayat + Topup + Deposit +
+ +
{canUpdate && ( { + onItemClick(location) + modalState.toggle() + } + + const params = { location_q: search } + useEffect(() => { + if (preValue) { + router.get( + route(route().current()), + { location_q: search }, + { + replace: true, + preserveState: true, + } + ) + } + }, [search]) + + return ( + +
+ setSearch(e.target.value)} + /> +
+ + + + + + + + + {data.map((location) => ( + handleOnItemClick(location)} + > + + + + ))} + +
+ Nama + + Deskripsi +
+ {location.name} + + {location.description} +
+
+ +
+
+ ) +}