Writeoff/Livewire/HapusBuku/NomorPinjamanModal.php

57 lines
1.7 KiB
PHP
Raw Normal View History

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