<body background="../forms/i.jpg">

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




// Get all _POST VALUES HERE..

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

$myGroup = $_POST['Group'];
// Get all _POST VALUES HERE..



foreach($_POST as $j=>$k)
{
	$_POST[$j] = trim($k);
}

$myType = $_POST['Type'];

foreach($_POST as $w=>$y)
{
	$_POST[$w] = trim($y);
}

$myBatch = $_POST['head'];

foreach($_POST as $w=>$y)
{
	$_POST[$w] = trim($y);
}

$myItem = $_POST['head2'];


foreach($_POST as $s=>$t)
{
	$_POST[$s] = trim($t);
}

$mySalesexp = $_POST['Salesexp'];



?>
<SCRIPT LANGUAGE="JavaScript" src="../../include/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var cal = new CalendarPopup();
</SCRIPT>
<title>Receipt</title>
<body background="../../images/blater01.gif" topmargin=0>
<center> 
<table cellpadding=0 cellspacing=4 width=568>
  <tr> 
    <td style="padding:3px;" colspan=2 bgcolor="#93BEE2"><font face="Verdana, Arial, Helvetica, sans-serif"><b><b>Invoice Preparation </b></font></td>
  </tr>

</table>
<form  name='myform' method='POST' action='<?=$_SERVER['PHP_SELF']?>?custcode=<?=$custcode?>&gcode=<?=$gcode?>&ipno=<?=$ipno?>'>
<table border=0 cellpadding=3 cellspacing=4 width="568" bgcolor="#E6E6FF">

   <?php
 $invtype[0] = 'Credit';   
 $invtype[1]='CASH';


?>

<tr>

    <td width="103" height="31" align="left" ><strong><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif">Invoice Type</font></strong></td>
    <td><select name='Type' onChange="javascript:submit();" >
      <?php

   for($ind=0;$ind<count($invtype);$ind++)
    {
   
	if(isset($myType) && preg_match("/" . preg_quote($myType, '/') . "/", $invtype[$ind]))
	{
		echo "<option selected value=\"$invtype[$ind]\">$invtype[$ind]";
	}
	else{
		echo "<option value=\"$invtype[$ind]\">$invtype[$ind]";
	}
 }
?>
    </select></td>



<?

if($custcode == '0' and $myType=='Credit')
{
?>
<script language="javascript">
alert("Sorry..Customer with no Ledger Account, Credit Sales is not allowed");
</script>
<?
exit;
}

if($custcode > '0' and $myType=='Credit')
{

	$acresult = mysqli_query($conn,"select acctcode from acctmast where acctcode = '$custcode'") or die(mysqli_error());
	$acrow = mysqli_fetch_row($acresult);
	if(!is_array($acrow))
	{	
	?>
	<script language="javascript">
	alert("Customer don't have GL, Credit Sales is not allowed");
	</script>
	<?
	exit;
	}
	else
	{
		$bcode = $acrow[0];
	}
}

	$dresult = mysqli_query($conn,"select discount,taxtype,gstin from buy where bcode  = '$custcode' ") or die(mysqli_error());
	$drow = mysqli_fetch_row($dresult);
	$discount = $drow[0];
	$taxtype = $drow[1];
	$buyertype = $drow[1];
	$gstin = $drow[2];
if($custcode > 0 and $taxtype=='')
{
	?>
    <script language="javascript">
	alert("Sorry. Customer  is not marked as STATE/INTERSTATE");
	</script>
 <?
 exit;
}
if($custcode == 0)
{
	$taxtype = 'STATE';
	$gstin = '';
}
	$presult = mysqli_query($conn,"select name from billcustomer ") or die(mysqli_error());
	$prow = mysqli_fetch_row($presult);
?>


    <td width="103" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Customer Name</b></font></td>
    <td width="200"><?=$prow[0]?>   
    </td>

<tr>
    <td width="103" align="left"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Discount % </b></font></td>
    <td width="200"><input type="text" onKeyPress="return event.keyCode!=13" name="discount" id="h2"  value='<?=$discount?>'   onChange="javascript:submit();"></td>
	

 
  
  </tr>
  <tr>
    <td width="59" height="31" align="left" ><strong><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif">Product Group</font></strong></td>
    <td><?
