<?php


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

	include_once("connection.php");
 

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

//	if(isset($_GET['itemname'])){
//		$letters = $_GET['itemname'];
    //$letters = $_GET['letters'];
//		$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
//	$res = $dbinv->query("SELECT * FROM mast_family where name like '".$letters."%'") or die("Error";
    //$res = $dbinv->query("SELECT distinct trn_involved.str_name FROM trn_involved where str_name like '".$letters."%'") or die("Error";
    //SELECT * FROM occupation_details where str_first_name like 'k%'
//echo $res;

    $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\">Barcode/QR</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=\"50\"  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>";

    $ResponseXML .= "</tr>";
 
    $letters = $_GET['itemname'];
    $letters1 = $_GET['jobno'];
    $letters2 = $_GET['brand'];
    $letters3 = $_GET['itno'];
    $letters4 = $_GET['qrcode'];
    
    $sql1 = "select * from s_mas where stk_no <> ''";
    if (isset($_GET['brand'])) {
        if ($_GET['brand'] != "") {
            $sql1 .= " and BRAND_NAME like '$letters2%'";
        }
    }
    if (isset($_GET['jobno'])) {
        if ($_GET['jobno'] != "") {
            $sql1 .= " and (PART_NO like '%$letters1%' OR GEN_NO like '%$letters1%')";
        }
    }
    if (isset($_GET['itemname'])) {
        if ($_GET['itemname'] != "") {
            $sql1 .= " and DESCRIPT like  '%$letters%'";
        }
    }
    if (isset($_GET['itno'])) {
        if ($_GET['itno'] != "") {
            $sql1 .= " and STK_NO like  '%$letters3%'";
        }
    }
    if (isset($_GET['qrcode'])) {
        if ($_GET['qrcode'] != "") {
            $sql1 .= " and comno like  '%$letters4%'";
        }
    }
    if ($_GET["checkbox"] == "true") {
       $sql1 .= " and qtyinhand >  0";
   }    
   $sql1 .= " order by stk_no limit 500";  
   $res = $dbinv->query($sql1);
 
   while ($row = $res->fetch()) {

    if ($_GET["mstatus2"] == "purord_item") {
        $ResponseXML .= "<tr>
        <td onclick=\"itno_purord('" . $row['STK_NO'] . "');\">" . $row['STK_NO'] . "</a></td>
        <td onclick=\"itno_purord('" . $row['STK_NO'] . "');\">" . $row['PART_NO'] . " " . $row['DESCRIPT'] . "</a></td>
        <td onclick=\"itno_purord('" . $row['STK_NO'] . "');\">" . $row['BRAND_NAME'] . "</td>
        <td onclick=\"itno_purord('" . $row['STK_NO'] . "');\">" . $row['GEN_NO'] . "</td>
        <td onclick=\"itno_purord('" . $row['STK_NO'] . "');\">" . $row['SUBSTITUTE'] . "</td>
        <td onclick=\"itno_purord('" . $row['STK_NO'] . "');\" align=right>" . number_format($row['SELLING'], 2, ".", ",") . "</td>
        <td onclick=\"itno_purord('" . $row['STK_NO'] . "');\" align=left>" . $row['PART_NO'] . "</td>
        <td onclick=\"itno_purord('" . $row['STK_NO'] . "');\" align=right>" . number_format($row['QTYINHAND'], 2, ".", "") . "</td>";
    } else if ($_GET["mstatus2"] == "grn_item") {
        $ResponseXML .= "<tr>
        <td onclick=\"itno_grn('" . $row['STK_NO'] . "');\">" . $row['STK_NO'] . "</a></td>
        <td onclick=\"itno_grn('" . $row['STK_NO'] . "');\">" . $row['PART_NO'] . " " . $row['DESCRIPT'] . "</a></td>
        <td onclick=\"itno_grn('" . $row['STK_NO'] . "');\">" . $row['BRAND_NAME'] . "</td>
        <td onclick=\"itno_grn('" . $row['STK_NO'] . "');\">" . $row['GEN_NO'] . "</td>
        <td onclick=\"itno_grn('" . $row['STK_NO'] . "');\">" . $row['SUBSTITUTE'] . "</td>
        <td onclick=\"itno_grn('" . $row['STK_NO'] . "');\" align=right>" . number_format($row['SELLING'], 2, ".", ",") . "</td>
        <td onclick=\"itno_grn('" . $row['STK_NO'] . "');\" align=left>" . $row['PART_NO'] . "</td>
        <td onclick=\"itno_grn('" . $row['STK_NO'] . "');\" align=right>" . number_format($row['QTYINHAND'], 2, ".", "") . "</td>";
    } else if ($_GET["mstatus2"] == "inv_item") {
 
        if (($_GET["mstatus"] == "itno") or ( $_GET["mstatus"] == "itemname") or ( $_GET["mstatus"] == "brand") or ( $_GET["mstatus"] == "jobno") or ( $_GET["mstatus"] == "itemname_brand") or ( $_GET["mstatus"] == "qrcode")) {

            if ($_GET['checkProblem'] == 'false') {
                $brName = $row['BRAND_NAME'];
                $problemBrands = ($brName == 'Dag Customer' || $brName == 'Dag Custormer' || $brName == 'Dag CustomeDag Customerr' || $brName == 'Dag Sale' || $brName == 'Rebuild Customer' || $brName == 'rebuild sale');
            }
            
            if ( $_GET["stname"] == "un_delivered" ) {

                if (!($problemBrands && ($row['QTYINHAND'] == '0'))) {
                    $ResponseXML .= "<tr>
                    <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['STK_NO'] . "</a></td>
                    <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['PART_NO'] . " " . $row['DESCRIPT'] . "</a></td>
                    <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['comno'] . "</td>
                    <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['BRAND_NAME'] . "</td>
                    <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['GEN_NO'] . "</td>
                    <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['SUBSTITUTE'] . "</td>
                    <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=right>" . number_format($row['SELLING'], 2, ".", ",") . "</td>
                    <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=left>" . $row['PART_NO'] . "</td>
                    <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=right>" . number_format($row['QTYINHAND'], 2, ".", "") . "</td>";
     
                    $ResponseXML .= "</tr>";
                }
            }else{
                if (!($problemBrands && ($row['QTYINHAND'] == '0'))) {
                    $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['PART_NO'] . " " . $row['DESCRIPT'] . "</a></td>
                    <td onclick=\"itno_quot('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['comno'] . "</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'] . "</td>
                    <td onclick=\"itno_quot('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['SUBSTITUTE'] . "</td>
                    <td onclick=\"itno_quot('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=right>" . number_format($row['SELLING'], 2, ".", ",") . "</td>
                    <td onclick=\"itno_quot('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=left>" . $row['PART_NO'] . "</td>
                    <td onclick=\"itno_quot('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=right>" . number_format($row['QTYINHAND'], 2, ".", "") . "</td>";
     
                    $ResponseXML .= "</tr>";
                }
            }
        } 
    } else if ($_GET["mstatus2"] == "bin_card") {

        if (($_GET["mstatus"] == "itno") or ( $_GET["mstatus"] == "itemname") or ( $_GET["mstatus"] == "brand") or ( $_GET["mstatus"] == "jobno") or ( $_GET["mstatus"] == "itemname_brand")) {
            $ResponseXML .= "<tr>
            <td onclick=\"itno_bin('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['STK_NO'] . "</a></td>
            <td onclick=\"itno_bin('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['PART_NO'] . " " . $row['DESCRIPT'] . "</a></td>
            <td onclick=\"itno_bin('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['BRAND_NAME'] . "</td>
            <td onclick=\"itno_bin('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['GEN_NO'] . "</td>
            <td onclick=\"itno_bin('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['SUBSTITUTE'] . "</td>
            <td onclick=\"itno_bin('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=right>" . number_format($row['SELLING'], 2, ".", ",") . "</td>
            <td onclick=\"itno_bin('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=left>" . $row['PART_NO'] . "</td>
            <td onclick=\"itno_bin('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=right>" . number_format($row['QTYINHAND'], 2, ".", "") . "</td>";



            $ResponseXML .= "</tr>";
        }
    } else if ($_GET["mstatus2"] == "claim_item") {

        if (($_GET["mstatus"] == "itno") or ( $_GET["mstatus"] == "itemname") or ( $_GET["mstatus"] == "brand") or ( $_GET["mstatus"] == "jobno") or ( $_GET["mstatus"] == "itemname_brand")) {
            $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['PART_NO'] . " " . $row['DESCRIPT'] . "</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['GEN_NO'] . "</td>
            <td onclick=\"itno_claim('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['SUBSTITUTE'] . "</td>
            <td onclick=\"itno_claim('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=right>" . number_format($row['SELLING'], 2, ".", ",") . "</td>
            <td onclick=\"itno_claim('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=left>" . $row['PART_NO'] . "</td>
            <td onclick=\"itno_claim('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=right>" . number_format($row['QTYINHAND'], 2, ".", "") . "</td>";



            $ResponseXML .= "</tr>";
        }
    } else {
        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['BRAND_NAME'] . "</td>

            <td onclick=\"itno_weekly('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['SUBSTITUTE'] . "</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") or ( $_GET["mstatus"] == "itemname_brand")) {
            $ResponseXML .= "<tr>
            <td onclick=\"itno('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['STK_NO'] . "</a></td>
            <td onclick=\"itno('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['PART_NO'] . " " . $row['DESCRIPT'] . "</a></td>
            <td onclick=\"itno('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['BRAND_NAME'] . "</td>
            <td onclick=\"itno('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['GEN_NO'] . "</td>
            <td onclick=\"itno('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\">" . $row['SUBSTITUTE'] . "</td>
            <td onclick=\"itno('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=right>" . number_format($row['SELLING'], 2, ".", ",") . "</td>
            <td onclick=\"itno('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=left>" . $row['PART_NO'] . "</td>
            <td onclick=\"itno('" . $row['STK_NO'] . "', '" . $_GET["stname"] . "');\" align=right>" . number_format($row['QTYINHAND'], 2, ".", "") . "</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['PART_NO'] . " " . $row['DESCRIPT'] . "</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['SUBSTITUTE'] . "</td>";
                /* 	  $department=$_SESSION["department"];

                  $sql1 = $dbinv->query("select QTYINHAND from s_submas where STK_NO='".$row['STK_NO']."' AND STO_CODE='".$department."'") or die("Error";
                  if($row1 = $sql1->fetch()){
                  $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>";
          }
      }
  }
  if($itemTotal > 0){
    $ResponseXML .= "<tr><td colspan='8'></td>";
    $ResponseXML .= "<td align='right'>" . number_format($itemTotal, 2, ".", "") . "</td>";
    $ResponseXML .= "<td align='right'>" . number_format($stockTotal, 2, ".", "") . "</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 = $dbinv->query("SELECT * from invpara") or die("Error";
			$row_invpara = $sql_invpara->fetch();
			
			$vatrate=$row_invpara["vatrate"]/100;
			
			
			
			$ResponseXML = "";
			$ResponseXML .= "<salesdetails>";

			
		
				$sql = $dbinv->query("Select * from s_mas where STK_NO='".$_GET['itno']."'") or die("Error";
			
				if($row = $sql->fetch()){
				
					
					$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($SELLING, 2, ".", "")."]]></str_selpri>";
					
					$ResponseXML .= "<str_partno><![CDATA[".$row["PART_NO"]."]]></str_partno>";
					
					
					$department=trim(substr($_GET["department"], 0, 2));
					
					
					$sql = $dbinv->query("select QTYINHAND from s_submas where STK_NO='".$_GET['itno']."' AND STO_CODE='".$department."'") or die("Error";
					if($row = $sql->fetch()){
						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;
				
			
	
}	


?>

