<?php 
$countdata=$_REQUEST['count'];
for($i=0;$i<$countdata;$i++)
{
$update12=DB_query("update addmrnqty set rejectqty='".$_REQUEST['reject_qty'][$i]."' where id='".$_REQUEST['mrnid_data'][$i]."'" ,$db);	
$sql="insert into goods_incoming_inspection set mrn_no='".$_REQUEST['mrn_no'][$i]."',mrn_date='".$_REQUEST['mrn_date'][$i]."',mrn_doc='".$_REQUEST['mrn_doc'][$i]."'
       ,party_name='".$_REQUEST['party_name'][$i]."',party_invoice_no='".$_REQUEST['party_invoice'][$i]."',party_invoice_date='".$_REQUEST['party_invoice_date	'][$i]."'
       ,against_order_no='".$_REQUEST['order_no'][$i]."' ,store_location='".$_REQUEST['store_loc'][$i]."',part_code='".$_REQUEST['part_code'][$i]."'
       ,material_desc='".$_REQUEST['mat_des'][$i]."',bill_qty='".$_REQUEST['bill_qty'][$i]."',recived_qty='".$_REQUEST['rec_qty'][$i]."'
       ,short_qty='".$_REQUEST['short_qty'][$i]."',rejected_qty='".$_REQUEST['reject_qty'][$i]."',total_qty='".$_REQUEST['total_qty'][$i]."',branch='".$_REQUEST['Branch'][$i]."'";
//$query=DB_query($sql,$db);
if($_REQUEST['reject_qty'][$i]!='0.00')
{
 $update="update addmrn set qc_status='1' where id='".$_REQUEST['mrnid'][$i]."'";	
 $update1=DB_query($update,$db);	
}
}
?>