$stQuery = mysqli_query($conn," select catcode, category from prodcat where rf = 'F'  order by category")or die( mysqli_error() );
?>
        <select name='Group' onChange="javascript:submit();">
          <?
echo "<option selected value=\" 0\"> Select Group";
while($row = mysqli_fetch_row($stQuery))
{
	
	if(isset($myGroup) && preg_match("/" . preg_quote($myGroup, '/') . "/", $row[0]))
	{
		echo "<option selected value=\"$row[0]\">$row[1]";
	}
	else{
		echo "<option value=\"$row[0]\">$row[1]";
	}
}
?>
      </select></td>
      



    <td width="103" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Product</b></font></td>
    <td><select name='head2'  onChange="javascript:submit();">
      <?

	echo "<option selected value=\" 0\"> Item";
	$prodresult = mysqli_query($conn,"select prodcode,prodname,rate from product  where catcode = '$myGroup'   ") or die(mysqli_error());
	while($prow = mysqli_fetch_row($prodresult))
	{

	$qresult = mysqli_query($conn,"select batch_no,sum(inqty),sum(outqty) from stktrans  where  acctcode = '$prow[0]'") or die(mysqli_error());
	while($qrow = mysqli_fetch_row($qresult))
	{
		if($qrow[1] - $qrow[2] >0)
		{
			
			$q1result = mysqli_query($conn,"select sum(qty) from spurch where prodcode ='$prow[0]' ") or die(mysqli_error());
			$q1row = mysqli_fetch_row($q1result);
			
			$qt = ($qrow[1] - $qrow[2]) - $q1row[0];	
	$temp = $prow[1].'('.$prow[2].')'.'&nbsp;A.Qty&nbsp;'.$qt;
	if(isset($myItem) && preg_match("/" . preg_quote($myItem, '/') . "/", $prow[0]))  
	{
		echo "<option selected value=\"$prow[0]\">$temp";
	}
	else{
		echo "<option value=\"$prow[0]\">$temp";
	}		
		}
	}
	}
	?>
    </select>
    </td>

      
      </tr>

    
          
<?
	  
 



	$mresult = mysqli_query($conn,"select rate,tax_rate from product where prodcode = '$myItem' ") or die(mysqli_error());
	$mrow = mysqli_fetch_row($mresult);
	$rt = $mrow[0];
	$ptax_percent = $mrow[1];



	$mresult = mysqli_query($conn,"select  discount from prodcat where catcode = '$myGroup' ") or die(mysqli_error());
	$mrow = mysqli_fetch_row($mresult);
	$dis = $mrow[0];
	if($dis == 'No')
	{
		$discount =0;
	}


	/*
	if($taxtype =='STATE')
	{
		$rate = round(($rt - $rt*$discount/100)*100/(100+5),2);
	}
	else
	{
		$rate = round(($rt - $rt*$discount/100)*100/(100+2),2);
	}
	//$rate = round(($rt - $rt*$discount/100),2);
	*/
?>
	  


 

<tr>
    <td width="59" align="left"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Qty </b></font></td>
    <td width="162"><input name="qty"  type="text" onKeyPress="return event.keyCode!=13" id="h1"   value='0' ></td>
    <td width="103" align="left"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Rate </b></font></td>
    <td width="200"><input type="text" onKeyPress="return event.keyCode!=13" name="rate1" id="h2"  value='<?=$rate?>'  ></td>
  </tr>
   

   
  <input type="hidden"  name="amount" id="h3">
</table>
<table cellpading=0 cellspacing=10 width= 668>

<tr><td width="307" align="left"><blockquote><input type =submit name="Clear" value = "Clear" ></blockquote></td><td width="288" align="right">
 <blockquote>  <input type =submit name="refresh" value = "Refresh" ></blockquote></td><td width="307" align="left"><blockquote><input type =submit name="add" value = "Add" ></blockquote></td>

