bug fix import voucher update

dev
Aji Kamaludin 1 year ago
parent f5519657db
commit 4138f22f0d
No known key found for this signature in database
GPG Key ID: 19058F67F0083AD3

@ -4,14 +4,14 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Notification;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
public function update(Notification $notif)
{
if ($notif->id == null) {
(new Notification())->mark_all_as_read();
(new Notification)->mark_all_as_read();
return;
}
$notif->mark_as_read();

@ -15,7 +15,7 @@ class CoinRewardController extends Controller
return inertia('CoinReward/Index', [
'query' => $query->paginate(),
'levels' => CustomerLevel::all()
'levels' => CustomerLevel::all(),
]);
}

@ -97,7 +97,7 @@ class AuthController extends Controller
'phone' => 'required|numeric',
'username' => 'required|string|min:5|alpha_dash|unique:customers,username',
'password' => 'required|string|min:8|confirmed',
'referral_code' => 'nullable|exists:customers,referral_code'
'referral_code' => 'nullable|exists:customers,referral_code',
]);
DB::beginTransaction();
@ -114,7 +114,7 @@ class AuthController extends Controller
$refferal = Customer::where('referral_code', $request->referral_code)->first();
$refferal->customerRefferals()->create([
'refferal_id' => $customer->id,
'customer_code' => $refferal->referral_code
'customer_code' => $refferal->referral_code,
]);
$affilateEnabled = Setting::getByKey('AFFILATE_ENABLED');

@ -3,7 +3,6 @@
namespace App\Http\Controllers\Customer;
use App\Http\Controllers\Controller;
use App\Models\CoinHistory;
use App\Models\CoinReward;
use App\Models\Customer;
use App\Models\DepositHistory;
@ -19,7 +18,6 @@ class CartController extends Controller
* show list of item in cart
* has payed button
* show payment method -> deposit, coin, paylater
*
*/
public function index()
{
@ -41,7 +39,6 @@ class CartController extends Controller
/**
* handle cart add, remove or sub
*
*/
public function store(Request $request, Voucher $voucher)
{
@ -113,10 +110,11 @@ class CartController extends Controller
$batchCount = $item['voucher']->count_unsold();
if ($batchCount < $item['quantity']) {
session()->remove('carts');
return redirect()->route('home.index')
->with('message', ['type' => 'error', 'message' => 'transaksi gagal, voucher sedang tidak tersedia']);
}
};
}
$total = $carts->sum(function ($item) {
return $item['quantity'] * $item['voucher']->validate_price;
@ -127,6 +125,7 @@ class CartController extends Controller
$paylater_limit = (int) $customer->paylater_limit;
if (($paylater_limit + $customer->deposit_balance) < $total) {
session()->remove('carts');
return redirect()->route('home.index')
->with('message', ['type' => 'error', 'message' => 'transaksi gagal, pembayaran ditolak']);
}
@ -191,7 +190,7 @@ class CartController extends Controller
$payedWithPaylater = $total - $customer->deposit_balance;
$paylater = $customer->paylaterHistories()->create([
'debit' => $payedWithPaylater,
'description' => $description
'description' => $description,
]);
$paylater->update_customer_paylater();

@ -4,7 +4,6 @@ namespace App\Http\Controllers\Customer;
use App\Http\Controllers\Controller;
use App\Models\CoinHistory;
use Illuminate\Http\Request;
class CoinController extends Controller
{

@ -9,7 +9,6 @@ use App\Models\Sale;
use App\Models\Voucher;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class CoinExchangeController extends Controller
{
@ -68,7 +67,7 @@ class CoinExchangeController extends Controller
'additional_info_json' => json_encode([
'id' => $voucher->id,
'quantity' => 1,
'voucher' => $voucher->load(['location'])
'voucher' => $voucher->load(['location']),
]),
]);

@ -47,7 +47,7 @@ class HomeController extends Controller
Notification::where('entity_id', auth()->id())->where('is_read', Notification::UNREAD)->update(['is_read' => Notification::READ]);
return inertia('Index/Notification', [
'notification' => Notification::where('entity_id', auth()->id())->orderBy('created_at', 'desc')->paginate()
'notification' => Notification::where('entity_id', auth()->id())->orderBy('created_at', 'desc')->paginate(),
]);
}
}

@ -20,7 +20,7 @@ class TransactionController extends Controller
public function show(Sale $sale)
{
return inertia('Trx/Detail', [
'sale' => $sale->load(['items.voucher.location'])
'sale' => $sale->load(['items.voucher.location']),
]);
}
}

@ -59,7 +59,7 @@ class CustomerController extends Controller
{
return inertia('Customer/Form', [
'customer' => $customer->load(['level']),
'levels' => CustomerLevel::all()
'levels' => CustomerLevel::all(),
]);
}
@ -121,7 +121,7 @@ class CustomerController extends Controller
$customer->paylater()->updateOrCreate([
'customer_id' => $customer->id,
], [
'limit' => $request->paylater_limit
'limit' => $request->paylater_limit,
]);
return redirect()->route('customer.index')

@ -3,7 +3,6 @@
namespace App\Http\Controllers;
use App\Models\Notification;
use Illuminate\Http\Request;
class NotificationController extends Controller
{

@ -15,7 +15,7 @@ class VerificationController extends Controller
->orderBy('updated_at', 'desc');
return inertia('Verification/Index', [
'query' => $query->paginate()
'query' => $query->paginate(),
]);
}
@ -28,7 +28,7 @@ class VerificationController extends Controller
return inertia('Verification/Form', [
'customer' => $customer->load(['level']),
'levels' => $levels
'levels' => $levels,
]);
}
@ -43,13 +43,13 @@ class VerificationController extends Controller
$customer->update([
'customer_level_id' => $level->id,
'identity_verified' => Customer::VERIFIED
'identity_verified' => Customer::VERIFIED,
]);
$customer->paylater()->updateOrCreate([
'customer_id' => $customer->id,
], [
'limit' => $request->paylater_limit
'limit' => $request->paylater_limit,
]);
return redirect()->route('customer-verification.index')

@ -33,7 +33,7 @@ class VoucherController extends Controller
public function create()
{
return inertia('Voucher/Form', [
'levels' => CustomerLevel::all()
'levels' => CustomerLevel::all(),
]);
}
@ -55,7 +55,7 @@ class VoucherController extends Controller
'expired_unit' => 'required|string',
'prices' => 'nullable|array',
'prices.*.customer_level_id' => 'required|exists:customer_levels,id',
'prices.*.display_price' => 'required|numeric'
'prices.*.display_price' => 'required|numeric',
]);
DB::beginTransaction();
@ -96,7 +96,7 @@ class VoucherController extends Controller
{
return inertia('Voucher/Form', [
'voucher' => $voucher->load(['prices.level']),
'levels' => CustomerLevel::all()
'levels' => CustomerLevel::all(),
]);
}
@ -118,11 +118,13 @@ class VoucherController extends Controller
'expired_unit' => 'required|string',
'prices' => 'nullable|array',
'prices.*.customer_level_id' => 'required|exists:customer_levels,id',
'prices.*.display_price' => 'required|numeric'
'prices.*.display_price' => 'required|numeric',
]);
DB::beginTransaction();
$voucher->update([
$vouchers = Voucher::where('batch_id', $voucher->batch_id);
$vouchers->update([
'name' => $request->name,
'description' => $request->description,
'location_id' => $request->location_id,
@ -137,6 +139,7 @@ class VoucherController extends Controller
'expired' => $request->expired,
]);
foreach ($vouchers->get() as $voucher) {
$voucher->prices()->delete();
foreach (collect($request->prices) as $price) {
$finalPrice = $price['display_price'];
@ -149,6 +152,7 @@ class VoucherController extends Controller
'display_price' => $price['display_price'],
]);
}
}
DB::commit();
return redirect()->route('voucher.index')
@ -166,7 +170,7 @@ class VoucherController extends Controller
public function form_import()
{
return inertia('Voucher/Import', [
'levels' => CustomerLevel::all()
'levels' => CustomerLevel::all(),
]);
}
@ -182,7 +186,7 @@ class VoucherController extends Controller
'expired_unit' => 'required|string',
'prices' => 'nullable|array',
'prices.*.customer_level_id' => 'required|exists:customer_levels,id',
'prices.*.display_price' => 'required|numeric'
'prices.*.display_price' => 'required|numeric',
]);
$batchId = Str::ulid();

@ -36,7 +36,6 @@ class CoinHistory extends Model
});
}
public function amount(): Attribute
{
return Attribute::make(get: function () {

@ -150,6 +150,7 @@ class Customer extends Authenticatable
if ($this->is_allow_paylater) {
return $this->paylater->limit - $this->paylater->usage;
}
return '';
});
}
@ -167,7 +168,7 @@ class Customer extends Authenticatable
return [
self::VERIFIED => 'Terverifikasi',
self::IN_VERICATION => 'Menunggu Verifikasi',
self::NOT_VERIFIED => 'Tidak Terverifikasi'
self::NOT_VERIFIED => 'Tidak Terverifikasi',
][$this->identity_verified];
});
}
@ -233,13 +234,13 @@ class Customer extends Authenticatable
$paylater = $this->paylaterHistories()->create([
'credit' => $cut,
'description' => $deposit->description . " (Pengembalian)",
'description' => $deposit->description.' (Pengembalian)',
]);
$paylater->update_customer_paylater();
$deposit = $this->deposites()->create([
'credit' => $cut,
'description' => 'Pembayaran Paylater'
'description' => 'Pembayaran Paylater',
]);
$deposit->update_customer_balance();
}

