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

$table		="supplier";

$kode		=$_POST[kode];
$nama		=$_POST[nama];
$alamat		=$_POST[alamat];
$telepon	=$_POST[telepon];
$fax		=$_POST[fax];
$bank		=$_POST[bank];
$nomorac	=$_POST[nomorac];
$namaac	    =$_POST[namaac];
$kontak		=$_POST[kontak];
$tanggal	=date('Y-m-d');
$tahun		=year($tanggal);

$sql	= mysql_query("SELECT * FROM interface");
$r 	    = mysql_fetch_assoc($sql);

$hutangdg	= $r[hutang_dg];
$hutangbg	= $r[hutang_bg];
$nobpudg 	= $hutangdg.$kode;
$nobpubg 	= $hutangbg.$kode;

$sql = mysql_query("SELECT * FROM $table WHERE kode_sp= '$kode'");
$row = mysql_num_rows($sql);
if ($row>0){
	mysql_query("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_sp= '$kode'");
	mysql_query("UPDATE akun_bp SET naakun='$nama' WHERE noakun='$nobpudg' OR noakun='$nobpubg'");
	echo "Data Sukses diubah.";
}

else{
	mysql_query("INSERT INTO $table (kode_sp,nama,alamat,telepon,fax,bank,nomor_ac,nama_ac,kontak) VALUES('$kode','$nama','$alamat','$telepon','$fax','$bank','$nomorac','$namaac','$kontak')");
	mysql_query("INSERT INTO akun_bp (noakun,naakun,nobb,kode,tahun) VALUES('$nobpudg','$nama','$hutangdg','K','$tahun')");
	mysql_query("INSERT INTO akun_bp (noakun,naakun,nobb,kode,tahun) VALUES('$nobpubg','$nama','$hutangbg','K','$tahun')");
	echo "Data sukses disimpan";
}
?>