</table>

<?
if($Clear == 'Clear')
{
	mysqli_query($conn,"truncate spurch ") or die(mysqli_error());
}
if($accthead == '0' and $qty > 0)
{
?>
<script language="JavaScript">
alert("Select Product please");
</script>
<?
exit;
}




//ECHO "$discount";
if($add == 'Add' and $qty >0)
{


	if($myType== '0')
	{
		?>
		<script language="JavaScript">
		alert("Select Type of Sales Please..");
		</script>
		<?
		exit;
	}
	
	if($myTax== '0')
	{
		?>
		<script language="JavaScript">
		alert("Select type of Tax please..");
		</script>
		<?
		exit;
	}	
	
	$bresult = mysqli_query($conn,"select distinct bcode from spurch ") or die(mysqli_error());
	$brow = mysqli_fetch_row($bresult);
	if(is_array($brow))
	{
	if($brow[0] != $custcode)
	{
		?>
			<script language="JavaScript">
            alert("Selected Buyer  is wrong");
            </script>
            <?
            exit;
	}
	}
		
	$qresult = mysqli_query($conn,"select sum(inqty - outqty) from stktrans where acctcode ='$myItem'  ") or die(mysqli_error());
	$qrow = mysqli_fetch_row($qresult);
	$st1 = $qrow[0];

	$qresult = mysqli_query($conn,"select sum(qty) from spurch where prodcode ='$myItem'  ") or die(mysqli_error());
	$qrow = mysqli_fetch_row($qresult);
	$st2 = $qrow[0];
	$sqty = $st1 - $st2;
	
	if($sqty - $qty < 0)
	{
		?>
		<script language="JavaScript">
		alert("Sorry you can't issue more than stock..");
		</script>
		<?
		exit;	
	}


	$aresult1=mysqli_query($conn,"select taxtype, tax,cess from salestax where reserved_word != 'INPUT' and tax = '$ptax_percent' ") or die(mysqli_error());
	$arow1 = mysqli_fetch_row($aresult1);
	$tax_type = $arow1[0];
	$tax_rate = $arow1[1];	
	
	$rate1 = round($rate1 *100/(100+$ptax_percent),2);
	if($gstin != '')
	{
		$cess_percent = 0;
	}
	else
	{
		$cess_percent = $arow1[2];
	}
		
		$amount = $rate1 * $qty;
		$result = mysqli_query($conn,"insert into spurch values ( '$compcode','$custcode','$myItem', '$qty','$rate1','$myBatch', '$amount','$bags', '$discount','$tax_type','$tax_rate','$cess_percent','$specification','$stainer_rate',  NULL)") or die(mysqli_error());

}


$bankQuery=mysqli_query($conn,"select acctcode,description from acctmast where reserved_word = 'SALESEXP' order by description") or die(mysqli_error());
?>

  <td width="74" height="31" align="left" ><strong><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Expense Type</font></strong></td>
<td> <SELECT name='Salesexp' onChange="javascript:submit();" >
<?php

    while($row = mysqli_fetch_row($bankQuery))
    {
   	$temp = $row[1];
	if(isset($mySalesexp) && preg_match("/" . preg_quote($mySalesexp, '/') . "/", $row[0]))
	{
		echo "<option selected value=\"$row[0]\">$temp";
	}
	else{
		echo "<option value=\"$row[0]\">$temp";
	}
 }
?>
    </SELECT></td>
  <td width="167"><input name="packing"  type="text"  value='<?=$packing?>' onChange="javascript:submit()"></td>



</tr>
</form>
 
<form name='myform2' method='POST' action='entry.php'  onsubmit="return check()" >


<script language="javascript">
function check()
{

if(myform2.inv_no.value=="")
	{
		alert("Please Enter Invoice No");
		myform2.inv_no.focus();
		return false;
	}	

if(myform2.invtype.value=="")
	{
		alert("Please Reselect the Invoice Type");
		myform2.invtype.focus();
		return false;
	}	


}
</script>
<?

