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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user