update hapus buku

This commit is contained in:
daengdeni 2023-12-14 16:59:57 +07:00
parent cf333c5a4d
commit 3d737ebd8d
9 changed files with 136 additions and 37 deletions

View File

@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Builder as QueryBuilder;
use Illuminate\Support\Number;
use Modules\Writeoff\Entities\Branch;
use Modules\Writeoff\Entities\Debitur;
use Modules\Writeoff\Entities\FacilityType;
use Modules\Writeoff\Entities\LoanType;
use Modules\Writeoff\Entities\HapusBuku;
@ -61,6 +62,8 @@
})->addIndexColumn()->editColumn('tanggal_hapus_buku', function ($row) {
$date = Carbon::create($row->tanggal_hapus_buku);
return $date->locale('id')->translatedFormat('d F Y');
})->editColumn('debitur', function ($row) {
return Debitur::where('kode', $row->kode_debitur)->first()->name;
})->editColumn('cabang', function ($row) {
return Branch::where('kode', $row->kode_cabang)->first()->name;
})->editColumn('jenis_pinjaman', function ($row) {

View File

@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Modules\Writeoff\Entities\GuaranteeType;
return new class extends Migration {
/**
* Run the migrations.
*/
public function up()
: void
{
Schema::create('detail_jaminan', function (Blueprint $table) {
$table->id();
$table->string('nomor_pinjaman');
$table->foreignIdFor(GuaranteeType::class);
$table->string('nomor_jaminan');
$table->double('nilai_jaminan', 20, 2);
$table->boolean('status')->default(true)->nullable();
$table->timestamps();
$table->timestamp('authorized_at')->nullable();
$table->char('authorized_status', 1)->nullable();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->unsignedBigInteger('authorized_by')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down()
: void
{
Schema::dropIfExists('detail_jaminan');
}
};

View File

@ -30,9 +30,9 @@
return $this->belongsTo(Debitur::class);
}
public function product()
public function loan_type()
{
return $this->belongsTo(Product::class);
return $this->belongsTo(LoanType::class);
}
public function currency()

View File

@ -1,5 +1,4 @@
<?php
namespace Modules\Writeoff\Http\Controllers;
use App\Http\Controllers\Controller;

View File

@ -3,15 +3,17 @@
namespace Modules\Writeoff\Http\Controllers;
use App\Http\Controllers\Controller;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Modules\Writeoff\DataTables\HapusBukuDataTable;
use Modules\Writeoff\Entities\Branch;
use Modules\Writeoff\Entities\Currency;
use Modules\Writeoff\Entities\FacilityType;
use Modules\Writeoff\Entities\HapusBuku;
use Modules\Writeoff\Entities\LoanType;
use Modules\Writeoff\Entities\Rekening;
use function Termwind\render;
use Modules\Writeoff\Http\Requests\HapusBuku\StoreHapusBukuRequest;
class HapusBukuController extends Controller
{
@ -38,9 +40,9 @@
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
}
if($request->rekening){
if ($request->rekening) {
return redirect()->route('pencatatan.hapus_buku.create', ['rekening' => $request->rekening]);
}else{
} else {
return $dataTable->render('writeoff::pencatatan.hapus_buku.index', ['add' => false]);
}
}
@ -69,20 +71,30 @@
$totalbayar = 0;
$rekening = Rekening::with('product', 'debitur','branch','currency')
->where('nomor_rekening', $request->rekening)
->whereDoesntHave('hapusBuku')
->whereHas('product', function ($query) {
$query->whereBetween('kode', [3000, 3999]);
})
->get()
->first();
$rekening = Rekening::with('loan_type', 'debitur', 'branch', 'currency')
->where('nomor_rekening', $request->rekening)
->whereDoesntHave('hapusBuku')
->whereHas('loan_type', function ($query) {
$query->whereBetween('kode', [3000, 3999]);
})
->get()
->first();
return view('writeoff::pencatatan.hapus_buku.add', compact('branch', 'loan_type', 'facility_type', 'currency','rekening','totalbayar'));
return view('writeoff::pencatatan.hapus_buku.add', compact('branch', 'loan_type', 'facility_type', 'currency', 'rekening', 'totalbayar'));
}
public function store(Request $request)
public function store(StoreHapusBukuRequest $request)
{
dd($request->all());
$validated = $request->validated();
if ($validated) {
try {
HapusBuku::create($validated);
echo json_encode(['status' => 'success', 'message' => 'Hapus Buku created successfully.']);
} catch (Exception $e) {
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
}
}
}

View File

@ -28,9 +28,9 @@
: array
{
return [
'nomor_pinjaman' => 'required|integer',
'kode_jenis_pinjaman' => 'required|integer',
'kode_debitur' => 'required|integer',
'nomor_pinjaman' => 'required|numeric|unique:hapus_buku,nomor_pinjaman',
'kode_jenis_pinjaman' => 'required|numeric',
'kode_debitur' => 'required|numeric',
'nama_debitur' => 'required|string',
'alamat_debitur' => 'nullable|string',
'npwp_debitur' => 'nullable|string',
@ -38,22 +38,22 @@
'kode_mata_uang' => 'required|string',
'tanggal_hapus_buku' => 'required|date|before:tomorrow',
'nomor_fasilitas' => 'required|string',
'kode_jenis_fasilitas' => 'required|integer',
'kode_jenis_fasilitas' => 'required|numeric',
'nilai_plafond_awal' => 'required|numeric',
'suku_bunga' => 'required|integer',
'suku_bunga' => 'required|numeric',
'baki_debet' => 'required|numeric',
'jumlah_bunga' => 'required|numeric',
'jumlah_kewajiban_lain' => 'nullable|numeric',
'total_kewajiban' => 'nullable|numeric',
'total_bunga_extra' => 'required|numeric',
'bunga_ekstra' => 'nullable|numeric',
'bunga_non_ekstra' => 'required|numeric',
'bunga_non_ekstra' => 'nullable|numeric',
'denda' => 'nullable|numeric',
'tagihan_lain' => 'required|numeric',
'tagihan_lain' => 'nullable|numeric',
'biaya_lain' => 'required|numeric',
'total_all_kewajiban' => 'nullable|numeric',
'memo_persetujuan' => 'nullable|string',
'lama_hari' => 'nullable|integer',
'lama_hari' => 'nullable|numeric',
'proses_hukum' => 'nullable|string',
'komitmen_debitur' => 'nullable|string',
'keterangan' => 'nullable|string',
@ -82,7 +82,7 @@
flash($value[0]);
}
return redirect()
->route('pencatatan.hapus_buku.index')
->route('pencatatan.hapus_buku.create')
->with('error', 'Hapus Buku created failed.');
}
@ -100,4 +100,13 @@
'messages' => 'Hapus Buku created failed.'
], JsonResponse::HTTP_UNPROCESSABLE_ENTITY));
}
protected function prepareForValidation()
: void
{
$this->merge([
'status' => $this->status=='on' ? 1 : 0,
]);
}
}

