<?php include("../../include/dbconnect.php"); 
$filename = 'templedger';
$result = mysqli_query($conn,"select trans_id,account_year from `$filename` where record = '$record' ") or die(mysqli_error());
$row = mysqli_fetch_row($result);
$trans_id = $row[0];
$account_year = $row[1];

$result = mysqli_query($conn,"select start_date,end_date from branches where code = '$branch' ") or die(mysqli_error());
$row = mysqli_fetch_row($result);
$start_date = $row[0];
$end_date = $row[1];


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

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

	$date_changed = us($date_changed);
	if($date_changed < $start_date or $date_changed > $end_date)
	{
	?>
    	<script language="javascript">
		alert("You have opted the date which is out of Scope. Please GO BACK and correct the date");
		</script>
    <?
	exit;
	}
	

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

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

?>

?>
<meta http-equiv="refresh" content="0 url=gl_editview.php?compcode=<?=$compcode?>&branch=<?=$branch?>&mdt=<?=$mdt?>&mGL=<?=$mGL?>&trans_id=<?=$trans_id?>">
