diff --git a/.env.example b/.env.example index 1d88053..7ccfa9d 100644 --- a/.env.example +++ b/.env.example @@ -8,7 +8,12 @@ LOG_CHANNEL=stack LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug -DB_CONNECTION=sqlite +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=voucher +DB_USERNAME=root +DB_PASSWORD= BROADCAST_DRIVER=log CACHE_DRIVER=file diff --git a/TODO.md b/TODO.md index ae7fbbe..4640904 100644 --- a/TODO.md +++ b/TODO.md @@ -1,48 +1 @@ # TODO - -### Admin - -- [x] CRUD Info -- [x] CRUD Banner -- [x] CRUD Rekening / Account -- [x] CRUD Customer -- [x] CRUD Lokasi -- [x] CRUD Voucher -- [x] Import Voucher -- [x] Setting Web (enable affilate, amount bonus affilate) -- [x] Setting Level Customer (view levels, edit name of level,minimal saldo, max amount saldo, max hutang) -- [x] Deposit Menu (view daftar histori deposit) -- [x] Manual Approve Deposit -- [x] List Customer Verification -- [x] Manual Approve Verification -> mendapatkan limit hutang -- [x] Setting Bonus Coin (memasukan amount bonus coin yang didapat dengan level dan harga voucher) - bonus coin -- [x] Voucher Sales (index: customer, total, jumlah voucher, detail: customer, list voucher, payment) -- [x] Dashboard (gafik hasil penjualan : disorting tanggal, lokasi dan customer) -- [x] Notification ([x]manual deposit, [x]deposit success, [x]stock voucher, [x]sale) -- [x] Voucher - harga per level , fixing detail transaksi -- [x] Voucher - harga coin -- [ ] View Customer Coin History - -### Add - -- hutang (paylater) adalah limit tiap customer jika deposit kurang dalam pembayaran voucher , setiap limit yang digunakan akan di potong / di lunasi ketika melakukan topup deposit -- tukar coin adalah dengan menambahkan harga coin di voucher dan menambahkan 1 fitur di customer untuk explorer voucher yang memiliki harga coin, disimpan menjadi sale biasa dengan cara 1 kali penukaran adalah 1 voucher - -### Customer - -- [x] Tampilan Depan Customer (banner, info, voucher, saldo, coin) - mobile page -- [x] Register Customer (wajib data lengkap) -- [x] Register Customer Gmail -- [x] Login Customer -- [x] Login Customer Gmail -- [x] Customer Edit Profile -- [x] Customer Deposit Manual -- [x] Customer Deposit Payment Gateway -- [x] Customer Purchase Voucher -- [x] Customer Share Buyed Voucher, via WA dll -- [x] Register Refferal -- [x] Customer View Coin History -- [x] Verified Akun -- [x] Paylater: index paylater, payment cart, deposite repay -- [x] Notification ([x] purchase success, [x] deposit success) -- [x] Coin Explorer: list voucher, modal voucher to excange diff --git a/app/Http/Controllers/Customer/AuthController.php b/app/Http/Controllers/Customer/AuthController.php index bab86ec..3a6d4df 100644 --- a/app/Http/Controllers/Customer/AuthController.php +++ b/app/Http/Controllers/Customer/AuthController.php @@ -73,7 +73,7 @@ class AuthController extends Controller 'fullname' => $user->name, 'name' => $user->nickname, '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), ]); @@ -98,7 +98,7 @@ class AuthController extends Controller 'fullname' => 'required|string', 'name' => 'required|string', 'address' => 'required|string', - 'phone' => 'required|numeric', + 'phone' => 'required|numeric|regex:/^([0-9\s\-\+\(\)]*)$/|min:9|max:16', 'username' => 'required|string|min:5|alpha_dash|unique:customers,username', 'password' => 'required|string|min:8|confirmed', 'referral_code' => 'nullable|exists:customers,referral_code', @@ -123,13 +123,13 @@ class AuthController extends Controller $affilateEnabled = Setting::getByKey('AFFILATE_ENABLED'); if ($affilateEnabled == 1) { - $bonusCoin = Setting::getByKey('AFFILATE_COIN_AMOUNT'); - $coin = $refferal->coins()->create([ - 'debit' => $bonusCoin, - 'description' => 'Bonus Refferal #'.Str::random(5), + $bonuspoin = Setting::getByKey('AFFILATE_poin_AMOUNT'); + $poin = $refferal->poins()->create([ + 'debit' => $bonuspoin, + 'description' => 'Bonus Refferal #' . Str::random(5), ]); - $coin->update_customer_balance(); + $poin->update_customer_balance(); } } @@ -143,7 +143,7 @@ class AuthController extends Controller public function destroy() { session()->remove('carts'); - + Auth::logout(); return redirect()->route('customer.login') diff --git a/app/Http/Controllers/Customer/CartController.php b/app/Http/Controllers/Customer/CartController.php index 51a4e61..72eceb0 100644 --- a/app/Http/Controllers/Customer/CartController.php +++ b/app/Http/Controllers/Customer/CartController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers\Customer; use App\Http\Controllers\Controller; -use App\Models\CoinReward; +use App\Models\PoinReward; use App\Models\Customer; use App\Models\DepositHistory; use App\Models\Sale; @@ -17,7 +17,7 @@ class CartController extends Controller /** * show list of item in cart * has payed button - * show payment method -> deposit, coin, paylater + * show payment method -> deposit, poin, paylater */ public function index() { @@ -159,20 +159,20 @@ class CartController extends Controller } $sale->create_notification(); - $bonus = CoinReward::where('customer_level_id', $customer->customer_level_id) + $bonus = PoinReward::where('customer_level_id', $customer->customer_level_id) ->where('amount_buy', '<=', $total) - ->orderBy('bonus_coin', 'desc')->first(); + ->orderBy('bonus_poin', 'desc')->first(); if ($bonus != null) { - $coin = $customer->coins()->create([ - 'debit' => $bonus->bonus_coin, - 'description' => 'Bonus Pembelian #'.$sale->code, + $poin = $customer->poins()->create([ + 'debit' => $bonus->bonus_poin, + 'description' => 'Bonus Pembelian #' . $sale->code, ]); - $coin->update_customer_balance(); + $poin->update_customer_balance(); } - $description = 'Pembayaran #'.$sale->code; + $description = 'Pembayaran #' . $sale->code; if ($customer->deposit_balance < $total) { if ($customer->deposit_balance > 0) { diff --git a/app/Http/Controllers/Customer/CoinController.php b/app/Http/Controllers/Customer/CoinController.php deleted file mode 100644 index 3e1861b..0000000 --- a/app/Http/Controllers/Customer/CoinController.php +++ /dev/null @@ -1,26 +0,0 @@ -id()) - ->orderBy('updated_at', 'desc'); - - return inertia('Coin/Index', [ - 'coins' => $coins->paginate(20), - ]); - } - - public function show(CoinHistory $coin) - { - return inertia('Coin/Detail', [ - 'coin' => $coin, - ]); - } -} diff --git a/app/Http/Controllers/Customer/PoinController.php b/app/Http/Controllers/Customer/PoinController.php new file mode 100644 index 0000000..060fdff --- /dev/null +++ b/app/Http/Controllers/Customer/PoinController.php @@ -0,0 +1,26 @@ +id()) + ->orderBy('updated_at', 'desc'); + + return inertia('Poin/Index', [ + 'poins' => $poins->paginate(20), + ]); + } + + public function show(poinHistory $poin) + { + return inertia('Poin/Detail', [ + 'poin' => $poin, + ]); + } +} diff --git a/app/Http/Controllers/Customer/CoinExchangeController.php b/app/Http/Controllers/Customer/PoinExchangeController.php similarity index 76% rename from app/Http/Controllers/Customer/CoinExchangeController.php rename to app/Http/Controllers/Customer/PoinExchangeController.php index 9d3e581..7603384 100644 --- a/app/Http/Controllers/Customer/CoinExchangeController.php +++ b/app/Http/Controllers/Customer/PoinExchangeController.php @@ -10,15 +10,15 @@ use App\Models\Voucher; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class CoinExchangeController extends Controller +class PoinExchangeController extends Controller { public function index(Request $request) { $locations = Location::get(); $vouchers = Voucher::with(['location']) ->where(function ($q) { - $q->where('price_coin', '!=', 0) - ->where('price_coin', '!=', null); + $q->where('price_poin', '!=', 0) + ->where('price_poin', '!=', null); }) ->where('is_sold', Voucher::UNSOLD) ->groupBy('batch_id') @@ -28,7 +28,7 @@ class CoinExchangeController extends Controller $vouchers->where('location_id', $request->location_id); } - return inertia('Coin/Exchange', [ + return inertia('Poin/Exchange', [ 'locations' => $locations, 'vouchers' => tap($vouchers->paginate(10))->setHidden(['username', 'password']), '_location_id' => $request->location_id ?? '', @@ -39,30 +39,30 @@ class CoinExchangeController extends Controller { $batchCount = $voucher->count_unsold(); if ($batchCount < 1) { - return redirect()->route('customer.coin.exchange') + return redirect()->route('customer.poin.exchange') ->with('message', ['type' => 'error', 'message' => 'transaksi gagal, voucher sedang tidak tersedia']); } $customer = Customer::find(auth()->id()); - if ($customer->coin_balance < $voucher->price_coin) { - return redirect()->route('customer.coin.exchange') + if ($customer->poin_balance < $voucher->price_poin) { + return redirect()->route('customer.poin.exchange') ->with('message', ['type' => 'error', 'message' => 'koin kamu tidak cukup untuk ditukar voucher ini']); } DB::beginTransaction(); $sale = $customer->sales()->create([ - 'code' => 'Tukar Coin '.str()->upper(str()->random(5)), + 'code' => 'Tukar poin ' . str()->upper(str()->random(5)), 'date_time' => now(), 'amount' => 0, - 'payed_with' => Sale::PAYED_WITH_COIN, + 'payed_with' => Sale::PAYED_WITH_poin, ]); $voucher = $voucher->shuffle_unsold(); $sale->items()->create([ 'entity_type' => $voucher::class, 'entity_id' => $voucher->id, - 'price' => $voucher->price_coin, + 'price' => $voucher->price_poin, 'quantity' => 1, 'additional_info_json' => json_encode([ 'id' => $voucher->id, @@ -76,12 +76,12 @@ class CoinExchangeController extends Controller $sale->create_notification(); - $coin = $customer->coins()->create([ - 'credit' => $voucher->price_coin, + $poin = $customer->poins()->create([ + 'credit' => $voucher->price_poin, 'description' => $sale->code, ]); - $coin->update_customer_balance(); + $poin->update_customer_balance(); DB::commit(); return redirect()->route('transactions.show', $sale) diff --git a/app/Http/Controllers/GeneralController.php b/app/Http/Controllers/GeneralController.php index adb97db..e83cc6a 100644 --- a/app/Http/Controllers/GeneralController.php +++ b/app/Http/Controllers/GeneralController.php @@ -24,9 +24,9 @@ class GeneralController extends Controller $month = now()->locale('id')->translatedFormat('F'); $startOfMonth = now()->startOfMonth()->format('m/d/Y'); $endOfMonth = now()->endOfMonth()->format('m/d/Y'); - $total_voucher_sale_this_month = SaleItem::whereBetween(DB::raw("strftime('%m/%d/%Y', created_at)"), [$startOfMonth, $endOfMonth]) + $total_voucher_sale_this_month = SaleItem::whereBetween("created_at", [$startOfMonth, $endOfMonth]) ->sum('price'); - $count_voucher_sale_this_month = SaleItem::whereBetween(DB::raw("strftime('%m/%d/%Y', created_at)"), [$startOfMonth, $endOfMonth]) + $count_voucher_sale_this_month = SaleItem::whereBetween("created_at", [$startOfMonth, $endOfMonth]) ->sum('quantity'); $total_voucher_sale_this_day = SaleItem::whereDate('created_at', now()->format('Y-m-d')) ->sum('price'); @@ -61,10 +61,10 @@ class GeneralController extends Controller if ($request->end_date != '') { $endDate = Carbon::parse($request->end_date)->format('m/d/Y'); } - $charts = Sale::selectRaw("SUM(amount) as sale_total, strftime('%d/%m/%Y', date_time) as date") - ->whereBetween(DB::raw("strftime('%m/%d/%Y', date_time)"), [$startDate, $endDate]) + $charts = Sale::selectRaw('SUM(amount) as sale_total, date_time') + ->whereBetween('date_time', [$startDate, $endDate]) ->orderBy('date_time', 'asc') - ->groupBy(DB::raw("strftime('%m/%d/%Y', date_time)")); + ->groupBy('date_time'); // filter lokasi if ($request->location_id != '') { diff --git a/app/Http/Controllers/CoinRewardController.php b/app/Http/Controllers/PoinRewardController.php similarity index 72% rename from app/Http/Controllers/CoinRewardController.php rename to app/Http/Controllers/PoinRewardController.php index f9c3248..27ab17a 100644 --- a/app/Http/Controllers/CoinRewardController.php +++ b/app/Http/Controllers/PoinRewardController.php @@ -2,18 +2,18 @@ namespace App\Http\Controllers; -use App\Models\CoinReward; +use App\Models\PoinReward; use App\Models\CustomerLevel; use Illuminate\Http\Request; -class CoinRewardController extends Controller +class PoinRewardController extends Controller { public function index() { - $query = CoinReward::with(['level']) + $query = PoinReward::with(['level']) ->orderBy('updated_at', 'desc'); - return inertia('CoinReward/Index', [ + return inertia('PoinReward/Index', [ 'query' => $query->paginate(), 'levels' => CustomerLevel::all(), ]); @@ -23,37 +23,37 @@ class CoinRewardController extends Controller { $request->validate([ 'amount_buy' => 'required|numeric', - 'bonus_coin' => 'required|numeric', + 'bonus_poin' => 'required|numeric', 'customer_level_id' => 'required|exists:customer_levels,id', ]); - CoinReward::create([ + PoinReward::create([ 'amount_buy' => $request->amount_buy, - 'bonus_coin' => $request->bonus_coin, + 'bonus_poin' => $request->bonus_poin, 'customer_level_id' => $request->customer_level_id, ]); session()->flash('message', ['type' => 'success', 'message' => 'Item has beed saved']); } - public function update(Request $request, CoinReward $reward) + public function update(Request $request, PoinReward $reward) { $request->validate([ 'amount_buy' => 'required|numeric', - 'bonus_coin' => 'required|numeric', + 'bonus_poin' => 'required|numeric', 'customer_level_id' => 'required|exists:customer_levels,id', ]); $reward->update([ 'amount_buy' => $request->amount_buy, - 'bonus_coin' => $request->bonus_coin, + 'bonus_poin' => $request->bonus_poin, 'customer_level_id' => $request->customer_level_id, ]); session()->flash('message', ['type' => 'success', 'message' => 'Item has beed updated']); } - public function destroy(CoinReward $reward) + public function destroy(PoinReward $reward) { $reward->delete(); diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php index 4b89073..4371d5a 100644 --- a/app/Http/Controllers/SettingController.php +++ b/app/Http/Controllers/SettingController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Models\Setting; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; class SettingController extends Controller @@ -21,9 +22,10 @@ class SettingController extends Controller public function update(Request $request) { $request->validate([ + 'OPEN_WEBSITE_NAME' => 'required|string', 'VOUCHER_STOCK_NOTIFICATION' => 'required|numeric', 'AFFILATE_ENABLED' => 'required|in:0,1', - 'AFFILATE_COIN_AMOUNT' => 'required|numeric', + 'AFFILATE_POIN_AMOUNT' => 'required|numeric', 'MIDTRANS_SERVER_KEY' => 'required|string', 'MIDTRANS_CLIENT_KEY' => 'required|string', 'MIDTRANS_MERCHANT_ID' => 'required|string', @@ -42,6 +44,8 @@ class SettingController extends Controller Setting::where('key', 'MIDTRANS_LOGO')->update(['value' => $file->hashName('uploads')]); } + Cache::flush(); + DB::commit(); session()->flash('message', ['type' => 'success', 'message' => 'Setting has beed saved']); diff --git a/app/Http/Controllers/VoucherController.php b/app/Http/Controllers/VoucherController.php index 90d3142..1150822 100644 --- a/app/Http/Controllers/VoucherController.php +++ b/app/Http/Controllers/VoucherController.php @@ -47,7 +47,7 @@ class VoucherController extends Controller 'password' => 'required|string', 'discount' => 'required|numeric', 'display_price' => 'required|numeric', - 'price_coin' => 'nullable|numeric', + 'price_poin' => 'nullable|numeric', 'quota' => 'required|string', 'profile' => 'required|string', 'comment' => 'required|string', @@ -67,7 +67,7 @@ class VoucherController extends Controller 'password' => $request->password, 'discount' => $request->discount, 'display_price' => $request->display_price, - 'price_coin' => $request->price_coin, + 'price_poin' => $request->price_poin, 'quota' => $request->quota, 'profile' => $request->profile, 'comment' => $request->comment, @@ -110,7 +110,7 @@ class VoucherController extends Controller 'password' => 'required|string', 'discount' => 'required|numeric', 'display_price' => 'required|numeric', - 'price_coin' => 'nullable|numeric', + 'price_poin' => 'nullable|numeric', 'quota' => 'required|string', 'profile' => 'required|string', 'comment' => 'required|string', @@ -135,7 +135,7 @@ class VoucherController extends Controller 'location_id' => $request->location_id, 'discount' => $request->discount, 'display_price' => $request->display_price, - 'price_coin' => $request->price_coin, + 'price_poin' => $request->price_poin, 'quota' => $request->quota, 'profile' => $request->profile, 'comment' => $request->comment, @@ -184,7 +184,7 @@ class VoucherController extends Controller 'location_id' => 'required|exists:locations,id', 'discount' => 'required|numeric', 'display_price' => 'required|numeric', - 'price_coin' => 'nullable|numeric', + 'price_poin' => 'nullable|numeric', 'expired' => 'required|numeric', 'expired_unit' => 'required|string', 'prices' => 'nullable|array', @@ -203,7 +203,7 @@ class VoucherController extends Controller 'password' => $voucher['password'], 'discount' => $request->discount, 'display_price' => $request->display_price, - 'price_coin' => $request->price_coin, + 'price_poin' => $request->price_poin, 'quota' => $voucher['quota'], 'profile' => $voucher['profile'], 'comment' => $voucher['comment'], diff --git a/app/Http/Middleware/HandleInertiaCustomerRequests.php b/app/Http/Middleware/HandleInertiaCustomerRequests.php index 9a32b4e..690e3d4 100644 --- a/app/Http/Middleware/HandleInertiaCustomerRequests.php +++ b/app/Http/Middleware/HandleInertiaCustomerRequests.php @@ -3,6 +3,7 @@ namespace App\Http\Middleware; use App\Models\Notification; +use App\Models\Setting; use Illuminate\Http\Request; use Inertia\Middleware; @@ -45,6 +46,7 @@ class HandleInertiaCustomerRequests extends Middleware return array_merge(parent::share($request), [ 'app_name' => env('APP_NAME', 'App Name'), + 'setting' => Setting::getSettings(), 'auth' => [ 'user' => auth('customer')->user()?->load(['level', 'paylater']), ], @@ -53,6 +55,7 @@ class HandleInertiaCustomerRequests extends Middleware ], 'notification_count' => $notification_count, 'cart_count' => $cart_count, + ]); } } diff --git a/app/Models/CoinHistory.php b/app/Models/CoinHistory.php index 3578029..1c48480 100644 --- a/app/Models/CoinHistory.php +++ b/app/Models/CoinHistory.php @@ -5,7 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Support\Carbon; -class CoinHistory extends Model +class poinHistory extends Model { protected $fillable = [ 'debit', @@ -55,6 +55,6 @@ class CoinHistory extends Model public function update_customer_balance() { $customer = Customer::find($this->customer_id); - $customer->update(['coin_balance' => $customer->coin_balance + $this->debit - $this->credit]); + $customer->update(['poin_balance' => $customer->poin_balance + $this->debit - $this->credit]); } } diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 2ac9e6a..ff166a0 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -32,7 +32,7 @@ class Customer extends Authenticatable 'referral_code', 'google_id', 'deposit_balance', - 'coin_balance', + 'poin_balance', 'identity_verified', 'identity_image', 'customer_level_id', @@ -48,7 +48,7 @@ class Customer extends Authenticatable 'image_url', 'identity_image_url', 'display_deposit', - 'display_coin', + 'display_poin', 'display_phone', 'paylater_limit', 'is_allow_paylater', @@ -126,7 +126,7 @@ class Customer extends Authenticatable return ' - '; } - return '+62'.$this->phone; + return '+62' . $this->phone; }); } @@ -137,10 +137,10 @@ class Customer extends Authenticatable }); } - public function displayCoin(): Attribute + public function displayPoin(): Attribute { return Attribute::make(get: function () { - return number_format($this->coin_balance, is_float($this->coin_balance) ? 2 : 0, ',', '.'); + return number_format($this->poin_balance, is_float($this->poin_balance) ? 2 : 0, ',', '.'); }); } @@ -188,9 +188,9 @@ class Customer extends Authenticatable return $this->hasMany(DepositHistory::class); } - public function coins() + public function poins() { - return $this->hasMany(CoinHistory::class); + return $this->hasMany(PoinHistory::class); } public function paylater() @@ -234,7 +234,7 @@ class Customer extends Authenticatable $paylater = $this->paylaterHistories()->create([ 'credit' => $cut, - 'description' => $deposit->description.' (Pengembalian)', + 'description' => $deposit->description . ' (Pengembalian)', ]); $paylater->update_customer_paylater(); diff --git a/app/Models/PoinHistory.php b/app/Models/PoinHistory.php new file mode 100644 index 0000000..50b43fe --- /dev/null +++ b/app/Models/PoinHistory.php @@ -0,0 +1,60 @@ +created_at)->locale('id')->translatedFormat('d F Y'); + }); + } + + public function formatCreatedAt(): Attribute + { + return Attribute::make(get: function () { + return Carbon::parse($this->created_at)->locale('id')->translatedFormat('d F Y H:i:s'); + }); + } + + public function amount(): Attribute + { + return Attribute::make(get: function () { + if ($this->credit == 0) { + return number_format($this->debit, is_float($this->debit) ? 2 : 0, ',', '.'); + } + + return number_format($this->credit, is_float($this->credit) ? 2 : 0, ',', '.'); + }); + } + + public function customer() + { + return $this->belongsTo(Customer::class); + } + + public function update_customer_balance() + { + $customer = Customer::find($this->customer_id); + $customer->update(['poin_balance' => $customer->poin_balance + $this->debit - $this->credit]); + } +} diff --git a/app/Models/CoinReward.php b/app/Models/PoinReward.php similarity index 81% rename from app/Models/CoinReward.php rename to app/Models/PoinReward.php index 3f6f85d..aba8392 100644 --- a/app/Models/CoinReward.php +++ b/app/Models/PoinReward.php @@ -2,11 +2,11 @@ namespace App\Models; -class CoinReward extends Model +class PoinReward extends Model { protected $fillable = [ 'amount_buy', - 'bonus_coin', + 'bonus_poin', 'customer_level_id', ]; diff --git a/app/Models/Sale.php b/app/Models/Sale.php index 8017575..5f47a52 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -15,7 +15,7 @@ class Sale extends Model const PAYED_WITH_PAYLATER = 'paylater'; - const PAYED_WITH_COIN = 'coin'; + const PAYED_WITH_poin = 'poin'; protected $fillable = [ 'code', @@ -63,21 +63,21 @@ class Sale extends Model public function displayAmount(): Attribute { return Attribute::make(get: function () { - return 'Rp'.number_format($this->amount, is_float($this->amount) ? 2 : 0, ',', '.'); + return 'Rp' . number_format($this->amount, is_float($this->amount) ? 2 : 0, ',', '.'); }); } public function create_notification() { - if ($this->payed_with == self::PAYED_WITH_COIN) { + if ($this->payed_with == self::PAYED_WITH_poin) { Notification::create([ 'entity_type' => User::class, - 'description' => $this->customer->fullname.' melakukan penukaran '.$this->items()->count().' voucher sebesar '.$this->items->value('price').' coin', + 'description' => $this->customer->fullname . ' melakukan penukaran ' . $this->items()->count() . ' voucher sebesar ' . $this->items->value('price') . ' poin', ]); Notification::create([ 'entity_id' => auth()->id(), - 'description' => 'Transaksi '.$this->code.' berhasil', + 'description' => 'Transaksi ' . $this->code . ' berhasil', ]); return; @@ -85,12 +85,12 @@ class Sale extends Model Notification::create([ 'entity_type' => User::class, - 'description' => $this->customer->fullname.' melakukan pembelian '.$this->items()->count().' voucher sebesar '.$this->display_amount, + 'description' => $this->customer->fullname . ' melakukan pembelian ' . $this->items()->count() . ' voucher sebesar ' . $this->display_amount, ]); Notification::create([ 'entity_id' => auth()->id(), - 'description' => 'Transaksi pembelian anda #'.$this->code.' sebesar '.$this->display_amount.' berhasil', + 'description' => 'Transaksi pembelian anda #' . $this->code . ' sebesar ' . $this->display_amount . ' berhasil', ]); } } diff --git a/app/Models/Setting.php b/app/Models/Setting.php index ac494cf..e7a021a 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Concerns\HasUlids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Facades\Cache; class Setting extends Model { @@ -43,4 +44,18 @@ class Setting extends Model { return Setting::where('key', $key)->value('value'); } + + public static function getSettings() + { + $data = Cache::get('settings'); + if ($data == null) { + $settings = Setting::where('key', 'like', 'OPEN%')->get(); + foreach ($settings as $setting) { + $data[$setting->key] = $setting->value; + } + Cache::put('settings', $data, now()->addDay()); + } + + return $data; + } } diff --git a/app/Models/Voucher.php b/app/Models/Voucher.php index 6f5202b..20d4ad2 100644 --- a/app/Models/Voucher.php +++ b/app/Models/Voucher.php @@ -17,7 +17,7 @@ class Voucher extends Model 'location_id', 'username', 'password', - 'price_coin', // harga voucher untuk ditukarkan dengan coin + 'price_poin', // harga voucher untuk ditukarkan dengan poin 'price', // harga jual 'discount', 'display_price', //yang di input user @@ -63,14 +63,14 @@ class Voucher extends Model public function displayQuota(): Attribute { return Attribute::make(get: function () { - return round($this->quota / (1024 * 1024 * 1024), 2).' GB'; + return round($this->quota / (1024 * 1024 * 1024), 2) . ' GB'; }); } public function displayExpired(): Attribute { return Attribute::make(get: function () { - return $this->expired.' '.$this->expired_unit; + return $this->expired . ' ' . $this->expired_unit; }); } @@ -146,7 +146,7 @@ class Voucher extends Model if ($count <= $treshold) { Notification::create([ 'entity_type' => User::class, - 'description' => 'stok voucher '.$this->location->name.' ( '.$this->profile.' ) '.'tersisa : '.$count, + 'description' => 'stok voucher ' . $this->location->name . ' ( ' . $this->profile . ' ) ' . 'tersisa : ' . $count, ]); } } diff --git a/app/Services/GeneralService.php b/app/Services/GeneralService.php index 9e2a209..c176a1f 100644 --- a/app/Services/GeneralService.php +++ b/app/Services/GeneralService.php @@ -70,7 +70,7 @@ class GeneralService public static function getCartEnablePayment() { // deposit - // coin + // poin // paylater } } diff --git a/config/database.php b/config/database.php index 137ad18..84b10bb 100644 --- a/config/database.php +++ b/config/database.php @@ -61,6 +61,15 @@ return [ 'options' => extension_loaded('pdo_mysql') ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), ]) : [], + 'modes' => [ + // 'ONLY_FULL_GROUP_BY', // Disable this to allow grouping by one column + 'STRICT_TRANS_TABLES', + 'NO_ZERO_IN_DATE', + 'NO_ZERO_DATE', + 'ERROR_FOR_DIVISION_BY_ZERO', + 'NO_AUTO_CREATE_USER', + 'NO_ENGINE_SUBSTITUTION', + ], ], 'pgsql' => [ diff --git a/database/migrations/2023_05_24_130522_create_vouchers_table.php b/database/migrations/2023_05_24_130522_create_vouchers_table.php index 6a668e5..0b840be 100644 --- a/database/migrations/2023_05_24_130522_create_vouchers_table.php +++ b/database/migrations/2023_05_24_130522_create_vouchers_table.php @@ -19,7 +19,7 @@ return new class extends Migration $table->ulid('location_id')->nullable(); $table->string('username')->nullable(); $table->string('password')->nullable(); - $table->decimal('price_coin', 20, 2)->default(0); + $table->decimal('price_poin', 20, 2)->default(0); $table->decimal('price', 20, 2)->default(0); $table->decimal('discount', 20, 0)->default(0); $table->decimal('display_price', 20, 2)->default(0); diff --git a/database/migrations/2023_05_24_130552_create_customers_table.php b/database/migrations/2023_05_24_130552_create_customers_table.php index 3f916af..f1e14d1 100644 --- a/database/migrations/2023_05_24_130552_create_customers_table.php +++ b/database/migrations/2023_05_24_130552_create_customers_table.php @@ -25,7 +25,7 @@ return new class extends Migration $table->string('referral_code')->nullable(); $table->string('google_id')->nullable(); $table->decimal('deposit_balance', 20, 2)->default(0); - $table->decimal('coin_balance', 20, 2)->default(0); + $table->decimal('poin_balance', 20, 2)->default(0); $table->smallInteger('identity_verified')->default(0); $table->string('identity_image')->nullable(); $table->ulid('customer_level_id')->nullable(); diff --git a/database/migrations/2023_05_24_130650_create_coin_histories_table.php b/database/migrations/2023_06_16_045835_create_poin_histories_table.php similarity index 89% rename from database/migrations/2023_05_24_130650_create_coin_histories_table.php rename to database/migrations/2023_06_16_045835_create_poin_histories_table.php index ed10528..9689342 100644 --- a/database/migrations/2023_05_24_130650_create_coin_histories_table.php +++ b/database/migrations/2023_06_16_045835_create_poin_histories_table.php @@ -11,7 +11,7 @@ return new class extends Migration */ public function up(): void { - Schema::create('coin_histories', function (Blueprint $table) { + Schema::create('poin_histories', function (Blueprint $table) { $table->ulid('id')->primary(); $table->decimal('debit', 20, 2)->default(0); @@ -34,6 +34,6 @@ return new class extends Migration */ public function down(): void { - Schema::dropIfExists('coin_histories'); + Schema::dropIfExists('poin_histories'); } }; diff --git a/database/migrations/2023_05_24_145103_create_coin_rewards_table.php b/database/migrations/2023_06_16_045840_create_poin_rewards_table.php similarity index 81% rename from database/migrations/2023_05_24_145103_create_coin_rewards_table.php rename to database/migrations/2023_06_16_045840_create_poin_rewards_table.php index 8656cbd..eee2243 100644 --- a/database/migrations/2023_05_24_145103_create_coin_rewards_table.php +++ b/database/migrations/2023_06_16_045840_create_poin_rewards_table.php @@ -11,11 +11,11 @@ return new class extends Migration */ public function up(): void { - Schema::create('coin_rewards', function (Blueprint $table) { + Schema::create('poin_rewards', function (Blueprint $table) { $table->ulid('id')->primary(); $table->decimal('amount_buy', 20, 2)->default(0); - $table->decimal('bonus_coin', 20, 2)->default(0); + $table->decimal('bonus_poin', 20, 2)->default(0); $table->ulid('customer_level_id')->nullable(); $table->timestamps(); @@ -31,6 +31,6 @@ return new class extends Migration */ public function down(): void { - Schema::dropIfExists('coin_rewards'); + Schema::dropIfExists('poin_rewards'); } }; diff --git a/database/seeders/DummySeeder.php b/database/seeders/DummySeeder.php index 016161b..7b519d7 100644 --- a/database/seeders/DummySeeder.php +++ b/database/seeders/DummySeeder.php @@ -41,8 +41,8 @@ class DummySeeder extends Seeder $images = ['1.webp', '2.webp', '3.webp']; foreach ($images as $index => $image) { Banner::create([ - 'title' => 'Banner '.$index, - 'image' => 'sample/'.$image, + 'title' => 'Banner ' . $index, + 'image' => 'sample/' . $image, 'description' => '