-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
221408f
commit cc0f93c
Showing
9 changed files
with
260 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
resources/views/livewire/setting/setting-component.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters