<center><h2>RG-1</h2></center>
<form action="" method="post">
<table width="50%" border="0" align="center">
  <tr>
    <td>Branch :<?php  
 	$SQL_client=DB_query("SELECT loccode,prefix,locationname   from locations Where companyid='".$_SESSION['ACGCompanyId']."'",$db);
	?>
   <select  name="branch_name" style="width:143px; height:20px;"  onchange="ShowBranch(this.value)"  tabindex="1" >
   <option value="0" >--Branch Name--</option>
   <?php
	while($row_client=DB_fetch_array($SQL_client))
	{
	  $p='';
	  if($row_client['prefix']==$_SESSION['branch_name'])
	  $p="selected";
	 ?>
          <option value="<?php  echo $row_client['prefix']?>" <?php  echo $p; ?> >
          <?php  echo $row_client['locationname'];?>
          </option>
          <?php }?>
        </select>  </td>
    <td>Date :<input name="search_date" type="text" class="datepicker" id="search_date" style="width:90px"  tabindex="16"   value="<?php  echo $_SESSION['search_date']?>" size="15" /></td>
	    <td>Items :
		<?php 
 	 //$sql_stockmaster=db_query("select  distinct(B.productid),B.product_no ,C.cf_613 from xpert_inventoryproductrel A,xpert_products  B , xpert_productcf  C where   A.productid  =B.productid   and B.productid=C.productid and B.CompanyId ='".$_SESSION['ACGCompanyId']."'",$db );
	 $sql_stockmaster=db_query("select  * from item_master",$db );
 	   $numrow=db_num_rows($sql_stockmaster);

	?>
   <select  name="product_no" style="width:143px; height:20px;"  >
   <option value="0" >--Item Name--</option>
   <?php
	while($row_item=db_fetch_array($sql_stockmaster))
	{
	  $p='';
	  if($row_item['StockID']==$_SESSION['product_no'])
	  $p="selected";
	 ?>
          <option value="<?php  echo $row_item['StockID']?>" <?php  echo $p; ?> >
          <?php  echo $row_item['StockID']?>
          </option>
          <?php }?>
        </select>
		
		</td>  <td><input name="Search" value="Search" type="submit" /></td>
  </tr>
</table>

</form>

 <?php 
if($_REQUEST['Search']) 
{
   $_SESSION['branch_name']  =trim($_REQUEST['branch_name']) ; 
  $_SESSION['product_no']=trim($_REQUEST['product_no'])  ;
  $_SESSION['search_date']= trim($_REQUEST['search_date'])  ;
  	 $branchname=	$s->getFieldByCompanyId('locations','prefix',$_SESSION['branch_name'],'locationname',$_SESSION['ACGCompanyId']);
//$_SESSION['productid'] =getFieldCRM('xpert_products','product_no', $_SESSION['product_no'],'productid' );
//$_SESSION['product_shadename']=getFieldCRM('xpert_productcf','productid', $_SESSION['productid'],'cf_613' );

  $GetProductionFloor= "select * from production_floor where branch='". $_SESSION['branch_name']."' and companyid='".$_SESSION['ACGCompanyId']."'";
} 
else
{
  $GetProductionFloor= "select * from production_floor where companyid='".$_SESSION['ACGCompanyId']."'";
} 
?>


<table width="100%" border="0"> 
   <tr>
    <td  ><center><b> Form RG-1(Rules 53 and 173G) (<?php  echo  $_SESSION['search_date'];?>)</b></center></td>
  </tr>
   <tr>
    <td ><center> Item : <?php echo $_SESSION['StockID'].'&nbsp;&nbsp;'.$_SESSION['product_shadename']; ?>   </center></td>
  </tr>
  <tr>
  <td >
  <table width="100%" border="1" cellpadding="2" cellspacing="2">
  <tr>
	<td>Date</td>
	<td>Opening<br>Bal.</td>
	<td>Qty<br>MFD</td>
	<td>Total</td>
	<td>No</td>
	<td>For Home Use(Duty)</td>
	<td>Export Duty</td>
	<td>WitdOut Payment of Duty</td>
	<td>Duty</td>
	<td>C.Cess</td>
	<td>H.Cess</td>
	<td>Total</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><table width="100%" >
      <tr>
        <td width="50%"><div align="center">Qty</div></td>
        <td  width="50%"><div align="center">Value</div></td>
      </tr>
    </table></td>
    <td><table width="100%" >
      <tr>
        <td width="50%"><div align="center">Qty</div></td>
        <td  width="50%"><div align="center">Value</div></td>
      </tr>
    </table></td>
    <td><table width="100%" >
      <tr>
        <td><div align="center">Export</div></td>
        <td><div align="center">Orders</div></td>
		<td><div align="center">Reprocess Issue</div></td>
		<td><div align="center">Reprocess Rec.</div></td>
      </tr>
    </table></td>
	
	
	 <td><table width="100%" >
      <tr>
        <td width="50%"><div align="center">Qty</div></td>
        <td  width="50%"><div align="center">Value</div></td>
      </tr>
    </table></td>

 <td><table width="100%" >
      <tr>
        <td width="50%"><div align="center">Qty</div></td>
        <td  width="50%"><div align="center">Value</div></td>
      </tr>
    </table></td> <td><table width="100%" >
      <tr>
        <td width="50%"><div align="center">Qty</div></td>
        <td  width="50%"><div align="center">Value</div></td>
      </tr>
    </table></td>
 <td><table width="100%" >
      <tr>
        <td width="50%"><div align="center">Closing</div></td>
        <td  width="50%"><div align="center">Signature</div></td>
      </tr>
    </table></td>
  </tr>
  
 <?php
 //echo "select * from production_floor where branch='".$_SESSION['branch_name']."' and CompanyId='".$_SESSION['ACGCompanyId']."' and item_id='".$_SESSION['productid'] ."' order by id desc limit 1";
 $chk_floor=DB_query("select * from production_floor where branch='".$_SESSION['branch_name']."' and CompanyId='".$_SESSION['ACGCompanyId']."' and item_id='".$_SESSION['productid'] ."' order by id desc limit 1",$db);
  $numrows_chk_floor = DB_num_rows($chk_floor);
