Writeoff/Livewire/HapusBuku/NomorPinjamanModal.php
2023-12-19 18:00:24 +07:00

57 lines
1.7 KiB
PHP

<?php
namespace Modules\Writeoff\Livewire\HapusBuku;
use Livewire\Component;
use Modules\Writeoff\Entities\HapusBuku;
use Modules\Writeoff\Entities\Rekening;
class NomorPinjamanModal extends Component
{
public $nomor_pinjaman;
public $edit_mode = false;
protected $listeners = [
'delete' => 'delete'
];
public function render()
{
return view('writeoff::livewire.hapus-buku.nomor-pinjaman-modal');
}
public function submit()
{
$this->validate([
'nomor_pinjaman' => 'required',
]);
$rekenings = Rekening::with('loan_type', 'debitur')
->where('nomor_rekening', $this->nomor_pinjaman)
->whereDoesntHave('hapusBuku')
->whereHas('loan_type', function ($query) {
$query->whereBetween('kode', [3000, 3999]);
})
->get()
->first();
if ($rekenings) {
$this->dispatch('success', __('Nomor Pinjaman ditemukan'));
$this->redirect(route('pencatatan.hapus_buku.index', ['rekening' => $this->nomor_pinjaman]));
} else {
$this->addError('nomor_pinjaman', 'Nomor Pinjaman Salah Atau Nomor Pinjaman sudah terdaftar');
}
//$this->dispatch('showHapusBuku');
}
public function delete($id)
{
HapusBuku::destroy($id);
// Emit a success event with a message
$this->dispatch('success', 'Hapus Buku successfully deleted');
}
}