<body background="i.jpg">
<?php include("../../include/dbconnect.php");?>


<title>Credit Note Entry</title>
<body background = 'blater01.gif'  topmargin=0>
<center>
<table cellpadding=0 cellspacing=4 width=590>
<tr> 
<td style="padding:3px;" colspan=2 bgcolor="#93BEE2"><font face="Verdana, Arial, Helvetica, sans-serif"><b><b>Add new Credit Note</b></font>
</td>
</tr>
<tr valign="top"> 
<td colspan=2> <font >&nbsp;</font> </td>
</tr>
</table>

<?php 
foreach($_POST as $p=>$t)
{
	$_POST[$p] = trim($t);
}
$myCustomer = $_POST['Customer'];
?>
<table border=0 cellpadding=3 cellspacing=4 width="590">
<form name='myForm02' method='POST' action='<?=$_SERVER[PHP_SELF]?>'>
<tr><td >
<font class="sbd"><b>Select  Company</b></font>
</td>
	<td colspan=2>
	<select name= seller>
	<?php $query="select distinct compcode,name from company order by name ";
		  $query=stripslashes($query);
		  $result=mysql_query($query) or
		  die( mysql_error() );
		  
		  while ( $row= mysql_fetch_row($result))
		  {
			  echo "<option value='$row[0]'>";
		  echo $row[1];
		  echo "\n";
		  }
	?>
	</select>
	</td></tr>
<?php
$result=mysql_query("select bcode,name,unit from buy order by name") or die(mysql_error());
?> 
  <tr> 
    <td nowrap ><font class="sbd"><b>Cusomter Name </b></font></td>
    <td width="418">   <SELECT name='Customer' onChange="javascript:submit();">
<?php	
while($row = mysql_fetch_row($result))
{
if(isset($myCustomer) && eregi("$myCustomer", $row[0]))
  {
    $temp = $row[1].'&nbsp; '.$row[2];
	echo "<option selected value=\"$row[0]\">$temp";
  }
  else
  {
       $temp = $row[1].'&nbsp; '.$row[2];
       echo "<option value=\"$row[0]\">$temp";      
  }
}
echo "</select>";
?>

</SELECT>
</td>
</form>

<form name="myForm03" method='POST' action="crnotesave.php">

<?
$result = mysql_query("select compcode,account_year from company where compcode like '%$compcode' ") or die(mysql_error());
$row = mysql_fetch_row($result);
$account_year = $row[1];
$result = mysql_query("select max(crnoteno) from crnote where account_year = '$account_year' ") or die(mysql_error());
$row = mysql_fetch_row($result);
$crnoteno = $row[0]+1;
?>

<input type="hidden" name="bcd" value=<? echo($myCustomer);?> >
<input type="hidden" name="acct_yr" value=<? echo($account_year);?> >

<?php
$custQuery=mysql_query("select record,invno,date,dbamt from custledger where bcode= '$myCustomer' and paystatus='No' ") or die(mysql_error());
?>
<tr> 
    <td nowrap ><font class="sbd"><b>Invoice Details</b></font></td>
    <td> <SELECT name='invno[]' multiple size="5" multiple >
<?php
     echo "<option selected value=\" 0\"> Select Invoice No";
    while($row = mysql_fetch_row($custQuery))
    {
			$temp = 'Inv No'.$row[1].'&nbsp;Dt&nbsp;'.$row[2].'&nbsp;Amt:&nbsp;'.$row[3];
            echo "<option value=\"$row[0]\">$temp";        
    }
?>
    </SELECT>
    </td>
  </tr>
  <td nowrap></div>


<tr>
<td nowrap> <font class="sbd"><b>Credit Note No</b></font></td>
<td><input name="crnoteno" type="text" onKeyPress="return event.keyCode!=13" size="10" maxlength="10" value = <? echo "$crnoteno" ?> ></td></tr>


<SCRIPT LANGUAGE="JavaScript" src="../../include/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var cal = new CalendarPopup();
</SCRIPT>

<? // echo $sdt;
if(empty($sdt))
{
  $sdt=strftime ("%d/%m/%Y", mktime (0,0,0,date("m"),date("d"),date("Y"))); 
}?>
<td nowrap> <font class="sbd"><b>Credit Note Date</b></font></td>
<td>
<INPUT NAME="sdt" TYPE="text" class="text_box_button" VALUE="<?=$sdt?>" SIZE="15" readonly  >
 <A HREF="#" onClick="cal.select(document.myForm03.sdt,'anchor1','dd/MM/yyyy'); return false;"NAME="anchor1" ID="anchor1"><img  src="../../images/cal.gif" border="0"></A> <BR>
 </td>
</tr>

<tr>
<td nowrap> <font class="sbd"><b>Credit Note Amount</b></font></td>
<td><input name="crnoteamt" type="text" onKeyPress="return event.keyCode!=13"value= 0.00 size="10" maxlength="10"></td></tr>


<tr>
<td nowrap> <font class="sbd"><b>Description </b></font></td>
<td><textarea name="narration" cols="50" onKeyPress="return event.keyCode!=13"></textarea></td></tr>

<table cellpading=0 cellspacing=10 width= 50>
<tr>
<td><div align="center">
  <input type =submit name="submit" value = "Submit" >
</div></td>
</tr>

</table>
</table>

<br><br><font size=1><center><a href= "http://192.168.1.2/wilson/index.html">Return to index page</a></center></font>
</body></form>

