<?php include("../../include/dbconnect.php"); 
	$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;
	}

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

	if($type=='DR')
	{	
  		$result=mysqli_query($conn,"update $filename set acctcode = '$acctcode', narration = '$narration',dbamt='$amount',cramt=0,invno='$invno',date = '$date',type = '$type',cheqno = '$cheqno',voucher_no='$voucher_no',reconciled_by = '$sms', cheq_date = '$ttype' where  trans_id='$trans_id' and record = '$record' ") or die(mysqli_error());
  		$result=mysqli_query($conn,"update $filename set  narration = '$narration',dbamt=0,cramt=$amount,invno='$invno',date = '$date',type = 'CR' ,cheqno = '$cheqno',voucher_no='$voucher_no',reconciled_by = '$sms',cheq_date = '$ttype' where  trans_id='$trans_id' and record != '$record' ") or die(mysqli_error());

	}
	elseif($type=='CR')
	{
  		$result=mysqli_query($conn,"update $filename set acctcode = '$acctcode', narration = '$narration',dbamt='0',cramt='$amount',invno='$invno',date = '$date',type = '$type',cheqno = '$cheqno',voucher_no='$voucher_no',reconciled_by = '$sms',cheq_date = '$ttype' where  trans_id='$trans_id' and record = '$record' ") or die(mysqli_error());
  		$result=mysqli_query($conn,"update $filename set  narration = '$narration',dbamt='$amount',cramt='0',invno='$invno',date = '$date',type = 'DR' ,cheqno = '$cheqno',voucher_no='$voucher_no',reconciled_by='$sms',cheq_date = '$ttype' where  trans_id='$trans_id' and record != '$record' ") or die(mysqli_error());
	}
      
}
elseif (isset($submit) && $submit == "Delete")

{
$result=mysqli_query($conn,"delete from `$filename` where trans_id='$trans_id' ") or die(mysqli_error());
$result=mysqli_query($conn,"delete from tranid where trans_id='$trans_id' and branch_code = '$branch' and account_year='$account_year' ") or die(mysqli_error());
}

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