<?php
$PageSecurity = 11;
include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/function_lib.php');
   
//echo "Select againstSOP from dispatch where id='".$_REQUEST['dispatchNum']."'";

		?>
  <div style="overflow:auto; width:800px" >
 <table width="100%" border="0" cellspacing="2" cellpadding="2" class="maintable" align="center" >
   <tr>
        <th>SNo. </th>
        <th>Mrn No.</th>
        <th>Item Name
         <label><font color="#FF0000">*</font></label>        </th>
        <th nowrap="nowrap"> Description
          <label><font color="#FF0000">*</font></label></th>
        <th>Unit</th>
        <th>No &amp; Description of Packaging(Box Details)
          <label><font color="#FF0000">*</font></label></th>
        <th> Quantity
          <label><font color="#FF0000">*</font></label></th>
        <th>Purchase Rate</th>
        <th>Total Bill Amt.</th>
        <th>Sale Qty</th>
        <th>Sale Rate </th>
        <th>Total Sale Amt.</th>
        <th>Discount</th>
         <th>Discounted Amount</th>
        <th>Total Discounted </th>
        <th>EDRate</th>
        <th>EDAmount</th>
      </tr>
	 <?php
	 $ordernodata=$s->getField('addmrn','id',$_REQUEST['dispatchNum'],'PO_WO_MTO');
	 
	 
	 
	  
   	 $detail_sql="Select * from addmrnqty where issue_id='".$_REQUEST['dispatchNum']."' and reciveqty!='0'";
	 $detail_result=DB_query($detail_sql,$db);
	 $i=0;
	 while($detail_row=DB_fetch_array($detail_result))
	 {
	 $podetails=DB_query("select Excise_Duty from purchorderdetails where orderno='".$ordernodata."' and mst_itemid='".$detail_row['mst_itemid']."'",$db);	
	 $podetailsdata=DB_fetch_array($podetails);
	// echo "Select * from salesorder_details where masterId='".$detail_row['SOPNo']."' and ItemCode='".$detail_row['item']."'";
	 	//$prod_dispatch_details="Select * from salesorder_details where masterId='".$detail_row['SOPNo']."' and ItemCode='".$detail_row['item']."'";		
	 	//$prod_dispatch_result=DB_query($prod_dispatch_details,$db);
		//$prod_dispatch_row=DB_fetch_array($prod_dispatch_result);
		//echo "Select item_name, unit from item_master where id='".$detail_row['item']."'";
 	 	$item_sql=DB_query("Select item_name, unit from item_master where id='".$detail_row['mst_itemid']."'",$db);
		$item_row=DB_fetch_array($item_sql);
 	 ?>       
      <tr bgcolor="#FFFFFF">
      <td><?php echo $i+1;?></td>
      <td><input type="hidden" name="saleOrderNo[<?php echo $i;?>]" id="" value="<?php echo $detail_row['SOPNo'];?>" /><?php 
      echo $SOPCode=$s->getField('addmrn','id',$detail_row['issue_id'],'MRNNo');
      ?></td>
      <td><?php   echo $s->GetFieldValue('item_master',"id='".$detail_row['mst_itemid']."'",'item_name');
	  ;?><input type="hidden" name="ItemCode[<?php echo $i;?>]" value="<?php echo $detail_row['mst_itemid'];?>" /></td>
      <td><?php echo $item_row['item_name'];
	 
	  
	  ?></td>
      <td><?php echo $unitname=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');?></td>
      <td><input type="text" name="PackageDesc[<?php echo $i;?>]" value="<?php echo $detail_row['boxDetails'];?>" size="20" /></td>
      <td><input type="text" name="Quantity[<?php echo $i;?>]" id="Quantity_<?php echo $i;?>" value="<?php echo $detail_row['reciveqty'];?>" size="15" readonly />
	  </td>
      <td><input type="text" name="RatePerThousand[<?php echo $i;?>]"  id="RatePerThousand_<?php echo $i;?>" value="<?php echo $detail_row['itemprice'];?>" size="22" readonly /></td>
      <td><input type="text" name="Amount[<?php echo $i;?>]" id="Amount_<?php echo $i;?>" value="<?php echo $detail_row['item_total_rate'];?>" size="15" onfocus="calculateAmount(<?php echo $i;?>)"/></td>      
     <td><input type="text" name="saleqty[<?php echo $i; ?>]" id="saleqty_<?php echo $i; ?>"   /></td>
       <td><input type="text" name="salerate[<?php echo $i; ?>]" id="salerate_<?php echo $i; ?>" value=""  onchange="calsaleamount(<?php echo $i; ?>)"/></td>
     <td><input type="text" name="totalsalerate[<?php echo $i; ?>]" id="totalsalerate_<?php echo $i; ?>"  /></td>
     <td>
	 <select name="discountType[<?php echo $i;?>]" id="discountType_<?php echo $i;?>" style="width: 98%">
	<option value="A"<?php echo ($prod_dispatch_row['DiscountType']=='A'?'selected':'')?>>Amount</option>
	<option value="P"<?php echo ($prod_dispatch_row['DiscountType']=='P'?'selected':'')?>>Percent</option>
    </select>
	</td>
	<td>
<input type="text" name="discount[<?php echo $i;?>]" id="discount_<?php echo $i;?>" value="<?php echo $prod_dispatch_row['Discount']?>" size="15" onblur="calculateDiscount(this.value,<?php echo $i;?>)" /></td>
<td><input type="text" name="valueAfterDisc[<?php echo $i;?>]" id="valueAfterDisc_<?php echo $i;?>" value="" size="15" readonly/></td>
      
      <td><select name="EDRate[<?php echo $i;?>]" id="EDRate_<?php echo $i?>" style="width:107px" 
		onchange="ShowDiv(this.value,'hid_ED_div_<?php echo $i?>','calculateExcise.php?type=TELORD&i=<?php echo $i;?>&amount='+document.getElementById('valueAfterDisc_<?php echo $i;?>').value)">
    		<option value="0">--Select--</option>
    		<?php
    		$ServiceSql="select * from  excise_tax WHERE caption LIKE '%excise%'" ;
			$ServiceRes=DB_query($ServiceSql,$db);
			while($ServiceRow=DB_fetch_array($ServiceRes))
			{
			$p='';	
			if($ServiceRow['id']==$podetailsdata['Excise_Duty'])
			{
			$p="select";	
			}	
			?>
		  <option value="<?php echo $ServiceRow['id']?>" <?php echo $p1; ?>><?php echo $ServiceRow['caption']?>
		  </option>
			<?php	
			}
    		
    		?>
    		</select>
		 
 		 <!--<input type="text" name="HidRate[<?php echo $i;?>]" id="HidRate_<?php echo $i;?>" value="<?php  echo $s->getField('excise_tax','id',$detail_row['EdRate'],'id');?>"   />-->
		 </td>
	  <td>
		 <div id='hid_ED_div_<?php echo $i?>'>  
 		<input type="text" name="EDamount[<?php echo $i;?>]" id="EDAmt_<?php echo $i;?>" value="<?php echo $detail_row['EDamount']; ?>" />
		</div>
		</td>
    </tr>
	<?php $i++; } ?>
	
<input name="rowcount" id="rowcount" 	type="hidden" value="<?php echo $i;?>" />
	
  </table> </div>
