2023-12-08 09:56:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Writeoff\Livewire\HapusBuku;
|
|
|
|
|
|
|
|
use Livewire\Component;
|
2023-12-26 06:35:41 +00:00
|
|
|
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)
|
|
|
|
{
|
2023-12-26 06:35:41 +00:00
|
|
|
$hapusbuku = HapusBuku::find($id);
|
2023-12-26 06:45:38 +00:00
|
|
|
$hapusbuku->delete_by = auth()->user()->id;
|
|
|
|
$hapusbuku->deleted_at = now();
|
2023-12-08 09:56:25 +00:00
|
|
|
|
2023-12-26 06:35:41 +00:00
|
|
|
$approval = [
|
|
|
|
'method' => 'delete',
|
2024-03-27 09:54:06 +00:00
|
|
|
'menu' => 'Hapus Buku',
|
2023-12-26 06:35:41 +00:00
|
|
|
'old_request' => json_encode($hapusbuku),
|
|
|
|
'description' => 'Delete Data Hapus Buku',
|
|
|
|
'status' => '0',
|
|
|
|
'ref' => $hapusbuku->nomor_pinjaman
|
|
|
|
];
|
|
|
|
|
2024-03-27 09:54:06 +00:00
|
|
|
$is_approval = Approval::where('menu', 'Hapus Buku')
|
2023-12-26 06:35:41 +00:00
|
|
|
->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|