2023-11-15 08:05:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Writeoff\Livewire\Rekening;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Livewire\Component;
|
2023-12-26 06:35:41 +00:00
|
|
|
use Modules\Writeoff\Entities\Approval;
|
2023-11-15 08:05:46 +00:00
|
|
|
use Modules\Writeoff\Entities\Branch;
|
|
|
|
use Modules\Writeoff\Entities\Currency;
|
|
|
|
use Modules\Writeoff\Entities\Debitur;
|
2023-12-13 14:23:49 +00:00
|
|
|
use Modules\Writeoff\Entities\LoanType;
|
2023-11-15 08:05:46 +00:00
|
|
|
use Modules\Writeoff\Entities\Product;
|
|
|
|
use Modules\Writeoff\Entities\Rekening;
|
|
|
|
use Modules\Writeoff\Http\Requests\Rekening\StoreRekeningRequest;
|
|
|
|
use Modules\Writeoff\Http\Requests\Rekening\UpdateRekeningRequest;
|
|
|
|
|
|
|
|
class RekeningModal extends Component
|
|
|
|
{
|
|
|
|
public $id;
|
|
|
|
public $nomor_rekening;
|
|
|
|
public $status_rekening;
|
|
|
|
public $branch_id;
|
|
|
|
public $debitur_id;
|
2023-12-13 14:23:49 +00:00
|
|
|
public $loan_type_id;
|
2023-11-15 08:05:46 +00:00
|
|
|
public $currency_id;
|
|
|
|
|
|
|
|
public $status;
|
|
|
|
public $limit_ref;
|
|
|
|
public $registered_at;
|
|
|
|
|
|
|
|
public $edit_mode = false;
|
|
|
|
|
|
|
|
protected $listeners = [
|
|
|
|
'delete' => 'delete',
|
|
|
|
'update' => 'update',
|
2024-01-10 04:51:13 +00:00
|
|
|
'reload' => 'reload',
|
2023-11-15 08:05:46 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
2023-12-13 14:23:49 +00:00
|
|
|
$cabang = Branch::all();
|
|
|
|
$debitur = Debitur::all();
|
|
|
|
$loan_type = LoanType::all();
|
|
|
|
$currency = Currency::all();
|
2023-11-15 08:05:46 +00:00
|
|
|
|
|
|
|
return view('writeoff::livewire.rekening.rekening-modal', compact([
|
|
|
|
'cabang',
|
|
|
|
'debitur',
|
2023-12-13 14:23:49 +00:00
|
|
|
'loan_type',
|
2023-11-15 08:05:46 +00:00
|
|
|
'currency'
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
|
|
|
|
// Validate the form input data
|
|
|
|
DB::transaction(function () {
|
|
|
|
// Prepare the data for creating a new user
|
|
|
|
$data = [
|
|
|
|
'nomor_rekening' => $this->nomor_rekening,
|
|
|
|
'branch_id' => $this->branch_id,
|
|
|
|
'debitur_id' => $this->debitur_id,
|
2023-12-13 14:23:49 +00:00
|
|
|
'loan_type_id' => $this->loan_type_id,
|
2023-11-15 08:05:46 +00:00
|
|
|
'currency_id' => $this->currency_id,
|
|
|
|
'status' => $this->status,
|
|
|
|
'status_rekening' => $this->status_rekening,
|
|
|
|
'limit_ref' => $this->limit_ref,
|
|
|
|
'registered_at' => $this->registered_at
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->edit_mode) {
|
|
|
|
// Emit a success event with a message
|
|
|
|
$rekening = Rekening::find($this->id);
|
|
|
|
|
2023-12-26 08:00:48 +00:00
|
|
|
$approval = [
|
|
|
|
'method' => 'update',
|
|
|
|
'menu' => 'Parameter Rekening',
|
|
|
|
'old_request' => json_encode($rekening),
|
|
|
|
'new_request' => json_encode($data),
|
|
|
|
'description' => 'Update Parameter Rekening',
|
|
|
|
'status' => '0',
|
|
|
|
'ref' => $this->kode
|
|
|
|
];
|
|
|
|
|
|
|
|
$is_approval = Approval::where('menu', 'Parameter Rekening')
|
|
|
|
->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');
|
|
|
|
}
|
2023-11-15 08:05:46 +00:00
|
|
|
} else {
|
|
|
|
// Emit a success event with a message
|
2023-12-26 08:00:48 +00:00
|
|
|
$approval = [
|
|
|
|
'method' => 'create',
|
|
|
|
'menu' => 'Parameter Rekening',
|
|
|
|
'new_request' => json_encode($data),
|
|
|
|
'description' => 'Create Parameter Rekening',
|
|
|
|
'status' => '0',
|
|
|
|
'ref' => $this->kode
|
|
|
|
];
|
|
|
|
|
|
|
|
$is_approval = Approval::where('menu', 'Parameter Rekening')
|
|
|
|
->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-15 08:05:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Reset the form fields after successful submission
|
|
|
|
$this->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update($id)
|
|
|
|
{
|
|
|
|
$this->edit_mode = true;
|
|
|
|
|
|
|
|
$rekening = Rekening::find($id);
|
|
|
|
|
|
|
|
$this->id = $rekening->id;
|
|
|
|
$this->nomor_rekening = $rekening->nomor_rekening;
|
|
|
|
$this->branch_id = $rekening->branch_id;
|
|
|
|
$this->debitur_id = $rekening->debitur_id;
|
2023-12-13 14:23:49 +00:00
|
|
|
$this->loan_type_id = $rekening->loan_type_id;
|
2023-11-15 08:05:46 +00:00
|
|
|
$this->currency_id = $rekening->currency_id;
|
|
|
|
$this->status = $rekening->status == 1 ? true : false;
|
|
|
|
$this->status_rekening = $rekening->status_rekening == 1 ? true : false;
|
2023-12-13 14:23:49 +00:00
|
|
|
$this->limit_ref = $rekening->limit_ref;
|
2023-11-15 08:05:46 +00:00
|
|
|
$this->registered_at = $rekening->registered_at;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($id)
|
|
|
|
{
|
2023-12-26 06:35:41 +00:00
|
|
|
$rekening = Rekening::find($id);
|
2023-12-26 06:45:38 +00:00
|
|
|
$rekening->delete_by = auth()->user()->id;
|
|
|
|
$rekening->deleted_at = now();
|
2023-11-15 08:05:46 +00:00
|
|
|
|
2023-12-26 06:35:41 +00:00
|
|
|
$approval = [
|
|
|
|
'method' => 'delete',
|
|
|
|
'menu' => 'Parameter Rekening',
|
|
|
|
'old_request' => json_encode($rekening),
|
|
|
|
'description' => 'Delete Parameter Rekening',
|
|
|
|
'status' => '0',
|
|
|
|
'ref' => $rekening->nomor_rekening
|
|
|
|
];
|
|
|
|
|
|
|
|
$is_approval = Approval::where('menu', 'Parameter Rekening')
|
|
|
|
->where('ref', $rekening->nomor_rekening)
|
|
|
|
->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-15 08:05:46 +00:00
|
|
|
}
|
|
|
|
|
2024-01-10 04:51:13 +00:00
|
|
|
public function reload()
|
|
|
|
{
|
|
|
|
$this->edit_mode = false;
|
|
|
|
$this->reset();
|
|
|
|
}
|
|
|
|
|
2023-11-15 08:05:46 +00:00
|
|
|
public function hydrate()
|
|
|
|
{
|
|
|
|
$this->resetErrorBag();
|
|
|
|
$this->resetValidation();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function rules()
|
|
|
|
{
|
|
|
|
if ($this->edit_mode) {
|
|
|
|
$request = new UpdateRekeningRequest();
|
|
|
|
} else {
|
|
|
|
$request = new StoreRekeningRequest();
|
|
|
|
}
|
|
|
|
return $request->rules();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|