<?php
include "../../inc/inc.koneksi.php";

$table="customer";

$kode	 =$_POST['kode'];
$nama	 =$_POST['nama'];
$alamat	 =$_POST['alamat'];
$telepon =$_POST['telepon'];
$kategori=$_POST['kategori'];
$gudang  =$_POST['gudang'];

$sql= mysql_query("SELECT * FROM interface");
$r  = mysql_fetch_assoc($sql);
$nopiut	= $r['piutang'];
$nobppi = $nopiut.$kode;

$sql = mysql_query("SELECT * FROM $table WHERE kode_pl= '$kode'");
$row = mysql_num_rows($sql);
if ($row>0){
	mysql_query("UPDATE $table SET nama='$nama',alamat='$alamat',telepon='$telepon',kategori='$kategori',kode_cab='$gudang',lastupdate=now() WHERE kode_pl= '$kode'");
	mysql_query("UPDATE akun_bp SET naakun='$nama',lastupdate=now() WHERE noakun= '$nobppi'");
	echo "Data Sukses diubah.";
}
else{
	mysql_query("INSERT INTO $table (kode_pl,nama,alamat,telepon,kategori,kode_cab,lastupdate) VALUES('$kode','$nama','$alamat','$telepon','$kategori','$gudang',now())");
	
	$sql = mysql_query("SELECT tahun FROM akun_bb WHERE noakun='11101'");
	$r   = mysql_fetch_assoc($sql);
	$tahun= $r['tahun'];
	
	mysql_query("INSERT INTO akun_bp (noakun,naakun,nobb,kode,tahun,saldo,mutasi_db,mutasi_kd,saldo_tl,lastupdate) VALUES('$nobppi','$nama','$nopiut','D','$tahun','0','0','0','0',now())");
	echo "Data sukses disimpan";
}
?>