Forum Moderators: coopster
if(isset($_POST['submit'])){
$sql2 = "INSERT INTO invoice (inv_date, inv_subtotal, inv_vat, inv_total) VALUES ('$_POST[date]', '', '', '')";
$result2 = mysql_query($sql2) or die(mysql_error());
$lastid=mysql_insert_id();
foreach($_POST['grade'] as $key => $grade) {
$weight = $_POST['weight'][$key];
$price = $_POST['price'][$key];
$sql1 = "INSERT INTO invoice_items (item_inv_id, item_grade, item_weight, item_price) VALUES ('$lastid', '$grade', '$weight', '$price')";
$result1 = mysql_query($sql1) or die(mysql_error());
}
}
$item_subtotal = $row['price'] / 1000 * $row['weight'];
if(isset($_POST['submit'])){
$sql2 = "INSERT INTO invoice (inv_date, inv_subtotal, inv_vat, inv_total) VALUES ('$_POST[date]', '', '', '')";
$result2 = mysql_query($sql2) or die(mysql_error());
$id=mysql_insert_id();
}
foreach($_POST['grade'] as $key => $grade) {
$weight = $_POST['weight'][$key];
$price = $_POST['price'][$key];
$subtotal = $price / 1000 * $weight;
$sql1 = "INSERT INTO invoice_items (item_inv_id, item_grade, item_weight, item_price, item_subtotal) VALUES ('$id', '$grade', '$weight', '$price', '$subtotal')";
$result1 = mysql_query($sql1) or die(mysql_error());
}
$sql3="SELECT SUM(item_subtotal) AS subtotal FROM invoice_items WHERE item_inv_id=$id";
$result3 = mysql_query($sql3) or die(mysql_error());
while($row3=mysql_fetch_array($result3)) {
$inv_subtotal = $row3['subtotal'];
$inv_vat = $inv_subtotal * 0.2;
$inv_total = $inv_subtotal + $inv_vat;
}
$sql4 = "UPDATE invoice SET inv_subtotal='$inv_subtotal', inv_vat='$inv_vat', inv_total='$inv_total' WHERE inv_id=$id LIMIT 1";
$result4 = mysql_query($sql4) or die(mysql_error());