Perubahan barcode dan inventory
This commit is contained in:
@@ -27,114 +27,81 @@ class Generateneracasaldo extends CI_Controller {
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 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())
|
||||
// AMBIL DATA NERACA SALDO
|
||||
// DIPAKAI OLEH AJAX & PDF
|
||||
// =========================
|
||||
private function get_neracasaldo_data()
|
||||
{
|
||||
$this->db->select('
|
||||
$tanggal_awal = $this->input->get('tanggal_awal');
|
||||
$tanggal_akhir = $this->input->get('tanggal_akhir');
|
||||
|
||||
$this->db->select("
|
||||
accounts.id,
|
||||
accounts.kode_akun,
|
||||
accounts.nama_akun,
|
||||
accounts.kategori,
|
||||
accounts.tipe,
|
||||
accounts.posisi,
|
||||
COALESCE(SUM(journal_details.debit),0) as debit,
|
||||
COALESCE(SUM(journal_details.kredit),0) as kredit
|
||||
');
|
||||
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');
|
||||
// ======================================
|
||||
// FILTER PERIODE
|
||||
// ======================================
|
||||
if (!empty($tanggal_awal) && !empty($tanggal_akhir)) {
|
||||
|
||||
$this->db->group_by('accounts.id');
|
||||
$this->db->order_by('accounts.kode_akun','ASC');
|
||||
$this->db->join(
|
||||
"(SELECT jd.*
|
||||
FROM journal_details jd
|
||||
JOIN journals j ON j.id = jd.journal_id
|
||||
WHERE j.tanggal BETWEEN ".$this->db->escape($tanggal_awal)."
|
||||
AND ".$this->db->escape($tanggal_akhir)."
|
||||
) journal_details",
|
||||
"journal_details.account_id = accounts.id",
|
||||
"left",
|
||||
false
|
||||
);
|
||||
|
||||
$rows = $this->db->get()->result();
|
||||
} else {
|
||||
|
||||
// =========================
|
||||
// HITUNG LABA BERJALAN
|
||||
// =========================
|
||||
$laba = $this->get_laba_berjalan();
|
||||
$this->db->join(
|
||||
'journal_details',
|
||||
'journal_details.account_id = accounts.id',
|
||||
'left'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$rows = $this->db
|
||||
->where('accounts.is_active',1)
|
||||
->group_by('accounts.id')
|
||||
->order_by('accounts.kode_akun','ASC')
|
||||
->get()
|
||||
->result();
|
||||
|
||||
$result = [];
|
||||
$total_debit = 0;
|
||||
$total_kredit = 0;
|
||||
|
||||
foreach ($rows as $r) {
|
||||
foreach($rows as $row){
|
||||
|
||||
// ================= SALDO NORMAL
|
||||
if ($r->posisi == 'debit') {
|
||||
$saldo = $r->debit - $r->kredit;
|
||||
} else {
|
||||
$saldo = $r->kredit - $r->debit;
|
||||
}
|
||||
$row->debit = (float)$row->debit;
|
||||
$row->kredit = (float)$row->kredit;
|
||||
|
||||
// ================= 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,
|
||||
];
|
||||
$total_debit += $row->debit;
|
||||
$total_kredit += $row->kredit;
|
||||
}
|
||||
|
||||
return [
|
||||
'rows' => $rows,
|
||||
'data' => $result,
|
||||
'total_debit' => $total_debit,
|
||||
'total_kredit' => $total_kredit,
|
||||
'tanggal_awal' => $tanggal_awal,
|
||||
'tanggal_akhir' => $tanggal_akhir,
|
||||
'rows' => $rows,
|
||||
'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();
|
||||
@@ -142,68 +109,80 @@ class Generateneracasaldo extends CI_Controller {
|
||||
echo json_encode($result['rows']);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// PDF GENERATE — NERACA SALDO
|
||||
// =========================
|
||||
public function generatepdf()
|
||||
{
|
||||
if ($this->session->userdata('role') != 'Admin') {
|
||||
show_error('Akses ditolak', 403);
|
||||
show_error('Akses ditolak',403);
|
||||
}
|
||||
|
||||
if (ob_get_length()) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
// =============================================================
|
||||
// AMBIL DATA
|
||||
// =============================================================
|
||||
// ==========================================
|
||||
// DATA
|
||||
// ==========================================
|
||||
$neracasaldo = $this->get_neracasaldo_data();
|
||||
|
||||
// =============================================================
|
||||
// DATA PERUSAHAAN
|
||||
// =============================================================
|
||||
// ==========================================
|
||||
// PERUSAHAAN
|
||||
// ==========================================
|
||||
$company = $this->db->get('pengaturan')->row();
|
||||
|
||||
// =============================================================
|
||||
// BUILD STRING PERIODE
|
||||
// =============================================================
|
||||
$periodeStr = 'Per Tanggal : ' . date('d-m-Y');
|
||||
// ==========================================
|
||||
// PERIODE
|
||||
// ==========================================
|
||||
if(!empty($neracasaldo['tanggal_awal']) && !empty($neracasaldo['tanggal_akhir'])){
|
||||
|
||||
// =============================================================
|
||||
// LOAD LIBRARY PDF
|
||||
// =============================================================
|
||||
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||
require_once(APPPATH . 'libraries/PDF_Neracasaldo.php');
|
||||
$periodeStr = 'Periode : '
|
||||
. date('d-m-Y',strtotime($neracasaldo['tanggal_awal']))
|
||||
.' s/d '
|
||||
. date('d-m-Y',strtotime($neracasaldo['tanggal_akhir']));
|
||||
|
||||
$pdf = new PDF ('P', 'mm', 'A4');
|
||||
$pdf->SetMargins(10, 10, 10);
|
||||
}else{
|
||||
|
||||
$periodeStr = 'Seluruh Periode';
|
||||
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 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'
|
||||
FCPATH.'uploads/img/logo-ljn.png'
|
||||
);
|
||||
|
||||
$pdf->setInfoLaporan($periodeStr);
|
||||
|
||||
$pdf->AddPage('P', 'A4');
|
||||
$pdf->AddPage();
|
||||
|
||||
$pdf->NeracaSaldoTable(
|
||||
$neracasaldo['data'],
|
||||
$neracasaldo['rows'],
|
||||
$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);
|
||||
$pdf->Pembuat(
|
||||
$this->session->userdata('nama') ?: 'Administrator',
|
||||
'Finance Department'
|
||||
);
|
||||
|
||||
$filename = 'Neraca_Saldo_'.date('YmdHis').'.pdf';
|
||||
|
||||
$pdf->Output('I',$filename);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user