<?php 
 $useurgent='';
$submenu='';
include ("../../operainfo/getq.php");
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
$allowtoview = array(); // ensure variable is initialized before include

$s = "SELECT * FROM pw_companys WHERE vui='$vui'";
$result = sqlquery($s); // updated from deprecated getquery()
if ($result) {
    while ($row = $result->fetch_assoc()) {
        $hid = $row['company_id'];
        $allowtoview[$hid] = 1;
    }
}

$submenu = "";
$x = getsecurity();

if (isset($_POST['hostcompanyid']) && $_POST['hostcompanyid'] == 0) {
    $_POST['hostcompanyid'] = '';
}
if (isset($_GET['hostcompanyid']) && $_GET['hostcompanyid'] == 0) {
    $_GET['hostcompanyid'] = '';
}

$tablewidth = '75%';

// DATABASE LOOK UPS

$stkref = safetext2(trim(isset($_POST['stkref']) ? $_POST['stkref'] : ''));
$companyid = safetext2(isset($_POST['companyid']) ? $_POST['companyid'] : '');
$usedescription = safetext2(isset($_POST['description']) ? $_POST['description'] : '');
$showhidden = isset($_POST['showhidden']) ? $_POST['showhidden'] : '';
$usehostid = safetext2(isset($_POST['hostcompanyid']) ? $_POST['hostcompanyid'] : '');

// Code confirmed for PHP 5.6 and 8.x compatibility


if ($stkref != '') {
    //print "Posted Redirect:";
    $relink = "stock_search.php" . $x . "&stkref=$stkref&companyid=$companyid&description=$usedescription&showhidden=$showhidden&hostcompanyid=$usehostid&directlink=2";
    //print "<a href=\"$relink\">Test</a>";
    print '
    <script>
    window.location="' . $relink . '";
    </script>';
}



$directlink = 0;

if ($stkref == '') {
    $stkref = trim(isset($_GET['stkref']) ? $_GET['stkref'] : '');
    $companyid = isset($_GET['companyid']) ? $_GET['companyid'] : '';
    $usedescription = safetext2(isset($_GET['description']) ? $_GET['description'] : '');
    $directlink = safetext2(isset($_GET['directlink']) ? $_GET['directlink'] : '');
    $showhidden = isset($_GET['showhidden']) ? $_GET['showhidden'] : '';

    if ($directlink == 2) {
        $directlink = '';
    } else {
        $directlink = 1;
    }

    $usehostid = safetext2(isset($_GET['hostcompanyid']) ? $_GET['hostcompanyid'] : '');
}

if ($showhidden != '') {
    $showhiddencheck = "CHECKED";
}

$prncompanyid = substr($companyid, 1);

if ($stkref == '') {
    $stkref = 'Search';
    $directlink = 0;
}

if ($usedescription == '') {
    $usedescription = 'opera';
}


?><center>
<h3>Stock Search</h3>

<div id="customConfirmModal" class="modal">
    <div class="modal-content">
        <p>
            Are you sure you want to go to Stock View?<br>
            It's a really, really old page, the data might not be correct!<br>
            Click OK to confirm.
        </p>
        <button onclick="confirmNavigation()">OK</button>
        <button onclick="closeModal()">Cancel</button>
    </div>
</div>

<!-- QA Failed Barcodes Modal -->
<div id="qaFailedModal" style="display:none; position:fixed; z-index:10000; left:0; top:0; width:100%; height:100%; background:rgba(0,0,0,0.5);">
    <div style="position:absolute; left:50%; top:50%; transform:translate(-50%,-50%); width:80%; max-width:900px; max-height:80vh; background:white; border:2px solid #000; padding:20px; box-shadow:0px 4px 10px rgba(0,0,0,0.4); overflow-y:auto; font-family:Arial,sans-serif;">
        <div style="text-align:right;"><button onclick="closeQaModal()" style="background:#c00; color:#fff; border:none; padding:5px 12px; cursor:pointer; font-size:14px;">&times; Close</button></div>
        <div id="qaFailedContent">Loading...</div>
    </div>
</div>
</center>


<style>
.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    background: white;
    border: 2px solid #000;
    padding: 20px;
    box-shadow: 0px 4px 6px rgba(0,0,0,0.3);
    text-align: center;
}

.modal-content {
    font-family: Arial, sans-serif;
}

.modal button {
    margin: 10px;
    padding: 10px 20px;
    cursor: pointer;
}

.modal button:first-child {
    background-color: #007bff;
    color: white;
    border: none;
}

.modal button:last-child {
    background-color: #ccc;
    border: none;
}

</style>

<script>

var targetUrl = "";

function confirmStockView(stkref, hostcompanyid) {
    targetUrl = "/intranet/databases/stock/stock_view.php<?php print "$x";?>&stkref=" + stkref + "&companyid=" + hostcompanyid;
    document.getElementById("customConfirmModal").style.display = "block";
}

function confirmNavigation() {
    window.location.href = targetUrl;
}

function closeModal() {
    document.getElementById("customConfirmModal").style.display = "none";
}

function confirmStockView(stkref, hostcompanyid) {
    var confirmMessage = "Are you sure you want to go to Stock View?\nIt's a really, really old page the data might not be correct!\nClick OK to confirm.";
    
    if (confirm(confirmMessage)) {
        window.location.href = "/intranet/databases/stock/stock_view.php<?php print "$x";?>&stkref=" + stkref + "&companyid=" + hostcompanyid;
    }
}

// JavaScript function to filter the table
function filterTable(filterType) {
    var rows = document.querySelectorAll("#salesTable tr");
    rows.forEach(function(row, index) {
        if (index === 0) return; // Skip table header row
        
        row.style.display = "table-row"; // Reset all to visible
        
        var isLosing = row.classList.contains("row-losing");
        var isBlacklisted = row.classList.contains("row-losing-blacklist");

        if (filterType === "losing" && !isLosing) {
            row.style.display = "none";
        } else if (filterType === "losing-no-blacklist" && (isBlacklisted || !isLosing)) {
            row.style.display = "none";
        }
    });
}
</script>

<script type="text/javascript">
function get_survey_feedback(usestk,hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+usestk;
	document.getElementById(hostlink).innerHTML='hostlink';
	var link ="../functions/get_Stock_feedback.php<?php print "$x";?>&stk="+usestk+"&hostcompanyid="+hostcompanyid;
	//document.getElementById(hostlink).innerHTML=link;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
    }
  }
}
</script>

<script type="text/javascript">
function UpdateWatchSRS(usestk,keylink) {
	document.getElementById(keylink).innerHTML='Updating';
	var link ="../functions/add_stk_srs_watchman.php<?php print "$x";?>&stk="+usestk+"&keylink="+keylink;
	//document.getElementById(uselink).innerHTML=link;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(keylink).innerHTML=xmlhttp.responseText;
    }
  }
}
</script>



<script type="text/javascript">
function updatedays(account,stkref,linkid, companyid) {
	var newv = document.getElementById(linkid).value;
	var link = "/intranet/databases/sales/addtrackingaccountstockdays.php<?php print "$x";?>&companyid="+companyid+"&account="+account+"&value="+newv+"&stkref="+stkref;
	//document.getElementById("testme").innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    
	 //document.getElementById("testme").innerHTML=linkid;
    document.getElementById("L"+linkid).innerHTML=xmlhttp.responseText;
    }
  }
}
</script>


<script type="text/javascript">
function UpdateWatchItem(usestk,po,keylink,lineid) {
	document.getElementById(keylink).innerHTML='Updating';
	var link ="../functions/watchitem.php<?php print "$x";?>&po="+po+"&stk="+usestk+"&keylink="+keylink+"&lineid="+lineid;
	//document.getElementById(uselink).innerHTML=link;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(keylink).innerHTML=xmlhttp.responseText;
    }
  }
}
</script>


<script type="text/javascript">
function get_stockqtydistribution(stkref, hostcompanyid) {
var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Getting Sales Report '+stkref;
var link = "/intranet/databases/functions/get_stockqtydistribution.php<?php print "$x";?>&stk="+stkref+"&hostcompanyid="+hostcompanyid;
//document.getElementById('test').innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

    }
  }
}
</script>

<script type="text/javascript">
function get_stockdeletedorders(stkref, hostcompanyid,targetmonthyear , curency) {
var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Getting Cancelled Orders '+stkref;
var link = "/intranet/databases/functions/getstock_deletedorders.php<?php print "$x";?>&stk="+stkref+"&hostcompanyid="+hostcompanyid;
//document.getElementById('test').innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

    }
  }
}
</script>


