Perubahan barcode dan inventory
This commit is contained in:
@@ -26,87 +26,54 @@ class Neracasaldo extends CI_Controller {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function get_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');
|
||||
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'
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
$rows = $this->db
|
||||
->where('accounts.is_active', 1)
|
||||
->group_by('accounts.id')
|
||||
->order_by('accounts.kode_akun', 'ASC')
|
||||
->get()
|
||||
->result();
|
||||
|
||||
echo json_encode($rows);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user