<?php include("../../include/dbconnect.php"); 
$filename = 'templedger';

$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")
{
	$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;
	}	
	if($type=='DR')
	{	
  		$result=mysqli_query($conn,"update $filename set acctcode = '$acctcode', narration = '$narration',dbamt='$amount',cramt=0,invno='$invno',date = '$date_changed',type = '$type',cheqno = '$cheqno',voucher_no='$voucher_no',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_changed',type = 'CR',cheqno = '$cheqno',voucher_no='$voucher_no',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_changed',type = '$type',cheqno = '$cheqno',voucher_no='$voucher_no',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_changed',type = 'DR', cheqno = '$cheqno',voucher_no='$voucher_no',cheq_date ='$ttype' where trans_id='$trans_id' and record != '$record' ") 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?>">
