<?php
include "../../inc/inc.koneksi.php";
session_start();

$kodepl= $_POST['kodepl'];
$tglaw = $_POST['tglaw'];
$tglak = $_POST['tglak'];

mysql_query("DELETE FROM jurppi_tmp");

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

$tbayar=0;
while($r=mysql_fetch_array($sql)){
	$nofak=$r[nofak];
	$tglfak=$r[tanggal];
	$nopol=$r[nopol];
	$jmlpiut=$r[jumlah];
	$dibayar=$r[jumlah];
	$tbayar=$tbayar+$r[jumlah];
	
	$query1= "INSERT INTO jurppi_tmp (nofak,tgl_fak,nopol,jml_piut,dibayar) VALUES('$nofak','$tglfak','$nopol','$jmlpiut','$dibayar')";
	mysql_query($query1);
}
$data['tbayar'] = $tbayar;
echo json_encode($data);
?>