Penambahan tombol PDF di Bukubesar, Neraca, Laba rugi, Neraca saldo, dan Data Barang
Format PDF tersimpan di library semua
This commit is contained in:
@@ -13,19 +13,23 @@
|
||||
<select id="account_id" class="form-control select-search"></select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-2">
|
||||
<label>Dari</label>
|
||||
<input type="date" id="start_date" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-2">
|
||||
<label>Sampai</label>
|
||||
<input type="date" id="end_date" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="col-md-2 d-flex align-items-end">
|
||||
|
||||
<div class="col-md-4 d-flex align-items-end gap-2">
|
||||
<button class="btn btn-primary w-100" id="btnFilter">Filter</button>
|
||||
<button type="button" class="btn btn-danger w-100" id="generate_pdf">
|
||||
Generate PDF</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
@@ -92,10 +96,61 @@ $(function(){
|
||||
},'json');
|
||||
}
|
||||
|
||||
|
||||
// FILTER
|
||||
$('#btnFilter').click(function(){
|
||||
loadData();
|
||||
});
|
||||
|
||||
|
||||
// Prevent double submit
|
||||
$(document).on('submit', 'form', function(e){
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
|
||||
// GENERATE PDF
|
||||
$('#generate_pdf').on('click', function () {
|
||||
|
||||
const now = new Date();
|
||||
const today = now.getFullYear() + '-'
|
||||
+ String(now.getMonth() + 1).padStart(2, '0') + '-'
|
||||
+ String(now.getDate()).padStart(2, '0');
|
||||
|
||||
const account_id = $('#account_id').val();
|
||||
const start_date = $('#start_date').val() || '0000-00-00';
|
||||
const end_date = $('#end_date').val() || today;
|
||||
|
||||
let btn = $(this);
|
||||
|
||||
btn.prop('disabled', true).html('Generate PDF...');
|
||||
|
||||
$.ajax({
|
||||
url: "<?= base_url('Generatebuku/generatepdf'); ?>"
|
||||
+ '/' + account_id
|
||||
+ '/' + start_date
|
||||
+ '/' + end_date,
|
||||
|
||||
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