<?php include("../../include/dbconnect.php");
foreach($_POST as $p=>$t)
  {
     $_POST[$p] = trim($t);
  }

  $myCompany = $_POST['Company'];
  
  
  
  foreach($_POST as $p=>$t)
  {
     $_POST[$p] = trim($t);
  }

  $myBranch = $_POST['Branch'];
  
    foreach($_POST as $p=>$t)
  {
     $_POST[$p] = trim($t);
  }

  $myCatcode = $_POST['Catcode'];



?>
<title>Opening Balance Updation</title>
<style type="text/css">
body{
font-family:Verdana, Arial, Helvetica, sans-serif;
}
</style>
<link rel="stylesheet" href="../../include/style.css">
<body oncontextmenu = "javascript:return false;" ondragdrop= "javascript:return false;" onselectstart="javascript:return false;">

<center>

<table cellpadding=0 cellspacing=4 width=590>
<tr>
    <td style="padding:3px;" colspan="2"  class="tdhead"><b>
	New Account Head</b></td>
</tr><tr valign="top"><td colspan=2>
</td>
</tr>

 <form name='myForm01' method='POST' action='<?=$_SERVER['PHP_SELF']?>'>


<tr>
<td  class="tdindent" ><b>Select Company</b></td>
<td width="74" >
  
  <SELECT name='Company'   onChange="javascript:submit();">
    <?
	// Pull all the data from Catcode master & populate it
	
	$stQuery = mysqli_query($conn,"select distinct compcode,name from company order by name");


	
	
     echo "<option selected value=\" 0\"> Select Company ";
    while($row = mysqli_fetch_row($stQuery))
    {

		$temp = $row[1];
        if(isset($myCompany) && preg_match("/" . preg_quote($myCompany, '/') . "/", $row[0]))
	    {
            echo "<option selected value=\"$row[0]\">$temp";
        }
        else{
            echo "<option value=\"$row[0]\">$temp";
        }
    }
?>
  </SELECT></td></tr>

<?
/*
<tr>
<td class="tdindent"  ><b>Select Profit Centre</b></td>
<td >
  
  <SELECT name='Branch'   onChange="javascript:submit();">
    <?
	// Pull all the data from Catcode master & populate it
	
	$stQuery = mysqli_query($conn,"select distinct code,name from branches where compcode = '$myCompany' order by name");


	
	
     echo "<option selected value=\" 0\"> Select Profit Centre ";
    while($row = mysqli_fetch_row($stQuery))
    {

		$temp = $row[1];
        if(isset($myBranch) && preg_match("/" . preg_quote($myBranch", '/') . "/", $row[0]))
	    {
            echo "<option selected value=\"$row[0]\">$temp";
        }
        else{
            echo "<option value=\"$row[0]\">$temp";
        }
    }
?>
  </SELECT></td></tr>
 */
 ?> 
  
    <?php

// Pull all the data from Catcode master & populate it

$stQuery = mysqli_query($conn,"select distinct acctcode,groupname from acctgroup  order by groupname");

?>
<tr>
<td class="tdindent"  ><b>Select Account Group</b></td>
<td >
  
  <SELECT name='Catcode'   onChange="javascript:submit();">
    <?
     echo "<option selected value=\" 0\"> Select Group";
    while($row = mysqli_fetch_row($stQuery))
    {

		$temp = $row[1];
        if(isset($myCatcode) && preg_match("/" . preg_quote($myCatcode, '/') . "/", $row[0]))
	    {
            echo "<option selected value=\"$row[0]\">$temp";
        }
        else{
            echo "<option value=\"$row[0]\">$temp";
        }
    }
?>
  </SELECT></td></tr>

  
  
</form>
<td width="198"><form name="myform1" action="entry.php" method="post">

  <tr class="tdindent"> 
    <td><b>GL Head</b> 
    </td>
    <td colspan=2 class="tdindent">  
      <select name=accthead>
        <?php
$query = "select acctcode,description from acctmast  where acctmast.acctgroup= '$myCatcode' order by description";
$query = stripslashes($query);
$result= mysqli_query($conn,$query) or
      die (mysqli_error() );
     while($row=mysqli_fetch_row($result) )
       {
        echo "<option value='$row[0]'>";
	echo $row[1];
	echo "\n";
	}
?>
      </select>
      </td>
  </tr>

  <tr class="tdindent">
  
    <td><b>Opening Balance </b></td>
    <td width="300">  
      <input type="text" onKeyPress="return event.keyCode!=13" size="50" name="opening_balance" >
      </td>
  </tr>  
  
    <tr class="tdindent">
      <td><b>Status Debit / Credit</b></td>
        <td>  
	<select name="db_cr">
	<option value="DR">Debit</option>
	<option value="CR">Credit</option>
	</select>
      </td>
  </tr>
  <input type="hidden" name="compcode" value="<?=$myCompany?>">
  <input type="hidden" name="branch" value="<?=$myBranch?>">
  
  <table cellpading=0 cellspacing=10 width= 50>
    <tr> 
      <blockquote> 
        <td> <input type =submit name=submit value = "Submit"></td>
        <td><input type="reset" name="reset" value="Clear"></blockquote></td>
  </table>
</table>
<br><br><font size=1><center><a href= "#" onClick="javascript:window.close();">Close Window</a></center>

</body>

</form>
