<?php 
//include '../koneksi.php';
//$id = $_POST['id'];              
//$data = mysqli_query($koneksi, "select * from brg_dft where id='$id'");
//$d = mysqli_fetch_assoc($data);

//$idb    = $d['id'];
//$kode   = $d['kode'];
//$nama   = $d['nama'];
//$sat    = $d['sat'];
//$hjual  = $d['hjual'];
//$s_ak   = $d['s_ak'];

//$returnArr = [$idb,$kode,$nama,$sat,$hjual,$s_ak];    
//echo json_encode($returnArr);


include '../koneksi.php';
$id = $_POST['id'];

$dft = mysqli_query($koneksi, "select * from brg_dft where id='$id'");
$a = mysqli_fetch_assoc($dft);
$akode   = $a['kode'];

// Hitung nilai s_ak secara dinamis
$s_ak_query = mysqli_query($koneksi, "SELECT SUM(nbeli-njual) as s_ak FROM brg_mts WHERE kode = '$akode'");
$s_ak_data = mysqli_fetch_assoc($s_ak_query);
$s_ak = $s_ak_data['s_ak'];

$data = mysqli_query($koneksi, "select * from brg_dft where id='$id'");
$d = mysqli_fetch_assoc($data);
$idb    = $d['id'];
$kode   = $d['kode'];
$nama   = $d['nama'];
$sat    = $d['sat'];
$hjual  = $d['hjual'];
$hjual_format = number_format($hjual, 0, ',', '.');

//$returnArr = array(
//  'id'      => $idb,
//  'kode'    => $kode,
//  'nama'    => $nama,
//  'sat'     => $sat,
//  'hjual'   => $hjual,
//  's_ak'    => $s_ak
//);

$returnArr = [$idb,$kode,$nama,$sat,$hjual_format,$s_ak];    
echo json_encode($returnArr);

?>