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

$planid = $_POST['planid'];
$shift = $_POST['shift'];
$jenis = $_POST['jenis'];
$reject_id = $_POST['reject_id'];
$reject = $_POST['myreject'];
$qty = $_POST['myqty'];

$hitung = count($reject_id);

for( $i=0; $i < $hitung; $i++ ) {
	if($reject[$i]!==''||$qty[$i]!=='') {
	if($reject_id[$i]!=='') {
		$query = "UPDATE reject SET Reason = '$reject[$i]',
									Qty = '$qty[$i]'
									WHERE Reject_ID = '$reject_id[$i]'";

			mysqli_query($koneksi, $query)
			or die ("Gagal Perintah SQL".mysql_error());
	} else {
    $query = "insert INTO reject SET
										PlanID = '$planid',
										Shift = '$shift',
										Jenis = '$jenis',
										Reason = '$reject[$i]',
										Qty = '$qty[$i]'
										";

	mysqli_query($koneksi, $query)
	or die ("Gagal Perintah SQL".mysql_error());
	}
	} else {
	if($reject_id[$i]!=='') {
		$query = "DELETE FROM reject 
							WHERE Reject_ID ='$reject_id[$i]' 
								";

		mysqli_query($koneksi, $query)
		or die ("Gagal Perintah SQL".mysql_error());
	}else{

	}

	}
}

header('Location:lap_prod.php?id='.$planid.'&shift='.$shift);

?>

