form mitra done

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

@ -24,10 +24,10 @@ class CustomerController extends Controller
if ($request->q != '') { if ($request->q != '') {
$query->where(function ($query) use ($request) { $query->where(function ($query) use ($request) {
$query->where('name', 'like', "%$request->q%") $query->where('name', 'ilike', "%$request->q%")
->orWhere('fullname', 'like', "%$request->q%") ->orWhere('fullname', 'ilike', "%$request->q%")
->orWhere('email', 'like', "%$request->q%") ->orWhere('email', 'ilike', "%$request->q%")
->orWhere('phone', 'like', "%$request->q%"); ->orWhere('phone', 'ilike', "%$request->q%");
}); });
} }
@ -158,7 +158,7 @@ class CustomerController extends Controller
$request->validate([ $request->validate([
'level' => 'required|exists:customer_levels,key', 'level' => 'required|exists:customer_levels,key',
'paylater_limit' => 'required|numeric', 'paylater_limit' => 'required|numeric',
'day_deadline' => 'required|numeric', 'day_deadline' => 'required|numeric|max:365',
]); ]);
$level = CustomerLevel::where('key', $request->level)->first(); $level = CustomerLevel::where('key', $request->level)->first();

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Customer; use App\Models\Customer;
use App\Models\CustomerLevel; use App\Models\CustomerLevel;
use App\Models\Location;
use App\Models\PaylaterCustomer; use App\Models\PaylaterCustomer;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -43,10 +44,10 @@ class CustomerMitraController extends Controller
if ($request->q != '') { if ($request->q != '') {
$query->where(function ($query) use ($request) { $query->where(function ($query) use ($request) {
$query->where('name', 'like', "%$request->q%") $query->where('name', 'ilike', "%$request->q%")
->orWhere('fullname', 'like', "%$request->q%") ->orWhere('fullname', 'ilike', "%$request->q%")
->orWhere('email', 'like', "%$request->q%") ->orWhere('email', 'ilike', "%$request->q%")
->orWhere('phone', 'like', "%$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) $levels = CustomerLevel::where('key', CustomerLevel::GOLD)
->orWhere('key', CustomerLevel::PLATINUM) ->orWhere('key', CustomerLevel::PLATINUM)
->get(); ->get();
$locations = Location::query();
if ($request->location_q != '') {
$locations->where('name', 'ilike', "%$request->location_q%");
}
return inertia('CustomerMitra/Form', [ return inertia('CustomerMitra/Form', [
'levels' => $levels, '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', 'level' => 'required|exists:customer_levels,key',
'paylater_limit' => 'required|numeric', 'paylater_limit' => 'required|numeric',
'day_deadline' => 'required|numeric', 'day_deadline' => 'required|numeric|max:365',
// //
'id_number' => 'nullable|string', 'id_number' => 'nullable|string',
'job' => 'nullable|string', 'job' => 'nullable|string',
@ -109,6 +117,8 @@ class CustomerMitraController extends Controller
'items.*.name' => 'nullable|string', 'items.*.name' => 'nullable|string',
'items.*.type' => 'required|in:text,file', 'items.*.type' => 'required|in:text,file',
'items.*.value' => 'nullable|string', 'items.*.value' => 'nullable|string',
'locations' => 'nullable|array',
'locations.*.id' => 'nullable|exists:locations,id',
]); ]);
$level = CustomerLevel::where('key', $request->level)->first(); $level = CustomerLevel::where('key', $request->level)->first();
@ -141,6 +151,10 @@ class CustomerMitraController extends Controller
$customer->save(); $customer->save();
foreach (collect($request->locations) as $location) {
$customer->locationFavorites()->attach($location['id']);
}
$customer->paylater()->create([ $customer->paylater()->create([
'limit' => $request->paylater_limit, 'limit' => $request->paylater_limit,
'day_deadline' => $request->day_deadline 'day_deadline' => $request->day_deadline
@ -149,7 +163,7 @@ class CustomerMitraController extends Controller
$partner = $customer->partner()->create([ $partner = $customer->partner()->create([
'id_number' => $request->id_number, 'id_number' => $request->id_number,
'job' => $request->job, 'job' => $request->job,
'additional_json' => json_encode($request->items), 'additional_json' => json_encode($request->items ?? []),
]); ]);
if ($request->hasFile('image_selfie')) { if ($request->hasFile('image_selfie')) {
@ -175,16 +189,24 @@ class CustomerMitraController extends Controller
->with('message', ['type' => 'success', 'message' => 'Item has beed created']); ->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) $levels = CustomerLevel::where('key', CustomerLevel::GOLD)
->orWhere('key', CustomerLevel::PLATINUM) ->orWhere('key', CustomerLevel::PLATINUM)
->get(); ->get();
$locations = Location::query();
if ($request->location_q != '') {
$locations->where('name', 'ilike', "%$request->location_q%");
}
return inertia('CustomerMitra/Form', [ return inertia('CustomerMitra/Form', [
'customer' => $customer->load(['paylater', 'partner']), 'customer' => $customer->load(['paylater', 'partner', 'locationFavorites']),
'levels' => $levels, 'levels' => $levels,
'statuses' => Customer::STATUS 'statuses' => Customer::STATUS,
'locations' => $locations->paginate(10),
]); ]);
} }
@ -250,6 +272,11 @@ class CustomerMitraController extends Controller
$customer->save(); $customer->save();
$customer->locationFavorites()->detach();
foreach (collect($request->locations) as $location) {
$customer->locationFavorites()->attach($location['id']);
}
$customer->paylater()->updateOrCreate([ $customer->paylater()->updateOrCreate([
'customer_id' => $customer->id, 'customer_id' => $customer->id,
], [ ], [
@ -262,7 +289,7 @@ class CustomerMitraController extends Controller
], [ ], [
'id_number' => $request->id_number, 'id_number' => $request->id_number,
'job' => $request->job, 'job' => $request->job,
'additional_json' => json_encode($request->items), 'additional_json' => json_encode($request->items ?? []),
]); ]);
if ($request->hasFile('image_selfie')) { if ($request->hasFile('image_selfie')) {

@ -20,11 +20,11 @@ class DepositController extends Controller
if ($request->q != '') { if ($request->q != '') {
$query->where(function ($query) use ($request) { $query->where(function ($query) use ($request) {
$query->where('description', 'like', "%$request->q%") $query->where('description', 'ilike', "%$request->q%")
->orWhereHas('customer', function ($query) use ($request) { ->orWhereHas('customer', function ($query) use ($request) {
$query->where('fullname', 'like', "%$request->q%") $query->where('fullname', 'ilike', "%$request->q%")
->orWhere('email', 'like', "%$request->q%") ->orWhere('email', 'ilike', "%$request->q%")
->orWhere('phone', 'like', "%$request->q%"); ->orWhere('phone', 'ilike', "%$request->q%");
}); });
}); });
} }

@ -13,7 +13,7 @@ class LocationController extends Controller
$query = Location::orderBy('updated_at', 'desc'); $query = Location::orderBy('updated_at', 'desc');
if ($request->q != '') { if ($request->q != '') {
$query->where('name', 'like', "%$request->q%"); $query->where('name', 'ilike', "%$request->q%");
} }
return inertia('Location/Index', [ return inertia('Location/Index', [

@ -19,8 +19,8 @@ class LocationProfileController extends Controller
} }
if ($request->q != '') { if ($request->q != '') {
$query->where('name', 'like', "%$request->q%") $query->where('name', 'ilike', "%$request->q%")
->orWhere('display_note', 'like', "%$request->q%"); ->orWhere('display_note', 'ilike', "%$request->q%");
} }
return inertia('LocationProfile/Index', [ return inertia('LocationProfile/Index', [

@ -20,7 +20,7 @@ class RoleController extends Controller
$query = Role::query()->with(['users']); $query = Role::query()->with(['users']);
if ($request->q) { if ($request->q) {
$query->where('name', 'like', "%{$request->q}%"); $query->where('name', 'ilike', "%{$request->q}%");
} }
$query->orderBy('created_at', 'desc'); $query->orderBy('created_at', 'desc');

@ -15,11 +15,11 @@ class SaleController extends Controller
->orderBy('updated_at', 'desc'); ->orderBy('updated_at', 'desc');
if ($request->q != '') { if ($request->q != '') {
$query->where('code', 'like', "%$request->q%") $query->where('code', 'ilike', "%$request->q%")
->orWhereHas('customer', function ($query) use ($request) { ->orWhereHas('customer', function ($query) use ($request) {
$query->where('name', 'like', "%$request->q%") $query->where('name', 'ilike', "%$request->q%")
->orWhere('fullname', 'like', "%$request->q%") ->orWhere('fullname', 'ilike', "%$request->q%")
->orWhere('username', 'like', "%$request->q%"); ->orWhere('username', 'ilike', "%$request->q%");
}); });
} }

@ -15,7 +15,7 @@ class UserController extends Controller
$query = User::query()->with(['role']); $query = User::query()->with(['role']);
if ($request->q) { if ($request->q) {
$query->where('name', 'like', "%{$request->q}%"); $query->where('name', 'ilike', "%{$request->q}%");
} }
$query->orderBy('created_at', 'desc'); $query->orderBy('created_at', 'desc');

@ -20,7 +20,7 @@ class VoucherController extends Controller
$query = Location::orderBy('updated_at', 'desc'); $query = Location::orderBy('updated_at', 'desc');
if ($request->q != '') { if ($request->q != '') {
$query->where('name', 'like', "%$request->q%"); $query->where('name', 'ilike', "%$request->q%");
} }
return inertia('Voucher/Location', [ return inertia('Voucher/Location', [
@ -38,8 +38,8 @@ class VoucherController extends Controller
} }
if ($request->q != '') { if ($request->q != '') {
$query->where('name', 'like', "%$request->q%") $query->where('name', 'ilike', "%$request->q%")
->orWhere('display_note', 'like', "%$request->q%"); ->orWhere('display_note', 'ilike', "%$request->q%");
} }
return inertia('Voucher/Profile', [ return inertia('Voucher/Profile', [
@ -55,9 +55,9 @@ class VoucherController extends Controller
->where('location_profile_id', $profile->id); ->where('location_profile_id', $profile->id);
if ($request->q != '') { if ($request->q != '') {
$query->where('username', 'like', "%$request->q%") $query->where('username', 'ilike', "%$request->q%")
->orWhere('comment', 'like', "%$request->q%") ->orWhere('comment', 'ilike', "%$request->q%")
->orWhere('profile', 'like', "%$request->q%"); ->orWhere('profile', 'ilike', "%$request->q%");
} }
if ($request->sortBy != '' && $request->sortRule != '') { if ($request->sortBy != '' && $request->sortRule != '') {

@ -13,9 +13,9 @@ class CustomerController extends Controller
$query = Customer::orderBy('updated_at', 'desc'); $query = Customer::orderBy('updated_at', 'desc');
if ($request->q != '') { if ($request->q != '') {
$query->where('name', 'like', "%$request->q%") $query->where('name', 'ilike', "%$request->q%")
->orWhere('fullname', 'like', "%$request->q%") ->orWhere('fullname', 'ilike', "%$request->q%")
->orWhere('username', 'like', "%$request->q%"); ->orWhere('username', 'ilike', "%$request->q%");
} }
return $query->limit(100)->get(); return $query->limit(100)->get();

@ -13,7 +13,7 @@ class LocationController extends Controller
$query = Location::orderBy('updated_at', 'desc'); $query = Location::orderBy('updated_at', 'desc');
if ($request->q != '') { if ($request->q != '') {
$query->where('name', 'like', "%$request->q%"); $query->where('name', 'ilike', "%$request->q%");
} }
return $query->limit(100)->get(); return $query->limit(100)->get();

@ -14,9 +14,9 @@ class LocationProfileController extends Controller
->orderBy('updated_at', 'desc'); ->orderBy('updated_at', 'desc');
if ($request->q != '') { if ($request->q != '') {
$query->where('name', 'like', "%$request->q%") $query->where('name', 'ilike', "%$request->q%")
->orWhere('display_note', 'like', "%$request->q%") ->orWhere('display_note', 'ilike', "%$request->q%")
->orWhereHas('location', fn ($q) => $q->where('name', 'like', "%$request->q%")); ->orWhereHas('location', fn ($q) => $q->where('name', 'ilike', "%$request->q%"));
} }
return $query->limit(100)->get(); return $query->limit(100)->get();

@ -13,7 +13,7 @@ class RoleController extends Controller
$query = Role::query(); $query = Role::query();
if ($request->q) { if ($request->q) {
$query->where('name', 'like', "%{$request->q}%"); $query->where('name', 'ilike', "%{$request->q}%");
} }
return $query->limit(100)->get(); return $query->limit(100)->get();

@ -51,7 +51,7 @@ class Setting extends Model
{ {
$data = Cache::get('settings'); $data = Cache::get('settings');
if ($data == null) { if ($data == null) {
$settings = Setting::where('key', 'like', 'OPEN%')->get(); $settings = Setting::where('key', 'ilike', 'OPEN%')->get();
foreach ($settings as $setting) { foreach ($settings as $setting) {
$data[$setting->key] = $setting->value; $data[$setting->key] = $setting->value;
} }

@ -43,7 +43,7 @@ const VerificationForm = () => {
preview={ preview={
<img <img
src={`${user.identity_image_url}`} src={`${user.identity_image_url}`}
className="w-full object-fill h-48 mb-1 " className="w-full object-fill mb-1 "
alt="ktp image" alt="ktp image"
loading="lazy" loading="lazy"
/> />

@ -11,9 +11,13 @@ import TextArea from '@/Components/TextArea'
import FormFile from '@/Components/FormFile' import FormFile from '@/Components/FormFile'
import Button from '@/Components/Button' import Button from '@/Components/Button'
import FormInputNumeric from '@/Components/FormInputNumeric' import FormInputNumeric from '@/Components/FormInputNumeric'
import { useModalState } from '@/hooks'
import LocationModal from './LocationModal'
export default function Form(props) { 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 [uploadIndex, setUploadIndex] = useState(null)
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
@ -121,6 +125,21 @@ export default function Form(props) {
: event.target.value : 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 = () => { const handleSubmit = () => {
if (isEmpty(customer) === false) { if (isEmpty(customer) === false) {
post(route('mitra.update', customer)) post(route('mitra.update', customer))
@ -132,8 +151,10 @@ export default function Form(props) {
useEffect(() => { useEffect(() => {
if (isEmpty(customer) === false) { if (isEmpty(customer) === false) {
let items = [] let items = []
if (isEmpty(customer.partner) == false) { if (isEmpty(customer.partner) === false) {
items = JSON.parse(customer.partner.additional_json) if (customer.partner.additional_json !== null) {
items = JSON.parse(customer.partner.additional_json)
}
} }
setData({ setData({
email: customer.email, email: customer.email,
@ -155,6 +176,7 @@ export default function Form(props) {
file_statement_url: customer?.partner?.file_statement_url, file_statement_url: customer?.partner?.file_statement_url,
file_agreement_url: customer?.partner?.file_agreement_url, file_agreement_url: customer?.partner?.file_agreement_url,
items: items, items: items,
locations: customer.location_favorites,
}) })
} }
}, [customer]) }, [customer])
@ -184,7 +206,6 @@ export default function Form(props) {
label="Nama Panggilan" label="Nama Panggilan"
error={errors.name} error={errors.name}
/> />
<FormInputWith <FormInputWith
type="number" type="number"
leftItem={<div className="text-sm">+62</div>} leftItem={<div className="text-sm">+62</div>}
@ -548,6 +569,58 @@ export default function Form(props) {
</> </>
)} )}
</div> </div>
<div className="border rounded-md px-2 mt-4">
<div className="flex flex-col w-full gap-2 p-2">
<div className="font-semibold">
Lokasi Favorit
</div>
<div>
<Button
onClick={() => locationModal.toggle()}
>
Tambah
</Button>
</div>
</div>
<div className="w-full px-2 mb-2">
<table className="w-full">
<thead>
<tr>
<th className="text-left px-2 py-1">
Nama
</th>
<th className="text-left px-2 py-1">
Deskripsi
</th>
<th className="px-2 py-1 justify-end" />
</tr>
</thead>
<tbody>
{data.locations.map((location) => (
<tr key={location.id}>
<td className="px-2 py-1">
{location.name}
</td>
<td className="px-2 py-1">
{location.description}
</td>
<td className="px-2 py-1">
<div
onClick={() =>
removeLocation(
location
)
}
>
<HiXCircle className="text-red-700 w-10 h-7" />
</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
<div className="mt-8"> <div className="mt-8">
<Button <Button
onClick={handleSubmit} onClick={handleSubmit}
@ -559,6 +632,11 @@ export default function Form(props) {
</div> </div>
</div> </div>
</div> </div>
<LocationModal
locations={locations}
modalState={locationModal}
onItemClick={handleItemClick}
/>
</AuthenticatedLayout> </AuthenticatedLayout>
) )
} }

@ -14,6 +14,7 @@ import SearchInput from '@/Components/SearchInput'
import LocationSelectionInput from '../Location/SelectionInput' import LocationSelectionInput from '../Location/SelectionInput'
import LevelSelectionInput from '../CustomerLevel/SelectionInput' import LevelSelectionInput from '../CustomerLevel/SelectionInput'
import ThSort from '@/Components/ThSortComponent' import ThSort from '@/Components/ThSortComponent'
import { HiEye } from 'react-icons/hi2'
export default function Customer(props) { export default function Customer(props) {
const { const {
@ -361,6 +362,83 @@ export default function Customer(props) {
dismissOnClick={true} dismissOnClick={true}
size={'sm'} size={'sm'}
> >
<Dropdown.Item>
<Link
href={route(
'mitra.edit',
customer
)}
className="flex space-x-1 items-center"
>
<HiEye />
<div>
Transaksi
Pembelian
</div>
</Link>
</Dropdown.Item>
<Dropdown.Item>
<Link
href={route(
'mitra.edit',
customer
)}
className="flex space-x-1 items-center"
>
<HiEye />
<div>
Riwayat
Hutang
</div>
</Link>
</Dropdown.Item>
<Dropdown.Item>
<Link
href={route(
'mitra.edit',
customer
)}
className="flex space-x-1 items-center"
>
<HiEye />
<div>
Riwayat
Topup limit
</div>
</Link>
</Dropdown.Item>
<Dropdown.Item>
<Link
href={route(
'mitra.edit',
customer
)}
className="flex space-x-1 items-center"
>
<HiEye />
<div>
Riwayat
penambahan
tenor
</div>
</Link>
</Dropdown.Item>
<Dropdown.Item>
<Link
href={route(
'mitra.edit',
customer
)}
className="flex space-x-1 items-center"
>
<HiEye />
<div>
Riwayat
Topup
Deposit
</div>
</Link>
</Dropdown.Item>
{canUpdate && ( {canUpdate && (
<Dropdown.Item> <Dropdown.Item>
<Link <Link

@ -0,0 +1,86 @@
import React, { useEffect, useState } from 'react'
import { usePrevious } from 'react-use'
import { router } from '@inertiajs/react'
import Modal from '@/Components/Modal'
import Pagination from '@/Components/Pagination'
import SearchInput from '@/Components/SearchInput'
export default function LocationModal(props) {
const {
modalState,
locations: { data, links },
onItemClick,
} = props
const [search, setSearch] = useState('')
const preValue = usePrevious(search)
const handleOnItemClick = (location) => {
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 (
<Modal
isOpen={modalState.isOpen}
toggle={modalState.toggle}
title={'Lokasi'}
>
<div className="w-full flex flex-row">
<SearchInput
value={search}
onChange={(e) => setSearch(e.target.value)}
/>
</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">
Deskripsi
</th>
</tr>
</thead>
<tbody>
{data.map((location) => (
<tr
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-200"
key={location.id}
onClick={() => handleOnItemClick(location)}
>
<td
scope="row"
className="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white"
>
{location.name}
</td>
<td className="py-4 px-6">
{location.description}
</td>
</tr>
))}
</tbody>
</table>
<div className="w-full flex flex-row justify-center">
<Pagination links={links} params={params} />
</div>
</Modal>
)
}
Loading…
Cancel
Save