$result = mysqli_query($conn,"select compcode from company  ") or die(mysqli_error());
$row = mysqli_fetch_row($result);
$compcode= $row[0];


if($packing>0)
{
	if($mySalesexp =='0')
	{
		?>
        <script language="javascript">
		alert("You have not opted Expense Type. Please select otherwise data won't be saved");
        </script>
        <?
	}
}
?>



<input type="hidden" name="bcode" value="<?=$custcode?>">
<input type="hidden" name="invtype" value="<?=$myType?>">
<input type="hidden" name="gcode" value="<?=$gcode?>">
<input type="hidden" name="ipno" value="<?=$ipno?>">

<input type="hidden" name="exp_accthead" value="<?=$mySalesexp?>">
<table width="670">
  <tr  bgcolor="#A4A4FF">

<td width="42" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Modify</b></font></td>
<td width="119" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Product Name</b></font></td>



<td width="35" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Qty &nbsp;</b></font></td>
<td width="47" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Rate &nbsp;</b></font></td>
<td width="67" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Discount % &nbsp;</b></font></td>
<td width="95" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Value</b></font></td>
<td width="95" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Value after Discount</b></font></td>
<td width="47" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Tax %</b></font></td>
<td width="60" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Tax amount</b></font></td>
<td width="118" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Amount</b></font></td>


<?



$gtotal = 0;
$result = mysqli_query($conn,"select * from spurch  order by record ") or die(mysqli_error());
while($row = mysqli_fetch_row($result))
{
	$compcode = $row[0];
	$bcode = $row[1];
	$accthead = $row[2];
	$qty = $row[3];
	$rate = $row[4];
	$batch_no = $row[5];	
	$amount = $row[6];
	$units = $row[7];
	$discount_percent = $row[8];
	$taxtype = $row[9];
	$tax_percent = $row[10];
	$cess_percent = $row[11];
	$specification = $row[12];
	$stainer_rate = $row[13];
	$record = $row[14];
	$rate = $rate + $stainer_rate;



	$value= round($qty * $rate,2);
	$taxable_value = round($value,2);
	if($bcode ==0)
	{
		$buyertype = 'STATE';
	}
	//$disc_amt = round($value * $discount_percent /100,2);
	if($gstin !='')
	{
		$cess_percent =0;
	}
	
	$taxamt = round($taxable_value * $tax_percent / 100,2);
	if($buyertype == 'STATE')
	{
		$cess_amt = round($taxable_value * $cess_percent/100,2);
	}
	else
	{
		$cess_amt=0;
	}
	
	$amount=  $taxable_value + $taxamt; 
		


	$tottax = $tottax +$taxamt;
	$gtotal = $gtotal + $amount;
	$valuetot = $valuetot + $value;
	$cesstotal = $cesstotal +$cess_amt;
		//$disctotal = $disctotal + $disc_amt;


	$bresult  = mysqli_query($conn,"select name,taxtype from buy where bcode = '$bcode' ") or die(mysqli_error());
	$brow = mysqli_fetch_row($bresult);
	$bname = $brow[0];
	$taxtype = $brow[1];
	


	$bresult  = mysqli_query($conn,"select prodname from product where prodcode = '$accthead' ") or die(mysqli_error());
	$brow = mysqli_fetch_row($bresult);
	$pname = $brow[0];
	if($specification != "")
	{
		$pname = $pname.'&nbsp;('.$specification.')';
	}
	

?>



<tr  bgcolor="#D7D7FF">
<td width="42" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><a href = "peditview.php?record=<?echo($record);?>"><?echo($record);?></a></b></font></td>
<td width="119" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$pname?></b></font></td>



<td width="35" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><? if($qty >0) echo $qty;?></b></font></td>
<td width="47" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><? if($rate >0) echo $rate;?></b></font></td>
<td width="67" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><? if($discount_percent >0) echo $discount_percent;?></b></font></td>
<td width="95" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><? if($value >0) echo $value;?></b></font></td>
<td width="95" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><? if($taxable_value >0) echo $taxable_value;?></b></font></td>
<td width="47" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><? if($tax_percent >0) echo $tax_percent;?></b></font></td>
<td width="60" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$taxamt?></b></font></td>
<td width="118" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><? if($amount >0) echo $amount;?></b></font></td>

</tr>

<?
}












