<?php

session_start();


include_once("connectioni.php");




if ($_GET["Command"] == "pass_itno") {
    header('Content-Type: text/xml');
    echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";


    $ResponseXML = "";
    $ResponseXML .= "<salesdetails>";



    $sql = mysqli_query($GLOBALS['dbinv'], "Select * from s_mas where stk_no='" . $_GET['itno'] . "'") or die(mysqli_error());

    if ($row = mysqli_fetch_array($sql)) {


        $ResponseXML .= "<str_code><![CDATA[" . $row['STK_NO'] . "]]></str_code>";
        $ResponseXML .= "<str_description><![CDATA[" . $row['DESCRIPT'] . "]]></str_description>";
        $ResponseXML .= "<actual_selling><![CDATA[" . $row['SELLING'] . "]]></actual_selling>";

         
    }
	
	
	$tb = "";
	$tb .= "<table class='table'>";
	$tb .= "<tr><th>Date</th><th>Reference No</th><th>In</th><th>Out</th><th>Balance</th></tr>";
	
	$sql = "select * from s_trn_defective where stk_no = '" . $_GET['itno']    . "' order by sdate,id";
	$result = mysqli_query($GLOBALS['dbinv'],$sql);
	$mbal = 0;
	while ($row = mysqli_fetch_array($result)) {
		
		$tb .= "<tr>";
		$tb .= "<td>" .  $row['SDATE']   .  "</td>";
		$tb .= "<td>" .  $row['REFNO']   .  "</a></td>";
		 
		if ($row['QTY'] >0) {
		$tb .= "<td>" .  number_format($row['QTY'],0,"","")   .  "</td>";
		$tb .= "<td></td>";
		} else {
		$tb .= "<td></td>";
		$tb .= "<td>" .  $row['QTY']   .  "</td>";		
		}
		$mbal = $mbal +  $row['QTY'];
		$tb .= "<td>" .  $mbal   .  "</td>";		
		
		$tb .= "</tr>";
		
	}
	
	$tb .= "</table>";
	$ResponseXML .= "<stname><![CDATA[" . $_GET['stname'] . "]]></stname>";
	$ResponseXML .= "<tb><![CDATA[" . $tb . "]]></tb>";

	
    $ResponseXML .= "</salesdetails>";
    echo $ResponseXML;
}
?>
