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

mysql_query("UPDATE stock SET jml_stok=stok_tl,jml_stokb=stok_tlb WHERE 1");

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

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

    if($gudang=='Gudang')
		mysql_query("UPDATE stock SET jml_stokb=jml_stokb+$mutasi WHERE kode_st='$kodest' AND kode_cab='01'");
	else
		mysql_query("UPDATE stock SET jml_stok=jml_stok+$mutasi WHERE kode_st='$kodest' AND kode_cab='$gudang'");
}
echo "Kartu persediaan selesai diposting ulang.";
?>