<?php

session_start();

////////////////////////////////////////////// Database Connector /////////////////////////////////////////////////////////////
require_once ("connection_sql.php");

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

date_default_timezone_set('Asia/Colombo');

/////////////////////////////////////// GetValue //////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Registration /////////////////////////////////////////////////////////////////////////




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

    header('Content-Type: text/xml');
    echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";

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

    $cuscode = $_GET["refno"];
    
    $sql = "Select * from view_dag_invoice where REFNO='" . $cuscode . "' ";
  
    $sql = $conn->query($sql);
    if ($row = $sql->fetch()) {


        $ResponseXML .= "<id><![CDATA[" . $row['REFNO'] . "]]></id>";
        $ResponseXML .= "<str_customername><![CDATA[" . $row['SUP_CODE'] . "]]></str_customername>";
        $ResponseXML .= "<str_customername1><![CDATA[" . $row['SUP_NAME'] . "]]></str_customername1>";
        $ResponseXML .= "<str_customername2><![CDATA[" . $row['COUNTRY'] . "]]></str_customername2>";
        $ResponseXML .= "<str_customername3><![CDATA[" . $row['SDATE'] . "]]></str_customername3>";
        $ResponseXML .= "<str_customername4><![CDATA[" . $row['REMARK'] . "]]></str_customername4>";
        $ResponseXML .= "<str_customername5><![CDATA[" . $row['AMOUNT'] . "]]></str_customername5>";
        
    }
    
    
    $ResponseXML .= "<sales_table><![CDATA[<table class=\"table\">
					<tr>
						<td style=\"width: 90px;\">Item</td>
						<td>Description</td>
						<td style=\"width: 100px;\">Brand</td>
						<td style=\"width: 100px;\">Serial No</td>
						<td style=\"width: 100px;\">Rate</td>
						<td style=\"width: 10px;\"></td>
					</tr>";

    $i = 1;
    $mtot = 0;
   $sql1 = "select * from s_ordtrn_dag where REFNO ='" . $cuscode . "' ";
  
    foreach ($conn->query($sql1) as $row1) {

        $ResponseXML .= "<tr>                              
                             <td>" . $row1['STK_NO'] . "</td>
                             <td >" . $row1['DESCRIPT'] . "</td>
                             <td>" . $row1['RATE'] . "</td>
                             <td>" . $row1['serial_no'] . "</td>
                             </tr>";

        $mtot = $mtot + $row['rate'];
        $i = $i + 1;
    }

    $ResponseXML .= "   </table>]]></sales_table>";
    $ResponseXML .= "<subtot><![CDATA[" . number_format($mtot, 2, ".", ",") . "]]></subtot>";
    $ResponseXML .= "</salesdetails>";

    echo $ResponseXML;
}

?>