$pp_total_akhir=0;
                $ap_total_akhir=0;
                $nb_total_akhir=0;*/

     foreach ($data as $gol) {
            $q_gol_final=$gol;
		$kode_golongan = $data_gol;
		$ps = $param_satker;
		$pt =$param_tgl;
		$paramLevelGol = $levelAset;
		//$data[$i]=$data_gol;
		/*if($paramLevelGol != 2){
			$data[$i]['Bidang'] = bidang($kode_golongan,$gol,$ps,$pt,$paramLevelGol);
		}*/
                $data_awal=  subsub_awal($kode_golongan, $q_gol_final, $ps, $pt);
                $data_akhir=  subsub($kode_golongan, $q_gol_final, $ps, "$tahun_neraca-12-31");
                $data_hilang=subsub_hapus($kode_golongan, $q_gol_final, $ps, "$tahun_neraca-12-31",$pt);
		//exit();
                $hasil=  group_data($data_awal, $data_akhir,$data_hilang);
               //echo "<pre>";
               //print_r($hasil);
              // exit();
                $data[$i]=$hasil;
                //head asal
				
                
		foreach($hasil as $gol)
		{	
	   
                    
                   if($gol[ap]==""||$gol[ap]==0)
function sub($kodeKelompok,$gol,$ps,$pt,$paramLevelKelompok) {
$param_satker = $ps;
$splitKodeSatker = explode ('.',$param_satker);
if(count($splitKodeSatker) == 4){	
	$paramSatker = "kodeSatker = '$param_satker'";
}else{
	$paramSatker = "kodeSatker like '$param_satker%'";
}
$param_tgl = $pt;
if($gol == 'mesin_ori'){
	$param_where = "Status_Validasi_barang=1 and StatusTampil = 1 and kondisi != '3'  and 
					( (TglPerolehan < '2008-01-01' and TglPembukuan <= '$param_tgl' and kodeLokasi like '12%' and kodeKa=1) or 
					  (TglPerolehan >= '2008-01-01' and TglPembukuan <= '$param_tgl'  and kodeLokasi like '12%' and (NilaiPerolehan >=1000000 or kodeKa=1)))
					 and $paramSatker";
 
	$sql = "select  SUBSTRING_INDEX(kodeKelompok,'.',4) as sub,
			sum(NilaiPerolehan)as nilai,count(Aset_ID) as jml,
			sum(PenyusutanPerTahun)as PP,sum(AkumulasiPenyusutan)as AP,sum(NilaiBuku)as NB,
			(select Uraian from kelompok 
			where kode= SUBSTRING_INDEX(kodeKelompok,'.',4) 
			) as Uraian,
			Status_Validasi_barang,kodeSatker from $gol m
			 where kodeKelompok like '$kodeKelompok%' and
			 $param_where     
			group by sub";
}elseif($gol == 'bangunan_ori'){
	$param_where = "Status_Validasi_barang=1 and StatusTampil = 1 and kondisi != '3'  and 
				( (TglPerolehan < '2008-01-01' and TglPembukuan <= '$param_tgl' and kodeLokasi like '12%' and kodeKa=1) or 
				  (TglPerolehan >= '2008-01-01' and TglPembukuan <= '$param_tgl' and kodeLokasi like '12%' and (NilaiPerolehan >=20000000  or kodeKa=1)))
				 and $paramSatker";
	 
	$sql = "select  SUBSTRING_INDEX(kodeKelompok,'.',4) as sub,
			sum(NilaiPerolehan)as nilai,count(Aset_ID) as jml,
			sum(PenyusutanPerTahun)as PP,sum(AkumulasiPenyusutan)as AP,sum(NilaiBuku)as NB,
			(select Uraian from kelompok 
			where kode= SUBSTRING_INDEX(kodeKelompok,'.',4) 
			) as Uraian,
			Status_Validasi_barang,kodeSatker from $gol m
			 where kodeKelompok like '$kodeKelompok%' and
			 $param_where     
			group by sub";
}else{
	if($gol!="tanahView")
		  $param_where = "Status_Validasi_barang=1 and StatusTampil = 1  
					 and TglPerolehan <= '$param_tgl' 
					 and TglPembukuan <='$param_tgl' 
					 and kodeLokasi like '12%' 
					 and kondisi != '3'					 
					 and $paramSatker";
		else
		    $param_where = "Status_Validasi_barang=1 and StatusTampil = 1  
					 and TglPerolehan <= '$param_tgl' 
					 and TglPembukuan <='$param_tgl' 
					 and kodeLokasi like '12%' 
					 and $paramSatker";
				 
	 if($gol == 'jaringan_ori'){
		$sql = "select  SUBSTRING_INDEX(kodeKelompok,'.',4) as sub,
				sum(NilaiPerolehan)as nilai,count(Aset_ID) as jml,
				sum(PenyusutanPerTahun)as PP,sum(AkumulasiPenyusutan)as AP,sum(NilaiBuku)as NB,
				(select Uraian from kelompok 
				where kode= SUBSTRING_INDEX(kodeKelompok,'.',4) 
				) as Uraian,
				Status_Validasi_barang,kodeSatker from $gol m
				 where kodeKelompok like '$kodeKelompok%' and
				 $param_where     
				group by sub";
	 }else{
		$sql = "select  SUBSTRING_INDEX(kodeKelompok,'.',4) as sub,
				sum(NilaiPerolehan)as nilai,count(Aset_ID) as jml,
				(select Uraian from kelompok 
				where kode= SUBSTRING_INDEX(kodeKelompok,'.',4) 
				) as Uraian,
				Status_Validasi_barang,kodeSatker from $gol m
				 where kodeKelompok like '$kodeKelompok%' and
				 $param_where     
				group by sub";
	 }
}
// echo "<pre>";
// print_r($sql); 
// echo "</pre>"; 
$data=array();
$c=0;
$resultparentSub = mysql_query($sql) or die(mysql_error());
	 while ($data_sub = mysql_fetch_array($resultparentSub)) {
		$kode_sub = $data_sub[sub];
		$data[$c]=$data_sub;
		$paramLevelSub = $paramLevelKelompok;
		if($paramLevelSub !=5){
			$data[$c]['SubSub'] =subsub($kode_sub,$gol,$ps,$pt,$paramLevelSub);
		}
		$c++;
	 }
return $data ;
}