<?php
	include '../../../lib/conn.php';
	$jenis = $_GET['jenis'];
	if ($jenis=='group') {		
		
		$group = $_GET['group'];
		$sqlgrp = mysqli_query($conn,"SELECT * FROM `tb_group` WHERE `kode_group` = '$group'");
		$grp = mysqli_fetch_assoc($sqlgrp);
		
		
			$sql_akun = mysqli_query($conn,"SELECT `pegawai_id` as id,`pegawai_nama` as nama FROM `pegawai`");
		
        while($k = mysqli_fetch_assoc($sql_akun))
        {          
            echo"<option value='$k[id]'>$k[nama]</option>";
          
        }
	}else{
		$pos = $_GET['pos'];
		$query = "SELECT * FROM `tb_pos_akun` WHERE `id` = '$pos' ";
		$sql_kul = mysqli_query($conn,$query);	
		$obt = mysqli_fetch_assoc($sql_kul);
		$c1 = "SELECT max(kode_akun)as kode FROM tb_akun WHERE kode_pos_akun = '$pos' ";
		  $d1 = mysqli_query($conn,$c1);
		  $e1 = mysqli_fetch_array($d1);
		  $kode=substr($e1['kode'],1,2); //mengambil string mulai dari karakter pertama 'A' dan mengambil 4 karakter setelahnya. 
		  $tambah=$kode+1; //kode yang sudah di pecah di tambah 1
		   if($tambah<10){ //jika kode lebih kecil dari 10 (9,8,7,6 dst) maka
		    $idi="00".$tambah;
		    }elseif ($tambah<100) {
		      $idi="0".$tambah;
		    }else {
		      $idi="".$tambah;
		    } 
		$data = array(
            'kode'      =>  $obt['kode_pos_akun'],
            'nama'      =>  $obt['pos_akun'],
            'akun'      =>  $idi,
            'jenis'   =>  $obt['jenis_pos_akun'],);
 		echo json_encode($data);
	}
?>