diff --git a/application/controllers/Generatebuku.php b/application/controllers/Generatebuku.php new file mode 100644 index 0000000..0bb5738 --- /dev/null +++ b/application/controllers/Generatebuku.php @@ -0,0 +1,138 @@ +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; + } +} \ No newline at end of file diff --git a/application/controllers/Generateitems.php b/application/controllers/Generateitems.php new file mode 100644 index 0000000..d36702d --- /dev/null +++ b/application/controllers/Generateitems.php @@ -0,0 +1,68 @@ +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'); +} +} \ No newline at end of file diff --git a/application/controllers/Generatelabarugi.php b/application/controllers/Generatelabarugi.php new file mode 100644 index 0000000..3f639a1 --- /dev/null +++ b/application/controllers/Generatelabarugi.php @@ -0,0 +1,197 @@ +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; + } +} \ No newline at end of file diff --git a/application/controllers/Generateneraca.php b/application/controllers/Generateneraca.php new file mode 100644 index 0000000..fe038be --- /dev/null +++ b/application/controllers/Generateneraca.php @@ -0,0 +1,252 @@ +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; + } +} \ No newline at end of file diff --git a/application/controllers/Generateneracasaldo.php b/application/controllers/Generateneracasaldo.php new file mode 100644 index 0000000..c59e05c --- /dev/null +++ b/application/controllers/Generateneracasaldo.php @@ -0,0 +1,209 @@ +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; + } +} \ No newline at end of file diff --git a/application/libraries/PDF_BukuBesar.php b/application/libraries/PDF_BukuBesar.php new file mode 100644 index 0000000..1a74f8a --- /dev/null +++ b/application/libraries/PDF_BukuBesar.php @@ -0,0 +1,329 @@ +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; + } +} diff --git a/application/libraries/PDF_Items.php b/application/libraries/PDF_Items.php new file mode 100644 index 0000000..c8f9cfe --- /dev/null +++ b/application/libraries/PDF_Items.php @@ -0,0 +1,216 @@ +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'); + // } +} diff --git a/application/libraries/PDF_Labarugi.php b/application/libraries/PDF_Labarugi.php new file mode 100644 index 0000000..a0eccc7 --- /dev/null +++ b/application/libraries/PDF_Labarugi.php @@ -0,0 +1,345 @@ +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; + } +} \ No newline at end of file diff --git a/application/libraries/PDF_Neraca.php b/application/libraries/PDF_Neraca.php new file mode 100644 index 0000000..da3c4ae --- /dev/null +++ b/application/libraries/PDF_Neraca.php @@ -0,0 +1,296 @@ +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'); + } + } +} diff --git a/application/libraries/PDF_Neracasaldo.php b/application/libraries/PDF_Neracasaldo.php new file mode 100644 index 0000000..61f37f1 --- /dev/null +++ b/application/libraries/PDF_Neracasaldo.php @@ -0,0 +1,303 @@ +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; + } +} \ No newline at end of file diff --git a/application/views/buku_besar/layout.php b/application/views/buku_besar/layout.php index eca4e7c..301fa5c 100644 --- a/application/views/buku_besar/layout.php +++ b/application/views/buku_besar/layout.php @@ -13,19 +13,23 @@ -
+
-
+
-
+ +
+
+
@@ -92,10 +96,61 @@ $(function(){ },'json'); } + // FILTER $('#btnFilter').click(function(){ loadData(); }); + + // Prevent double submit + $(document).on('submit', 'form', function(e){ + e.preventDefault(); + }); + + + // GENERATE PDF + $('#generate_pdf').on('click', function () { + + const now = new Date(); + const today = now.getFullYear() + '-' + + String(now.getMonth() + 1).padStart(2, '0') + '-' + + String(now.getDate()).padStart(2, '0'); + + const account_id = $('#account_id').val(); + const start_date = $('#start_date').val() || '0000-00-00'; + const end_date = $('#end_date').val() || today; + + let btn = $(this); + + btn.prop('disabled', true).html('Generate PDF...'); + + $.ajax({ + url: "" + + '/' + 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'); + } + }); +}); }); \ No newline at end of file diff --git a/application/views/items/layout.php b/application/views/items/layout.php index d4dbe5c..ae37f44 100644 --- a/application/views/items/layout.php +++ b/application/views/items/layout.php @@ -7,6 +7,7 @@
+
@@ -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( + + "", + '_blank' + ); + + setTimeout(function(){ + btn.prop('disabled', false) + .html('Generate PDF'); + },1000); + +}); }); \ No newline at end of file diff --git a/application/views/laporan/laba_rugi.php b/application/views/laporan/laba_rugi.php index 271a484..a7ff768 100644 --- a/application/views/laporan/laba_rugi.php +++ b/application/views/laporan/laba_rugi.php @@ -16,10 +16,13 @@
-
+
+
@@ -168,5 +171,42 @@ $(function(){ loadData(dari, sampai); }); + + + $('#generate_pdf').on('click', function () { + + const tanggal_dari = $('#tanggal_dari').val() || '0000-00-00'; + const tanggal_sampai = $('#tanggal_sampai').val() || '0000-00-00'; + + let btn = $(this); + + + btn.prop('disabled', true).html('Generate PDF...'); + + $.ajax({ + url: "" + + '/' + 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'); + } + }); +}); }); \ No newline at end of file diff --git a/application/views/laporan/neraca.php b/application/views/laporan/neraca.php index 91fa22e..7599dad 100644 --- a/application/views/laporan/neraca.php +++ b/application/views/laporan/neraca.php @@ -18,10 +18,12 @@
-
+
+
+
@@ -76,6 +78,7 @@
\ No newline at end of file +}); + diff --git a/application/views/laporan/neraca_saldo.php b/application/views/laporan/neraca_saldo.php index ff1898b..757ae4f 100644 --- a/application/views/laporan/neraca_saldo.php +++ b/application/views/laporan/neraca_saldo.php @@ -4,6 +4,9 @@

Neraca Saldo

+
@@ -62,5 +65,26 @@ $(function(){ }, 'json'); + + //GENERATE PDF + $('#generate_pdf').on('click', function(){ + + let btn = $(this); + + btn.prop('disabled', true) + .html('Generate PDF...'); + + window.open( + + "", + '_blank' + ); + + setTimeout(function(){ + btn.prop('disabled', false) + .html('Generate PDF'); + },1000); + +}); }); \ No newline at end of file