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

$table	="jurppi_tmp";

$nofak	=$_POST[nofak];
$tglfak =$_POST[tglfak];
$nopol 	=$_POST[nopol];
$jmlpiut=$_POST[jmlpiut];
$dibayar=$_POST[dibayar];
$sisa	=$_POST[sisa];
$user	=$_SESSION[namauser];

$sql = mysql_query("SELECT * FROM $table WHERE nofak='$nofak'");
$row= mysql_num_rows($sql);

if ($row>0){
	$input = "UPDATE $table SET nofak='$nofak',tgl_fak='$tglfak',nopol='$nopol',jml_piut='$jmlpiut',dibayar='$dibayar',sisa='$sisa'
	WHERE nofak='$nofak' ";
	mysql_query($input);
}
else{
	$input = "INSERT INTO $table (nofak,tgl_fak,nopol,jml_piut,dibayar,sisa) VALUES('$nofak','$tglfak','$nopol','$jmlpiut','$dibayar','$sisa')";
	mysql_query($input);		
}

$sql = mysql_query("SELECT * FROM $table WHERE batal=''");
$row= mysql_num_rows($sql);
$tbayar=0;
while($r1=mysql_fetch_array($sql1)){
	$tbayar=$tbayar+$r[dibayar];
}
$data['tbayar']=$tbayar;
echo json_encode($data);
?>