if($numrows_chk_floor >0)
{
  $row_floor=DB_fetch_array($chk_floor);
  $balanceqty= $row_floor['balanceqty'];
}
//$result_ProductionFloor=DB_query($GetProductionFloor,$db);
//$j=1;
// while( $row_ProductionFloor=DB_fetch_array($result_ProductionFloor))
 //{
 ?>
  <?php 
//	$stockqty= $s->getField('production_floor','item_id',$productid,'stockqty'); 

 
if($_REQUEST['Search']) 
{
	  // $branch  =$_REQUEST['branch_name']  ;
	  // $productno=$_REQUEST['productno']  ;   //shadename
	  // $search_date= ConvertSQLDate( $_REQUEST['search_date']) ;
	//  echo  $shadeid= getFieldCRM('xpert_productcf','productid',$productid,'cf_613'); and B.shade_name='".$_SESSION['product_shadename']."' and B.shade_name='".$shadeid."'
 
 
 
  	$cond="A.invoice_status='Y' and A.CompanyId='".$_SESSION['ACGCompanyId']."' and     A.branch_name='".$_SESSION['branch_name']."' ";
  	
   $GetRecord= "select * from invoice A JOIN invoice_details B on A.invoice_id=B.invoiceid JOIN invoice_tracking C on B.invoiceid=C.invoice_id where   A.invoice_status='Y' and $cond group by C.issue_stock ";

} 
else
{ 
// $shadeid= getFieldCRM('xpert_productcf','productid',$row_ProductionFloor['item_id'],'cf_613'); 

	$cond="A.invoice_status='Y' and A.CompanyId='".$_SESSION['ACGCompanyId']."' ";
	 $GetRecord= "select * from invoice A,invoice_details B where A.invoice_id=B.invoiceid and $cond";
	
		
}
$result=DB_query($GetRecord,$db);
   $numrows = DB_num_rows($result);  
if($numrows>0)
{
   $i=1;
   $total_duty=array();
      $total_CCess=array();
	     $total_HCess=array();
  while( $row=DB_fetch_array($result))
 {
  if($i%2==0)
  $bg="bgcolor='#CCCCCC'";
  else
  $bg="bgcolor='#FFFFFF'";
  
  
 
				 
   ?>
  <tr  align="left" <?php  echo $bg?>>
    <td align="left"> <?php echo   $row['id'].'--'.$row['invoice_date'];	 ?></td>
	<td><?php echo $row['opening_balance']	?></td>
	<td><?php  
	//echo "<pre>";
	// print_r($_SESSION['invoice_ids']);	?>&nbsp;</td>
	<td><?php echo $row['opening_balance']	?></td>
	<td><?php echo  $row['shade_name'];?></td>
	<td><table width="100%" >
        <tr>
          <td width="50%"><?php echo  $row['qty'];?></td>
           <td width="50%">&nbsp;</td>
        </tr>
      </table></td>
	<td><table width="100%" >
        <tr>
          <td><?php  ?></td>
          <td>&nbsp;</td>
        </tr>
      </table></td>
	<td><table width="100%" >
        <tr>
          <td><?php  ?></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table></td>
	<td><table width="100%" >
        <tr>
          <td><?php echo  $row['excise_duty'];
		   $total_duty[]= $row['excise_duty'];
		  	 ?></td>
          <td>&nbsp;</td>
        </tr>
      </table></td>
	<td><table width="100%" >
        <tr>
          <td><?php echo  $row['she_cess'];	
		    $total_CCess[]= $row['she_cess']; ?></td>
          <td>&nbsp;</td>
        </tr>
      </table></td>
	<td><table width="100%" >
        <tr>
          <td><?php echo  $row['edu_cess'];	
		    $total_HCess[]= $row['edu_cess'];
		   ?></td>
          <td>&nbsp;</td>
        </tr>
      </table></td>
	<td><table width="100%" >
        <tr>
          <td><?php echo     $row['closing_balance']	 ;	 ?></td>
          <td>&nbsp;</td>
        </tr>
      </table></td></tr>
 <?php } 
 
  ?>
  
  <tr  align="left"  bgcolor="#999999" >
    <td align="left">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp; </td>
    <td>&nbsp; </td>
    <td>Total:</td>
    <td><table width="100%" >
      <tr>
        <td><?php 
		 
		echo  array_sum ($total_duty) ;	 ?></td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
    <td><table width="100%" >
      <tr>
        <td><?php echo  array_sum ($total_CCess) ;	 ?></td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
    <td><table width="100%" >
      <tr>
        <td><?php echo   array_sum($total_HCess) ;	 ?></td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
    <td><table width="100%" >
      <tr>
        <td>&nbsp; </td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr><td colspan="12"> 
  
  <a href="Download_CompaintReport.php"><input name="Download" type="submit" value="Download" /></a> </td></tr>
  <?php }
  else
 {
 ?>
  <tr><td colspan="12">No Record</td></tr>
 <?php 
 }?>
</table>



   
  
  
  
  
  </td>
  </tr>
</table>
