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

$kode= $_POST['kode'];
$tanggal= $_POST['tanggal'];
$kodepl= $_POST['kodepl'];
$namapl= $_POST['namapl'];
$tglaw = $_POST['tglaw'];
$tglak = $_POST['tglak'];

mysql_query("DELETE FROM jurppi_tmp");

$query = "SELECT * FROM piutang WHERE kode_pl='$kodepl' AND tanggal BETWEEN '$tglaw' AND '$tglak' AND !(jumlah='0') ORDER BY nofak ";
$sql= mysql_query($query);

$tbayar=0;
while($r=mysql_fetch_array($sql)){
	$nofak=$r[nofak];
	$tglfak=$r[tanggal];
	$nopol=$r[nopol];
	$jmlliter=$r[jml_liter];
	$jmlpiut=$r[jumlah];
	$dibayar=$r[jumlah];
	$tbayar=$tbayar+$r[jumlah];
	
	$query1= "INSERT INTO jurppi_tmp (kode_ppi,tanggal,kode_pl,nama_pl,tanggal_aw,tanggal_ak,nofak,tgl_fak,nopol,jml_liter,jml_piut,dibayar) VALUES('$kode','$tanggal','$kodepl','$namapl','$tglaw','$tglak','$nofak','$tglfak','$nopol','$jmlliter','$jmlpiut','$dibayar')";
	mysql_query($query1);
}
$data['tbayar'] = $tbayar;
echo json_encode($data);
?>