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

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

mysql_query("DELETE FROM rekap_mbr WHERE jurnal='PJL' AND tanggal BETWEEN '$tglawal' AND '$tglakhir'");

$sql1=mysql_query("SELECT kode_pj,tanggal,kode_cab,user,jam FROM faktur_pj WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND posting='P' AND batal='' GROUP BY kode_pj");
 
while($r1=mysql_fetch_array($sql1)){
	$kode	=$r1['kode_pj'];
	$tanggal=$r1['tanggal'];
	$kodecab=$r1['kode_cab'];
	$user 	=$r1['user'];
	$jam    =$r1['jam'];
	
	$sql = mysql_query("SELECT * FROM faktur_pj WHERE kode_pj='$kode' ORDER BY no_urut");
	while($r=mysql_fetch_array($sql)){
		$nourut =$r['no_urut'];
		$kodest =$r['kode_st'];
		$jmlunit=$r['jml_unit'];
		$hgjual	=$r['hg_jual'];
		
		mysql_query("INSERT INTO rekap_mbr (kode_tr,jurnal,tanggal,no_bukti,no_urut,kode_st,gudang,keterangan,masuk,keluar,harga,user,jam,batal) VALUES('$kode','PJL','$tanggal','$kode','$nourut','$kodest','$kodecab','Penjualan retail','0','$jmlunit','$hgjual','$user','$jam','')");
	}
}
echo "Data penjualan tanggal $tglawal s/d $tglakhir telah diposting ulang.";
?>