<?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."'";
 $query1=Db_query($sql1,$db);
 $num=DB_num_rows($query1);
}

?>
<table  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="left" valign="top" ><strong>MRP S.O.P Based</strong></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="left" valign="top">
    <fieldset>
    <legend ><h4>Search S.O.P</h4></legend>
    <table  border="0" align="center" cellpadding="0" cellspacing="0">
         <tr>
        <td align="left" valign="top">
        <form action="" method="post"><table  border="0" cellspacing="2" cellpadding="1" style="background-color: #FFFFFF; border: solid 1px #CCC">
          <tr>
            <th align="left" valign="top" class="text">From Date </th>
            <td align="left" valign="top">
            <input type="text" name="from_date"  id="from_date" class="datepicker" style="width: 100%"/></td>	
                <th align="left" valign="top" class="text">To Date </th>
            <td align="left" valign="top"><input type="text" name="to_date"  id="to_date" class="datepicker" style="width: 100%"/></td>
            <td align="left" valign="top">
            <input type="submit" name="View" id="View" value="View" /></td>
          </tr>
          <tr>
            <th align="left" valign="top" class="text">Total of Orders </th>
            <td align="left" valign="top"><input style="width: 100%" type="text" name="total_order" id="total_order" value="<?php echo $num; ?> " readonly /></td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
          </tr>
        </table></form></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
     
          <tr>
            <td>
			<div class="scroll"><table  border="0" cellpadding="1" cellspacing="2" style="border: solid 1px #CCC">
              <tr>
                <th  height="40" align="left" ><strong>Action</strong></th>
                <th align="left" ><strong>S.O.P. Date</strong></th>
                <th  align="left" ><strong>S.O.P. No.</strong></th>
                <th  align="left" ><strong>S.O.P. Type</strong></th>
                 <th  align="left" ><strong>Party Name</strong></th>
                <th  align="left" ><strong>P.O Ref. NO.</strong></th>
                <th  align="left"  width="20%"><strong>Item Desc</strong></th>
               <th  align="left" ><strong>UOM</strong></th>
                <th  align="left" ><strong>Order Qty</strong></th>
                <th  align="left" ><strong>Stock Qty in store</strong></th>
                           <th  align="left" ><strong>Indent Status</strong></th>
                <th  align="left" ><strong>Unit Name</strong></th>
              </tr>
             <?php
             $sql="select * from salesorder where orderDate between '".$orderdate1."' and '".$orderdate2."' and indent_status=0";
			 $query=DB_query($sql,$db);
			 $num1=DB_num_rows($query1);
			 if($num1>0)
			 {
			 while($row=DB_fetch_array($query))
			 {
			 $salesorder1=DB_query("select * from salesorder_details where masterId='".$row['id']."'",$db);
			 $salesorder_row=DB_fetch_array($salesorder1);
			$bill=DB_query("select * from bill_material where part_code='".$salesorder_row['ItemCode']."'",$db);
			 $bill_data=DB_fetch_array($bill);	
			 $num=DB_num_rows($bill);
			 $stockqty=$unit=$s->getField('stock_maintenance','itemcode',$salesorder_row['ItemCode'],'stockbalance');             
              ?>
              <tr bgcolor="#FFFFFF">
            <td align="left" valign="top"><?php if($num>0) { ?>
            <a href="index.php?route=mrpgeneratedata&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $row['id']; ?>" >MRP Generate</a><?php } else { ?>
            <a href="#" onclick="alert('This Item Has Not Bom Details ')">MRP Generate</a>	<?php } ?>
            	</td>
                <td align="left" valign="top"><?php echo $row['orderDate']; ?></td>
                <td align="left" valign="top"><?php echo $row['orderNo']; ?></td>
                <td align="left" valign="top"><?php if($row['orderType']=="P") {echo "Process Order"; }  else {echo "Open Order"; } ?></td>
                <td align="left" valign="top"><?php $clientname=$s->getField('clientmaster','client_code',$row['client'],'c_name');  echo $clientname; ?></td>
                <td align="left" valign="top"><?php echo $row['PORefNo']; ?></td>
                <td align="left" valign="top"><?php echo $item=$s->getField('item_master','StockId',$salesorder_row['ItemCode'],'item_name');
                	 ?></td>
                <td align="left" valign="top"><?php echo $salesorder_row['unit']; ?></td>
                <td align="left" valign="top"><?php echo $bill_data['total_qty']; ?></td>
                <td align="left" valign="top"><?php echo $stockqty; ?></td>
               <td align="left" valign="top">&nbsp;</td>
               <td align="left" valign="top"><?php echo $bill_data['uom'];  ?></td>
              </tr>
             <?php } } else { ?>
             	 <tr><td colspan="20"><?php echo"Sorry No Records"; ?></td></tr><?php } ?>
             	
              </table></div></td>
          </tr>
        </table></fieldset></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>    
     </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<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");
}
	
</script>