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

$table		="supplier";

$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);
$utdg= $r['hutang_dg'];
$utbg= $r['hutang_bg'];
$noutdg 	= $utdg.$kode;
$noutbg 	= $utbg.$kode;

$sql = mysql_query("SELECT * FROM $table WHERE kode_sp= '$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_sp= '$kode'";
	mysql_query($input);
	
	$input	= "UPDATE akun_bp SET naakun='$nama',lastupdate=now() WHERE noakun= '$noutdg'";
	mysql_query($input);
	$input	= "UPDATE akun_bp SET naakun='$nama',lastupdate=now() WHERE noakun= '$noutbg'";
	mysql_query($input);	
	echo "Data Sukses diubah.";
}

else{
	$input = "INSERT INTO $table (kode_sp,nama,alamat,telepon,fax,bank,nomor_ac,nama_ac,kontak,lastupdate) VALUES('$kode','$nama','$alamat','$telepon','$fax','$bank','$nomorac','$namaac','$kontak',now())";
	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,saldo,mutasi_db,mutasi_kd,saldo_tl,lastupdate) VALUES('$noutdg','$nama','$utdg','K','$tahun','0','0','0','0',now())";
	mysql_query($input);
	$input = "INSERT INTO akun_bp (noakun,naakun,nobb,kode,tahun,saldo,mutasi_db,mutasi_kd,saldo_tl,lastupdate) VALUES('$noutbg','$nama','$utbg','K','$tahun','0','0','0','0',now())";
	mysql_query($input);
	echo "Data sukses disimpan";
}
?>