<script type="text/javascript">
function get_unique_customers_stock(stkref, hostcompanyid , fromtime) {
var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Getting Unique Customers '+stkref;
var link = "/intranet/databases/functions/get_unique_customers_stock.php<?php print "$x";?>&stk="+stkref+"&fromtime="+fromtime+"&hostcompanyid="+hostcompanyid;
//document.getElementById('test').innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

    }
  }
}
</script>



<script type="text/javascript">
function get_unique_customers_stock_lost(stkref, hostcompanyid , fromtime) {
var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Getting Unique Customers '+stkref;
var link = "/intranet/databases/functions/get_unique_customers_stock_lost.php<?php print "$x";?>&stk="+stkref+"&fromtime="+fromtime+"&hostcompanyid="+hostcompanyid;
//document.getElementById('test').innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

    }
  }
}
</script>

<script type="text/javascript">
function get_unique_customers_stock_qty(stkref, hostcompanyid , fromtime) {
var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Getting Unique Customers '+stkref;
var link = "/intranet/databases/functions/get_unique_customers_stock_qty.php<?php print "$x";?>&stk="+stkref+"&fromtime="+fromtime+"&hostcompanyid="+hostcompanyid;
document.getElementById(hostlink).innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

    }
  }
}
</script>

<script type="text/javascript">
function get_newsalesreport(stkref, hostcompanyid , monthyearonly) {
var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Getting Sales Report '+stkref;
var link = "/intranet/databases/functions/get_stocksalesreport.php<?php print "$x";?>&stk="+stkref+"&hostcompanyid="+hostcompanyid+"&monthyearonly"+monthyearonly;
//document.getElementById(hostlink).innerHTML='Gffffetting Sales Report '+stkref;
document.getElementById(hostlink).innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

    }
  }
}
</script>

<script type="text/javascript">
function get_newsalesreportmonth(stkref, hostcompanyid , monthyearonly , currency) {
var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Getting Sales Report '+stkref;
var link = "/intranet/databases/functions/get_stocksalesreportmonth.php<?php print "$x";?>&stk="+stkref+"&hostcompanyid="+hostcompanyid+"&monthyearonly="+monthyearonly+"&"+"crrency="+currency;
//document.getElementById(hostlink).innerHTML='Gffffetting Sales Report '+stkref;
document.getElementById(hostlink).innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

    }
  }
}
</script>

<script type="text/javascript">
function customerstockreport(companyid,stkref , hostcompanyid) {
 
 var hostlink = ""+hostcompanyid+"S"+stkref;
 document.getElementById(hostlink).innerHTML="Started";
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","../sales_reports/listcustomerstockshipments.php<?php print "$x";?>&hostcompanyid="+hostcompanyid+"&companyid="+companyid+"&stkref="+stkref,true);
xmlhttp.send();

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
    }
  }


}
</script>



<script type="text/javascript">
function get_salesreport(stkref, hostcompanyid) {
var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Getting Sales Report '+stkref;
var link = "/intranet/databases/functions/stocksalesreport.php<?php print "$x";?>&stk="+stkref+"&hostcompanyid="+hostcompanyid;
var link = "/intranet/databases/stock/showstock.php<?php print "$x";?>&stk="+stkref+"&A=1&hostcompanyid="+hostcompanyid;
document.getElementById('test').innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 
xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

    }
  }
}
</script>

<script type="text/javascript">
function get_supplierordersstockreport(stkref, hostcompanyid) {
var hostlink = ""+hostcompanyid+"S"+stkref;
var divid = 'supplierordersref'+stkref+'H'+hostcompanyid;
document.getElementById(divid).innerHTML='Getting Orders '+stkref;

	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 
xmlhttp.open("GET","/intranet/databases/functions/supplierordersstockreport.php<?php print "$x";?>&stockref="+stkref+"&hostcompanyid="+hostcompanyid,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(divid).innerHTML=xmlhttp.responseText;

    }
  }
}
</script>

<script type="text/javascript">
function getbarcodesadvref(stkref,porref,advref, hostcompanyid) {
var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Searching';

var link = "/intranet/databases/functions/getbarcodesadvref.php<?php print "$x";?>&porref="+porref+"&advref="+advref+"&stkref="+stkref+"&hostcompanyid="+hostcompanyid;
//document.getElementById(stkref).innerHTML=link;

xmlhttp=new XMLHttpRequest();
 
xmlhttp.open("GET",link,true);

xmlhttp.send();


xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
    }
  }
}

</script>

<script type="text/javascript">
function getorderstkdetails(stkref,porref,advref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Searching';

var link = "/intranet/databases/functions/getorderstkdetails.php<?php print "$x";?>&porref="+porref+"&advref="+advref+"&stkref="+stkref+"&hostcompanyid="+hostcompanyid;
//document.getElementById(hostlink).innerHTML=link;

xmlhttp=new XMLHttpRequest();

//document.getElementById(stkref).innerHTML=link;
 
xmlhttp.open("GET",link,true);

xmlhttp.send();


xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
    }
  }
}

</script>


<script type="text/javascript">

function searchbarcodesgenerated(stkref,tex, hostcompanyid) {
var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Searching '+stkref;



	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","/intranet/databases/functions/stock_recent_additions_search.php<?php print "$x";?>&stkref="+stkref+"&text="+tex+"&hostcompanyid="+hostcompanyid,true);
xmlhttp.send();


xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
    }
  }

	
	
}

</script>

<script type="text/javascript">
// AI_TAG: get_qa_failed_barcodes - popup for QA/Non-Warranty failed barcodes
function get_qa_failed_barcodes(stkref, datebookedin, hostcompanyid) {
	document.getElementById('qaFailedContent').innerHTML = 'Loading failed barcodes...';
	document.getElementById('qaFailedModal').style.display = 'block';

	var link = "/intranet/databases/functions/get_qa_failed_barcodes.php<?php print "$x";?>&stkref=" + stkref + "&datebookedin=" + datebookedin + "&hostcompanyid=" + hostcompanyid;

	var xmlhttp2;
	if (window.XMLHttpRequest) {
		xmlhttp2 = new XMLHttpRequest();
	} else {
		xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp2.open("GET", link, true);
	xmlhttp2.send();
	xmlhttp2.onreadystatechange = function() {
		if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
			document.getElementById('qaFailedContent').innerHTML = xmlhttp2.responseText;
		}
	}
}

function closeQaModal() {
	document.getElementById('qaFailedModal').style.display = 'none';
}

// AI_TAG: get_warranty_failed_barcodes - popup for warranty (Customer Fails) barcodes
function get_warranty_failed_barcodes(stkref, datebookedin, hostcompanyid) {
	document.getElementById('qaFailedContent').innerHTML = 'Loading warranty repair barcodes...';
	document.getElementById('qaFailedModal').style.display = 'block';

	var link = "/intranet/databases/functions/get_warranty_failed_barcodes.php<?php print "$x";?>&stkref=" + stkref + "&datebookedin=" + datebookedin + "&hostcompanyid=" + hostcompanyid;

	var xmlhttp3;
	if (window.XMLHttpRequest) {
		xmlhttp3 = new XMLHttpRequest();
	} else {
		xmlhttp3 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp3.open("GET", link, true);
	xmlhttp3.send();
	xmlhttp3.onreadystatechange = function() {
		if (xmlhttp3.readyState == 4 && xmlhttp3.status == 200) {
			document.getElementById('qaFailedContent').innerHTML = xmlhttp3.responseText;
		}
	}
}

// AI_TAG: get_srs_barcodes - popup for SRS/SRN barcodes (sent for investigation)
function get_srs_barcodes(stkref, datebookedin, hostcompanyid) {
	document.getElementById('qaFailedContent').innerHTML = 'Loading SRS/SRN barcodes...';
	document.getElementById('qaFailedModal').style.display = 'block';

	var link = "/intranet/databases/functions/get_srs_barcodes.php<?php print "$x";?>&stkref=" + stkref + "&datebookedin=" + datebookedin + "&hostcompanyid=" + hostcompanyid;

	var xmlhttp4;
	if (window.XMLHttpRequest) {
		xmlhttp4 = new XMLHttpRequest();
	} else {
		xmlhttp4 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp4.open("GET", link, true);
	xmlhttp4.send();
	xmlhttp4.onreadystatechange = function() {
		if (xmlhttp4.readyState == 4 && xmlhttp4.status == 200) {
			document.getElementById('qaFailedContent').innerHTML = xmlhttp4.responseText;
		}
	}
}
</script>

<script type="text/javascript">
function linktopricelists(stkref,pricelist,hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
//document.getElementById('stockquantities').innerHTML="--";	
//document.getElementById(locationid).innerHTML="--";
var link="../functions/findpricelistsstkpricelist.php<?php print "$x";?>&stkref="+stkref+"&pricelist="+pricelist+"&hostcompanyid="+hostcompanyid;
//document.getElementById(stkref).innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
    }
  }
}
</script>


