2023-11-29 07:33:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Writeoff\Livewire\SubrogasiJamkrindo;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Livewire\Component;
|
2023-12-26 06:35:41 +00:00
|
|
|
use Modules\Writeoff\Entities\Approval;
|
2023-11-29 07:33:55 +00:00
|
|
|
use Modules\Writeoff\Entities\Branch;
|
|
|
|
use Modules\Writeoff\Entities\Debitur;
|
|
|
|
use Modules\Writeoff\Entities\Rekening;
|
|
|
|
use Modules\Writeoff\Entities\SubrogasiJamkrindo;
|
2023-12-05 11:17:27 +00:00
|
|
|
use Modules\Writeoff\Http\Requests\SubrogasiJamkrindo\StoreHapusBukuRequest;
|
|
|
|
use Modules\Writeoff\Http\Requests\SubrogasiJamkrindo\UpdateHapusBukuRequest;
|
2023-11-29 07:33:55 +00:00
|
|
|
|
|
|
|
class SubrogasiJamkrindoModal extends Component
|
|
|
|
{
|
|
|
|
public $id;
|
|
|
|
public $nomor_pinjaman;
|
|
|
|
public $kode_debitur;
|
|
|
|
public $nama_debitur;
|
|
|
|
public $kode_cabang;
|
|
|
|
public $nama_cabang;
|
|
|
|
public $nomor_rekening;
|
|
|
|
public $nama_rekening;
|
|
|
|
public $plafond;
|
|
|
|
public $tenor;
|
|
|
|
public $tanggal_pengajuan_klaim;
|
|
|
|
public $piutang_subrogasi;
|
|
|
|
public $total_bayar_subrogasi;
|
|
|
|
public $sisa_piutang_subrogasi;
|
|
|
|
public $is_lunas_subrogasi;
|
|
|
|
public $keterangan;
|
|
|
|
public $status;
|
|
|
|
|
|
|
|
public $edit_mode = false;
|
|
|
|
|
|
|
|
protected $listeners = [
|
|
|
|
'delete' => 'delete',
|
|
|
|
'update' => 'update',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('writeoff::livewire.subrogasi-jamkrindo.subrogasi-jamkrindo-modal');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
|
|
|
|
// Validate the form input data
|
|
|
|
DB::transaction(function () {
|
|
|
|
// Prepare the data for creating a new user
|
|
|
|
$data = [
|
|
|
|
'nomor_pinjaman' => $this->nomor_pinjaman,
|
|
|
|
'kode_debitur' => $this->kode_debitur,
|
|
|
|
'nama_debitur' => $this->nama_debitur,
|
|
|
|
'kode_cabang' => $this->kode_cabang,
|
|
|
|
'nama_cabang' => $this->nama_cabang,
|
|
|
|
'nomor_rekening' => $this->nomor_rekening,
|
|
|
|
'nama_rekening' => $this->nama_rekening,
|
|
|
|
'plafond' => $this->plafond,
|
|
|
|
'tenor' => $this->tenor,
|
|
|
|
'tanggal_pengajuan_klaim' => $this->tanggal_pengajuan_klaim,
|
|
|
|
'piutang_subrogasi' => $this->piutang_subrogasi,
|
|
|
|
'total_bayar_subrogasi' => $this->total_bayar_subrogasi,
|
|
|
|
'sisa_piutang_subrogasi' => $this->sisa_piutang_subrogasi,
|
|
|
|
'is_lunas_subrogasi' => $this->is_lunas_subrogasi,
|
|
|
|
'keterangan' => $this->keterangan,
|
|
|
|
'status' => $this->status
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($this->edit_mode) {
|
|
|
|
// Emit a success event with a message
|
|
|
|
$subrogasi_jamkrindo = SubrogasiJamkrindo::find($this->id);
|
|
|
|
$subrogasi_jamkrindo->update($data);
|
|
|
|
|
|
|
|
$this->dispatch('success', __('Subrogasi Jamkrindo updated'));
|
|
|
|
} else {
|
|
|
|
// Emit a success event with a message
|
|
|
|
SubrogasiJamkrindo::create($data);
|
|
|
|
$this->dispatch('success', __('New Subrogasi Jamkrindo created'));
|
|
|
|
}
|
2024-01-17 04:49:27 +00:00
|
|
|
|
|
|
|
if ($this->edit_mode) {
|
|
|
|
// Emit a success event with a message
|
|
|
|
$subrogasi_jamkrindo = SubrogasiJamkrindo::find($this->id);
|
|
|
|
|
|
|
|
$data['updated_by'] = auth()->user()->id;
|
|
|
|
$data['updated_at'] = now();
|
|
|
|
|
|
|
|
$approval = [
|
|
|
|
'method' => 'update',
|
|
|
|
'menu' => 'Subrogasi Jamkrindo',
|
|
|
|
'old_request' => json_encode($subrogasi_jamkrindo),
|
|
|
|
'new_request' => json_encode($data),
|
|
|
|
'description' => 'Update Subrogasi Jamkrindo',
|
|
|
|
'status' => '0',
|
|
|
|
'ref' => $this->kode
|
|
|
|
];
|
|
|
|
|
|
|
|
$is_approval = Approval::where('menu', 'Subrogasi Jamkrindo')
|
|
|
|
->where('ref', $this->kode)
|
|
|
|
->where('status', '0')
|
|
|
|
->where('method', 'update')
|
|
|
|
->get()
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if ($is_approval) {
|
|
|
|
$this->dispatch('error', 'Data Sedang Menunggu Approval');
|
|
|
|
} else {
|
|
|
|
Approval::create($approval);
|
|
|
|
$this->dispatch('success', 'Data Berhasil Di Update, Menunggu Approval');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$data['created_by'] = auth()->user()->id;
|
|
|
|
$data['created_at'] = now();
|
|
|
|
|
|
|
|
// Emit a success event with a message
|
|
|
|
$approval = [
|
|
|
|
'method' => 'create',
|
|
|
|
'menu' => 'Subrogasi Jamkrindo',
|
|
|
|
'new_request' => json_encode($data),
|
|
|
|
'description' => 'Create Subrogasi Jamkrindo',
|
|
|
|
'status' => '0',
|
|
|
|
'ref' => $this->kode
|
|
|
|
];
|
|
|
|
|
|
|
|
$is_approval = Approval::where('menu', 'Subrogasi Jamkrindo')
|
|
|
|
->where('ref', $this->kode)
|
|
|
|
->where('status', '0')
|
|
|
|
->where('method', 'create')
|
|
|
|
->get()
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if ($is_approval) {
|
|
|
|
$this->dispatch('error', 'Data Sedang Menunggu Approval');
|
|
|
|
$this->reset();
|
|
|
|
} else {
|
|
|
|
Approval::create($approval);
|
|
|
|
$this->dispatch('success', 'Data Berhasil Di Input, Menunggu Approval');
|
|
|
|
}
|
|
|
|
}
|
2023-11-29 07:33:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Reset the form fields after successful submission
|
|
|
|
//$this->reset();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update($id)
|
|
|
|
{
|
|
|
|
$this->edit_mode = true;
|
|
|
|
|
|
|
|
$subrogasi_jamkrindo = SubrogasiJamkrindo::find($id);
|
|
|
|
|
|
|
|
$this->id = $subrogasi_jamkrindo->id;
|
|
|
|
$this->nomor_pinjaman = $subrogasi_jamkrindo->nomor_pinjaman;
|
|
|
|
$this->kode_debitur = $subrogasi_jamkrindo->kode_debitur;
|
|
|
|
$this->nama_debitur = $subrogasi_jamkrindo->nama_debitur;
|
|
|
|
$this->kode_cabang = $subrogasi_jamkrindo->kode_cabang;
|
|
|
|
$this->nama_cabang = $subrogasi_jamkrindo->nama_cabang;
|
|
|
|
$this->nomor_rekening = $subrogasi_jamkrindo->nomor_rekening;
|
|
|
|
$this->nama_rekening = $subrogasi_jamkrindo->nama_rekening;
|
|
|
|
$this->plafond = $subrogasi_jamkrindo->plafond;
|
|
|
|
$this->tenor = $subrogasi_jamkrindo->tenor;
|
|
|
|
$this->tanggal_pengajuan_klaim = $subrogasi_jamkrindo->tanggal_pengajuan_klaim;
|
|
|
|
$this->piutang_subrogasi = $subrogasi_jamkrindo->piutang_subrogasi;
|
|
|
|
$this->total_bayar_subrogasi = $subrogasi_jamkrindo->total_bayar_subrogasi;
|
|
|
|
$this->sisa_piutang_subrogasi = $subrogasi_jamkrindo->sisa_piutang_subrogasi;
|
|
|
|
$this->is_lunas_subrogasi = $subrogasi_jamkrindo->is_lunas_subrogasi == 1;
|
|
|
|
$this->keterangan = $subrogasi_jamkrindo->keterangan;
|
|
|
|
$this->status = $subrogasi_jamkrindo->status == 1;
|
|
|
|
}
|
|
|
|
|
2023-12-26 06:35:41 +00:00
|
|
|
public function getDebitur()
|
|
|
|
{
|
|
|
|
$debitur = Debitur::where('kode', $this->kode_debitur)->first();
|
|
|
|
if ($debitur) {
|
2023-11-29 07:33:55 +00:00
|
|
|
$this->nama_debitur = $debitur->name;
|
|
|
|
} else {
|
|
|
|
$this->nama_debitur = '';
|
|
|
|
$this->addError('nama_debitur', 'Debitur Tidak Ditemukan');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-26 06:35:41 +00:00
|
|
|
public function getBranch()
|
|
|
|
{
|
|
|
|
$branch = Branch::where('kode', $this->kode_cabang)->first();
|
|
|
|
if ($branch) {
|
2023-11-29 07:33:55 +00:00
|
|
|
$this->nama_cabang = $branch->name;
|
|
|
|
} else {
|
|
|
|
$this->nama_cabang = '';
|
|
|
|
$this->addError('nama_cabang', 'Cabang Tidak Ditemukan');
|
|
|
|
}
|
|
|
|
}
|
2023-12-26 06:35:41 +00:00
|
|
|
|
|
|
|
public function getRekening()
|
|
|
|
{
|
|
|
|
$rekening = Rekening::where('nomor_rekening', $this->nomor_rekening)->first();
|
|
|
|
if ($rekening) {
|
|
|
|
$debitur = Debitur::where('id', $rekening->debitur_id)->first();
|
|
|
|
if ($debitur) {
|
2023-11-29 07:33:55 +00:00
|
|
|
$this->nama_rekening = $debitur->name;
|
|
|
|
} else {
|
|
|
|
$this->nama_rekening = '';
|
|
|
|
$this->addError('nama_rekening', 'Nomor Rekening Tidak Ditemukan');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->nama_rekening = '';
|
|
|
|
$this->addError('nama_rekening', 'Nomor Rekening Tidak Ditemukan');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($id)
|
|
|
|
{
|
2024-01-17 04:49:27 +00:00
|
|
|
$old = SubrogasiJamkrindo::find($id);
|
|
|
|
unset($old->deleted_at);
|
|
|
|
unset($old->deleted_by);
|
|
|
|
|
|
|
|
$subrogasi = SubrogasiJamkrindo::find($id);
|
|
|
|
$subrogasi->delete_by = auth()->user()->id;
|
2023-12-26 06:45:38 +00:00
|
|
|
$subrogasi->deleted_at = now();
|
2023-12-26 06:35:41 +00:00
|
|
|
|
|
|
|
$approval = [
|
|
|
|
'method' => 'delete',
|
2024-01-17 04:49:27 +00:00
|
|
|
'menu' => 'Subrogasi Jamkrindo',
|
2024-01-17 04:52:49 +00:00
|
|
|
'old_request' => json_encode($old),
|
|
|
|
'new_request' => json_encode($subrogasi),
|
2023-12-26 06:35:41 +00:00
|
|
|
'description' => 'Delete Data Subrogasi Jamkrindo',
|
|
|
|
'status' => '0',
|
|
|
|
'ref' => $subrogasi->nomor_pinjaman
|
|
|
|
];
|
|
|
|
|
2024-01-17 04:49:27 +00:00
|
|
|
$is_approval = Approval::where('menu', 'Subrogasi Jamkrindo')
|
2023-12-26 06:35:41 +00:00
|
|
|
->where('ref', $subrogasi->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-11-29 07:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function hydrate()
|
|
|
|
{
|
|
|
|
$this->resetErrorBag();
|
|
|
|
$this->resetValidation();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function rules()
|
|
|
|
{
|
|
|
|
|
|
|
|
if ($this->edit_mode) {
|
2023-12-05 11:17:27 +00:00
|
|
|
$request = new UpdateHapusBukuRequest();
|
2023-11-29 07:33:55 +00:00
|
|
|
} else {
|
2023-12-05 11:17:27 +00:00
|
|
|
$request = new StoreHapusBukuRequest();
|
2023-11-29 07:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $request->rules();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|