Skip to content

Commit

Permalink
feat: Setting page
Browse files Browse the repository at this point in the history
  • Loading branch information
bangyadiii committed Jun 5, 2024
1 parent 221408f commit cc0f93c
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 23 deletions.
37 changes: 37 additions & 0 deletions app/Livewire/Forms/SettingForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Livewire\Forms;

use Livewire\Attributes\Validate;
use Livewire\Form;

class SettingForm extends Form
{
public bool $enabled = true;
public string $template = '';
public $ppn = 0;
public ?string $rekening = '';
public ?bool $changed = false;

public array $rules = [
'enabled' => 'required|boolean',
'template' => 'required|string|min:2|max:1200',
'ppn' => 'required|integer|min:0|max:100',
'rekening' => 'nullable|string|min:2|max:255'
];

public array $validationAttributes = [
'enabled' => 'Enabled',
'template' => 'Template',
'ppn' => 'PPN',
'rekening' => 'Rekening'
];

public function setData(array $data)
{
$this->enabled = $data['enabled'];
$this->template = $data['template'];
$this->ppn = $data['ppn'];
$this->rekening = $data['rekening'];
}
}
69 changes: 69 additions & 0 deletions app/Livewire/Setting/SettingComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Livewire\Setting;

use App\Livewire\Forms\SettingForm;
use App\Models\Setting;
use Livewire\Component;

class SettingComponent extends Component
{
public SettingForm $form;
public $data = [];

public function mount()
{
$this->data['enabled'] = (bool) Setting::query()->where('key', 'reminder_enabled')->first()?->value ?? 0;
$this->data['template'] = Setting::query()->where('key', 'whatsapp_template')->first()?->value ?? '';
$this->data['ppn'] = (int) Setting::query()->where('key', 'ppn')->first()?->value ?? 0;
$this->data['rekening'] = Setting::query()->where('key', 'rekening')->first()?->value ?? '';
$this->form->setData($this->data);
}

public function render()
{
return view('livewire.setting.setting-component');
}

public function cancel()
{
$this->form->reset();
$this->form->setData($this->data);
}

public function store()
{
$this->form->validate();

$enabled = Setting::query()->updateOrCreate([
'key' => 'reminder_enabled'
], [
'value' => $this->form->enabled
]);
$template = Setting::query()->updateOrCreate([
'key' => 'whatsapp_template'
], [
'value' => $this->form->template
]);
$ppn = Setting::query()->updateOrCreate([
'key' => 'ppn'
], [
'value' => $this->form->ppn
]);
$rekening = Setting::query()->updateOrCreate([
'key' => 'rekening'
], [
'value' => $this->form->rekening
]);

$this->dispatch('toast', title: 'Setting berhasil tersimpan');
$this->form->reset();

$this->form->setData([
'enabled' => (bool) $enabled->value,
'template' => $template->value,
'ppn' => $ppn->value,
'rekening' => $rekening->value
]);
}
}
2 changes: 2 additions & 0 deletions app/Livewire/Transaction/CreateTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Enums\InstallmentStatus;
use App\Enums\PaymentMethod;
use App\Enums\PaymentStatus;
use App\Jobs\GenerateMonthlyBills;
use App\Jobs\UnisolateCustomerJob;
use App\Livewire\Forms\TransactionForm;
use App\Models\Bill;
Expand Down Expand Up @@ -81,6 +82,7 @@ public function store()
$this->currentBill->total_amount = $this->grand_total;
$this->currentBill->status = BillStatus::PAID;
$this->currentBill->save();
\dispatch(new GenerateMonthlyBills);
$this->resetElement();

$this->dispatch('toast', title: 'Berhasil disimpan');
Expand Down
4 changes: 2 additions & 2 deletions database/factories/PlanFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function definition(): array
return [
'ppp_profile_id' => $this->faker->randomNumber(),
'name' => $this->faker->word,
'price' => $this->faker->randomFloat(2, 0, 100000),
'speed_limit' => $this->faker->randomNumber(),
'price' => $this->faker->randomFloat(2, 0, 200_000),
'speed_limit' => $this->faker->randomNumber() . 'M',
'router_id' => Router::factory()
];
}
Expand Down
5 changes: 5 additions & 0 deletions database/seeders/SettingSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ public function run(): void
'key' => 'whatsapp_template',
'value' => config('template-notif.template'),
]);

Setting::create([
'key' => 'rekening',
'value' => 'BCA 1234567890 a/n PT. ABCD',
]);
}
}
20 changes: 4 additions & 16 deletions resources/menu/verticalMenu.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,17 @@
"icon": "menu-icon tf-icons bx bx-user",
"slug": "customers.index"
},
{
"menuHeader": "Transaksi"
},
{
"url": "/transactions",
"name": "Transaksi Pembayaran",
"icon": "menu-icon tf-icons bx bx-money-withdraw",
"slug": "transactions.index"
},
{
"menuHeader": "Settings"
},
{
"url": "/settings/notifications",
"name": "Setting Notifikasi",
"icon": "menu-icon tf-icons bx bxs-megaphone",
"slug": "notifications.index"
},
{
"url": "/settings/tax",
"name": "Setting Pajak",
"icon": "menu-icon tf-icons bx bx-purchase-tag-alt",
"slug": "tax"
"url": "/settings",
"name": "Pengaturan",
"icon": "menu-icon tf-icons bx bx-cog",
"slug": "settings.index"
}
]
}
134 changes: 134 additions & 0 deletions resources/views/livewire/setting/setting-component.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<div>
<h4 class="py-3 mb-4"><span class="text-muted fw-light">Setting /</span> Notifikasi</h4>

