<?php
/* $Revision: 1.49 $ */

$PageSecurity = 2;
$PricesSecurity = 9;
include('includes/session.inc');
include('includes/function_lib.php');
$title = _('Search Inventory Items');
include('includes/header.inc');

/*echo "<pre>"; print_r($_SESSION);
exit;*/

$action=$_REQUEST['daction'];
$StockID=$_REQUEST['StockID'];

$msg = '';

if($_REQUEST['action']=='delete' && isset($_REQUEST['StockID']))
{
  $sql_delete=DB_query("delete from  stockmaster where stockid   ='".$_REQUEST['StockID']."'",$db);
  if(! $sql_delete)
  {
     die("Error Can't  Delete".DB_error());
  }
 $s->pageLocation('SelectProduct.php?daction=deleted');
}
if($_REQUEST['Search'])
{
	$sql="select * from stockmaster";
	
	$filter=array();
	
	if($_REQUEST['StockCat']!='000')
	$filter[]="maincategoryid='".$_REQUEST['StockCat']."'";
	if($_REQUEST['Keywords']!='000')
	$filter[]="categoryid='".$_REQUEST['Keywords']."'";
	
	if($filter!='')
	{
		$sql=$sql." where ".implode("and",$filter);
	}
//echo $sql;
}
else
{
	$sql="select * from stockmaster order by stockid asc";
}
$result=DB_query($sql,$db);
 $SQL='SELECT categoryid,
        categorydescription
    FROM stockcategory
    ORDER BY categorydescription';

$result1 = DB_query($SQL,$db);
if (DB_num_rows($result1) == 0) {
    echo '<p><font size=4 color=red>' . _('Problem Report') . ':</font><br>' . _('There are no stock categories currently defined please use the link below to set them up');
    echo '<br><a href="' . $rootpath . '/StockCategories.php?' . SID .'">' . _('Define Stock Categories') . '</a>';
    exit;
}
echo '<form action="'. $_SERVER['PHP_SELF'] . '?' . SID .'" method=post>';
echo '<b>' . $msg . '</b>';
echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/magnifier.png" title="' . _('Search') . '" alt="">' . ' ' . _('Search for Inventory Items');


//**************************************************************************************
 if($_REQUEST['daction'])
{
  echo "<div class='success'>Record ".$_REQUEST['daction']." successfully</div>";
}

 //************************************************************************************** 
 ?>
<table border=0 align="center" cellpadding="2"> 
<tr> 
<th><strong>MAIN CATEGORY</strong> </th>
<td> 
<select name="StockCat" id="StockCat">
<option value="000">---Select Main Item Category---</option>
<?php
$main_sql=DB_query("select * from stockmaincategory",$db);
while($main_row=DB_fetch_array($main_sql))
{
?>
<option value="<?php echo $main_row['stockmaincategoryid'];?>"><?php echo $main_row['stockmaincategoryname'];?></option>
<?php } ?>
</select>
</td>
<td><strong>OR</strong></td>
<th><strong>SUB CATEGORY </strong></th>
<td>
<select name="Keywords" id="Keywords">
<option value="000">---Select Item Sub Category---</option>
<?php
$sub_sql=DB_query("select * from stockcategory",$db);
while($sub_row=DB_fetch_array($sub_sql))
{
?>
<option value="<?php echo $sub_row['categoryid'];?>"><?php echo $sub_row['categorydescription'];?></option>
<?php } ?>
</select>
</td>
</tr> 
</table>
<br>
<br />
<div class="centre" align="center"><input type=submit name="Search" value="Search Now">
<a href="<?php echo $rootpath . '/Stocks.php' ;?>"><b><input name="Add Inventory Items" value="Add Inventory Items" type="button" /> </b></a>
</div><hr>
</form>
<br />
<br />
<table  width="90%"border="0"    cellspacing="1" cellpadding="4"  >
 <tr>
    <th width="8%" ><strong>Code</strong></th>
    <th width="26%"><strong>Description</strong></th>
	 <th width="10%"><strong>Code</strong></th>
	  <th width="14%"><strong>Grade</strong></th>
	   <th width="13%"><strong>Item Serial No</strong></th>
     <th width="7%"><strong>Units</strong></th>
     <th width="7%"><strong>View</strong></th>
	  <th width="6%"><strong>Edit</strong></th>  
	  <th width="9%"><strong>Delete</strong></th>
 </tr>
     <?php $i=0;
