diff --git a/app/Http/Controllers/Admin/CustomerMitraController.php b/app/Http/Controllers/Admin/CustomerMitraController.php index bf6d78b..2dc1916 100644 --- a/app/Http/Controllers/Admin/CustomerMitraController.php +++ b/app/Http/Controllers/Admin/CustomerMitraController.php @@ -33,7 +33,7 @@ class CustomerMitraController extends Controller ->count(), 'sum_paylater_limit' => PaylaterCustomer::sum('limit'), 'sum_paylater_usage' => PaylaterCustomer::sum('usage'), - 'sum_paylater_remain' => PaylaterCustomer::selectRaw('(SUM("limit") - SUM(usage)) as remain')->value('remain'), + 'sum_paylater_remain' => PaylaterCustomer::selectRaw('(SUM("limit") - SUM("usage")) as remain')->value('remain'), ]; $query = Customer::query()->with(['level', 'paylater', 'locationFavorites']) @@ -220,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/app/Http/Controllers/Admin/GeneralController.php b/app/Http/Controllers/Admin/GeneralController.php index 0d3f014..60982fa 100644 --- a/app/Http/Controllers/Admin/GeneralController.php +++ b/app/Http/Controllers/Admin/GeneralController.php @@ -103,15 +103,15 @@ class GeneralController extends Controller $date = $date->addDay(); } - $saleYearDepositCharts = Sale::selectRaw("SUM(amount) as sale_total, DATE_PART('month', date_time) as month") + $saleYearDepositCharts = Sale::selectRaw("SUM(amount) as sale_total, MONTH(date_time) as month") ->where('payed_with', Sale::PAYED_WITH_DEPOSIT) - ->whereRaw("DATE_PART('year', sales.date_time) = " . Carbon::parse($year)->year) - ->groupBy(DB::raw("DATE_PART('month', date_time)")); + ->whereRaw("YEAR(sales.date_time) = " . Carbon::parse($year)->year) + ->groupBy(DB::raw("MONTH(date_time)")); - $saleYearPaylaterCharts = Sale::selectRaw("SUM(amount) as sale_total, DATE_PART('month', date_time) as month") + $saleYearPaylaterCharts = Sale::selectRaw("SUM(amount) as sale_total, MONTH(date_time) as month") ->where('payed_with', Sale::PAYED_WITH_PAYLATER) - ->whereRaw("DATE_PART('year', sales.date_time) = " . Carbon::parse($year)->year) - ->groupBy(DB::raw("DATE_PART('month', date_time)")); + ->whereRaw("YEAR(sales.date_time) = " . Carbon::parse($year)->year) + ->groupBy(DB::raw("MONTH(date_time)")); // filter lokasi if ($request->year_location_id != '') { diff --git a/app/Http/Controllers/Admin/VoucherController.php b/app/Http/Controllers/Admin/VoucherController.php index c9b50de..8334a5c 100644 --- a/app/Http/Controllers/Admin/VoucherController.php +++ b/app/Http/Controllers/Admin/VoucherController.php @@ -54,9 +54,11 @@ class VoucherController extends Controller ->where('location_profile_id', $profile->id); if ($request->q != '') { - $query->where('username', 'ilike', "%$request->q%") + $query->where(function ($query) use ($request){ + $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/Customer/AuthController.php b/app/Http/Controllers/Customer/AuthController.php index 8c8cc1c..2b8f325 100644 --- a/app/Http/Controllers/Customer/AuthController.php +++ b/app/Http/Controllers/Customer/AuthController.php @@ -54,7 +54,7 @@ class AuthController extends Controller } $password = Hash::check($request->password, $user->password); - if (! $password) { + if (!$password) { return redirect()->route('customer.login') ->with('message', ['type' => 'error', 'message' => 'Invalid credentials']); } @@ -107,9 +107,9 @@ class AuthController extends Controller DB::beginTransaction(); $customer = Customer::create([ 'fullname' => $user->name, - 'name' => $user->nickname, + 'name' => $user->name, 'email' => $user->email, - 'username' => Str::slug($user->name.'_'.Str::random(5), '_'), + 'username' => Str::slug($user->name . '_' . Str::random(5), '_'), 'google_id' => $user->id, 'google_oauth_response' => json_encode($user), 'status' => Customer::STATUS_ACTIVE, @@ -153,7 +153,7 @@ class AuthController extends Controller $request->validate([ 'fullname' => 'required|string', 'email' => 'required|email|unique:users,email', - 'name' => 'required|string', + 'name' => 'nullable|string', 'address' => 'required|string', 'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:9|max:16', 'username' => 'required|string|min:5|alpha_dash|unique:customers,username', @@ -164,7 +164,7 @@ class AuthController extends Controller DB::beginTransaction(); $customer = Customer::create([ 'fullname' => $request->fullname, - 'name' => $request->name, + 'name' => $request->fullname, 'address' => $request->address, 'phone' => $request->phone, 'username' => $request->username, diff --git a/app/Http/Controllers/Customer/CartController.php b/app/Http/Controllers/Customer/CartController.php index e4dfa93..b2adc41 100644 --- a/app/Http/Controllers/Customer/CartController.php +++ b/app/Http/Controllers/Customer/CartController.php @@ -109,7 +109,7 @@ class CartController extends Controller // validate carts not empty if ($carts->count() == 0) { - return redirect()->route('home.index') + return redirect()->route('home.index', ['direct' => 1]) ->with('message', ['type' => 'error', 'message' => 'transaksi gagal, keranjang anda kosong']); } @@ -119,7 +119,7 @@ class CartController extends Controller if ($batchCount < $item->quantity) { $customer->carts()->delete(); - return redirect()->route('home.index') + return redirect()->route('home.index', ['direct' => 1]) ->with('message', ['type' => 'error', 'message' => 'transaksi gagal, voucher sedang tidak tersedia']); } } diff --git a/app/Http/Controllers/Customer/ProfileController.php b/app/Http/Controllers/Customer/ProfileController.php index 61ce33d..5ea743f 100644 --- a/app/Http/Controllers/Customer/ProfileController.php +++ b/app/Http/Controllers/Customer/ProfileController.php @@ -29,10 +29,10 @@ class ProfileController extends Controller $request->validate([ 'fullname' => 'string|required', - 'name' => 'string|required', + 'name' => 'string|nullable', 'address' => 'string|required', 'phone' => 'string|required|numeric', - 'username' => 'string|required|min:5|alpha_dash|unique:customers,username,'.$customer->id, + 'username' => 'string|required|min:5|alpha_dash|unique:customers,username,' . $customer->id, 'password' => 'nullable|string|min:8|confirmed', 'image' => 'nullable|image', ]); @@ -49,7 +49,7 @@ class ProfileController extends Controller $customer->update([ 'fullname' => $request->fullname, - 'name' => $request->name, + 'name' => $request->fullname, 'address' => $request->address, 'phone' => $request->phone, 'username' => $request->username, diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 68242dd..5246f01 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -70,5 +70,6 @@ class Kernel extends HttpKernel 'inertia.customer' => \App\Http\Middleware\HandleInertiaCustomerRequests::class, 'guard_should_customer' => \App\Http\Middleware\GuardCustomer::class, 'http_secure_aware' => \App\Http\Middleware\HttpSecureAware::class, + 'customer.is_complate_profile' => \App\Http\Middleware\CustomerComplateProfile::class, ]; } diff --git a/app/Http/Middleware/CustomerApi.php b/app/Http/Middleware/CustomerApi.php new file mode 100644 index 0000000..7cbe4ad --- /dev/null +++ b/app/Http/Middleware/CustomerApi.php @@ -0,0 +1,26 @@ +header('user') != '') { + $customer = Customer::find($request->header('user')); + Auth::guard('customer')->setUser($customer); + } + return $next($request); + } +} diff --git a/app/Http/Middleware/CustomerComplateProfile.php b/app/Http/Middleware/CustomerComplateProfile.php new file mode 100644 index 0000000..297ebe5 --- /dev/null +++ b/app/Http/Middleware/CustomerComplateProfile.php @@ -0,0 +1,27 @@ +user('customer'); + + if (!$customer->is_profile_complate) { + return redirect()->route('customer.profile.show') + ->with('message', ['type' => 'error', 'message' => 'silahkan lengkapi profile sebelum dapat ber-transaksi']); + } + + return $next($request); + } +} diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 91211db..8e657f7 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -145,7 +145,7 @@ class Customer extends Authenticatable return ' - '; } - return '+62'.$this->phone; + return '+62' . $this->phone; }); } @@ -245,6 +245,34 @@ class Customer extends Authenticatable }); } + public function isProfileComplate(): Attribute + { + return Attribute::make(get: function () { + if (in_array(null, [ + $this->username, + $this->email, + $this->name, + $this->fullname, + $this->address, + $this->phone, + ])) { + return false; + } + if (in_array('', [ + $this->username, + $this->email, + $this->name, + $this->fullname, + $this->address, + $this->phone, + ])) { + return false; + } + + return true; + }); + } + public function level() { return $this->belongsTo(CustomerLevel::class, 'customer_level_id'); diff --git a/app/Models/SaleItem.php b/app/Models/SaleItem.php index 36a8641..b0e952b 100644 --- a/app/Models/SaleItem.php +++ b/app/Models/SaleItem.php @@ -37,7 +37,10 @@ class SaleItem extends Model public function shareWord(): Attribute { return Attribute::make(get: function () { - return Setting::getByKey('SHARE_TEXT'); + $shareText = Setting::getByKey('SHARE_TEXT').' +Kode Voucher : ' . $this->voucher->username; + + return $shareText; }); } } diff --git a/resources/js/Customer/Auth/Register.jsx b/resources/js/Customer/Auth/Register.jsx index f3b820b..acac204 100644 --- a/resources/js/Customer/Auth/Register.jsx +++ b/resources/js/Customer/Auth/Register.jsx @@ -68,7 +68,7 @@ export default function Index({ referral_code, flash }) { onKeyDownCapture={(e) => handleKeyDown(e)} /> -
+ {/*
handleKeyDown(e)} /> -
+
*/}
{ + setCarts(carts.filter((c) => c.id !== cart.id)) + } + + console.log(carts) + const changeQty = (cart, qty) => { + setCarts( + carts.map((c) => { + if (c.id === cart.id) { + return { + ...c, + quantity: qty, + } + } + return c + }) + ) + } + const handlePayment = () => { paymentModal.toggle() } @@ -28,7 +48,12 @@ export default function Index({ carts, total, allow_process }) { <>
{carts.map((item) => ( - + ))}
diff --git a/resources/js/Customer/Cart/VoucherCard.jsx b/resources/js/Customer/Cart/VoucherCard.jsx index 92f8b64..9d0fd4c 100644 --- a/resources/js/Customer/Cart/VoucherCard.jsx +++ b/resources/js/Customer/Cart/VoucherCard.jsx @@ -1,23 +1,72 @@ import { formatIDR } from '@/utils' -import { router } from '@inertiajs/react' +import { router, usePage } from '@inertiajs/react' import { HiMinusCircle, HiPlusCircle, HiTrash } from 'react-icons/hi2' -export default function VoucherCard({ item: { location_profile, quantity } }) { +export default function VoucherCard({ item, onRemove, onChangeQty }) { + const { + props: { + auth: { user }, + }, + } = usePage() + + const { location_profile, quantity } = item + const handleDelete = () => { - router.post( - route('cart.store', { profile: location_profile, param: 'delete' }) + onRemove(item) + fetch( + route('api.cart.store', { + profile: location_profile, + param: 'delete', + }), + { + method: 'POST', + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + user: user.id, + }, + } ) } const handleAdd = () => { - router.post( - route('cart.store', { profile: location_profile, param: 'add' }) + const qty = +quantity + 1 + onChangeQty(item, qty) + fetch( + route('api.cart.store', { + profile: location_profile, + param: 'add', + }), + { + method: 'POST', + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + user: user.id, + }, + } ) } const handleSub = () => { - router.post( - route('cart.store', { profile: location_profile, param: 'sub' }) + const qty = +quantity - 1 + if (qty <= 0) { + return + } + onChangeQty(item, qty) + fetch( + route('api.cart.store', { + profile: location_profile, + param: 'sub', + }), + { + method: 'POST', + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + user: user.id, + }, + } ) } diff --git a/resources/js/Customer/Deposit/Detail.jsx b/resources/js/Customer/Deposit/Detail.jsx index c23c5c2..73e0f49 100644 --- a/resources/js/Customer/Deposit/Detail.jsx +++ b/resources/js/Customer/Deposit/Detail.jsx @@ -88,7 +88,7 @@ export default function Detail({ deposit, back }) {
{deposit.status.text}
diff --git a/resources/js/Customer/Deposit/Index.jsx b/resources/js/Customer/Deposit/Index.jsx index 3c4b894..c48c3ab 100644 --- a/resources/js/Customer/Deposit/Index.jsx +++ b/resources/js/Customer/Deposit/Index.jsx @@ -110,7 +110,7 @@ export default function Index(props) {
{+history.is_valid !== 0 && (
{history.status.text}
diff --git a/resources/js/Customer/Index/Partials/UserBanner.jsx b/resources/js/Customer/Index/Partials/UserBanner.jsx index c1ff1dd..e5ccb97 100644 --- a/resources/js/Customer/Index/Partials/UserBanner.jsx +++ b/resources/js/Customer/Index/Partials/UserBanner.jsx @@ -12,12 +12,24 @@ export default function UserBanner({ user }) {
{/* user */}
-
-
{user.name}
-
-
{user.username}
-
- {user.level.name} +
+ {user.image_url !== null ? ( + profile image + ) : ( + + )} +
+
{user.name}
+
+
{user.username}
+
+ {user.level.name} +
diff --git a/resources/js/Customer/Paylater/Index.jsx b/resources/js/Customer/Paylater/Index.jsx index 40f04c0..9be8c2b 100644 --- a/resources/js/Customer/Paylater/Index.jsx +++ b/resources/js/Customer/Paylater/Index.jsx @@ -97,9 +97,9 @@ export default function Index({
{history.status !== '' && (
- {history.status} + {history.status_text.text}
)}
diff --git a/resources/js/Customer/Profile/Form.jsx b/resources/js/Customer/Profile/Form.jsx index 97685cf..13fad0b 100644 --- a/resources/js/Customer/Profile/Form.jsx +++ b/resources/js/Customer/Profile/Form.jsx @@ -70,7 +70,7 @@ export default function Index({ auth: { user }, flash }) { label="nama lengkap" />
-
+ {/*
handleKeyDown(e)} label="nama panggilan" /> -
+
*/} +62
} diff --git a/resources/js/Pages/DepositHistory/Form.jsx b/resources/js/Pages/DepositHistory/Form.jsx index 8ed092e..ef36ac2 100644 --- a/resources/js/Pages/DepositHistory/Form.jsx +++ b/resources/js/Pages/DepositHistory/Form.jsx @@ -157,7 +157,7 @@ export default function Form(props) { > diff --git a/resources/js/Pages/Paylater/Form.jsx b/resources/js/Pages/Paylater/Form.jsx index d4b1fe7..4affec4 100644 --- a/resources/js/Pages/Paylater/Form.jsx +++ b/resources/js/Pages/Paylater/Form.jsx @@ -186,7 +186,7 @@ export default function Form(props) { > diff --git a/resources/views/app.blade.php b/resources/views/app.blade.php index 0f981d5..43b6a87 100644 --- a/resources/views/app.blade.php +++ b/resources/views/app.blade.php @@ -2,7 +2,7 @@ - + diff --git a/resources/views/emails/customers/verification.blade.php b/resources/views/emails/customers/verification.blade.php index 215f9ab..b1c5e9d 100644 --- a/resources/views/emails/customers/verification.blade.php +++ b/resources/views/emails/customers/verification.blade.php @@ -1,5 +1,5 @@ -# Hai, {{ $customer->name }} +# Hai, {{ $customer->fullname }} ## Welcome to {{ config('app.name', 'Voucher WBB') }} Untuk mulai menggunakan layanan kami, harap aktifkan akun Anda dengan mengklik tombol aktivasi ini di bawah. diff --git a/routes/api.php b/routes/api.php index f3de73d..134e72f 100644 --- a/routes/api.php +++ b/routes/api.php @@ -7,7 +7,9 @@ use App\Http\Controllers\Api\LocationController; use App\Http\Controllers\Api\LocationProfileController; use App\Http\Controllers\Api\NotificationController; use App\Http\Controllers\Api\RoleController; +use App\Http\Controllers\Customer\CartController; use App\Http\Controllers\Customer\DepositController; +use App\Http\Middleware\CustomerApi; use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; @@ -37,3 +39,8 @@ Route::get('/notifications/{notif?}', [NotificationController::class, 'update']) // midtrans Route::post('mindtrans/notification', [DepositController::class, 'mindtrans_notification'])->name('api.midtrans.notification'); Route::post('mindtrans/{deposit}/payment', [DepositController::class, 'midtrans_payment'])->name('api.midtrans.payment'); + +// cart customer +Route::middleware([CustomerApi::class])->group(function () { + Route::post('cart/{profile}', [CartController::class, 'store'])->name('api.cart.store'); +}); diff --git a/routes/web.php b/routes/web.php index fb09722..316f8c1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -30,16 +30,11 @@ Route::middleware(['http_secure_aware', 'guard_should_customer', 'inertia.custom Route::get('/banner/{banner}', [HomeController::class, 'banner'])->name('home.banner'); - Route::middleware('auth:customer')->group(function () { + Route::middleware(['auth:customer', 'customer.is_complate_profile'])->group(function () { // location to favorite Route::post('/locations/{location}/add-favorite', [HomeController::class, 'addFavorite'])->name('customer.location.favorite'); Route::get('/favorites', [HomeController::class, 'favorite'])->name('home.favorite'); - // profile - Route::get('profile', [ProfileController::class, 'index'])->name('customer.profile.index'); - Route::get('profile/update', [ProfileController::class, 'show'])->name('customer.profile.show'); - Route::post('profile/update', [ProfileController::class, 'update']); - // verification Route::get('profile/verification', [VerificationController::class, 'index'])->name('customer.verification'); Route::post('profile/verification', [VerificationController::class, 'update']); @@ -87,6 +82,13 @@ Route::middleware(['http_secure_aware', 'guard_should_customer', 'inertia.custom Route::get('cash-deposit-locations', [DepositLocationController::class, 'index'])->name('customer.deposit-location.index'); }); + Route::middleware('auth:customer')->group(function () { + // profile + Route::get('profile', [ProfileController::class, 'index'])->name('customer.profile.index'); + Route::get('profile/update', [ProfileController::class, 'show'])->name('customer.profile.show'); + Route::post('profile/update', [ProfileController::class, 'update']); + }); + Route::middleware('guest:customer')->group(function () { // login Route::get('/login', [AuthController::class, 'login'])->name('customer.login');