<script type="text/javascript">
function updatecounter2(stkref,locationid,hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
//document.getElementById('stockquantities').innerHTML="--";	
//document.getElementById(locationid).innerHTML="--";
var link="updatecount.php<?php print "$x";?>&stkref=<?php print "$stkref";?>&locationid="+locationid+"&hostcompanyid="+hostcompanyid;
//document.getElementById(locationid).innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    //document.getElementById(locationid).innerHTML=xmlhttp.responseText;
	//updatecounterdisplay(hostlink);
    }
  }
}


function tracebatch(stkref,batchnumber,Datebookedin, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById(hostlink).innerHTML='Tracing Barcodes';
var link="stock_tracebatch.php<?php print "$x";?>&stkref=<?php print "$stkref";?>&batchnumber="+batchnumber+"&advref="+Datebookedin+"&hostcompanyid="+hostcompanyid;
//document.getElementById(hostlink).innerHTML=link;
	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.open("GET",link,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
    }
  }
}

function tracebatchnewtab(stkref,batchnumber,Datebookedin, hostcompanyid) {
var link="stock_tracebatch.php<?php print "$x";?>&tab=1&stkref=<?php print "$stkref";?>&batchnumber="+batchnumber+"&advref="+Datebookedin+"&hostcompanyid="+hostcompanyid;
window.open(link, '_tracebarcodes').focus();
}


function updatecounterdisplay(stkref,justtotal,hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById('stockquantities').innerHTML="Getting Stock Levels "+hostcompanyid;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Levels.php<?php print "$x";?>&stkref="+stkref,true);xmlhttp.send();
	xmlhttp.open("GET","/intranet/databases/functions/display_Stock_Levels.php<?php print "$x";?>&hostcompanyid="+hostcompanyid+"&justtotal="+justtotal+"&stkref="+stkref,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('stockquantities').innerHTML=xmlhttp.responseText;
			document.getElementById('Hstockquantities').value=xmlhttp.responseText;
			updatecounterbockorders(stkref,justtotal,hostcompanyid);
		}
	}
}
function updatecounterbockorders(stkref,justtotal,hostcompanyid,type) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById('customerorders').innerHTML="Getting Back Orders";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Levels.php<?php print "$x";?>&stkref="+stkref,true);xmlhttp.send();
	xmlhttp.open("GET","/intranet/databases/functions/display_back_orders.php<?php print "$x";?>&type="+type+"&hostcompanyid="+hostcompanyid+"&justtotal="+justtotal+"&stkref="+stkref,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('customerorders').innerHTML=xmlhttp.responseText;
			document.getElementById('Hcustomerorders').value=xmlhttp.responseText;
			updatecounterproformaorders(stkref,justtotal,hostcompanyid,'2');
		}
	}
}

function updatecounterproformaorders(stkref,justtotal,hostcompanyid,type) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById('proformaorders').innerHTML="Getting Proformas";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Levels.php<?php print "$x";?>&stkref="+stkref,true);xmlhttp.send();
	xmlhttp.open("GET","/intranet/databases/functions/display_back_orders.php<?php print "$x";?>&type="+type+"&hostcompanyid="+hostcompanyid+"&justtotal="+justtotal+"&stkref="+stkref,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('proformaorders').innerHTML=xmlhttp.responseText;
			document.getElementById('Hproformaorders').value=xmlhttp.responseText;
			updatecounterproformaordersar(stkref,justtotal,hostcompanyid,'3');

		}
	}
}

function updatecounterproformaordersar(stkref,justtotal,hostcompanyid,type) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById('proformaordersar').innerHTML="Getting Orders Tagged as real";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Levels.php<?php print "$x";?>&stkref="+stkref,true);xmlhttp.send();
	xmlhttp.open("GET","/intranet/databases/functions/display_back_orders.php<?php print "$x";?>&type="+type+"&hostcompanyid="+hostcompanyid+"&justtotal="+justtotal+"&stkref="+stkref,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('proformaordersar').innerHTML=xmlhttp.responseText;
			document.getElementById('Hproformaordersar').value=xmlhttp.responseText;
			updatecounterquoteorders(stkref,justtotal,hostcompanyid,'1');

		}
	}
}

function updatecounterquoteorders(stkref,justtotal,hostcompanyid,type) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById('quoteorders').innerHTML="Getting Quotations";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Levels.php<?php print "$x";?>&stkref="+stkref,true);xmlhttp.send();
	xmlhttp.open("GET","/intranet/databases/functions/display_back_orders.php<?php print "$x";?>&type="+type+"&hostcompanyid="+hostcompanyid+"&justtotal="+justtotal+"&stkref="+stkref,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('quoteorders').innerHTML=xmlhttp.responseText;
			document.getElementById('Hquoteorders').value=xmlhttp.responseText;
			updatecountersupplierorders(stkref,justtotal,hostcompanyid);

		}
	}
}

</script>
<script type="text/javascript">
function updatecountersupplierorders(stkref,justtotal,hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	var link="/intranet/databases/functions/display_supplier_orders.php<?php print "$x";?>&hostcompanyid="+hostcompanyid+"&justtotal="+justtotal+"&stkref="+stkref;
	document.getElementById('supplierorders').innerHTML='Getting Back Orders';
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Levels.php<?php print "$x";?>&stkref="+stkref,true);xmlhttp.send();
	xmlhttp.open("GET",link,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('supplierorders').innerHTML=xmlhttp.responseText;
			document.getElementById('Hsupplierorders').value=xmlhttp.responseText;
			updatecounterinpicking(stkref,justtotal,hostcompanyid)
		}
	}
}

function updatecounterinpicking(stkref,justtotal,hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	var link="/intranet/databases/functions/display_in_picking.php<?php print "$x";?>&hostcompanyid="+hostcompanyid+"&justtotal="+justtotal+"&stkref="+stkref;
	document.getElementById('inpicking').innerHTML='Barcodes in Picking';
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Levels.php<?php print "$x";?>&stkref="+stkref,true);xmlhttp.send();
	xmlhttp.open("GET",link,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('inpicking').innerHTML=xmlhttp.responseText;

		recalculatetotals();
		}
	}
}

function get_overview(stkref,hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Prices" +hostcompanyid;

	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/stock_overview.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
			updatecounterdisplay(stkref,'0',hostcompanyid);
		}
	}
}

function recalculatetotals() {
	document.getElementById('Ttotalavailable').innerHTML=parseInt(document.getElementById('Hstockquantities').value)+parseInt(document.getElementById('Hsupplierorders').value);
	document.getElementById('Tproformaordersar').innerHTML=parseInt(document.getElementById('Hcustomerorders').value)+parseInt(document.getElementById('Hproformaordersar').value);
	document.getElementById('TFinalCount').innerHTML=
	parseInt(document.getElementById('Hstockquantities').value)+
	parseInt(document.getElementById('Hsupplierorders').value)-
	parseInt(document.getElementById('Hproformaordersar').value)-
	parseInt(document.getElementById('Hcustomerorders').value)
	;
	}
</script>



<script type="text/javascript">

function countasreal(stkref,quote) {

var link ="../stock/countasreal.php<?php print "$x";?>&orderid="+quote+"&stkref="+stkref;

	if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  xmlhttp.open("GET",link,true);
xmlhttp.send();
	xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("realtot").innerHTML="Refresh Required";
    }
  }

	
}
</script>

<script type="text/javascript">

function AuditStock(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
document.getElementById("Audit"+stkref).innerHTML="Updating";
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","/intranet/databases/stock/auditstock.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);
xmlhttp.send();

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("Audit"+stkref).innerHTML=xmlhttp.responseText;
    }
  }
}

</script>


<script type="text/javascript">