$bamt =  $gtotal+(float)$packing+(float)$cesstotal ;

$billamt = round($bamt);
$diff = $billamt- $bamt;


?>

<input type="hidden" name="packing" value="<?=$packing?>">


<tr  bgcolor="#D7D7FF">
<td colspan="5"   align="right"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Total </b></font></td>
<td width="60" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($valuetot,2,'.','')?></b></font></td>
<td width="60" height="31" align="right" ><font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($disctotal,2,'.','')?>(D)</b></font></td>
<td width="60" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b></b></font></td>

<td width="60" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($tottax,2,'.','')?></b></font></td>
<td width="118" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($gtotal,2,'.','')?></b></font></td>
</tr>
<?
	$taxresult = mysqli_query($conn,"select taxtype,round(sum(rate*qty*tax_rate/100),2),round(sum((rate*qty)),2) from spurch group by taxtype") or die(mysqli_error());
	while($trow = mysqli_fetch_row($taxresult))
	{
		$stresult = mysqli_query($conn,"select sgst_acctcode, cgst_acctcode, igst_acctcode, sp_acctcode,tax,cess,cess_acctcode from salestax where taxtype = '$trow[0]' ") or die(mysqli_error());
		$srow = mysqli_fetch_row($stresult);	
		$sgst_acctcode = $srow[0];	
		$cgst_acctcode = $srow[1];
		$igst_acctcode = $srow[2];
		$myPurgl = $srow[3];
		$tax_rate = $srow[4];
		//$cess_percent = $srow[5];
		$cess_acctcode = $srow[6];
		
		$bresult = mysqli_query($conn,"select taxtype,gstin from buy where bcode = '$bcode' ") or die(mysqli_error());
		$brow = mysqli_fetch_row($bresult);
		$buyertype =  $brow[0];
				$taxamt=round($trow[1],2);
		$pvalue = round($trow[2],2);		
		if($buyertype == 'STATE')
		{
		//	$cess_amt = round($taxamt * $cess_percent/100,2);
			$sgst_amt = round($taxamt/2,2);
			$cgst_amt = $sgst_amt;
			$igst_amt =0;
			$tax_rate = $tax_rate/2;
		}
		if($buyertype == 'INTERSTATE')
		{
			$igst_amt = round($taxamt,2);
			$sgst_amt=0;
			$cgst_amt=0;
			$cess_amt=0;
		}
		if($sgst_amt >0)
		{		
?>
<tr  bgcolor="#D7D7FF">
<td colspan="8"   align="right"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>SGST &nbsp;<?=$tax_rate?>&nbsp;% </b></font></td>
<td width="45" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($sgst_amt,2,'.','')?></b></font></td>

<td>&nbsp;</td>
</tr>

<?
		}
		if($cgst_amt >0)
		{		
?>
<tr  bgcolor="#D7D7FF">
<td colspan="8"   align="right"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>CGST &nbsp;<?=$tax_rate?>&nbsp;% </b></font></td>
<td width="45" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($cgst_amt,2,'.','')?></b></font></td>

<td>&nbsp;</td>
</tr>

<?
		}		

		if($cess_amt >0)
		{		
?>
<tr  bgcolor="#D7D7FF">
<td colspan="8"   align="right"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Cess &nbsp;<?=$cess_percent?>&nbsp;% </b></font></td><td>&nbsp;</td>
<td width="45" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($cesstotal,2,'.','')?></b></font></td>


</tr>

<?
		}	
				
		if($igst_amt >0)
		{		
?>
<tr  bgcolor="#D7D7FF">
<td colspan="8"   align="right"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>IGST &nbsp;<?=$tax_rate?>&nbsp;% </b></font></td>
<td width="45" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($igst_amt,2,'.','')?></b></font></td>

<td>&nbsp;</td>
</tr>

<?
		}

}// end of WHile Loop.
?>
<tr  bgcolor="#D7D7FF">
<td colspan="9"   align="right"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Other  Charges </b></font></td>
<td width="118" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><? if($packing>0) echo number_format($packing,2);?></b></font></td>
</tr> 






  <tr  bgcolor="#D7D7FF">
