Penambahan tombol PDF di Bukubesar, Neraca, Laba rugi, Neraca saldo, dan Data Barang
Format PDF tersimpan di library semua
This commit is contained in:
@@ -16,10 +16,13 @@
|
||||
<input type="date" id="tanggal_sampai" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 d-flex align-items-end">
|
||||
<div class="col-md-4 d-flex align-items-end gap-2">
|
||||
<button type="submit" class="btn btn-warning w-100">
|
||||
Tampilkan
|
||||
</button>
|
||||
<button type="button" class="btn btn-danger w-100" id="generate_pdf">
|
||||
Generate PDF
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
@@ -168,5 +171,42 @@ $(function(){
|
||||
loadData(dari, sampai);
|
||||
});
|
||||
|
||||
|
||||
|
||||
$('#generate_pdf').on('click', function () {
|
||||
|
||||
const tanggal_dari = $('#tanggal_dari').val() || '0000-00-00';
|
||||
const tanggal_sampai = $('#tanggal_sampai').val() || '0000-00-00';
|
||||
|
||||
let btn = $(this);
|
||||
|
||||
|
||||
btn.prop('disabled', true).html('Generate PDF...');
|
||||
|
||||
$.ajax({
|
||||
url: "<?= base_url('generatelabarugi/generatepdf'); ?>"
|
||||
+ '/' + tanggal_dari
|
||||
+ '/' + tanggal_sampai,
|
||||
|
||||
type: "GET",
|
||||
xhrFields: {
|
||||
responseType: 'blob' // penting untuk PDF
|
||||
},
|
||||
success: function (response) {
|
||||
let blob = new Blob([response], { type: 'application/pdf' });
|
||||
let url = window.URL.createObjectURL(blob);
|
||||
|
||||
// buka di tab baru
|
||||
window.open(url, '_blank');
|
||||
|
||||
},
|
||||
error: function () {
|
||||
Swal.fire('Error', 'Gagal generate PDF', 'error');
|
||||
},
|
||||
complete: function(){
|
||||
btn.prop('disabled', false).html('Generate PDF');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user