@ -109,9 +109,9 @@ class DepositHistory extends Model
public function create_notification()
{
if ($this->payment_channel == Setting::PAYMENT_MANUAL) {
$status = "";
$status = '';
if ($this->is_valid == self::STATUS_WAIT_APPROVE) {
$status = " (bukti bayar di upload, membutuhkan konfirmasi)";
$status = ' (bukti bayar di upload, membutuhkan konfirmasi)';
}
Notification::create([
'entity_type' => User::class,

@ -8,6 +8,7 @@ use Illuminate\Support\Carbon;
class Notification extends Model
{
const UNREAD = 0;
const READ = 1;
protected $fillable = [
@ -18,7 +19,7 @@ class Notification extends Model
];
protected $appends = [
'format_created_at'
'format_created_at',
];
public function mark_as_read()

@ -30,7 +30,6 @@ class Sale extends Model
'payment_type',
];
protected $appends = [
'format_human_created_at',
'format_created_at',

@ -48,14 +48,14 @@ Username : {$item->voucher->username}
Password : {$item->voucher->password}
";
$string .= "Cuman Rp" . number_format($this->price, is_float($this->price) ? 2 : 0, ',', '.') . " aja, ";
$string .= 'Cuman Rp'.number_format($this->price, is_float($this->price) ? 2 : 0, ',', '.').' aja, ';
if ($item->voucher->discount > 0) {
$string .= "lagi ada discount {$item->voucher->discount}% loh.
";
}
$string .= "dapatkat penawaran voucher lainnya di " . route('home.index');
$string .= 'dapatkat penawaran voucher lainnya di '.route('home.index');
return $string;
});

@ -80,6 +80,7 @@ class Voucher extends Model
if (auth('customer')->check()) {
if ($this->prices()->count() > 0) {
$price = $this->prices()->where('customer_level_id', auth()->user()->customer_level_id)->value('price');
return $price;
}
}
@ -94,6 +95,7 @@ class Voucher extends Model
if (auth('customer')->check()) {
if ($this->prices()->count() > 0) {
$price = $this->prices()->where('customer_level_id', auth()->user()->customer_level_id)->value('display_price');
return $price;
}
}
@ -116,7 +118,7 @@ class Voucher extends Model
{
$voucher = Voucher::where([
['is_sold', '=', self::UNSOLD],
['batch_id', '=', $this->batch_id]
['batch_id', '=', $this->batch_id],
])->first();
return $voucher;
@ -126,7 +128,7 @@ class Voucher extends Model
{
$voucher = Voucher::where([
['is_sold', '=', self::UNSOLD],
['batch_id', '=', $this->batch_id]
['batch_id', '=', $this->batch_id],
])->count();
return $voucher;
@ -136,7 +138,7 @@ class Voucher extends Model
{
$count = Voucher::where([
['is_sold', '=', self::UNSOLD],
['batch_id', '=', $this->batch_id]
['batch_id', '=', $this->batch_id],
])->count();
$treshold = Setting::getByKey('VOUCHER_STOCK_NOTIFICATION');
@ -144,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,
]);
}
}

@ -1,22 +1,22 @@
<?php
use App\Http\Controllers\AccountController;
use App\Http\Controllers\NotificationController;
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\BannerController;
use App\Http\Controllers\CoinRewardController;
use App\Http\Controllers\CustomerController;
use App\Http\Controllers\CustomerLevelController;
use App\Http\Controllers\VerificationController;
use App\Http\Controllers\DepositController;
use App\Http\Controllers\GeneralController;
use App\Http\Controllers\InfoController;
use App\Http\Controllers\LocationController;
use App\Http\Controllers\NotificationController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\SaleController;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\VerificationController;
use App\Http\Controllers\VoucherController;
use Illuminate\Support\Facades\Route;

@ -1,10 +1,10 @@
<?php
use App\Http\Controllers\Api\CustomerController;
use App\Http\Controllers\Api\LocationController;
use App\Http\Controllers\Api\NotificationController;
use App\Http\Controllers\Api\RoleController;
use App\Http\Controllers\Customer\DepositController;
use App\Http\Controllers\Api\CustomerController;
use App\Http\Controllers\Api\NotificationController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

@ -58,7 +58,6 @@ Route::middleware(['http_secure_aware', 'guard_should_customer', 'inertia.custom
Route::get('coin', [CoinController::class, 'index'])->name('customer.coin.index');
Route::get('coin/{coin}', [CoinController::class, 'show'])->name('customer.coin.show');
// cart
Route::get('cart', [CartController::class, 'index'])->name('cart.index');
Route::post('cart/process', [CartController::class, 'purchase'])->name('cart.purchase');

Loading…
Cancel
Save