<?php include("../../include/dbconnect.php"); 

if($dbamt>0 and $cramt > 0 )
{
	?>
    <script language="javascript">
	alert("Either Credit or Debit is allowed in Single entry. Please correct");
	</script>
   
		<meta http-equiv="refresh" content="0 url=input2.php?compcode=<?=$compcode?>&branch=<?=$branch?>">
	

    <?
	exit;
}

if ( isset($submit) && $submit == "Update")
{

	if($type == 'CR')
	{
		$cramt=$amount;
		$dbamt=0;
	}
	elseif($type=='DR')
	{
		$dbamt= $amount;
		$cramt=0;
	}

	$date = us($date);
	
	
	$result = mysqli_query($conn,"select account_year,start_date,end_date from branches where code = '$branch' ") or die(mysqli_error());
	$row = mysqli_fetch_row($result);
	$account_year = $row[0];
	$startdt = $row[1];
	$enddt = $row[2];
	if($date < $startdt or $date > $enddt)
	{
	?>
		<script language="JavaScript">
		alert("Selected date does not belong to current accounting year. Please recheck the date");
		</script>	
	<?
	exit;
	}		
	

   $result=mysqli_query($conn,"update $filename set narration = '$narration',dbamt='$dbamt',cramt ='$cramt',invno='$invno',date = '$date',type='$type',acctcode= '$acctcode',amttype = 'J',voucher_no = '$voucher_no',cheqno = '$cheqno',cheq_date = '$ttype' where record = '$record'  ") or die(mysqli_error());
   $result=mysqli_query($conn,"update $filename set date = '$date' where trans_id = '$trans_id' and account_year = '$account_year'  ") or die(mysqli_error()); 
   

}
elseif (isset($submit) && $submit == "Delete")

{
$result=mysqli_query($conn,"delete from `$filename` where record ='$record' ") or die(mysqli_error());

}

?>
<meta http-equiv="refresh" content="0 url=input2.php?compcode=<?=$compcode?>&branch=<?=$branch?>">
