
<?php

session_start();


require_once ("connection_sql.php");
header('Content-Type: text/xml');
date_default_timezone_set('Asia/Colombo');


if ($_POST["Command"] == "sendother") {
    try {
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $conn->beginTransaction();
        
        if($_POST['ocompany']==""){
            echo "Enter Company Name";
        }else{
            
            $sql = "Select * from dag_item  where id='" . $_POST['id'] . "'";
            $result = $conn->query($sql); 
            if ($rowM = $result->fetch()) {
                $sql = "UPDATE dag_item set flag='3',oldjobno=jobno,ocompany='".$_POST['ocompany']."',onhand_date='" . date("Y-m-d") . "',TYPE='SENDOTHER'  where id='" . $_POST['id'] . "'";
                $result = $conn->query($sql); 
                
                $sqllog = "insert into entry_log(refno, username, docname, trnType, stime, sdate,company) values
                ('" . $rowM['jobno'] . "', '" . $_SESSION["CURRENT_USER"] . "', 'SEND ONHAND TO OTHER', 'Save', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d") . "','".$rowM['department']."')";
                $resultlog = $conn->query($sqllog);
                
                
                echo "SENDED";
                
            }
        }
        $conn->commit();

    } catch (Exception $e) {
        $conn->rollBack();
        echo $e;
    }
}

if ($_POST["Command"] == "sendinvoice") {
    try {
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $conn->beginTransaction();
        
        $sql = "Select * from dag_item  where id='" . $_POST['id'] . "'";
        $result = $conn->query($sql); 
        if ($rowM = $result->fetch()) {
            $sql = "UPDATE dag_item set flag='6',onhand_date='" . date("Y-m-d") . "',TYPE='SENDINVOICE'  where id='" . $_POST['id'] . "'";
            $result = $conn->query($sql); 
            
            $sqllog = "insert into entry_log(refno, username, docname, trnType, stime, sdate,company) values
            ('" . $rowM['jobno'] . "', '" . $_SESSION["CURRENT_USER"] . "', 'SEND ONHAND TO INVOICE', 'Save', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d") . "','".$rowM['department']."')";
            $resultlog = $conn->query($sqllog);
            
            
            echo "SEND INVOICE";
          
            
        }
             
        $conn->commit();

    } catch (Exception $e) {
        $conn->rollBack();
        echo $e;
    }
}



?>