<?php


		
		
session_start();
    include_once("config.inc.php");
	include_once("DBConnector.php");

	include_once("connection.php");

if ($_GET["Command"]=="search_item"){

include './new/connection_sql.php';
		$ResponseXML .= "";
		//$ResponseXML .= "<invdetails>";
			
	
	
		$ResponseXML .= "<table width=\"735\" border=\"0\" class=\"form-matrix-table\">
                            <tr>
                              <td width=\"121\"  background=\"images/headingbg.gif\" ><font color=\"#FFFFFF\">Item No</font></td>
                              <td width=\"424\"  background=\"images/headingbg.gif\"><font color=\"#FFFFFF\">Item Description</font></td>
                               <td width=\"200\"  background=\"images/headingbg.gif\" ><font color=\"#FFFFFF\">Brand</font></td>
                              <td width=\"100\"  background=\"images/headingbg.gif\"><font color=\"#FFFFFF\">Gen No</font></td>
                               <td width=\"80\"  background=\"images/headingbg.gif\" ><font color=\"#FFFFFF\">Substitute</font></td>
                              <td width=\"100\"  background=\"images/headingbg.gif\"><font color=\"#FFFFFF\">Selling</font></td>
                               <td width=\"100\"  background=\"images/headingbg.gif\" ><font color=\"#FFFFFF\">Part No</font></td>
                              <td width=\"100\"  background=\"images/headingbg.gif\"><font color=\"#FFFFFF\">Stock In Hand</font></td>

   							</tr>";
                        
				// 		if ($_GET["checkbox"]=="true"){								
				// 			if ($_GET["mstatus"]=="itno"){
				// 		   		$letters = $_GET['itno'];
				// 				//$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
				// 				if (isset($_SESSION["brand"])==true){
				// 				$sql = mysql_query("SELECT * from s_mas where STK_NO like  '$letters%' and QTYINHAND>0 and BRAND_NAME='".$_SESSION["brand"]."' order by STK_NO limit 50") or die(mysql_error());
				// 				} else {
				// 				$sql = mysql_query("SELECT * from s_mas where STK_NO like  '$letters%' and QTYINHAND>0 order by STK_NO limit 50") or die(mysql_error());
				// 				}
				// 			}	else if ($_GET["mstatus"]=="brand1"){
				// 				$letters = $_GET['brand1'];
				// 				//$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
				// 				if (isset($_SESSION["brand"])==true){
				// 					$sql = mysql_query("SELECT * from s_mas where BRAND_NAME like  '$letters%' and BRAND_NAME='".$_SESSION["brand"]."' order by STK_NO limit 50")or die(mysql_error());
				// 				//	echo 'aaaaaaaaaaaaaaaaaaaaaaccc';
				// 				} else {
				// 					$sql = mysql_query("SELECT * from s_mas where BRAND_NAME like  '$letters%' order by STK_NO limit 50") or die(mysql_error());
				// 					//echo 'aaaaaaaaaaaaaaaaaaaaaa';
				// 				}
				// 			} else if ($_GET["mstatus"]=="jobno"){

				// 				$letters = $_GET['jobno'];
				// 				//$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
				// 				if (isset($_SESSION["brand"])==true){
				// 					$sql = mysql_query("SELECT * from s_mas where PART_NO like  '$letters%' and BRAND_NAME='".$_SESSION["brand"]."' order by STK_NO limit 50")or die(mysql_error());
									
				// 				} else { 
				// 					$sql = mysql_query("SELECT * from s_mas where PART_NO like  '$letters%' order by STK_NO limit 50") or die(mysql_error());
									
				// 				}
				// 			} 	else if ($_GET["mstatus"]=="itemname"){
				// 				$letters = $_GET['itemname'];
				// 				//$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
				// 				if (isset($_SESSION["brand"])==true){
				// 					$sql = mysql_query("SELECT * from s_mas where DESCRIPT like  '$letters%' and BRAND_NAME='".$_SESSION["brand"]."' and QTYINHAND>0 order by STK_NO limit 50")or die(mysql_error());
									
				// 				} else {
				// 					$sql = mysql_query("SELECT * from s_mas where DESCRIPT like  '$letters%' order by STK_NO limit 50") or die(mysql_error());
				// 				}
				// 			} else {
								
				// 				$letters = $_GET['itemname'];
				// 				//$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
				// 				if (isset($_SESSION["brand"])==true){
				// 					$sql = mysql_query("SELECT * from s_mas where DESCRIPT like  '$letters%' and BRAND_NAME='".$_SESSION["brand"]."' and QTYINHAND>0 order by STK_NO limit 50") or die(mysql_error());
				// 				} else {
				// 					$sql = mysql_query("SELECT * from s_mas where DESCRIPT like  '$letters%' and QTYINHAND>0 order by STK_NO limit 50") or die(mysql_error());
				// 				}
				// 			}
				// 		}	else {
							
				// 			if ($_GET["mstatus"]=="itno"){
				// 		   		$letters = $_GET['itno'];
				// 				//$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
				// 				if (isset($_SESSION["brand"])==true){
				// 				$sql = mysql_query("SELECT * from s_mas where STK_NO like  '$letters%' and BRAND_NAME='".$_SESSION["brand"]."' order by STK_NO limit 50") or die(mysql_error());
				// 				} else {
				// 				$sql = mysql_query("SELECT * from s_mas where STK_NO like  '$letters%' order by STK_NO") or die(mysql_error());
							 
				// 				}
				// 			} else if ($_GET["mstatus"]=="brand1"){
							    
				// 				$letters = $_GET['brand1'];
				// 				//$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
				// 				if (isset($_SESSION["brand"])==true){
				// 					$sql = mysql_query("SELECT * from s_mas where BRAND_NAME like  '$letters%'  order by STK_NO limit 50")or die(mysql_error());
								 
				// 				} else {
								    
				// 					$sql = mysql_query("SELECT * from s_mas where BRAND_NAME like  '$letters%'  limit 50") or die(mysql_error());
									 
				// 				}
				// 			} else if ($_GET["mstatus"]=="jobno"){

							   
				// 				$letters = $_GET['jobno'];
				// 				//$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
				// 				if (isset($_SESSION["brand"])==true){
				// 					// $sql = mysql_query("SELECT * from s_mas where PART_NO like  '$letters%' and BRAND_NAME='".$_SESSION["brand"]."' order by STK_NO limit 50")or die(mysql_error());
				// 					$sql = mysql_query("SELECT * from s_mas where PART_NO like  '%$letters%'  order by STK_NO limit 50")or die(mysql_error());
				// 				} else {
				// 					$sql =  "SELECT * from s_mas where PART_NO like  '$letters%' order by STK_NO limit 50";
				// 					echo $sql;

								 
				// 				}
				// 			} else if ($_GET["mstatus"]=="itemname"){
				// 				$letters = $_GET['itemname'];
				// 				//$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
				// 				if (isset($_SESSION["brand"])==true){
				// 					$sql = mysql_query("SELECT * from s_mas where DESCRIPT like  '$letters%' and BRAND_NAME='".$_SESSION["brand"]."' order by STK_NO limit 50")or die(mysql_error());
									
				// 				} else {
				// 					$sql = mysql_query("SELECT * from s_mas where DESCRIPT like  '$letters%' order by STK_NO limit 50") or die(mysql_error());
									
				// 				}
				// 			} else {
								
				// 				$letters = $_GET['itemname'];
				// 				//$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
				// 				if (isset($_SESSION["brand"])==true){
				// 					$sql = mysql_query("SELECT * from s_mas where DESCRIPT like  '$letters%' and BRAND_NAME='".$_SESSION["brand"]."' order by STK_NO limit 50") or die(mysql_error());
				// 				} else {
				// 					$sql = mysql_query("SELECT * from s_mas where DESCRIPT like  '$letters%' order by STK_NO limit 50") or die(mysql_error());
									
				// 				}
				// 			}
				// 		}
                    		$sql = "select * from s_mas where STK_NO <> ''";
                            if ($_GET["itno"] != "") {
                                $sql .= " and STK_NO like '" . Trim($_GET["itno"]) . "%'";
                            }
                            if ($_GET["itemname"] != "") {
                                $sql .= " and DESCRIPT like '" . Trim($_GET["itemname"]) . "%'";
                            }
                            if ($_GET["brand1"] != "") {
                                $sql .= " and BRAND_NAME like '" . Trim($_GET["brand1"]) . "%'";
                            }
                            if ($_GET["jobno"] != "") {
                                $sql .= " and PART_NO like '" . Trim($_GET["jobno"]) . "%'";
                            }
                            $sql .= " ORDER BY STK_NO limit 50";
                            echo $sql;
							
                            foreach ($conn->query($sql) as $row) {
							
							if ($_SESSION["stname"]=="weekly_order"){
							
								$ResponseXML .= "<tr>               
                              <td onclick=\"itno_weekly('".$row['STK_NO']."');\">".$row['STK_NO']."</td>
                              <td onclick=\"itno_weekly('".$row['STK_NO']."');\">".$row['DESCRIPT']."</td>
							  <td onclick=\"itno_weekly('".$row['STK_NO']."');\">".$row['PART_NO']."</td>
							  <td onclick=\"itno_weekly('".$row['STK_NO']."');\">".$row['BRAND_NAME']."</td>
							  <td onclick=\"itno_weekly('".$row['STK_NO']."');\">".$row['QTYINHAND']."</td>";
						
                                                        	
                            $ResponseXML .= "</tr>";
							
							}else if (($_GET["mstatus"]=="itno") or ($_GET["mstatus"]=="itemname") or ($_GET["mstatus"]=="brand") or ($_GET["mstatus"]=="jobno")){
							    
							    //echo '1111';
								$ResponseXML .= "<tr>
                              <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['STK_NO']."</a></td>
                              <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['DESCRIPT']."</a></td>
							  <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['BRAND_NAME']."</td>
							   <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['GEN_NO']."</a></td>
							  <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['SUBSTITUTE']."</td>
							  <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['SELLING']."</td>
							   <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['PART_NO']."</a></td>
							  <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['QTYINHAND']."</td>";
							  
                                                        	
                            	$ResponseXML .= "</tr>";
							} else if ($_GET["mstatus2"]=="claim_item"){		
									
							$ResponseXML .= "<tr>
                              <td onclick=\"itno_claim('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['STK_NO']."</a></td>
                              <td onclick=\"itno_claim('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['DESCRIPT']."</a></td>
							  <td onclick=\"itno_claim('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['PART_NO']."</a></td>
							  <td onclick=\"itno_claim('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['BRAND_NAME']."</td>
							  <td onclick=\"itno_claim('".$row['STK_NO']."', '".$_GET["stname"]."');\">".$row['QTYINHAND']."</td>";
						/*	  $department=$_SESSION["department"];
							  
							  $sql1 = mysql_query("select QTYINHAND from s_submas where STK_NO='".$row['STK_NO']."' AND STO_CODE='".$department."'") or die(mysql_error()) or die(mysql_error());
							  if($row1 = mysql_fetch_array($sql1)){
							  	$ResponseXML .= "<td bgcolor=\"#222222\" onclick=\"itno('".$row['STK_NO']."');\">".$row1['QTYINHAND']."</a></td>";
							  }	else {
							  	$ResponseXML .= "<td bgcolor=\"#222222\" onclick=\"itno('".$row['STK_NO']."');\">0</a></td>";
							  }*/
                                                        	
                            $ResponseXML .= "</tr>";
							
							}else if ($_GET["mstatus2"]=="grn_item"){	
							    
							   // echo '2222222';
								
								$ResponseXML .= "<tr>               
                              <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['STK_NO']."</a></td>
                              <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['DESCRIPT']."</a></td>
							  <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['BRAND_NAME']."</a></td>
							  <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['GEN_NO']."</a></td>
							  <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['SUBSTITUTE']."</a></td>
							   <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['SELLING']."</a></td>
							  <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['PART_NO']."</a></td>
							  <td onclick=\"itno_quot('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['QTYINHAND']."</a></td></tr>";
							  
							  
							 //  <td onclick=\"itno_grn('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['STK_NO']."</a></td>
        //                       <td onclick=\"itno_grn('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['DESCRIPT']."</a></td>
							 // <td onclick=\"itno_grn('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['BRAND_NAME']."</a></td>
							 // <td onclick=\"itno_grn('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['GEN_NO']."</a></td>
							 // <td onclick=\"itno_grn('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['SUBSTITUTE']."</a></td>
							 //  <td onclick=\"itno_grn('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['SELLING']."</a></td>
							 // <td onclick=\"itno_grn('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['PART_NO']."</a></td>
							 // <td onclick=\"itno_grn('".$row['STK_NO']."', '".$_GET["mstatus2"]."');\">".$row['QTYINHAND']."</a></td></tr>";
							  
					
							 }   
							}
							  
                    $ResponseXML .= "   </table>";
		
										
					echo $ResponseXML;
	//}
}


