Skip to content

Instantly share code, notes, and snippets.

@korrio
Created January 12, 2024 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save korrio/a2465290c24b391a069279d0d217d1db to your computer and use it in GitHub Desktop.
Save korrio/a2465290c24b391a069279d0d217d1db to your computer and use it in GitHub Desktop.
upload_slip_updated.js
<script type="text/javascript">
$(function(){
function countdown() {
// Set the countdown date/time
var countDownDate = new Date().getTime() + 15 * 60 * 1000;
// Update the countdown every second
var countdownTimer = setInterval(function() {
// Get today's date/time
var now = new Date().getTime();
// Find the distance between now and the countdown date/time
var distance = countDownDate - now;
// Calculate minutes and seconds
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the countdown
$('#countdown').html(minutes + " นาที " + seconds + " วินาที");
// If countdown is finished, display "Expired" and clear the timer
if (distance < 0) {
clearInterval(countdownTimer);
$('#countdown').html("Expired");
}
}, 1000);
}
countdown();
const now = new Date();
const hour = now.getHours();
const minute = now.getMinutes();
if ((hour === 23 && minute >= 30) || (hour === 0 && minute <= 30)) {
Swal.fire({
position: 'center',
icon: 'success',
title: "หลีกเลี่ยงการฝากหรือถอนเงินบาท",
text: "ในช่วงเวลา 23.30น. - 00.30น. ของทุกวัน",
showConfirmButton: true,
timer: 10000
});
}
function decodeImageFromBase64(data, callback) {
// set callback
qrcode.callback = callback;
// Start decoding
qrcode.decode(data)
}
function readFile(event) {
console.log("readFile",readFile)
if (!this.files || !this.files[0]) return;
const FR = new FileReader();
files_upload = event.target.files;
FR.addEventListener("load", function(evt) {
console.log("evt",evt);
document.querySelector("#img_preview").src = evt.target.result;
console.log('evt.target.result', evt.target.result);
imageURI = evt.target.result;
decodeImageFromBase64(imageURI, function(decodedInformation) {
raw_qr = (decodedInformation);
console.log('raw qr is ', raw_qr);
$('#qr_raw').val(raw_qr);
console.log('qr_raw', raw_qr);
});
// document.querySelector("#b64").textContent = evt.target.result;
});
// console.log('this.files[0]', this.files[0]);
FR.readAsDataURL(this.files[0]);
}
$("#qr_image").on('change',function(e){
readFile(e);
})
$(':file').on('change', function (e) {
var file = this.files[0];
// if (file.size > 1024) {
// alert('max upload size is 1k');
// }
readFile(e);
// Also see .name, .type
});
document.querySelector("#qr_image").addEventListener("change", readFile);
$('#slip_upload').on('submit', (function(e) {
e.preventDefault();
var formData = new FormData(this);
if (typeof files_upload !== 'undefined') {
console.log('files_upload', files_upload);
// alert('found image!');
$.each(files_upload, function(key, value) {
formData.delete('qr_image');
formData.append('qr_image', value);
});
} else {
Swal.fire({
position: 'center',
icon: 'error',
title: 'กรุณาเลือกไฟล์สลิปการโอนก่อน',
showConfirmButton: false,
timer: 10000
});
}
var xhr = new XMLHttpRequest();
<?php $the_url = '';
if($_SERVER['HTTP_HOST'] == 'localhost:8000')
$the_url = 'http://' . $_SERVER['HTTP_HOST'];
else
$the_url = 'https://' . $_SERVER['HTTP_HOST']; ?>
$.ajax({
type: 'POST',
url: '<?php echo $the_url; ?>/deposit/verifyDepositSlip',
data: formData,
cache: false,
contentType: false,
processData: false,
headers: {
"cache-control": "no-cache"
},
success: function(data) {
console.log('data', data);
if (data.success == 0) {
Swal.fire({
position: 'center',
icon: 'error',
title: 'เติมเงินไม่สำเร็จ กรุณาตรวจสอบสลิป หรือติดต่อแอดมินค่ะ',
text: data.error.message,
showConfirmButton: false,
timer: 10000
});
} else if (data && !data.success && data.message) {
Swal.fire({
position: 'center',
icon: 'error',
title: data.message,
showConfirmButton: false,
timer: 10000
});
} else if (data && data.success) {
Swal.fire({
position: 'center',
icon: 'success',
title: data.message,
showConfirmButton: false,
timer: 10000
});
location.reload();
}
},
error: function(data) {
if (data?.responseJSON?.message) {
Swal.fire({
position: 'center',
icon: 'error',
title: data.responseJSON.message,
showConfirmButton: false,
timer: 10000
})
}
console.log(data);
}
});
$(this).prop('disabled', true);
return false;
}));
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment