2023-12-19 11:00:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Writeoff\Livewire\DetailSubrogasiJamkrindo;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Livewire\Component;
|
2023-12-26 06:35:41 +00:00
|
|
|
use Modules\Writeoff\Entities\Approval;
|
2023-12-19 11:00:24 +00:00
|
|
|
use Modules\Writeoff\Entities\DetailSubrogasiJamkrindo;
|
|
|
|
use Modules\Writeoff\Http\Requests\DetailSubrogasiJamkrindo\StoreDetailSubrogasiJamkrindoRequest;
|
|
|
|
use Request;
|
|
|
|
|
|
|
|
class DetailSubrogasiJamkrindoModal extends Component
|
|
|
|
{
|
|
|
|
public $id;
|
|
|
|
public $nomor_pinjaman;
|
2024-03-21 03:36:55 +00:00
|
|
|
public $kode;
|
2023-12-19 11:00:24 +00:00
|
|
|
public $tanggal_pembayaran;
|
|
|
|
public $pembayaran_debitur;
|
|
|
|
public $subrogasi_jamkrindo;
|
|
|
|
public $pendapatan_bank;
|
|
|
|
public $keterangan;
|
|
|
|
public $status;
|
|
|
|
public $edit_mode = false;
|
|
|
|
|
|
|
|
protected $listeners = [
|
|
|
|
'delete' => 'delete',
|
|
|
|
'update' => 'update',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
$this->pinjaman = request()->segment(3);
|
|
|
|
$this->nomor_pinjaman = $this->pinjaman;
|
|
|
|
return view('writeoff::livewire.detail-subrogasi-jamkrindo.detail-subrogasi-jamkrindo-modal');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
session_start();
|
|
|
|
// Validate the form input data
|
|
|
|
DB::transaction(function () {
|
|
|
|
// Prepare the data for creating a new user
|
2024-03-25 07:49:47 +00:00
|
|
|
$kode = round(microtime(true) * 100);
|
2023-12-19 11:00:24 +00:00
|
|
|
$data = [
|
2024-03-25 07:49:47 +00:00
|
|
|
'nomor_pinjaman' => $this->nomor_pinjaman ?? $_SESSION['nomor_pinjaman'],
|
|
|
|
'kode' => $this->kode ?? $kode,
|
2023-12-19 11:00:24 +00:00
|
|
|
'tanggal_pembayaran' => $this->tanggal_pembayaran,
|
|
|
|
'pembayaran_debitur' => $this->pembayaran_debitur,
|
|
|
|
'subrogasi_jamkrindo' => $this->subrogasi_jamkrindo,
|
|
|
|
'pendapatan_bank' => $this->pendapatan_bank,
|
|
|
|
'keterangan' => $this->keterangan,
|
|
|
|
'status' => $this->status,
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($this->edit_mode) {
|
|
|
|
// Emit a success event with a message
|
|
|
|
$detail_penagihan = DetailSubrogasiJamkrindo::find($this->id);
|
|
|
|
|
2024-03-19 03:03:00 +00:00
|
|
|
$data['updated_by'] = auth()->user()->id;
|
|
|
|
$data['updated_at'] = now();
|
|
|
|
|
|
|
|
$approval = [
|
|
|
|
'method' => 'update',
|
|
|
|
'menu' => 'Detail Subrogasi Jamkrindo',
|
|
|
|
'old_request' => json_encode($detail_penagihan),
|
|
|
|
'new_request' => json_encode($data),
|
|
|
|
'description' => 'Update Detail Subrogasi Jamkrindo',
|
|
|
|
'status' => '0',
|
|
|
|
'ref' => $this->kode
|
|
|
|
];
|
|
|
|
|
|
|
|
$is_approval = Approval::where('menu', 'Detail Subrogasi Jamkrindo')
|
|
|
|
->where('ref', $this->kode)
|
|
|
|
->where('status', '0')
|
|
|
|
->get()
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if ($is_approval) {
|
|
|
|
$this->dispatch('error', 'Data Detail Subrogasi Jamkrindo Sedang Menunggu Approval');
|
|
|
|
} else {
|
|
|
|
Approval::create($approval);
|
|
|
|
$this->dispatch('success', 'Data Detail Subrogasi Jamkrindo Berhasil Di Update, Menunggu Approval');
|
|
|
|
}
|
2023-12-19 11:00:24 +00:00
|
|
|
} else {
|
|
|
|
// Emit a success event with a message
|
2024-03-19 03:03:00 +00:00
|
|
|
$data['created_by'] = auth()->user()->id;
|
|
|
|
$data['created_at'] = now();
|
|
|
|
|
|
|
|
$approval = [
|
|
|
|
'method' => 'create',
|
|
|
|
'menu' => 'Detail Subrogasi Jamkrindo',
|
|
|
|
'new_request' => json_encode($data),
|
|
|
|
'description' => 'Create Detail Subrogasi Jamkrindo',
|
|
|
|
'status' => '0',
|
2024-03-25 07:49:47 +00:00
|
|
|
'ref' => $kode
|
2024-03-19 03:03:00 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$is_approval = Approval::where('menu', 'Detail Subrogasi Jamkrindo')
|
2024-03-25 07:49:47 +00:00
|
|
|
->where('ref', $kode)
|
2024-03-19 03:03:00 +00:00
|
|
|
->where('status', '0')
|
|
|
|
->get()
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if ($is_approval) {
|
|
|
|
$this->dispatch('error', 'Data Detail Subrogasi Jamkrindo Sedang Menunggu Approval');
|
|
|
|
$this->reset();
|
|
|
|
} else {
|
|
|
|
Approval::create($approval);
|
|
|
|
$this->dispatch('success', 'Data Detail Subrogasi Jamkrindo Berhasil Di Input, Menunggu Approval');
|
|
|
|
}
|
2023-12-19 11:00:24 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Reset the form fields after successful submission
|
|
|
|
$this->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update($id)
|
|
|
|
{
|
|
|
|
$this->edit_mode = true;
|
|
|
|
|
|
|
|
$detail_subrogasi_jamkrindo = DetailSubrogasiJamkrindo::find($id);
|
|
|
|
|
|
|
|
$this->id = $id;
|
|
|
|
$this->nomor_pinjaman = $detail_subrogasi_jamkrindo->nomor_pinjaman;
|
|
|
|
$this->tanggal_pembayaran = $detail_subrogasi_jamkrindo->tanggal_pembayaran;
|
|
|
|
$this->pembayaran_debitur = $detail_subrogasi_jamkrindo->pembayaran_debitur;
|
|
|
|
$this->subrogasi_jamkrindo = $detail_subrogasi_jamkrindo->subrogasi_jamkrindo;
|
|
|
|
$this->pendapatan_bank = $detail_subrogasi_jamkrindo->pendapatan_bank;
|
|
|
|
$this->keterangan = $detail_subrogasi_jamkrindo->keterangan;
|
|
|
|
$this->status = $detail_subrogasi_jamkrindo->status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($id)
|
|
|
|
{
|
|
|
|
// Emit a success event with a message
|
2024-03-19 03:03:00 +00:00
|
|
|
$detailsubrogasi = DetailSubrogasiJamkrindo::find($id);
|
|
|
|
$detailsubrogasi->delete_by = auth()->user()->id;
|
2023-12-26 06:45:38 +00:00
|
|
|
$detailsubrogasi->deleted_at = now();
|
2023-12-26 06:35:41 +00:00
|
|
|
|
|
|
|
$approval = [
|
|
|
|
'method' => 'delete',
|
|
|
|
'menu' => 'Detail Subrogasi Jamkrindo',
|
|
|
|
'old_request' => json_encode($detailsubrogasi),
|
|
|
|
'description' => 'Delete Detail Subrogasi Jamkrindo',
|
|
|
|
'status' => '0',
|
|
|
|
'ref' => $detailsubrogasi->kode
|
|
|
|
];
|
|
|
|
|
|
|
|
$is_approval = Approval::where('menu', 'Detail Subrogasi Jamkrindo')
|
|
|
|
->where('ref', $detailsubrogasi->kode)
|
|
|
|
->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-19 11:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function hydrate()
|
|
|
|
{
|
|
|
|
$this->resetErrorBag();
|
|
|
|
$this->resetValidation();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function rules()
|
|
|
|
{
|
|
|
|
$request = new StoreDetailSubrogasiJamkrindoRequest();
|
|
|
|
|
|
|
|
return $request->rules();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|