if(DB_num_rows($result)>0)	
{
while($RowGetItems=DB_fetch_array($result))
{
   if($i++%2==0)
     $bgcolor="#CCCCCC";
	 else{
	 $bgcolor="#FFFFFF";
	 }
   ?><tr bgcolor="<?php echo $bgcolor;?>" >
    <td   valign="middle" ><?php  echo $RowGetItems['stockid']?></td>	
    <td ><?php  echo $RowGetItems['description']?></td>
	  <td ><?php  echo $RowGetItems['client_code']?></td>
	    <td ><?php  echo $RowGetItems['shade_name']?></td>
		  <td ><?php  echo $RowGetItems['item_serial_code']?></td>
     <td ><?php 
	  echo $s->getField('unitsofmeasure','unitid',$RowGetItems['units'],'unitname');
	   
	  ?></td>
	   <td><a href="ViewStocks.php?StockID=<?php  echo $RowGetItems['stockid']?>">View</a></td>
	    <td><div align="center"><a href="Stocks.php?StockID=<?php  echo $RowGetItems['stockid']?>"><img src="images/icon-edit.png"  width="10" height="10"/></a></div></td> 
		 <td><div align="center"><a href="SelectProduct.php?action=delete&StockID=<?php  echo $RowGetItems['stockid']?>"><img src="images/Icon_Delete.png"  width="10" height="10"/></a></div></td>
  </tr>
<?php }}else{ ?> 
<tr>
<td colspan="7"><h2 align="center"><font color="#FF0000"><strong>--No Record Found--</strong></font></h2></td>
</tr>
<?php } ?>
</table>
<?php   
switch($action){
case "view": 
?>
		<table width="90%" border="0"  class="maintable" >  
        
		 <tr  >
		 <td class="tdpadding"  colspan="3" style="font-size:14px"><center >StockID : <?php echo $StockID ?></center></td></tr> 
		 <tr  class="tablehead" >
		<td width="33%">Item Inquiries</td>
        <td class="tdpadding"  width="33%">Item Transactions</td>
        <td class="tdpadding"  width="33%">Item Maintenance</td>
    </tr>  <tr ><td class="tdpadding"  valign="top">
  <a href="<?php echo $rootpath . '/StockMovements.php?' . SID . '&StockID=' . $StockID ;?>">Show Stock Movements</a><br>
<?php 
    if ($Its_A_Kitset_Assembly_Or_Dummy == false) {?>
         <a href="<?php echo $rootpath . '/StockStatus.php?' . SID . '&StockID=' . $StockID ;?>">Show Stock Status</a><br>
        <a href="<?php echo $rootpath . '/StockUsage.php?' . SID . '&StockID=' . $StockID ; ?>">Show Stock Usage</a><br> 
   <?php  }?>
         <a href="<?php echo $rootpath . '/SelectSalesOrder.php?' . SID . '&SelectedStockItem=' . $StockID; ?>">Search Outstanding Sales Orders</a><br> 
       <a href="<?php echo  $rootpath . '/SelectCompletedOrder.php?' .SID . '&SelectedStockItem=' . $StockID ?>"> Search Completed Sales Orders</a><br> 
	   <?php 
    if ($Its_A_Kitset_Assembly_Or_Dummy == false) {?>
	
       <a href="<?php echo  $rootpath . '/PO_SelectOSPurchOrder.php?' . SID . '&SelectedStockItem=' . $StockID ;?>">Search Outstanding Purchase Orders</a><br> 
	   
   
	   <a href="<?php echo  $rootpath . '/PO_SelectOSPurchOrder.php?' . SID . '&SelectedStockItem=' . $StockID ;?>">Search All Purchase Orders</a><br> 
         
         <a href="<?php echo  $rootpath . '/' . $_SESSION['part_pics_dir'] . '/' . $StockID . '.jpg?' . SID ;?>">Show Part Picture (if available)</a><br> 
<?php     }

    if ($Its_A_Dummy == False) {
        echo '<a href="' . $rootpath . '/BOMInquiry.php?' . SID . '&StockID=' . $StockID . '">' . _('View Costed Bill Of Material') . '</a><br>';
        echo '<a href="' . $rootpath . '/WhereUsedInquiry.php?' . SID . '&StockID=' . $StockID . '">' . _('Where This Item Is Used') . '</a><br>';
    }
    if ($Its_A_Labour_Item==True) {
        echo '<a href="' . $rootpath . '/WhereUsedInquiry.php?' . SID . '&StockID=' . $StockID . '">' . _('Where This Labour Item Is Used') . '</a><br>';
    }
    wikiLink('Product', $StockID);

    echo '</td><td class="tdpadding"  valign="top">';

    /* Stock Transactions */
    if ($Its_A_Kitset_Assembly_Or_Dummy == False) {
        echo '<a href="' . $rootpath . '/StockAdjustments.php?' . SID . '&StockID=' . $StockID . '">' . _('Quantity Adjustments') . '</a><br>';
            echo '<a href="' . $rootpath . '/StockTransfers.php?' . SID . '&StockID=' . $StockID . '">' . _('Location Transfers') . '</a><br>';
        /**
         * 2008-08-19 ToPu
         * enter a purchase order for this SelectedStockItem and suppliers
         * supplierid -- one link for each supplierid.
         */
        if ($myrow['mbflag'] == 'B') {
            /**/
            echo '<br>';
            $SuppResult = DB_query("SELECT  suppliers.suppname,
                        suppliers.supplierid,
                        purchdata.preferred
                    FROM purchdata INNER JOIN suppliers
                    ON purchdata.supplierno=suppliers.supplierid
                    WHERE purchdata.stockid = '" . $StockID . "'",
                    $db);
            while ($SuppRow = DB_fetch_array($SuppResult)) {
                /**/
                //
                echo '<a href="' . $rootpath . '/PO_Header.php?' . SID . '&NewOrder=Yes' . '&SelectedSupplier=' . $SuppRow['supplierid'] . '&StockID=' . $StockID . '">' . _('Purchase this Item from') . ' ' . $SuppRow['suppname'] . ' (default)</a><br>';
                /**/
            } /* end of while */
        } /* end of $myrow['mbflag'] == 'B' */
    } /* end of ($Its_A_Kitset_Assembly_Or_Dummy == False) */

    echo '</td><td class="tdpadding"  valign="top">';

    /* Stock Maintenance Options */

 
  echo '<a href="' . $rootpath . '/Stocks.php?' . SID . '&StockID=' . $StockID . '">' . _('Modify Item Details') . '</a><br>';
    if ($Its_A_Kitset_Assembly_Or_Dummy == False) {
        echo '<a href="' . $rootpath . '/StockReorderLevel.php?' . SID . '&StockID=' . $StockID . '">' . _('Maintain Reorder Levels') . '</a><br>';
            echo '<a href="' . $rootpath . '/StockCostUpdate.php?' . SID . '&StockID=' . $StockID . '">' . _('Maintain Standard Cost') . '</a><br>';
			
			
			 echo '<a href="' . $rootpath . '/Overheadcost.php?' . SID . '&StockID=' . $StockID . '">' . _('Maintain Overhead Cost') . '</a><br>';
			
            echo '<a href="' . $rootpath . '/PurchData.php?' . SID . '&StockID=' . $StockID . '">' . _('Maintain Purchasing Data') . '</a><br>';
    }
    if ($Its_A_Labour_Item==True){
            echo '<a href="' . $rootpath . '/StockCostUpdate.php?' . SID . '&StockID=' . $StockID . '">' . _('Maintain Standard Cost') . '</a><br>';
    }
    if (! $Its_A_Kitset) {
        echo '<a href="' . $rootpath . '/Prices.php?' . SID . '&Item=' . $StockID . '">' . _('Maintain Pricing') . '</a><br>';
            if (isset($_SESSION['CustomerID']) AND $_SESSION['CustomerID'] != "" AND Strlen($_SESSION['CustomerID']) > 0) {
            echo '<a href="' . $rootpath . '/Prices_Customer.php?' . SID . '&Item=' . $StockID . '">' . _('Special Prices for customer') . ' - ' . $_SESSION['CustomerID'] . '</a><br>';
            }
		echo '<a href="' . $rootpath . '/DiscountCategories.php?' . SID . '&StockID=' . $StockID . '">' . _('Maintain Discount Category') . '</a><br>';
    }

    echo '</td></tr></table>';
				

//default : include('View_InventoryItems.php');
 }
?>
<?php 

include('includes/footer.inc');
?>
