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

$PageSecurity = 2;
$PricesSecurity = 9;

include('includes/session.inc');

$title = _('Search Inventory Items');

include('includes/header.inc');

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

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

$msg = '';

if($_REQUEST['Search'])
{
   $_REQUEST['StockCat'] =$_REQUEST['StockCat'];
	$_REQUEST['Keywords'] =$_REQUEST['Keywords'];
	$_REQUEST['StockCode'] =$_REQUEST['StockCode'];
	$filter=array();
	if(isset($_REQUEST['StockCode']) && $_REQUEST['StockCode']!=''){
	$filter[] ="stockid ='".$_REQUEST['StockCode']."' ";
	}

	if(isset($_REQUEST['StockCat']) && $_REQUEST['StockCat']!='All'){
	$filter[] ="maincategoryid   ='".$_REQUEST['StockCat']."' ";
	}
	
	if(isset($_REQUEST['Keywords']) && $_REQUEST['Keywords']!=''){
	$filter[] ="description like'%".$_REQUEST['Keywords']."%' or  longdescription  like'%".$_REQUEST['Keywords']."%'";
	}
	 
	if(count($filter)>0)
	{
	    $search_items=implode(' or ',$filter);
	}
	else{
	$search_items="1=1";
	}
	 
   	
	//$rowdata=DB_fetch_array($search_key);
 }

 $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'); 
echo '<table border=0> <tr   >';
 
echo '<td class="tdpadding" >'. _('In Stock Category') . ':';
echo '<select name="StockCat">';

if (!isset($_POST['StockCat'])) {
	$_POST['StockCat'] = "";
}

if ($_POST['StockCat'] == "All") {
	echo '<option selected value="All">' . _('All');
} else {
	echo '<option value="All">' . _('All');
}

while ($myrow1 = DB_fetch_array($result1)) {
	if ($myrow1['categoryid'] == $_POST['StockCat']) {
		echo '<option selected VALUE="' . $myrow1['categoryid'] . '">' . $myrow1['categorydescription'];
	} else {
		echo '<option value="' . $myrow1['categoryid'] . '">' . $myrow1['categorydescription'];
	}
}

echo '</select>';
echo '<td class="tdpadding" >'. _('Enter partial') . '<b> ' . _('Description') . '</b>:</td><td class="tdpadding" >';
	echo '<input type="text" name="Keywords" size=20 maxlength=25>';
echo '</td></tr> <tr><td class="tdpadding" ></td>';

echo '<td class="tdpadding" ><font size 3><b>' . _('OR') . '</b></font>' . _('Enter partial') .' <b>'. _('Stock Code') . '</b>:</td>';
echo '<td class="tdpadding" >';


	echo '<input type="text" name="StockCode" size=15 maxlength=18>';


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

echo '<div class="centre"><input type=submit name="Search" value="'. _('Search Now') . '">&nbsp;

<a href="' . $rootpath . '/Stocks.php'.'"><b><input name="Add Inventory Items" value="Add Inventory Items" type="button" /> </b></a>
</div><hr>';
  
echo '</form>';

?>
 

<?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');
?>
