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

foreach($_POST as $q=>$r)
{
	$_POST[$q] = trim($r);
}
$myHead = $_POST['Head'];
$filename = 'templedger';
?>
<title> edit</title>
<body bgcolor="#ffffff"  topmargin=0>
<center>
<table cellpadding=0 cellspacing=4 width=590>
<tr>
<td style="padding:3px;" colspan=2 bgcolor="#93BEE2"><font ><b>Edit Entered Details </font></td>
</tr><tr valign="top"><td colspan=2>
<font >&nbsp;</font>
</td>
</tr>
</table>
<table border=0 cellpadding=3 cellspacing=4 width="590">
<table border="0" cellspacing="1" cellpadding="4" align="center" width="500" bgcolor="#999999">
<form name='myform' method='POST' action='<?=$_SERVER['PHP_SELF']?>?record=<?echo($record);?>&compcode=<?=$compcode?>&branch=<?=$branch?>&mdt=<?=$mdt?>&mGL=<?=$mGL?>&trans_id=<?=$trans_id?>'>


<input type="hidden" name="record" value="<?=$record?>">
   <tr>
      <td width="104" height="31" align="left" ><b><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif">GL</font></b></td>
      <td  ><?


$res = mysqli_query($conn,"SELECT distinct $filename.acctcode,description from `$filename`,acctmast where $filename.acctcode = acctmast.acctcode and $filename.record = '$record' ") or die(mysqli_error());
$arr = mysqli_fetch_row($res);

$sBuyQuery = mysqli_query($conn,"SELECT distinct acctcode,description from acctmast where active != 'No'  order by acctmast.description ") or die(mysqli_error());
?>
          <select name='Head' onChange="javascript:submit();">
            <?
		echo "<option selected value=\"$arr[0]\">$arr[1]";
		while($row = mysqli_fetch_row($sBuyQuery))
		{
			
			if(isset($myHead) && preg_match("/" . preg_quote($myHead, '/') . "/", $row[0]))
			{
				echo "<option selected value=\"$row[0]\">$row[1]";
			}
			else{
				echo "<option value=\"$row[0]\">$row[1]";
			}
		}
?>
        </select></td>
		
    </tr>
</form>
<form  name="abc" method="POST"   action="pupdate2.php?record=<?echo($record);?>&compcode=<?=$compcode?>&branch=<?=$branch?>&mdt=<?=$mdt?>&mGL=<?=$mGL?>&trans_id=<?=$trans_id?>">
<?php 
$result = mysqli_fetch_array(mysqli_query($conn,"select acctcode,date,narration,dbamt,cramt,type,trans_id,record,invno,account_year,cheqno,voucher_no,cheq_date from `$filename` where record = '$record' ")) or die(mysqli_error());

$acctcode = $result['acctcode'];
$trans_id = $result['trans_id'];
$account_year = $result['account_year'];
$dbamt= $result['dbamt'];
$cramt= $result['cramt'];
$type = $result['type'];
$cheqno = $result['cheqno'];
$voucher_no = $result['voucher_no'];
$ttype = $result['cheq_date'];

if($dbamt>0)
{
	$amount = $dbamt;
}
elseif($cramt>0)
{
	$amount = $cramt;
}	

if($myHead=='')
{
	$myHead = $acctcode;
}


?>
<input type="hidden" name="record" value="<?=$result['record']?>">
<input type="hidden" name="acctcode" value="<?=$myHead?>">
	



        









<tr><td  bgcolor="#FFFFFF"><font  face="Arial, Helvetica, sans-serif">Bill  No </font></td><td  bgcolor="#FFFFFF">
<input type="text" onKeyPress="return event.keyCode!=13"   maxlength=10 size="10" name="invno" value = <?=$result['invno']?>></td></tr>

<tr><td  bgcolor="#FFFFFF"><font  face="Arial, Helvetica, sans-serif">Voucher  No </font></td><td  bgcolor="#FFFFFF">
<input type="text" onKeyPress="return event.keyCode!=13"   maxlength=10 size="10" name="voucher_no" value = <?=$result['voucher_no']?>></td></tr>

<tr><td  bgcolor="#FFFFFF"><font  face="Arial, Helvetica, sans-serif">Cheque / RTGS  No </font></td><td  bgcolor="#FFFFFF">
<input type="text" onKeyPress="return event.keyCode!=13"   maxlength=10 size="10" name="cheqno" value = <?=$result['cheqno']?>></td></tr>



<tr><td  bgcolor="#FFFFFF"><font  face="Arial, Helvetica, sans-serif">Date </font></td><td  bgcolor="#FFFFFF">
<input type="text" onKeyPress="return event.keyCode!=13"   smaxlength=10 size="10" name="date_changed" value = <?=british($result['date'])?>></td></tr>


<tr><td  bgcolor="#FFFFFF"><font  face="Arial, Helvetica, sans-serif">Description </font></td><td  bgcolor="#FFFFFF">
<input type="text" onKeyPress="return event.keyCode!=13"    size="60" name="narration" value = <? echo("'$result[narration]'");?>></td></tr>



<tr><td  bgcolor="#FFFFFF"><font  face="Arial, Helvetica, sans-serif">Amount</font></td><td  bgcolor="#FFFFFF">
<input type="text" onKeyPress="return event.keyCode!=13"    size="40" name="amount" value = <?=$amount?>></td></tr>



<tr><td  bgcolor="#FFFFFF"><font  face="Arial, Helvetica, sans-serif">Type</font></td><td  bgcolor="#FFFFFF">

<select name="type">
<?
if($type == 'CR')
{
?>
	<option selected value="CR">CR</option>
    <option value="DR">DR</option>
<?
}
elseif($type=='DR')
{
?>
    <option selected value="DR">DR</option>
	<option value="CR">CR</option>

<?
}
?>

<tr><td  bgcolor="#FFFFFF"><font  face="Arial, Helvetica, sans-serif">Transaction Type</font></td><td  bgcolor="#FFFFFF">
<input type="text" onKeyPress="return event.keyCode!=13"    size="40" name="ttype" value = <?=$ttype?>></td></tr>



<input type="hidden" name="trans_id" value="<?=$result['trans_id']?>">
<input type="hidden" name="account_year" value="<?=$result['account_year']?>">


<tr> <blockquote>
<td align=right>
  <input  type =submit name=submit value = "Update"></td> <td><input type =submit name=submit value = "Delete"></blockquote>
</table>

<br><br><font size=1><center><a href= "javascript:window.close();">Close Window</a></center></font>
</body>
</form>
