<link rel="stylesheet" href="css/css/purchase_requision_print.css">
<link rel="stylesheet" href="css/new_mxerp.css">

<?php
$date=implode('-',explode(',',date('Y,m,d')));
$orderdate1=$date;
$orderdate2=$date;
$num=0;
if(isset($_POST['View']))
{
$orderdate1=FormatDateForSQL($_REQUEST['from_date']);	
$orderdate2=FormatDateForSQL($_REQUEST['to_date']);	
 $sql1="select * from salesorder where orderDate between '".$orderdate1."' and '".$orderdate2."'
 and  branch='".$_REQUEST['mst_branchid']."' and indent_status=0";
 $query1=Db_query($sql1,$db);
 $num=DB_num_rows($query1);
}

?>

<div class="body_contain">
<div class="tab_div">

<h1>Material Requirement Planning Against Order</h1>
    
	<h3><strong>Search S.O.P</strong></h3>

<form action="" method="post">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
          <tr>
            <td class="tabledata">From Date </td>
            <td>
            <input type="text" name="from_date"  id="from_date" class="datepicker" style="width: 100%" readonly="readonly" value="<?php echo $_REQUEST['from_date']; ?>"/></td>	
                <td class="tabledata">To Date </td>
            <td><input type="text" name="to_date"  id="to_date" class="datepicker" style="width: 100%" readonly="readonly" value="<?php echo $_REQUEST['to_date']; ?>"/></td>
          </tr>
          <tr>
		  <td class="tabledata" >Site</td>
		  <td>
		  <select name="mst_branchid" id="mst_branchid" style="width:100%;"  onchange="showsitename158(this.value)">
				
	        		<?php 			
		          $sql_state=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$db);	
			       while($SiteName=DB_fetch_array($sql_state)) 
				   {			
			        ?>
			<option value="<?php echo $SiteName['loccode']; ?>" ><?php echo $SiteName['locationname']; ?></option>
			<?php }?>
		</select>
		  </td>
            <td class="tabledata">Total of Orders </td>
            <td><input style="width: 100%" type="text" name="total_order" id="total_order" value="<?php echo $num; ?> " readonly /></td>
            
          </tr>
        </table>
		
		<p align="left" style="margin-left:0px;"><input type="submit" name="View" id="View" value="View" class="search" onclick="return validate()" /></p>
		
		</form>
<?php if(isset($_POST['View'])){ ?>
<div style="overflow:auto;">

<table width="100%" border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 2px;">
              <tr>
                <td class="tabledata">S. No.</td>
                <td class="tabledata">SOP Date</td>
                <td class="tabledata">SOP. No.</td>
                 <td class="tabledata">Party Name</td>
                <td class="tabledata">PO Ref. No.</td>
                <td colspan="3" ><table width="100%" ><tr><td width="194" class="tabledata">Item Desc</td>
               <td width="82"  class="tabledata" style="width:50px;">UOM</td>
                <td width="62"  class="tabledata" style="width:50px;">Order Qty</td>
				</tr></table></td>
                <td  class="tabledata">Action</td>
              </tr>
             <?php
             echo $sql="select * from salesorder where orderDate between '".$orderdate1."' and '".$orderdate2."'
			 and branch='".$_REQUEST['mst_branchid']."' and indent_status=0";
			 $query=DB_query($sql,$db);
			 $num1=DB_num_rows($query1);
			 if($num1>0)
			 {
			 $sno=1;  
			 while($row=DB_fetch_array($query))
			 {
			 $salesorder2=DB_query("select * from salesorder_details where masterId='".$row['id']."'",$db);
			 $salesorder_row2=DB_fetch_array($salesorder2);
			 $itmcode=$s->getField('item_master','id',$salesorder_row2['mst_itemid'],'StockID');
			 $bill=DB_query("select * from bill_material where part_id='".$salesorder_row2['mst_itemid']."'",$db);
			  $num=DB_num_rows($bill);	
			 $stockqty=$unit=$s->getField('stock_maintenance','itemcode',$salesorder_row['mst_itemid'],'stockbalance');
			 // $mrpsop=$s->getField('requisitionorderdetails','salesorder',$row['id'],'id');     
			 $mrpsop='';       
              ?>
			<tr>
				<td class="jjrs_tablehead"><?php echo $sno++;?></td>
                <td class="jjrs_tablehead"><?php echo ConvertSQLDate($row['orderDate']); ?></td>
                <td class="jjrs_tablehead"><?php echo $row['orderNo']; ?></td>
                <td class="jjrs_tablehead"><?php echo $clientname=$s->getField('clientmaster','id',$row['client'],'c_name'); ?></td>
                <td class="jjrs_tablehead"><?php echo $row['PORefNo']; ?></td>
				<td colspan="3">
				<table width="100%"  >
				<?php 
				$salesorder1=DB_query("select * from salesorder_details where masterId='".$row['id']."'",$db);
				while($salesorder_row=DB_fetch_array($salesorder1)){ ?>
				<tr><td width="194" class="jjrs_tablehead"><?php echo $item=$s->getField('item_master','id',$salesorder_row['mst_itemid'],'item_name'); ?></td>
               <td width="82" align="center" valign="middle"  class="jjrs_tablehead" style="width:50px;"><?php echo $item=$s->getField('unitsofmeasure','unitid',$s->getField('item_master','id',$salesorder_row['mst_itemid'],'mst_unitid'),'unitname'); ?></td>
                <td width="62" align="center"  class="jjrs_tablehead" style="width:50px;"><?php echo $salesorder_row['Quantity']; ?></td>
				</tr>  <?php } ?>
				</table></td>				
				
             
			 
			   <td class="jjrs_tablehead"><?php if($num>0 && $mrpsop=='') { ?>
            <a href="index.php?route=Production/bommrpgeneratedata&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>&amp;id=<?php echo $row['id']; ?>"><input type="button" value="Generate MRP" class="search" /></a><?php } else if($mrpsop!='') { 
			echo " MRP Generated";  } else { ?>
            <a href="#" onclick="alert('This Item Has Not Bom Details ')"><input type="button" value="Generate MRP" class="search" /></a>	<?php } ?>
            	</td>
              </tr>
             <?php } } else { ?>
             	 <tr><td colspan="20"><?php echo"Sorry No Records"; ?></td></tr><?php } ?>
             	
              </table>

</div>
<?php } ?>
</div></div>


<script language="javascript"  type="text/javascript">
function open_items(str)
{
window.open("mrpgenerate.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&str1=<?php echo str; ?>","item_popup_window","resizable =yes, scrollbars=yes");
}

function validate()
{
if(document.getElementById("from_date").value=='')
{
alert("Must Select From Date First");
return false;
}

if(document.getElementById("to_date").value=='')
{
alert("Must Select To Date First");
return false;

}

if(document.getElementById("mst_branchid").value=='0')
{
alert("Must Select Site First");
return false;

}
return true;

}

	
</script>