<!-- Basic Layout -->
<div class="row">
<div class="col-xl">
<div class="card mb-4">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">Setting Notifikasi</h5>
</div>
<div class="card-body">
<form wire:submit='store' x-data="{
enabled: $wire.entangle('form.enabled'),
template: $wire.entangle('form.template'),
ppn: $wire.entangle('form.ppn'),
rekening: $wire.entangle('form.rekening'),
changed: $wire.entangle('form.changed'),
}" x-init="$watch('enabled', value => {
changed = true;
}); $watch('template', value => {
changed = true;
}); $watch('ppn', value => {
changed = true;
}); $watch('rekening', value => {
changed = true;
}); ">
@csrf
<div class="mb-3">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch"
id="flexSwitchCheckDefault" wire:model='form.enabled' x-model="enabled">
<label class="form-check-label" for="flexSwitchCheckDefault">Otomatis mengirim
notifikasi pembayaran ke pelanggan?</label>
</div>
</div>
<div class="mb-3">
<label class="form-label" for="format">Template Notifikasi</label>
<textarea id="format" type="text" class="form-control @error('form.template')
is-invalid
@enderror" wire:model='form.template' rows="13" :disabled="!enabled"></textarea>

@error('form.template')
<div class="error">
{{ $message }}
</div>
@enderror
</div>
Gunakan variabel berikut untuk mengganti data pelanggan:
<ul>
<li>
[NOPEL] = Nomor Pelanggan
</li>
<li>
[NAMA] = Nama Pelanggan
</li>
<li>
[PHONE] = Nomor Wa Pelanggan
</li>
<li>
[ALAMAT] = Alamat Pelanggan
</li>
<li>
[PAKET] = Nama Paket Pelanggan
</li>
<li>
[TARIFPAKET] = Tarif Paket Pelanggan
</li>
<li>
[DISKON] = Diskon Paket Pelanggan
</li>
<li>
[TAGIHAN] =Total Tagihan perBulan
</li>
<li>
[ISOLIR] = Tanggal Isolir Pelanggan
</li>
<li>
[BANK] = data Bank Perusahaan
</li>
</ul>

<div class="mb-3 col-4">
<label class="form-label" for="format">PPN</label>
<div class="input-group">
<input id="format" type="number" class="form-control @error('form.ppn')
is-invalid
@enderror" wire:model='form.ppn' />
<span class="input-group-text">%</span>
</div>

@error('ppn')
<div class="error">
{{ $message }}
</div>
@enderror
</div>

<div class="mb-3 col-4">
<label class="form-label" for="rekening">Rekening</label>
<input id="rekening" type="text" class="form-control @error('form.rekening')
is-invalid
@enderror" wire:model='form.rekening' />

@error('form.rekening')
<div class="error">
{{ $message }}
</div>
@enderror
</div>

<button type="submit" class="btn btn-primary" wire:loading.attr='disabled' :disabled="!changed">
<output class="spinner-border" wire:loading>
<span class="visually-hidden">Loading...</span>
</output>
<span wire:loading.remove>
Simpan
</span>
</button>
<button type="button" class="btn btn-secondary" wire:loading.attr='disabled' wire:click='cancel'
x-show="changed" x-transition>
<output class="spinner-border" wire:loading>
<span class="visually-hidden">Loading...</span>
</output>
<span wire:loading.remove>
Batal Simpan
</span>
</button>
</form>
</div>
</div>
</div>

</div>
</div>
6 changes: 3 additions & 3 deletions resources/views/livewire/transaction/bill-check.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@include('_partials.logo',[ "height" => 60, 'width' => 150,"fillColor"=>'#697A8D'])
</a>
</div>
<form id="formAuthentication" class="mb-3" wire:submit.prevent='store'>
<form class="mb-3" wire:submit.prevent='store'>
@csrf
<div class="mb-3">
<label for="nopel" class="form-label">Nomor Pelanggan</label>
Expand All @@ -32,9 +32,9 @@
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary d-grid w-100" wire:loading.attr='disabled'>
<div class="spinner-border" role="status" wire:loading>
<output class="spinner-border" wire:loading>
<span class="visually-hidden">Loading...</span>
</div>
</output>
<span wire:loading.remove>
Cek Tagihan
</span>
Expand Down
6 changes: 4 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Livewire\Router\EditRouter;
use App\Livewire\Router\RouterIndex;
use App\Livewire\Setting\NotificationSetting;
use App\Livewire\Setting\SettingComponent;
use App\Livewire\Setting\TaxSetting;
use App\Livewire\Transaction\BillCheck;
use App\Livewire\Transaction\CreateOnlinePayment;
Expand Down Expand Up @@ -64,8 +65,9 @@
Route::middleware('auth')
->prefix('settings')
->group(function () {
Route::get('/notifications', NotificationSetting::class)->name('notifications.index');
Route::get('/tax', TaxSetting::class)->name('tax');
Route::get('/', SettingComponent::class)->name('settings');
// Route::get('/notifications', NotificationSetting::class)->name('notifications.index');
// Route::get('/tax', TaxSetting::class)->name('tax');
});

Route::get('/bill-checks', BillCheck::class)->name('bill_checks');
Expand Down

0 comments on commit cc0f93c

Please sign in to comment.