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)} /> -