function searchxref(srch) {
 
	document.getElementById(hostlink).innerHTML="<center><h3>Searching X reference Tables</h3></center>";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","extendsearch.php?search="+srch,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('rst').innerHTML=xmlhttp.responseText;
			document.getElementById(hostlink).innerHTML="<center><h3>Results Xreference Tables</h3></center>";
		}
	}
}



function get_prices(stkref , hostcompanyid) {
	
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Prices "+hostcompanyid;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_Prices.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_prices_histroy(stkref,pricelist, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Price History "+stkref+" PriceCode "+pricelist;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_Prices_history.php<?php print "$x";?>&stkref="+stkref+"&pricecode="+pricelist+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function close_stk(stkref, hostcompanyid) {
	
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(stkref).innerHTML="";
	document.getElementById(hostlink).innerHTML="";
}


function get_stock(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Stock Levels";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Levels.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	//xmlhttp.open("GET","/intranet/databases/functions/display_Stock_Levels.php<?php print "$x";?>&stkref="+stkref,true);xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
			get_supplierordersstockreport(stkref, hostcompanyid);
		}
	}
}


function get_photos(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Stock Photos";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Photos.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	//xmlhttp.open("GET","/intranet/databases/functions/display_Stock_Levels.php<?php print "$x";?>&stkref="+stkref,true);xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
		}
	}
}

function add_issue( stkref , description, hostcompanyid) {
	
	var link = "/intranet/databases/agenda/issuesubsection.php<?php print "$x";?>&sectionid=1&subsectionid=1&meetingid=55&agendaid=332&upend=on&stkref="+stkref+"&subject="+stkref+" "+description+"&hostcompanyid="+hostcompanyid;
	var win = window.open(link, '_blank');
	win.focus();
}

function get_stock_locations(stkref,location, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Stock Location Informations";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Locations.php<?php print "$x";?>&stkref="+stkref+"&location="+location,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}


function get_stock_extrainfo(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Stock Extra Information";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_Stock_Information.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_stock_distributors(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Distributor Information";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_stock_distributors.php<?php print "$x";?>&stk="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_ranked(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(stkref).innerHTML="Getting Distributor Information";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_stock_rankedsales.php<?php print "$x";?>&stk="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_uniqueqa(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Searching QA Results for unique Answers";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_stock_uniqueqa.php<?php print "$x";?>&stk="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}


function get_memo(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Perm Memo";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_Stock_memo.php<?php print "$x";?>&stk="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_ranked2(stkref, hostcompanyid) {
var hostlink = ""+hostcompanyid+"S"+stkref;
	var year = document.getElementById('year').value;
	var region = document.getElementById('region').value;
	document.getElementById(hostlink).innerHTML="Getting Distributor Information";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_stock_rankedsales.php<?php print "$x";?>&stk="+stkref+"&year="+year+"&region="+region+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_stock_faq(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting FAQ Questions";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_Stock_faq.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_stock_xref(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Cross References";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_Stock_xref.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_stock_related(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Related Stock";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_Stock_related.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_stock_repairs(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Repair Information";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/get_Stock_repair_stats_new.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_stock_supplierrepairs(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Repair Information";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/get_Stock_supplier_repair_stats.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

//get_stock_supplierrepairs



function get_stock_po(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting Order information";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_suppliersstk.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_stock_header(stkref,hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Getting header bar";
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_Stock_header.php<?php print "$x";?>&hostcompanyid="+hostcompanyid+"&stkref="+stkref,true);xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function goto_weights(stkref)
{
	window.location.href="../../operainfo/stockbook/enterweight.php<?php print "$x";?>&stkref="+stkref;
}

function clear_stock(stkref, hostcompanyid)
{
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(stkref).innerHTML="";
	document.getElementById(hostlink).innerHTML="";
}

</script>

<script type="text/javascript">




function logpricecheck(company , pricelist , qty ,stkref, hostcompanyid) {
var hostlink = ""+hostcompanyid+"S"+stkref;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","addpricerequest.php<?php print "$x";?>&company="+company+"&pricelist="+pricelist+"&qty="+qty+"&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	
	loadClicks();
	
}

function get_quotereport(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML='Getting Quotes Reports';
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/getstock_quotes.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();

	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;
		}
	}

	
}

function get_stock_groups(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Finding Groups Stock is Linked to "+stkref;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET","/intranet/databases/functions/search_linkedstockgroups.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function get_superceedhistory(stkref, hostcompanyid) {
	var hostlink = ""+hostcompanyid+"S"+stkref;
	document.getElementById(hostlink).innerHTML="Finding History of Superceed Field "+stkref;
	link="/intranet/databases/functions/get_superceedhistory.php<?php print "$x";?>&stkref="+stkref+"&hostcompanyid="+hostcompanyid;
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET",link,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(hostlink).innerHTML=xmlhttp.responseText;

		}
	}
}

function logfeedbackrequest(divfinder , contactid , companyid , stkref , hostcompanyid) {
	document.getElementById(divfinder).innerHTML="DOES NOT FUNCTION YET  "+stkref;
	link="logfeedbackrequest.php<?php print "$x";?>&contactid="+contactid+"&companyid="+companyid+"&stkref="+stkref+"&hostcompanyid="+hostcompanyid;
	document.getElementById(divfinder).innerHTML=link;
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.open("GET",link,true);
	xmlhttp.send();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById(divfinder).innerHTML=xmlhttp.responseText;

		}
	}	
	
	
}




</script>

<script>
function logDebug(message) {
    var debugDiv = document.getElementById("test2");
    if (debugDiv) {
        debugDiv.innerHTML = "<pre>" + message + "</pre>";
    }
}

function saveStatus(companyId, stkref , hostcompanyid) {
	logDebug("save Status Selected");
    var select = document.querySelector("select.status-select[data-cid='" + companyId + "']");
    var statusId = select.value;



    var params = "companyid=" + companyId +
                 "&stkref=" + encodeURIComponent(stkref) +
                 "&hostcompanyid=" + encodeURIComponent(hostcompanyid) +
                 "&statusid=" + statusId +
                 "&typeofstatus=1";

    logDebug("Sending Status Update for CID " + companyId + "\n\nPOST: logfeedbackrequest.php\n" + params);

    var xhr = new XMLHttpRequest();
    xhr.open("POST", "../stock/logfeedbackrequest.php<?php echo $x;?>", true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    xhr.onload = function () {
        logDebug("Status Response for CID " + companyId + ":\n" + xhr.responseText);
    };

    xhr.onerror = function () {
        logDebug("Status Update Error: Network or server issue.");
    };

    xhr.send(params);
}

function saveAction(companyId, stkref , hostcompanyid) {
    logDebug("save Action Selected");

 
  var select = document.querySelector("select.action-select[data-cid='" + companyId + "']");
    var actionId = select.value;

 

    var params = "companyid=" + companyId +
                 "&stkref=" + encodeURIComponent(stkref) +
                 "&hostcompanyid=" + encodeURIComponent(hostcompanyid) +
                 "&statusid=" + actionId +
                 "&typeofstatus=2";

    logDebug("Sending Action Update for CID " + companyId + "\n\nPOST: logfeedbackrequest.php\n" + params);

    var xhr = new XMLHttpRequest();
    xhr.open("POST", "../stock/logfeedbackrequest.php<?php echo $x;?>", true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    xhr.onload = function () {
        logDebug("Action Response for CID " + companyId + ":\n" + xhr.responseText);
    };

    xhr.onerror = function () {
        logDebug("Action Update Error: Network or server issue.");
    };

    xhr.send(params);
}
</script>
<div id='test'></div>

<?php





// Check the Technical FIles to See if this product is includeed


// removed and stage='Complete' from the next search, not sure why as it only counts production stock
// not sure implications as to why i put this in unless it was due to me not having a holding stage before 
// productions shhets has an opera todo list.




$s = "SELECT * FROM serialnumber_questions WHERE logchanges='1' GROUP BY stock_ref";
$result = sqlquery($s); // Replaces deprecated getquery()

$hasuniquie = array(); // initialize before use

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $stkref4 = $row['stock_ref'];
        $hasuniquie[$stkref4] = 1;
    }
}



$r2 = "SELECT * FROM ISO_quality_manual_files 
WHERE archived='' AND exp_date < '$nowis' AND exp_date_ignore='0' AND exp_date > '1000' AND type <> 'PRICE' ORDER BY description";

$result2 = sqlquery($r2); // Replaces deprecated getquery()

