<body background="">
<form name='myForm02' method='POST' action='post.php' >
<?php include("../../include/dbconnect.php"); 



if(empty($bcode)) 
{
	echo("Customer not selected, Please select Customer and resubmit<br>");
	exit;
}


$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(invno) from salesreg where compcode = '$compcode'  and account_year = '$account_year' ") or die(mysql_error());
$row = mysql_fetch_row($result);
$invno1 = $row[0]+1;

?>

<input type="hidden" name="compcode" value="<? echo($compcode);?>">
<input type="hidden" name="bcode" value="<? echo($bcode);?>">		
<input type="hidden" name="packing_percentage" value="<? echo($packing_percentage);?>">
<input type="hidden" name="transport_charges" value="<? echo($transport_charges);?>">
<input type="hidden" name="typeofsale" value="<? echo($typeofsale);?>">
<input type="hidden" name="cexreg" value="<? echo($cexreg);?>">
<input type="hidden" name="prepare_time" value="<? echo($prepare_time);?>">
	<input type="hidden" name="removal_time" value="<? echo($removal_time);?>">
 <input  type="hidden" name="taxcode" value="<?=$Tax?>">

<?
$result= mysql_query("select name,address1,address2,city,state,pin,cst,tin,taxtype,eccno,vendercode from buy where bcode ='$bcode' ") or die(mysql_error());
$row = mysql_fetch_row($result);
$custname = $row[0];
$address1=$row[1];
$address2=$row[2];
$city = $row[3];
$state=$row[4];
$pin =$row[5];
$cst=$row[6];
$tin=$row[7];
$taxtype=$row[8];
$eccno=$row[9];
$vendercode=$row[10];


$result = mysql_query("select description,tariff,tax,surcharge,ad_surcharge from salestax where taxtype ='$Tax' ") or die(mysql_error());;
$row = mysql_fetch_row($result);
$st_class=$row[0];
$st_type = $row[1];
$tax = $row[2];
$surcharge= $row[3];
$ad_surcharge=$row[4];	

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

<table width="900">
<tr><td width="413"><? echo($custname);?></td></tr>
<tr><td height="21"><? echo("'$address1'");echo(",$address2");?></td></tr>
<tr><td><? echo($city);echo(",$state");echo(",$pin");?></td></tr>
<tr><td> CST No&nbsp;&nbsp;:<? echo($cst);?></td><td width="440"> TIN No:&nbsp;&nbsp; <? echo($tin);?></td></tr>
<tr><td> ECC Code:&nbsp;&nbsp;<? echo($eccno);?></td><td width="440"> VENDER CODE:&nbsp;&nbsp; <? echo($vendercode);?></td></tr>
<tr><td><hr width="100%" color="#CC0000"></td><td><hr width="100%" color="#CC0000"></td></tr>
<tr><td> Invoice No:&nbsp;&nbsp; <input name="invno" value="<? echo($invno1);?>"></td><td>Date :&nbsp;&nbsp;
<input name="invdt" value="<? echo($invdt);?>"></td></tr>

<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td> Type of Sale:&nbsp; <? echo($typeofsale);?></td>
<td>Post duty in :&nbsp;<? echo($cexreg);?></td>
</tr>
<tr>
<td><hr width="100%" color="#CC0000" ></td>
<td><hr width="100%" color="#CC0000"></td>
</tr>
</table>
</table>
<table width="880">
<tr><td width="528" bgcolor="#999999">Product</td><td width="102" align="right">Qty</td><td width="95" align="right">Rate</td><td width="135" align="right">Value</td></tr>
<tr><td><hr width="100%" color="#CC0000"></td><td><hr width="100%" color="#CC0000"></td><td><hr width="100%" color="#CC0000"></td><td><hr width="100%" color="#CC0000"></td></tr>	
<?