if ($_GET["Command"]=="pass_itno_quot"){
	header('Content-Type: text/xml'); 
	echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
			
			$sql_invpara = mysql_query("SELECT * from invpara") or die(mysql_error());
			$row_invpara = mysql_fetch_array($sql_invpara);
			
			$vatrate=$row_invpara["vatrate"]/100;
			
			
			
			$ResponseXML = "";
			$ResponseXML .= "<salesdetails>";

			
		
				$sql = mysql_query("Select * from s_mas where STK_NO='".$_GET['itno']."'") or die(mysql_error());
			
				if($row = mysql_fetch_array($sql)){
				
					
					$ResponseXML .= "<str_code><![CDATA[".$row['STK_NO']."]]></str_code>";
					$ResponseXML .= "<str_description><![CDATA[".$row['DESCRIPT']."]]></str_description>";
					
				// 	if ($_GET["vatmethod"]=="non"){
				// 		$SELLING=$row['SELLING'];
				// 	} else {
				// 		$SELLING=$row['SELLING']/($vatrate+1);
				// 	}
				
				if ($row['Flagdesc']=='1'){
                                            
         $ResponseXML .= "<str_Flagdesc><![CDATA[yess]]></str_Flagdesc>";
        } else {
                                             
        $ResponseXML .= "<str_Flagdesc><![CDATA[Noo]]></str_Flagdesc>";
        }
					$ResponseXML .= "<str_selpri><![CDATA[".number_format($row["SELLING"], 2, ".", "")."]]></str_selpri>";
					
					$ResponseXML .= "<str_partno><![CDATA[".$row["PART_NO"]."]]></str_partno>";
					
					
					$department=trim(substr($_GET["department"], 0, 2));
					
					
					$sql = mysql_query("select QTYINHAND from s_submas where STK_NO='".$_GET['itno']."' AND STO_CODE='".$department."'") or die(mysql_error());
					if($row = mysql_fetch_array($sql)){
						if (is_null($row["QTYINHAND"])==false){
							$ResponseXML .= "<qtyinhand><![CDATA[".$row["QTYINHAND"]."]]></qtyinhand>";
						} else {
							$ResponseXML .= "<qtyinhand><![CDATA[]]></qtyinhand>";
						}
					} else {
						$ResponseXML .= "<qtyinhand><![CDATA[]]></qtyinhand>";
					}
				
				
				}				
			
				 
			
	
				$ResponseXML .= "</salesdetails>";	
				echo $ResponseXML;
				
			
	
}	


?>
