<?php 
    include '../koneksi.php';

    $tperk      = $_POST['nama'];
    $tnosub     = $_POST['nosub'];
    $tkdu       = $_POST['kdu'];
    $tnoak       = $_POST['noak'];
    
              $klp = mysqli_query($koneksi, "SELECT kd AS tkd_klp FROM n_kode_3 WHERE kd='$tnosub' LIMIT 1");
                list($tkd_klp) = mysqli_fetch_array($klp);
              $count3 = mysqli_num_rows($kaw);    
    
              // fungsi membuat NOPERK
              $kaw = mysqli_query($koneksi, "SELECT left(noperk,5) as kode3,sub AS tnama_sub FROM nawal WHERE nosub='$tnosub' ORDER BY noperk DESC LIMIT 1");
                list($kode3,$tnama_sub) = mysqli_fetch_array($kaw);
              $count3 = mysqli_num_rows($kaw);

              if ($count3 <> 0) {
                  $data_id3 = mysqli_fetch_assoc($kaw);
                  $kode4    = $kode3+1;
              } else {
                  $kode4    = $tnosub.'01';
              }
              $noperk=$kode4 ;
              
    /////////// 
    $query = mysqli_query($mysqli, "INSERT INTO nawal (noperk,perk,klp,nosub,ry,kdu,kdc) 
                                    VALUES('$noperk','$tperk','$tkd_klp','$tnosub','$tnoak','$tkdu','01')")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));
                                    
    header("location:kode_akunt_new.php");