for($ind=0;$ind<5;$ind++)
{
	if($qty[$ind]>0)
	{
		
		$result = mysql_query("select issued_qty,balance_qty,schedule_qty from orders where record = '$record[$ind]'") or die(mysql_error());
		$row = mysql_fetch_row($result);
		$issue_qty = $row[0];
		$balance_qty = $row[1];
		$schedule_qty = $row[2];
	
		$issue_qty = $issue_qty + $qty[$ind];
		$balance_qty = $balance_qty - $qty[$ind];
		
		
		
		if($balance_qty < 0)
		{
			echo("PENDING QTY : $row[1]<br>");
			echo("Invoice qty : $qty<br>");	
			echo("Sorry !  Entered Qty is more than Pending Qty. Please recheck and submit again;<br>");
			exit;
		}
	
		
		
		$result = mysql_query("select prodcode,drawing_no,order_no,order_date, issued_qty,balance_qty,rate from orders where record = '$record[$ind]' ") or die(mysql_error());
		$row = mysql_fetch_row($result);
		$prodcode=$row[0];
		$drawing_no = $row[1];
		$order_no=$row[2];
		$order_date=substr($row[3],8,2).'-'.substr($row[3],5,2).'-'.substr($row[4],0,4);
		$issued_qty=$row[4];
		$balance_qty=$row[5];
		$rate= $row[6];
		$order_no = $order_no.'&nbsp;&nbsp;'.$order_date;
		
	
	
		$result= mysql_query("select prodname,tariff from product where prodcode ='$prodcode' and bcode ='$bcode' ") or die(mysql_error());
		$row = mysql_fetch_row($result);
		$prodname = $row[0];
		$tariff=$row[1];
	
	
		$result = mysql_query("select commodity,notification,bed,aed,cess from excise where tariff='$tariff' ") or die(mysql_error());
		$row = mysql_fetch_row($result);
		$ex_commodity=$row[0];
		$notification = $row[1];
		$bed= $row[2];
		$hcess=$row[3];	
		$cess=$row[4];
		
		$result = mysql_query("select schedule_no,schedule_date from orders where record = '$record[$ind]' ") or die(mysql_error());
		$row = mysql_fetch_row($result);
		$schedule_no=$row[0];
		$schedule_date = $row[1];
		
		if(!empty($schedule_no))
		{
			$scn = 'Sch No:'. $schedule_no. 'Dt:&nbsp;'.substr($schedule_date,8,2).'-'.substr($schedule_date,5,2).'-'.substr($schedule_date,0,4);
		}
		else 
		{
			$scn=' ';
		}
		
		$ord_scd=$order_no.$scn;
		$value = $qty[$ind] * $rate;
	
		$totalvalue = $totalvalue  + $value;
		
		?>
		<tr><td bgcolor="#999999"><? echo($prodname);echo("&nbsp;&nbsp; Dr.No :&nbsp;&nbsp;"); echo($drawing_no);echo("&nbsp;&nbsp; Order No :&nbsp;&nbsp;");echo($scn);?></td>
		<td align="right" width="102"> <? echo($qty[$ind]);?></td>
		<td align="right"> <? echo(number_format($rate,2));?></td>
		<td align="right"> <? echo(number_format($value,2));?></td></tr>
	<input type="hidden" name="record1[<? echo($ind);?>]" value="<? echo($record[$ind]);?>">
		<input type="hidden" name="qty1[<? echo($ind);?>]" value="<? echo($qty[$ind]);?>">				
		<?
	}
}
	$pack_amt = $totalvalue * $packing_percentage/100;
	$assessable_value=$totalvalue+$pack_amt;
	$vat_app_value = $assessable_value;
	$vat_amt = $vat_app_value * $tax /100;
	
	$sum_amt = round($vat_app_value + $vat_amt+$transport_charges,2);
	$ceiled_amt = round($sum_amt,0);
	$difference  = $ceiled_amt - $sum_amt;
	
	
	
	?>


	<tr><td><hr width="100%" color="#CC0000"></td><td><hr width="100%" color="#CC0000"></td><td><hr width="100%" color="#CC0000"></td><td><hr width="100%" color="#CC0000"></td></tr>		

</table>
	<table width="894">
<tr><td width="733" align="right"> Packing Charges <? echo($packing_percentage);?>%</td><td width="135" align="right"> <? echo(number_format($pack_amt,2));?></td></tr>


<tr><td align="right"> Assessable Value </td><td align="right"> <? echo(number_format($vat_app_value,2));?></td></tr>
<tr><td align="right"> <? echo($st_class);?>&nbsp; <? echo($tax);?>%</td><td align="right"> <? echo(number_format($vat_amt,2));?></td></tr>
<tr><td align="right"> Transport Charges </td><td align="right"> <? echo(number_format($transport_charges,2));?></td></tr>
<tr><td align="right"> Total Amt  </td><td align="right"> <? echo(number_format($sum_amt,2));?></td></tr>
<tr><td align="right"> Round Off  </td><td align="right"> <? echo(number_format($difference,2));?></td></tr>
<tr><td align="right"> Grand Total  </td><td align="right"> <? echo(number_format($ceiled_amt,2));?></td></tr>
<tr><td><hr width="100%" color="#CC0000"></td><td><hr width="100%" color="#CC0000"></td><td width="10"><hr width="100%" color="#CC0000"></td></tr>	
<?
	$tax_rate = $tax;
	$tax_rate1 = $tax;
		if($typeofsale == 'STATE')
		{
			$sgst_amt = round($vat_amt/2,2);
			$cgst_amt = $sgst_amt;
			$igst_amt =0;
			$tax_rate = round($tax_rate/2,2);
		}
		if($typeofsale == 'INTERSTATE')
		{
			$igst_amt = round($vat_amt,2);
			$sgst_amt=0;
			$cgst_amt=0;
		}
		
if($sgst_amt >0)
{
	?>
<tr><td align="right"> SGST&nbsp;@&nbsp; <?=$tax_rate?>&nbsp;%=></td><td align="right"> <?=number_format($sgst_amt,2);?></td></tr>
<?
}
if($cgst_amt >0)
{
		?>
<tr><td align="right"> CGST&nbsp;@&nbsp; <?=$tax_rate?>&nbsp;%=></td><td align="right"> <?=number_format($cgst_amt,2);?></td></tr>
<?
}
if($igst_amt >0)
{
			?>
<tr><td align="right"> IGST&nbsp;@&nbsp; <?=$tax_rate?>&nbsp;%=></td><td align="right"> <?=number_format($igst_amt,2);?></td></tr>
<?
}

?>		
</table>

<table>
<tr><td>Rupees &nbsp;<? echo(connum($ceiled_amt));?></td></tr>
</table>
	
<table width="900">
	<tr><td><hr width="100%" color="#CC0000"></td><td><hr width="100%" color="#CC0000"></td><td><hr width="100%" color="#CC0000"></td></tr>
	<tr> <td width="339">&nbsp;</td>
	<td width="71" align="right" ><font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Confirm</b></font></td>
	<td width="474"> <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>  
</table>
	
  <table cellpading=0 cellspacing=10 width= 900>
    <tr> 
      
    <td width="457" align="right"> <blockquote> <input type =submit name="submit" value = "Submit"></td>
    <td width="367"></blockquote><td width="28"></td></tr>
  </table>		
<br><br><font size=1><center><a href= "index.html">Return to index page</a></center></font>
