<link rel="stylesheet" href="css/new_mxerp.css">
<div class="tab_div">
<center> <h2>Goods Incoming Inspection Reports</h2></center>
<div id="container">
<form action=""  method="post">	
<table  border="0" cellspacing="0" cellpadding="3" width="100%">
          <tr class="row1">
		  <td width="13%" align="left" valign="top" class="text"><strong>From Date :</strong></td>
            <td width="20%" align="left" valign="top">
            <input type="text" name="from_date" style="width:100%;" id="from_date" class="datepicker" value="<?php echo $_REQUEST['from_date']; ?>"/></td>
            <td width="13%" align="left" valign="top" class="text"><strong>To Date :</strong></td>
            <td width="20%" align="left" valign="top"><input type="text" name="to_date"  id="to_date" class="datepicker" value="<?php echo $_REQUEST['to_date']; ?>" style="width:100%;"/></td>
            <td width="13%" align="left" valign="top" class="text"><strong>Branch :</strong></td>
            <td align="left" valign="top"><select name="site" id="site" style="width:100%;">
             <option value="0">Select Branch</option>
     <?php 	   $site_sql = "SELECT prefix,loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
     $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> 
            
          </tr>
		  <tr class="row1"><td colspan="6" align="center" style="text-align:center;"><input type="submit" name="Search" value="Search" class="search" /></td>
		  </tr>
		  <tr class="row1">
		  <td colspan="6" align="left" style="padding:0px;">
		  <div style="width:980px; overflow:auto;">
		  <table width="1812" border="0" cellpadding="0" cellspacing="0">
              <tr class="row1">
                <td  width="201" height="40" align="left"><strong>Mrn No.</strong></td>
                <td  width="105" align="left"><strong>MRN Date</strong></td>
                <td  width="81" align="left"><strong>MRN Doc</strong></td>
                <td  width="139" align="left"><strong>Party Name</strong></td>
                <td  width="172" align="left"><strong>Party Invoice No.</strong></td>
                <td  width="140" align="left"><strong>Party Invoice Date</strong></td>
                <td  width="140" align="left"><strong>Against Order No.</strong></td>
                <td  width="121" align="left"><strong>Store Location</strong></td>
                <td  width="85" align="left"><strong>Part Code</strong></td>
                <td  width="204" align="left"><strong>Material Description</strong></td>
                <td  width="80" align="left"><strong>Bill QTY</strong></td>
                <td  width="113" align="left"><strong>Received QTY.</strong></td>
                <td  width="104" align="left"><strong>Short QTY.</strong></td>
                <td  width="144" align="left"><strong>Rejected QTY.</strong></td>
                <td  width="144" align="left"><strong>Total QTY.</strong></td>
                <td  width="40" align="left"><strong>Branch</strong></td>
                </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']!='')
	                $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='1' 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='1' "; 
		}
		}
	     else
	  	{  
	    $sql="select addmrn.*, addmrnqty.* from addmrn inner join addmrnqty on(addmrn.id = addmrnqty.issue_id) where addmrn.qc_status='1'";
		}
			   $i=0;    
               $sql1=DB_query($sql,$db);
               $num=DB_num_rows($sql1);
			   if($num>0)
			   {
               while($data=DB_fetch_array($sql1))
			   {
			   	$totalqtu=$data['reciveqty']-$data['rejectqty'];
               ?> 
              <tr height="20px">
                <td align="left" valign="top">&nbsp;
                	<input type="hidden" name="mrnid[<?php echo $i;?>]"  value="<?php echo $data['issue_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="center" 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="hidden" name="reject_qty[<?php echo $i; ?>]" id="reject_qty_<?php echo $i; ?>"  value="<?php echo $data['rejectqty']; ?>" ><?php echo $data['rejectqty']; ?></td>
                <td align="left" valign="top"><?php if($totalqtu!=''){ echo $totalqtu; } else { echo "0.00"; } ?></td>
                <td align="left" valign="top"><?php echo $data['site_name']; ?></td>
                </tr>
                <?php $i++; }} else { ?>
                	 <tr><td colspan="16" align="center"><?php echo "No Records Found"; ?></td><?php    } } ?>
                	 	<input type="hidden" name="count" value="<?php echo $i; ?>" />
              </table>
		  </div>
		  
		  </td>
		  </tr>
      </table>
</form>
</div>
</div>
