<table align="center" width="100%">
<tr><th style="text-align:center;" colspan="11">Item Details</th></tr>
<tr>
<th>Item Code</th>
<th>Item Name</th>
<th>Unit</th>
<th>Qty</th>
<th>Price</th>
<th>Per Unit(s)</th>
<th>Value</th>
<th>Discount Type</th>
<th>Discount</th>
 <th>Total</th>
</tr>
	<?php $total=0; 
	$i=0;$after_discount=0;
	$getitem=DB_query("select * from crm_lead_items where mst_leadid='".$_REQUEST['q']."' ",$db); 
    while($row=DB_fetch_array($getitem))
 	{
  	 $itemquery=DB_query("select * from item_master where id='".$row['item_code']."'" , $db);
 	while($item_row=DB_fetch_array($itemquery))
	{
		if($i%2==0)
		{$bg="#CCCCCC";}
		else
		$bg="#C8BECB";
	
	?>
	
	<tr bgcolor="<?php echo $bg;?>">
  
    <td><?php echo $row['item_code'];?><input type="hidden" name="item_code[<?php echo $i;?>]" id="item_code_<?php echo $i;?>" value="<?php echo $row['item_code'];?>">	</td>
   <td><?php echo $item_row['item_name'];?><input type="hidden" name="item_name[<?php echo $i;?>]" id="item_name[<?php echo $i;?>]" value="<?php echo $item_row['item_name'];?>"/>	</td>
   <td><?php		$grade_query=DB_query("select * from unitsofmeasure where unitid='".$item_row['unit']."'", $db);
		while($grade_row=DB_fetch_array($grade_query))
		 {
		 echo $grade_row['unitname'];?>
		<?php } ?><input type="hidden" name="Unit[<?php echo $i;?>]" id="Unit[<?php echo $i;?>]" value="<?php $grade_row['id'];?>"/>			</td>
    <td><input type="text" name="stock_qty[<?php echo $i;?>]" id="stock_qty_<?php echo $i;?>" style="width:80px;"  value="<?php echo $row['stock_qty'];?>" readonly="true"/></td>
    <td><input type="text" name="stock_price[<?php echo $i;?>]" id="stock_price_<?php echo $i;?>" style="width:60px;" value="<?php echo $row['stock_price'];?>" readonly="true" /></td>
    <td><input type="text" name="stock_perunit[<?php echo $i;?>]" id="stock_perunit_<?php echo $i;?>" style="width:50px;" value="<?php echo $row['stock_perunit'];?>" readonly="true"/></td>
    <td><input type="text" name="stock_value[<?php echo $i;?>]" id="stock_value_<?php echo $i;?>" style="width:50px;" value="<?php echo $row['stock_value'];?>" readonly="true"/></td>
     
	 
	 <td><select   name="discountType[<?php echo $i;?>]" id="discountType_<?php echo $i;?>"  style="width: 98%">
         <option value="A">Amount</option>
         <option value="P">Percent</option>
       </select></td>

<td>
<?php  $total+=$row['discount'];
$after_discount+=$row['stock_value']-$row['total_stock'];
 ?>
<input type="text" name="discount[<?php echo $i;?>]" id="discount_<?php echo $i;?>" style="width:50px;"   /></td>
 
<td><input type="text" onfocus="ValueAfterDiscount(<?php echo $i;?>)"  name="valueAfterDisc[<?php echo $i;?>]" id="valueAfterDisc_<?php echo $i;?>" size="15"/></td>
   
</tr>

   
  
  <?php } 
    $i++;
  }?>
</table>
 
<input type="hidden" name="itemcount_totalamt" id="itemcount_totalamt" value="<?php echo $total;?>" />
<input type="hidden" name="itemcount_AfterDisc" id="itemcount_AfterDisc" value="<?php echo $after_discount;?>" />

<input type="hidden" name="hiditemcount" id="hiditemcount" value="<?php echo $i;?>" />