<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.mrp-haiding{
		font:16px Georgia, "Times New Roman", Times, serif;
		color:#000;
		font-weight:bold;
}
.search-haiding{
		font:14px Georgia, "Times New Roman", Times, serif;
		color:#000;
		font-weight:bold;
}
.text{
		font:12px Georgia, "Times New Roman", Times, serif;
		color:#000;
}
.text-table{
		font:12px Georgia, "Times New Roman", Times, serif;
		color:#fff;
		padding-left:12px;
}
.border-table{
		border:1px solid #dedede;
}
.scroll{
		margin:0px;
		padding:0px;
		overflow:scroll;
		width:988px;
		height: 300px;		
}
-->
</style>
<table  border="0" align="center" cellpadding="0" cellspacing="0">
 <tr><td>&nbsp;</td></tr>
  <tr><td align="left" valign="top">
    <fieldset>
    <legend class="search-haiding">Goods Incoming Inspection</legend>
    <table  border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>&nbsp;</td>
      </tr> 
      <tr>
        <td align="left" valign="top">
        <form action=""  method="post">	
        	<table  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="81" align="left" valign="top" class="text">From Date :</td>
            <td width="113" align="left" valign="top">
              <input type="text" name="from_date"  id="from_date" class="datepicker" value="<?php echo $_REQUEST['from_date']; ?>"/></td>
            <td width="64" align="left" valign="top" class="text">To Date :</td>
            <td width="124" align="left" valign="top"><input type="text" name="to_date"  id="to_date" class="datepicker" value="<?php echo $_REQUEST['to_date']; ?>"/></td>
            <td width="60" align="left" valign="top" class="text">Branch :</td>
            <td width="331" align="left" valign="top"><select name="site" id="site" >
            <option value="000">Select Branch</option>
     <?php  $site_sql = "SELECT prefix,loccode, locationname from locations";$site_result = DB_query($site_sql,$db);
		while($site_row = DB_fetch_array($site_result))	{	?>
         <option value="<?php echo $site_row['locationname']; ?>" <?php if($_REQUEST['site']==$site_row['locationname']){ ?> selected="selected" <?php }?>><?php echo $site_row['locationname']; ?></option>
       <?php } ?>
   </select></td> 
     <td  width="250"  align="left" valign="top"><input type="submit" name="Search" value="Search" /></td>
      </tr>
        </table></form></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><form action="" method="post">
        	<div class="scroll">
        	<table width="988" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
            <td><table width="1812" border="0" cellpadding="0" cellspacing="0">
              <tr class="text-table">
              <th  width="201" height="40" align="left">Mrn No.</th>
                <th  width="105" align="left">MRN Date</th>
                <th  width="81" align="left">MRN Doc</th>
                <th  width="139" align="left">Party Name</th>
                <th  width="172" align="left">Party Invoice No.</th>
                <th  width="140" align="left">Party Invoice Date</th>
                <th  width="140" align="left">Against Order No.</th>
                <th  width="121" align="left">Store Location</th>
                <th  width="85" align="left">Part Code</th>
                <th  width="204" align="left">Material Description</th>
                <th  width="80" align="left">Bill QTY</th>
                <th  width="113" align="left">Received QTY.</th>
                <th  width="104" align="left">Short QTY.</th>
                <th  width="144" align="left">Rejected QTY.</th>
                <th  width="144" align="left">Total QTY.</th>
                <th  width="40" align="left">Branch</th>
                </tr>                
               <?php  
	               if(isset($_POST['Search']))
				   {    	
	                $fordate = $_POST['from_date'];
					$todate = $_POST['to_date'];
					$fromdate = explode("/", $fordate);
					$daydate = $fromdate['0'];
					$Monthdate = $fromdate['1'];
					$yeardate = $fromdate['2'];
					$fdate = $yeardate."-".$Monthdate."-".$daydate;					   
					$tredate   = explode("/", $todate);
					$dayda     = $tredate['0'];
					$Monthda   = $tredate['1'];
					$yearda    = $tredate['2'];
					$toyrdate  = $yearda."-".$Monthda."-".$dayda;
					$filter = array();	
				if($_REQUEST['from_date'] != '' && $_REQUEST['to_date'] != '')
 	            $filter[]="addmrn.MRNVoucherDate between '".$fdate."' and '".$toyrdate."'";
 	            if($_REQUEST['site']!='000')
	            $filter[]="addmrn.site_name='".$_REQUEST['site']."' ";  
				if($filter != '')	{
		        $filter1 = implode(" and ",$filter);
		if($_REQUEST['site']!='000' || $_REQUEST['from_date']!='' || $_REQUEST['to_date']!='')
		{
		 $sql = "select addmrn.*, addmrnqty.* from addmrn inner join addmrnqty on(addmrn.id = addmrnqty.issue_id) where addmrn.qc_status='0' and $filter1 group by addmrn.id";
		}
		else
		{
		$sql = "select addmrn.*, addmrnqty.* from addmrn inner join addmrnqty on(addmrn.id = addmrnqty.issue_id) where addmrn.qc_status='0' "; 
		}
		}
	    else
	  	{  
	    $sql="select addmrn.*, addmrnqty.* from addmrn inner join addmrnqty on(addmrn.id = addmrnqty.issue_id) where addmrn.qc_status='0'";
		}
			   $i=0;    
               $sql1=DB_query($sql,$db);
               $num=DB_num_rows($sql1);
			   if($num>0)
			   {
               while($data=DB_fetch_array($sql1))
			   {
               ?> 
              <tr>
                <td align="left" valign="top">&nbsp;
                <input type="hidden" name="mrnid[<?php echo $i;?>]"  value="<?php echo $data['issue_id']; ?>" />
                <input type="hidden" name="mrnid_data[<?php echo $i;?>]"  value="<?php echo $data['id']; ?>" />
                <input type="hidden" name="mrn_no[<?php echo $i; ?>]" value="<?php echo $data['MRNNo']; ?>" ><?php echo $data['MRNNo']; ?> </td>
                <td align="left" valign="top"><input type="hidden" name="mrn_date[<?php echo $i; ?>]" value="<?php echo $data['MRNDate']; ?>"><?php echo $data['MRNDate']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="mrn_doc[<?php echo $i; ?>]" value="<?php echo $data['DocumentType']; ?>"><?php echo $data['DocumentType']; ?></td>
                <td align="left" valign="top"><?php $vendor=$s->getField('suppliers','vendor_code',$data['ReceivedFrom'],'vendor_name'); ?>
                <input type="hidden" name="party_name[]" value="<?php echo $data['ReceivedFrom']; ?>"><?php echo $vendor; ?></td>
                <td align="left" valign="top"><input type="hidden" name="party_invoice[<?php echo $i; ?>]" value="<?php echo $data['PO_WO_MTO']; ?>"><?php echo $data['PO_WO_MTO']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="party_invoice_date[<?php echo $i; ?>]" value="<?php echo $data['OrderDate']; ?>"><?php echo $data['OrderDate']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="order_no[<?php echo $i; ?>]" value="<?php echo $data['order_no']; ?>"><?php echo $data['order_no']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="store_loc[<?php echo $i; ?>]" value="<?php echo $data['StoreName']; ?>"><?php echo $data['StoreName']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="part_code[<?php echo $i; ?>]" value="<?php echo $data['itemcode']; ?>"><?php echo $data['itemcode']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="mat_des[<?php echo $i; ?>]" value="<?php echo $data['description']; ?>"><?php echo $data['description']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="bill_qty[<?php echo $i; ?>]" value="<?php echo $data['qty_as_per_bill']; ?>"><?php echo $data['qty_as_per_bill']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="rec_qty[<?php echo $i; ?>]" id="rec_qty_<?php echo $i; ?>" value="<?php echo $data['reciveqty']; ?>"><?php echo $data['reciveqty']; ?></td>
                <td align="left" valign="top"><input type="hidden" name="short_qty[<?php echo $i; ?>]" id="short_qty_<?php echo $i; ?>" value="<?php echo $data['short_accessid']; ?>"><?php echo $data['short_accessid']; ?></td>
                <td align="left" valign="top"><input type="text" name="reject_qty[<?php echo $i; ?>]" id="reject_qty_<?php echo $i; ?>"  value="0.00" ></td>
                <td align="left" valign="top"><input type="text" name="total_qty[<?php echo $i; ?>]" id="total_qty_<?php echo $i; ?>" value="" onfocus="calqty(<?php echo $i; ?>);"></td>
                <td align="left" valign="top"><input type="hidden" name="Branch[]" value="<?php echo $data['site_name']; ?>"><?php echo $data['site_name']; ?></td>
                </tr><?php $i++; }} else { ?>
                 <tr><td colspan="15" align="center"><?php echo "No Records Found"; ?></td><?php  } } ?><input type="hidden" name="count" value="<?php echo $i; ?>" />
              </table></td>
          </tr>
                   
        </table>
       
        </div><p align="center"><input type="submit" name="Save" value="Save" /></p></form></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      </table>  
       
    </fieldset>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

<script language="JavaScript">
function calqty(str)
{	
var shortqty=document.getElementById("rec_qty_"+str).value;
var rejectqty=document.getElementById("reject_qty_"+str).value;
var total=parseFloat(shortqty)-parseFloat(rejectqty);
document.getElementById("total_qty_"+str).value=total.toFixed(2);	
}	
	
	
	
	
</script>


