Files
admin-erahn/resources/js/WTD/SenaraiBakiLelong.vue
T
2023-03-01 15:11:08 +08:00

403 lines
15 KiB
Vue

<template>
<div v-if="arraybakilelong.length > 0" class="relative bg-white overflow-x-auto shadow-md sm:rounded-lg px-8 py-6">
<div class="flex justify-between">
<div class="p-4">
<h1 class="text-xl font-bold bg-clip-text text-transparent bg-gradient-to-br from-gray-500 to-gray-700">JUMLAH = RM {{ this.totalbaki }}</h1>
</div>
<div class="p-4">
<button @click.prevent="promptwtd" :disabled="boolblocksag == false" :class="{'hover:bg-yellow-600 bg-yellow-600 border-yellow-600': boolblocksag == true}" class="border border-yellow-300 text-white bg-yellow-300 font-montserrat py-2 px-8 font-medium rounded-xl transition-all duration-300">Proses WTD</button>
<span v-if="batchno != 0" class="text-lg font-bold ml-3">Batchno: {{ this.batchno }}</span>
</div>
<div class="p-4">
<button @click.prevent="callparentload" class="border border-yellow-600 text-white bg-yellow-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300">Kembali</button>
<button @click.prevent="printwtd" :disabled="blockseterusnya == true" :class="{'hover:bg-yellow-600 bg-yellow-600 border-yellow-600': blockseterusnya == false}" class="border text-white bg-yellow-300 border-yellow-300 font-montserrat py-2 px-8 font-medium rounded-xl transition-all duration-300">Seterusnya</button>
</div>
</div>
<div class="flex justify-between">
<div class="pr-4">
<button @click.prevent="cetakpdf" class="border border-yellow-600 text-white bg-yellow-600 font-montserrat py-2 px-4 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300">PDF</button>
<button @click.prevent="cetaksenarai" class="border border-yellow-600 text-white bg-yellow-600 font-montserrat py-2 px-4 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300">Excel</button>
</div>
<div class="p-4">
{{ extensionbulan(this.$props.bulanmula) }} Hingga {{ extensionbulan(this.$props.bulanhingga) }}
</div>
</div>
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400 rounded-lg border w-full sm:h-96 p-6 overflow-x-auto overflow-y-scroll scrollbar">
<thead class="text-xs text-gray-700 uppercase bg-yellow-200 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" class="p-4">
<div class="flex items-center">
<span v-if="batchno != 0">Bil</span>
<input v-if="batchno == 0" id="checkbox-all-search" :readonly="boolblocksag == true" @click="selectAll" v-model="allSelected" type="checkbox" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
</div>
</th>
<th scope="col" class="px-6 py-3">
Norujukan
</th>
<th scope="col" class="px-6 py-3">
Tarikh Lelong
</th>
<th scope="col" class="px-6 py-3">
Pembiayaan
</th>
<th scope="col" class="px-6 py-3">
Baki
</th>
</tr>
</thead>
<tbody>
<tr v-for="(bl,i) in arraybakilelong" :key="i" class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600">
<td class="w-4 p-4">
<div class="flex items-center">
<span v-if="batchno != 0">{{ i+1 }}</span>
<input v-if="batchno == 0" :id="bl.norujukan" :readonly="boolblocksag == true" :value="bl.norujukan" type="checkbox" v-model="selectedNorujukan" @change="select($event)" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
</div>
</td>
<th scope="row" class="px-6 py-4 font-medium text-gray-900 dark:text-white whitespace-nowrap">
{{ bl.norujukan }}
</th>
<td class="px-6 py-4">
{{ bl.t_jual }}
</td>
<td class="px-6 py-4">
{{ formattext(bl.pinjaman) }}
</td>
<td class="px-6 py-4">
{{ formattext(bl.baki) }}
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
const formatter = new Intl.NumberFormat('en-US', {
minimumFractionDigits: 2
});
export default {
data() {
return {
mula: null,
hingga: null,
totalbaki: 0.00,
arraybakilelong: [],
selectedNorujukan: [],
allSelected: false,
boolblocksag: false,
cawangan: '',
batchno: 0,
blockseterusnya: false,
}
},
props: ['bakilelong', 'bulanmula', 'bulanhingga'],
methods: {
formattext: function (value) {
return formatter.format(value);
},
async associate() {
this.arraybakilelong = this.$props.bakilelong;
},
async calculate() {
let total = 0;
let ref = this;
await this.$props.bakilelong.map(function (valuebaki, keybaki) {
ref.selectedNorujukan.map(function (value, key) {
if (valuebaki.norujukan == value) {
total += parseFloat(valuebaki.baki);
}
})
});
this.totalbaki = formatter.format(total);
},
callparentload: function () {
this.arraybakilelong = [];
this.selectedNorujukan = [];
this.totalbaki = 0;
this.allSelected = false;
this.$emit('updateLoad')
},
selectAll: function () {
this.selectedNorujukan = [];
if (!this.allSelected) {
let ref = this;
this.arraybakilelong.map(function (value, key) {
ref.selectedNorujukan.push(value.norujukan);
});
ref.calculate();
} else {
this.calculate();
}
},
select: function (e) {
this.calculate();
this.allSelected = false;
},
async blockwtd() {
if (this.blockseterusnya === true) {
this.$swal({
icon: 'warning',
title: 'Amaran',
text: 'Surat sudah Di Disekat!',
allowOutsideClick: false
})
}
let cawangan = this.$kodcaw;
let ref = this;
await this.$swal({
title: 'Sekat Surat Akuan Gadaian (SAG)?',
text: "anda tidak boleh ulang kembali setelah di sekat!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes',
allowOutsideClick: false,
}).then((result) => {
if (result.isConfirmed) {
this.axios.post(ref.$hostname + '/admin/wtd/insert', {
kodcaw: cawangan,
norujukan: ref.selectedNorujukan
}).then(response => {
if (response.data.status === 'success') {
this.batchno = response.data.batchno;
this.$swal(
'Berjaya!',
'Berjaya sekat senarai SAG!',
'success'
)
this.boolblocksag = true;
this.blockseterusnya = true;
}
});
}
})
},
async printwtd() {
let cawangan = this.$kodcaw;
let ref = this;
if (this.selectedNorujukan.length > 0) {
await this.$swal({
icon: 'info',
title: '<strong>Sekatan WTD</strong>',
html: "Sila tekan <b>Ya</b> untuk sekat SAG, Sila tekan Tidak untuk membatal urusan!",
// html:"<button onclick='console.log(`haha`);cetaksenarai();' class='px-4 py-2 bg-yellow-500 text-white rounded-xl'>PDF</button><button class='ml-2 px-4 py-2 bg-yellow-500 text-white rounded-xl'>Excel</button>",
showCloseButton: true,
showCancelButton: true,
// showDenyButton: true,
// focusConfirm: false,
confirmButtonText: 'Ya',
cancelButtonText: 'Tidak',
confirmButtonColor: '#2ecc71',
cancelButtonColor: '#e74c3c',
allowOutsideClick: false,
}).then((result) => {
if (result.isConfirmed) {
this.blockwtd();
this.blockseterusnya = true;
}
})
} else {
this.$swal(
'Amaran!',
'Sila pilih norujukan terlebih dahulu!',
'warning'
)
}
},
async promptwtd() {
let boolkatalaluan = 0;
const {
value: katalaluan
} = await this.$swal({
title: 'Masukkan Katalaluan Semula',
input: 'password',
inputPlaceholder: 'Katalaluan',
confirmButtonText: 'Hantar',
showCancelButton: true,
cancelButtonText: 'Batal',
allowOutsideClick: false
})
await this.axios.get('/mintasemulakelulusan', {
params: {
passsemula: katalaluan
}
}).then(response => {
if (response.data === 0) {
boolkatalaluan = 0;
} else {
boolkatalaluan = 1;
}
});
if (boolkatalaluan == 1) {
await this.$swal({
title: 'Proses WTD?',
text: "anda tidak boleh ulang kembali setelah di proses!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ya',
allowOutsideClick: false,
}).then((result) => {
if (result.isConfirmed) {
this.$swal({
title: "Masukkan No Cek:",
// text: "Write something interesting:",
input: 'text',
showCancelButton: true
}).then((result) => {
if (result.value) {
this.proseswtd(result.value);
}
});
}
});
} else {
this.$swal('Kata laluan salah', '', 'error')
}
},
proseswtd: function () {
let cawangan = this.$kodcaw;
this.axios.post(this.$hostname + '/admin/wtd/process', {
kodcaw: cawangan,
batch: this.batchno
}).then(response => {
if (response.data == 'success') {
this.$swal(
'Berjaya!',
'Berjaya Simpan Wang Tak Dituntut!',
'success'
)
this.blockseterusnya = true;
this.boolblocksag = false;
}
});
},
cetaksenarai: function () {
let cawangan = this.$kodcaw;
if (this.selectedNorujukan.length > 0) {
let urldirect = window.route('wtd.cetak');
let noruj = JSON.stringify(this.selectedNorujukan);
window.open(urldirect + '?cawangan=' + cawangan + '&&norujukan=' + noruj + '&&jenis=excel' + '&&mula=' + this.extensionbulan(this.$props.bulanmula) + '&&hingga=' + this.extensionbulan(this.$props.bulanhingga), '_blank');
} else {
this.$swal(
'Amaran!',
'Sila pilih norujukan terlebih dahulu!',
'warning'
)
}
},
cetakpdf: function () {
let cawangan = this.$kodcaw;
if (this.selectedNorujukan.length > 0) {
let urldirect = window.route('wtd.cetak');
let noruj = JSON.stringify(this.selectedNorujukan);
window.open(urldirect + '?cawangan=' + cawangan + '&&norujukan=' + noruj + '&&jenis=pdf' + '&&mula=' + this.extensionbulan(this.$props.bulanmula) + '&&hingga=' + this.extensionbulan(this.$props.bulanhingga), '_blank');
} else {
this.$swal(
'Amaran!',
'Sila pilih norujukan terlebih dahulu!',
'warning'
)
}
},
extensionbulan: function (bulan) {
var stringexplode = bulan.split("-");
switch (stringexplode[0]) {
case '01':
bulan = "Januari";
break;
case '02':
bulan = "Februari";
break;
case '03':
bulan = "Mac";
break;
case '04':
bulan = "April";
break;
case '05':
bulan = "Mei";
break;
case '06':
bulan = "Jun";
break;
case '07':
bulan = "Julai";
break;
case '08':
bulan = "Ogos";
break;
case '09':
bulan = "September";
break;
case '10':
bulan = "Oktober";
break;
case '11':
bulan = "November";
break;
case '12':
bulan = "Disember";
break;
}
return bulan + '-' + stringexplode[1];
}
}
}
</script>
<style scoped>
.scrollbar::-webkit-scrollbar {
width: 20px;
height: 20px;
}
.scrollbar::-webkit-scrollbar-track {
border-radius: 100vh;
background: #f7f4ed;
}
.scrollbar::-webkit-scrollbar-thumb {
background: #e0cbcb;
border-radius: 100vh;
border: 3px solid #f6f7ed;
}
.scrollbar::-webkit-scrollbar-thumb:hover {
background: #c0a0b9;
}
</style>