<br>
<br>
 
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="50%">&nbsp;</td>
<td valign="top">
<table width="90%" border="0" cellspacing="1" cellpadding="0" align="right" bgcolor="#FFFFFF" style="border:1px solid #ccc;">
    		<tr>
    	<th style="text-align:center;" colspan="2">Amount And Taxes</th>
    </tr>
    <tr>
   	    <tr>
    	    <th>Basic Amount<label><font color="#FF0000">*</font></label></th>
    	    <td><input name="basicAmount" type="text" value="<?php echo $basicAmount;?>" style="width:auto;" onfocus="calculateBasic()" id="basicAmount"   /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th nowrap="nowrap">Discounted Price<label><font color="#FF0000">*</font></label></th>
    	    <td><input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text" value="<?php echo $totalDiscountedPrice!=''?$totalDiscountedPrice:0;?>" style="width:auto;" onfocus ="calculateDiscounted()"/>
			
			
			</td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Excise</th>
    	    <td>
    	    <select name="exciseDuty" style="width:107px;" onchange="claculateExcise(this.value)">
    	    <option value="0">Select</option>
    	    <?php 
    	    $excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Sales'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['id'];?>"><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select><div id="exciseId"><input name="exciseValue" id="exciseValue" type="text" value="<?php echo $exciseValue;?>" style="width:auto;" /></div>
   	    </tr>
    	     
    	     <?php 
    	     $cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			 $k=1;
			 while($cessRow=DB_fetch_array($cessSql))
			 {
			 	$caption[$k]=$cessRow['caption']; 
				
				$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
				while($rate_row=DB_fetch_array($rate_sql))
				{
					$rate[$k]=$rate_row['def_rate'];
				}
				$k++;
			 } 
    	     ?>
    	     <tr>
    	    <th>E-Cess</th>
    	    <td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" style="width:auto;" readonly />
    	    	<input name="ECessValue" id="ECessValue" type="text" value="<?php echo $ECessValue?>" style="width:auto;" readonly onfocus="calculateECess()"/></td>
    	    </tr>
    	    <tr>
            <th nowrap="nowrap">SAH-E Cess </th>
    	    <td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" style="width:auto;" readonly/>
    	    	<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $SAHCessValue?>" style="width:auto;" readonly onfocus="calculateSAHCess()"/></td>
  	    	</tr>
    	  
    	  
   <tr>
   	<th>Taxable Amount<label><font color="#FF0000">*</font></label></th>
   	<td><input name="taxableAmount" id="taxableAmount" type="text" value="<?php echo $taxableAmount?>" style="width:auto;" onfocus="calculateTaxable()"/></td>
   </tr>
    	  
    	  
    	  
    	  <tr>
    	    <th>VAT/CST</th>
    	    <td>
    	    <select name="VatCst" id="value3" style="width:107px;" onchange="calculateVATCST(this.value)">
    	    <option value="" style="width:auto;">Select</option>
    	    <?php 
    	    $salesSql=DB_query("Select * from sales_tax_master",$db);
			while($salesRow=DB_fetch_array($salesSql))
			{?>
				<option value="<?php echo $salesRow['salestax_id'];?>" <?php echo $VatCst==$salesRow['salestax_id']?'selected':''?>><?php echo $salesRow['tax_code'];?></option>
			<?php 	
			}
    	    ?>
  	      </select>
    	      <div id="VATId"> <input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $VatCstValue?>" style="width:auto;" readonly /></div></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Freight</th>
    	    <td><input name="freightValue" id="value2" type="text" value="<?php echo $freightValue?>" style="width:auto;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Pkg Charges</th>
    	    <td><input name="packagingCharges" id="value1" type="text" value="<?php echo $packagingCharges;?>" style="width:auto;" /></td>
    	    
  	    </tr>
  	    <tr>
    	    <th>Additional Charges</th>
    	    <td><input name="additionalCharges" id="value4" type="text" value="<?php  echo $additionalCharges;?>" style="width:auto;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Round Off</th>
    	    <td><input name="roundOff" id="roundOff" readonly="true" type="text" value="<?php echo $roundOff;?>" style="width:auto;" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Grand Total<label><font color="#FF0000">*</font></label></th>
    	    <td><input name="grandTotal" id="grandTotal" type="text"  style="width:auto;" onfocus="calculateGrand()" readonly="readonly" value="<?php echo $grandTotal  ;?>" /></td>
    	    
  	    </tr>
      </table>
</td>
</tr></table>
<p align="center"><input type="submit" name="Save" value="Save"  /></p>
<script type="text/javascript" language="javascript">
function calculateECess(str)
{
 	var exciseValue=document.getElementById("basic"+str).value;
	var ECessPercentage=document.getElementById("rate_"+str).value;
	var total=exciseValue*(ECessPercentage/100);
	document.getElementById("caption_value_"+str).value=total.toFixed(2);
 }
 
 
 

 
</script>

	