View File

@ -3,12 +3,17 @@
namespace Modules\Writeoff\Livewire\HapusBuku;
use Livewire\Component;
use Modules\Writeoff\Entities\HapusBuku;
use Modules\Writeoff\Entities\Rekening;
class NomorPinjamanModal extends Component
{
public $nomor_pinjaman;
protected $listeners = [
'delete' => 'delete'
];
public function render()
{
return view('writeoff::livewire.hapus-buku.nomor-pinjaman-modal');
@ -20,16 +25,16 @@
'nomor_pinjaman' => 'required',
]);
$rekenings = Rekening::with('product', 'debitur')
$rekenings = Rekening::with('loan_type', 'debitur')
->where('nomor_rekening', $this->nomor_pinjaman)
->whereDoesntHave('hapusBuku')
->whereHas('product', function ($query) {
->whereHas('loan_type', function ($query) {
$query->whereBetween('kode', [3000, 3999]);
})
->get()
->first();
if ($rekenings->count() > 0) {
if ($rekenings) {
$this->dispatch('success', __('Nomor Pinjaman ditemukan'));
$this->redirect(route('pencatatan.hapus_buku.index', ['rekening' => $this->nomor_pinjaman]));
} else {
@ -37,7 +42,14 @@
}
//$this->dispatch('showHapusBuku');
}
public function delete($id)
{
HapusBuku::destroy($id);
// Emit a success event with a message
$this->dispatch('success', 'Hapus Buku successfully deleted');
}
}

View File

@ -43,11 +43,11 @@
<label class="required fw-semibold fs-6 mb-2">Jenis Pinjaman</label>
<!--end::Label-->
<!--begin::Input-->
<select wire:model.defer="kode_jenis_pinjaman" disabled name="kode_jenis_pinjaman" data-control="select2" data-placeholder="Pilih Jenis Pinjaman" class="form-control form-control-solid mb-3 mb-lg-0">
<select name="kode_jenis_pinjaman" data-control="select2" data-placeholder="Pilih Jenis Pinjaman" class="form-control form-control-solid mb-3 mb-lg-0">
<option value="">Jenis Pinjaman</option>
@foreach($loan_type as $item)
@php $selected = ''; @endphp
@if($item->kode == $rekening->product->kode)
@if($item->kode == $rekening->loan_type->kode)
@php $selected = 'selected'; @endphp
@endif
<option value="{{ $item->kode }}" {{ $selected }}>{{ $item->kode }} - {{ $item->name }}</option>
@ -114,7 +114,7 @@
<label class="required fw-semibold fs-6 mb-2">Cabang</label>
<!--end::Label-->
<!--begin::Input-->
<select disabled name="kode_cabang" data-control="select2" data-placeholder="Pilih Cabang" class="form-control form-control-solid mb-3 mb-lg-0">
<select name="kode_cabang" data-control="select2" data-placeholder="Pilih Cabang" class="form-control form-control-solid mb-3 mb-lg-0">
<option value="">Cabang</option>
@foreach($branch as $item)
@php $selected = ''; @endphp
@ -133,7 +133,7 @@
<label class="required fw-semibold fs-6 mb-2">Mata Uang</label>
<!--end::Label-->
<!--begin::Input-->
<select disabled name="kode_mata_uang" id="kode_mata_uang" data-control="select2" data-placeholder="Pilih Mata Uang" class="form-control form-control-solid mb-3 mb-lg-0">
<select name="kode_mata_uang" id="kode_mata_uang" data-control="select2" data-placeholder="Pilih Mata Uang" class="form-control form-control-solid mb-3 mb-lg-0">
<option value="">Mata Uang</option>
@foreach($currency as $item)
@php $selected = ''; @endphp
@ -382,7 +382,7 @@
<!--end::Input group-->
<div class="fv-row mb-7"><label class="fw-semibold fs-6 mb-2">Status Data</label>
<div class="form-check form-switch form-check-custom form-check-solid" style="display: block!important;">
<input class="form-check-input h-20px w-30px me-5" type="checkbox" wire:model.defer="status" id="status" name="status"/>
<input class="form-check-input h-20px w-30px me-5" type="checkbox" value="1" id="status" name="status"/>
<label class="form-check-label" for="status">
Aktif
</label>
@ -421,6 +421,30 @@
});
$(function () {
$("#kt_modal_add_hapus_buku_form").submit(function (e) {
e.preventDefault(); // avoid to execute the actual submit of the form.
var form = $(this);
var actionUrl = form.attr('action');
$.ajax({
type: "POST",
url: actionUrl,
data: form.serialize(),
success: function (data) {
var _data = JSON.parse(data);
toastr.success(_data.message);
window.location.href = "{{ route('pencatatan.hapus_buku.index') }}";
},
error: function (data, textStatus, errorThrown) {
var errors = data.responseJSON.errors;
$.each(errors, function (key, value) {
toastr.error(value);
});
}
});
});
$('#baki_debet,#suku_bunga,#jumlah_bunga,#jumlah_kewajiban_lain,#lama_hari').on('change', function () {
calcTotKewajiban();
})
@ -482,8 +506,8 @@
function calcTotAllKewajiban() {
var total;
var biaya_lain = $('#biaya_lain').val() ?? 0;
var denda = $('#denda').val() ?? 0;
var biaya_lain = $('#biaya_lain').val() === '' ? 0 : $('#biaya_lain').val();
var denda = $('#denda').val() === '' ? 0 : $('#denda').val();
total = parseFloat($('#total_kewajiban').val()) +
parseFloat($('#total_bunga_extra').val()) + parseFloat($('#bunga_extra').val()) + parseFloat(denda) + parseFloat(biaya_lain);

View File

@ -66,7 +66,6 @@
});
document.addEventListener('livewire:initialized', function () {
Livewire.on('success', function () {
$('#kt_modal_add_hapus_buku').modal('show');
$('#kt_modal_nomor_pinjaman').modal('hide');
window.LaravelDataTables['hapus-buku-table'].ajax.reload();
});