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

$table	="jurppi_tmp";

$kode		=$_POST[kode];
$tanggal	=$_POST[tanggal];
$kodepl	=$_POST[kodepl];
$namapl	=$_POST[namapl];
$tglaw		=$_POST[tglaw];
$tglak		=$_POST[tglak];
$nofak	=$_POST[nofak];
$tglfak 	=$_POST[tglfak];
$nopol 	=$_POST[nopol];
$jmlliter	=$_POST[jmlliter];
$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){
	mysql_query("UPDATE $table SET nofak='$nofak',tgl_fak='$tglfak',nopol='$nopol',jml_liter='$jmlliter',jml_piut='$jmlpiut',dibayar='$dibayar',sisa='$sisa' WHERE nofak='$nofak' ");
}
else{
	mysql_query("INSERT INTO $table (kode_ppi,tanggal,kode_pl,nama_pl,tanggal_aw,tanggal_ak,nofak,tgl_fak,nopol,jml_liter,jml_piut,dibayar,sisa) VALUES('$kode','$tanggal','kodepl','$namapl','$tglaw','$tglak','$nofak','$tglfak','$nopol','$jmlliter','$jmlpiut','$dibayar','$sisa')");
}

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