$docout = array(); // initialize to avoid undefined warnings

if ($result2) {
    while ($row2 = $result2->fetch_assoc()) {
        $udocid = $row2['docid'];
        $docout[$udocid] = -1;
    }
}


$s = "SELECT * FROM viamed_xref GROUP BY stock_ref";
$result = sqlquery($s); // Replaces deprecated getquery()

$onxref = array(); // initialize before use

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $xrefstk = $row['stock_ref'];
        $onxref[$xrefstk] = 1;
    }
}


if ($usedescription == "opera") {
    //print "Using $usedescription<br>";

    $s = "SELECT * FROM stocklist_tarriffs";
    $result = sqlquery($s); // Replaces deprecated getquery()

    $uselistdesc = array(); // initialize to avoid undefined warnings

    if ($result) {
        while ($row = $result->fetch_assoc()) {
            $usestk = $row['stock_ref'];
            $uselistdesc[$usestk] = $row['OperaDescription'];
        }
    }
}


if ($usedescription == "label") {
    //print "Using $usedescription<br>";

    $s = "SELECT * FROM stocklist_tarriffs";
    $result = sqlquery($s); // Replaces deprecated getquery()

    $uselistdesc = array(); // initialize to avoid undefined warnings

    if ($result) {
        while ($row = $result->fetch_assoc()) {
            $usestk = $row['stock_ref'];
            $uselistdesc[$usestk] = $row['label_description'];
        }
    }
}

if ($usedescription == "pricelist") {
    //print "Using $usedescription<br>";

    $s = "SELECT * FROM stocklist_tarriffs";
    $result = sqlquery($s); // Replaces deprecated getquery()

    $uselistdesc = array(); // initialize to avoid undefined warnings

    if ($result) {
        while ($row = $result->fetch_assoc()) {
            $usestk = $row['stock_ref'];
            $uselistdesc[$usestk] = str_replace("\n", "<br>", $row['pricedesc']);
        }
    }
}

if ($usedescription == "ghxdescription") {
    //print "Using $usedescription<br>";

    $s = "SELECT * FROM stocklist_tarriffs";
    $result = sqlquery($s); // Replaces deprecated getquery()

    $uselistdesc = array(); // initialize to avoid undefined warnings

    if ($result) {
        while ($row = $result->fetch_assoc()) {
            $usestk = $row['stock_ref'];
            $uselistdesc[$usestk] = str_replace("\n", "<br>", $row['GHX_description']);
        }
    }
}


if ( "$usedescription" == "ghxextendeddescription")
{
	//print "Using $usedescription<br>";

	$s="SELECT * FROM stocklist_tarriffs";
	$result=sqlquery($s);
	while ($row = $result->fetch_assoc()) 
	{	
		$usestk=$row[stock_ref];
		$uselistdesc[$usestk]=str_replace("\n","<br>",$row[GHX_description_extend]);			
	}
}			

if ($usedescription == "ghxextendeddescription") {
    //print "Using $usedescription<br>";

    $s = "SELECT * FROM stocklist_tarriffs";
    $result = sqlquery($s); // Replaces deprecated getquery()

    $uselistdesc = array(); // initialize to avoid undefined warnings

    if ($result) {
        while ($row = $result->fetch_assoc()) {
            $usestk = $row['stock_ref'];
            $uselistdesc[$usestk] = str_replace("\n", "<br>", $row['GHX_description_extend']);
        }
    }
}



$xt1search = "(1=0 ";

$s = "SELECT * FROM viamed_customer_stock_references WHERE customer_ref LIKE '%$stkref%' AND customer_ref <> '' GROUP BY customer_ref, stock_ref ORDER BY stock_ref";
$result = sqlquery($s); // Replaces deprecated getquery()

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $usestk = $row['stock_ref'];
        $xt1search .= " OR stock_ref = '" . $row['stock_ref'] . "'";
    }
}

$xt1search .= " )";

$stseextra = "(1=2 ";

$memoddate = array(); // Store memo update dates by hostcompany and stockref

// Build SQL statement
$s = "SELECT 
    stocklist_tarriffs_fieldhistory.stockref, 
    stocklist_tarriffs_fieldhistory.updatedon, 
    stocklist_tarriffs_fieldhistory.updatedby,
    stocklist_tarriffs_fieldhistory.hostcompanyid
FROM stocklist_tarriffs, stocklist_tarriffs_fieldhistory 
WHERE  
($xt1search 
    OR stocklist_tarriffs.stock_ref LIKE '%$stkref%' 
    OR stocklist_tarriffs.OperaDescription LIKE '%$stkref%' 
    OR stocklist_tarriffs.DescriptionExtra LIKE '%$stkref%' 
    OR stocklist_tarriffs.paperworkdescription LIKE '%$stkref%' 
    OR stocklist_tarriffs.ean13 LIKE '%$stkref%' 
    OR stocklist_tarriffs.pricedesc LIKE '%$stkref%' 
    OR stocklist_tarriffs.label_description LIKE '%$stkref%')
AND stocklist_tarriffs.stock_ref <> '' 
AND stocklist_tarriffs_fieldhistory.stockref = stocklist_tarriffs.stock_ref 
AND stocklist_tarriffs_fieldhistory.hostcompanyid = stocklist_tarriffs.hostcompany_id 
AND (stocklist_tarriffs_fieldhistory.fieldname = 'tempnote' 
     OR stocklist_tarriffs_fieldhistory.fieldname = 'permnote')
ORDER BY stocklist_tarriffs_fieldhistory.id";

// Run SQL using mysqli (preferred in PHP 5.6+ and 8.x)
$result = sqlquery($s); // Replaces deprecated getquery()

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $usestk = $row['stockref'];
        $hostid = $row['hostcompanyid'];
        $hostklink = $hostid . "S" . $usestk;
        $memoddate[$hostklink] = date("d M Y", $row['updatedon']) . " By " . getusername($row['updatedby']);
    }
}

$hostsearch = "";

if ($usehostid != '') {
    $hostsearch = " AND hostcompany_id='$usehostid'";
}


$s = "SELECT stockref FROM feedbacksurveymonkey GROUP BY stockref";
//print "$s<br>";

$result = sqlquery($s); // Replaces deprecated getquery()

$hasmonkeyfeedback = array(); // initialize to avoid undefined warnings

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $xstk = safetext2(trim($row['stockref']));
        $hasmonkeyfeedback[$xstk] = "e";
    }
}

if ($showhidden=='') {

// LETS SEE HOE MANY WE ARE HIDING
$s="SELECT * FROM stocklist_tarriffs where  
($xt1search or stock_ref LIKE '%$stkref%' or 
OperaDescription LIKE '%$stkref%' or 
extrasearch LIKE '%$stkref%' or 
DescriptionExtra LIKE '%$stkref%' or
paperworkdescription LIKE '%$stkref%' or
ean13 LIKE '%$stkref%' or 
pricedesc LIKE '%$stkref%' or 
label_description LIKE '%$stkref%')
and stock_ref<>'' and 	hidefromsystemreports='Yes' $hostsearch
 order by stock_ref , hostcompany_id";
$result = sqlquery($s); // Replaces deprecated getquery()
// Get number of rows
$hiddennum = 0; // Initialize to avoid undefined warning
if ($result) {
    $hiddennum = $result->num_rows;
}

 
// ACTUAL END SEARCH FOR REFERENCES
$s="SELECT * FROM stocklist_tarriffs where  
($xt1search or stock_ref LIKE '%$stkref%' or 
OperaDescription LIKE '%$stkref%' or 
DescriptionExtra LIKE '%$stkref%' or
paperworkdescription LIKE '%$stkref%' or
ean13 LIKE '%$stkref%' or 
extrasearch LIKE '%$stkref%' or 
pricedesc LIKE '%$stkref%' or 
label_description LIKE '%$stkref%')
and stock_ref<>'' and (hidefromsystemreports='0' or hidefromsystemreports='No') $hostsearch
 order by stock_ref , hostcompany_id";
} else {
$s="SELECT * FROM stocklist_tarriffs where  
($xt1search or stock_ref LIKE '%$stkref%' or 
OperaDescription LIKE '%$stkref%' or 
DescriptionExtra LIKE '%$stkref%' or
paperworkdescription LIKE '%$stkref%' or
ean13 LIKE '%$stkref%' or 
pricedesc LIKE '%$stkref%' or 
label_description LIKE '%$stkref%')
and stock_ref<>'' $hostsearch
 order by stock_ref , hostcompany_id";	
}
 

