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 != '') {
$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();

@ -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')) {

@ -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%");
});
});
}

@ -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', [

@ -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', [

@ -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');

@ -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%");
});
}

@ -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');

@ -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 != '') {

@ -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();

@ -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();

@ -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();

@ -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();

@ -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;
}

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

@ -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}
/>
<FormInputWith
type="number"
leftItem={<div className="text-sm">+62</div>}
@ -548,6 +569,58 @@ export default function Form(props) {
</>
)}
</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">
<Button
onClick={handleSubmit}
@ -559,6 +632,11 @@ export default function Form(props) {
</div>
</div>
</div>
<LocationModal
locations={locations}
modalState={locationModal}
onItemClick={handleItemClick}
/>
</AuthenticatedLayout>
)
}

@ -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'}
>
<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 && (
<Dropdown.Item>
<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