179 lines
7.0 KiB
PHP
179 lines
7.0 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Modules\Writeoff\Livewire\SubrogasiJamkrindo;
|
||
|
|
||
|
use Exception;
|
||
|
use Illuminate\Support\Facades\DB;
|
||
|
use Livewire\Component;
|
||
|
use Modules\Writeoff\Entities\Branch;
|
||
|
use Modules\Writeoff\Entities\Debitur;
|
||
|
use Modules\Writeoff\Entities\Rekening;
|
||
|
use Modules\Writeoff\Entities\SubrogasiJamkrindo;
|
||
|
use Modules\Writeoff\Http\Requests\SubrogasiJamkrindo\StoreSubrogasiJamkrindoRequest;
|
||
|
use Modules\Writeoff\Http\Requests\SubrogasiJamkrindo\UpdateSubrogasiJamkrindoRequest;
|
||
|
|
||
|
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'));
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// 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;
|
||
|
}
|
||
|
|
||
|
public function getDebitur(){
|
||
|
$debitur = Debitur::where('kode',$this->kode_debitur)->first();
|
||
|
if($debitur) {
|
||
|
$this->nama_debitur = $debitur->name;
|
||
|
} else {
|
||
|
$this->nama_debitur = '';
|
||
|
$this->addError('nama_debitur', 'Debitur Tidak Ditemukan');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function getBranch(){
|
||
|
$branch = Branch::where('kode',$this->kode_cabang)->first();
|
||
|
if($branch) {
|
||
|
$this->nama_cabang = $branch->name;
|
||
|
} else {
|
||
|
$this->nama_cabang = '';
|
||
|
$this->addError('nama_cabang', 'Cabang Tidak Ditemukan');
|
||
|
}
|
||
|
}
|
||
|
public function getRekening(){
|
||
|
$rekening = Rekening::where('nomor_rekening',$this->nomor_rekening)->first();
|
||
|
if($rekening) {
|
||
|
$debitur = Debitur::where('id',$rekening->debitur_id)->first();
|
||
|
if($debitur) {
|
||
|
$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)
|
||
|
{
|
||
|
SubrogasiJamkrindo::destroy($id);
|
||
|
|
||
|
// Emit a success event with a message
|
||
|
$this->dispatch('success', 'Subrogasi Jamkrindo successfully deleted');
|
||
|
}
|
||
|
|
||
|
public function hydrate()
|
||
|
{
|
||
|
$this->resetErrorBag();
|
||
|
$this->resetValidation();
|
||
|
}
|
||
|
|
||
|
protected function rules()
|
||
|
{
|
||
|
|
||
|
if ($this->edit_mode) {
|
||
|
$request = new UpdateSubrogasiJamkrindoRequest();
|
||
|
} else {
|
||
|
$request = new StoreSubrogasiJamkrindoRequest();
|
||
|
}
|
||
|
|
||
|
|
||
|
return $request->rules();
|
||
|
}
|
||
|
}
|
||
|
|