feat(voucher): menambahkan beberapa kolom baru
- membuat class enum IsShow - menyesuaikan seeder - menambahkan input kolom baru ke form - membuat handle crud nya
This commit is contained in:
parent
f874c36486
commit
4078201b03
30
app/Enums/IsShow.php
Normal file
30
app/Enums/IsShow.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\WithCommentEnum;
|
||||
use App\Traits\WithValueEnum;
|
||||
|
||||
enum IsShow: int
|
||||
{
|
||||
use WithCommentEnum, WithValueEnum;
|
||||
|
||||
case SHOW = 1;
|
||||
case HIDDEN = 2;
|
||||
|
||||
public function label()
|
||||
{
|
||||
return match ($this) {
|
||||
self::SHOW => 'Ditampilkan',
|
||||
self::HIDDEN => 'Disembunyikan',
|
||||
};
|
||||
}
|
||||
|
||||
public function color()
|
||||
{
|
||||
return match ($this) {
|
||||
self::SHOW => 'emerald',
|
||||
self::HIDDEN => 'red',
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -36,6 +36,10 @@ public function columns(): array
|
||||
})
|
||||
->html(),
|
||||
|
||||
Column::make('Tags', 'tags')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Column::make('Min. Belanja', 'min_purchase')
|
||||
->format(fn ($value) => currency($value, 'Rp'))
|
||||
->searchable()
|
||||
|
||||
@ -17,6 +17,8 @@ class VoucherForm extends Form
|
||||
|
||||
public string $code = '';
|
||||
|
||||
public string $tags = '';
|
||||
|
||||
public string $type = '1';
|
||||
|
||||
public string $discount_amount = '';
|
||||
@ -29,6 +31,8 @@ class VoucherForm extends Form
|
||||
|
||||
public ?string $limit_per_user = null;
|
||||
|
||||
public string $summary = '';
|
||||
|
||||
public string $start_date = '';
|
||||
|
||||
public ?string $end_date = null;
|
||||
@ -46,6 +50,7 @@ public function rules(): array
|
||||
'alpha_num',
|
||||
Rule::unique('vouchers', 'code')->ignore($this->voucher),
|
||||
],
|
||||
'tags' => ['required', 'string', 'max:20'],
|
||||
'type' => ['required', Rule::in(VoucherType::values())],
|
||||
'discount_amount' => [
|
||||
'required',
|
||||
@ -65,6 +70,7 @@ public function rules(): array
|
||||
],
|
||||
'quota' => ['nullable', new UnsignedInteger],
|
||||
'limit_per_user' => ['nullable', new UnsignedInteger],
|
||||
'summary' => ['required', 'string', 'max:200'],
|
||||
'start_date' => ['required', 'date', 'after:yesterday'],
|
||||
'end_date' => ['nullable', 'date', 'after_or_equal:start_date'],
|
||||
'outlet_ids' => ['required', 'array', 'min:1'],
|
||||
@ -81,6 +87,7 @@ public function validationAttributes(): array
|
||||
'max_discount' => 'maks. diskon',
|
||||
'quota' => 'kuota',
|
||||
'limit_per_user' => 'limit per user',
|
||||
'summary' => 'summary',
|
||||
'type' => 'Tipe',
|
||||
'discount_amount' => 'Jumlah Diskon',
|
||||
'start_date' => 'tanggal mulai',
|
||||
@ -98,12 +105,14 @@ public function setVoucher(Voucher $voucher)
|
||||
|
||||
$this->name = $this->voucher->name;
|
||||
$this->code = $this->voucher->code;
|
||||
$this->summary = $this->voucher->summary;
|
||||
$this->type = $this->voucher->type->value;
|
||||
$this->discount_amount = replaceCurrency($this->voucher->discount_amount);
|
||||
$this->min_purchase = replaceCurrency($this->voucher->min_purchase);
|
||||
$this->max_discount = replaceCurrency($this->voucher->max_discount);
|
||||
$this->quota = $this->voucher->quota;
|
||||
$this->limit_per_user = $this->voucher->limit_per_user;
|
||||
$this->summary = $this->voucher->summary;
|
||||
$this->start_date = $this->voucher->start_date;
|
||||
$this->end_date = $this->voucher->end_date;
|
||||
|
||||
@ -141,6 +150,7 @@ private function prepareSavedData()
|
||||
return [
|
||||
'name' => $this->name,
|
||||
'code' => $this->code,
|
||||
'tags' => $this->tags,
|
||||
'type' => $this->type,
|
||||
'discount_amount' => replaceCurrency($this->discount_amount),
|
||||
'min_purchase' => replaceCurrency($this->min_purchase),
|
||||
@ -148,6 +158,7 @@ private function prepareSavedData()
|
||||
'quota' => $this->quota,
|
||||
'available_count' => $this->quota,
|
||||
'limit_per_user' => $this->limit_per_user,
|
||||
'summary' => $this->summary,
|
||||
'start_date' => $this->start_date,
|
||||
'end_date' => $this->end_date,
|
||||
];
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\IsShow;
|
||||
use App\Enums\VoucherType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
@ -17,14 +18,17 @@ public function up(): void
|
||||
$table->string('name', 50);
|
||||
$table->string('code', 20)->unique();
|
||||
$table->enum('type', [VoucherType::values()])->default(VoucherType::PERCENTAGE)->comment(VoucherType::comment());
|
||||
$table->string('tags', 20);
|
||||
$table->string('summary', 200);
|
||||
$table->unsignedInteger('discount_amount');
|
||||
$table->unsignedInteger('min_purchase')->nullable();
|
||||
$table->unsignedInteger('max_discount')->nullable();
|
||||
$table->unsignedInteger('quota')->nullable();
|
||||
$table->unsignedInteger('available_count')->nullable();
|
||||
$table->unsignedInteger('available_count')->default(0);
|
||||
$table->unsignedInteger('limit_per_user')->nullable();
|
||||
$table->date('start_date');
|
||||
$table->date('end_date')->nullable();
|
||||
$table->enum('is_show', [IsShow::values()])->default(IsShow::SHOW)->comment(IsShow::comment());
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
||||
$table->softDeletes();
|
||||
|
||||
@ -16,6 +16,8 @@ public function run(): void
|
||||
'name' => 'Diskon 10%',
|
||||
'code' => 'DISC10',
|
||||
'type' => VoucherType::PERCENTAGE,
|
||||
'tags' => 'DISC 10%',
|
||||
'summary' => 'Diskon 10% untuk pembelian minimal Rp50.000',
|
||||
'discount_amount' => 10,
|
||||
'min_purchase' => 50000,
|
||||
'max_discount' => 20000,
|
||||
@ -29,6 +31,8 @@ public function run(): void
|
||||
'name' => 'Diskon 20%',
|
||||
'code' => 'DISC20',
|
||||
'type' => VoucherType::PERCENTAGE,
|
||||
'tags' => 'DISC 20%',
|
||||
'summary' => 'Diskon 20% untuk pembelian minimal Rp100.000',
|
||||
'discount_amount' => 20,
|
||||
'min_purchase' => 100000,
|
||||
'max_discount' => 50000,
|
||||
@ -40,8 +44,10 @@ public function run(): void
|
||||
],
|
||||
[
|
||||
'name' => 'Potongan Rp25K',
|
||||
'code' => 'SAVE25K',
|
||||
'code' => 'SAVE 25K',
|
||||
'type' => VoucherType::FIXED,
|
||||
'tags' => 'SAVE 25K',
|
||||
'summary' => 'Potongan Rp25K untuk pembelian minimal Rp100.000',
|
||||
'discount_amount' => 25000,
|
||||
'min_purchase' => 100000,
|
||||
'max_discount' => null,
|
||||
@ -55,6 +61,8 @@ public function run(): void
|
||||
'name' => 'Potongan Rp50K',
|
||||
'code' => 'SAVE50K',
|
||||
'type' => VoucherType::FIXED,
|
||||
'tags' => 'SAVE 50K',
|
||||
'summary' => 'Potongan Rp50K untuk pembelian minimal Rp200.000',
|
||||
'discount_amount' => 50000,
|
||||
'min_purchase' => 200000,
|
||||
'max_discount' => null,
|
||||
@ -68,6 +76,8 @@ public function run(): void
|
||||
'name' => 'Gratis Ongkir',
|
||||
'code' => 'ONGKIR',
|
||||
'type' => VoucherType::FIXED,
|
||||
'tags' => 'GRATIS ONGKIR',
|
||||
'summary' => 'Gratis Ongkir untuk pembelian minimal Rp50.000',
|
||||
'discount_amount' => 15000,
|
||||
'min_purchase' => 50000,
|
||||
'max_discount' => 15000,
|
||||
@ -81,6 +91,8 @@ public function run(): void
|
||||
'name' => 'Flash Sale 30%',
|
||||
'code' => 'FLASH30',
|
||||
'type' => VoucherType::PERCENTAGE,
|
||||
'tags' => 'FLASH 30%',
|
||||
'summary' => 'Diskon 30% untuk pembelian minimal Rp75.000',
|
||||
'discount_amount' => 30,
|
||||
'min_purchase' => 75000,
|
||||
'max_discount' => 40000,
|
||||
@ -94,11 +106,12 @@ public function run(): void
|
||||
'name' => 'Spesial Member',
|
||||
'code' => 'MEMBER15',
|
||||
'type' => VoucherType::PERCENTAGE,
|
||||
'tags' => 'Serial Member',
|
||||
'summary' => 'Diskon 15% untuk pembelian minimal Rp50.000',
|
||||
'discount_amount' => 15,
|
||||
'min_purchase' => 50000,
|
||||
'max_discount' => 25000,
|
||||
'quota' => null,
|
||||
'available_count' => null,
|
||||
'limit_per_user' => null,
|
||||
'start_date' => now(),
|
||||
'end_date' => null,
|
||||
|
||||
@ -32,9 +32,15 @@
|
||||
oninput="this.value = this.value.toUpperCase()" />
|
||||
<flux:error name="form.code" />
|
||||
</flux:field>
|
||||
|
||||
<div class="lg:col-span-2">
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<flux:field>
|
||||
<flux:label>Tags <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:input placeholder="Member Baru"
|
||||
wire:model.live.debounce.500ms="form.tags" autocomplete="off" />
|
||||
<flux:error name="form.tags" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>Min. Belanja</flux:label>
|
||||
<flux:input.group>
|
||||
@ -57,6 +63,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<flux:field>
|
||||
<flux:label>Ringkasan <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:input placeholder="Diskon 10% untuk member baru"
|
||||
wire:model.live.debounce.500ms="form.summary" autofocus
|
||||
autocomplete="off" />
|
||||
<flux:error name="form.summary" />
|
||||
</flux:field>
|
||||
</div>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>Tanggal Mulai <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:date-picker with-today wire:model.live.debounce.500ms="form.start_date"
|
||||
@ -108,8 +124,7 @@
|
||||
<flux:label>Maks. Diskon <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:input.group>
|
||||
<flux:input.group.prefix>Rp</flux:input.group.prefix>
|
||||
<flux:input placeholder="10.000"
|
||||
x-mask:dynamic="$money($input, ',')"
|
||||
<flux:input placeholder="10.000" x-mask:dynamic="$money($input, ',')"
|
||||
wire:model.live.debounce.500ms="form.max_discount" autocomplete="off" />
|
||||
</flux:input.group>
|
||||
<flux:error name="form.max_discount" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user