<td colspan="9"   align="right"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Round off</b></font></td>
<td width="118" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($diff,2,'.','')?></b></font></td>
</tr>

  <tr  bgcolor="#D7D7FF">
<td colspan="9"   align="right"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Net Amount </b></font></td>
<td width="118" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($billamt,2,'.','')?></b></font></td>
</tr>

</table>

<table border=0 cellpadding=3 cellspacing=4 width="667" bgcolor="#D9E0F9">

<? 

	$result = mysqli_query($conn,"select compcode from company  ") or die(mysqli_error());
	$row = mysqli_fetch_row($result);
	$compcode= $row[0];

	$aresult = mysqli_query($conn,"select account_year from branches ") or die(mysqli_error());
	$arow = mysqli_fetch_row($aresult);
	$account_year = $arow[0];
	

	  $billres = mysqli_query($conn,"select max(inv_no) from salesreg8b where  compcode = '$compcode' and account_year = '$account_year'   ") or die(mysqli_error());
  	  $sinvrow = mysqli_fetch_row($billres);
	  $inv_no = $sinvrow[0]+1;
	  ?>

		<tr > 
		<td width="97" height="31" align="left" ><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Invoice  No
		&nbsp;</b></font></td>
		<td width="195" > <input type="text" onKeyPress="return event.keyCode!=13" name="inv_no" value= '<?=$inv_no?>'   >		</td>
	<td  align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Invoice Date &nbsp;</b></font> </td>
		<td class="small_site_font_black" > 
		<?
		
		$today2=strftime ("%d/%m/%Y", mktime(0,0,0,date("m"),date("d"),date("Y"))); ?>
		<input name="today2" type="text" onKeyPress="return event.keyCode!=13" class="text_box_button" value="<?=$today2?>" size="10"   > 
		<a href="#" onClick="cal.select(document.myform2.today2,'anchor1','dd/MM/yyyy'); return false;"name="anchor1" id="anchor1"><img  src="../../images/cal.gif" border="0"></a>		</td>
		</tr>



        

<tr > 
    <td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Documents Through&nbsp;</b></font></td> <td width="145" > <input type="text" name="form20" value= "">
  </td>
  
    <td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Type of Sale 
    &nbsp;</b></font></td><td>
	<SELECT name='saletype' >
	
    <option value="GST">GST

	
      </SELECT> </td>
      
</tr>


<tr >   <td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Order Ref No:
    &nbsp;</b></font></td>
  <td width="145" > <input type="text" name="pur_no" value= ""> 
  </td>
  <td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Order Ref Date: 
    &nbsp;</b></font></td>
  <td width="145" > <input type="text" name="pur_date" value= ""> 
  </td>

</tr>
  

<tr >   <td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Mode of Transport: 
    &nbsp;</b></font></td>
  <td width="145" > <input type="text" name="vehicle_no" value= ""> 
  </td>
  <td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>
    Tick to send SMS</b></font></td>
  <td width="145" > <input  type="checkbox"  onKeyPress="return event.keyCode!=13" name="sms" value="Yes"> </td>

</tr>  
</table>

<table width = "667">
  <tr> 
    <td width = "284" align="right" ><font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Confirm</b></font></td>
    <td width="371"> <input type="radio"    onKeyPress="return event.keyCode!=13"   name="cnf" value = "No" checked> <font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>No 
    </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio"    onKeyPress="return event.keyCode!=13"   name="cnf" value = "Yes"> <font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Yes
      </b></font>&nbsp;</td>
  </tr> 


    <tr> 
      <td align="center" colspan="2"> <blockquote> <input type =submit name="submit" value = "Submit"></blockquote></td>
  </table>


<font size=1> 
<br><br><font size=1><center><a href= "index.html">Return to index page</center></font>
</font> 
