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>
|
||||
@@ -7,6 +7,7 @@
|
||||
<div class="text-end">
|
||||
<button class="btn btn-add bg-danger btn-out mr-2">Pengeluaran</button>
|
||||
<button class="btn btn-warning btn-add btn-add-item mr-2">Tambah Barang</button>
|
||||
<button class="btn btn-add bg-primary" id="generate_pdf">Generate PDF</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -681,5 +682,26 @@ $('#btnAdjust').click(function(){
|
||||
|
||||
});
|
||||
|
||||
|
||||
//PDF GENERATE//
|
||||
$('#generate_pdf').on('click', function(){
|
||||
|
||||
let btn = $(this);
|
||||
|
||||
btn.prop('disabled', true)
|
||||
.html('Generate PDF...');
|
||||
|
||||
window.open(
|
||||
|
||||
"<?= base_url('generateitems/generatepdf'); ?>",
|
||||
'_blank'
|
||||
);
|
||||
|
||||
setTimeout(function(){
|
||||
btn.prop('disabled', false)
|
||||
.html('Generate PDF');
|
||||
},1000);
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -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>
|
||||
@@ -18,10 +18,12 @@
|
||||
<input type="date" name="tanggal_sampai" 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><br>
|
||||
<button type="button" class="btn btn-danger w-100" id="generate_pdf">
|
||||
<i class="fa fa-print"></i>Generate PDF</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
@@ -76,6 +78,7 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
$(function(){
|
||||
|
||||
function loadData(tanggal_dari = '', tanggal_sampai = ''){
|
||||
@@ -85,6 +88,7 @@ $(function(){
|
||||
tanggal_sampai: tanggal_sampai
|
||||
}, function(res){
|
||||
|
||||
|
||||
let act = '', pas = '';
|
||||
|
||||
// ================= ACTIVA
|
||||
@@ -134,18 +138,64 @@ $(function(){
|
||||
},'json');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ================= LOAD AWAL
|
||||
loadData();
|
||||
|
||||
|
||||
// ================= SUBMIT FILTER
|
||||
$('#filterForm').on('submit', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
let dari = $('#tanggal_dari').val();
|
||||
let sampai = $('#tanggal_sampai').val();
|
||||
|
||||
loadData(dari, sampai);
|
||||
});
|
||||
|
||||
|
||||
// Prevent double submit
|
||||
$(document).on('submit', 'form', function(e){
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
|
||||
$('#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('generateneraca/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>
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h4 class="mb-0 fw-bold">Neraca Saldo</h4>
|
||||
<button type="button" class="btn btn-danger w-30" id="generate_pdf">
|
||||
Generate PDF
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
@@ -62,5 +65,26 @@ $(function(){
|
||||
|
||||
}, 'json');
|
||||
|
||||
|
||||
//GENERATE PDF
|
||||
$('#generate_pdf').on('click', function(){
|
||||
|
||||
let btn = $(this);
|
||||
|
||||
btn.prop('disabled', true)
|
||||
.html('Generate PDF...');
|
||||
|
||||
window.open(
|
||||
|
||||
"<?= base_url('generateneracasaldo/generatepdf'); ?>",
|
||||
'_blank'
|
||||
);
|
||||
|
||||
setTimeout(function(){
|
||||
btn.prop('disabled', false)
|
||||
.html('Generate PDF');
|
||||
},1000);
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user