Writeoff/Livewire/HapusBuku/NomorPinjamanModal.php

78 lines
2.6 KiB
PHP
Raw Normal View History

2023-12-08 09:56:25 +00:00
<?php
namespace Modules\Writeoff\Livewire\HapusBuku;
use Livewire\Component;
use Modules\Writeoff\Entities\Approval;
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 = HapusBuku::find($id);
2023-12-08 09:56:25 +00:00
$approval = [
'method' => 'delete',
'menu' => 'Data Hapus Buku',
'old_request' => json_encode($hapusbuku),
'description' => 'Delete Data Hapus Buku',
'status' => '0',
'ref' => $hapusbuku->nomor_pinjaman
];
$is_approval = Approval::where('menu', 'Data Hapus Buku')
->where('ref', $hapusbuku->nomor_pinjaman)
->where('status', '0')
->where('method', 'delete')
->get()
->first();
if ($is_approval) {
$this->dispatch('error', 'Data Sedang Menunggu Approval');
} else {
Approval::create($approval);
$this->dispatch('success', 'Data Berhasil Di Hapus, Menunggu Approval');
}
2023-12-08 09:56:25 +00:00
}
}