Penambahan tombol PDF di Bukubesar, Neraca, Laba rugi, Neraca saldo, dan Data Barang
Format PDF tersimpan di library semua
This commit is contained in:
@@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Generatebuku extends CI_Controller
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->load->model('DynamicModel', 'dm');
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// PDF GENERATE — BUKU BESAR
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function generatepdf($account_id, $start, $end)
|
||||||
|
{
|
||||||
|
if ($this->session->userdata('role') != 'Admin') {
|
||||||
|
show_error('Akses ditolak', 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ob_get_length()) {
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// AMBIL INFO AKUN
|
||||||
|
// =============================================================
|
||||||
|
$akun = null;
|
||||||
|
if (!empty($account_id)) {
|
||||||
|
$akun = $this->db->get_where('accounts', ['id' => (int) $account_id])->row();
|
||||||
|
}
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// QUERY DATA
|
||||||
|
// =============================================================
|
||||||
|
$this->db->select('
|
||||||
|
journals.tanggal,
|
||||||
|
journals.no_ref,
|
||||||
|
journals.keterangan,
|
||||||
|
journal_details.debit,
|
||||||
|
journal_details.kredit,
|
||||||
|
accounts.tipe
|
||||||
|
');
|
||||||
|
$this->db->from('journal_details');
|
||||||
|
$this->db->join('journals', 'journals.id = journal_details.journal_id');
|
||||||
|
$this->db->join('accounts', 'accounts.id = journal_details.account_id');
|
||||||
|
|
||||||
|
if (!empty($account_id)) {
|
||||||
|
$this->db->where('journal_details.account_id', (int) $account_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($start) && !empty($end)) {
|
||||||
|
$this->db->where('journals.tanggal >=', $start);
|
||||||
|
$this->db->where('journals.tanggal <=', $end);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->group_start();
|
||||||
|
$this->db->where('journal_details.debit >', 0);
|
||||||
|
$this->db->or_where('journal_details.kredit >', 0);
|
||||||
|
$this->db->group_end();
|
||||||
|
|
||||||
|
$this->db->order_by('journals.tanggal', 'ASC');
|
||||||
|
|
||||||
|
$rows = $this->db->get()->result();
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// HITUNG SALDO BERJALAN
|
||||||
|
// =============================================================
|
||||||
|
$saldo = 0;
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($rows as $r) {
|
||||||
|
if (in_array($r->tipe, ['asset', 'expense'])) {
|
||||||
|
$saldo += ($r->debit - $r->kredit);
|
||||||
|
} else {
|
||||||
|
$saldo += ($r->kredit - $r->debit);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[] = [
|
||||||
|
'tanggal' => $r->tanggal,
|
||||||
|
'no_ref' => $r->no_ref,
|
||||||
|
'keterangan' => $r->keterangan,
|
||||||
|
'debit' => $r->debit,
|
||||||
|
'kredit' => $r->kredit,
|
||||||
|
'saldo' => $saldo,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$total_debit = array_sum(array_column($result, 'debit'));
|
||||||
|
$total_kredit = array_sum(array_column($result, 'kredit'));
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// DATA PERUSAHAAN
|
||||||
|
// =============================================================
|
||||||
|
$company = $this->db->get('pengaturan')->row();
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// BUILD STRING INFO LAPORAN
|
||||||
|
// =============================================================
|
||||||
|
$namaAkun = $akun
|
||||||
|
? $akun->kode_akun . ' - ' . $akun->nama_akun
|
||||||
|
: 'Semua Akun';
|
||||||
|
|
||||||
|
$periodeStr = (!empty($start) && !empty($end))
|
||||||
|
? 'Periode : ' . date('d-m-Y', strtotime($start)) . ' s/d ' . date('d-m-Y', strtotime($end))
|
||||||
|
: 'Periode : Semua Tanggal';
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// LOAD LIBRARY PDF
|
||||||
|
// =============================================================
|
||||||
|
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||||
|
require_once(APPPATH . 'libraries/PDF_BukuBesar.php');
|
||||||
|
|
||||||
|
$pdf = new PDF ('P', 'mm', 'A4');
|
||||||
|
$pdf->SetMargins(10, 10, 10);
|
||||||
|
|
||||||
|
$pdf->setHeaderData(
|
||||||
|
$company->nama_perusahaan,
|
||||||
|
$company->alamat_perusahaan,
|
||||||
|
FCPATH . 'uploads/img/logo-ljn.png'
|
||||||
|
);
|
||||||
|
|
||||||
|
$pdf->setInfoLaporan($namaAkun, $periodeStr);
|
||||||
|
|
||||||
|
$pdf->AddPage('P', 'A4');
|
||||||
|
$pdf->BukuBesarTable($result);
|
||||||
|
$pdf->BukuBesarTotal($total_debit, $total_kredit, $saldo);
|
||||||
|
$pdf->Pembuat('Tito Ngudiana', 'Finance Department');
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// OUTPUT
|
||||||
|
// =============================================================
|
||||||
|
$filename = 'Buku_Besar_' . date('YmdHis') . '.pdf';
|
||||||
|
$pdf->Output('D', $filename);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Generateitems extends CI_Controller {
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->load->model('DynamicModel', 'dm');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function generatepdf()
|
||||||
|
{
|
||||||
|
if(ob_get_length()){
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->select('
|
||||||
|
items.id,
|
||||||
|
items.nama_barang,
|
||||||
|
items.kode_detail,
|
||||||
|
items.harga_beli,
|
||||||
|
items.harga_jual,
|
||||||
|
items.created_at,
|
||||||
|
items.tanggal_pembelian,
|
||||||
|
items.stok,
|
||||||
|
(
|
||||||
|
SELECT GROUP_CONCAT(DISTINCT w.nama SEPARATOR ", ")
|
||||||
|
FROM stock_logs sl
|
||||||
|
LEFT JOIN warehouses w ON sl.warehouse_id = w.id
|
||||||
|
WHERE sl.item_id = items.id
|
||||||
|
) as gudang
|
||||||
|
');
|
||||||
|
|
||||||
|
$this->db->where('items.status','active');
|
||||||
|
$this->db->where('items.stok >', 0); // <-- stok 0 agar tidak muncul
|
||||||
|
|
||||||
|
$this->db->order_by('(items.stok = 0)','ASC',false);
|
||||||
|
$this->db->order_by('items.tanggal_pembelian','ASC');
|
||||||
|
$this->db->order_by('items.kode_detail','ASC');
|
||||||
|
|
||||||
|
$data = $this->db->get('items')->result();
|
||||||
|
|
||||||
|
|
||||||
|
$company = $this->db->get('pengaturan')->row_array();
|
||||||
|
|
||||||
|
|
||||||
|
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||||
|
require_once(APPPATH. 'libraries/PDF_Items.php');
|
||||||
|
|
||||||
|
$pdf = new PDF();
|
||||||
|
|
||||||
|
$pdf->setHeaderData(
|
||||||
|
$company['nama_perusahaan'],
|
||||||
|
$company['alamat_perusahaan'],
|
||||||
|
$company['telepon_perusahaan'],
|
||||||
|
FCPATH.'uploads/img/logo-ljn.png'
|
||||||
|
);
|
||||||
|
|
||||||
|
$pdf->AddPage('P', 'A4');
|
||||||
|
$pdf->ItemsTable($data);
|
||||||
|
$pdf->TotalBarang(count($data));
|
||||||
|
// $pdf->Pembuat($company['nama_bendahara']);
|
||||||
|
$pdf->Output('I','Data_Barang_'.date('YmdHis').'.pdf');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
<?php
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Generatelabarugi extends CI_Controller {
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->load->model('DynamicModel', 'dm');
|
||||||
|
|
||||||
|
if (!$this->session->userdata('logged_in')) {
|
||||||
|
redirect('auth');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
if($this->session->userdata('role') != 'Admin'){
|
||||||
|
show_error('Akses ditolak', 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = ["active_menu" => "laba_rugi"];
|
||||||
|
$this->load->view('partials/header', $data);
|
||||||
|
$this->load->view('laporan/laba_rugi');
|
||||||
|
$this->load->view('partials/footer');
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// AMBIL DATA LABA RUGI (DIPAKAI BERSAMA OLEH get_data() & generatepdf())
|
||||||
|
// =========================
|
||||||
|
private function get_labarugi_data($tanggal_dari = null, $tanggal_sampai = null)
|
||||||
|
{
|
||||||
|
$this->db->select('
|
||||||
|
a.id,
|
||||||
|
a.kode_akun,
|
||||||
|
a.nama_akun,
|
||||||
|
a.tipe,
|
||||||
|
COALESCE(SUM(jd.debit),0) as debit,
|
||||||
|
COALESCE(SUM(jd.kredit),0) as kredit
|
||||||
|
');
|
||||||
|
$this->db->from('accounts a');
|
||||||
|
|
||||||
|
// ================= JOIN
|
||||||
|
$this->db->join('journal_details jd','a.id = jd.account_id','LEFT');
|
||||||
|
$this->db->join('journals j','j.id = jd.journal_id','LEFT');
|
||||||
|
|
||||||
|
// ================= FILTER AKUN
|
||||||
|
$this->db->where('a.kategori','laba_rugi');
|
||||||
|
$this->db->where('a.is_active',1);
|
||||||
|
|
||||||
|
// ================= FILTER TANGGAL (AMAN)
|
||||||
|
if($tanggal_dari){
|
||||||
|
$this->db->where('(j.tanggal >= "'.$tanggal_dari.'" OR j.tanggal IS NULL)');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($tanggal_sampai){
|
||||||
|
$this->db->where('(j.tanggal <= "'.$tanggal_sampai.'" OR j.tanggal IS NULL)');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->group_by('a.id');
|
||||||
|
$this->db->order_by('a.kode_akun','ASC');
|
||||||
|
|
||||||
|
$rows = $this->db->get()->result();
|
||||||
|
|
||||||
|
$pendapatan = [];
|
||||||
|
$beban = [];
|
||||||
|
|
||||||
|
$revenue = 0;
|
||||||
|
$expense = 0;
|
||||||
|
|
||||||
|
foreach ($rows as $r) {
|
||||||
|
|
||||||
|
if ($r->tipe == 'revenue') {
|
||||||
|
$saldo = $r->kredit - $r->debit;
|
||||||
|
$revenue += $saldo;
|
||||||
|
|
||||||
|
$pendapatan[] = [
|
||||||
|
'kode' => $r->kode_akun,
|
||||||
|
'nama' => $r->nama_akun,
|
||||||
|
'saldo' => $saldo
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($r->tipe == 'expense') {
|
||||||
|
$saldo = $r->debit - $r->kredit;
|
||||||
|
$expense += $saldo;
|
||||||
|
|
||||||
|
$beban[] = [
|
||||||
|
'kode' => $r->kode_akun,
|
||||||
|
'nama' => $r->nama_akun,
|
||||||
|
'saldo' => $saldo
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'data' => $rows,
|
||||||
|
'pendapatan' => $pendapatan,
|
||||||
|
'beban' => $beban,
|
||||||
|
'revenue' => $revenue,
|
||||||
|
'expense' => $expense,
|
||||||
|
'total_pendapatan'=> $revenue,
|
||||||
|
'total_beban' => $expense,
|
||||||
|
'laba' => $revenue - $expense
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// GET DATA LABA RUGI (JSON, untuk AJAX/datatable)
|
||||||
|
// =========================
|
||||||
|
public function get_data()
|
||||||
|
{
|
||||||
|
$tanggal_dari = $this->input->get('tanggal_dari');
|
||||||
|
$tanggal_sampai = $this->input->get('tanggal_sampai');
|
||||||
|
|
||||||
|
$result = $this->get_labarugi_data($tanggal_dari, $tanggal_sampai);
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'data' => $result['data'],
|
||||||
|
'revenue' => $result['revenue'],
|
||||||
|
'expense' => $result['expense'],
|
||||||
|
'laba' => $result['laba']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// PDF GENERATE — LABA RUGI
|
||||||
|
// =========================
|
||||||
|
public function generatepdf($start = null, $end = null)
|
||||||
|
{
|
||||||
|
if ($this->session->userdata('role') != 'Admin') {
|
||||||
|
show_error('Akses ditolak', 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ob_get_length()) {
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalisasi parameter URL (0000-00-00 dianggap kosong)
|
||||||
|
$tanggal_dari = (!empty($start) && $start != '0000-00-00') ? $start : null;
|
||||||
|
$tanggal_sampai = (!empty($end) && $end != '0000-00-00') ? $end : null;
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// AMBIL DATA
|
||||||
|
// =============================================================
|
||||||
|
$labarugi = $this->get_labarugi_data($tanggal_dari, $tanggal_sampai);
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// DATA PERUSAHAAN
|
||||||
|
// =============================================================
|
||||||
|
$company = $this->db->get('pengaturan')->row();
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// BUILD STRING PERIODE
|
||||||
|
// =============================================================
|
||||||
|
$periodeStr = (!empty($tanggal_dari) && !empty($tanggal_sampai))
|
||||||
|
? 'Periode : ' . date('d-m-Y', strtotime($tanggal_dari))
|
||||||
|
. ' s/d ' . date('d-m-Y', strtotime($tanggal_sampai))
|
||||||
|
: ((!empty($tanggal_sampai))
|
||||||
|
? 'Per Tanggal : ' . date('d-m-Y', strtotime($tanggal_sampai))
|
||||||
|
: 'Per Tanggal : ' . date('d-m-Y'));
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// LOAD LIBRARY PDF
|
||||||
|
// =============================================================
|
||||||
|
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||||
|
require_once(APPPATH . 'libraries/PDF_Labarugi.php');
|
||||||
|
|
||||||
|
$pdf = new PDF ('P', 'mm', 'A4');
|
||||||
|
$pdf->SetMargins(10, 10, 10);
|
||||||
|
|
||||||
|
$pdf->setHeaderData(
|
||||||
|
$company->nama_perusahaan,
|
||||||
|
$company->alamat_perusahaan,
|
||||||
|
FCPATH . 'uploads/img/logo-ljn.png'
|
||||||
|
);
|
||||||
|
|
||||||
|
$pdf->setInfoLaporan($periodeStr);
|
||||||
|
|
||||||
|
$pdf->AddPage('P', 'A4');
|
||||||
|
$pdf->LabaRugiTable(
|
||||||
|
$labarugi['pendapatan'],
|
||||||
|
$labarugi['beban'],
|
||||||
|
$labarugi['total_pendapatan'],
|
||||||
|
$labarugi['total_beban']
|
||||||
|
);
|
||||||
|
$pdf->LabaRugiRingkasan($labarugi['laba']);
|
||||||
|
$pdf->Pembuat('Tito Ngudiana', 'Finance Department');
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// OUTPUT
|
||||||
|
// =============================================================
|
||||||
|
$filename = 'Laba_Rugi_' . date('YmdHis') . '.pdf';
|
||||||
|
$pdf->Output('D', $filename);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Generateneraca extends CI_Controller {
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->load->model('DynamicModel', 'dm');
|
||||||
|
|
||||||
|
if (!$this->session->userdata('logged_in')) {
|
||||||
|
redirect('auth');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
if($this->session->userdata('role') != 'Admin'){
|
||||||
|
show_error('Akses ditolak', 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = ["active_menu" => "neraca"];
|
||||||
|
$this->load->view('partials/header', $data);
|
||||||
|
$this->load->view('laporan/neraca');
|
||||||
|
$this->load->view('partials/footer');
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// LABA BERJALAN (PAKAI TANGGAL JOURNAL)
|
||||||
|
// =========================
|
||||||
|
private function get_laba_berjalan($tanggal_dari = null, $tanggal_sampai = null)
|
||||||
|
{
|
||||||
|
$this->db->select('
|
||||||
|
accounts.tipe,
|
||||||
|
COALESCE(SUM(jd.debit),0) as debit,
|
||||||
|
COALESCE(SUM(jd.kredit),0) as kredit
|
||||||
|
');
|
||||||
|
$this->db->from('accounts');
|
||||||
|
$this->db->join('journal_details jd','jd.account_id = accounts.id','LEFT');
|
||||||
|
$this->db->join('journals j','j.id = jd.journal_id','LEFT');
|
||||||
|
|
||||||
|
$this->db->where_in('accounts.tipe',['revenue','expense']);
|
||||||
|
|
||||||
|
// ================= FILTER TANGGAL
|
||||||
|
if($tanggal_dari){
|
||||||
|
$this->db->where('(j.tanggal >= "'.$tanggal_dari.'" OR j.tanggal IS NULL)');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($tanggal_sampai){
|
||||||
|
$this->db->where('(j.tanggal <= "'.$tanggal_sampai.'" OR j.tanggal IS NULL)');
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = $this->db->get()->result();
|
||||||
|
|
||||||
|
$revenue = 0;
|
||||||
|
$expense = 0;
|
||||||
|
|
||||||
|
foreach ($rows as $r) {
|
||||||
|
if ($r->tipe == 'revenue') {
|
||||||
|
$revenue += ($r->kredit - $r->debit);
|
||||||
|
} else {
|
||||||
|
$expense += ($r->debit - $r->kredit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $revenue - $expense;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// AMBIL DATA NERACA (DIPAKAI BERSAMA OLEH get_data() & generatepdf())
|
||||||
|
// =========================
|
||||||
|
private function get_neraca_data($tanggal_dari = null, $tanggal_sampai = null)
|
||||||
|
{
|
||||||
|
$this->db->select('
|
||||||
|
a.id,
|
||||||
|
a.kode_akun,
|
||||||
|
a.nama_akun,
|
||||||
|
a.tipe,
|
||||||
|
a.posisi,
|
||||||
|
a.is_kontra,
|
||||||
|
COALESCE(SUM(jd.debit),0) as debit,
|
||||||
|
COALESCE(SUM(jd.kredit),0) as kredit
|
||||||
|
');
|
||||||
|
$this->db->from('accounts a');
|
||||||
|
$this->db->join('journal_details jd','jd.account_id = a.id','LEFT');
|
||||||
|
$this->db->join('journals j','j.id = jd.journal_id','LEFT');
|
||||||
|
|
||||||
|
$this->db->where('a.kategori','neraca');
|
||||||
|
|
||||||
|
// ================= FILTER TANGGAL
|
||||||
|
if($tanggal_dari){
|
||||||
|
$this->db->where('(j.tanggal >= "'.$tanggal_dari.'" OR j.tanggal IS NULL)');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($tanggal_sampai){
|
||||||
|
$this->db->where('(j.tanggal <= "'.$tanggal_sampai.'" OR j.tanggal IS NULL)');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->group_by('a.id');
|
||||||
|
$this->db->order_by('a.kode_akun','ASC');
|
||||||
|
|
||||||
|
$rows = $this->db->get()->result();
|
||||||
|
|
||||||
|
$activa = [];
|
||||||
|
$pasiva = [];
|
||||||
|
|
||||||
|
$total_activa = 0;
|
||||||
|
$total_pasiva = 0;
|
||||||
|
|
||||||
|
// ================= LABA BERJALAN
|
||||||
|
$laba = $this->get_laba_berjalan($tanggal_dari, $tanggal_sampai);
|
||||||
|
|
||||||
|
foreach ($rows as $r) {
|
||||||
|
|
||||||
|
// ================= SALDO NORMAL
|
||||||
|
if ($r->posisi == 'debit') {
|
||||||
|
$saldo = $r->debit - $r->kredit;
|
||||||
|
} else {
|
||||||
|
$saldo = $r->kredit - $r->debit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================= KONTRA ACCOUNT
|
||||||
|
if ($r->is_kontra == 1) {
|
||||||
|
$saldo = -$saldo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================= LABA BERJALAN
|
||||||
|
if ($r->kode_akun == '302') {
|
||||||
|
$saldo = $laba;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================= ACTIVA
|
||||||
|
if ($r->tipe == 'asset') {
|
||||||
|
|
||||||
|
$activa[] = [
|
||||||
|
'kode' => $r->kode_akun,
|
||||||
|
'nama' => $r->nama_akun,
|
||||||
|
'saldo' => $saldo
|
||||||
|
];
|
||||||
|
|
||||||
|
$total_activa += $saldo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================= PASIVA
|
||||||
|
if (in_array($r->tipe, ['liability','equity'])) {
|
||||||
|
|
||||||
|
$pasiva[] = [
|
||||||
|
'kode' => $r->kode_akun,
|
||||||
|
'nama' => $r->nama_akun,
|
||||||
|
'saldo' => $saldo
|
||||||
|
];
|
||||||
|
|
||||||
|
$total_pasiva += $saldo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'activa' => $activa,
|
||||||
|
'pasiva' => $pasiva,
|
||||||
|
'total_activa' => $total_activa,
|
||||||
|
'total_pasiva' => $total_pasiva,
|
||||||
|
'laba' => $laba,
|
||||||
|
'selisih' => $total_activa - $total_pasiva
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// GET DATA NERACA (JSON, untuk AJAX/datatable)
|
||||||
|
// =========================
|
||||||
|
public function get_data()
|
||||||
|
{
|
||||||
|
$tanggal_dari = $this->input->get('tanggal_dari');
|
||||||
|
$tanggal_sampai = $this->input->get('tanggal_sampai');
|
||||||
|
|
||||||
|
$data = $this->get_neraca_data($tanggal_dari, $tanggal_sampai);
|
||||||
|
|
||||||
|
echo json_encode($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// PDF GENERATE — NERACA
|
||||||
|
// =========================
|
||||||
|
public function generatepdf($start = null, $end = null)
|
||||||
|
{
|
||||||
|
if ($this->session->userdata('role') != 'Admin') {
|
||||||
|
show_error('Akses ditolak', 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ob_get_length()) {
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalisasi parameter URL (0000-00-00 dianggap kosong)
|
||||||
|
$tanggal_dari = (!empty($start) && $start != '0000-00-00') ? $start : null;
|
||||||
|
$tanggal_sampai = (!empty($end) && $end != '0000-00-00') ? $end : null;
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// AMBIL DATA
|
||||||
|
// =============================================================
|
||||||
|
$neraca = $this->get_neraca_data($tanggal_dari, $tanggal_sampai);
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// DATA PERUSAHAAN
|
||||||
|
// =============================================================
|
||||||
|
$company = $this->db->get('pengaturan')->row();
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// BUILD STRING PERIODE
|
||||||
|
// =============================================================
|
||||||
|
$periodeStr = (!empty($tanggal_dari) && !empty($tanggal_sampai))
|
||||||
|
? 'Per Tanggal : ' . date('d-m-Y', strtotime($tanggal_sampai))
|
||||||
|
. ' (Sejak ' . date('d-m-Y', strtotime($tanggal_dari)) . ')'
|
||||||
|
: ((!empty($tanggal_sampai))
|
||||||
|
? 'Per Tanggal : ' . date('d-m-Y', strtotime($tanggal_sampai))
|
||||||
|
: 'Per Tanggal : ' . date('d-m-Y'));
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// LOAD LIBRARY PDF
|
||||||
|
// =============================================================
|
||||||
|
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||||
|
require_once(APPPATH . 'libraries/PDF_Neraca.php');
|
||||||
|
|
||||||
|
$pdf = new PDF ('P', 'mm', 'A4');
|
||||||
|
$pdf->SetMargins(10, 10, 10);
|
||||||
|
|
||||||
|
$pdf->setHeaderData(
|
||||||
|
$company->nama_perusahaan,
|
||||||
|
$company->alamat_perusahaan,
|
||||||
|
FCPATH . 'uploads/img/logo-ljn.png'
|
||||||
|
);
|
||||||
|
|
||||||
|
$pdf->setInfoLaporan($periodeStr);
|
||||||
|
|
||||||
|
$pdf->AddPage('P', 'A4');
|
||||||
|
$pdf->NeracaTable(
|
||||||
|
$neraca['activa'],
|
||||||
|
$neraca['pasiva'],
|
||||||
|
$neraca['total_activa'],
|
||||||
|
$neraca['total_pasiva']
|
||||||
|
);
|
||||||
|
$pdf->NeracaRingkasan($neraca['laba'], $neraca['selisih']);
|
||||||
|
$pdf->Pembuat('Tito Ngudiana', 'Finance Department');
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// OUTPUT
|
||||||
|
// =============================================================
|
||||||
|
$filename = 'Neraca_' . date('YmdHis') . '.pdf';
|
||||||
|
$pdf->Output('D', $filename);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,209 @@
|
|||||||
|
<?php
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Generateneracasaldo extends CI_Controller {
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->load->model('DynamicModel', 'dm');
|
||||||
|
|
||||||
|
if (!$this->session->userdata('logged_in')) {
|
||||||
|
redirect('auth');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
|
||||||
|
if($this->session->userdata('role') != 'Admin'){
|
||||||
|
show_error('Akses ditolak', 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = ["active_menu" => "neraca_saldo"];
|
||||||
|
$this->load->view('partials/header', $data);
|
||||||
|
$this->load->view('laporan/neraca_saldo');
|
||||||
|
$this->load->view('partials/footer');
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// HITUNG LABA BERJALAN (REALTIME)
|
||||||
|
// =========================
|
||||||
|
private function get_laba_berjalan()
|
||||||
|
{
|
||||||
|
$this->db->select('
|
||||||
|
accounts.tipe,
|
||||||
|
COALESCE(SUM(journal_details.debit),0) as debit,
|
||||||
|
COALESCE(SUM(journal_details.kredit),0) as kredit
|
||||||
|
');
|
||||||
|
$this->db->from('accounts');
|
||||||
|
$this->db->join('journal_details','journal_details.account_id = accounts.id','LEFT');
|
||||||
|
$this->db->where_in('accounts.tipe',['revenue','expense']);
|
||||||
|
|
||||||
|
$rows = $this->db->get()->result();
|
||||||
|
|
||||||
|
$revenue = 0;
|
||||||
|
$expense = 0;
|
||||||
|
|
||||||
|
foreach ($rows as $r) {
|
||||||
|
if ($r->tipe == 'revenue') {
|
||||||
|
$revenue += ($r->kredit - $r->debit);
|
||||||
|
} else {
|
||||||
|
$expense += ($r->debit - $r->kredit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $revenue - $expense;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// AMBIL DATA NERACA SALDO (DIPAKAI BERSAMA OLEH get_data() & generatepdf())
|
||||||
|
// =========================
|
||||||
|
private function get_neracasaldo_data()
|
||||||
|
{
|
||||||
|
$this->db->select('
|
||||||
|
accounts.kode_akun,
|
||||||
|
accounts.nama_akun,
|
||||||
|
accounts.tipe,
|
||||||
|
accounts.posisi,
|
||||||
|
COALESCE(SUM(journal_details.debit),0) as debit,
|
||||||
|
COALESCE(SUM(journal_details.kredit),0) as kredit
|
||||||
|
');
|
||||||
|
$this->db->from('accounts');
|
||||||
|
$this->db->join('journal_details','journal_details.account_id = accounts.id','LEFT');
|
||||||
|
|
||||||
|
// OPTIONAL (best practice)
|
||||||
|
$this->db->where('accounts.is_active',1);
|
||||||
|
$this->db->where('accounts.kategori','neraca');
|
||||||
|
|
||||||
|
$this->db->group_by('accounts.id');
|
||||||
|
$this->db->order_by('accounts.kode_akun','ASC');
|
||||||
|
|
||||||
|
$rows = $this->db->get()->result();
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// HITUNG LABA BERJALAN
|
||||||
|
// =========================
|
||||||
|
$laba = $this->get_laba_berjalan();
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
$total_debit = 0;
|
||||||
|
$total_kredit = 0;
|
||||||
|
|
||||||
|
foreach ($rows as $r) {
|
||||||
|
|
||||||
|
// ================= SALDO NORMAL
|
||||||
|
if ($r->posisi == 'debit') {
|
||||||
|
$saldo = $r->debit - $r->kredit;
|
||||||
|
} else {
|
||||||
|
$saldo = $r->kredit - $r->debit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================= OVERRIDE LABA BERJALAN
|
||||||
|
if ($r->kode_akun == '302') {
|
||||||
|
$saldo = $laba;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================= NORMALISASI KE KOLOM
|
||||||
|
if ($saldo >= 0 AND $r->posisi == 'debit') {
|
||||||
|
$r->saldo_debit = $saldo;
|
||||||
|
$r->saldo_kredit = 0;
|
||||||
|
} else {
|
||||||
|
$r->saldo_debit = 0;
|
||||||
|
$r->saldo_kredit = abs($saldo);
|
||||||
|
}
|
||||||
|
|
||||||
|
$total_debit += $r->saldo_debit;
|
||||||
|
$total_kredit += $r->saldo_kredit;
|
||||||
|
|
||||||
|
$result[] = [
|
||||||
|
'kode' => $r->kode_akun,
|
||||||
|
'nama' => $r->nama_akun,
|
||||||
|
'saldo_debit' => $r->saldo_debit,
|
||||||
|
'saldo_kredit' => $r->saldo_kredit,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'rows' => $rows,
|
||||||
|
'data' => $result,
|
||||||
|
'total_debit' => $total_debit,
|
||||||
|
'total_kredit' => $total_kredit,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// GET DATA NERACA SALDO (JSON, untuk AJAX/datatable)
|
||||||
|
// =========================
|
||||||
|
public function get_data()
|
||||||
|
{
|
||||||
|
$result = $this->get_neracasaldo_data();
|
||||||
|
|
||||||
|
echo json_encode($result['rows']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// PDF GENERATE — NERACA SALDO
|
||||||
|
// =========================
|
||||||
|
public function generatepdf()
|
||||||
|
{
|
||||||
|
if ($this->session->userdata('role') != 'Admin') {
|
||||||
|
show_error('Akses ditolak', 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ob_get_length()) {
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// AMBIL DATA
|
||||||
|
// =============================================================
|
||||||
|
$neracasaldo = $this->get_neracasaldo_data();
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// DATA PERUSAHAAN
|
||||||
|
// =============================================================
|
||||||
|
$company = $this->db->get('pengaturan')->row();
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// BUILD STRING PERIODE
|
||||||
|
// =============================================================
|
||||||
|
$periodeStr = 'Per Tanggal : ' . date('d-m-Y');
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// LOAD LIBRARY PDF
|
||||||
|
// =============================================================
|
||||||
|
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||||
|
require_once(APPPATH . 'libraries/PDF_Neracasaldo.php');
|
||||||
|
|
||||||
|
$pdf = new PDF ('P', 'mm', 'A4');
|
||||||
|
$pdf->SetMargins(10, 10, 10);
|
||||||
|
|
||||||
|
$pdf->setHeaderData(
|
||||||
|
$company->nama_perusahaan,
|
||||||
|
$company->alamat_perusahaan,
|
||||||
|
FCPATH . 'uploads/img/logo-ljn.png'
|
||||||
|
);
|
||||||
|
|
||||||
|
$pdf->setInfoLaporan($periodeStr);
|
||||||
|
|
||||||
|
$pdf->AddPage('P', 'A4');
|
||||||
|
$pdf->NeracaSaldoTable(
|
||||||
|
$neracasaldo['data'],
|
||||||
|
$neracasaldo['total_debit'],
|
||||||
|
$neracasaldo['total_kredit']
|
||||||
|
);
|
||||||
|
$pdf->NeracaSaldoRingkasan(
|
||||||
|
$neracasaldo['total_debit'],
|
||||||
|
$neracasaldo['total_kredit']
|
||||||
|
);
|
||||||
|
$pdf->Pembuat('Tito Ngudiana', 'Finance Department');
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// OUTPUT
|
||||||
|
// =============================================================
|
||||||
|
$filename = 'Neraca_Saldo_' . date('YmdHis') . '.pdf';
|
||||||
|
$pdf->Output('I', $filename);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,329 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||||
|
|
||||||
|
class PDF extends FPDF
|
||||||
|
{
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// PROPERTI HEADER
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
private $nama;
|
||||||
|
private $alamat;
|
||||||
|
private $logo;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// PROPERTI TABEL
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
private $isTable = false;
|
||||||
|
private $tableWidth = [];
|
||||||
|
private $tableHeader = [];
|
||||||
|
|
||||||
|
// Konfigurasi tabel A4 Portrait (lebar efektif = 190mm, margin 10+10)
|
||||||
|
// Tanggal : 22 | No Ref : 28 | Keterangan : 60 | Debit : 26 | Kredit : 26 | Saldo : 28 → TOTAL : 190
|
||||||
|
private $colWidths = [22, 28, 60, 26, 26, 28];
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// PROPERTI INFO LAPORAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
private $namaAkun = '';
|
||||||
|
private $periodeStr = '';
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// SETTER
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function setHeaderData($nama, $alamat, $logo = '')
|
||||||
|
{
|
||||||
|
$this->nama = $nama;
|
||||||
|
$this->alamat = $alamat;
|
||||||
|
$this->logo = $logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setInfoLaporan($namaAkun, $periodeStr)
|
||||||
|
{
|
||||||
|
$this->namaAkun = $namaAkun;
|
||||||
|
$this->periodeStr = $periodeStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTableHeader($header, $width)
|
||||||
|
{
|
||||||
|
$this->tableHeader = $header;
|
||||||
|
$this->tableWidth = $width;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HEADER HALAMAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function Header()
|
||||||
|
{
|
||||||
|
// Lebar halaman A4 Portrait = 210mm (area cetak 10..200)
|
||||||
|
$pageRight = 200;
|
||||||
|
|
||||||
|
// Logo (opsional)
|
||||||
|
if (!empty($this->logo) && file_exists($this->logo)) {
|
||||||
|
$this->Image($this->logo, 10, 6, 18);
|
||||||
|
$this->SetXY(31, 10);
|
||||||
|
} else {
|
||||||
|
$this->SetXY(10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nama perusahaan
|
||||||
|
$this->SetFont('Arial', 'B', 12);
|
||||||
|
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
|
||||||
|
|
||||||
|
// Alamat
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$x = !empty($this->logo) && file_exists($this->logo) ? 31 : 10;
|
||||||
|
$this->SetX($x);
|
||||||
|
$this->Cell(0, 5, $this->alamat, 0, 1, 'L');
|
||||||
|
|
||||||
|
// Garis pemisah
|
||||||
|
$this->Ln(2);
|
||||||
|
$this->SetLineWidth(0.6);
|
||||||
|
$this->Line(10, $this->GetY(), $pageRight, $this->GetY());
|
||||||
|
$this->SetLineWidth(0.2);
|
||||||
|
$this->Line(10, $this->GetY() + 1, $pageRight, $this->GetY() + 1);
|
||||||
|
$this->Ln(5);
|
||||||
|
|
||||||
|
// Judul
|
||||||
|
$this->SetFont('Arial', 'B', 13);
|
||||||
|
$this->SetTextColor(245, 140, 0);
|
||||||
|
$this->Cell(0, 7, 'LAPORAN BUKU BESAR', 0, 1, 'C');
|
||||||
|
$this->SetTextColor(0, 0, 0);
|
||||||
|
|
||||||
|
// Periode
|
||||||
|
$this->SetFont('Arial', '', 10);
|
||||||
|
$this->Cell(0, 5, $this->periodeStr, 0, 1, 'C');
|
||||||
|
|
||||||
|
$this->Ln(3);
|
||||||
|
|
||||||
|
// Info akun & tanggal cetak
|
||||||
|
$colLabel = 35;
|
||||||
|
$colSep = 5;
|
||||||
|
$startX = ($this->GetPageWidth() - array_sum($this->colWidths)) / 2;
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
$this->Cell($colLabel, 6, 'Akun');
|
||||||
|
$this->SetFont('Arial', '', 10);
|
||||||
|
$this->Cell($colSep, 6, ':');
|
||||||
|
$this->Cell(0, 6, $this->namaAkun, 0, 1);
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
$this->Cell($colLabel, 6, 'Di Cetak Pada');
|
||||||
|
$this->SetFont('Arial', '', 10);
|
||||||
|
$this->Cell($colSep, 6, ':');
|
||||||
|
$this->Cell(0, 6, date('d-m-Y') . ' Jam ' . date('H:i:s'), 0, 1);
|
||||||
|
|
||||||
|
$this->Ln(3);
|
||||||
|
|
||||||
|
if ($this->isTable && !empty($this->tableHeader)) {
|
||||||
|
$this->_drawTableHeader();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// FOOTER HALAMAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function Footer()
|
||||||
|
{
|
||||||
|
$this->SetY(-10);
|
||||||
|
$this->SetFont('Arial', 'I', 8);
|
||||||
|
$this->Cell(0, 5, 'Halaman ' . $this->PageNo(), 0, 0, 'C');
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: Gambar baris header tabel
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function _drawTableHeader()
|
||||||
|
{
|
||||||
|
$startX = ($this->GetPageWidth() - array_sum($this->colWidths)) / 2;
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFillColor(245, 140, 0);
|
||||||
|
$this->SetTextColor(255, 255, 255);
|
||||||
|
$this->SetFont('Arial', 'B', 9);
|
||||||
|
|
||||||
|
foreach ($this->tableHeader as $k => $v) {
|
||||||
|
$this->Cell($this->tableWidth[$k], 8, $v, 1, 0, 'C', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->SetTextColor(0, 0, 0);
|
||||||
|
$this->Ln();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// TABEL BUKU BESAR
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function BukuBesarTable($result)
|
||||||
|
{
|
||||||
|
$header = ['Tanggal', 'No Ref', 'Keterangan', 'Debit', 'Kredit', 'Saldo'];
|
||||||
|
|
||||||
|
$this->isTable = true;
|
||||||
|
$this->setTableHeader($header, $this->colWidths);
|
||||||
|
|
||||||
|
// Header halaman pertama
|
||||||
|
$this->_drawTableHeader();
|
||||||
|
|
||||||
|
$startX = ($this->GetPageWidth() - array_sum($this->colWidths)) / 2;
|
||||||
|
$lineH = 5;
|
||||||
|
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
|
||||||
|
if (empty($result)) {
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
$this->Cell(array_sum($this->colWidths), 8, 'Tidak ada data', 1, 1, 'C');
|
||||||
|
$this->isTable = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fill = false;
|
||||||
|
|
||||||
|
// Batas bawah A4 Portrait (297mm) dikurangi area footer
|
||||||
|
$pageBreakTrigger = 277;
|
||||||
|
|
||||||
|
foreach ($result as $row) {
|
||||||
|
|
||||||
|
// Hitung tinggi baris berdasar No Ref & Keterangan (keduanya MultiCell)
|
||||||
|
$nbRef = $this->NbLines($this->colWidths[1], $row['no_ref']);
|
||||||
|
$nbKet = $this->NbLines($this->colWidths[2], $row['keterangan']);
|
||||||
|
$nbLines = max(1, $nbRef, $nbKet);
|
||||||
|
$rowH = $nbLines * $lineH;
|
||||||
|
|
||||||
|
// Ganti halaman jika mendekati batas bawah
|
||||||
|
if ($this->GetY() + $rowH > $pageBreakTrigger) {
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fill) {
|
||||||
|
$this->SetFillColor(245, 245, 245);
|
||||||
|
}
|
||||||
|
|
||||||
|
$x = $startX;
|
||||||
|
$y = $this->GetY();
|
||||||
|
|
||||||
|
// Tanggal
|
||||||
|
$this->SetX($x);
|
||||||
|
$this->Cell($this->colWidths[0], $rowH, date('d-m-Y', strtotime($row['tanggal'])), 1, 0, 'C', $fill);
|
||||||
|
|
||||||
|
// No Ref (MultiCell)
|
||||||
|
$xRef = $this->GetX();
|
||||||
|
$offsetRef = ($rowH - $nbRef * $lineH) / 2;
|
||||||
|
// gambar border kotak dulu
|
||||||
|
$this->Rect($xRef, $y, $this->colWidths[1], $rowH, $fill ? 'DF' : 'D');
|
||||||
|
$this->SetXY($xRef, $y + $offsetRef);
|
||||||
|
$this->MultiCell($this->colWidths[1], $lineH, $row['no_ref'], 0, 'C', false);
|
||||||
|
|
||||||
|
// Keterangan (MultiCell)
|
||||||
|
$xKet = $xRef + $this->colWidths[1];
|
||||||
|
$offsetKet = ($rowH - $nbKet * $lineH) / 2;
|
||||||
|
$this->Rect($xKet, $y, $this->colWidths[2], $rowH, $fill ? 'DF' : 'D');
|
||||||
|
$this->SetXY($xKet, $y + $offsetKet);
|
||||||
|
$this->MultiCell($this->colWidths[2], $lineH, $row['keterangan'], 0, 'L', false);
|
||||||
|
|
||||||
|
// Kolom angka
|
||||||
|
$this->SetXY($xKet + $this->colWidths[2], $y);
|
||||||
|
$this->Cell($this->colWidths[3], $rowH, number_format($row['debit'], 2, ',', '.'), 1, 0, 'R', $fill);
|
||||||
|
$this->Cell($this->colWidths[4], $rowH, number_format($row['kredit'], 2, ',', '.'), 1, 0, 'R', $fill);
|
||||||
|
$this->Cell($this->colWidths[5], $rowH, number_format($row['saldo'], 2, ',', '.'), 1, 0, 'R', $fill);
|
||||||
|
|
||||||
|
$this->SetXY($x, $y + $rowH);
|
||||||
|
|
||||||
|
$fill = !$fill;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->isTable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// BARIS TOTAL
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function BukuBesarTotal($totalDebit, $totalKredit, $saldo)
|
||||||
|
{
|
||||||
|
$startX = ($this->GetPageWidth() - array_sum($this->colWidths)) / 2;
|
||||||
|
$labelWidth = $this->colWidths[0] + $this->colWidths[1] + $this->colWidths[2];
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFillColor(255, 204, 102);
|
||||||
|
$this->SetFont('Arial', 'B', 9);
|
||||||
|
|
||||||
|
$this->Cell($labelWidth, 8, 'TOTAL', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[3], 8, number_format($totalDebit, 2, ',', '.'), 1, 0, 'R', true);
|
||||||
|
$this->Cell($this->colWidths[4], 8, number_format($totalKredit, 2, ',', '.'), 1, 0, 'R', true);
|
||||||
|
$this->Cell($this->colWidths[5], 8, number_format($saldo, 2, ',', '.'), 1, 1, 'R', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// TANDA TANGAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function Pembuat($nama, $jabatan = '')
|
||||||
|
{
|
||||||
|
$signWidth = 70;
|
||||||
|
$signX = 125; // disesuaikan untuk A4 Portrait (210mm)
|
||||||
|
|
||||||
|
$this->Ln(10);
|
||||||
|
$this->SetX($signX);
|
||||||
|
$this->SetFont('Arial', '', 10);
|
||||||
|
$this->Cell($signWidth, 6, 'Mengetahui,', 0, 1, 'C');
|
||||||
|
|
||||||
|
$this->Ln(10);
|
||||||
|
$this->SetX($signX);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
$this->Cell($signWidth, 6, $nama, 0, 1, 'C');
|
||||||
|
|
||||||
|
if (!empty($jabatan)) {
|
||||||
|
$this->SetX($signX);
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$this->Cell($signWidth, 5, '(' . $jabatan . ')', 0, 1, 'C');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: Hitung jumlah baris MultiCell
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function NbLines($w, $txt)
|
||||||
|
{
|
||||||
|
$cw = &$this->CurrentFont['cw'];
|
||||||
|
if ($w == 0) {
|
||||||
|
$w = $this->w - $this->rMargin - $this->x;
|
||||||
|
}
|
||||||
|
$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
|
||||||
|
$s = str_replace("\r", '', (string)$txt);
|
||||||
|
$nb = strlen($s);
|
||||||
|
if ($nb > 0 && $s[$nb - 1] == "\n") {
|
||||||
|
$nb--;
|
||||||
|
}
|
||||||
|
$sep = -1;
|
||||||
|
$i = 0; $j = 0; $l = 0; $nl = 1;
|
||||||
|
while ($i < $nb) {
|
||||||
|
$c = $s[$i];
|
||||||
|
if ($c == "\n") {
|
||||||
|
$i++; $sep = -1; $j = $i; $l = 0; $nl++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($c == ' ') {
|
||||||
|
$sep = $i;
|
||||||
|
}
|
||||||
|
$l += isset($cw[ord($c)]) ? $cw[ord($c)] : 600;
|
||||||
|
if ($l > $wmax) {
|
||||||
|
if ($sep == -1) {
|
||||||
|
if ($i == $j) $i++;
|
||||||
|
} else {
|
||||||
|
$i = $sep + 1;
|
||||||
|
}
|
||||||
|
$sep = -1; $j = $i; $l = 0; $nl++;
|
||||||
|
} else {
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(APPPATH.'third_party/fpdf/fpdf.php');
|
||||||
|
|
||||||
|
class PDF extends FPDF
|
||||||
|
{
|
||||||
|
private $nama;
|
||||||
|
private $alamat;
|
||||||
|
private $telepon;
|
||||||
|
private $logo;
|
||||||
|
|
||||||
|
private $isTable = false;
|
||||||
|
private $tableWidth = [];
|
||||||
|
private $tableHeader = [];
|
||||||
|
|
||||||
|
// Lebar kertas A4 Portrait = 210mm, margin kiri+kanan = 10+10 = 20mm
|
||||||
|
// Area cetak efektif = 190mm
|
||||||
|
private $pageWidth = 190;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// SETTER
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function setHeaderData($nama, $alamat, $telepon, $logo = '')
|
||||||
|
{
|
||||||
|
$this->nama = $nama;
|
||||||
|
$this->alamat = $alamat;
|
||||||
|
$this->telepon = $telepon;
|
||||||
|
$this->logo = $logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTableHeader($header, $width)
|
||||||
|
{
|
||||||
|
$this->tableHeader = $header;
|
||||||
|
$this->tableWidth = $width;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HEADER HALAMAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function Header()
|
||||||
|
{
|
||||||
|
// Logo (opsional)
|
||||||
|
if (!empty($this->logo) && file_exists($this->logo)) {
|
||||||
|
$this->Image($this->logo, 10, 8, 18);
|
||||||
|
$this->SetXY(31, 10);
|
||||||
|
} else {
|
||||||
|
$this->SetXY(10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nama perusahaan
|
||||||
|
$this->SetFont('Arial', 'B', 12);
|
||||||
|
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
|
||||||
|
|
||||||
|
// Alamat
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$x = !empty($this->logo) && file_exists($this->logo) ? 31 : 10;
|
||||||
|
$this->SetX($x);
|
||||||
|
$this->Cell(0, 5, $this->alamat, 0, 1, 'L');
|
||||||
|
|
||||||
|
$this->SetX($x);
|
||||||
|
$this->Cell(0, 5, 'Telp : ' . $this->telepon, 0, 1, 'L');
|
||||||
|
|
||||||
|
// Garis pemisah header (A4 Portrait: dari x=10 s/d x=200)
|
||||||
|
$this->Ln(2);
|
||||||
|
$this->SetLineWidth(0.6);
|
||||||
|
$this->Line(10, $this->GetY(), 200, $this->GetY());
|
||||||
|
$this->SetLineWidth(0.2);
|
||||||
|
$this->Line(10, $this->GetY() + 1, 200, $this->GetY() + 1);
|
||||||
|
|
||||||
|
$this->Ln(5);
|
||||||
|
|
||||||
|
// Judul laporan
|
||||||
|
$this->SetFont('Arial', 'B', 14);
|
||||||
|
$this->SetTextColor(245, 140, 0);
|
||||||
|
$this->Cell(0, 8, 'LAPORAN DATA BARANG', 0, 1, 'C');
|
||||||
|
$this->SetTextColor(0, 0, 0);
|
||||||
|
|
||||||
|
// Tanggal cetak
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$this->Cell(0, 5, 'DIcetak Pada : ' . date('d-m-Y') . ' - ' . date('H:i:s'), 0, 1, 'C');
|
||||||
|
|
||||||
|
$this->Ln(3);
|
||||||
|
|
||||||
|
// Header tabel (muncul otomatis saat ganti halaman)
|
||||||
|
if ($this->isTable && !empty($this->tableHeader)) {
|
||||||
|
$this->_drawTableHeader();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// FOOTER HALAMAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function Footer()
|
||||||
|
{
|
||||||
|
$this->SetY(-10);
|
||||||
|
$this->SetFont('Arial', 'I', 8);
|
||||||
|
$this->Cell(0, 5, 'Halaman ' . $this->PageNo(), 0, 0, 'C');
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: Gambar baris header tabel
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function _drawTableHeader()
|
||||||
|
{
|
||||||
|
$this->SetFillColor(245, 140, 0);
|
||||||
|
$this->SetTextColor(255, 255, 255);
|
||||||
|
$this->SetFont('Arial', 'B', 8);
|
||||||
|
|
||||||
|
foreach ($this->tableHeader as $k => $v) {
|
||||||
|
$this->Cell($this->tableWidth[$k], 7, $v, 1, 0, 'C', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->SetTextColor(0, 0, 0);
|
||||||
|
$this->Ln();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// TABEL DATA BARANG
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function ItemsTable($data)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Total lebar kolom = 190mm (pas A4 Portrait, margin 10mm kiri & kanan)
|
||||||
|
*
|
||||||
|
* NO : 8
|
||||||
|
* TGL BELI : 22
|
||||||
|
* KODE : 22
|
||||||
|
* NAMA BARANG : 48 ← kolom terpanjang
|
||||||
|
* GUDANG : 35
|
||||||
|
* STOK : 13
|
||||||
|
* HARGA BELI : 21
|
||||||
|
* HARGA JUAL : 21
|
||||||
|
* ----
|
||||||
|
* TOTAL : 190
|
||||||
|
*/
|
||||||
|
$w = [8, 22, 22, 48, 35, 13, 21, 21];
|
||||||
|
|
||||||
|
$header = [
|
||||||
|
'NO',
|
||||||
|
'TGL BELI',
|
||||||
|
'KODE',
|
||||||
|
'NAMA BARANG',
|
||||||
|
'GUDANG',
|
||||||
|
'STOK',
|
||||||
|
'HARGA BELI',
|
||||||
|
'HARGA JUAL',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Daftarkan SEBELUM AddPage() agar Header() sudah tahu isTable=true
|
||||||
|
// ketika halaman berikutnya dibuat (termasuk halaman ke-2, 3, dst.)
|
||||||
|
$this->isTable = true;
|
||||||
|
$this->setTableHeader($header, $w);
|
||||||
|
|
||||||
|
// Gambar header tabel di halaman PERTAMA secara eksplisit,
|
||||||
|
// karena saat AddPage() awal dipanggil isTable masih false.
|
||||||
|
$this->_drawTableHeader();
|
||||||
|
|
||||||
|
// ---- Baris data ----
|
||||||
|
$this->SetFont('Arial', '', 8);
|
||||||
|
$no = 1;
|
||||||
|
|
||||||
|
foreach ($data as $row) {
|
||||||
|
|
||||||
|
// Ganti halaman sebelum batas bawah (A4 Portrait: tinggi efektif ~267mm)
|
||||||
|
if ($this->GetY() > 262) {
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
// _drawTableHeader() sudah dipanggil otomatis oleh Header()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warna baris selang-seling
|
||||||
|
if ($no % 2 === 0) {
|
||||||
|
$this->SetFillColor(255, 245, 230);
|
||||||
|
$fill = true;
|
||||||
|
} else {
|
||||||
|
$fill = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->Cell($w[0], 6, $no++, 1, 0, 'C', $fill);
|
||||||
|
$this->Cell($w[1], 6, date('d-m-Y', strtotime($row->tanggal_pembelian)), 1, 0, 'C', $fill);
|
||||||
|
$this->Cell($w[2], 6, $row->kode_detail, 1, 0, 'C', $fill);
|
||||||
|
$this->Cell($w[3], 6, mb_substr($row->nama_barang, 0, 45), 1, 0, 'L', $fill);
|
||||||
|
$this->Cell($w[4], 6, mb_substr($row->gudang ?: '-', 0, 30), 1, 0, 'L', $fill);
|
||||||
|
$this->Cell($w[5], 6, number_format($row->stok), 1, 0, 'R', $fill);
|
||||||
|
$this->Cell($w[6], 6, number_format($row->harga_beli, 0, ',', '.'), 1, 0, 'R', $fill);
|
||||||
|
$this->Cell($w[7], 6, number_format($row->harga_jual, 0, ',', '.'), 1, 1, 'R', $fill);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->isTable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// RINGKASAN & TANDA TANGAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function TotalBarang($jumlah)
|
||||||
|
{
|
||||||
|
$this->Ln(4);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
$this->Cell(0, 7, 'Total Data Barang : ' . $jumlah, 0, 1, 'R');
|
||||||
|
}
|
||||||
|
|
||||||
|
// public function Pembuat($nama)
|
||||||
|
// {
|
||||||
|
// $this->Ln(12);
|
||||||
|
// $this->SetFont('Arial', '', 10);
|
||||||
|
// $this->Cell(0, 6, 'Mengetahui,', 0, 1, 'R');
|
||||||
|
// $this->Ln(18);
|
||||||
|
// $this->SetFont('Arial', 'B', 10);
|
||||||
|
// $this->Cell(0, 6, $nama, 0, 1, 'R');
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,345 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||||
|
|
||||||
|
class PDF extends FPDF
|
||||||
|
{
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// PROPERTI HEADER
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
private $nama;
|
||||||
|
private $alamat;
|
||||||
|
private $logo;
|
||||||
|
private $periodeStr = '';
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// KONFIGURASI TABEL
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// A4 Portrait efektif = 190mm, margin 10+10
|
||||||
|
// Kolom: Kode 20 | Nama Akun 120 | Saldo 50 → TOTAL 190
|
||||||
|
private $colWidths = [20, 120, 50];
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// SETTER
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function setHeaderData($nama, $alamat, $logo = '')
|
||||||
|
{
|
||||||
|
$this->nama = $nama;
|
||||||
|
$this->alamat = $alamat;
|
||||||
|
$this->logo = $logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setInfoLaporan($periodeStr)
|
||||||
|
{
|
||||||
|
$this->periodeStr = $periodeStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HEADER HALAMAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function Header()
|
||||||
|
{
|
||||||
|
// Logo (opsional)
|
||||||
|
if (!empty($this->logo) && file_exists($this->logo)) {
|
||||||
|
$this->Image($this->logo, 10, 6, 18);
|
||||||
|
$this->SetXY(31, 10);
|
||||||
|
} else {
|
||||||
|
$this->SetXY(10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nama perusahaan
|
||||||
|
$this->SetFont('Arial', 'B', 12);
|
||||||
|
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
|
||||||
|
|
||||||
|
// Alamat
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$x = !empty($this->logo) && file_exists($this->logo) ? 31 : 10;
|
||||||
|
$this->SetX($x);
|
||||||
|
$this->Cell(0, 5, $this->alamat, 0, 1, 'L');
|
||||||
|
|
||||||
|
// Garis pemisah (A4 Portrait: x=10 s/d x=200)
|
||||||
|
$this->Ln(2);
|
||||||
|
$this->SetLineWidth(0.6);
|
||||||
|
$this->Line(10, $this->GetY(), 200, $this->GetY());
|
||||||
|
$this->SetLineWidth(0.2);
|
||||||
|
$this->Line(10, $this->GetY() + 1, 200, $this->GetY() + 1);
|
||||||
|
$this->Ln(5);
|
||||||
|
|
||||||
|
// Judul
|
||||||
|
$this->SetFont('Arial', 'B', 13);
|
||||||
|
$this->SetTextColor(245, 140, 0);
|
||||||
|
$this->Cell(0, 7, 'LAPORAN LABA RUGI', 0, 1, 'C');
|
||||||
|
$this->SetTextColor(0, 0, 0);
|
||||||
|
|
||||||
|
// Periode
|
||||||
|
$this->SetFont('Arial', '', 10);
|
||||||
|
$this->Cell(0, 5, $this->periodeStr, 0, 1, 'C');
|
||||||
|
|
||||||
|
// Tanggal cetak
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$this->Cell(0, 5, 'Di Cetak Pada : ' . date('d-m-Y') . ' Jam ' . date('H:i:s'), 0, 1, 'C');
|
||||||
|
|
||||||
|
$this->Ln(4);
|
||||||
|
|
||||||
|
// Header kolom tabel
|
||||||
|
$this->_drawTableHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// FOOTER HALAMAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function Footer()
|
||||||
|
{
|
||||||
|
$this->SetY(-10);
|
||||||
|
$this->SetFont('Arial', 'I', 8);
|
||||||
|
$this->Cell(0, 5, 'Halaman ' . $this->PageNo(), 0, 0, 'C');
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: posisi X awal — TABEL RATA TENGAH KERTAS
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function _startX()
|
||||||
|
{
|
||||||
|
$tableW = array_sum($this->colWidths);
|
||||||
|
return ($this->GetPageWidth() - $tableW) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: Gambar header kolom tabel
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function _drawTableHeader()
|
||||||
|
{
|
||||||
|
$startX = $this->_startX();
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFillColor(245, 140, 0);
|
||||||
|
$this->SetTextColor(255, 255, 255);
|
||||||
|
$this->SetFont('Arial', 'B', 9);
|
||||||
|
|
||||||
|
$this->Cell($this->colWidths[0], 8, 'Kode', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[1], 8, 'Nama Akun', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[2], 8, 'Saldo', 1, 1, 'C', true);
|
||||||
|
|
||||||
|
$this->SetTextColor(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: Gambar baris judul section (PENDAPATAN / BEBAN)
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function _drawSectionTitle($title)
|
||||||
|
{
|
||||||
|
if ($this->GetY() + 8 > 270) {
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$tableW = array_sum($this->colWidths);
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFillColor(255, 224, 178);
|
||||||
|
$this->SetFont('Arial', 'B', 9);
|
||||||
|
$this->Cell($tableW, 7, $title, 1, 1, 'L', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: Gambar baris detail akun (dengan dukungan multiline Nama Akun)
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function _drawRow($kode, $namaAkun, $saldo)
|
||||||
|
{
|
||||||
|
$lineH = 6;
|
||||||
|
|
||||||
|
$nbLines = $this->NbLines($this->colWidths[1], $namaAkun);
|
||||||
|
$rowH = max(1, $nbLines) * $lineH;
|
||||||
|
|
||||||
|
if ($this->GetY() + $rowH > 270) {
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$y = $this->GetY();
|
||||||
|
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$this->SetXY($startX, $y);
|
||||||
|
$this->Cell($this->colWidths[0], $rowH, $kode, 1, 0, 'C');
|
||||||
|
|
||||||
|
$xNama = $this->GetX();
|
||||||
|
$this->MultiCell($this->colWidths[1], $lineH, $namaAkun, 1, 'L');
|
||||||
|
|
||||||
|
$this->SetXY($xNama + $this->colWidths[1], $y);
|
||||||
|
$this->Cell($this->colWidths[2], $rowH, number_format($saldo, 0, ',', '.'), 1, 0, 'R');
|
||||||
|
|
||||||
|
$this->SetXY($startX, $y + $rowH);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: Gambar baris total section
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function _drawSectionTotal($label, $total)
|
||||||
|
{
|
||||||
|
if ($this->GetY() + 7 > 270) {
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$startX = $this->_startX();
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFillColor(255, 224, 178);
|
||||||
|
$this->SetFont('Arial', 'B', 9);
|
||||||
|
$this->Cell($this->colWidths[0] + $this->colWidths[1], 7, $label, 1, 0, 'L', true);
|
||||||
|
$this->Cell($this->colWidths[2], 7, number_format($total, 0, ',', '.'), 1, 1, 'R', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// TABEL LABA RUGI (PENDAPATAN, BEBAN, masing-masing dengan rincian akun)
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function LabaRugiTable($pendapatan, $beban, $totalPendapatan, $totalBeban)
|
||||||
|
{
|
||||||
|
// ---- SECTION PENDAPATAN ----
|
||||||
|
$this->_drawSectionTitle('PENDAPATAN');
|
||||||
|
|
||||||
|
if (empty($pendapatan)) {
|
||||||
|
$this->_drawRow('-', 'Tidak ada data', 0);
|
||||||
|
} else {
|
||||||
|
foreach ($pendapatan as $row) {
|
||||||
|
$this->_drawRow($row['kode'], $row['nama'], $row['saldo']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_drawSectionTotal('TOTAL PENDAPATAN', $totalPendapatan);
|
||||||
|
|
||||||
|
// ---- SECTION BEBAN ----
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
$this->_drawSectionTitle('BEBAN');
|
||||||
|
|
||||||
|
if (empty($beban)) {
|
||||||
|
$this->_drawRow('-', 'Tidak ada data', 0);
|
||||||
|
} else {
|
||||||
|
foreach ($beban as $row) {
|
||||||
|
$this->_drawRow($row['kode'], $row['nama'], $row['saldo']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_drawSectionTotal('TOTAL BEBAN', $totalBeban);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// RINGKASAN: LABA / RUGI BERSIH
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function LabaRugiRingkasan($laba)
|
||||||
|
{
|
||||||
|
if ($this->GetY() + 9 > 270) {
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$tableW = array_sum($this->colWidths);
|
||||||
|
$labelW = $tableW - $this->colWidths[2];
|
||||||
|
|
||||||
|
$this->Ln(2);
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
|
||||||
|
if ($laba >= 0) {
|
||||||
|
$this->SetFillColor(198, 239, 206); // hijau, laba
|
||||||
|
$label = 'LABA BERSIH';
|
||||||
|
} else {
|
||||||
|
$this->SetFillColor(255, 199, 206); // merah, rugi
|
||||||
|
$label = 'RUGI BERSIH';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->Cell($labelW, 8, $label, 1, 0, 'L', true);
|
||||||
|
$this->Cell($this->colWidths[2], 8, number_format($laba, 0, ',', '.'), 1, 1, 'R', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// TANDA TANGAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function Pembuat($nama, $jabatan = '')
|
||||||
|
{
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$tableW = array_sum($this->colWidths);
|
||||||
|
$signWidth = 70;
|
||||||
|
$signX = $startX + $tableW - $signWidth; // sejajar sisi kanan tabel
|
||||||
|
|
||||||
|
$this->Ln(10);
|
||||||
|
$this->SetX($signX);
|
||||||
|
$this->SetFont('Arial', '', 10);
|
||||||
|
$this->Cell($signWidth, 6, 'Mengetahui,', 0, 1, 'R');
|
||||||
|
|
||||||
|
$this->Ln(10);
|
||||||
|
$this->SetX($signX);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
$this->Cell($signWidth, 6, $nama, 0, 1, 'R');
|
||||||
|
|
||||||
|
if (!empty($jabatan)) {
|
||||||
|
$this->SetX($signX);
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$this->Cell($signWidth, 5, '(' . $jabatan . ')', 0, 1, 'R');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: Hitung jumlah baris yang dibutuhkan MultiCell
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function NbLines($w, $txt)
|
||||||
|
{
|
||||||
|
$cw = &$this->CurrentFont['cw'];
|
||||||
|
if ($w == 0) {
|
||||||
|
$w = $this->w - $this->rMargin - $this->x;
|
||||||
|
}
|
||||||
|
$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
|
||||||
|
$s = str_replace("\r", '', $txt);
|
||||||
|
$nb = strlen($s);
|
||||||
|
if ($nb > 0 && $s[$nb - 1] == "\n") {
|
||||||
|
$nb--;
|
||||||
|
}
|
||||||
|
$sep = -1;
|
||||||
|
$i = 0;
|
||||||
|
$j = 0;
|
||||||
|
$l = 0;
|
||||||
|
$nl = 1;
|
||||||
|
while ($i < $nb) {
|
||||||
|
$c = $s[$i];
|
||||||
|
if ($c == "\n") {
|
||||||
|
$i++;
|
||||||
|
$sep = -1;
|
||||||
|
$j = $i;
|
||||||
|
$l = 0;
|
||||||
|
$nl++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($c == ' ') {
|
||||||
|
$sep = $i;
|
||||||
|
}
|
||||||
|
$l += isset($cw[ord($c)]) ? $cw[ord($c)] : 600;
|
||||||
|
if ($l > $wmax) {
|
||||||
|
if ($sep == -1) {
|
||||||
|
if ($i == $j) {
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$i = $sep + 1;
|
||||||
|
}
|
||||||
|
$sep = -1;
|
||||||
|
$j = $i;
|
||||||
|
$l = 0;
|
||||||
|
$nl++;
|
||||||
|
} else {
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,296 @@
|
|||||||
|
<?php
|
||||||
|
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||||
|
|
||||||
|
class PDF extends FPDF
|
||||||
|
{
|
||||||
|
private $nama;
|
||||||
|
private $alamat;
|
||||||
|
private $logo;
|
||||||
|
private $periodeStr = '';
|
||||||
|
|
||||||
|
private $colWidths = [15, 47, 23];
|
||||||
|
private $gap = 10;
|
||||||
|
|
||||||
|
public function setHeaderData($nama, $alamat, $logo = '')
|
||||||
|
{
|
||||||
|
$this->nama = $nama;
|
||||||
|
$this->alamat = $alamat;
|
||||||
|
$this->logo = $logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setInfoLaporan($periodeStr)
|
||||||
|
{
|
||||||
|
$this->periodeStr = $periodeStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Header()
|
||||||
|
{
|
||||||
|
if (!empty($this->logo) && file_exists($this->logo)) {
|
||||||
|
$this->Image($this->logo, 10, 6, 18);
|
||||||
|
$this->SetXY(31, 10);
|
||||||
|
} else {
|
||||||
|
$this->SetXY(10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->SetFont('Arial', 'B', 12);
|
||||||
|
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
|
||||||
|
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$x = !empty($this->logo) && file_exists($this->logo) ? 31 : 10;
|
||||||
|
$this->SetX($x);
|
||||||
|
$this->Cell(0, 5, $this->alamat, 0, 1, 'L');
|
||||||
|
|
||||||
|
$this->Ln(2);
|
||||||
|
$this->SetLineWidth(0.6);
|
||||||
|
$this->Line(10, $this->GetY(), 200, $this->GetY());
|
||||||
|
$this->SetLineWidth(0.2);
|
||||||
|
$this->Line(10, $this->GetY() + 1, 200, $this->GetY() + 1);
|
||||||
|
$this->Ln(5);
|
||||||
|
|
||||||
|
$this->SetFont('Arial', 'B', 13);
|
||||||
|
$this->SetTextColor(245, 140, 0);
|
||||||
|
$this->Cell(0, 7, 'LAPORAN NERACA', 0, 1, 'C');
|
||||||
|
$this->SetTextColor(0, 0, 0);
|
||||||
|
|
||||||
|
$this->SetFont('Arial', '', 10);
|
||||||
|
$this->Cell(0, 5, $this->periodeStr, 0, 1, 'C');
|
||||||
|
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$this->Cell(0, 5, 'Di Cetak Pada : ' . date('d-m-Y') . ' - ' . date('H:i:s'), 0, 1, 'C');
|
||||||
|
|
||||||
|
$this->Ln(4);
|
||||||
|
$this->_drawSectionHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
function Footer()
|
||||||
|
{
|
||||||
|
$this->SetY(-10);
|
||||||
|
$this->SetFont('Arial', 'I', 8);
|
||||||
|
$this->Cell(0, 5, 'Halaman ' . $this->PageNo(), 0, 0, 'C');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _drawSectionHeader()
|
||||||
|
{
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$tableW = array_sum($this->colWidths);
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFillColor(245, 140, 0);
|
||||||
|
$this->SetTextColor(255, 255, 255);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
$this->Cell($tableW, 7, 'ACTIVA', 1, 0, 'C', true);
|
||||||
|
|
||||||
|
$this->SetX($startX + $tableW + $this->gap);
|
||||||
|
$this->Cell($tableW, 7, 'PASIVA', 1, 1, 'C', true);
|
||||||
|
|
||||||
|
$this->SetFont('Arial', 'B', 8);
|
||||||
|
$this->SetFillColor(255, 224, 178);
|
||||||
|
$this->SetTextColor(0, 0, 0);
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->Cell($this->colWidths[0], 6, 'Kode', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[1], 6, 'Nama Akun', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[2], 6, 'Saldo', 1, 0, 'C', true);
|
||||||
|
|
||||||
|
$this->SetX($startX + $tableW + $this->gap);
|
||||||
|
$this->Cell($this->colWidths[0], 6, 'Kode', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[1], 6, 'Nama Akun', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[2], 6, 'Saldo', 1, 1, 'C', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _startX()
|
||||||
|
{
|
||||||
|
$totalW = (array_sum($this->colWidths) * 2) + $this->gap;
|
||||||
|
return ($this->GetPageWidth() - $totalW) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hitung jumlah baris yang dibutuhkan MultiCell untuk teks tertentu
|
||||||
|
* pada lebar kolom $w. Diadaptasi dari contoh resmi FPDF.
|
||||||
|
*/
|
||||||
|
private function _nbLines($w, $txt)
|
||||||
|
{
|
||||||
|
if ($txt === null || $txt === '') return 1;
|
||||||
|
$cw = &$this->CurrentFont['cw'];
|
||||||
|
if ($w == 0) {
|
||||||
|
$w = $this->w - $this->rMargin - $this->x;
|
||||||
|
}
|
||||||
|
$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
|
||||||
|
$s = str_replace("\r", '', (string)$txt);
|
||||||
|
$nb = strlen($s);
|
||||||
|
if ($nb > 0 && $s[$nb - 1] == "\n") $nb--;
|
||||||
|
$sep = -1; $i = 0; $j = 0; $l = 0; $nl = 1;
|
||||||
|
while ($i < $nb) {
|
||||||
|
$c = $s[$i];
|
||||||
|
if ($c == "\n") { $i++; $sep = -1; $j = $i; $l = 0; $nl++; continue; }
|
||||||
|
if ($c == ' ') $sep = $i;
|
||||||
|
$l += isset($cw[$c]) ? $cw[$c] : 0;
|
||||||
|
if ($l > $wmax) {
|
||||||
|
if ($sep == -1) {
|
||||||
|
if ($i == $j) $i++;
|
||||||
|
} else {
|
||||||
|
$i = $sep + 1;
|
||||||
|
}
|
||||||
|
$sep = -1; $j = $i; $l = 0; $nl++;
|
||||||
|
} else {
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render satu baris (kiri+kanan) dengan tinggi sama,
|
||||||
|
* memakai MultiCell untuk kolom Nama Akun.
|
||||||
|
*/
|
||||||
|
private function _drawRow($activaRow, $pasivaRow, $startX, $rightX, $lineH)
|
||||||
|
{
|
||||||
|
$wNama = $this->colWidths[1];
|
||||||
|
|
||||||
|
$nlA = $activaRow ? $this->_nbLines($wNama, $activaRow['nama']) : 1;
|
||||||
|
$nlB = $pasivaRow ? $this->_nbLines($wNama, $pasivaRow['nama']) : 1;
|
||||||
|
$nl = max($nlA, $nlB, 1);
|
||||||
|
$h = $lineH * $nl;
|
||||||
|
|
||||||
|
// page break manual agar baris tidak terpotong
|
||||||
|
if ($this->GetY() + $h > $this->PageBreakTrigger) {
|
||||||
|
$this->AddPage($this->CurOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
$y = $this->GetY();
|
||||||
|
|
||||||
|
// ---------- ACTIVA ----------
|
||||||
|
$this->SetXY($startX, $y);
|
||||||
|
if ($activaRow) {
|
||||||
|
// Kode (auto vertical-center karena pakai Cell dengan tinggi $h)
|
||||||
|
$this->Cell($this->colWidths[0], $h, $activaRow['kode'], 1, 0, 'C');
|
||||||
|
|
||||||
|
// Nama (MultiCell) — vertical center manual
|
||||||
|
$xNama = $this->GetX();
|
||||||
|
$this->Rect($xNama, $y, $wNama, $h);
|
||||||
|
$nLines = $this->_nbLines($wNama, $activaRow['nama']);
|
||||||
|
$offsetY = ($h - $lineH * $nLines) / 2;
|
||||||
|
$this->SetXY($xNama, $y + $offsetY);
|
||||||
|
$this->MultiCell($wNama, $lineH, $activaRow['nama'], 0, 'L');
|
||||||
|
|
||||||
|
// Saldo
|
||||||
|
$this->SetXY($xNama + $wNama, $y);
|
||||||
|
$this->Cell($this->colWidths[2], $h, number_format($activaRow['saldo'], 0, ',', '.'), 1, 0, 'R');
|
||||||
|
} else {
|
||||||
|
$this->Cell($this->colWidths[0], $h, '', 1, 0);
|
||||||
|
$this->Cell($wNama, $h, '', 1, 0);
|
||||||
|
$this->Cell($this->colWidths[2], $h, '', 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- PASIVA ----------
|
||||||
|
$this->SetXY($rightX, $y);
|
||||||
|
if ($pasivaRow) {
|
||||||
|
$this->Cell($this->colWidths[0], $h, $pasivaRow['kode'], 1, 0, 'C');
|
||||||
|
|
||||||
|
$xNama = $this->GetX();
|
||||||
|
$this->Rect($xNama, $y, $wNama, $h);
|
||||||
|
$nLines = $this->_nbLines($wNama, $pasivaRow['nama']);
|
||||||
|
$offsetY = ($h - $lineH * $nLines) / 2;
|
||||||
|
$this->SetXY($xNama, $y + $offsetY);
|
||||||
|
$this->MultiCell($wNama, $lineH, $pasivaRow['nama'], 0, 'L');
|
||||||
|
|
||||||
|
$this->SetXY($xNama + $wNama, $y);
|
||||||
|
$this->Cell($this->colWidths[2], $h, number_format($pasivaRow['saldo'], 0, ',', '.'), 1, 0, 'R');
|
||||||
|
} else {
|
||||||
|
$this->Cell($this->colWidths[0], $h, '', 1, 0);
|
||||||
|
$this->Cell($wNama, $h, '', 1, 0);
|
||||||
|
$this->Cell($this->colWidths[2], $h, '', 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// pindah ke baris berikutnya
|
||||||
|
$this->SetXY($startX, $y + $h);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function NeracaTable($activa, $pasiva, $totalActiva, $totalPasiva)
|
||||||
|
{
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$tableW = array_sum($this->colWidths);
|
||||||
|
$rightX = $startX + $tableW + $this->gap;
|
||||||
|
$lineH = 5;
|
||||||
|
|
||||||
|
$this->SetFont('Arial', '', 8);
|
||||||
|
|
||||||
|
$maxRow = max(count($activa), count($pasiva));
|
||||||
|
for ($i = 0; $i < $maxRow; $i++) {
|
||||||
|
$this->_drawRow(
|
||||||
|
isset($activa[$i]) ? $activa[$i] : null,
|
||||||
|
isset($pasiva[$i]) ? $pasiva[$i] : null,
|
||||||
|
$startX, $rightX, $lineH
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- BARIS TOTAL ----
|
||||||
|
if ($this->GetY() + 8 > $this->PageBreakTrigger) {
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$y = $this->GetY();
|
||||||
|
$this->SetFont('Arial', 'B', 8);
|
||||||
|
$this->SetFillColor(255, 204, 102);
|
||||||
|
|
||||||
|
$this->SetXY($startX, $y);
|
||||||
|
$this->Cell($this->colWidths[0] + $this->colWidths[1], 7, 'TOTAL ACTIVA', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[2], 7, number_format($totalActiva, 0, ',', '.'), 1, 0, 'R', true);
|
||||||
|
|
||||||
|
$this->SetXY($rightX, $y);
|
||||||
|
$this->Cell($this->colWidths[0] + $this->colWidths[1], 7, 'TOTAL PASIVA', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[2], 7, number_format($totalPasiva, 0, ',', '.'), 1, 1, 'R', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function NeracaRingkasan($laba, $selisih)
|
||||||
|
{
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$tableW = array_sum($this->colWidths) * 2 + $this->gap;
|
||||||
|
$labelW = $tableW - 40;
|
||||||
|
|
||||||
|
$this->Ln(4);
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFont('Arial', 'B', 9);
|
||||||
|
$this->Cell($labelW, 7, 'Laba Rugi Berjalan', 1, 0, 'L');
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$this->Cell(40, 7, number_format($laba, 0, ',', '.'), 1, 1, 'R');
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFont('Arial', 'B', 9);
|
||||||
|
if (abs($selisih) < 1) {
|
||||||
|
$this->SetFillColor(198, 239, 206);
|
||||||
|
$label = 'Selisih (Balance)';
|
||||||
|
} else {
|
||||||
|
$this->SetFillColor(255, 199, 206);
|
||||||
|
$label = 'Selisih (Tidak Balance)';
|
||||||
|
}
|
||||||
|
$this->Cell($labelW, 7, $label, 1, 0, 'L', true);
|
||||||
|
$this->Cell(40, 7, number_format($selisih, 0, ',', '.'), 1, 1, 'R', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Pembuat($nama, $jabatan = '')
|
||||||
|
{
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$tableW = array_sum($this->colWidths) * 2 + $this->gap;
|
||||||
|
$signWidth = 70;
|
||||||
|
$signX = $startX + $tableW - $signWidth;
|
||||||
|
|
||||||
|
$this->Ln(15);
|
||||||
|
$this->SetX($signX);
|
||||||
|
$this->SetFont('Arial', '', 10);
|
||||||
|
$this->Cell($signWidth, 6, 'Mengetahui,', 0, 1, 'R');
|
||||||
|
|
||||||
|
$this->Ln(18);
|
||||||
|
$this->SetX($signX);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
$this->Cell($signWidth, 6, $nama, 0, 1, 'R');
|
||||||
|
|
||||||
|
if (!empty($jabatan)) {
|
||||||
|
$this->SetX($signX);
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$this->Cell($signWidth, 5, '(' . $jabatan . ')', 0, 1, 'R');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,303 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||||
|
|
||||||
|
class PDF extends FPDF
|
||||||
|
{
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// PROPERTI HEADER
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
private $nama;
|
||||||
|
private $alamat;
|
||||||
|
private $logo;
|
||||||
|
private $periodeStr = '';
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// KONFIGURASI TABEL
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// A4 Portrait efektif = 190mm, margin 10+10
|
||||||
|
// Kolom: Kode 20 | Nama Akun 90 | Debit 40 | Kredit 40 → TOTAL 190
|
||||||
|
private $colWidths = [20, 90, 40, 40];
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// SETTER
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function setHeaderData($nama, $alamat, $logo = '')
|
||||||
|
{
|
||||||
|
$this->nama = $nama;
|
||||||
|
$this->alamat = $alamat;
|
||||||
|
$this->logo = $logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setInfoLaporan($periodeStr)
|
||||||
|
{
|
||||||
|
$this->periodeStr = $periodeStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HEADER HALAMAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function Header()
|
||||||
|
{
|
||||||
|
// Logo (opsional)
|
||||||
|
if (!empty($this->logo) && file_exists($this->logo)) {
|
||||||
|
$this->Image($this->logo, 10, 6, 18);
|
||||||
|
$this->SetXY(31, 10);
|
||||||
|
} else {
|
||||||
|
$this->SetXY(10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nama perusahaan
|
||||||
|
$this->SetFont('Arial', 'B', 12);
|
||||||
|
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
|
||||||
|
|
||||||
|
// Alamat
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$x = !empty($this->logo) && file_exists($this->logo) ? 31 : 10;
|
||||||
|
$this->SetX($x);
|
||||||
|
$this->Cell(0, 5, $this->alamat, 0, 1, 'L');
|
||||||
|
|
||||||
|
// Garis pemisah (A4 Portrait: x=10 s/d x=200)
|
||||||
|
$this->Ln(2);
|
||||||
|
$this->SetLineWidth(0.6);
|
||||||
|
$this->Line(10, $this->GetY(), 200, $this->GetY());
|
||||||
|
$this->SetLineWidth(0.2);
|
||||||
|
$this->Line(10, $this->GetY() + 1, 200, $this->GetY() + 1);
|
||||||
|
$this->Ln(5);
|
||||||
|
|
||||||
|
// Judul
|
||||||
|
$this->SetFont('Arial', 'B', 13);
|
||||||
|
$this->SetTextColor(245, 140, 0);
|
||||||
|
$this->Cell(0, 7, 'LAPORAN NERACA SALDO', 0, 1, 'C');
|
||||||
|
$this->SetTextColor(0, 0, 0);
|
||||||
|
|
||||||
|
// Periode
|
||||||
|
$this->SetFont('Arial', '', 10);
|
||||||
|
$this->Cell(0, 5, $this->periodeStr, 0, 1, 'C');
|
||||||
|
|
||||||
|
// Tanggal cetak
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$this->Cell(0, 5, 'Di Cetak Pada : ' . date('d-m-Y') . ' - ' . date('H:i:s'), 0, 1, 'C');
|
||||||
|
|
||||||
|
$this->Ln(4);
|
||||||
|
|
||||||
|
// Header kolom tabel
|
||||||
|
$this->_drawTableHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// FOOTER HALAMAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function Footer()
|
||||||
|
{
|
||||||
|
$this->SetY(-10);
|
||||||
|
$this->SetFont('Arial', 'I', 8);
|
||||||
|
$this->Cell(0, 5, 'Halaman ' . $this->PageNo(), 0, 0, 'C');
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: posisi X awal — TABEL RATA TENGAH KERTAS
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function _startX()
|
||||||
|
{
|
||||||
|
$tableW = array_sum($this->colWidths);
|
||||||
|
return ($this->GetPageWidth() - $tableW) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: Gambar header kolom tabel
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function _drawTableHeader()
|
||||||
|
{
|
||||||
|
$startX = $this->_startX();
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFillColor(245, 140, 0);
|
||||||
|
$this->SetTextColor(255, 255, 255);
|
||||||
|
$this->SetFont('Arial', 'B', 9);
|
||||||
|
|
||||||
|
$this->Cell($this->colWidths[0], 8, 'Kode', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[1], 8, 'Nama Akun', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[2], 8, 'Debit', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[3], 8, 'Kredit', 1, 1, 'C', true);
|
||||||
|
|
||||||
|
$this->SetTextColor(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// TABEL NERACA SALDO (mendukung multiline Nama Akun)
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function NeracaSaldoTable($rows, $totalDebit, $totalKredit)
|
||||||
|
{
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$lineH = 6;
|
||||||
|
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
|
||||||
|
if (empty($rows)) {
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
$this->Cell(array_sum($this->colWidths), 8, 'Tidak ada data', 1, 1, 'C');
|
||||||
|
} else {
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
|
||||||
|
$nbLines = $this->NbLines($this->colWidths[1], $row['nama']);
|
||||||
|
$rowH = max(1, $nbLines) * $lineH;
|
||||||
|
|
||||||
|
if ($this->GetY() + $rowH > 270) {
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$y = $this->GetY();
|
||||||
|
|
||||||
|
$this->SetFont('Arial', '', 9);
|
||||||
|
$this->SetXY($startX, $y);
|
||||||
|
$this->Cell($this->colWidths[0], $rowH, $row['kode'], 1, 0, 'C');
|
||||||
|
|
||||||
|
$xNama = $this->GetX();
|
||||||
|
$this->MultiCell($this->colWidths[1], $lineH, $row['nama'], 1, 'L');
|
||||||
|
|
||||||
|
$this->SetXY($xNama + $this->colWidths[1], $y);
|
||||||
|
$this->Cell($this->colWidths[2], $rowH, $row['saldo_debit'] > 0 ? number_format($row['saldo_debit'], 0, ',', '.') : '-', 1, 0, 'R');
|
||||||
|
$this->Cell($this->colWidths[3], $rowH, $row['saldo_kredit'] > 0 ? number_format($row['saldo_kredit'], 0, ',', '.') : '-', 1, 0, 'R');
|
||||||
|
|
||||||
|
$this->SetXY($startX, $y + $rowH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- BARIS TOTAL ----
|
||||||
|
if ($this->GetY() + 8 > 270) {
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFillColor(255, 204, 102);
|
||||||
|
$this->SetFont('Arial', 'B', 9);
|
||||||
|
|
||||||
|
$this->Cell($this->colWidths[0] + $this->colWidths[1], 8, 'TOTAL', 1, 0, 'C', true);
|
||||||
|
$this->Cell($this->colWidths[2], 8, number_format($totalDebit, 0, ',', '.'), 1, 0, 'R', true);
|
||||||
|
$this->Cell($this->colWidths[3], 8, number_format($totalKredit, 0, ',', '.'), 1, 1, 'R', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// RINGKASAN: STATUS BALANCE
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function NeracaSaldoRingkasan($totalDebit, $totalKredit)
|
||||||
|
{
|
||||||
|
if ($this->GetY() + 9 > 270) {
|
||||||
|
$this->AddPage('P', 'A4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$tableW = array_sum($this->colWidths);
|
||||||
|
$labelW = $tableW - $this->colWidths[3];
|
||||||
|
$selisih = $totalDebit - $totalKredit;
|
||||||
|
|
||||||
|
$this->Ln(2);
|
||||||
|
$this->SetX($startX);
|
||||||
|
$this->SetFont('Arial', 'B', 10);
|
||||||
|
|
||||||
|
if (abs($selisih) < 1) {
|
||||||
|
$this->SetFillColor(198, 239, 206); // hijau, balance
|
||||||
|
$label = 'SELISIH (BALANCE)';
|
||||||
|
} else {
|
||||||
|
$this->SetFillColor(255, 199, 206); // merah, tidak balance
|
||||||
|
$label = 'SELISIH (TIDAK BALANCE)';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->Cell($labelW, 8, $label, 1, 0, 'L', true);
|
||||||
|
$this->Cell($this->colWidths[3], 8, number_format($selisih, 0, ',', '.'), 1, 1, 'R', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// TANDA TANGAN
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
public function Pembuat($nama, $jabatan = '')
|
||||||
|
{
|
||||||
|
$startX = $this->_startX();
|
||||||
|
$tableW = array_sum($this->colWidths);
|
||||||
|
$signWidth = 70;
|
||||||
|
$signX = $startX + $tableW - $signWidth; // sejajar sisi kanan tabel
|
||||||
|
|
||||||
|
$this->Ln(3);
|
||||||
|
// $this->SetX($signX);
|
||||||
|
$this->SetFont('Arial', 'I', 9);
|
||||||
|
$this->Cell($signWidth, 6, '*Mengetahui, (Finance Departement)', 0, 1, 'L');
|
||||||
|
// $this->Cell($signWidth, 6, $nama, 0, 1, 'L');
|
||||||
|
// if (!empty($jabatan)) {
|
||||||
|
// $this->Cell($signWidth, 5, '(' . $jabatan . ')', 0, 1, 'L');
|
||||||
|
// }
|
||||||
|
// $this->Ln(0);
|
||||||
|
// $this->SetX($signX);
|
||||||
|
// $this->SetFont('Arial', 'B', 10);
|
||||||
|
// $this->Cell($signWidth, 6, $nama, 0, 1, 'R');
|
||||||
|
|
||||||
|
// if (!empty($jabatan)) {
|
||||||
|
// $this->SetX($signX);
|
||||||
|
// $this->SetFont('Arial', '', 9);
|
||||||
|
// $this->Cell($signWidth, 5, '(' . $jabatan . ')', 0, 1, 'R');
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// HELPER: Hitung jumlah baris yang dibutuhkan MultiCell
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
private function NbLines($w, $txt)
|
||||||
|
{
|
||||||
|
$cw = &$this->CurrentFont['cw'];
|
||||||
|
if ($w == 0) {
|
||||||
|
$w = $this->w - $this->rMargin - $this->x;
|
||||||
|
}
|
||||||
|
$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
|
||||||
|
$s = str_replace("\r", '', $txt);
|
||||||
|
$nb = strlen($s);
|
||||||
|
if ($nb > 0 && $s[$nb - 1] == "\n") {
|
||||||
|
$nb--;
|
||||||
|
}
|
||||||
|
$sep = -1;
|
||||||
|
$i = 0;
|
||||||
|
$j = 0;
|
||||||
|
$l = 0;
|
||||||
|
$nl = 1;
|
||||||
|
while ($i < $nb) {
|
||||||
|
$c = $s[$i];
|
||||||
|
if ($c == "\n") {
|
||||||
|
$i++;
|
||||||
|
$sep = -1;
|
||||||
|
$j = $i;
|
||||||
|
$l = 0;
|
||||||
|
$nl++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($c == ' ') {
|
||||||
|
$sep = $i;
|
||||||
|
}
|
||||||
|
$l += isset($cw[ord($c)]) ? $cw[ord($c)] : 600;
|
||||||
|
if ($l > $wmax) {
|
||||||
|
if ($sep == -1) {
|
||||||
|
if ($i == $j) {
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$i = $sep + 1;
|
||||||
|
}
|
||||||
|
$sep = -1;
|
||||||
|
$j = $i;
|
||||||
|
$l = 0;
|
||||||
|
$nl++;
|
||||||
|
} else {
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,19 +13,23 @@
|
|||||||
<select id="account_id" class="form-control select-search"></select>
|
<select id="account_id" class="form-control select-search"></select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-3">
|
<div class="col-md-2">
|
||||||
<label>Dari</label>
|
<label>Dari</label>
|
||||||
<input type="date" id="start_date" class="form-control">
|
<input type="date" id="start_date" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-3">
|
<div class="col-md-2">
|
||||||
<label>Sampai</label>
|
<label>Sampai</label>
|
||||||
<input type="date" id="end_date" class="form-control">
|
<input type="date" id="end_date" class="form-control">
|
||||||
</div>
|
</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 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>
|
</div>
|
||||||
|
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
@@ -92,10 +96,61 @@ $(function(){
|
|||||||
},'json');
|
},'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FILTER
|
// FILTER
|
||||||
$('#btnFilter').click(function(){
|
$('#btnFilter').click(function(){
|
||||||
loadData();
|
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>
|
</script>
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
<div class="text-end">
|
<div class="text-end">
|
||||||
<button class="btn btn-add bg-danger btn-out mr-2">Pengeluaran</button>
|
<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-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>
|
||||||
</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>
|
</script>
|
||||||
@@ -16,10 +16,13 @@
|
|||||||
<input type="date" id="tanggal_sampai" class="form-control">
|
<input type="date" id="tanggal_sampai" class="form-control">
|
||||||
</div>
|
</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">
|
<button type="submit" class="btn btn-warning w-100">
|
||||||
Tampilkan
|
Tampilkan
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" class="btn btn-danger w-100" id="generate_pdf">
|
||||||
|
Generate PDF
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
@@ -168,5 +171,42 @@ $(function(){
|
|||||||
loadData(dari, sampai);
|
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>
|
</script>
|
||||||
@@ -18,10 +18,12 @@
|
|||||||
<input type="date" name="tanggal_sampai" id="tanggal_sampai" class="form-control">
|
<input type="date" name="tanggal_sampai" id="tanggal_sampai" class="form-control">
|
||||||
</div>
|
</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">
|
<button type="submit" class="btn btn-warning w-100">
|
||||||
Tampilkan
|
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>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
@@ -76,6 +78,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|
||||||
function loadData(tanggal_dari = '', tanggal_sampai = ''){
|
function loadData(tanggal_dari = '', tanggal_sampai = ''){
|
||||||
@@ -85,6 +88,7 @@ $(function(){
|
|||||||
tanggal_sampai: tanggal_sampai
|
tanggal_sampai: tanggal_sampai
|
||||||
}, function(res){
|
}, function(res){
|
||||||
|
|
||||||
|
|
||||||
let act = '', pas = '';
|
let act = '', pas = '';
|
||||||
|
|
||||||
// ================= ACTIVA
|
// ================= ACTIVA
|
||||||
@@ -134,18 +138,64 @@ $(function(){
|
|||||||
},'json');
|
},'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ================= LOAD AWAL
|
// ================= LOAD AWAL
|
||||||
loadData();
|
loadData();
|
||||||
|
|
||||||
|
|
||||||
// ================= SUBMIT FILTER
|
// ================= SUBMIT FILTER
|
||||||
$('#filterForm').on('submit', function(e){
|
$('#filterForm').on('submit', function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
|
||||||
let dari = $('#tanggal_dari').val();
|
let dari = $('#tanggal_dari').val();
|
||||||
let sampai = $('#tanggal_sampai').val();
|
let sampai = $('#tanggal_sampai').val();
|
||||||
|
|
||||||
loadData(dari, sampai);
|
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">
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
<h4 class="mb-0 fw-bold">Neraca Saldo</h4>
|
<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>
|
||||||
|
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
@@ -62,5 +65,26 @@ $(function(){
|
|||||||
|
|
||||||
}, 'json');
|
}, '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>
|
</script>
|
||||||
Reference in New Issue
Block a user