$result = sqlquery($s); // Replaces deprecated getquery()
$num=mysqli_num_rows($result);
$num = 0;

$ean13 = array();
$lbldesc = array();
$pricedesc = array();
$tempnotice = array();
$permnotice = array();
$cedoc = array();
$stklisting = array();
$hostlist = array();
$isactive = array();
$searchtext = array();
$sellingp = array();
$superceedlist = array();
$operamemo = array();
$opera_description = array();
$priceldesc = array();
$ghxdesc = array();
$ghxedesc = array();
$paperworkdescription = array();
$superceedtarrif = array();
$whilestockstockslast = array();

if ($result) {
    $num = $result->num_rows;

    while ($row = $result->fetch_assoc()) {
        $usestk = $row['stock_ref'];
		$ean13[$usestk] = isset ( $ean13[$usestk] ) ? $ean13[$usestk] : '' ;
        $ean13[$usestk] .= $row['ean13'];

        if ($row['label_description'] == '') {
            $lbldesc[$usestk] = '';
        } else {
            $lbldesc[$usestk] = $row['label_description'];
            $uselistdesc[$usestk] = $lbldesc[$usestk];
        }

        if ($row['pricedesc'] == '') {
            $pricedesc[$usestk] = 'No Pricelist Description';
        } else {
            $pricedesc[$usestk] = str_replace("\n", "<br>", $row['pricedesc']);
            $uselistdesc[$usestk] = $pricedesc[$usestk];
        }

        $hostid = $row['hostcompany_id'];
        $hostklink = $hostid . "S" . $usestk;
        $lbldesc[$hostklink] = $row['label_description'];
        $tempnotice[$hostklink] = $row['tempnote'];
        $permnotice[$hostklink] = str_replace("\n", " ", $row['permnote']);
        $permnotice[$hostklink] .= $row['exclusivetomemo'];

        $udocid = $row['ce_docid'];
        $cedoc[$usestk] = isset($docout[$udocid]) ? $docout[$udocid] : '';

        if ($cedoc[$usestk] == -1) {
            $tempnotice[$usestk] = "<b>We have a Temporary Issue with the EC Certification unable to send out this product until we receive the new certificate</b><br>" . $tempnotice[$usestk];
        }

        $stkref2 = $row['stock_ref'];
        $stklisting[$stkref2] = $stkref2;

        $hostlist[$hostid] = $hostid;

        $hostklink = $hostid . "S" . $stkref2;
        $isactive[$hostklink] = 1;
        $searchtext[$stkref2] = "- - -<br>- - -";
        $sellingp[$stkref2] = "- - -";
        $searchtext[$hostklink] = $row['DescriptionExtra'];
        $superceedlist[$stkref2] = $row['SUPERSEDED'];
        $stseextra .= "OR STOCK_REFE='" . $stkref2 . "' ";
        $operamemo[$stkref2] = $row['operamemo'];
        $opera_description[$hostklink] = $row['OperaDescription'];
        $priceldesc[$hostklink] = $row['pricedesc'];
        $ghxdesc[$hostklink] = $row['GHX_description'];
        $ghxedesc[$hostklink] = $row['GHX_description_extend'];
        $paperworkdescription[$hostklink] = str_replace("\n", "<br>", $row['paperworkdescription']);
        $superlink = $row['hostcompany_id'] . "S" . $stkref2;
        $superceedtarrif[$superlink] = $row['SUPERSEDED'];
        $whilestockstockslast[$hostklink] = $row['whilestockslast'];
    }
}

$stseextra .= ") ";

$s = "SELECT * FROM specialprices WHERE Pricelist='0001' AND hostcompanyid='1'";
$result = sqlquery($s); // Replaces deprecated getquery()

$singleprices = array(); // initialize before use

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $hostcompanyid = $row['hostcompanyid'];
        $stkref2 = $row['Stock_ref'];
        $superlink = $hostcompanyid . "S" . $stkref2;
        $singleprices[$superlink] = number_format(($row['Price'] / pow(10, (int)$row['D'])), 2, '.', ',');
    }
}


$thirtydaysofseconds = 86400 * 30;
$date30dayback = $nowis - $thirtydaysofseconds;

$s = "SELECT * FROM specialprices_history 
WHERE Pricelist='0001' 
AND hostcompanyid='1' 
AND datereplaced > '$date30dayback' 
ORDER BY id";

//print "$s";

$result = sqlquery($s); // Replaces deprecated getquery()

$singlepricesold = array(); // initialize before use

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $hostcompanyid = $row['hostcompanyid'];
        $stkref2 = $row['Stock_ref'];
        $superlink = $hostcompanyid . "S" . $stkref2;
        $singlepricesold[$superlink] = "/ &pound; " . number_format(($row['Price'] / pow(10, $row['D'])), 2, '.', ',');
    }
}

// Retrieve quantities on quotes and proformas
$proformaqty = array();
$quoteqty = array();
$orderqty = array();
$s = "SELECT viamedquote_orders.quote_proforma, viamedquote_orders_details.stockref, SUM(viamedquote_orders_details.qty - viamedquote_orders_details.qty_shipped) as totalqty
FROM viamedquote_orders, viamedquote_orders_details
WHERE viamedquote_orders.signofascompleteon='0' AND viamedquote_orders.quote_proforma != '0' AND viamedquote_orders.order_stage > '0' AND viamedquote_orders.order_stage < '3' AND viamedquote_orders.id = viamedquote_orders_details.orderid AND viamedquote_orders_details.qty <> viamedquote_orders_details.qty_shipped
GROUP BY viamedquote_orders.quote_proforma, viamedquote_orders_details.stockref";
$result = sqlquery($s);
while ($row = $result->fetch_assoc()) {
    $stk = $row['stockref'];
    $qty = $row['totalqty'];
    if ($row['quote_proforma'] == '1') {
        $quoteqty[$stk] = isset($quoteqty[$stk]) ? $quoteqty[$stk] + $qty : $qty;
    } elseif ($row['quote_proforma'] == '2') {
        $proformaqty[$stk] = isset($proformaqty[$stk]) ? $proformaqty[$stk] + $qty : $qty;
    }
}

// For orders (backorders)
$s = "SELECT viamedquote_orders_details.stockref, SUM(viamedquote_orders_details.qty - viamedquote_orders_details.qty_shipped) as totalqty
FROM viamedquote_orders, viamedquote_orders_details
WHERE viamedquote_orders.signofascompleteon='0' AND viamedquote_orders.quote_proforma = '0' AND viamedquote_orders.order_stage > '0' AND viamedquote_orders.order_stage < '3' AND viamedquote_orders.id = viamedquote_orders_details.orderid AND viamedquote_orders_details.qty <> viamedquote_orders_details.qty_shipped
GROUP BY viamedquote_orders_details.stockref";
$result = sqlquery($s);
while ($row = $result->fetch_assoc()) {
    $stk = $row['stockref'];
    $qty = $row['totalqty'];
    $orderqty[$stk] = isset($orderqty[$stk]) ? $orderqty[$stk] + $qty : $qty;
}

// Code confirmed for PHP 5.6 and 8.x compatibility

// do a line by line search

?>

<table>
<tr>
    <td valign="top">Search:</td>
    <td valign="top">
        <form method="POST" action="stock_search.php<?php echo $x;?>">
            <input type="text" id="mainsearch" name="stkref" value="<?php print "$stkref"; ?>" onkeyup="search()" autocomplete="off">
    </td>
    <td valign="top">Display Description</td>
    <td valign="top">
        <select name="description">
            <option value="<?php print "$usedescription"; ?>"></option>
<?php

$operaselected = '';
$labelselected = '';
$pricelistselected = '';
$ghxdescriptionselected = '';
$ghxextendeddescriptionselected = '';
$paperworkdescriptionselected = '';
$used = '';

if ($usedescription == 'opera') {
    $operaselected = "SELECTED";
    $used = 'Internal Description';
}

if ($usedescription == 'label') {
    $labelselected = "SELECTED";
}

if ($usedescription == 'pricelist') {
    $pricelistselected = "SELECTED";
}

if ($usedescription == 'ghxdescription') {
    $ghxdescriptionselected = "SELECTED";
}

if ($usedescription == 'ghxextendeddescription') {
    $ghxextendeddescriptionselected = "SELECTED";
}

