<?php require_once('auth.php'); ?>
<?php
// mysqli_query($conn,"UPDATE `item` SET `item_qty`=(SELECT SUM(COALESCE(CASE WHEN plus = '+' THEN qty END,0)) - SUM(COALESCE(CASE WHEN plus = '-' THEN qty END,0)) FROM order_list WHERE pro_id=item.pro_id GROUP BY pro_id),`avg_cost`=(SELECT SUM(COALESCE(CASE WHEN plus = '+' THEN t_amount END,0)) / SUM(COALESCE(CASE WHEN plus = '+' THEN qty END,0)) FROM order_list WHERE  pro_id=item.pro_id AND item.coid='$coid' AND item.bid='$bid' AND item.brid='$brid' GROUP BY pro_id)") or die (mysqli_error($conn));
   mysqli_query($conn,"UPDATE `item` SET `item_qty`=(SELECT SUM(COALESCE(CASE WHEN plus = '+' THEN qty END,0)) - SUM(COALESCE(CASE WHEN plus = '-' THEN qty END,0)) FROM order_list WHERE pro_id=item.pro_id GROUP BY pro_id),avg_cost=(SELECT SUM(COALESCE(CASE WHEN plus = '+' THEN t_amount END,0)) / SUM(COALESCE(CASE WHEN plus = '+' THEN qty END,0)) FROM order_list WHERE pro_id=item.pro_id GROUP BY pro_id) WHERE item.coid='$coid' AND item.bid='$bid' AND item.brid='$brid'") or die (mysqli_error($conn));
   echo 'Update Complete';
?>