<?php

session_start();



////////////////////////////////////////////// Database Connector /////////////////////////////////////////////////////////////

require_once ("connection_sql.php");



////////////////////////////////////////////// Write XML ////////////////////////////////////////////////////////////////////

header('Content-Type: text/xml');



date_default_timezone_set('Asia/Colombo');


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

    $ResponseXML = "";

    $ResponseXML .= "<table class=\"table table-bordered\">

	            <tr>

                        <th width=\"100\">Stk No</th>

                        <th width=\"250\">Description</th>

                        <th width=\"100\">Part No</th> 

                        <th width=\"100\">Brand</th> 
  

                    </tr>";





    $sql = "select * from s_mas where STK_NO  <> '' ";



    if ($_GET['refno'] != "") {
        $sql .= " and STK_NO like '%" . $_GET['refno'] . "%'";
    } 
    if ($_GET['des'] != "") {

        $sql .= " and DESCRIPT like '%" . $_GET['des'] . "%'";
    }
    if ($_GET['partno'] != "") {

        $sql .= " and PART_NO like '%" . $_GET['partno'] . "%'";
    }
    if ($_GET['brand'] != "") {

        $sql .= " and BRAND_NAME like '%" . $_GET['brand'] . "%'";
    }

    $stname = $_GET['stname'];



    $sql .= " order by STK_NO asc limit 50";


    // echo $sql;
    foreach ($conn->query($sql) as $row) {

        $cuscode = $row["STK_NO"];
        $ResponseXML .= "<tr>               
                              <td onclick=\"crnview('$cuscode', '$stname');\">" . $row['STK_NO'] . "</a></td>
                              <td onclick=\"crnview('$cuscode', '$stname');\">" . $row['PART_NO'].'&nbsp;'.$row['DESCRIPT'] . "</a></td>
                              <td onclick=\"crnview('$cuscode', '$stname');\">" . $row['PART_NO'] . "</a></td>
                              <td onclick=\"crnview('$cuscode', '$stname');\">" . $row['BRAND_NAME'] . "</a></td> 
                            </tr>";
    }

    $ResponseXML .= "</table>";

    echo $ResponseXML;
}


if ($_GET["Command"] == "pass_rec") {
 
    $ResponseXML = "";

    $ResponseXML .= "<salesdetails>";

    $sql = "Select * from s_mas where STK_NO='" . $_GET['refno'] . "'";

    $result = $conn->query($sql);



    if ($row = $result->fetch()) {

        $ResponseXML .= "<stk_no><![CDATA[" . $row["STK_NO"] . "]]></stk_no>";

        
 
    }

 

    $ResponseXML .= "</salesdetails>";

    echo $ResponseXML;
}

?>