<?php require_once('../Connections/lancrox.php'); ?>
<?php
//insert.php;
//itemname is actually the price of the item which is called from the db too
if(isset($_POST["item_name"]))
{
	 if ($_POST[bank]>0){
  	$update="insert into billing(userid,datein,tcode,sender,bank,means,station,typo)values('$_POST[userid]','$today','$_POST[batch]','$_POST[sender]','$_POST[bank]','Bank Transfer','Head Office','3')";
mysqli_query( $lancrox, $update ) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
 }
  if ($_POST[cash]>0){
 $update1="insert into billing(userid,datein,tcode,sender,paid,means,station,confirm,typo)values('$_POST[userid]','$today','$_POST[batch]','$_POST[sender]','$_POST[cash]','Cash Deposit','Head Office','YES','3')";
 mysqli_query( $lancrox, $update1 ) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
  }
  if ($_POST[cash]==0&& $_POST[bank]==0){$update2="insert into billing(userid,datein,tcode,sender,paid,means,station,confirm,typo)values('$_POST[userid]','$today','$_POST[batch]','$_POST[sender]','0','Credit','Head Office', 'YES','3')";
 mysqli_query( $lancrox, $update2 ) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
  }

 $order_id = uniqid();
 for($count = 0; $count < count($_POST["item_name"]); $count++)
 {  
 	

$query = "INSERT INTO agwa (userid,tcode,amount,unitcost,outputs,item,sender,datein,office) 
  VALUES ('$_POST[userid]','$_POST[batch]',:item_name*:item_quantity,:item_name, :item_quantity, :item_unit,'$_POST[sender]','$today','Head Office')
  ";
  $statement = $connect->prepare($query);
  $statement->execute(
   array(
 
    ':item_name'  => $_POST["item_name"][$count], 
    ':item_quantity' => $_POST["item_quantity"][$count], 
    ':item_unit'  => $_POST["item_unit"][$count]
   )
  );
 }
 $result = $statement->fetchAll();
 if(isset($result))
 {
  echo 'ok';
 }
}
?>
