<?php
for($i=0;$i<$row;$i++){
	$pm_autoid 		= $_POST["pm_autoid".$i];
	$qty 			= $_POST["qty".$i];
	$price 			= $_POST['pm_bprice'.$i];
	$subtotal  		= $_POST['subtotal'.$i];
	$nett_price  	= $_POST['nett_price'.$i];
	$pm_disc  		= $_POST['pm_disc'.$i];
	$pm_disctype  	= $_POST['pm_disctype'.$i];
	$expdate 		= dtosql($_POST['expdate'.$i]);
	$ums 			= $_POST['um'.$i];
	
	$qty_p 			= $_POST["qty_p".$i];
	$qty_r 			= $_POST["qty_r".$i];
	$potongan 		= $_POST["potongan".$i];


	$sd_notes 		= $conn->real_escape_string($_POST["sd_notes".$i]);	
	$total_qty 	= $qty + $qty_p + $qty_r;
	
	if($total_qty!=0){
		$sqlprod = "SELECT * FROM mst_product
		WHERE pm_autoid = '$pm_autoid' LIMIT 0,1";
		$prod_conn = $conn->query($sqlprod);
		$prod = $prod_conn->fetch_assoc();
		$prod_name = $conn->real_escape_string($prod['pm_name']);

		$sqlin = "INSERT INTO sodetail 
			(so_autoid,pm_autoid,pm_name,sd_qty,sd_price, sd_qtyp, sd_qtyr, sd_potongan, sd_notes) 
			VALUES 
			('$autoid','$pm_autoid','$prod_name','$qty','$price', '$qty_p' , '$qty_r', '$potongan', '$sd_notes')";
			if($prod_name){
				$conn->query($sqlin) or die($sqlin);
			}

	}
}
?>