if ($usedescription == 'paperworkdescription') {
    $paperworkdescriptionselected = "SELECTED";
}


print "$used"; ?></option>
<option value='opera' <?php print "$operaselected"; ?>>Internal Description</option>
<option value='label' <?php print "$labelselected"; ?>>Label</option>
<option value='pricelist' <?php print "$pricelistselected"; ?>>Price List</option>
<option value='ghxdescription' <?php print "$ghxdescriptionselected"; ?>>Ghx Description</option>
<option value='ghxextendeddescription' <?php print "$ghxextendeddescriptionselected"; ?>>Ghx Extended Description</option>
<option value='paperworkdescription' <?php print "$paperworkdescriptionselected"; ?>>Paperwork Description</option>

</select>
</td>
<td valign="top">
    Host Company
    <select name="hostcompanyid">
        <option value="">All Companies</option>
<?php
$s = "SELECT
    global_companys.id AS id,
    global_companys.fullname AS fullname
FROM
    global_companys, pw_companys
WHERE
    pw_companys.company_id = global_companys.id AND
    pw_companys.vui = '$vui' AND
    active = '0'
ORDER BY
    name";

$result = sqlquery($s); // Replaces deprecated getquery()

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $selected = ($row['id'] == $usehostid) ? "SELECTED" : "";
        print "<option value='" . $row['id'] . "' $selected>" . $row['fullname'] . "</option>";
    }
}
?>

</td></tr>
<?php
$hiddennum = isset ( $hiddennum ) ? $hiddennum : 0 ;
if ($hiddennum > 0) {
?>
<tr>
    <td>Include <?php print "$hiddennum"; ?> hidden results</td>
<?php  $showhiddencheck = isset($showhiddencheck) ? $showhiddencheck : '';?>
    <td><input type="checkbox" name="showhidden" <?php print "$showhiddencheck"; ?> ></td>
</tr>
<?php 
}
?>
<tr>
    <td></td>
    <td></td>
    <td valign="top"><input type="submit" value="Search"></td>
</tr>
</form>
</td></tr></table>
<?php



