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

mysql_query("UPDATE stock SET jml_gd1=stok_tl WHERE 1");

$sql = mysql_query("SELECT kode_st,sum(masuk) as jmasuk,sum(keluar) as jkeluar FROM rekap_mbr WHERE batal='' GROUP BY kode_st");

while($r=mysql_fetch_array($sql)){
    $kodest = $r[kode_st];
	$jmasuk = $r[jmasuk];
	$jkeluar= $r[jkeluar];
	$mutasi = $jmasuk-$jkeluar;

    mysql_query("UPDATE stock SET jml_gd1=jml_gd1+$mutasi WHERE kode_st='$kodest'");
} 

echo "Kartu persediaan selesai diposting ulang.";
?>
