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

$tglawal	= $_POST['tglawal'];
$tglakhir	= $_POST['tglakhir'];

$sql	= mysql_query("SELECT * FROM faktur_pj WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND jenis_by='EDC' AND batal='' AND posting='P' ORDER BY kode_pj");
$row= mysql_num_rows($sql);

if($row>0){
	while($r=mysql_fetch_array($sql)){
		$kodepj=$r['kode_pj'];
		mysql_query("UPDATE faktur_pj SET import='v' WHERE kode_pj='$kodepj' ");
	}
}

$sql1 	= mysql_query("SELECT sum(jumlah) as tjumlah,sum(potongan) as tpotongan FROM faktur_pj WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND batal='' AND posting='P' ");
$row1	= mysql_num_rows($sql1);

if($row1>0){
	$r1=mysql_fetch_assoc($sql1);
	$tjumlah=$r1['tjumlah']-$r1['tpotongan'];
}else $tjumlah=0;

$sql1 	= mysql_query("SELECT sum(jumlah) as timport,sum(potongan) as tpotongan FROM faktur_pj WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND import='v' ");
$row1	= mysql_num_rows($sql1);

if($row1>0){
	$r1=mysql_fetch_assoc($sql1);
	$timport=$r1['timport']-$r1['tpotongan'];
}else $timport=0;

if($timport>0)
	$prosen=($timport/$tjumlah)*100;
else $prosen=0;

$data['tjumlah']	= $tjumlah;
$data['timport']	= $timport;
$data['prosen'] 	= $prosen;

echo json_encode($data);
?>