try 
{
	if ($stklisting != null)
	{
ksort($stklisting);
		$repmsg="";
		print "<div id='rst'><table width=100% class=n3><tr><td>Options</td><td>Stock Reference</td><Td>".ucwords($usedescription)." Description</td><td>Search</td><td>Gtin/Ean</td><td>UK End User</tD><td>Comment/Note</td><td>Outstanding</td></tr>";

foreach ($stklisting as $stkref2 => $stkref2vaule)
		{
		foreach ($hostlist as $hostid => $vhost){
				$hostklink=$hostid."S".$stkref2;
				$isactive[$hostklink] = isset($isactive[$hostklink]) ? $isactive[$hostklink] : '';
				$allowtoview[$hostid] = isset($allowtoview[$hostid]) ? $allowtoview[$hostid] : '';
				if ($isactive[$hostklink]==1 and $allowtoview[$hostid]==1) {
						$hostcompanyid=$hostid;
						$superlink=$hostcompanyid."S".$stkref2;
						$supper= $superceedtarrif[$superlink];
						$repmsg="";
						$msgcolor="00aacc";

			
						if ($supper<>"" and $supper<>'- - -')
							{
							$repmsg="<button onclick=\"get_superceedhistory('$stkref2')\">Superseded:</button>";
							$msgcolor="dddd00";
							}
			
						if ($supper=="9919999" )
							{			
							$supper2=$supper;
							$repmsg="<button onclick=\"get_superceedhistory('$stkref2')\">Discontinued:</button>";
							$msgcolor="dd0000";
							}
						if ($supper=="9919998" )
							{
							$repmsg="Unreleased:";
							$msgcolor="dddd00";
							}
						if  ($supper=="9919997" )
							{
							$repmsg="RELEASE SCHEDULED:";
							$msgcolor="dddd00";
							}
						if  ($supper=="9919996" )
							{
							$repmsg="NON-STOCK BUT AVAILABLE:";
							$msgcolor="dddd00";
							}
						if  ($supper=="9919995" )
							{
							$repmsg="ONLY FOR SPECIFIC OEM CUSTOMER:";
							$msgcolor="dddd00";
							}				
						if  ($supper=="9919994" )
							{
							$repmsg="EBay Only:";
							$msgcolor="8B008B";
							}
						if  ($supper=="MEMO" )
							{
							$repmsg="SEE MEMO";
							$msgcolor="8B008B";
							}
							print "<TR bgcolor=\"#$msgcolor\" $useurgent onMouseOver=\"this.bgColor='#d4deea';\" onMouseOut=\"this.bgColor='#$msgcolor';\">";
							print "<td valign=middle>";
						if ($global_access_updatestock[$hostcompanyid]==1 )
							{
							?>
							<a  href="/intranet/databases/stock_extra/editwarranty.php<?php echo $x; ?>&stockref=<?php print"$stkref2";?>&hostcompanyid=<?php print "$hostcompanyid";?>"  title="Edit Extra Information">
							<img src="/intranet/images/pen.jpg" border=0 width=24 height=24></a>
							<?php
							} else {				
							print "<a href=\"stock_search.php$x&stkref=$stkref2&hostcompanyid=$hostcompanyid\" title=\"Zoom\"> <img src=\"../../images/space.png\" border=0 width=24 height=24> </a>";
							}
						//$dispcomp=ucwords($row['companyid']);
						print "<a onclick=\"close_stk('$stkref2','$hostcompanyid')\">".$global_company_logo24[$hostcompanyid]."</a>";
						?>
						<img onclick="get_stock('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/stocklevels.jpg" border=0 width=24 height=24 title="<?php print "$stkref2";?> Stock Levels"></a>
						<img onclick="get_prices('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/prices.jpg" border=0 width=24 height=24 title="<?php print "$stkref2";?> Prices">
						<img onclick="get_stock_extrainfo('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/infom.png" border=0 width=24 height=24 title="<?php print "$stkref2";?> Extra Information">
						<img onclick="get_stock_faq('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/faq.jpg" border=0 width=24 height=24 title="<?php print "$stkref2";?> Frequently asked questions">
						<?php	
						$onxref[$stkref2] = isset($onxref[$stkref2]) ? $onxref[$stkref2] : '';
						if ($onxref[$stkref2]==1) 
							{
							?>
							<img onclick="get_stock_xref('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/xref.png" border=0 width=24 height=24 title="<?php print "$stkref2";?> Cross Reference Data to competitors">
							<?php
							} else {
							?>
							<img src="../../images/space.png" border=0 width=24 height=24>	
							<?php
							}
							?>
						<img onclick="get_stock_related('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/relate.jpg" border=0 width=24 height=24 title="<?php print "$stkref2";?> Similar / related stock">
						<img onclick="get_stock_repairs('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/warranty_bl.jpg" border=0 width=24 height=24 title="<?php print "$stkref2";?> Repair Statistics">
						<img onclick="get_stock_supplierrepairs('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/warranty_sup.jpg" border=0 width=24 height=24 title="<?php print "$stkref2";?> Supplier Returns">
						<img onclick="get_stock_po('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/manufacture.jpg" border=0 width=24 height=24 title="<?php print "$stkref2";?> Suppliers">
						<img onclick="searchbarcodesgenerated('<?php print "$stkref2";?>','','<?php print "$hostcompanyid";?>')" src="../../images/barcode1.jpg" border=0 width=24 height=24 title="<?php print "$stkref2";?> Barcodes Generated">
						<img onclick="get_stock_distributors('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/is_dist22.png" border=0 width=24 height=24 title="<?php print "$stkref2";?> Distributors">
						<img onclick="goto_weights('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/menu/scales.png" border=0 width=24 height=24 title="<?php print "$stkref2";?> Weights and Dimensions">
						<?php
						$hasphotos[$stkref2] = isset($hasphotos[$stkref2]) ? $hasphotos[$stkref2] : 0;
						if ($hasphotos[$stkref2]>0) 
							{
							?>
							<img onclick="get_photos('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/photo.png" border=0 width=24 height=24 title="<?php print "$stkref2 ";?> Show Photos">
							<?php
							} else {
							?>
							<img onclick="get_photos('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/photo.png" border=0 width=24 height=24 title="<?php print "$stkref2";?> No Photos">
							<?php
							}			
							?>
						<img onclick="get_ranked('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/menu/ranked.png" border=0 width=24 height=24 title="<?php print "$stkref2";?> Ranked Sales / best customers">	
						<img onclick="get_stock_header('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/menu/x_sm.jpg" border=0 width=24 height=24 title="<?php print "$stkref2";?> HeaderBar">
						<?php
						$uselistdesc[$stkref2] = isset($uselistdesc[$stkref2]) ? safetext2($uselistdesc[$stkref2]) : '';
						?>
						<img onclick="add_issue('<?php print "$stkref2";?>','<?php print "$uselistdesc[$stkref2]";?>','<?php print "$hostcompanyid";?>')" src="../../images/menu/add_issue.png" border=0 width=24 height=24 title="<?php print "Add Issue $stkref2";?> ">
						
						<?php
						$permnotice[$hostklink] = isset($permnotice[$hostklink]) ? $permnotice[$hostklink] : '';
						$operamemo[$stkref2] = isset($operamemo[$stkref2]) ? $operamemo[$stkref2]: '';
						if ($permnotice[$hostklink]<>'' or $operamemo[$stkref2]<>'')
							{
							?>
							<img onclick="get_memo('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/redm.jpg" border=0 width=24 height=24 title="<?php print "Memo $stkref2";?> ">
							<?php	
							} else {
							?>
							<img src="../../images/space.png" border=0 width=24 height=24  title='No Memo'>
							<?php
							}
						$hasuniquie[$stkref2]  = isset($hasuniquie[$stkref2]) ? $hasuniquie[$stkref2]: '';
						if ($hasuniquie[$stkref2] !='')
							{	
							?>
							<img onclick="get_uniqueqa('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" src="../../images/menu/unique.png" border=0 width=24 height=24 title="<?php print "$stkref2";?> Show Unique QA Field Answers">	
							<?php		
							}		
						?>
						<img src="../../images/sales.png" onclick="get_newsalesreport('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>','')" border=0 width=24 height=24 title="<?php print "$stkref2";?> Sales"></a>
						<img src="../../images/menu/customers.jpg" onclick="get_unique_customers_stock('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>','')" border=0 width=24 height=24 title="<?php print "$stkref2";?> Unique Customers"></a>
						<?php
						$hasmonkeyfeedback[$stkref2] = isset($hasmonkeyfeedback[$stkref2]) ? $hasmonkeyfeedback[$stkref2]: '';						
						if ($hasmonkeyfeedback[$stkref2]<>'') 
							{
							?>
							<img src="../../images/surveymonkey.png" onclick="get_survey_feedback('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" border=0 width=24 height=24 title="<?php print "$stkref2";?> Survey Feedback"></a>
							<?php		
							} else {
							?>
							<img src="../../images/space.png" border=0 width=24 height=24  title='No Surveys'>
							<?php	
							}
						if ($usersecurity > 7)
							{
							?>
							<img src="../../images/overview.png" onclick="get_overview('<?php print "$stkref2";?>','<?php print "$hostcompanyid";?>')" border=0 width=24 height=24 title="<?php print "$stkref2";?> Overview"></a>
							<a href="addtraining.php<?php print "$x";?>&stkref=<?php print "$stkref2";?>"><img src="../../images/menu/emploeetraining.png" border=0 width=24 height=24" title="Add Employee Training"></a>
							<?php
							}	
							?>
<a href="../warehouserequest/add.php<?php echo $x; ?>&hostcompanyid=<?php echo urlencode($hostcompanyid); ?>&stkref=<?php echo urlencode($stkref2); ?>">
  <img src="../../images/is_ware.png" border="0" width="24" height="24"
       title="<?php echo htmlspecialchars($stkref2, ENT_QUOTES, 'UTF-8'); ?> Warehouse Request"
       alt="Warehouse Request">
</a>
							<a href="/intranet/databases/stock_bookin/stockbookadditem.php<?php print "$x";?>&stkref=<?php print "$stkref2";?>&hostcompanyid=<?php print "$hostcompanyid";?>&action=refresh"><img src="/intranet/images/pallet.png" border=0 width=24 height=24" title="Add New Stock"></a>
							</td><td valign=middle align=left>
							<?php
							print "".linkstkref($x,$stkref2,$float,46,$hostcompanyid)."<a href=\"#\" onclick=\"confirmStockView('$stkref2','$hostcompanyid'); return false;\">$stkref2</a>";
							print "</td>";
							// Description Type
							print "<td valign=middle >";
							if ($usedescription=='opera') {
								print "$opera_description[$hostklink] ";
							}
							if ($usedescription=='label') {
								print "$lbldesc[$hostklink]";
							}
							if ($usedescription=='paperworkdescription') {
								print "$paperworkdescription[$hostklink]";
							}		
							if ($usedescription=='pricelist') {
								print "$priceldesc[$hostklink]";
							}	
							if ($usedescription=='ghxdescription') {
								print "$ghxdesc[$hostklink]";
							}	
							if ($usedescription=='ghxextendeddescription') {
								print "$ghxedesc[$hostklink]";
							}	
							print "</td>";
							$searchtext[$hostklink]= isset($searchtext[$hostklink]) ? $searchtext[$hostklink]: '';	
							$ean13[$stkref2]= isset($ean13[$stkref2]) ? $ean13[$stkref2]: '';	
							print "<td valign=top>$searchtext[$hostklink]</td><td>$ean13[$stkref2]</td><Td valign=top>";
							$singlepricesold[$superlink]= isset($singlepricesold[$superlink]) ? $singlepricesold[$superlink]: '';
							$singleprices[$superlink]= isset($singleprices[$superlink]) ? $singleprices[$superlink]: '';
							if ($singlepricesold[$superlink]=='') 
								{
								print "&pound $singleprices[$superlink]";
								} else {
								print "Pending Change";	
								}
							print "</td><td valign=top>";
							$whilestockstockslast[$hostklink]= isset($whilestockstockslast[$hostklink]) ? $whilestockstockslast[$hostklink]: '';
							if ($whilestockstockslast[$hostklink]=='Yes') {
								print "AVAILABLE While Stocks Last<br>";
								} 

							$repmsg = isset($repmsg) ? $repmsg: '';
							if ( $repmsg <>'' )
								{
								if ($supper=='MEMO') {
									print "<input type=button onclick=\"get_memo('$stkref2','$hostcompanyid')\" value='See Memo'>";
									} else {			
									print $repmsg."<a href=\"stock_search.php$x$supper\">$supper</a>";
									
									}
								}
							print "</td><td>";
							$ustkref= isset($ustkref) ? $ustkref: '';
							$lastrecieved[$ustkref] = isset($lastrecieved[$ustkref]) ? $lastrecieved[$ustkref]: '';
							if ($lastrecieved[$ustkref]<>'') 
								{
								print "$lastrecieved[$stkref2]";
								}
							print "</td>";
							$orderqty_val = isset($orderqty[$stkref2]) ? $orderqty[$stkref2] : 0;
							$quoteqty_val = isset($quoteqty[$stkref2]) ? $quoteqty[$stkref2] : 0;
							$proformaqty_val = isset($proformaqty[$stkref2]) ? $proformaqty[$stkref2] : 0;
							$outstanding = '';
							if ($orderqty_val > 0) $outstanding .= $orderqty_val . ' Orders<br>';
							if ($proformaqty_val > 0) $outstanding .= $proformaqty_val . ' Proformas<br>';
							if ($quoteqty_val > 0) $outstanding .= $quoteqty_val . ' Quotes<br>';
							print "<td>$outstanding</td>";

							print "</tr>\n";
							$tempnotice[$hostklink] = isset($tempnotice[$hostklink]) ? $tempnotice[$hostklink]: '';
							$memoddate[$hostklink] = isset($memoddate[$hostklink]) ? $memoddate[$hostklink]: '';
							if ($tempnotice[$hostklink]<>'' )
								{
								print "<tr><td colspan=10 align=left><b>$stkref2</b> Memo (Memos updated $memoddate[$hostklink]) </br>$tempnotice[$hostklink] </td></tr>";
								}
								print "<tr><td colspan=10 align=middle><div id='$stkref2'> </div><div id='$hostklink'></div></td></tr>";
				
				
		
			


				// end is active loop				
				}
			// End of host loop
			}		
		// End of $stklisting
		}

	// End of null listing check
	}

// End of Try Fail Check
} catch (Exception $e) 
{
	print "Nothing found!";
}







?>

<div id='header'>
</div>
<div id='xsearch'>
</div>


</body>
</html>
