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

$table		="customer";

$kode		=$_POST[kode];
$nama		=$_POST[tnama];
$alamat	=$_POST[talamat];
$telepon	=$_POST[ttelepon];
$fax			=$_POST[tfax];
$bank		=$_POST[tbank];
$nomorac=$_POST[nomorac];
$namaac=$_POST[namaac];
$kontak	=$_POST[tkontak];

$sql	= mysql_query("SELECT * FROM interface");
$r = mysql_fetch_assoc($sql);
$nobb	= $r[piutang];
$noakun 	= $nobb.$kode;

$sql = mysql_query("SELECT * FROM $table WHERE kode_pl= '$kode'");
$row= mysql_num_rows($sql);
if ($row>0){
	$input	= "UPDATE $table SET nama='$nama',alamat='$alamat',telepon='$telepon',fax='$fax',bank='$bank',nomor_ac='$nomorac',nama_ac='$namaac',kontak='$kontak',lastupdate=now() WHERE kode_pl= '$kode'";
	mysql_query($input);
	$input	= "UPDATE akun_bp SET naakun='$nama',lastupdate=now() WHERE noakun= '$noakun'";
	mysql_query($input);	
	echo "Data Sukses diubah.";
}
else{
	$input = "INSERT INTO $table (kode_pl,nama,alamat,telepon,fax,bank,nomor_ac,nama_ac,kontak) VALUES('$kode','$nama','$alamat','$telepon','$fax','$bank','$nomorac','$namaac','$kontak')";
	mysql_query($input);
	
	$sql = mysql_query("SELECT tahun FROM akun_bp");
	$r = mysql_fetch_assoc($sql);
	$tahun = $r[tahun];
	
	$input = "INSERT INTO akun_bp (noakun,naakun,nobb,kode,tahun) VALUES('$noakun','$nama','$nobb','D','$tahun')";
	mysql_query($input);
	echo "Data sukses disimpan";
}
?>