2085 lines
101 KiB
PHP
2085 lines
101 KiB
PHP
@extends('layouts.app')
|
|
@section('content')
|
|
@include('modal.editmarhun')
|
|
|
|
|
|
@php
|
|
if($customer_info['kpbaru'] != null){
|
|
$noic = $customer_info['kpbaru'];
|
|
}else{
|
|
$noic = $customer_info['kplama'];
|
|
}
|
|
$gadai_session = Http::withOptions(['verify' => config('app.api_verify')])->get($api_url . '/api/check/sag',['kodcaw'=>$cawangan_info['kodcaw'],'norujukan'=>$norujukan,'nokp'=>$noic])->json();
|
|
$outstanding_semasa = Http::withOptions(['verify' => config('app.api_verify')])->get($api_url . '/api/gadai/customers/'. $noic .'/outstandingsemasa/'.$cawangan_info['kodcaw'])->json();
|
|
@endphp
|
|
|
|
@if($gadai_session != null)
|
|
<div class="p-4">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-12 col-lg-12">
|
|
|
|
<nav aria-label="breadcrumb">
|
|
<ol class="breadcrumb pb-3">
|
|
<li class="breadcrumb-item"><a href="#">Home</a></li>
|
|
<li class="breadcrumb-item"><a href="#">Pelanggan</a></li>
|
|
<li class="breadcrumb-item active" aria-current="page">Pembiayaan</li>
|
|
</ol>
|
|
</nav>
|
|
|
|
<div class="form-group row col-12">
|
|
<input type="hidden" name="kodcaw" id="kodcaw" value="{{$cawangan_info['kodcaw']}}">
|
|
<input type="hidden" name="nokp" id="nokp" value="{{ $customer_info['kpbaru'] }}">
|
|
|
|
</div>
|
|
<div class="col-12 mb-2">
|
|
<div class="form-group row">
|
|
<div class="col-6 text-left">
|
|
<div class="form-group row">
|
|
<div class="col-md-4">
|
|
<b>No Rujukan</b>
|
|
</div>
|
|
<div class="col-md-8">
|
|
<input type="text" class="form-control" name="norujukan" id="norujukan" readonly value="{{ $norujukan }}">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 text-left">
|
|
<div class="form-group row">
|
|
<div class="col-md-4">
|
|
<b>Baki Limit Pembiayaan</b>
|
|
</div>
|
|
<div class="col-md-8">
|
|
@php
|
|
$limit_pinjaman_semasa = 300000 - $outstanding_semasa;
|
|
@endphp
|
|
<input type="text" class="form-control" name="limit_pinjaman" id="limit_pinjaman" readonly value="{{ number_format($limit_pinjaman_semasa,2) }}">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-12 text-right">
|
|
<button type="button" style="margin:auto" class="btn btn-primary" data-toggle="modal" data-target="#daftar_marhun">Daftar Marhun</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<!-- Toggle Button -->
|
|
<div class="mb-3">
|
|
<button type="button" class="btn btn-info" id="toggleTableBtn">
|
|
<i class="fas fa-exchange-alt"></i> Papar Margin
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Main Marhun Table -->
|
|
<table class="table table-striped table-hover text-center" id="myTable">
|
|
<thead class="thead-dark">
|
|
<tr>
|
|
<th>Bil</th>
|
|
<th>Recno</th>
|
|
<th>Marhun</th>
|
|
<th>Nilai Marhun</th>
|
|
<th>Karat</th>
|
|
<th>Berat</th>
|
|
<th>Kuantiti</th>
|
|
<th>Nota</th>
|
|
<th>Harga</th>
|
|
<th>Batu Permata</th>
|
|
<th>Berat Permata</th>
|
|
<th>Tindakan</th>
|
|
</tr>
|
|
</thead>
|
|
<tfoot class="thead-dark">
|
|
<th colspan="3" class="text-center">Jumlah</th>
|
|
<th id="totalnilaimarhuntable"></th>
|
|
<th></th>
|
|
<th id="totalberattable"></th>
|
|
<th id="totalkuantititable"></th>
|
|
<th colspan="5"></th>
|
|
</tfoot>
|
|
</table>
|
|
|
|
<!-- Margin Summary Table (Hidden by default) -->
|
|
<table class="table table-striped table-hover text-center" id="marginTable" style="display: none;">
|
|
<thead class="thead-dark">
|
|
<tr>
|
|
<th>Bil</th>
|
|
<th>Karat</th>
|
|
<th>Nilai Marhun</th>
|
|
<th>Margin Teller (%)</th>
|
|
<th>Margin PC (%)</th>
|
|
<th>Pembiayaan Teller</th>
|
|
<th>Pembiayaan PC</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="marginTableBody">
|
|
<!-- Data will be populated by JavaScript -->
|
|
</tbody>
|
|
<tfoot class="thead-dark">
|
|
<tr>
|
|
<th>Jumlah</th>
|
|
<th></th>
|
|
<th id="totalNilaiMarhunMargin"></th>
|
|
<th></th>
|
|
<th></th>
|
|
<th id="totalNilaiTellerMargin"></th>
|
|
<th id="totalNilaiPCMargin"></th>
|
|
</tr>
|
|
</tfoot>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<form name="gadaistore" action="{{ route('gadai.store') }}" method='post' onsubmit="return verifyGadai(this)">
|
|
<!-- <form action="{{ route('gadai.store') }}" method='post' name="gadaistore" id="gadaistore"> -->
|
|
@csrf
|
|
<div class="col-12 form-group row">
|
|
<div class="col-md-5">
|
|
<div class="form-group row">
|
|
<div class="col-5">
|
|
Pembiayaan Maks
|
|
</div>
|
|
<div class="col-7 input-group">
|
|
<input type="text" style="height:50px !important" class="form-control" readonly name="pembiayaan_max_teller" id="pembiayaan_max_teller">
|
|
<div class="input-group-append">
|
|
<span class="input-group-text span-pinjaman-max"></span>
|
|
</div>
|
|
</div>
|
|
</diV>
|
|
</div>
|
|
<div class="col-4">
|
|
<div class="form-group row">
|
|
<div class="col-md-6">
|
|
Pendapatan Sebulan
|
|
</div>
|
|
<div class="col-md-6">
|
|
<input type="text" class="form-control" readonly name="keuntungan_sebulan" id="keuntungan_sebulan">
|
|
</div>
|
|
</diV>
|
|
</div>
|
|
<div class="col-3">
|
|
<div class="form-group row">
|
|
<div class="col-md-6">
|
|
Lain-Lain Caj
|
|
</div>
|
|
<div class="col-md-6">
|
|
<input type="text" class="form-control" readonly name="ujrah" id="ujrah">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{{-- <div class="col-1">
|
|
<div class="form-group row">
|
|
</div>
|
|
</div> --}}
|
|
<div class="col-md-5">
|
|
<div class="form-group row">
|
|
<div class="col-5">
|
|
Pembiayaan
|
|
</div>
|
|
<div class="col-7 input-group">
|
|
<input type="text" class="form-control" onpaste="return false;" ondrop="return false;" onkeypress="return validateFloatKeyPress(this,event);" name="pinjaman" id="pinjaman">
|
|
<div class="input-group-append">
|
|
<span class="input-group-text span-pinjaman">0 %</span>
|
|
</div>
|
|
</div>
|
|
</diV>
|
|
</div>
|
|
<div class="col-4">
|
|
<div class="form-group row">
|
|
<div class="col-md-6">
|
|
Pendapatan 6 Bulan
|
|
</div>
|
|
<div class="col-md-6">
|
|
<input type="text" class="form-control" readonly name="keuntungan_6bln" id="keuntungan_6bln">
|
|
</div>
|
|
</diV>
|
|
</div>
|
|
<div class="col-3">
|
|
<div class="form-group row">
|
|
<div class="col-md-6">
|
|
Keuntungan
|
|
</div>
|
|
<div class="col-md-6">
|
|
<input type="text" class="form-control" readonly name="onepercent" id="onepercent">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-5">
|
|
<div class="form-group row">
|
|
<div class="col-md-5">
|
|
Pembiayaan Maks Pelulus
|
|
</div>
|
|
<div class="col-md-7 input-group">
|
|
<input type="text" class="form-control" readonly name="pembiyaan_max_pelulus" id="pembiyaan_max_pelulus">
|
|
<div class="input-group-append">
|
|
<span class="input-group-text span-pinjaman-max-pelulus"></span>
|
|
</div>
|
|
</div>
|
|
</diV>
|
|
</div>
|
|
<div class="col-12">
|
|
<input type="text" name="norujukan_gadai" id="norujukan_gadai" value="{{ $norujukan }}" hidden>
|
|
<input type="text" name="marhun_detail" id="marhun_detail" value="" hidden>
|
|
<input type="text" name="total_berat" id="total_berat" value="" hidden>
|
|
<input type="text" name="kadarkeuntungan" id="kadarkeuntungan" value="" hidden>
|
|
<input type="text" name="kuantiti_marhun" id="kuantiti_marhun" value="" hidden>
|
|
<input type="text" name="total_nilai_marhun" id="total_nilai_marhun" value="" hidden>
|
|
<input type="text" name="nokp" id="nokp" value="{{ !empty($customer_info['kpbaru']) ? $customer_info['kpbaru'] : ($customer_info['kplama'] ?? '') }}" hidden>
|
|
<a href="{{ route('gadai.batal',['norujukan'=>$norujukan]) }}" class="float-right btn btn-danger mr-2">Batal</a>
|
|
<input type="submit" name="terima_gadai" id="terima_gadai" class="float-right btn btn-primary mr-2" value="Terima">
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<!-- modal daftar marhun-->
|
|
<div class="modal fade" id="daftar_marhun" tabindex="-1" data-backdrop="static" aria-labelledby="ModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="ModalLabel">Daftar Marhun</h5>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form action="" id="maklumat_marhun" method="post">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6">
|
|
<div class="form-group row">
|
|
<input type="hidden" name="kodcaw" id="kodcaw" value="">
|
|
<div class="col-md-4">No Rujukan</div>
|
|
<div class="col-md-8"><input class="form-control" type="text" name="norujukan_marhun" id="norujukan_marhun" value="{{ $norujukan }}"></div>
|
|
<div class="col-md-4">Marhun</div>
|
|
<div class="col-md-8">
|
|
<select class="form-control" name="marhun" id="marhun">
|
|
<option disabled selected value> -- Pilih Jenis Marhun -- </option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-12">
|
|
<div class="form-group">
|
|
<label>Nota</label>
|
|
<select name="nota" id="nota" class="select2 form-control" multiple="multiple" data-placeholder="Nota Tambahan" style="width: 100%;">
|
|
<option value="Rosak">Rosak</option>
|
|
<option value="Putus">Putus</option>
|
|
<option value="Patah">Patah</option>
|
|
<option value="Sebelah">Sebelah</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-4">Kuantiti</div>
|
|
<div class="col-md-8">
|
|
<input class="form-control" name="kuantiti" id="kuantiti" type="text" pattern="\d*" maxlength="2" disabled>
|
|
</div>
|
|
|
|
<div class="col-md-4">Karat</div>
|
|
<div class="col-md-8">
|
|
<select class="form-control" name="karat" id="karat">
|
|
<option disabled selected value> -- Pilih Karat -- </option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4">Berat Bersih</div>
|
|
<div class="col-md-8"><input class="form-control" type="text" name="berat_emas" id="berat_emas"></div>
|
|
<div class="col-md-4">Harga</div>
|
|
<div class="col-md-8"><input class="form-control" type="text" name="harga" id="harga" readonly></div>
|
|
<div class="col-md-4">Nilai Marhun</div>
|
|
<div class="col-md-8"><input class="form-control" type="text" name="nilai_marhun" id="nilai_marhun" readonly></div>
|
|
<div class="col-md-4">Bilangan Marhun</div>
|
|
<div class="col-md-8"><input class="form-control" type="text" name="bilangan_marhun" id="bilangan_marhun" readonly></div>
|
|
<div class="col-md-4">Jumlah Kuantiti</div>
|
|
<div class="col-md-8"><input class="form-control" type="text" name="bilangan_jumlah_kuantiti" id="bilangan_jumlah_kuantiti" readonly></div>
|
|
<div class="col-md-4">Jumlah Nilai Marhun</div>
|
|
<div class="col-md-8"><input class="form-control" type="text" name="jumlah_nilai_marhun" id="jumlah_nilai_marhun" readonly></div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6" id="col_right" style="display: none">
|
|
<div class="form-group row">
|
|
<div class="col-md-12">
|
|
<div class="form-group">
|
|
<div class="d-flex justify-content-between">
|
|
<span>Ada Batu Permata?</span>
|
|
<div>
|
|
<label for="tagpermata">Ya</label>
|
|
<input type="checkbox" id="tagpermata" name="tagpermata">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex" id="divanggaran" style="visibility: hidden">
|
|
<div class="col-8">Anggaran Berat Permata</div>
|
|
<div class="col-4"><input class="form-control" type="text" name="beratpermata" id="beratpermata" autocomplete="off"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<div class="form-group row">
|
|
<input class="btn btn-primary mr-2" type="button" name="tambah_marhun" id="tambah_marhun" value="Tambah">
|
|
<input class="btn btn-primary mr-2" type="button" name="terima_marhun" id="terima_marhun" value="Terima">
|
|
<button type="button" class="btn btn-danger" name="batal_marhun" id="batal_marhun">Batal</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@else
|
|
@php
|
|
header("Refresh:0");
|
|
@endphp
|
|
@endif
|
|
<script src="{{ asset('js/rounded-methods.js') }}"></script>
|
|
<script>
|
|
var api_url = "<?php echo $api_url ?>";
|
|
var kodcaw_ujrah = "<?php echo $cawangan_info['kodcaw'] ?>";
|
|
$('form input').keydown(function (e) {
|
|
if (e.keyCode == 13) {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
});
|
|
function disableF5(e) { if ((e.which || e.keyCode) == 116) e.preventDefault(); };
|
|
$(document).ready( function () {
|
|
$(document).on("keydown", disableF5);
|
|
var norujukan = $('#norujukan').val();
|
|
getMarhun(norujukan);
|
|
|
|
$.ajax({
|
|
method:'GET',
|
|
url: api_url + '/api/jemas',
|
|
success:function(data){
|
|
$.each(data,function(index,jemas){
|
|
$("#marhun").append(new Option(jemas['descpt'], jemas['marhun']));
|
|
})
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
method:'GET',
|
|
url: api_url + '/api/harga_emas',
|
|
success:function(data){
|
|
$.each(data,function(index,harga_emas){
|
|
var text = harga_emas['karat']+' - '+harga_emas['keterangan'];
|
|
$("#karat").append(new Option(text, harga_emas['karat']));
|
|
})
|
|
}
|
|
});
|
|
});
|
|
|
|
function getMarhun(norujukan){
|
|
$.ajax({
|
|
method:'GET',
|
|
url: api_url + '/api/marhun/'+norujukan,
|
|
success:function(data){
|
|
marhuntable(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
let arrayBatuPermata = [
|
|
'DNR',
|
|
'SYE',
|
|
'WFR',
|
|
'G/B',
|
|
];
|
|
|
|
$('#marhun').change(function(){
|
|
var marhun = this.value;
|
|
|
|
if (!arrayBatuPermata.includes(marhun)) {
|
|
$("#col_right").css("display", "block");
|
|
} else {
|
|
$("#col_right").css("display", "none");
|
|
$('#tagpermata').prop('checked', false);
|
|
$("#divanggaran").css("visibility", "hidden");
|
|
$('#beratpermata').val("");
|
|
}
|
|
|
|
var marh = $(this).find(':selected').val();
|
|
|
|
$('#kuantiti').val('');
|
|
|
|
$('#karat').val('');
|
|
if(marh == 'G/B' || marh == 'WFR' || marh == 'SYE' || marh == 'DNR'){
|
|
if(marh == 'DNR' || marh == 'SYE'){
|
|
$('#karat option').show();
|
|
$('#karat option').not('[value="21.0K"]').not('[value="22.0K"]').not('[value="23.0K"]').not('[value="24.0K"]').not('[value="24.0Kgb"]').not(':first').hide();
|
|
}else{
|
|
$('#karat option').show();
|
|
$('#karat option').not('[value="21.0K"]').not('[value="22.0K"]').not('[value="23.0K"]').not('[value="24.0K"]').not('[value="24.0Kgb"]').not(':first').hide();
|
|
}
|
|
|
|
$('#text-berat').html('Berat Keseluruhan');
|
|
$('#kuantiti').attr('disabled', false);
|
|
}else{
|
|
$('#karat option').show();
|
|
$('#text-berat').html('Berat');
|
|
$('#kuantiti').attr('disabled', true);
|
|
}
|
|
|
|
});
|
|
|
|
$('#tagpermata').change(function () {
|
|
if($('#tagpermata').is(':checked')) {
|
|
$("#divanggaran").css("visibility", "visible");
|
|
} else {
|
|
$("#divanggaran").css("visibility", "hidden");
|
|
$('#beratpermata').val("");
|
|
}
|
|
});
|
|
|
|
$('#tagpermataedit').change(function () {
|
|
if($('#tagpermataedit').is(':checked')) {
|
|
$(".div_anggaran_edit").css("display", "block");
|
|
} else {
|
|
$(".div_anggaran_edit").css("display", "none");
|
|
$('#beratpermataedit').val("");
|
|
}
|
|
});
|
|
|
|
$('#marhun_edit').change(function(){
|
|
var marhun = this.value;
|
|
|
|
if (!arrayBatuPermata.includes(marhun)) {
|
|
$(".col_edit_permata").css("display", "block");
|
|
} else {
|
|
$(".col_edit_permata").css("display", "none");
|
|
$('#tagpermataedit').prop('checked', false);
|
|
$(".div_anggaran_edit").css("display", "none");
|
|
$('#beratpermataedit').val("");
|
|
}
|
|
|
|
if(marhun == 'G/B' || marhun == 'WFR' || marhun == 'SYE' || marhun == 'DNR'){
|
|
if(marhun == 'DNR' || marhun == 'SYE'){
|
|
$('#sltkarat option').show();
|
|
$('#sltkarat option').not('[value="21.0K"]').not('[value="22.0K"]').not('[value="23.0K"]').not('[value="24.0K"]').not('[value="24.0Kgb"]').not(':first').hide();
|
|
}else{
|
|
$('#sltkarat option').show();
|
|
$('#sltkarat option').not('[value="21.0K"]').not('[value="22.0K"]').not('[value="23.0K"]').not('[value="24.0K"]').not('[value="24.0Kgb"]').not(':first').hide();
|
|
}
|
|
|
|
$('#text-berat').html('Berat Keseluruhan');
|
|
$('#kuantiti_edit').attr('disabled', false);
|
|
}else{
|
|
$('#kuantiti_edit').val(1);
|
|
$('#sltkarat option').show();
|
|
$('#text-berat').html('Berat');
|
|
$('#kuantiti_edit').attr('disabled', true);
|
|
}
|
|
});
|
|
|
|
$('#karat').change(function(){
|
|
var karat = this.value;
|
|
karat = karat.replace(/\./g,'-');
|
|
var berat = $('#berat_emas').val();
|
|
getHargaEmas(karat,berat)
|
|
});
|
|
|
|
$('#berat_emas').on('input',function(){
|
|
var berat = this.value;
|
|
var karat = $('#karat').val();
|
|
karat = karat.replace(/\./g,'-');
|
|
getHargaEmas(karat,berat);
|
|
})
|
|
|
|
$('#batal_marhun').click(function(){
|
|
|
|
$('#nota').val('').trigger("change");
|
|
$('#tagpermata').prop("checked", false);
|
|
$("#col_right").css("display", "none");
|
|
$("#divanggaran").css("visibility", "hidden");
|
|
$('#beratpermata').val("");
|
|
$('#marhun').val(0);
|
|
$('#karat').val(0);
|
|
$('#berat_emas').val("");
|
|
$('#harga').val("");
|
|
$('#nilai_marhun').val("");
|
|
$('#daftar_marhun').modal('hide');
|
|
})
|
|
|
|
function getHargaEmas(karat,berat){
|
|
$.ajax({
|
|
method:'GET',
|
|
url: api_url + '/api/harga_emas/'+karat,
|
|
success:function(data){
|
|
var nilai_marhun = data['harga'] * berat;
|
|
$('#harga').val(data['harga']);
|
|
$('#nilai_marhun').val(formatter.format(nilai_marhun));
|
|
}
|
|
})
|
|
}
|
|
|
|
var tablemarhun = $('#myTable').DataTable({
|
|
"ordering": false,
|
|
"columnDefs": [{
|
|
"targets": [1],
|
|
"visible": false,
|
|
"searchable": false
|
|
},
|
|
{
|
|
"targets": [7],
|
|
"visible": true,
|
|
"searchable": false
|
|
}
|
|
],
|
|
"language": {
|
|
"lengthMenu": "Papar _MENU_ rekod setiap halaman",
|
|
"zeroRecords": "Tiada rekod dijumpai",
|
|
"info": "Memapar halaman _PAGE_ dari _PAGES_",
|
|
"infoEmpty": "Tiada rekod tersedia",
|
|
"infoFiltered": "(ditapis dari _MAX_ jumlah rekod)",
|
|
"search": "Cari:",
|
|
"paginate": {
|
|
"first": "Pertama",
|
|
"last": "Akhir",
|
|
"next": "Seterusnya",
|
|
"previous": "Sebelumnya"
|
|
}
|
|
},
|
|
});
|
|
|
|
$(".select2").select2({
|
|
dropdownParent: $('#daftar_marhun'),
|
|
tags: true,
|
|
tokenSeparators: [',', ' '],
|
|
allowClear: true,
|
|
closeOnSelect: false
|
|
});
|
|
|
|
$(".select2_daftar_batu_permata").select2({
|
|
dropdownParent: $('#daftar_marhun'),
|
|
tags: true,
|
|
tokenSeparators: [',', ' '],
|
|
allowClear: true,
|
|
closeOnSelect: false
|
|
});
|
|
|
|
$(".select2_nota").select2({
|
|
dropdownParent: $('#editMarhunModal'),
|
|
tags: true,
|
|
tokenSeparators: [',', ' '],
|
|
allowClear: true,
|
|
closeOnSelect: false
|
|
});
|
|
|
|
$('#nota_edit').select2({
|
|
tags: true,
|
|
placeholder: "Select or add options",
|
|
width: 'resolve'
|
|
});
|
|
|
|
$(".select2_batupermata").select2({
|
|
dropdownParent: $('#editMarhunModal'),
|
|
tags: true,
|
|
tokenSeparators: [',', ' '],
|
|
allowClear: true,
|
|
closeOnSelect: false
|
|
});
|
|
|
|
var total_nilai_marhun = 0;
|
|
var total_berat = 0;
|
|
var total_kuantiti = 0;
|
|
var kadarupah = 0;
|
|
var jumlah_marhun = 0;
|
|
var jumlah_nilai_marhun = 0;
|
|
var pinjaman_pelulus = 0;
|
|
var pinjaman_teller = 0;
|
|
|
|
function marhuntable(data) {
|
|
var counter = 1;
|
|
total_nilai_marhun = 0;
|
|
total_berat = 0;
|
|
total_kuantiti = 0;
|
|
var marhun_details = '';
|
|
var array_mutu = [];
|
|
jumlah_nilai_marhun = 0;
|
|
tablemarhun.clear().draw();
|
|
$.each(data, function(index, marhun) {
|
|
$.each(marhun, function(index, marhun_detail) {
|
|
total_nilai_marhun = total_nilai_marhun + Number(marhun_detail['n_marhun']);
|
|
total_berat = total_berat + Number(marhun_detail['berat']);
|
|
marhun_details = marhun_details + marhun_detail['bil'] + " " + marhun_detail['marhun'] + ",";
|
|
jumlah_nilai_marhun += Number(marhun_detail['n_marhun']);
|
|
status_tag_permata = marhun_detail['tag_permata'] == 1 ? 'Ada' : '';
|
|
total_kuantiti += Number(marhun_detail['bil']);
|
|
array_mutu.push([marhun_detail['karat'], marhun_detail['n_marhun']]);
|
|
tablemarhun.row.add([
|
|
counter,
|
|
marhun_detail['recno'],
|
|
marhun_detail['marhun'],
|
|
formatter.format(marhun_detail['n_marhun']),
|
|
marhun_detail['karat'],
|
|
formatter.format(marhun_detail['berat']),
|
|
marhun_detail['bil'],
|
|
marhun_detail['nota'],
|
|
marhun_detail['harga'],
|
|
status_tag_permata,
|
|
marhun_detail['berat_batu_permata'],
|
|
"<div class='buttonpunya text-center'><button onclick='editmarhun(this)' class='btn btn-primary'><i class='fas fa-edit'></i></button> <button onclick='deletemarhun(this)' class='btn btn-danger'><i class='fas fa-trash-alt'></i></button></div>"
|
|
]).draw();
|
|
counter = counter + 1;
|
|
});
|
|
});
|
|
$('#totalberattable').text(formatter.format(total_berat));
|
|
$('#totalkuantititable').text(total_kuantiti);
|
|
$('#totalnilaimarhuntable').text(formatter.format(jumlah_nilai_marhun));
|
|
$('#bilangan_marhun').val(formatter.format(counter - 1));
|
|
$('#bilangan_jumlah_kuantiti').val(formatter.format(total_kuantiti));
|
|
$('#jumlah_nilai_marhun').val(formatter.format(jumlah_nilai_marhun));
|
|
|
|
|
|
$.ajax({
|
|
method:'GET',
|
|
url: api_url + '/api/kadarujrah',
|
|
async:false,
|
|
data:{
|
|
'nokp': $('#nokp').val(),
|
|
'nilaimarhun' : total_nilai_marhun,
|
|
'kodcaw' : kodcaw_ujrah
|
|
},
|
|
success:function(data){
|
|
kadarupah = data;
|
|
}
|
|
});
|
|
|
|
$('#total_nilai_marhun').val(formatter.format(total_nilai_marhun));
|
|
$('#marhun_detail').val(marhun_details);
|
|
$('#total_berat').val(formatter.format(total_berat));
|
|
$('#kadarkeuntungan').val(formatter.format(kadarupah));
|
|
$('#kuantiti_marhun').val(formatter.format(jumlah_marhun));
|
|
|
|
var max_teller = 0;
|
|
var max_pelulus = 0;
|
|
|
|
$.ajax({
|
|
method: 'GET',
|
|
url: api_url + '/api/maxpinjaman',
|
|
data: {
|
|
'mutu': array_mutu,
|
|
'total_nilai_marhun': total_nilai_marhun,
|
|
},
|
|
success: function(data) {
|
|
$.each(data, function(index, pinjaman) {
|
|
if (pinjaman['user_type'] == 'teller') {
|
|
pinjaman_teller = Number(pinjaman['max']);
|
|
max_teller = pinjaman['teller_pinjaman'];
|
|
}
|
|
if (pinjaman['user_type'] == 'khazanah') {
|
|
pinjaman_pelulus = Number(pinjaman['max']);
|
|
max_pelulus = pinjaman['pc_pinjaman'];
|
|
}
|
|
});
|
|
$('.span-pinjaman-max-pelulus').text(formatter.format(pinjaman_pelulus) + ' %');
|
|
$('.span-pinjaman-max').text(formatter.format(pinjaman_teller) + ' %');
|
|
$('#pembiayaan_max_teller').val(formatter.format(max_teller));
|
|
$('#pembiyaan_max_pelulus').val(formatter.format(max_pelulus));
|
|
}
|
|
});
|
|
}
|
|
|
|
$('#pinjaman').on('input',function(){
|
|
var pinjaman = Number(this.value);
|
|
var nilaimarhun = Number($('#jumlah_nilai_marhun').val());
|
|
var nokp = $('#nokp').val();
|
|
//console.log('DEBUG NOKP:', nokp, kadarupah);
|
|
|
|
|
|
// var keuntungan_sebulan = pinjaman * kadarupah;
|
|
// var keuntungan_6bln = keuntungan_sebulan * 6;
|
|
|
|
percent_pinjaman = (Number(pinjaman)/Number(total_nilai_marhun))*100;
|
|
|
|
let array_keuntungan = [];
|
|
|
|
$.ajax({
|
|
method:'POST',
|
|
url: api_url + '/api/onepercent',
|
|
async:false,
|
|
data:{
|
|
'nokp': nokp,
|
|
'nilaimarhun' : total_nilai_marhun,
|
|
'pembiayaan' : pinjaman,
|
|
'kadarujrah' : kadarupah,
|
|
'margin' : percent_pinjaman,
|
|
'kodcaw' : "{{ Auth::user()->cawangan }}"
|
|
},
|
|
success:function(data){
|
|
array_keuntungan = data;
|
|
}
|
|
});
|
|
|
|
var keuntungan_sebulan = getRoundedMethod(array_keuntungan['keuntungan']);
|
|
var keuntungan_6bln = getRoundedMethod(keuntungan_sebulan * 6);
|
|
|
|
$('.span-pinjaman').text(formatter.format(percent_pinjaman.toFixed(2)) + ' %');
|
|
$('#keuntungan_sebulan').val(formatter.format(keuntungan_sebulan.toFixed(2)));
|
|
$('#keuntungan_6bln').val(formatter.format(keuntungan_6bln.toFixed(2)));
|
|
$('#ujrah').val(formatter.format(getRoundedMethod(array_keuntungan['ujrah']).toFixed(2)));
|
|
$('#onepercent').val(formatter.format(getRoundedMethod(array_keuntungan['onepercent']).toFixed(2)));
|
|
|
|
});
|
|
|
|
const formatter = new Intl.NumberFormat('en-US', {
|
|
minimumFractionDigits: 2
|
|
});
|
|
|
|
$('#terima_marhun').click(function(){
|
|
$("#tambah_marhun").prop('disabled', true);
|
|
$("#terima_marhun").prop('disabled', true);
|
|
var kodcaw = $('#kodcaw').val();
|
|
var norujukan = $('#norujukan').val();
|
|
var marhun = $('#marhun').val();
|
|
var karat = $('#karat').val();
|
|
var berat_emas = $('#berat_emas').val();
|
|
var harga = $('#harga').val();
|
|
var nilaimarhun = $('#nilai_marhun').val();
|
|
var bilangan_marhun_daftar = Number($('#bilangan_marhun').val());
|
|
var nilai_marhun = Number(nilaimarhun.replace(/[^0-9.-]+/g,""));
|
|
var nota_array = $('#nota').val();
|
|
var berat_permata = $('#beratpermata').val();
|
|
var tag_permata = $('input[id=tagpermata]').is(':checked') ? 1 : 0;
|
|
var kuantiti = $('#kuantiti').val();
|
|
|
|
if(kuantiti > 10)
|
|
{
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Kuantiti tidak boleh melebihi 10'
|
|
});
|
|
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
if(nota_array != null){
|
|
var nota = nota_array.toString();
|
|
}else{
|
|
var nota = '';
|
|
}
|
|
|
|
if(marhun == null && karat == null && berat_emas == ''){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
$('#daftar_marhun').modal('hide');
|
|
}
|
|
else{
|
|
if(marhun == null){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Pilih Marhun'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
if(karat == null){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Pilih Karat'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
if($.isNumeric(berat_emas) == false){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Masukkan Berat Marhun'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
var resultValidation = validateBatuPermata(tag_permata, berat_permata);
|
|
if(resultValidation == false) {
|
|
return false;
|
|
}
|
|
|
|
if(bilangan_marhun_daftar<10){
|
|
//new added 190624 filter if gadaian already exist pinjaman not null
|
|
$.ajax({
|
|
method:'get',
|
|
url: api_url + '/api/gadai/norujukan/' + kodcaw + '/' + norujukan,
|
|
|
|
success:function(data)
|
|
{
|
|
var checking = Object.keys(data[0]).length;
|
|
|
|
if (data[0]['pinjaman'] > 0) {
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Tidak Berjaya',
|
|
text: 'Maklumat Pembiayaan Telah Wujud. Sila Tekan Batal.'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
|
|
} else {
|
|
$.ajax({
|
|
method:'POST',
|
|
url: api_url + '/api/marhun/'+kodcaw,
|
|
dataType:'json',
|
|
data: {
|
|
'norujukan': norujukan,
|
|
'marhun' : marhun,
|
|
'nota':nota,
|
|
'tag_permata':tag_permata,
|
|
'berat_batu_permata':berat_permata,
|
|
'karat' : karat,
|
|
'berat_emas' :berat_emas,
|
|
'harga' : harga,
|
|
'nilai_marhun' : nilai_marhun,
|
|
'teller' : "{{ Auth::user()->name }}",
|
|
'kuantiti' : (kuantiti) ? kuantiti : 1
|
|
},
|
|
success:function(data){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
$('#nota').val('').trigger("change");
|
|
$('#beratpermata').val("");
|
|
$('#marhun').val(0);
|
|
$('#karat').val(0);
|
|
$('#berat_emas').val("");
|
|
$('#harga').val("");
|
|
$('#nilai_marhun').val("");
|
|
$('#daftar_marhun').modal('hide');
|
|
$("#col_right").css("display", "none");
|
|
$('#tagpermata').prop('checked', false);
|
|
$('#beratpermata').val("");
|
|
$("#divanggaran").css("visibility", "hidden");
|
|
|
|
$('#kuantiti').val("");
|
|
$('#kuantiti').attr('disabled', true);
|
|
|
|
jumlah_marhun += 1;
|
|
jumlah_nilai_marhun += Number(nilai_marhun);
|
|
$('#bilangan_marhun').val(formatter.format(jumlah_marhun));
|
|
$('#jumlah_nilai_marhun').val(formatter.format(jumlah_nilai_marhun));
|
|
getMarhun(norujukan);
|
|
},
|
|
error: function(xhRequest, ErrorText, thrownError){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Tambah Marhun Tidak Berjaya'
|
|
});
|
|
console.log(xhRequest);
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
});
|
|
//end new added 190624
|
|
|
|
}else{
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Hanya 10 Marhun dibenarkan dalam 1 SAG'
|
|
});
|
|
$('#daftar_marhun').modal('hide');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
$('#tambah_marhun').click(function(){
|
|
$("#tambah_marhun").prop('disabled', true);
|
|
$("#terima_marhun").prop('disabled', true);
|
|
var kodcaw = $('#kodcaw').val();
|
|
var norujukan = $('#norujukan').val();
|
|
var marhun = $('#marhun').val();
|
|
var karat = $('#karat').val();
|
|
var berat_emas = $('#berat_emas').val();
|
|
var harga = $('#harga').val();
|
|
var nilaimarhun = $('#nilai_marhun').val();
|
|
var bilangan_marhun_daftar = Number($('#bilangan_marhun').val());
|
|
var nilai_marhun = Number(nilaimarhun.replace(/[^0-9.-]+/g,""));
|
|
var nota_array = $('#nota').val();
|
|
var batu_permata_array = $('#batupermata').val();
|
|
var tag_permata = $('input[id=tagpermata]').is(':checked') ? 1 : 0;
|
|
|
|
var beratpermata = $('#beratpermata').val();
|
|
var kuantiti = $('#kuantiti').val();
|
|
|
|
|
|
if(kuantiti > 10)
|
|
{
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Kuantiti tidak boleh melebihi 10'
|
|
});
|
|
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
if(nota_array != null){
|
|
var nota = nota_array.toString();
|
|
}else{
|
|
var nota = '';
|
|
}
|
|
|
|
if(marhun == null){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Pilih Marhun'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
if(karat == null){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Pilih Karat'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
if($.isNumeric(berat_emas) == false){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Masukkan Berat Marhun'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
var resultValidation = validateBatuPermata(tag_permata, beratpermata);
|
|
if(resultValidation == false) {
|
|
return false;
|
|
}
|
|
|
|
if(bilangan_marhun_daftar < 10){
|
|
//new added 190624 filter if gadaian already registered pinjaman > 0
|
|
$.ajax({
|
|
method:'get',
|
|
url: api_url + '/api/gadai/norujukan/' + kodcaw + '/' + norujukan,
|
|
|
|
success:function(data)
|
|
{
|
|
var checking = Object.keys(data[0]).length;
|
|
|
|
if (data[0]['pinjaman'] > 0) {
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Tidak Berjaya',
|
|
text: 'Maklumat Pembiayaan Telah Wujud. Sila Tekan Batal.'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
|
|
} else {
|
|
$.ajax({
|
|
method:'POST',
|
|
url: api_url + '/api/marhun/'+kodcaw,
|
|
dataType:'json',
|
|
data: {
|
|
'norujukan': norujukan,
|
|
'marhun' : marhun,
|
|
'nota':nota,
|
|
'tag_permata':tag_permata,
|
|
'berat_batu_permata':beratpermata,
|
|
'karat' : karat,
|
|
'berat_emas' :berat_emas,
|
|
'harga' : harga,
|
|
'nilai_marhun' : nilai_marhun,
|
|
'teller' : "{{ Auth::user()->name }}",
|
|
'kuantiti' : (kuantiti) ? kuantiti : 1
|
|
|
|
},
|
|
success:function(data){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
$('#nota').val('').trigger("change");
|
|
$('#batupermata').val('').trigger("change");
|
|
$('#beratpermata').val("");
|
|
$('#marhun').val(0);
|
|
$('#karat').val(0);
|
|
$('#berat_emas').val("");
|
|
$('#harga').val("");
|
|
$('#nilai_marhun').val("");
|
|
|
|
$('#kuantiti').val("");
|
|
$('#kuantiti').attr('disabled', true);
|
|
|
|
$("#col_right").css("display", "none");
|
|
$('#tagpermata').prop('checked', false);
|
|
$('#beratpermata').val("");
|
|
$("#divanggaran").css("visibility", "hidden");
|
|
|
|
jumlah_marhun += 1;
|
|
jumlah_nilai_marhun += Number(nilai_marhun);
|
|
$('#bilangan_marhun').val(formatter.format(jumlah_marhun));
|
|
$('#jumlah_nilai_marhun').val(formatter.format(jumlah_nilai_marhun));
|
|
getMarhun(norujukan);
|
|
},
|
|
error: function(xhRequest, ErrorText, thrownError){
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Tambah Marhun Tidak Berjaya'
|
|
});
|
|
console.log(xhRequest);
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
});
|
|
//end new added 190624
|
|
|
|
}else{
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Hanya 10 Marhun dibenarkan dalam 1 SAG'
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
function validateBatuPermata(tag, berat) {
|
|
function countDecimalPlaces(value) {
|
|
const match = value.match(/(?:\.(\d+))?$/);
|
|
if (!match || !match[1]) {
|
|
return 0;
|
|
}
|
|
return match[1].length;
|
|
}
|
|
|
|
function validateInput(inputValue) {
|
|
const decimalPlaces = countDecimalPlaces(inputValue);
|
|
return decimalPlaces <= 2;
|
|
}
|
|
|
|
if(tag == 1) {
|
|
if(berat == '') {
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Isi Anggaran Berat Permata'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
} else if($.isNumeric(berat) == false) {
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Semak Semula Berat Permata'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
} else if(berat <= 0) {
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Nilai berat permata mesti lebih besar daripada ' + berat,
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
} else if(!validateInput(berat)) {
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Hanya 2 titik perpuluhan dibenarkan untuk berat batu permata'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
} else if(berat != '') {
|
|
if($.isNumeric(berat) == false) {
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Semak Semula Berat Permata'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
if(berat <= 0) {
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Nilai berat permata mesti lebih besar daripada ' + berat,
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
if(!validateInput(berat)) {
|
|
$("#tambah_marhun").prop('disabled', false);
|
|
$("#terima_marhun").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Hanya 2 titik perpuluhan dibenarkan untuk berat batu permata'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function getDataCawangan(){
|
|
|
|
let header = {
|
|
'pragma': 'no-cache',
|
|
'cache-control': 'no-store',
|
|
};
|
|
|
|
let kodcaw = $('#kodcaw').val();
|
|
let teller = "{{ Auth::user()->name }}";
|
|
let apiUrl = api_url + '/api/GetCurrentTunai/' + kodcaw + '?kodlaluan=' + teller;
|
|
|
|
return fetch(apiUrl, {
|
|
header: header,
|
|
})
|
|
.then(response => response.json());
|
|
}
|
|
|
|
async function verifyGadai(func){
|
|
$("#terima_gadai").prop('disabled', true);
|
|
event.preventDefault();
|
|
var kodcaw = $('#kodcaw').val();
|
|
var nokp = $('#nokp').val();
|
|
var nopelanggan = $('#nopelanggan').val();
|
|
var norujukan = $('#norujukan').val();
|
|
var pinjaman = Number($('#pinjaman').val());
|
|
var total_nilai_marhun = $('#total_nilai_marhun').val();
|
|
var nilai_marhun_total = Number(total_nilai_marhun.replace(/[^0-9.-]+/g,""));
|
|
var count_error = 0;
|
|
var pembiayaan_max_teller = $('#pembiayaan_max_teller').val();
|
|
var pembiayaan_max_teller = Number(pembiayaan_max_teller.replace(/[^0-9.-]+/g,""));
|
|
var pembiyaan_max_pelulus = $('#pembiyaan_max_pelulus').val();
|
|
var pembiyaan_max_pelulus = Number(pembiyaan_max_pelulus.replace(/[^0-9.-]+/g,""));
|
|
var min_pinjaman = nilai_marhun_total * 0.10;
|
|
var max_pinjaman = pembiyaan_max_pelulus;
|
|
var outstanding_semasa = Number("{{ $outstanding_semasa }}");
|
|
|
|
let teller = "{{ Auth::user()->name }}";
|
|
let bakiakhir = 0;
|
|
var kodcaw = $('#kodcaw').val();
|
|
if(pinjaman == 0){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Pembiayaan Tidak Lengkap'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
let dataCawangan = await getDataCawangan();
|
|
let bakiAkhir = dataCawangan.baki;
|
|
|
|
if(bakiAkhir < pinjaman){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Baki Akhir Tunai Lebih Rendah Daripada Nilai Marhun Yang Ingin Digadaikan. Sila Tambah Pendahuluan di Laman Aliran Tunai Segera. '
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
|
|
if($.isNumeric(pinjaman) == false){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Masukkan Nombor Sahaja'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
if(pinjaman < min_pinjaman){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Masukan Pembiayaan, Minimal Pembiayaan ialah RM '+ formatter.format(min_pinjaman)
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else if(pinjaman > max_pinjaman){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Pinjaman Melebihi Margin Yang Dibenarkan'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
if(outstanding_semasa+pinjaman >= 300000){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Had Pembiayaan',
|
|
text: 'Outstanding Pembiayaan Pelanggan Telah Melebihi Had'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
$.ajax({
|
|
method:'get',
|
|
url: api_url + '/api/komuditi/check',
|
|
success:function(data){
|
|
var check_komuditi = Object.keys(data).length;
|
|
if(check_komuditi == 0){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Unit Komuditi Berbaki Minumum',
|
|
text: 'Sila Hubungi Operasi Untuk Membuat Pembelian Komuditi'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
if(Number(data['unit_komuditi']) < pinjaman){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Baki Unit Komuditi Tidak Mencukupi',
|
|
text: 'Sila Hubungi Operasi Untuk Membuat Pembelian Komuditi'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
else{
|
|
if(pinjaman >= 10000 && pinjaman <= Number(pembiyaan_max_pelulus)){
|
|
//new added
|
|
$.ajax({
|
|
method:'get',
|
|
url: api_url + '/api/gadai/norujukan/' + kodcaw + '/' + norujukan,
|
|
|
|
success:function(data)
|
|
{
|
|
var checking = Object.keys(data[0]).length;
|
|
|
|
if (data[0]['pinjaman'] > 0) {
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Tidak Berjaya',
|
|
text: 'Maklumat Pembiayaan Telah Wujud. Sila Tekan Batal.'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
} else {
|
|
//insert code asal
|
|
const swalWithBootstrapButtons = Swal.mixin({
|
|
customClass: {
|
|
confirmButton: 'btn btn-success',
|
|
cancelButton: 'btn btn-danger'
|
|
},
|
|
buttonsStyling: false
|
|
});
|
|
|
|
if(pinjaman > Number(pembiyaan_max_pelulus)){
|
|
var errortext = "Tetapan margin melebihi " + pinjaman_pelulus + "% untuk Operasi!";
|
|
}
|
|
if(pinjaman >= 10000){
|
|
var errortext = "Pinjaman Melebihi 10,000";
|
|
}
|
|
|
|
swalWithBootstrapButtons.fire({
|
|
title: 'Dapatkan Pengesahan Operasi',
|
|
text: errortext,
|
|
icon: 'info',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Hantar',
|
|
cancelButtonText: 'Batal',
|
|
reverseButtons: true
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
|
|
let norujukan = $('#norujukan').val();
|
|
let nm = parseFloat($('#total_nilai_marhun').val().replace(/[^0-9.-]+/g,""));let ber = $('#total_berat').val();let marg = $('.span-pinjaman').text();
|
|
let status = errortext;
|
|
let jumpinjam = $('#pinjaman').val();
|
|
let teller = "{{ Auth::user()->name }}";
|
|
|
|
Swal.fire({
|
|
title: 'Tunggu Pengesahan Daripada Khazanah-Operasi.',
|
|
icon: 'info',
|
|
width: 600,
|
|
padding: '3em',
|
|
background: '#fffff',
|
|
showCancelButton: false,
|
|
showConfirmButton: false,
|
|
allowOutsideClick: false,
|
|
allowEscapeKey: false,
|
|
allowEnterKey: false
|
|
})
|
|
let siricreated = 0;
|
|
$.ajax({
|
|
method:'post',
|
|
url: "{{ route('operasi.createkelulusan') }}",
|
|
data: {
|
|
"_token": "{{ csrf_token() }}",
|
|
"norujukan" : norujukan,
|
|
"komen" : '',
|
|
"margin" : marg,
|
|
"berat" : ber,
|
|
"nilaimarhun" : nm,
|
|
"status" : status,
|
|
"jumpinjam" : jumpinjam,
|
|
"teller" : teller
|
|
},
|
|
success:function(data){
|
|
siricreated = data;
|
|
},
|
|
error: function(xhr, status, error) {
|
|
var err = eval("(" + xhr.responseText + ")");
|
|
alert(xhr.responseText);
|
|
}
|
|
});
|
|
|
|
var pusher = new Pusher("{{ env('PUSHER_APP_KEY') }}", {
|
|
cluster: 'ap1',
|
|
encrypted: true
|
|
});
|
|
|
|
var channel = pusher.subscribe('notice-kelulusan');
|
|
channel.bind('my-kelulusan', function(data) {
|
|
|
|
if(data.norujukan == norujukan && data.siri == siricreated && data.teller == teller)
|
|
{
|
|
if(data.kelulusan == 'lulus')
|
|
{
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Telah Disahkan',
|
|
text: `Komen : ${data.komen}`
|
|
}).then(function(){
|
|
|
|
$(func).attr("onSubmit","return true;");
|
|
$(func).submit();
|
|
return true;
|
|
});
|
|
|
|
}
|
|
else if(data.kelulusan == 'batal')
|
|
{
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Telah Dibatalkan',
|
|
text: `Komen : ${data.komen}`
|
|
}).then(function(){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
return false;
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
}else if (result.dismiss === Swal.DismissReason.cancel){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
swalWithBootstrapButtons.fire(
|
|
'Batal',
|
|
'Maklumat Pembiayaan Tidak Berjaya Disimpan',
|
|
'error'
|
|
)
|
|
}
|
|
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
//end insert code asal
|
|
}
|
|
|
|
}
|
|
});
|
|
//end new added
|
|
|
|
}else if(pinjaman > Number(pembiayaan_max_teller)){
|
|
//new added
|
|
$.ajax({
|
|
method:'get',
|
|
url: api_url + '/api/gadai/norujukan/' + kodcaw + '/' + norujukan,
|
|
|
|
success:function(data)
|
|
{
|
|
var checking = Object.keys(data[0]).length;
|
|
|
|
if (data[0]['pinjaman'] > 0) {
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Tidak Berjaya',
|
|
text: 'Maklumat Pembiayaan Telah Wujud. Sila Tekan Batal.'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
} else {
|
|
//insert code asal
|
|
const swalWithBootstrapButtons = Swal.mixin({
|
|
customClass: {
|
|
confirmButton: 'btn btn-success',
|
|
cancelButton: 'btn btn-danger'
|
|
},
|
|
buttonsStyling: false
|
|
});
|
|
|
|
swalWithBootstrapButtons.fire({
|
|
title: 'Dapatkan Pengesahan Khazanah',
|
|
text: "Tetapan Margin Melebihi Limit Maksima Teller!",
|
|
icon: 'info',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Hantar',
|
|
cancelButtonText: 'Batal',
|
|
reverseButtons: true
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
|
|
let norujukan = $('#norujukan').val();
|
|
let nm = parseFloat($('#total_nilai_marhun').val().replace(/[^0-9.-]+/g, ""));
|
|
let ber = $('#total_berat').val();
|
|
let marg = $('.span-pinjaman').text();
|
|
let status = "Tetapan Margin Melebihi Limit Maksima Teller: " + pinjaman_teller + "%";
|
|
let jumpinjam = $('#pinjaman').val();
|
|
let teller = "{{ Auth::user()->name }}";
|
|
|
|
Swal.fire({
|
|
title: 'Tunggu Pengesahan Daripada Khazanah.',
|
|
icon: 'info',
|
|
width: 600,
|
|
padding: '3em',
|
|
background: '#fffff',
|
|
showCancelButton: false,
|
|
showConfirmButton: false,
|
|
allowOutsideClick: false,
|
|
allowEscapeKey: false,
|
|
allowEnterKey: false
|
|
})
|
|
|
|
let siricreated = 0;
|
|
$.ajax({
|
|
method:'post',
|
|
url: "{{ route('khazanah.createkelulusan') }}",
|
|
data: {
|
|
"_token": "{{ csrf_token() }}",
|
|
"norujukan" : norujukan,
|
|
"komen" : '',
|
|
"margin" : marg,
|
|
"berat" : ber,
|
|
"nilaimarhun" : nm,
|
|
"status" : status,
|
|
"jumpinjam" : jumpinjam,
|
|
"teller" : teller
|
|
},
|
|
success:function(data){
|
|
siricreated = data;
|
|
},
|
|
error: function(xhr, status, error) {
|
|
var err = eval("(" + xhr.responseText + ")");
|
|
alert(xhr.responseText);
|
|
}
|
|
});
|
|
|
|
//Try Pusher
|
|
|
|
var pusher = new Pusher("{{ env('PUSHER_APP_KEY') }}", {
|
|
cluster: 'ap1',
|
|
encrypted: true
|
|
});
|
|
|
|
var channel = pusher.subscribe('notice-kelulusan');
|
|
channel.bind('my-kelulusan', function(data) {
|
|
// let message = JSON.stringify(data);
|
|
|
|
if(data.norujukan == norujukan && data.siri == siricreated && data.teller == teller)
|
|
{
|
|
if(data.kelulusan == 'lulus')
|
|
{
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Telah Disahkan'
|
|
}).then(function(){
|
|
|
|
|
|
$(func).attr("onSubmit","return true;");
|
|
$(func).submit();
|
|
return true;
|
|
|
|
});
|
|
}
|
|
else if(data.kelulusan == 'batal')
|
|
{
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Telah Dibatalkan'
|
|
}).then(function(){
|
|
$("#terima_gadai").prop('disabled', false);
|
|
return false;
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (result.dismiss === Swal.DismissReason.cancel) {
|
|
$("#terima_gadai").prop('disabled', false);
|
|
swalWithBootstrapButtons.fire(
|
|
'Batal',
|
|
'Maklumat Pembiayaan Tidak Berjaya Disimpan',
|
|
'error'
|
|
)
|
|
}
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
//end insert code asal
|
|
}
|
|
|
|
}
|
|
});
|
|
//end new added
|
|
|
|
}
|
|
else if( pinjaman < 10000 && pinjaman <= Number(pembiayaan_max_teller)){
|
|
//new added
|
|
$.ajax({
|
|
method:'get',
|
|
url: api_url + '/api/gadai/norujukan/' + kodcaw + '/' + norujukan,
|
|
|
|
success:function(data)
|
|
{
|
|
var checking = Object.keys(data[0]).length;
|
|
|
|
if (data[0]['pinjaman'] > 0) {
|
|
$("#terima_gadai").prop('disabled', false);
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Tidak Berjaya',
|
|
text: 'Maklumat Pembiayaan Telah Wujud. Sila Tekan Batal.'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
} else {
|
|
//insert code asal
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Berjaya!',
|
|
text: 'Pembiayaan Berjaya Disimpan'
|
|
});
|
|
|
|
$(func).attr("onSubmit","return true;");
|
|
$(func).submit();
|
|
return true;
|
|
//end insert code asal
|
|
}
|
|
|
|
}
|
|
});
|
|
//end new added
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function deletemarhun(e){
|
|
let marhun = $(e).closest('tr').children('td:eq(1)').text();let selectedrow = $(e).closest('tr');let recnozz = tablemarhun.row(selectedrow).data();
|
|
let norujuk = $('#norujukan').val();
|
|
|
|
$.ajax({
|
|
method: 'put',
|
|
url: '{{ route("gadai.editmarhun") }}',
|
|
data: {
|
|
"_token": "{{ csrf_token() }}",
|
|
"norujukan": norujuk,
|
|
"recno": recnozz[1],
|
|
"teller": "{{ Auth::user()->name }}"
|
|
},
|
|
success: function(data) {
|
|
location.reload();
|
|
},
|
|
error: function(xhr, status, error) {
|
|
var err = eval("(" + xhr.responseText + ")");
|
|
alert(xhr.responseText);
|
|
}
|
|
});
|
|
}
|
|
|
|
function editmarhun(e){
|
|
let norujuk = $('#norujukan').val();
|
|
let selectedrow = $(e).closest('tr');
|
|
let recno = tablemarhun.row(selectedrow).data();
|
|
let nm = recno[3];
|
|
let karat = recno[4];
|
|
let berat = recno[5];
|
|
let harga = recno[8];
|
|
let nota = recno[7];
|
|
let tag_permata_edit = recno[8];
|
|
let beratpermata = recno[10];
|
|
let kuantiti = recno[6];
|
|
let jenismarhun = recno[2];
|
|
var res = nota.split(",");
|
|
|
|
// if(jenismarhun == 'G/B' || jenismarhun == 'WFR' || jenismarhun == 'SYE' || jenismarhun == 'DNR'){
|
|
// $('#kuantiti_modal').attr('disabled', false);
|
|
// $(".div_kuantiti_edit").css("display", "block");
|
|
// $(".div_column_kuantiti_edit").css("display", "block");
|
|
// $('#kuantiti_edit').val(kuantiti);
|
|
// }else{
|
|
// $('#kuantiti_modal').attr('disabled', false);
|
|
// $(".div_kuantiti_edit").css("display", "none");
|
|
// $(".div_column_kuantiti_edit").css("display", "none");
|
|
// $('#kuantiti_edit').val(1);
|
|
// }
|
|
|
|
if (!arrayBatuPermata.includes(jenismarhun)) {
|
|
$(".col_edit_permata").css("display", "block");
|
|
if(beratpermata != null) {
|
|
$('#tagpermataedit').prop('checked', true);
|
|
$(".div_anggaran_edit").css("display", "block");
|
|
$('#beratpermataedit').val(beratpermata);
|
|
} else {
|
|
$('#tagpermataedit').prop('checked', false);
|
|
$(".div_anggaran_edit").css("display", "none");
|
|
$('#beratpermataedit').val("");
|
|
}
|
|
} else {
|
|
$(".col_edit_permata").css("display", "none");
|
|
$('#tagpermataedit').prop('checked', false);
|
|
$(".div_anggaran_edit").css("display", "none");
|
|
$('#beratpermataedit').val("");
|
|
}
|
|
|
|
$.ajax({
|
|
method:'GET',
|
|
url: api_url + '/api/jemas',
|
|
success:function(data){
|
|
$.each(data,function(index,jemas){
|
|
$("#marhun_edit").append(new Option(jemas['descpt'], jemas['marhun']));
|
|
|
|
res.forEach(function(value) {
|
|
if ($('#nota_edit').find("option[value='" + value + "']").length === 0) {
|
|
let newOption = new Option(value, value, true, true);
|
|
$('#nota_edit').append(newOption).trigger('change');
|
|
}
|
|
});
|
|
|
|
$('#nota_edit').val(res).trigger('change');
|
|
|
|
$('#kuantiti_edit').val(kuantiti);
|
|
|
|
$('#sltkarat').val(karat);
|
|
$('#marhun_edit').val(jenismarhun);
|
|
$('#berat_edit').val(berat);
|
|
$('#nilaimarhun_edit').val(nm);
|
|
$('#harga_edit').val(harga);
|
|
$('#norujukedit').val(norujuk);
|
|
$('#recnoedit').val(recno[1]);
|
|
$('#editMarhunModal').modal();
|
|
})
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
|
|
$('#terima_edit').on('click',function(){
|
|
var nota_edit = $('#nota_edit').val();
|
|
var tagpermata_edit = $('input[id=tagpermataedit]').is(':checked') ? 1 : 0;
|
|
var beratpermata_edit = $('#beratpermataedit').val();
|
|
var norujukedit = $('#norujukedit').val();
|
|
var recnoedit = $('#recnoedit').val();
|
|
var marhun_edit = $('#marhun_edit').val();
|
|
var sltkarat = $('#sltkarat').val();
|
|
var berat_edit = $('#berat_edit').val();
|
|
var harga_edit = $('#harga_edit').val();
|
|
var nilaimarhun_edit = $('#nilaimarhun_edit').val();
|
|
var nilai_marhun_edit = Number(nilaimarhun_edit.replace(/[^0-9.-]+/g,""));
|
|
var kuantiti = $('#kuantiti_edit').val();
|
|
|
|
if(nota_edit != null){
|
|
var nota = nota_edit.toString();
|
|
}else{
|
|
var nota = '';
|
|
}
|
|
|
|
if(kuantiti > 10)
|
|
{
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Kuantiti tidak boleh melebihi 10'
|
|
});
|
|
|
|
event.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
var resultValidation = validateBatuPermata(tagpermata_edit, beratpermata_edit);
|
|
if(resultValidation == false) {
|
|
return false;
|
|
}
|
|
|
|
if($.isNumeric(berat_edit) == false){
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Amaran!',
|
|
text: 'Sila Masukkan Berat Marhun'
|
|
});
|
|
event.preventDefault();
|
|
return false;
|
|
}else{
|
|
$.ajax({
|
|
method:'put',
|
|
url: api_url + '/api/gadai/ubah/marhun/' + "{{ $cawangan_info['kodcaw'] }}" + '/' + norujukedit,
|
|
datatype:'json',
|
|
data:{
|
|
'recno' : recnoedit,
|
|
'karat' : sltkarat,
|
|
'berat' : berat_edit,
|
|
'harga' : harga_edit,
|
|
'n_marhun' : nilai_marhun_edit,
|
|
'marhun' : marhun_edit,
|
|
'nota' : nota,
|
|
'tag_permata' : tagpermata_edit,
|
|
'berat_batu_permata' : beratpermata_edit,
|
|
"teller": "{{ Auth::user()->name }}",
|
|
"kuantiti" : (kuantiti) ? kuantiti : 1
|
|
},
|
|
success:function(data){
|
|
getMarhun(norujukedit);
|
|
$('#editMarhunModal').modal('hide');
|
|
}
|
|
})
|
|
}
|
|
|
|
});
|
|
|
|
$("#sltkarat").change(function(e){
|
|
let hargaref = $(this).find(':selected').data('harga');
|
|
let ber = parseFloat($('#berat_edit').val());
|
|
let total = ber * hargaref;
|
|
$('#nilaimarhun_edit').val(formatter.format(total));
|
|
$('#harga_edit').val(hargaref);
|
|
});
|
|
|
|
function calculationharga(e){
|
|
let berat = $(e).val();
|
|
let total = 0;
|
|
let harga = $('#harga_edit').val();
|
|
|
|
total = berat * harga;
|
|
|
|
$('#nilaimarhun_edit').val(formatter.format(total));
|
|
}
|
|
|
|
function validateFloatKeyPress(el, evt) {
|
|
var charCode = (evt.which) ? evt.which : event.keyCode;
|
|
var number = el.value;
|
|
let keypress = evt.key;
|
|
|
|
// Split the current value by dot to check the number of decimal places
|
|
var numberParts = number.split('.');
|
|
|
|
// Check if the pressed key is a valid character for a floating-point number
|
|
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
|
|
return false;
|
|
}
|
|
|
|
// Check if there is already a dot, and the pressed key is another dot
|
|
if (numberParts.length > 1 && charCode == 46) {
|
|
return false;
|
|
}
|
|
|
|
// Get the caret position in the input field
|
|
var caratPos = getSelectionStart(el);
|
|
|
|
// Get the position of the existing dot
|
|
var dotPos = el.value.indexOf(".");
|
|
|
|
// Check if the caret is after the existing dot, and there are more than 2 digits after the dot
|
|
if (caratPos > dotPos && dotPos > -1 && (numberParts[1] && numberParts[1].length > 1)) {
|
|
return false;
|
|
}
|
|
|
|
// If the last digit is not 5 or 0, disallow the input
|
|
if (numberParts[1] && numberParts[1].length === 1 && !['0', '5'].includes(keypress)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function getSelectionStart(o) {
|
|
if (o.createTextRange) {
|
|
var r = document.selection.createRange().duplicate()
|
|
r.moveEnd('character', o.value.length)
|
|
if (r.text == '') return o.value.length
|
|
return o.value.lastIndexOf(r.text)
|
|
} else return o.selectionStart
|
|
}
|
|
|
|
$("#marhun_edit").change(function(e){
|
|
|
|
var marh = $(this).find(':selected').val();
|
|
$('#kuantiti_modal').val('');
|
|
|
|
if(marh == 'G/B' || marh == 'WFR' || marh == 'SYE' || marh == 'DNR'){
|
|
if(marh == 'DNR' || marh == 'SYE'){
|
|
$('#sltkarat option').show();
|
|
$('#sltkarat option').not('[value="21.0K"]').not('[value="22.0K"]').not('[value="23.0K"]').not('[value="24.0K"]').not('[value="24.0Kgb"]').not(':first').hide();
|
|
}else{
|
|
$('#sltkarat option').show();
|
|
$('#sltkarat option').not('[value="21.0K"]').not('[value="22.0K"]').not('[value="23.0K"]').not('[value="24.0K"]').not('[value="24.0Kgb"]').not(':first').hide();
|
|
}
|
|
|
|
$('#text_berat_modal').html('Berat Keseluruhan');
|
|
$('#kuantiti_modal').attr('disabled', false);
|
|
}else{
|
|
$('#text_berat_modal').html('Berat');
|
|
$('#kuantiti_modal').attr('disabled', true);
|
|
}
|
|
});
|
|
|
|
// Toggle Table Functionality
|
|
let isMarginTableVisible = false;
|
|
|
|
$('#toggleTableBtn').on('click', function() {
|
|
if (!isMarginTableVisible) {
|
|
// Check if main table has data before showing margin table
|
|
let tableData = $('#myTable').DataTable().data();
|
|
if (tableData.length === 0) {
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Amaran!',
|
|
text: 'Tiada data marhun untuk papar margin. Sila daftar marhun terlebih dahulu.'
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Show margin table, hide main table
|
|
$('#myTable_wrapper').hide();
|
|
$('#marginTable').show();
|
|
$(this).html('<i class="fas fa-exchange-alt"></i> Papar Marhun');
|
|
loadMarginData();
|
|
isMarginTableVisible = true;
|
|
|
|
// Disable Daftar Marhun button when margin table is visible
|
|
$('button[data-target="#daftar_marhun"]').prop('disabled', true);
|
|
} else {
|
|
// Show main table, hide margin table
|
|
$('#marginTable_wrapper').hide();
|
|
$('#myTable_wrapper').show();
|
|
$(this).html('<i class="fas fa-exchange-alt"></i> Papar Margin');
|
|
isMarginTableVisible = false;
|
|
|
|
// Enable Daftar Marhun button when main table is visible
|
|
$('button[data-target="#daftar_marhun"]').prop('disabled', false);
|
|
}
|
|
});
|
|
|
|
function loadMarginData() {
|
|
let marginData = [];
|
|
let totalNilaiMarhun = 0;
|
|
let totalNilaiTeller = 0;
|
|
let totalNilaiPC = 0;
|
|
|
|
// Process each individual row from the main table
|
|
let rowsData = [];
|
|
tablemarhun.rows().data().each(function(row, index) {
|
|
console.log(row);
|
|
let recno = row[1]; // Recno column
|
|
let karat = row[4]; // Karat column
|
|
let nilaiMarhun = parseFloat(row[3].replace(/[^0-9.-]+/g, "")); // Nilai Marhun column
|
|
rowsData.push({
|
|
index: index,
|
|
recno: recno,
|
|
karat: karat,
|
|
nilaiMarhun: nilaiMarhun
|
|
});
|
|
});
|
|
|
|
let bil = 1;
|
|
let processedCount = 0;
|
|
let totalEntries = rowsData.length;
|
|
|
|
rowsData.forEach((rowData) => {
|
|
// Call API to get margin data for each individual item
|
|
$.ajax({
|
|
url: '{{ config("api.url") }}/api/maxmutuemas/specific',
|
|
type: 'GET',
|
|
data: { karat: rowData.karat, nilaimarhun: rowData.nilaiMarhun },
|
|
success: function(response) {
|
|
if (response && response.karat) {
|
|
let nilaiTeller = parseFloat(response.maxteller) || 0;
|
|
let nilaiPC = parseFloat(response.maxpc) || 0;
|
|
|
|
marginData.push({
|
|
index: rowData.index,
|
|
bil: rowData.index + 1,
|
|
recno: rowData.recno,
|
|
karat: rowData.karat,
|
|
nilaiMarhun: rowData.nilaiMarhun,
|
|
marginTeller: response.teller,
|
|
marginPC: response.pc,
|
|
nilaiTeller: nilaiTeller,
|
|
nilaiPC: nilaiPC
|
|
});
|
|
|
|
totalNilaiMarhun += rowData.nilaiMarhun;
|
|
totalNilaiTeller += nilaiTeller;
|
|
totalNilaiPC += nilaiPC;
|
|
}
|
|
|
|
processedCount++;
|
|
if (processedCount === totalEntries) {
|
|
// Sort by original index to maintain order
|
|
marginData.sort((a, b) => a.index - b.index);
|
|
populateMarginTable(marginData, totalNilaiMarhun, totalNilaiTeller, totalNilaiPC);
|
|
}
|
|
},
|
|
error: function() {
|
|
processedCount++;
|
|
if (processedCount === totalEntries) {
|
|
// Sort by original index to maintain order
|
|
marginData.sort((a, b) => a.index - b.index);
|
|
populateMarginTable(marginData, totalNilaiMarhun, totalNilaiTeller, totalNilaiPC);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
let marginDataTable = null;
|
|
function populateMarginTable(data, totalMarhun, totalTeller, totalPC) {
|
|
// If DataTable already exists, destroy it first
|
|
if (marginDataTable !== null) {
|
|
marginDataTable.destroy();
|
|
marginDataTable = null;
|
|
}
|
|
|
|
let tbody = $('#marginTableBody');
|
|
tbody.empty();
|
|
|
|
data.forEach(function(item) {
|
|
let row = `
|
|
<tr>
|
|
<td>${item.bil}</td>
|
|
<td>${item.karat}</td>
|
|
<td>RM${item.nilaiMarhun.toLocaleString('en-MY', {minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
|
<td>${item.marginTeller}%</td>
|
|
<td>${item.marginPC}%</td>
|
|
<td>RM${item.nilaiTeller.toLocaleString('en-MY', {minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
|
<td>RM${item.nilaiPC.toLocaleString('en-MY', {minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
|
</tr>
|
|
`;
|
|
tbody.append(row);
|
|
});
|
|
|
|
// Initialize DataTable
|
|
marginDataTable = $('#marginTable').DataTable({
|
|
"pageLength": 10,
|
|
"ordering": false,
|
|
"order": [[ 0, "asc" ]],
|
|
"responsive": true,
|
|
"language": {
|
|
"lengthMenu": "Papar _MENU_ rekod setiap halaman",
|
|
"zeroRecords": "Tiada rekod dijumpai",
|
|
"info": "Memapar halaman _PAGE_ dari _PAGES_",
|
|
"infoEmpty": "Tiada rekod tersedia",
|
|
"infoFiltered": "(ditapis dari _MAX_ jumlah rekod)",
|
|
"search": "Cari:",
|
|
"paginate": {
|
|
"first": "Pertama",
|
|
"last": "Akhir",
|
|
"next": "Seterusnya",
|
|
"previous": "Sebelumnya"
|
|
}
|
|
},
|
|
"footerCallback": function (row, data, start, end, display) {
|
|
// Update footer totals
|
|
$('#totalNilaiMarhunMargin').text('RM' + totalMarhun.toLocaleString('en-MY', {minimumFractionDigits: 2, maximumFractionDigits: 2}));
|
|
$('#totalNilaiTellerMargin').text('RM' + totalTeller.toLocaleString('en-MY', {minimumFractionDigits: 2, maximumFractionDigits: 2}));
|
|
$('#totalNilaiPCMargin').text('RM' + totalPC.toLocaleString('en-MY', {minimumFractionDigits: 2, maximumFractionDigits: 2}));
|
|
}
|
|
});
|
|
}
|
|
|
|
</script>
|
|
@endsection
|