<?php 
 echo @$_GET['msg'];
  session_start();
  if(isset($_SESSION['userId'])){ 
if(isset($_POST['srate'])){
require 'connection.php';
 extract($_POST);

$ref="SELECT * from broilertransfer where vno='$vno'";
	$refrun=mysqli_query($connect, $ref) or die(mysqli_error($connect));
	$refrow = mysqli_fetch_array($refrun);
		$refno= $refrow['refno'];

	$qry = "UPDATE `broilertransfer` SET dated='$dated',supid='$supid' ,accid='$accid' ,vrate='$srate' ,crate='$crate' ,qty='$qty' ,kat='$kat' ,refno='$refno' ,status='posted' ,posted='posted' where vno=$vno";
	$run = mysqli_query($connect, $qry) or die(mysqli_error($connect));	
// Insert into Stock Ledger table
	$costin= ($qty)*($srate);
	

 $stockqty="INSERT INTO `stockledger`(`dated`, `accid`, `vno`, `refno`, `invoiceno`, `itemid`, `stockin`, `ratein`, `costin`) VALUES('$dated','$supid','$vno','$refno','BRL-PR','$itemid','$qty','$srate','$costin')";
	$stockresult=mysqli_query($connect,$stockqty) or die(mysqli_error($connect));
	$qty= ($qty)-($kat);
$des='weight= '.$qty.' @ '.$srate;
	$ledgerqry="INSERT INTO `ledger`(`dated`, `accid`, `description`, `vno`, `refno`, `entrytype`, `credit`) VALUES('$dated','$supid','$des','$vno','$refno','BRL-PR','$costin')";
	$ledgerrun=mysqli_query($connect,$ledgerqry) or die(mysqli_error($connect));

$purledgerqry="INSERT INTO `ledger`(`dated`, `accid`, `description`, `vno`, `refno`, `entrytype`, `debit`) VALUES('$dated','1','$des','$vno','$refno','BRL-PR','$costin')";
	$purledgerrun=mysqli_query($connect,$purledgerqry) or die(mysqli_error($connect));

	echo "Posted";
	
}
}
else
{
header('location: index.php');
}
 ?>
